1 //===-- MachineFunctionPass.cpp -------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This file contains the definitions of the MachineFunctionPass members. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #include "llvm/CodeGen/MachineFunctionPass.h" 15 #include "llvm/Analysis/AliasAnalysis.h" 16 #include "llvm/Analysis/BasicAliasAnalysis.h" 17 #include "llvm/Analysis/DominanceFrontier.h" 18 #include "llvm/Analysis/GlobalsModRef.h" 19 #include "llvm/Analysis/IVUsers.h" 20 #include "llvm/Analysis/LoopInfo.h" 21 #include "llvm/Analysis/MemoryDependenceAnalysis.h" 22 #include "llvm/Analysis/ScalarEvolution.h" 23 #include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h" 24 #include "llvm/CodeGen/MachineFunction.h" 25 #include "llvm/CodeGen/MachineFunctionAnalysis.h" 26 #include "llvm/CodeGen/Passes.h" 27 #include "llvm/CodeGen/StackProtector.h" 28 #include "llvm/IR/Dominators.h" 29 #include "llvm/IR/Function.h" 30 31 using namespace llvm; 32 33 Pass *MachineFunctionPass::createPrinterPass(raw_ostream &O, 34 const std::string &Banner) const { 35 return createMachineFunctionPrinterPass(O, Banner); 36 } 37 38 bool MachineFunctionPass::runOnFunction(Function &F) { 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 MachineFunction &MF = getAnalysis<MachineFunctionAnalysis>().getMF(); 45 MachineFunctionProperties &MFProps = MF.getProperties(); 46 47 assert(MFProps.verifyRequiredProperties(RequiredProperties) && 48 "Properties required by the pass are not met by the function"); 49 50 bool RV = runOnMachineFunction(MF); 51 52 MFProps.set(SetProperties); 53 MFProps.clear(ClearedProperties); 54 return RV; 55 } 56 57 void MachineFunctionPass::getAnalysisUsage(AnalysisUsage &AU) const { 58 AU.addRequired<MachineFunctionAnalysis>(); 59 AU.addPreserved<MachineFunctionAnalysis>(); 60 61 // MachineFunctionPass preserves all LLVM IR passes, but there's no 62 // high-level way to express this. Instead, just list a bunch of 63 // passes explicitly. This does not include setPreservesCFG, 64 // because CodeGen overloads that to mean preserving the MachineBasicBlock 65 // CFG in addition to the LLVM IR CFG. 66 AU.addPreserved<BasicAAWrapperPass>(); 67 AU.addPreserved<DominanceFrontierWrapperPass>(); 68 AU.addPreserved<DominatorTreeWrapperPass>(); 69 AU.addPreserved<AAResultsWrapperPass>(); 70 AU.addPreserved<GlobalsAAWrapperPass>(); 71 AU.addPreserved<IVUsers>(); 72 AU.addPreserved<LoopInfoWrapperPass>(); 73 AU.addPreserved<MemoryDependenceWrapperPass>(); 74 AU.addPreserved<ScalarEvolutionWrapperPass>(); 75 AU.addPreserved<SCEVAAWrapperPass>(); 76 AU.addPreserved<StackProtector>(); 77 78 FunctionPass::getAnalysisUsage(AU); 79 } 80