1//===-- MachineFunctionPass.cpp -------------------------------------------===//
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
7//===----------------------------------------------------------------------===//
9// This file contains the definitions of the MachineFunctionPass members.
11//===----------------------------------------------------------------------===//
38 cl::desc(
"Dump dropped debug variables stats for MIR passes"),
42 const std::string &Banner)
const {
46bool MachineFunctionPass::runOnFunction(
Function &
F) {
47 // Do not codegen any 'available_externally' functions at all, they have
48 // definitions outside the translation unit.
49 if (
F.hasAvailableExternallyLinkage())
60 <<
" pass are not met by function " <<
F.getName() <<
".\n"
61 <<
"Required properties: ";
62 RequiredProperties.print(
errs());
63 errs() <<
"\nCurrent properties: ";
69 // Collect the MI count of the function before the pass.
70 unsigned CountBefore, CountAfter;
72 // Check if the user asked for size remarks.
73 bool ShouldEmitSizeRemarks =
74 F.getParent()->shouldEmitInstrCountChangedRemark();
76 // If we want size remarks, collect the number of MachineInstrs in our
77 // MachineFunction before the pass runs.
78 if (ShouldEmitSizeRemarks)
81 // For --print-changed, if the function name is a candidate, save the
82 // serialized MF to be compared later.
83 SmallString<0> BeforeStr, AfterStr;
87 PassID = PI->getPassArgument();
93 if (ShouldPrintChanged) {
94 raw_svector_ostream OS(BeforeStr);
98 MFProps.
reset(ClearedProperties);
102 DroppedVariableStatsMIR DroppedVarStatsMF;
111 if (ShouldEmitSizeRemarks) {
112 // We wanted size remarks. Check if there was a change to the number of
113 // MachineInstrs in the module. Emit a remark if there was a change.
115 if (CountBefore != CountAfter) {
116 MachineOptimizationRemarkEmitter
MORE(MF,
nullptr);
118 int64_t Delta =
static_cast<int64_t
>(CountAfter) -
119 static_cast<int64_t
>(CountBefore);
120 MachineOptimizationRemarkAnalysis
R(
"size-info",
"FunctionMISizeChange",
124 <<
": Function: " <<
NV(
"Function",
F.getName()) <<
": "
125 <<
"MI Instruction count changed from "
126 <<
NV(
"MIInstrsBefore", CountBefore) <<
" to "
127 <<
NV(
"MIInstrsAfter", CountAfter)
128 <<
"; Delta: " <<
NV(
"Delta", Delta);
134 MFProps.
set(SetProperties);
136 // For --print-changed, print if the serialized MF has changed. Modes other
137 // than quiet/verbose are unimplemented and treated the same as 'quiet'.
138 if (ShouldPrintChanged || !IsInterestingPass) {
139 if (ShouldPrintChanged) {
140 raw_svector_ostream OS(AfterStr);
143 if (IsInterestingPass && BeforeStr != AfterStr) {
145 ") on " + MF.
getName() +
" ***\n");
162 StringRef Removed = Color ?
"033円[31m-%l033円[0m\n" :
"-%l\n";
163 StringRef
Added = Color ?
"033円[32m+%l033円[0m\n" :
"+%l\n";
164 StringRef NoChange =
" %l\n";
174 IsInterestingPass ?
" omitted because no change" :
" filtered out";
177 errs() <<
" (" << PassID <<
")";
178 errs() <<
" on " << MF.
getName() + Reason +
" ***\n";
188 // MachineFunctionPass preserves all LLVM IR passes, but there's no
189 // high-level way to express this. Instead, just list a bunch of
190 // passes explicitly. This does not include setPreservesCFG,
191 // because CodeGen overloads that to mean preserving the MachineBasicBlock
192 // CFG in addition to the LLVM IR CFG.
This is the interface for LLVM's primary stateless and local alias analysis.
===- DroppedVariableStatsMIR.h - Opt Diagnostics -*- C++ -*----------—===//
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.
static cl::opt< bool > DroppedVarStatsMIR("dropped-variable-stats-mir", cl::Hidden, cl::desc("Dump dropped debug variables stats for MIR passes"), cl::init(false))
This is the interface for a SCEV-based alias analysis.
static const char PassName[]
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.
void runBeforePass(StringRef PassID, MachineFunction *MF)
void runAfterPass(StringRef PassID, MachineFunction *MF)
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...
LLVM_ABI 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.
LLVM_ABI 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.
Pass interface - Implemented by all 'passes'.
AnalysisType & getAnalysis() const
getAnalysis<AnalysisType>() - This function is used by subclasses to get to the analysis information ...
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.
This class implements an extremely fast bulk output stream that can only output to a stream.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
initializer< Ty > init(const Ty &Val)
Add a small namespace to avoid name clashes with the classes used in the streaming interface.
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)
LLVM_ABI 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...
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
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.