[LLVMdev] non-pointer gcroot

Gordon Henriksen gordonhenriksen at me.com
Fri Nov 7 18:40:19 PST 2008


On Nov 7, 2008, at 15:29, Scott Graham wrote:

> I'm getting an assert in LowerIntrinsics::InsertRootInitializers  
> because I'm gcroot'ing an alloca to a non-pointer.
>
> I was hoping to modify InsertRootInitializers to memset the  
> structure in the case that it's not a pointer, but I'm not sure how  
> to. Can anyone suggest what should go at "todo; something here"?
>
>  ...
>  for (AllocaInst **I = Roots, **E = Roots + Count; I != E; ++I)
>    if (!InitedRoots.count(*I)) {
> 	  const Type* Ty = cast<PointerType>((*I)->getType())- 
> >getElementType();
> 	  if (Ty->getTypeID() == Type::PointerTyID) {
> 	    new StoreInst(ConstantPointerNull::get(cast<PointerType>(Ty)),
> 					*I, IP);
> 	  } else {
> 	    // todo; something here
> 	  }
>      MadeChange = true;
>    }
>  ...


Hi Scott,

Using the new support for first-class aggregate values, you should be  
able to rewrite the above code to use Constant::getNullValue  
regardless of the type of the alloca. There needn't be a special-case  
for !isa<PointerType>((*I)->getType()->getElementType()).

However, I hesitate to recommend this route; I think it boxes in from  
supporting escape analysis (where pointer fields within a stack- 
allocated struct would need to be initialized). I'd suggest you gcroot  
pointers to your fat pointers instead. This needn't imply any changes  
to your fat pointers in the heap, and constitutes a trivial change to  
a stalk walker.

— Gordon


P.S. — Avoid using Type::getTypeID; it's an implementation detail for  
the templates in llvm/support/Casing.h: isa<>, cast<>, dyn_cast<>, etc.





More information about the llvm-dev mailing list