LLVM  8.0.1
MachineFunctionPass.cpp
Go to the documentation of this file.
1 //===-- MachineFunctionPass.cpp -------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains the definitions of the MachineFunctionPass members.
11 //
12 //===----------------------------------------------------------------------===//
13 
19 #include "llvm/Analysis/IVUsers.h"
20 #include "llvm/Analysis/LoopInfo.h"
27 #include "llvm/CodeGen/Passes.h"
28 #include "llvm/IR/Dominators.h"
29 #include "llvm/IR/Function.h"
30 
31 using namespace llvm;
32 using namespace ore;
33 
34 Pass *MachineFunctionPass::createPrinterPass(raw_ostream &O,
35  const std::string &Banner) const {
36  return createMachineFunctionPrinterPass(O, Banner);
37 }
38 
40  // Do not codegen any 'available_externally' functions at all, they have
41  // definitions outside the translation unit.
43  return false;
44 
45  MachineModuleInfo &MMI = getAnalysis<MachineModuleInfo>();
47 
48  MachineFunctionProperties &MFProps = MF.getProperties();
49 
50 #ifndef NDEBUG
51  if (!MFProps.verifyRequiredProperties(RequiredProperties)) {
52  errs() << "MachineFunctionProperties required by " << getPassName()
53  << " pass are not met by function " << F.getName() << ".\n"
54  << "Required properties: ";
55  RequiredProperties.print(errs());
56  errs() << "\nCurrent properties: ";
57  MFProps.print(errs());
58  errs() << "\n";
59  llvm_unreachable("MachineFunctionProperties check failed");
60  }
61 #endif
62  // Collect the MI count of the function before the pass.
63  unsigned CountBefore, CountAfter;
64 
65  // Check if the user asked for size remarks.
66  bool ShouldEmitSizeRemarks =
68 
69  // If we want size remarks, collect the number of MachineInstrs in our
70  // MachineFunction before the pass runs.
71  if (ShouldEmitSizeRemarks)
72  CountBefore = MF.getInstructionCount();
73 
74  bool RV = runOnMachineFunction(MF);
75 
76  if (ShouldEmitSizeRemarks) {
77  // We wanted size remarks. Check if there was a change to the number of
78  // MachineInstrs in the module. Emit a remark if there was a change.
79  CountAfter = MF.getInstructionCount();
80  if (CountBefore != CountAfter) {
82  MORE.emit([&]() {
83  int64_t Delta = static_cast<int64_t>(CountAfter) -
84  static_cast<int64_t>(CountBefore);
85  MachineOptimizationRemarkAnalysis R("size-info", "FunctionMISizeChange",
86  MF.getFunction().getSubprogram(),
87  &MF.front());
88  R << NV("Pass", getPassName())
89  << ": Function: " << NV("Function", F.getName()) << ": "
90  << "MI Instruction count changed from "
91  << NV("MIInstrsBefore", CountBefore) << " to "
92  << NV("MIInstrsAfter", CountAfter)
93  << "; Delta: " << NV("Delta", Delta);
94  return R;
95  });
96  }
97  }
98 
99  MFProps.set(SetProperties);
100  MFProps.reset(ClearedProperties);
101  return RV;
102 }
103 
107 
108  // MachineFunctionPass preserves all LLVM IR passes, but there's no
109  // high-level way to express this. Instead, just list a bunch of
110  // passes explicitly. This does not include setPreservesCFG,
111  // because CodeGen overloads that to mean preserving the MachineBasicBlock
112  // CFG in addition to the LLVM IR CFG.
123 
125 }
Legacy wrapper pass to provide the GlobalsAAResult object.
Pass interface - Implemented by all &#39;passes&#39;.
Definition: Pass.h:81
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:24
MachineFunctionProperties & reset(Property P)
This is the interface for a simple mod/ref and alias analysis over globals.
bool hasAvailableExternallyLinkage() const
Definition: GlobalValue.h:423
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:92
===- 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:566
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
The legacy pass manager&#39;s analysis pass to compute loop information.
Definition: LoopInfo.h:970
This is the interface for LLVM&#39;s primary stateless and local alias analysis.
Legacy analysis pass which computes a DominatorTree.
Definition: Dominators.h:260
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.