[LLVMdev] Accessing constant indexes in GetElementPtr
Casey Carter
Casey at Carter.net
Mon Sep 23 08:10:00 PDT 2002
Vikram S. Adve wrote:
>>Also sprach Wojciech Stryjewski:
>>} Ok. Let's say I have a GetElementPtrInst that is used to access
>>structure
>>} elements. In this case the indexes will be constants and I want
>>to get the
>>} constant values as an a native C int.
>>}
>>} Now I can iterate over all the indexes with idx_begin(). I can cast
>>} all of the indexes to a ConstantIntegral. However, I cannot cast the
>>} indexes to a ConstantSInt or ConstantUInt (cast<> throws an
>>assertion) and
>>} these two classes are the ones that have the getValue() method I need.
>>}
>>} Am I missing something here?
>>}
>>I'm not quite sure what particular problem you're having, but a few
>>things to remember...
>>
>> - Not all of the operands of getelementptr are constants. (In
>> particular, Operand(0) isn't).
>>
>>
>
>
>Bill is right -- not all operands are necessarily constant. Basically, any
>index into an array may not be a constant. Any index into a structure must
>be a constant of type UByte, and so it should cast to a ConstantUInt.
>(Operand 0 is not a special case, but it is always an array index so it
>sometimes may not be a constant. Very often, though, it is the constant 0.)
>
>
That should be _index_ 0, operand 0 is the base pointer itself.
>anyway, indexVal->getType() == Type::UByteTy should tell you if you have a
>structure index or not.
>
>--Vikram
>
>_______________________________________________
>LLVM Developers mailing list
>LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
>http://mail.cs.uiuc.edu/mailman/listinfo/llvmdev
>
>
More information about the llvm-dev
mailing list