Dan Gohman | ad2afc2 | 2009-07-31 18:16:33 +0000 | [diff] [blame] | 1 | //===-- MachineFunctionAnalysis.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 MachineFunctionAnalysis members. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "llvm/CodeGen/MachineFunctionAnalysis.h" |
| 15 | #include "llvm/CodeGen/MachineFunction.h" |
Chris Lattner | 11d53c1 | 2010-03-13 20:55:24 +0000 | [diff] [blame] | 16 | #include "llvm/CodeGen/MachineModuleInfo.h" |
Dan Gohman | ad2afc2 | 2009-07-31 18:16:33 +0000 | [diff] [blame] | 17 | using namespace llvm; |
| 18 | |
| 19 | // Register this pass with PassInfo directly to avoid having to define |
| 20 | // a default constructor. |
| 21 | static PassInfo |
| 22 | X("Machine Function Analysis", "machine-function-analysis", |
| 23 | intptr_t(&MachineFunctionAnalysis::ID), 0, |
| 24 | /*CFGOnly=*/false, /*is_analysis=*/true); |
| 25 | |
| 26 | char MachineFunctionAnalysis::ID = 0; |
| 27 | |
Dan Gohman | 28a4c78 | 2009-11-09 18:18:49 +0000 | [diff] [blame] | 28 | MachineFunctionAnalysis::MachineFunctionAnalysis(const TargetMachine &tm, |
Dan Gohman | ad2afc2 | 2009-07-31 18:16:33 +0000 | [diff] [blame] | 29 | CodeGenOpt::Level OL) : |
| 30 | FunctionPass(&ID), TM(tm), OptLevel(OL), MF(0) { |
| 31 | } |
| 32 | |
Dan Gohman | f940833 | 2009-08-01 04:19:43 +0000 | [diff] [blame] | 33 | MachineFunctionAnalysis::~MachineFunctionAnalysis() { |
Chris Lattner | f5e1613 | 2009-10-12 04:22:44 +0000 | [diff] [blame] | 34 | releaseMemory(); |
Dan Gohman | f940833 | 2009-08-01 04:19:43 +0000 | [diff] [blame] | 35 | assert(!MF && "MachineFunctionAnalysis left initialized!"); |
| 36 | } |
| 37 | |
Chris Lattner | 421ccd9 | 2010-04-06 00:51:52 +0000 | [diff] [blame] | 38 | void MachineFunctionAnalysis::getAnalysisUsage(AnalysisUsage &AU) const { |
| 39 | AU.setPreservesAll(); |
| 40 | AU.addRequired<MachineModuleInfo>(); |
| 41 | } |
| 42 | |
| 43 | bool MachineFunctionAnalysis::doInitialization(Module &M) { |
| 44 | MachineModuleInfo *MMI = getAnalysisIfAvailable<MachineModuleInfo>(); |
| 45 | assert(MMI && "MMI not around yet??"); |
| 46 | MMI->setModule(&M); |
Dan Gohman | 9f23dee | 2010-04-17 16:29:15 +0000 | [diff] [blame] | 47 | NextFnNum = 0; |
| 48 | return false; |
Chris Lattner | 421ccd9 | 2010-04-06 00:51:52 +0000 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | |
Dan Gohman | ad2afc2 | 2009-07-31 18:16:33 +0000 | [diff] [blame] | 52 | bool MachineFunctionAnalysis::runOnFunction(Function &F) { |
| 53 | assert(!MF && "MachineFunctionAnalysis already initialized!"); |
Chris Lattner | 11d53c1 | 2010-03-13 20:55:24 +0000 | [diff] [blame] | 54 | MF = new MachineFunction(&F, TM, NextFnNum++, |
Chris Lattner | 820e55e | 2010-04-05 05:49:50 +0000 | [diff] [blame] | 55 | getAnalysis<MachineModuleInfo>()); |
Dan Gohman | ad2afc2 | 2009-07-31 18:16:33 +0000 | [diff] [blame] | 56 | return false; |
| 57 | } |
| 58 | |
| 59 | void MachineFunctionAnalysis::releaseMemory() { |
| 60 | delete MF; |
| 61 | MF = 0; |
| 62 | } |