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/MachineFunctionAnalysis.h" 25 #include "llvm/CodeGen/Passes.h" 26 #include "llvm/CodeGen/StackProtector.h" 27 #include "llvm/IR/Dominators.h" 28 #include "llvm/IR/Function.h" 29 using namespace llvm; 30 31 Pass *MachineFunctionPass::createPrinterPass(raw_ostream &O, 32 const std::string &Banner) const { 33 return createMachineFunctionPrinterPass(O, Banner); 34 } 35 36 bool MachineFunctionPass::runOnFunction(Function &F) { 37 // Do not codegen any 'available_externally' functions at all, they have 38 // definitions outside the translation unit. 39 if (F.hasAvailableExternallyLinkage()) 40 return false; 41 42 MachineFunction &MF = getAnalysis<MachineFunctionAnalysis>().getMF(); 43 return runOnMachineFunction(MF); 44 } 45 46 void MachineFunctionPass::getAnalysisUsage(AnalysisUsage &AU) const { 47 AU.addRequired<MachineFunctionAnalysis>(); 48 AU.addPreserved<MachineFunctionAnalysis>(); 49 50 // MachineFunctionPass preserves all LLVM IR passes, but there's no 51 // high-level way to express this. Instead, just list a bunch of 52 // passes explicitly. This does not include setPreservesCFG, 53 // because CodeGen overloads that to mean preserving the MachineBasicBlock 54 // CFG in addition to the LLVM IR CFG. 55 AU.addPreserved<BasicAAWrapperPass>(); 56 AU.addPreserved<DominanceFrontier>(); 57 AU.addPreserved<DominatorTreeWrapperPass>(); 58 AU.addPreserved<AAResultsWrapperPass>(); 59 AU.addPreserved<GlobalsAAWrapperPass>(); 60 AU.addPreserved<IVUsers>(); 61 AU.addPreserved<LoopInfoWrapperPass>(); 62 AU.addPreserved<MemoryDependenceAnalysis>(); 63 AU.addPreserved<ScalarEvolutionWrapperPass>(); 64 AU.addPreserved<SCEVAAWrapperPass>(); 65 AU.addPreserved<StackProtector>(); 66 67 FunctionPass::getAnalysisUsage(AU); 68 } 69