[llvm] r223859 - Remove the Module pointer from GCStrategy and GCMetadataPrinter
Philip Reames
listmail at philipreames.com
Tue Dec 9 15:57:54 PST 2014
Author: reames
Date: Tue Dec 9 17:57:54 2014
New Revision: 223859
URL: http://llvm.org/viewvc/llvm-project?rev=223859&view=rev
Log:
Remove the Module pointer from GCStrategy and GCMetadataPrinter
In the current implementation, GCStrategy is a part of the ownership structure for the gc metadata which describes a Module. It also contains a reference to the module in question. As a result, GCStrategy instances are essentially Module specific.
I plan to transition away from this design. Instead, a GCStrategy will be owned by the LLVMContext. It will be a lightweight policy object which contains no information about the Modules or Functions involved, but can be easily reached given a Function.
The first step in this transition is to remove the direct Module reference from GCStrategy. This also requires removing the single user of this reference, the GCMetadataPrinter hierarchy. In theory, this will allow the lifetime of the printers to be scoped to the LLVMContext as well, but in practice, I'm not actually changing that. (Yet?)
An alternate design would have been to move the direct Module reference into the GCMetadataPrinter and change the keying of the owning maps to explicitly key off both GCStrategy and Module. I'm open to doing it that way instead, but didn't see much value in preserving the per Module association for GCMetadataPrinters.
The next change in this sequence will be to start unwinding the intertwined ownership between GCStrategy, GCModuleInfo, and GCFunctionInfo.
Differential Revision: http://reviews.llvm.org/D6566
Modified:
llvm/trunk/include/llvm/CodeGen/GCMetadataPrinter.h
llvm/trunk/include/llvm/CodeGen/GCStrategy.h
llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
llvm/trunk/lib/CodeGen/AsmPrinter/ErlangGCPrinter.cpp
llvm/trunk/lib/CodeGen/AsmPrinter/OcamlGCPrinter.cpp
llvm/trunk/lib/CodeGen/GCMetadata.cpp
llvm/trunk/lib/CodeGen/GCMetadataPrinter.cpp
Modified: llvm/trunk/include/llvm/CodeGen/GCMetadataPrinter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/GCMetadataPrinter.h?rev=223859&r1=223858&r2=223859&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/GCMetadataPrinter.h (original)
+++ llvm/trunk/include/llvm/CodeGen/GCMetadataPrinter.h Tue Dec 9 17:57:54 2014
@@ -55,16 +55,14 @@ namespace llvm {
public:
GCStrategy &getStrategy() { return *S; }
- const Module &getModule() const { return S->getModule(); }
/// begin/end - Iterate over the collected function metadata.
iterator begin() { return S->begin(); }
iterator end() { return S->end(); }
/// beginAssembly/finishAssembly - Emit module metadata as assembly code.
- virtual void beginAssembly(AsmPrinter &AP);
-
- virtual void finishAssembly(AsmPrinter &AP);
+ virtual void beginAssembly(Module &M, AsmPrinter &AP);
+ virtual void finishAssembly(Module &M, AsmPrinter &AP);
virtual ~GCMetadataPrinter();
};
Modified: llvm/trunk/include/llvm/CodeGen/GCStrategy.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/GCStrategy.h?rev=223859&r1=223858&r2=223859&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/GCStrategy.h (original)
+++ llvm/trunk/include/llvm/CodeGen/GCStrategy.h Tue Dec 9 17:57:54 2014
@@ -59,7 +59,6 @@ namespace llvm {
private:
friend class GCModuleInfo;
- const Module *M;
std::string Name;
list_type Functions;
@@ -84,10 +83,6 @@ namespace llvm {
///
const std::string &getName() const { return Name; }
- /// getModule - The module within which the GC strategy is operating.
- ///
- const Module &getModule() const { return *M; }
-
/// needsSafePoitns - True if safe points of any kind are required. By
// default, none are recorded.
bool needsSafePoints() const {
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp?rev=223859&r1=223858&r2=223859&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Tue Dec 9 17:57:54 2014
@@ -210,7 +210,7 @@ bool AsmPrinter::doInitialization(Module
assert(MI && "AsmPrinter didn't require GCModuleInfo?");
for (auto &I : *MI)
if (GCMetadataPrinter *MP = GetOrCreateGCPrinter(*I))
- MP->beginAssembly(*this);
+ MP->beginAssembly(M, *this);
// Emit module-level inline asm if it exists.
if (!M.getModuleInlineAsm().empty()) {
@@ -985,7 +985,7 @@ bool AsmPrinter::doFinalization(Module &
assert(MI && "AsmPrinter didn't require GCModuleInfo?");
for (GCModuleInfo::iterator I = MI->end(), E = MI->begin(); I != E; )
if (GCMetadataPrinter *MP = GetOrCreateGCPrinter(**--I))
- MP->finishAssembly(*this);
+ MP->finishAssembly(M, *this);
// Emit llvm.ident metadata in an '.ident' directive.
EmitModuleIdents(M);
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/ErlangGCPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/ErlangGCPrinter.cpp?rev=223859&r1=223858&r2=223859&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/ErlangGCPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/ErlangGCPrinter.cpp Tue Dec 9 17:57:54 2014
@@ -36,8 +36,8 @@ namespace {
class ErlangGCPrinter : public GCMetadataPrinter {
public:
- void beginAssembly(AsmPrinter &AP) override;
- void finishAssembly(AsmPrinter &AP) override;
+ void beginAssembly(Module &M, AsmPrinter &AP) override;
+ void finishAssembly(Module &M, AsmPrinter &AP) override;
};
}
@@ -47,9 +47,9 @@ X("erlang", "erlang-compatible garbage c
void llvm::linkErlangGCPrinter() { }
-void ErlangGCPrinter::beginAssembly(AsmPrinter &AP) { }
+void ErlangGCPrinter::beginAssembly(Module &M, AsmPrinter &AP) { }
-void ErlangGCPrinter::finishAssembly(AsmPrinter &AP) {
+void ErlangGCPrinter::finishAssembly(Module &M, AsmPrinter &AP) {
MCStreamer &OS = AP.OutStreamer;
unsigned IntPtrSize =
AP.TM.getSubtargetImpl()->getDataLayout()->getPointerSize();
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/OcamlGCPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/OcamlGCPrinter.cpp?rev=223859&r1=223858&r2=223859&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/OcamlGCPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/OcamlGCPrinter.cpp Tue Dec 9 17:57:54 2014
@@ -34,8 +34,8 @@ namespace {
class OcamlGCMetadataPrinter : public GCMetadataPrinter {
public:
- void beginAssembly(AsmPrinter &AP) override;
- void finishAssembly(AsmPrinter &AP) override;
+ void beginAssembly(Module &M, AsmPrinter &AP) override;
+ void finishAssembly(Module &M, AsmPrinter &AP) override;
};
}
@@ -67,12 +67,12 @@ static void EmitCamlGlobal(const Module
AP.OutStreamer.EmitLabel(Sym);
}
-void OcamlGCMetadataPrinter::beginAssembly(AsmPrinter &AP) {
+void OcamlGCMetadataPrinter::beginAssembly(Module &M, AsmPrinter &AP) {
AP.OutStreamer.SwitchSection(AP.getObjFileLowering().getTextSection());
- EmitCamlGlobal(getModule(), AP, "code_begin");
+ EmitCamlGlobal(M, AP, "code_begin");
AP.OutStreamer.SwitchSection(AP.getObjFileLowering().getDataSection());
- EmitCamlGlobal(getModule(), AP, "data_begin");
+ EmitCamlGlobal(M, AP, "data_begin");
}
/// emitAssembly - Print the frametable. The ocaml frametable format is thus:
@@ -91,21 +91,21 @@ void OcamlGCMetadataPrinter::beginAssemb
/// (FrameSize and LiveOffsets would overflow). FrameTablePrinter will abort if
/// either condition is detected in a function which uses the GC.
///
-void OcamlGCMetadataPrinter::finishAssembly(AsmPrinter &AP) {
+void OcamlGCMetadataPrinter::finishAssembly(Module &M, AsmPrinter &AP) {
unsigned IntPtrSize =
AP.TM.getSubtargetImpl()->getDataLayout()->getPointerSize();
AP.OutStreamer.SwitchSection(AP.getObjFileLowering().getTextSection());
- EmitCamlGlobal(getModule(), AP, "code_end");
+ EmitCamlGlobal(M, AP, "code_end");
AP.OutStreamer.SwitchSection(AP.getObjFileLowering().getDataSection());
- EmitCamlGlobal(getModule(), AP, "data_end");
+ EmitCamlGlobal(M, AP, "data_end");
// FIXME: Why does ocaml emit this??
AP.OutStreamer.EmitIntValue(0, IntPtrSize);
AP.OutStreamer.SwitchSection(AP.getObjFileLowering().getDataSection());
- EmitCamlGlobal(getModule(), AP, "frametable");
+ EmitCamlGlobal(M, AP, "frametable");
int NumDescriptors = 0;
for (iterator I = begin(), IE = end(); I != IE; ++I) {
Modified: llvm/trunk/lib/CodeGen/GCMetadata.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GCMetadata.cpp?rev=223859&r1=223858&r2=223859&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GCMetadata.cpp (original)
+++ llvm/trunk/lib/CodeGen/GCMetadata.cpp Tue Dec 9 17:57:54 2014
@@ -71,7 +71,6 @@ GCStrategy *GCModuleInfo::getOrCreateStr
E = GCRegistry::end(); I != E; ++I) {
if (Name == I->getName()) {
std::unique_ptr<GCStrategy> S = I->instantiate();
- S->M = M;
S->Name = Name;
StrategyMap[Name] = S.get();
StrategyList.push_back(std::move(S));
Modified: llvm/trunk/lib/CodeGen/GCMetadataPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GCMetadataPrinter.cpp?rev=223859&r1=223858&r2=223859&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GCMetadataPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/GCMetadataPrinter.cpp Tue Dec 9 17:57:54 2014
@@ -18,10 +18,10 @@ GCMetadataPrinter::GCMetadataPrinter() {
GCMetadataPrinter::~GCMetadataPrinter() { }
-void GCMetadataPrinter::beginAssembly(AsmPrinter &AP) {
+void GCMetadataPrinter::beginAssembly(Module &M, AsmPrinter &AP) {
// Default is no action.
}
-void GCMetadataPrinter::finishAssembly(AsmPrinter &AP) {
+void GCMetadataPrinter::finishAssembly(Module &M, AsmPrinter &AP) {
// Default is no action.
}
More information about the llvm-commits
mailing list