07a0f45c0f481aa31c13a7b2f7feada680ed5150
[oota-llvm.git] / lib / CodeGen / MachineFunctionAnalysis.cpp
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"
16 #include "llvm/CodeGen/MachineModuleInfo.h"
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
28 MachineFunctionAnalysis::MachineFunctionAnalysis(const TargetMachine &tm,
29                                                  CodeGenOpt::Level OL) :
30   FunctionPass(&ID), TM(tm), OptLevel(OL), MF(0) {
31 }
32
33 MachineFunctionAnalysis::~MachineFunctionAnalysis() {
34   releaseMemory();
35   assert(!MF && "MachineFunctionAnalysis left initialized!");
36 }
37
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);
47   NextFnNum = 0;
48   return false;
49 }
50
51
52 bool MachineFunctionAnalysis::runOnFunction(Function &F) {
53   assert(!MF && "MachineFunctionAnalysis already initialized!");
54   MF = new MachineFunction(&F, TM, NextFnNum++,
55                            getAnalysis<MachineModuleInfo>());
56   return false;
57 }
58
59 void MachineFunctionAnalysis::releaseMemory() {
60   delete MF;
61   MF = 0;
62 }