Dan Gohman | ad2afc2 | 2009-07-31 18:16:33 +0000 | [diff] [blame] | 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 | |
Dan Gohman | ad2afc2 | 2009-07-31 18:16:33 +0000 | [diff] [blame] | 14 | #include "llvm/CodeGen/MachineFunctionPass.h" |
Stephen Hines | ebe69fe | 2015-03-23 12:10:34 -0700 | [diff] [blame^] | 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" |
David Greene | 5c8aa95 | 2010-04-02 23:17:14 +0000 | [diff] [blame] | 22 | #include "llvm/CodeGen/Passes.h" |
Stephen Hines | ebe69fe | 2015-03-23 12:10:34 -0700 | [diff] [blame^] | 23 | #include "llvm/CodeGen/StackProtector.h" |
| 24 | #include "llvm/IR/Dominators.h" |
| 25 | #include "llvm/IR/Function.h" |
Dan Gohman | ad2afc2 | 2009-07-31 18:16:33 +0000 | [diff] [blame] | 26 | using namespace llvm; |
| 27 | |
David Greene | 5c8aa95 | 2010-04-02 23:17:14 +0000 | [diff] [blame] | 28 | Pass *MachineFunctionPass::createPrinterPass(raw_ostream &O, |
| 29 | const std::string &Banner) const { |
| 30 | return createMachineFunctionPrinterPass(O, Banner); |
| 31 | } |
| 32 | |
Dan Gohman | ad2afc2 | 2009-07-31 18:16:33 +0000 | [diff] [blame] | 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 | |
| 43 | 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 |
Dan Gohman | 8a261e4 | 2009-10-08 17:00:02 +0000 | [diff] [blame] | 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. |
Dan Gohman | ad2afc2 | 2009-07-31 18:16:33 +0000 | [diff] [blame] | 52 | AU.addPreserved<AliasAnalysis>(); |
Stephen Hines | ebe69fe | 2015-03-23 12:10:34 -0700 | [diff] [blame^] | 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>(); |
Dan Gohman | ad2afc2 | 2009-07-31 18:16:33 +0000 | [diff] [blame] | 60 | |
| 61 | FunctionPass::getAnalysisUsage(AU); |
| 62 | } |