[LLVMdev] Adding fields in a already built type? (2)
letz at grame.fr
Tue Jun 15 12:45:29 PDT 2010
Le 15 juin 2010 à 21:14, Chris Lattner a écrit :
> On Jun 15, 2010, at 11:51 AM, Stéphane Letz wrote:
>>> Nope, types are immutable once created. The only thing you can do is "refine" opaque types to other types. There is a section in the programmer's manual on this:
>> So I succeeded in using a "PATypeHolder" for the "opaque" type, define a Type* with PointerType::getUnqual, prepare a field, then use " refineAbstractTypeTo " to built the real type with this added field.
>> The thing is that I would need to do that repeatedly, that is progressively adding fields, generates code that access those ready fields, and "refine" the type step by step.
>> Is that even possible?
> It would work, but sounds really inefficient. What are you really trying to do here?
inefficient : do you mean because all users of the refined type would have to be "notified" ?
The reason is that our code generator generates a struct (progressively adding fields) and generates code that access this struct (that is : the fields that are already added). If we cannot create the struct progressively, then we have to define a pass to build the complete struct, then define a second pass to generate the code. If we can simply create the struct progressively at LLVM level, then it make our code simpler.
More information about the llvm-dev