LLVM  9.0.0svn
MachineFunctionPass.cpp
Go to the documentation of this file.
1 //===-- MachineFunctionPass.cpp -------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains the definitions of the MachineFunctionPass members.
10 //
11 //===----------------------------------------------------------------------===//
12 
18 #include "llvm/Analysis/IVUsers.h"
19 #include "llvm/Analysis/LoopInfo.h"
26 #include "llvm/CodeGen/Passes.h"
27 #include "llvm/IR/Dominators.h"
28 #include "llvm/IR/Function.h"
29 
30 using namespace llvm;
31 using namespace ore;
32 
33 Pass *MachineFunctionPass::createPrinterPass(raw_ostream &O,
34  const std::string &Banner) const {
35  return createMachineFunctionPrinterPass(O, Banner);
36 }
37 
39  // Do not codegen any 'available_externally' functions at all, they have
40  // definitions outside the translation unit.
42  return false;
43 
44  MachineModuleInfo &MMI = getAnalysis<MachineModuleInfo>();
46 
47  MachineFunctionProperties &MFProps = MF.getProperties();
48 
49 #ifndef NDEBUG
50  if (!MFProps.verifyRequiredProperties(RequiredProperties)) {
51  errs() << "MachineFunctionProperties required by " << getPassName()
52  << " pass are not met by function " << F.getName() << ".\n"
53  << "Required properties: ";
54  RequiredProperties.print(errs());
55  errs() << "\nCurrent properties: ";
56  MFProps.print(errs());
57  errs() << "\n";
58  llvm_unreachable("MachineFunctionProperties check failed");
59  }
60 #endif
61  // Collect the MI count of the function before the pass.
62  unsigned CountBefore, CountAfter;
63 
64  // Check if the user asked for size remarks.
65  bool ShouldEmitSizeRemarks =
67 
68  // If we want size remarks, collect the number of MachineInstrs in our
69  // MachineFunction before the pass runs.
70  if (ShouldEmitSizeRemarks)
71  CountBefore = MF.getInstructionCount();
72 
73  bool RV = runOnMachineFunction(MF);
74 
75  if (ShouldEmitSizeRemarks) {
76  // We wanted size remarks. Check if there was a change to the number of
77  // MachineInstrs in the module. Emit a remark if there was a change.
78  CountAfter = MF.getInstructionCount();
79  if (CountBefore != CountAfter) {
81  MORE.emit([&]() {
82  int64_t Delta = static_cast<int64_t>(CountAfter) -
83  static_cast<int64_t>(CountBefore);
84  MachineOptimizationRemarkAnalysis R("size-info", "FunctionMISizeChange",
85  MF.getFunction().getSubprogram(),
86  &MF.front());
87  R << NV("Pass", getPassName())
88  << ": Function: " << NV("Function", F.getName()) << ": "
89  << "MI Instruction count changed from "
90  << NV("MIInstrsBefore", CountBefore) << " to "
91  << NV("MIInstrsAfter", CountAfter)
92  << "; Delta: " << NV("Delta", Delta);
93  return R;
94  });
95  }
96  }
97 
98  MFProps.set(SetProperties);
99  MFProps.reset(ClearedProperties);
100  return RV;
101 }
102 
106 
107  // MachineFunctionPass preserves all LLVM IR passes, but there's no
108  // high-level way to express this. Instead, just list a bunch of
109  // passes explicitly. This does not include setPreservesCFG,
110  // because CodeGen overloads that to mean preserving the MachineBasicBlock
111  // CFG in addition to the LLVM IR CFG.
122 
124 }
Legacy wrapper pass to provide the GlobalsAAResult object.
Pass interface - Implemented by all &#39;passes&#39;.
Definition: Pass.h:80
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
DiagnosticInfoOptimizationBase::Argument NV
This class represents lattice values for constants.
Definition: AllocatorList.h:23
MachineFunctionProperties & reset(Property P)
This is the interface for a simple mod/ref and alias analysis over globals.
bool hasAvailableExternallyLinkage() const
Definition: GlobalValue.h:422
F(f)
AnalysisUsage & addRequired()
void print(raw_ostream &OS) const
Print the MachineFunctionProperties in human-readable form.
This is the interface for a SCEV-based alias analysis.
Diagnostic information for optimization analysis remarks.
virtual void getAnalysisUsage(AnalysisUsage &) const
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Definition: Pass.cpp:96
===- MachineOptimizationRemarkEmitter.h - Opt Diagnostics -*- C++ -*-—===//
static bool runOnFunction(Function &F, bool PostInlining)
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
bool shouldEmitInstrCountChangedRemark()
Return true if size-info optimization remark is enabled, false otherwise.
Definition: Module.h:263
bool verifyRequiredProperties(const MachineFunctionProperties &V) const
Represent the analysis usage information of a pass.
MachineFunction & getOrCreateMachineFunction(const Function &F)
Returns the MachineFunction constructed for the IR function F.
A wrapper analysis pass for the legacy pass manager that exposes a MemoryDepnedenceResults instance...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Legacy wrapper pass to provide the SCEVAAResult object.
The optimization diagnostic interface.
#define MORE()
Definition: regcomp.c:251
MachineFunctionPass * createMachineFunctionPrinterPass(raw_ostream &OS, const std::string &Banner="")
MachineFunctionPrinter pass - This pass prints out the machine function to the given stream as a debu...
MachineFunctionProperties & set(Property P)
StringRef getName() const
Return a constant reference to the value&#39;s name.
Definition: Value.cpp:214
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:565
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
The legacy pass manager&#39;s analysis pass to compute loop information.
Definition: LoopInfo.h:974
This is the interface for LLVM&#39;s primary stateless and local alias analysis.
Legacy analysis pass which computes a DominatorTree.
Definition: Dominators.h:259
A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object...
Properties which a MachineFunction may have at a given point in time.
This class contains meta information specific to a module.
Legacy wrapper pass to provide the BasicAAResult object.