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