xref: /aosp_15_r20/external/llvm/lib/CodeGen/MachineFunctionPass.cpp (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker //===-- MachineFunctionPass.cpp -------------------------------------------===//
2*9880d681SAndroid Build Coastguard Worker //
3*9880d681SAndroid Build Coastguard Worker //                     The LLVM Compiler Infrastructure
4*9880d681SAndroid Build Coastguard Worker //
5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source
6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details.
7*9880d681SAndroid Build Coastguard Worker //
8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
9*9880d681SAndroid Build Coastguard Worker //
10*9880d681SAndroid Build Coastguard Worker // This file contains the definitions of the MachineFunctionPass members.
11*9880d681SAndroid Build Coastguard Worker //
12*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
13*9880d681SAndroid Build Coastguard Worker 
14*9880d681SAndroid Build Coastguard Worker #include "llvm/CodeGen/MachineFunctionPass.h"
15*9880d681SAndroid Build Coastguard Worker #include "llvm/Analysis/AliasAnalysis.h"
16*9880d681SAndroid Build Coastguard Worker #include "llvm/Analysis/BasicAliasAnalysis.h"
17*9880d681SAndroid Build Coastguard Worker #include "llvm/Analysis/DominanceFrontier.h"
18*9880d681SAndroid Build Coastguard Worker #include "llvm/Analysis/GlobalsModRef.h"
19*9880d681SAndroid Build Coastguard Worker #include "llvm/Analysis/IVUsers.h"
20*9880d681SAndroid Build Coastguard Worker #include "llvm/Analysis/LoopInfo.h"
21*9880d681SAndroid Build Coastguard Worker #include "llvm/Analysis/MemoryDependenceAnalysis.h"
22*9880d681SAndroid Build Coastguard Worker #include "llvm/Analysis/ScalarEvolution.h"
23*9880d681SAndroid Build Coastguard Worker #include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h"
24*9880d681SAndroid Build Coastguard Worker #include "llvm/CodeGen/MachineFunction.h"
25*9880d681SAndroid Build Coastguard Worker #include "llvm/CodeGen/MachineFunctionAnalysis.h"
26*9880d681SAndroid Build Coastguard Worker #include "llvm/CodeGen/Passes.h"
27*9880d681SAndroid Build Coastguard Worker #include "llvm/CodeGen/StackProtector.h"
28*9880d681SAndroid Build Coastguard Worker #include "llvm/IR/Dominators.h"
29*9880d681SAndroid Build Coastguard Worker #include "llvm/IR/Function.h"
30*9880d681SAndroid Build Coastguard Worker 
31*9880d681SAndroid Build Coastguard Worker using namespace llvm;
32*9880d681SAndroid Build Coastguard Worker 
createPrinterPass(raw_ostream & O,const std::string & Banner) const33*9880d681SAndroid Build Coastguard Worker Pass *MachineFunctionPass::createPrinterPass(raw_ostream &O,
34*9880d681SAndroid Build Coastguard Worker                                              const std::string &Banner) const {
35*9880d681SAndroid Build Coastguard Worker   return createMachineFunctionPrinterPass(O, Banner);
36*9880d681SAndroid Build Coastguard Worker }
37*9880d681SAndroid Build Coastguard Worker 
runOnFunction(Function & F)38*9880d681SAndroid Build Coastguard Worker bool MachineFunctionPass::runOnFunction(Function &F) {
39*9880d681SAndroid Build Coastguard Worker   // Do not codegen any 'available_externally' functions at all, they have
40*9880d681SAndroid Build Coastguard Worker   // definitions outside the translation unit.
41*9880d681SAndroid Build Coastguard Worker   if (F.hasAvailableExternallyLinkage())
42*9880d681SAndroid Build Coastguard Worker     return false;
43*9880d681SAndroid Build Coastguard Worker 
44*9880d681SAndroid Build Coastguard Worker   MachineFunction &MF = getAnalysis<MachineFunctionAnalysis>().getMF();
45*9880d681SAndroid Build Coastguard Worker   MachineFunctionProperties &MFProps = MF.getProperties();
46*9880d681SAndroid Build Coastguard Worker 
47*9880d681SAndroid Build Coastguard Worker #ifndef NDEBUG
48*9880d681SAndroid Build Coastguard Worker   if (!MFProps.verifyRequiredProperties(RequiredProperties)) {
49*9880d681SAndroid Build Coastguard Worker     errs() << "MachineFunctionProperties required by " << getPassName()
50*9880d681SAndroid Build Coastguard Worker            << " pass are not met by function " << F.getName() << ".\n"
51*9880d681SAndroid Build Coastguard Worker            << "Required properties: ";
52*9880d681SAndroid Build Coastguard Worker     RequiredProperties.print(errs(), /*OnlySet=*/true);
53*9880d681SAndroid Build Coastguard Worker     errs() << "\nCurrent properties: ";
54*9880d681SAndroid Build Coastguard Worker     MFProps.print(errs());
55*9880d681SAndroid Build Coastguard Worker     errs() << "\n";
56*9880d681SAndroid Build Coastguard Worker     llvm_unreachable("MachineFunctionProperties check failed");
57*9880d681SAndroid Build Coastguard Worker   }
58*9880d681SAndroid Build Coastguard Worker #endif
59*9880d681SAndroid Build Coastguard Worker 
60*9880d681SAndroid Build Coastguard Worker   bool RV = runOnMachineFunction(MF);
61*9880d681SAndroid Build Coastguard Worker 
62*9880d681SAndroid Build Coastguard Worker   MFProps.set(SetProperties);
63*9880d681SAndroid Build Coastguard Worker   MFProps.clear(ClearedProperties);
64*9880d681SAndroid Build Coastguard Worker   return RV;
65*9880d681SAndroid Build Coastguard Worker }
66*9880d681SAndroid Build Coastguard Worker 
getAnalysisUsage(AnalysisUsage & AU) const67*9880d681SAndroid Build Coastguard Worker void MachineFunctionPass::getAnalysisUsage(AnalysisUsage &AU) const {
68*9880d681SAndroid Build Coastguard Worker   AU.addRequired<MachineFunctionAnalysis>();
69*9880d681SAndroid Build Coastguard Worker   AU.addPreserved<MachineFunctionAnalysis>();
70*9880d681SAndroid Build Coastguard Worker 
71*9880d681SAndroid Build Coastguard Worker   // MachineFunctionPass preserves all LLVM IR passes, but there's no
72*9880d681SAndroid Build Coastguard Worker   // high-level way to express this. Instead, just list a bunch of
73*9880d681SAndroid Build Coastguard Worker   // passes explicitly. This does not include setPreservesCFG,
74*9880d681SAndroid Build Coastguard Worker   // because CodeGen overloads that to mean preserving the MachineBasicBlock
75*9880d681SAndroid Build Coastguard Worker   // CFG in addition to the LLVM IR CFG.
76*9880d681SAndroid Build Coastguard Worker   AU.addPreserved<BasicAAWrapperPass>();
77*9880d681SAndroid Build Coastguard Worker   AU.addPreserved<DominanceFrontierWrapperPass>();
78*9880d681SAndroid Build Coastguard Worker   AU.addPreserved<DominatorTreeWrapperPass>();
79*9880d681SAndroid Build Coastguard Worker   AU.addPreserved<AAResultsWrapperPass>();
80*9880d681SAndroid Build Coastguard Worker   AU.addPreserved<GlobalsAAWrapperPass>();
81*9880d681SAndroid Build Coastguard Worker   AU.addPreserved<IVUsers>();
82*9880d681SAndroid Build Coastguard Worker   AU.addPreserved<LoopInfoWrapperPass>();
83*9880d681SAndroid Build Coastguard Worker   AU.addPreserved<MemoryDependenceWrapperPass>();
84*9880d681SAndroid Build Coastguard Worker   AU.addPreserved<ScalarEvolutionWrapperPass>();
85*9880d681SAndroid Build Coastguard Worker   AU.addPreserved<SCEVAAWrapperPass>();
86*9880d681SAndroid Build Coastguard Worker   AU.addPreserved<StackProtector>();
87*9880d681SAndroid Build Coastguard Worker 
88*9880d681SAndroid Build Coastguard Worker   FunctionPass::getAnalysisUsage(AU);
89*9880d681SAndroid Build Coastguard Worker }
90