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