[LLVMdev] Initializing GC roots
Gordon Henriksen
gordonhenriksen at me.com
Sat Oct 8 07:01:41 PDT 2011
On Oct 6, 2011, at 17:19, Yiannis Tsiouris wrote:
> Hello all,
>
> I set: InitRoots = true; in my gc plugin as i want the roots to be
> initialized to the "null" value.
> Is there a way to define which value should be the initial one? For
> example, i would like to initialize my roots to -5 (tagged, null value
> for the GC in my runtime system) instead of 0.
>
> Ofcourse, i could do it in the frontend (storing -5 to all GC roots),
> but i was wondering if there is another way e.g. by modifying the GC
> plugin and implementing custom lowering for the gcroot intrinsic.
Hello Yiannis,
Yes, what you describe should be possible. In your GCStrategy subclass constructor, make the following change:
class MyGCStrategy : public GCStrategy {
MyGCStrategy() {
- InitRoots = true;
+ CustomRoots = true;
}
+
+ bool performCustomLowering(Function &F) {
+ // You can use LowerIntrinsics::InsertRootInitializers as a template.
+ }
};
LowerIntrinsics::InsertRootInitializers is only 26 lines of code. You can find it here:
http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GCStrategy.cpp?annotate=123170#l174
More invasively, you could consider adding a hook to GCStrategy which replaces the indicated call to ConstantPointerNull::get in LowerIntrinsics::InsertRootInitializers:
// Add root initializers.
bool MadeChange = false;
for (AllocaInst **I = Roots, **E = Roots + Count; I != E; ++I)
if (!InitedRoots.count(*I)) {
====> StoreInst* SI = new StoreInst(ConstantPointerNull::get(cast<PointerType>(
====> cast<PointerType>((*I)->getType())->getElementType())),
*I);
SI->insertAfter(*I);
MadeChange = true;
}
return MadeChange;
But such a change would not be strictly necessary.
Hope this helps,
Gordon
More information about the llvm-dev
mailing list