Skip to content

Commit 1e30897

Browse files
committedDec 11, 2014
GCStrategy should not own GCFunctionInfo
This change moves the ownership and access of GCFunctionInfo (the object which describes the safepoints associated with a safepoint under GCRoot) to GCModuleInfo. Previously, this was owned by GCStrategy which was in turned owned by GCModuleInfo. This made GCStrategy module specific which is 'surprising' given it's name and other purposes. There's a few more changes needed, but we're getting towards the point we can reuse GCStrategy for gc.statepoint as well. p.s. The style of this code ends up being a mess. I was trying to move code around without otherwise changing much. Once I get the ownership structure rearranged, I will go through and fixup spacing, naming, comments etc. Differential Revision: http://reviews.llvm.org/D6587 llvm-svn: 223994
1 parent f910e8a commit 1e30897

File tree

9 files changed

+64
-64
lines changed

9 files changed

+64
-64
lines changed
 

‎llvm/include/llvm/CodeGen/GCMetadata.h

+21-5
Original file line numberDiff line numberDiff line change
@@ -160,22 +160,37 @@ namespace llvm {
160160
size_t live_size(const iterator &p) const { return roots_size(); }
161161
};
162162

163-
164163
/// An analysis pass which caches information about the entire Module.
165164
/// Records both the function level information used by GCRoots and a
166165
/// cache of the 'active' gc strategy objects for the current Module.
167166
class GCModuleInfo : public ImmutablePass {
168167
typedef StringMap<GCStrategy*> strategy_map_type;
169168
typedef std::vector<std::unique_ptr<GCStrategy>> list_type;
170-
typedef DenseMap<const Function*,GCFunctionInfo*> finfo_map_type;
171169

172170
strategy_map_type StrategyMap;
173171
list_type StrategyList;
174-
finfo_map_type FInfoMap;
175172

176173
GCStrategy *getOrCreateStrategy(const Module *M, const std::string &Name);
177174

178175
public:
176+
/// List of per function info objects. In theory, Each of these
177+
/// may be associated with a different GC.
178+
typedef std::vector<std::unique_ptr<GCFunctionInfo>> FuncInfoVec;
179+
180+
FuncInfoVec::iterator funcinfo_begin() { return Functions.begin(); }
181+
FuncInfoVec::iterator funcinfo_end() { return Functions.end(); }
182+
183+
184+
private:
185+
/// Owning list of all GCFunctionInfos associated with this Module
186+
FuncInfoVec Functions;
187+
188+
/// Non-owning map to bypass linear search when finding the GCFunctionInfo
189+
/// associated with a particular Function.
190+
typedef DenseMap<const Function*,GCFunctionInfo*> finfo_map_type;
191+
finfo_map_type FInfoMap;
192+
public:
193+
179194
typedef list_type::const_iterator iterator;
180195

181196
static char ID;
@@ -192,8 +207,9 @@ namespace llvm {
192207
iterator begin() const { return StrategyList.begin(); }
193208
iterator end() const { return StrategyList.end(); }
194209

195-
/// get - Look up function metadata.
196-
///
210+
/// get - Look up function metadata. This is currently assumed
211+
/// have the side effect of initializing the associated GCStrategy. That
212+
/// will soon change.
197213
GCFunctionInfo &getFunctionInfo(const Function &F);
198214
};
199215

‎llvm/include/llvm/CodeGen/GCMetadataPrinter.h

+10-14
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,11 @@ namespace llvm {
3232
/// defaults from Registry.
3333
typedef Registry<GCMetadataPrinter> GCMetadataPrinterRegistry;
3434

35-
/// GCMetadataPrinter - Emits GC metadata as assembly code.
36-
///
35+
/// GCMetadataPrinter - Emits GC metadata as assembly code. Instances are
36+
/// created, managed, and owned by the AsmPrinter.
3737
class GCMetadataPrinter {
38-
public:
39-
typedef GCStrategy::list_type list_type;
40-
typedef GCStrategy::iterator iterator;
41-
4238
private:
4339
GCStrategy *S;
44-
4540
friend class AsmPrinter;
4641

4742
protected:
@@ -56,13 +51,14 @@ namespace llvm {
5651
public:
5752
GCStrategy &getStrategy() { return *S; }
5853

59-
/// begin/end - Iterate over the collected function metadata.
60-
iterator begin() { return S->begin(); }
61-
iterator end() { return S->end(); }
62-
63-
/// beginAssembly/finishAssembly - Emit module metadata as assembly code.
64-
virtual void beginAssembly(Module &M, AsmPrinter &AP);
65-
virtual void finishAssembly(Module &M, AsmPrinter &AP);
54+
/// Called before the assembly for the module is generated by
55+
/// the AsmPrinter (but after target specific hooks.)
56+
virtual void beginAssembly(Module &M, GCModuleInfo &Info,
57+
AsmPrinter &AP) {}
58+
/// Called after the assembly for the module is generated by
59+
/// the AsmPrinter (but before target specific hooks)
60+
virtual void finishAssembly(Module &M, GCModuleInfo &Info,
61+
AsmPrinter &AP) {}
6662

6763
virtual ~GCMetadataPrinter();
6864
};

‎llvm/include/llvm/CodeGen/GCStrategy.h

-15
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,10 @@ namespace llvm {
5555
/// through the GCModuleInfo analysis pass. They are owned by the analysis
5656
/// pass and recreated every time that pass is invalidated.
5757
class GCStrategy {
58-
public:
59-
typedef std::vector<std::unique_ptr<GCFunctionInfo>> list_type;
60-
typedef list_type::iterator iterator;
61-
6258
private:
6359
friend class GCModuleInfo;
6460
std::string Name;
6561

66-
list_type Functions;
67-
6862
protected:
6963
unsigned NeededSafePoints; ///< Bitmask of required safe points.
7064
bool CustomReadBarriers; ///< Default is to insert loads.
@@ -126,15 +120,6 @@ namespace llvm {
126120
/// the back-end (assembler, JIT, or otherwise).
127121
bool usesMetadata() const { return UsesMetadata; }
128122

129-
/// begin/end - Iterators for function metadata.
130-
///
131-
iterator begin() { return Functions.begin(); }
132-
iterator end() { return Functions.end(); }
133-
134-
/// insertFunctionMetadata - Creates metadata for a function.
135-
///
136-
GCFunctionInfo *insertFunctionInfo(const Function &F);
137-
138123
/// initializeCustomLowering/performCustomLowering - If any of the actions
139124
/// are set to custom, performCustomLowering must be overriden to transform
140125
/// the corresponding actions to LLVM IR. initializeCustomLowering is

‎llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ bool AsmPrinter::doInitialization(Module &M) {
210210
assert(MI && "AsmPrinter didn't require GCModuleInfo?");
211211
for (auto &I : *MI)
212212
if (GCMetadataPrinter *MP = GetOrCreateGCPrinter(*I))
213-
MP->beginAssembly(M, *this);
213+
MP->beginAssembly(M, *MI, *this);
214214

215215
// Emit module-level inline asm if it exists.
216216
if (!M.getModuleInlineAsm().empty()) {
@@ -985,7 +985,7 @@ bool AsmPrinter::doFinalization(Module &M) {
985985
assert(MI && "AsmPrinter didn't require GCModuleInfo?");
986986
for (GCModuleInfo::iterator I = MI->end(), E = MI->begin(); I != E; )
987987
if (GCMetadataPrinter *MP = GetOrCreateGCPrinter(**--I))
988-
MP->finishAssembly(M, *this);
988+
MP->finishAssembly(M, *MI, *this);
989989

990990
// Emit llvm.ident metadata in an '.ident' directive.
991991
EmitModuleIdents(M);

‎llvm/lib/CodeGen/AsmPrinter/ErlangGCPrinter.cpp

+10-7
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ namespace {
3636

3737
class ErlangGCPrinter : public GCMetadataPrinter {
3838
public:
39-
void beginAssembly(Module &M, AsmPrinter &AP) override;
40-
void finishAssembly(Module &M, AsmPrinter &AP) override;
39+
void finishAssembly(Module &M, GCModuleInfo &Info,
40+
AsmPrinter &AP) override;
4141
};
4242

4343
}
@@ -47,9 +47,8 @@ X("erlang", "erlang-compatible garbage collector");
4747

4848
void llvm::linkErlangGCPrinter() { }
4949

50-
void ErlangGCPrinter::beginAssembly(Module &M, AsmPrinter &AP) { }
51-
52-
void ErlangGCPrinter::finishAssembly(Module &M, AsmPrinter &AP) {
50+
void ErlangGCPrinter::finishAssembly(Module &M, GCModuleInfo &Info,
51+
AsmPrinter &AP) {
5352
MCStreamer &OS = AP.OutStreamer;
5453
unsigned IntPtrSize =
5554
AP.TM.getSubtargetImpl()->getDataLayout()->getPointerSize();
@@ -60,9 +59,13 @@ void ErlangGCPrinter::finishAssembly(Module &M, AsmPrinter &AP) {
6059
SectionKind::getDataRel()));
6160

6261
// For each function...
63-
for (iterator FI = begin(), FE = end(); FI != FE; ++FI) {
62+
for (GCModuleInfo::FuncInfoVec::iterator FI = Info.funcinfo_begin(),
63+
IE = Info.funcinfo_end();
64+
FI != IE; ++FI) {
6465
GCFunctionInfo &MD = **FI;
65-
66+
if (MD.getStrategy().getName() != getStrategy().getName())
67+
// this function is managed by some other GC
68+
continue;
6669
/** A compact GC layout. Emit this data structure:
6770
*
6871
* struct {

‎llvm/lib/CodeGen/AsmPrinter/OcamlGCPrinter.cpp

+18-6
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ namespace {
3434

3535
class OcamlGCMetadataPrinter : public GCMetadataPrinter {
3636
public:
37-
void beginAssembly(Module &M, AsmPrinter &AP) override;
38-
void finishAssembly(Module &M, AsmPrinter &AP) override;
37+
void beginAssembly(Module &M, GCModuleInfo &Info,
38+
AsmPrinter &AP) override;
39+
void finishAssembly(Module &M, GCModuleInfo &Info,
40+
AsmPrinter &AP) override;
3941
};
4042

4143
}
@@ -67,7 +69,8 @@ static void EmitCamlGlobal(const Module &M, AsmPrinter &AP, const char *Id) {
6769
AP.OutStreamer.EmitLabel(Sym);
6870
}
6971

70-
void OcamlGCMetadataPrinter::beginAssembly(Module &M, AsmPrinter &AP) {
72+
void OcamlGCMetadataPrinter::beginAssembly(Module &M, GCModuleInfo &Info,
73+
AsmPrinter &AP) {
7174
AP.OutStreamer.SwitchSection(AP.getObjFileLowering().getTextSection());
7275
EmitCamlGlobal(M, AP, "code_begin");
7376

@@ -91,7 +94,8 @@ void OcamlGCMetadataPrinter::beginAssembly(Module &M, AsmPrinter &AP) {
9194
/// (FrameSize and LiveOffsets would overflow). FrameTablePrinter will abort if
9295
/// either condition is detected in a function which uses the GC.
9396
///
94-
void OcamlGCMetadataPrinter::finishAssembly(Module &M, AsmPrinter &AP) {
97+
void OcamlGCMetadataPrinter::finishAssembly(Module &M, GCModuleInfo &Info,
98+
AsmPrinter &AP) {
9599
unsigned IntPtrSize =
96100
AP.TM.getSubtargetImpl()->getDataLayout()->getPointerSize();
97101

@@ -108,8 +112,12 @@ void OcamlGCMetadataPrinter::finishAssembly(Module &M, AsmPrinter &AP) {
108112
EmitCamlGlobal(M, AP, "frametable");
109113

110114
int NumDescriptors = 0;
111-
for (iterator I = begin(), IE = end(); I != IE; ++I) {
115+
for (GCModuleInfo::FuncInfoVec::iterator I = Info.funcinfo_begin(),
116+
IE = Info.funcinfo_end(); I != IE; ++I) {
112117
GCFunctionInfo &FI = **I;
118+
if (FI.getStrategy().getName() != getStrategy().getName())
119+
// this function is managed by some other GC
120+
continue;
113121
for (GCFunctionInfo::iterator J = FI.begin(), JE = FI.end(); J != JE; ++J) {
114122
NumDescriptors++;
115123
}
@@ -122,8 +130,12 @@ void OcamlGCMetadataPrinter::finishAssembly(Module &M, AsmPrinter &AP) {
122130
AP.EmitInt16(NumDescriptors);
123131
AP.EmitAlignment(IntPtrSize == 4 ? 2 : 3);
124132

125-
for (iterator I = begin(), IE = end(); I != IE; ++I) {
133+
for (GCModuleInfo::FuncInfoVec::iterator I = Info.funcinfo_begin(),
134+
IE = Info.funcinfo_end(); I != IE; ++I) {
126135
GCFunctionInfo &FI = **I;
136+
if (FI.getStrategy().getName() != getStrategy().getName())
137+
// this function is managed by some other GC
138+
continue;
127139

128140
uint64_t FrameSize = FI.getFrameSize();
129141
if (FrameSize >= 1<<16) {

‎llvm/lib/CodeGen/GCMetadata.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,14 @@ GCFunctionInfo &GCModuleInfo::getFunctionInfo(const Function &F) {
9191
return *I->second;
9292

9393
GCStrategy *S = getOrCreateStrategy(F.getParent(), F.getGC());
94-
GCFunctionInfo *GFI = S->insertFunctionInfo(F);
94+
Functions.push_back(make_unique<GCFunctionInfo>(F, *S));
95+
GCFunctionInfo *GFI = Functions.back().get();
9596
FInfoMap[&F] = GFI;
9697
return *GFI;
9798
}
9899

99100
void GCModuleInfo::clear() {
101+
Functions.clear();
100102
FInfoMap.clear();
101103
StrategyMap.clear();
102104
StrategyList.clear();

‎llvm/lib/CodeGen/GCMetadataPrinter.cpp

-8
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,3 @@ using namespace llvm;
1717
GCMetadataPrinter::GCMetadataPrinter() { }
1818

1919
GCMetadataPrinter::~GCMetadataPrinter() { }
20-
21-
void GCMetadataPrinter::beginAssembly(Module &M, AsmPrinter &AP) {
22-
// Default is no action.
23-
}
24-
25-
void GCMetadataPrinter::finishAssembly(Module &M, AsmPrinter &AP) {
26-
// Default is no action.
27-
}

‎llvm/lib/CodeGen/GCStrategy.cpp

-6
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,6 @@ bool GCStrategy::findCustomSafePoints(GCFunctionInfo& FI, MachineFunction &F) {
115115
llvm_unreachable(nullptr);
116116
}
117117

118-
119-
GCFunctionInfo *GCStrategy::insertFunctionInfo(const Function &F) {
120-
Functions.push_back(make_unique<GCFunctionInfo>(F, *this));
121-
return Functions.back().get();
122-
}
123-
124118
// -----------------------------------------------------------------------------
125119

126120
INITIALIZE_PASS_BEGIN(LowerIntrinsics, "gc-lowering", "GC Lowering",

0 commit comments

Comments
 (0)
Please sign in to comment.