Hi 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; } ... thanks, scott
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.
On Fri, Nov 7, 2008 at 6:40 PM, Gordon Henriksen <gordonhenriksen at me.com> wrote:> 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.Hi Gordon Thanks, I'll look forward to getting up to 2.4/head for the new and improved getNullValue. I'm not sure I understand your suggestion. The concern is that a future optimization pass may be hampered by having structs rooted? In my front end, the fat pointers will only ever be stack allocated (never in the heap), so it seems strange to add the extra indirection. I suppose the loads through the fat-pointer-pointer should be optimized away anyway?> P.S. — Avoid using Type::getTypeID; it's an implementation detail for > the templates in llvm/support/Casing.h: isa<>, cast<>, dyn_cast<>, etc.Noted, thank you. scott