From 421ccd9892178e741e24c96cef4304262475255d Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 6 Apr 2010 00:51:52 +0000 Subject: [PATCH] Give MachineModuleInfo an actual Module*. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@100508 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/MachineFunctionAnalysis.h | 2 +- include/llvm/CodeGen/MachineModuleInfo.h | 6 ++++++ lib/CodeGen/MachineFunctionAnalysis.cpp | 18 +++++++++++++----- lib/CodeGen/MachineModuleInfo.cpp | 1 + 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/include/llvm/CodeGen/MachineFunctionAnalysis.h b/include/llvm/CodeGen/MachineFunctionAnalysis.h index ee2c6ddc81f..75dbaab973d 100644 --- a/include/llvm/CodeGen/MachineFunctionAnalysis.h +++ b/include/llvm/CodeGen/MachineFunctionAnalysis.h @@ -39,7 +39,7 @@ public: CodeGenOpt::Level getOptLevel() const { return OptLevel; } private: - virtual bool doInitialization(Module &) { NextFnNum = 1; return false; } + virtual bool doInitialization(Module &M); virtual bool runOnFunction(Function &F); virtual void releaseMemory(); virtual void getAnalysisUsage(AnalysisUsage &AU) const; diff --git a/include/llvm/CodeGen/MachineModuleInfo.h b/include/llvm/CodeGen/MachineModuleInfo.h index d610390b635..17da43b7d62 100644 --- a/include/llvm/CodeGen/MachineModuleInfo.h +++ b/include/llvm/CodeGen/MachineModuleInfo.h @@ -100,6 +100,9 @@ class MachineModuleInfo : public ImmutablePass { /// Context - This is the MCContext used for the entire code generator. MCContext Context; + /// TheModule - This is the LLVM Module being worked on. + Module *TheModule; + /// ObjFileMMI - This is the object-file-format-specific implementation of /// MachineModuleInfoImpl, which lets targets accumulate whatever info they /// want. @@ -176,6 +179,9 @@ public: const MCContext &getContext() const { return Context; } MCContext &getContext() { return Context; } + void setModule(Module *M) { TheModule = M; } + Module *getModule() const { return TheModule; } + /// getInfo - Keep track of various per-function pieces of information for /// backends that would like to do so. /// diff --git a/lib/CodeGen/MachineFunctionAnalysis.cpp b/lib/CodeGen/MachineFunctionAnalysis.cpp index faddcb29201..3b2eb6d388b 100644 --- a/lib/CodeGen/MachineFunctionAnalysis.cpp +++ b/lib/CodeGen/MachineFunctionAnalysis.cpp @@ -35,6 +35,19 @@ MachineFunctionAnalysis::~MachineFunctionAnalysis() { assert(!MF && "MachineFunctionAnalysis left initialized!"); } +void MachineFunctionAnalysis::getAnalysisUsage(AnalysisUsage &AU) const { + AU.setPreservesAll(); + AU.addRequired(); +} + +bool MachineFunctionAnalysis::doInitialization(Module &M) { + MachineModuleInfo *MMI = getAnalysisIfAvailable(); + assert(MMI && "MMI not around yet??"); + MMI->setModule(&M); + NextFnNum = 1; return false; +} + + bool MachineFunctionAnalysis::runOnFunction(Function &F) { assert(!MF && "MachineFunctionAnalysis already initialized!"); MF = new MachineFunction(&F, TM, NextFnNum++, @@ -46,8 +59,3 @@ void MachineFunctionAnalysis::releaseMemory() { delete MF; MF = 0; } - -void MachineFunctionAnalysis::getAnalysisUsage(AnalysisUsage &AU) const { - AU.setPreservesAll(); - AU.addRequired(); -} diff --git a/lib/CodeGen/MachineModuleInfo.cpp b/lib/CodeGen/MachineModuleInfo.cpp index ad4f01b7a9a..f813a553670 100644 --- a/lib/CodeGen/MachineModuleInfo.cpp +++ b/lib/CodeGen/MachineModuleInfo.cpp @@ -262,6 +262,7 @@ MachineModuleInfo::MachineModuleInfo(const MCAsmInfo &MAI) // Always emit some info, by default "no personality" info. Personalities.push_back(NULL); AddrLabelSymbols = 0; + TheModule = 0; } MachineModuleInfo::MachineModuleInfo()