Home | History | Annotate | Download | only in CodeGen
      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/GCMetadata.h"
     16 #include "llvm/CodeGen/MachineFunction.h"
     17 #include "llvm/CodeGen/MachineModuleInfo.h"
     18 using namespace llvm;
     19 
     20 char MachineFunctionAnalysis::ID = 0;
     21 
     22 MachineFunctionAnalysis::MachineFunctionAnalysis(const TargetMachine &tm,
     23                                                  CodeGenOpt::Level OL) :
     24   FunctionPass(ID), TM(tm), OptLevel(OL), MF(0) {
     25   initializeMachineModuleInfoPass(*PassRegistry::getPassRegistry());
     26 }
     27 
     28 MachineFunctionAnalysis::~MachineFunctionAnalysis() {
     29   releaseMemory();
     30   assert(!MF && "MachineFunctionAnalysis left initialized!");
     31 }
     32 
     33 void MachineFunctionAnalysis::getAnalysisUsage(AnalysisUsage &AU) const {
     34   AU.setPreservesAll();
     35   AU.addRequired<MachineModuleInfo>();
     36 }
     37 
     38 bool MachineFunctionAnalysis::doInitialization(Module &M) {
     39   MachineModuleInfo *MMI = getAnalysisIfAvailable<MachineModuleInfo>();
     40   assert(MMI && "MMI not around yet??");
     41   MMI->setModule(&M);
     42   NextFnNum = 0;
     43   return false;
     44 }
     45 
     46 
     47 bool MachineFunctionAnalysis::runOnFunction(Function &F) {
     48   assert(!MF && "MachineFunctionAnalysis already initialized!");
     49   MF = new MachineFunction(&F, TM, NextFnNum++,
     50                            getAnalysis<MachineModuleInfo>(),
     51                            getAnalysisIfAvailable<GCModuleInfo>());
     52   return false;
     53 }
     54 
     55 void MachineFunctionAnalysis::releaseMemory() {
     56   delete MF;
     57   MF = 0;
     58 }
     59