LLVM API Documentation
00001 //===-- MachineFunctionAnalysis.cpp ---------------------------------------===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file contains the definitions of the MachineFunctionAnalysis members. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #include "llvm/CodeGen/MachineFunctionAnalysis.h" 00015 #include "llvm/CodeGen/GCMetadata.h" 00016 #include "llvm/CodeGen/MachineFunction.h" 00017 #include "llvm/CodeGen/MachineModuleInfo.h" 00018 using namespace llvm; 00019 00020 char MachineFunctionAnalysis::ID = 0; 00021 00022 MachineFunctionAnalysis::MachineFunctionAnalysis(const TargetMachine &tm) : 00023 FunctionPass(ID), TM(tm), MF(nullptr) { 00024 initializeMachineModuleInfoPass(*PassRegistry::getPassRegistry()); 00025 } 00026 00027 MachineFunctionAnalysis::~MachineFunctionAnalysis() { 00028 releaseMemory(); 00029 assert(!MF && "MachineFunctionAnalysis left initialized!"); 00030 } 00031 00032 void MachineFunctionAnalysis::getAnalysisUsage(AnalysisUsage &AU) const { 00033 AU.setPreservesAll(); 00034 AU.addRequired<MachineModuleInfo>(); 00035 } 00036 00037 bool MachineFunctionAnalysis::doInitialization(Module &M) { 00038 MachineModuleInfo *MMI = getAnalysisIfAvailable<MachineModuleInfo>(); 00039 assert(MMI && "MMI not around yet??"); 00040 MMI->setModule(&M); 00041 NextFnNum = 0; 00042 return false; 00043 } 00044 00045 00046 bool MachineFunctionAnalysis::runOnFunction(Function &F) { 00047 assert(!MF && "MachineFunctionAnalysis already initialized!"); 00048 MF = new MachineFunction(&F, TM, NextFnNum++, 00049 getAnalysis<MachineModuleInfo>(), 00050 getAnalysisIfAvailable<GCModuleInfo>()); 00051 return false; 00052 } 00053 00054 void MachineFunctionAnalysis::releaseMemory() { 00055 delete MF; 00056 MF = nullptr; 00057 }