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//===----------------------------------------------------------------------===// 36const std::string &Banner)
const{
40bool MachineFunctionPass::runOnFunction(
Function &
F) {
41// Do not codegen any 'available_externally' functions at all, they have 42// definitions outside the translation unit. 43if (
F.hasAvailableExternallyLinkage())
54 <<
" pass are not met by function " <<
F.getName() <<
".\n" 55 <<
"Required properties: ";
57errs() <<
"\nCurrent properties: ";
63// Collect the MI count of the function before the pass. 64unsigned CountBefore, CountAfter;
66// Check if the user asked for size remarks. 67bool ShouldEmitSizeRemarks =
68F.getParent()->shouldEmitInstrCountChangedRemark();
70// If we want size remarks, collect the number of MachineInstrs in our 71// MachineFunction before the pass runs. 72if (ShouldEmitSizeRemarks)
75// For --print-changed, if the function name is a candidate, save the 76// serialized MF to be compared later. 81 PassID = PI->getPassArgument();
87if (ShouldPrintChanged) {
92 MFProps.
reset(ClearedProperties);
96if (ShouldEmitSizeRemarks) {
97// We wanted size remarks. Check if there was a change to the number of 98// MachineInstrs in the module. Emit a remark if there was a change. 100if (CountBefore != CountAfter) {
103 int64_t Delta =
static_cast<int64_t
>(CountAfter) -
104static_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);
119 MFProps.
set(SetProperties);
121// For --print-changed, print if the serialized MF has changed. Modes other 122// than quiet/verbose are unimplemented and treated the same as 'quiet'. 123if (ShouldPrintChanged || !IsInterestingPass) {
124if (ShouldPrintChanged) {
128if (IsInterestingPass && BeforeStr != AfterStr) {
130") on " + MF.
getName() +
" ***\n");
147StringRef Removed = Color ?
"\033[31m-%l\033[0m\n" :
"-%l\n";
159 IsInterestingPass ?
" omitted because no change" :
" filtered out";
162errs() <<
" (" << PassID <<
")";
173// MachineFunctionPass preserves all LLVM IR passes, but there's no 174// high-level way to express this. Instead, just list a bunch of 175// passes explicitly. This does not include setPreservesCFG, 176// because CodeGen overloads that to mean preserving the MachineBasicBlock 177// CFG in addition to the LLVM IR CFG. 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.
===- MachineOptimizationRemarkEmitter.h - Opt Diagnostics -*- C++ -*-—===//
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.
Diagnostic information for optimization analysis remarks.
The optimization diagnostic interface.
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.