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 
MachineFunctionAnalysis(const TargetMachine & tm)22 MachineFunctionAnalysis::MachineFunctionAnalysis(const TargetMachine &tm) :
23   FunctionPass(ID), TM(tm), MF(nullptr) {
24   initializeMachineModuleInfoPass(*PassRegistry::getPassRegistry());
25 }
26 
~MachineFunctionAnalysis()27 MachineFunctionAnalysis::~MachineFunctionAnalysis() {
28   releaseMemory();
29   assert(!MF && "MachineFunctionAnalysis left initialized!");
30 }
31 
getAnalysisUsage(AnalysisUsage & AU) const32 void MachineFunctionAnalysis::getAnalysisUsage(AnalysisUsage &AU) const {
33   AU.setPreservesAll();
34   AU.addRequired<MachineModuleInfo>();
35 }
36 
doInitialization(Module & M)37 bool MachineFunctionAnalysis::doInitialization(Module &M) {
38   MachineModuleInfo *MMI = getAnalysisIfAvailable<MachineModuleInfo>();
39   assert(MMI && "MMI not around yet??");
40   MMI->setModule(&M);
41   NextFnNum = 0;
42   return false;
43 }
44 
45 
runOnFunction(Function & F)46 bool MachineFunctionAnalysis::runOnFunction(Function &F) {
47   assert(!MF && "MachineFunctionAnalysis already initialized!");
48   MF = new MachineFunction(&F, TM, NextFnNum++,
49                            getAnalysis<MachineModuleInfo>());
50   return false;
51 }
52 
releaseMemory()53 void MachineFunctionAnalysis::releaseMemory() {
54   delete MF;
55   MF = nullptr;
56 }
57