LLVM: lib/CodeGen/MachineFunctionPass.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
31
32using namespace llvm;
33using namespace ore;
34
35Pass *MachineFunctionPass::createPrinterPass(raw_ostream &O,
36 const std::string &Banner) const {
38}
39
40bool MachineFunctionPass::runOnFunction(Function &F) {
41
42
43 if (F.hasAvailableExternallyLinkage())
44 return false;
45
46 MachineModuleInfo &MMI = getAnalysis().getMMI();
48
50
51#ifndef NDEBUG
53 errs() << "MachineFunctionProperties required by " << getPassName()
54 << " pass are not met by function " << F.getName() << ".\n"
55 << "Required properties: ";
57 errs() << "\nCurrent properties: ";
59 errs() << "\n";
61 }
62#endif
63
64 unsigned CountBefore, CountAfter;
65
66
67 bool ShouldEmitSizeRemarks =
68 F.getParent()->shouldEmitInstrCountChangedRemark();
69
70
71
72 if (ShouldEmitSizeRemarks)
74
75
76
81 PassID = PI->getPassArgument();
82 }
85 IsInterestingPass &&
87 if (ShouldPrintChanged) {
90 }
91
92 MFProps.reset(ClearedProperties);
93
95
96 if (ShouldEmitSizeRemarks) {
97
98
100 if (CountBefore != CountAfter) {
102 MORE.emit([&]() {
103 int64_t Delta = static_cast<int64_t>(CountAfter) -
104 static_cast<int64_t>(CountBefore);
109 << ": Function: " << NV("Function", F.getName()) << ": "
110 << "MI Instruction count changed from "
111 << NV("MIInstrsBefore", CountBefore) << " to "
112 << NV("MIInstrsAfter", CountAfter)
113 << "; Delta: " << NV("Delta", Delta);
114 return R;
115 });
116 }
117 }
118
119 MFProps.set(SetProperties);
120
121
122
123 if (ShouldPrintChanged || !IsInterestingPass) {
124 if (ShouldPrintChanged) {
127 }
128 if (IsInterestingPass && BeforeStr != AfterStr) {
129 errs() << ("*** IR Dump After " + getPassName() + " (" + PassID +
130 ") on " + MF.getName() + " ***\n");
138 errs() << AfterStr;
139 break;
147 StringRef Removed = Color ? "\033[31m-%l\033[0m\n" : "-%l\n";
148 StringRef Added = Color ? "\033[32m+%l\033[0m\n" : "+%l\n";
150 errs() << doSystemDiff(BeforeStr, AfterStr, Removed, Added, NoChange);
151 break;
152 }
153 }
158 const char *Reason =
159 IsInterestingPass ? " omitted because no change" : " filtered out";
161 if (!PassID.empty())
162 errs() << " (" << PassID << ")";
163 errs() << " on " << MF.getName() + Reason + " ***\n";
164 }
165 }
166 return RV;
167}
168
172
173
174
175
176
177
188
190}
This is the interface for LLVM's primary stateless and local alias analysis.
This is the interface for a simple mod/ref and alias analysis over globals.
Module.h This file contains the declarations for the Module class.
This is the interface for a SCEV-based alias analysis.
A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object.
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
Legacy wrapper pass to provide the BasicAAResult object.
Legacy analysis pass which computes a DominatorTree.
DISubprogram * getSubprogram() const
Get the attached subprogram.
Legacy wrapper pass to provide the GlobalsAAResult object.
The legacy pass manager's analysis pass to compute loop information.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
virtual bool runOnMachineFunction(MachineFunction &MF)=0
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
Properties which a MachineFunction may have at a given point in time.
void print(raw_ostream &OS) const
Print the MachineFunctionProperties in human-readable form.
bool verifyRequiredProperties(const MachineFunctionProperties &V) const
MachineFunctionProperties & set(Property P)
MachineFunctionProperties & reset(Property P)
unsigned getInstructionCount() const
Return the number of MachineInstrs in this MachineFunction.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
Function & getFunction()
Return the LLVM function that this machine code represents.
const MachineFunctionProperties & getProperties() const
Get the function properties.
const MachineBasicBlock & front() const
void print(raw_ostream &OS, const SlotIndexes *=nullptr) const
print - Print out the MachineFunction in a format suitable for debugging to the specified stream.
This class contains meta information specific to a module.
MachineFunction & getOrCreateMachineFunction(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.
PassInfo class - An instance of this class exists for every pass known by the system,...
Pass interface - Implemented by all 'passes'.
AnalysisID getPassID() const
getPassID - Return the PassID number that corresponds to this pass.
virtual void getAnalysisUsage(AnalysisUsage &) const
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
static const PassInfo * lookupPassInfo(const void *TI)
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
Legacy wrapper pass to provide the SCEVAAResult object.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
This class implements an extremely fast bulk output stream that can only output to a stream.
A raw_ostream that writes to an SmallVector or SmallString.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
DiagnosticInfoOptimizationBase::Argument NV
This is an optimization pass for GlobalISel generic memory operations.
cl::opt< ChangePrinter > PrintChanged
bool isFunctionInPrintList(StringRef FunctionName)
bool isPassInPrintList(StringRef PassName)
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
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...
std::string doSystemDiff(StringRef Before, StringRef After, StringRef OldLineFormat, StringRef NewLineFormat, StringRef UnchangedLineFormat)
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.