LLVM  14.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"
25 #include "llvm/CodeGen/Passes.h"
26 #include "llvm/IR/Dominators.h"
27 #include "llvm/IR/Function.h"
28 
29 using namespace llvm;
30 using namespace ore;
31 
32 Pass *MachineFunctionPass::createPrinterPass(raw_ostream &O,
33  const std::string &Banner) const {
34  return createMachineFunctionPrinterPass(O, Banner);
35 }
36 
38  // Do not codegen any 'available_externally' functions at all, they have
39  // definitions outside the translation unit.
40  if (F.hasAvailableExternallyLinkage())
41  return false;
42 
43  MachineModuleInfo &MMI = getAnalysis<MachineModuleInfoWrapperPass>().getMMI();
45 
47 
48 #ifndef NDEBUG
49  if (!MFProps.verifyRequiredProperties(RequiredProperties)) {
50  errs() << "MachineFunctionProperties required by " << getPassName()
51  << " pass are not met by function " << F.getName() << ".\n"
52  << "Required properties: ";
53  RequiredProperties.print(errs());
54  errs() << "\nCurrent properties: ";
55  MFProps.print(errs());
56  errs() << "\n";
57  llvm_unreachable("MachineFunctionProperties check failed");
58  }
59 #endif
60  // Collect the MI count of the function before the pass.
61  unsigned CountBefore, CountAfter;
62 
63  // Check if the user asked for size remarks.
64  bool ShouldEmitSizeRemarks =
65  F.getParent()->shouldEmitInstrCountChangedRemark();
66 
67  // If we want size remarks, collect the number of MachineInstrs in our
68  // MachineFunction before the pass runs.
69  if (ShouldEmitSizeRemarks)
70  CountBefore = MF.getInstructionCount();
71 
72  bool RV = runOnMachineFunction(MF);
73 
74  if (ShouldEmitSizeRemarks) {
75  // We wanted size remarks. Check if there was a change to the number of
76  // MachineInstrs in the module. Emit a remark if there was a change.
77  CountAfter = MF.getInstructionCount();
78  if (CountBefore != CountAfter) {
80  MORE.emit([&]() {
81  int64_t Delta = static_cast<int64_t>(CountAfter) -
82  static_cast<int64_t>(CountBefore);
83  MachineOptimizationRemarkAnalysis R("size-info", "FunctionMISizeChange",
85  &MF.front());
86  R << NV("Pass", getPassName())
87  << ": Function: " << NV("Function", F.getName()) << ": "
88  << "MI Instruction count changed from "
89  << NV("MIInstrsBefore", CountBefore) << " to "
90  << NV("MIInstrsAfter", CountAfter)
91  << "; Delta: " << NV("Delta", Delta);
92  return R;
93  });
94  }
95  }
96 
97  MFProps.set(SetProperties);
98  MFProps.reset(ClearedProperties);
99  return RV;
100 }
101 
105 
106  // MachineFunctionPass preserves all LLVM IR passes, but there's no
107  // high-level way to express this. Instead, just list a bunch of
108  // passes explicitly. This does not include setPreservesCFG,
109  // because CodeGen overloads that to mean preserving the MachineBasicBlock
110  // CFG in addition to the LLVM IR CFG.
121 
123 }
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
DominanceFrontier.h
llvm::MachineFunctionProperties::print
void print(raw_ostream &OS) const
Print the MachineFunctionProperties in human-readable form.
Definition: MachineFunction.cpp:110
llvm::Function
Definition: Function.h:62
llvm::Function::getSubprogram
DISubprogram * getSubprogram() const
Get the attached subprogram.
Definition: Metadata.cpp:1541
llvm::MachineOptimizationRemarkEmitter
The optimization diagnostic interface.
Definition: MachineOptimizationRemarkEmitter.h:150
GlobalsModRef.h
ScalarEvolution.h
llvm::MachineFunction::getInstructionCount
unsigned getInstructionCount() const
Return the number of MachineInstrs in this MachineFunction.
Definition: MachineFunction.h:855
llvm::LoopInfoWrapperPass
The legacy pass manager's analysis pass to compute loop information.
Definition: LoopInfo.h:1268
llvm::MachineFunctionProperties
Properties which a MachineFunction may have at a given point in time.
Definition: MachineFunction.h:111
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:102
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::RISCVFenceField::R
@ R
Definition: RISCVBaseInfo.h:198
llvm::MachineFunction::front
const MachineBasicBlock & front() const
Definition: MachineFunction.h:824
llvm::MachineFunctionProperties::verifyRequiredProperties
bool verifyRequiredProperties(const MachineFunctionProperties &V) const
Definition: MachineFunction.h:201
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:721
llvm::MachineFunctionProperties::set
MachineFunctionProperties & set(Property P)
Definition: MachineFunction.h:173
llvm::MachineModuleInfo
This class contains meta information specific to a module.
Definition: MachineModuleInfo.h:78
llvm::DominatorTreeWrapperPass
Legacy analysis pass which computes a DominatorTree.
Definition: Dominators.h:287
llvm::MachineOptimizationRemarkAnalysis
Diagnostic information for optimization analysis remarks.
Definition: MachineOptimizationRemarkEmitter.h:108
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::ScalarEvolutionWrapperPass
Definition: ScalarEvolution.h:2084
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:197
llvm::SCEVAAWrapperPass
Legacy wrapper pass to provide the SCEVAAResult object.
Definition: ScalarEvolutionAliasAnalysis.h:55
llvm::MachineModuleInfoWrapperPass
Definition: MachineModuleInfo.h:279
llvm::BasicAAWrapperPass
Legacy wrapper pass to provide the BasicAAResult object.
Definition: BasicAliasAnalysis.h:176
MachineFunctionPass.h
MachineModuleInfo.h
llvm::MachineFunction
Definition: MachineFunction.h:234
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:134
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:164
llvm::MachineModuleInfo::getOrCreateMachineFunction
MachineFunction & getOrCreateMachineFunction(Function &F)
Returns the MachineFunction constructed for the IR function F.
Definition: MachineModuleInfo.cpp:291
llvm::MachineFunctionProperties::reset
MachineFunctionProperties & reset(Property P)
Definition: MachineFunction.h:178
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:596
llvm::MemoryDependenceWrapperPass
A wrapper analysis pass for the legacy pass manager that exposes a MemoryDepnedenceResults instance.
Definition: MemoryDependenceAnalysis.h:525
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:1336
llvm::GlobalsAAWrapperPass
Legacy wrapper pass to provide the GlobalsAAResult object.
Definition: GlobalsModRef.h:143
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:93
llvm::AnalysisUsage::addRequired
AnalysisUsage & addRequired()
Definition: PassAnalysisSupport.h:75
llvm::DominanceFrontierWrapperPass
Definition: DominanceFrontier.h:155
MachineFunction.h