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/MachineModuleInfo.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 createPrinterPass(raw_ostream & O,const std::string & Banner) const32Pass *MachineFunctionPass::createPrinterPass(raw_ostream &O, 33 const std::string &Banner) const { 34 return createMachineFunctionPrinterPass(O, Banner); 35 } 36 runOnFunction(Function & F)37bool MachineFunctionPass::runOnFunction(Function &F) { 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<MachineModuleInfo>(); 44 MachineFunction &MF = MMI.getOrCreateMachineFunction(F); 45 46 MachineFunctionProperties &MFProps = MF.getProperties(); 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 61 bool RV = runOnMachineFunction(MF); 62 63 MFProps.set(SetProperties); 64 MFProps.reset(ClearedProperties); 65 return RV; 66 } 67 getAnalysisUsage(AnalysisUsage & AU) const68void MachineFunctionPass::getAnalysisUsage(AnalysisUsage &AU) const { 69 AU.addRequired<MachineModuleInfo>(); 70 AU.addPreserved<MachineModuleInfo>(); 71 72 // MachineFunctionPass preserves all LLVM IR passes, but there's no 73 // high-level way to express this. Instead, just list a bunch of 74 // passes explicitly. This does not include setPreservesCFG, 75 // because CodeGen overloads that to mean preserving the MachineBasicBlock 76 // CFG in addition to the LLVM IR CFG. 77 AU.addPreserved<BasicAAWrapperPass>(); 78 AU.addPreserved<DominanceFrontierWrapperPass>(); 79 AU.addPreserved<DominatorTreeWrapperPass>(); 80 AU.addPreserved<AAResultsWrapperPass>(); 81 AU.addPreserved<GlobalsAAWrapperPass>(); 82 AU.addPreserved<IVUsersWrapperPass>(); 83 AU.addPreserved<LoopInfoWrapperPass>(); 84 AU.addPreserved<MemoryDependenceWrapperPass>(); 85 AU.addPreserved<ScalarEvolutionWrapperPass>(); 86 AU.addPreserved<SCEVAAWrapperPass>(); 87 88 FunctionPass::getAnalysisUsage(AU); 89 } 90