[LLVMdev] Initializing GC roots
Yiannis Tsiouris
yiannis.tsiouris at gmail.com
Sat Oct 8 14:35:56 PDT 2011
On 10/08/2011 05:01 PM, Gordon Henriksen wrote:
> 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
>
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(
Type::getInt64Ty(F.getContext()),-5),*I);
instead of:
StoreInst* SI = new StoreInst(ConstantPointerNull::get(cast<PointerType>(
cast<PointerType>((*I)->getType())->getElementType())),
*I);
Thank you very much,
Yiannis
More information about the llvm-dev
mailing list