1f4a2713aSLionel Sambuc //===-- MachineFunctionAnalysis.cpp ---------------------------------------===// 2f4a2713aSLionel Sambuc // 3f4a2713aSLionel Sambuc // The LLVM Compiler Infrastructure 4f4a2713aSLionel Sambuc // 5f4a2713aSLionel Sambuc // This file is distributed under the University of Illinois Open Source 6f4a2713aSLionel Sambuc // License. See LICENSE.TXT for details. 7f4a2713aSLionel Sambuc // 8f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===// 9f4a2713aSLionel Sambuc // 10f4a2713aSLionel Sambuc // This file contains the definitions of the MachineFunctionAnalysis members. 11f4a2713aSLionel Sambuc // 12f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===// 13f4a2713aSLionel Sambuc 14f4a2713aSLionel Sambuc #include "llvm/CodeGen/MachineFunctionAnalysis.h" 15f4a2713aSLionel Sambuc #include "llvm/CodeGen/GCMetadata.h" 16f4a2713aSLionel Sambuc #include "llvm/CodeGen/MachineFunction.h" 17f4a2713aSLionel Sambuc #include "llvm/CodeGen/MachineModuleInfo.h" 18f4a2713aSLionel Sambuc using namespace llvm; 19f4a2713aSLionel Sambuc 20f4a2713aSLionel Sambuc char MachineFunctionAnalysis::ID = 0; 21f4a2713aSLionel Sambuc MachineFunctionAnalysis(const TargetMachine & tm)22f4a2713aSLionel SambucMachineFunctionAnalysis::MachineFunctionAnalysis(const TargetMachine &tm) : 23*0a6a1f1dSLionel Sambuc FunctionPass(ID), TM(tm), MF(nullptr) { 24f4a2713aSLionel Sambuc initializeMachineModuleInfoPass(*PassRegistry::getPassRegistry()); 25f4a2713aSLionel Sambuc } 26f4a2713aSLionel Sambuc ~MachineFunctionAnalysis()27f4a2713aSLionel SambucMachineFunctionAnalysis::~MachineFunctionAnalysis() { 28f4a2713aSLionel Sambuc releaseMemory(); 29f4a2713aSLionel Sambuc assert(!MF && "MachineFunctionAnalysis left initialized!"); 30f4a2713aSLionel Sambuc } 31f4a2713aSLionel Sambuc getAnalysisUsage(AnalysisUsage & AU) const32f4a2713aSLionel Sambucvoid MachineFunctionAnalysis::getAnalysisUsage(AnalysisUsage &AU) const { 33f4a2713aSLionel Sambuc AU.setPreservesAll(); 34f4a2713aSLionel Sambuc AU.addRequired<MachineModuleInfo>(); 35f4a2713aSLionel Sambuc } 36f4a2713aSLionel Sambuc doInitialization(Module & M)37f4a2713aSLionel Sambucbool MachineFunctionAnalysis::doInitialization(Module &M) { 38f4a2713aSLionel Sambuc MachineModuleInfo *MMI = getAnalysisIfAvailable<MachineModuleInfo>(); 39f4a2713aSLionel Sambuc assert(MMI && "MMI not around yet??"); 40f4a2713aSLionel Sambuc MMI->setModule(&M); 41f4a2713aSLionel Sambuc NextFnNum = 0; 42f4a2713aSLionel Sambuc return false; 43f4a2713aSLionel Sambuc } 44f4a2713aSLionel Sambuc 45f4a2713aSLionel Sambuc runOnFunction(Function & F)46f4a2713aSLionel Sambucbool MachineFunctionAnalysis::runOnFunction(Function &F) { 47f4a2713aSLionel Sambuc assert(!MF && "MachineFunctionAnalysis already initialized!"); 48f4a2713aSLionel Sambuc MF = new MachineFunction(&F, TM, NextFnNum++, 49*0a6a1f1dSLionel Sambuc getAnalysis<MachineModuleInfo>()); 50f4a2713aSLionel Sambuc return false; 51f4a2713aSLionel Sambuc } 52f4a2713aSLionel Sambuc releaseMemory()53f4a2713aSLionel Sambucvoid MachineFunctionAnalysis::releaseMemory() { 54f4a2713aSLionel Sambuc delete MF; 55*0a6a1f1dSLionel Sambuc MF = nullptr; 56f4a2713aSLionel Sambuc } 57