LLVM  15.0.0git
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 
17 #include "llvm/Analysis/IVUsers.h"
18 #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.
41  if (F.hasAvailableExternallyLinkage())
42  return false;
43 
44  MachineModuleInfo &MMI = getAnalysis<MachineModuleInfoWrapperPass>().getMMI();
46 
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 =
66  F.getParent()->shouldEmitInstrCountChangedRemark();
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",
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 }
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
DominanceFrontier.h
llvm::MachineFunctionProperties::print
void print(raw_ostream &OS) const
Print the MachineFunctionProperties in human-readable form.
Definition: MachineFunction.cpp:134
llvm::Function
Definition: Function.h:60
llvm::Function::getSubprogram
DISubprogram * getSubprogram() const
Get the attached subprogram.
Definition: Metadata.cpp:1571
llvm::MachineOptimizationRemarkEmitter
The optimization diagnostic interface.
Definition: MachineOptimizationRemarkEmitter.h:151
OptimizationRemarkEmitter.h
GlobalsModRef.h
ScalarEvolution.h
llvm::MachineFunction::getInstructionCount
unsigned getInstructionCount() const
Return the number of MachineInstrs in this MachineFunction.
Definition: MachineFunction.h:896
llvm::LoopInfoWrapperPass
The legacy pass manager's analysis pass to compute loop information.
Definition: LoopInfo.h:1287
llvm::MachineFunctionProperties
Properties which a MachineFunction may have at a given point in time.
Definition: MachineFunction.h:127
llvm::ore::NV
DiagnosticInfoOptimizationBase::Argument NV
Definition: OptimizationRemarkEmitter.h:136
llvm::errs
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
Definition: raw_ostream.cpp:893
MemoryDependenceAnalysis.h
BasicAliasAnalysis.h
llvm::MachineFunctionPass::getAnalysisUsage
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Definition: MachineFunctionPass.cpp:103
F
#define F(x, y, z)
Definition: MD5.cpp:55
llvm::RISCVFenceField::R
@ R
Definition: RISCVBaseInfo.h:240
llvm::MachineFunction::front
const MachineBasicBlock & front() const
Definition: MachineFunction.h:865
llvm::MachineFunctionProperties::verifyRequiredProperties
bool verifyRequiredProperties(const MachineFunctionProperties &V) const
Definition: MachineFunction.h:224
llvm::AnalysisUsage
Represent the analysis usage information of a pass.
Definition: PassAnalysisSupport.h:47
llvm::MachineFunction::getProperties
const MachineFunctionProperties & getProperties() const
Get the function properties.
Definition: MachineFunction.h:747
llvm::MachineFunctionProperties::set
MachineFunctionProperties & set(Property P)
Definition: MachineFunction.h:196
llvm::MachineModuleInfo
This class contains meta information specific to a module.
Definition: MachineModuleInfo.h:75
llvm::DominatorTreeWrapperPass
Legacy analysis pass which computes a DominatorTree.
Definition: Dominators.h:302
llvm::MachineOptimizationRemarkAnalysis
Diagnostic information for optimization analysis remarks.
Definition: MachineOptimizationRemarkEmitter.h:109
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:54
llvm::ScalarEvolutionWrapperPass
Definition: ScalarEvolution.h:2145
llvm::createMachineFunctionPrinterPass
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...
LoopInfo.h
MachineOptimizationRemarkEmitter.h
===- MachineOptimizationRemarkEmitter.h - Opt Diagnostics -*- C++ -*-—===//
Passes.h
llvm::RISCVFenceField::O
@ O
Definition: RISCVBaseInfo.h:239
llvm::SCEVAAWrapperPass
Legacy wrapper pass to provide the SCEVAAResult object.
Definition: ScalarEvolutionAliasAnalysis.h:56
llvm::MachineModuleInfoWrapperPass
Definition: MachineModuleInfo.h:215
llvm::BasicAAWrapperPass
Legacy wrapper pass to provide the BasicAAResult object.
Definition: BasicAliasAnalysis.h:173
MachineFunctionPass.h
MachineModuleInfo.h
llvm::MachineFunction
Definition: MachineFunction.h:257
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:143
llvm::AnalysisUsage::addPreserved
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
Definition: PassAnalysisSupport.h:98
llvm::IVUsersWrapperPass
Definition: IVUsers.h:161
llvm::MachineModuleInfo::getOrCreateMachineFunction
MachineFunction & getOrCreateMachineFunction(Function &F)
Returns the MachineFunction constructed for the IR function F.
Definition: MachineModuleInfo.cpp:108
llvm::MachineFunctionProperties::reset
MachineFunctionProperties & reset(Property P)
Definition: MachineFunction.h:201
MORE
#define MORE()
Definition: regcomp.c:252
runOnFunction
static bool runOnFunction(Function &F, bool PostInlining)
Definition: EntryExitInstrumenter.cpp:69
llvm::MachineFunction::getFunction
Function & getFunction()
Return the LLVM function that this machine code represents.
Definition: MachineFunction.h:622
llvm::MemoryDependenceWrapperPass
A wrapper analysis pass for the legacy pass manager that exposes a MemoryDepnedenceResults instance.
Definition: MemoryDependenceAnalysis.h:526
Function.h
ScalarEvolutionAliasAnalysis.h
llvm::Pass
Pass interface - Implemented by all 'passes'.
Definition: Pass.h:91
IVUsers.h
Dominators.h
llvm::AAResultsWrapperPass
A wrapper pass to provide the legacy pass manager access to a suitably prepared AAResults object.
Definition: AliasAnalysis.h:1351
llvm::GlobalsAAWrapperPass
Legacy wrapper pass to provide the GlobalsAAResult object.
Definition: GlobalsModRef.h:148
llvm::Pass::getAnalysisUsage
virtual void getAnalysisUsage(AnalysisUsage &) const
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Definition: Pass.cpp:97
llvm::AnalysisUsage::addRequired
AnalysisUsage & addRequired()
Definition: PassAnalysisSupport.h:75
llvm::DominanceFrontierWrapperPass
Definition: DominanceFrontier.h:155
MachineFunction.h