Initializing GC roots

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;

Hi Gordon,

Your email was very helpful!
I think it would be better to implement it in the GC plugin
(MyGCStratedy). So i implemented performCustomLowering using
PerformDefaultLowering from lib/Codegen/GCStrategy.cpp as a template and
writing a custom InsertRootInitializers function with:

StoreInst* SI = new StoreInst(ConstantInt::getSigned(

instead of:

StoreInst* SI = new StoreInst(ConstantPointerNull::get(cast<PointerType>(

Thank you very much,