Wojciech Stryjewski
2002-Sep-22 23:55 UTC
[LLVMdev] Accessing constant indexes in GetElementPtr
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? Wojciech
Bill? Wendling
2002-Sep-23 00:24 UTC
[LLVMdev] Accessing constant indexes in GetElementPtr
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). - You might try "dyn_cast" which will return a valid pointer or 0 instead of throwing an assertion. - Look at the "getNullValue()" method in "Constant". That might be useful as well. -- || Bill? Wendling wendling at isanbard.org
Vikram S. Adve
2002-Sep-23 07:35 UTC
[LLVMdev] Accessing constant indexes in GetElementPtr
> 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.) anyway, indexVal->getType() == Type::UByteTy should tell you if you have a structure index or not. --Vikram
Seemingly Similar Threads
- [LLVMdev] Accessing constant indexes in GetElementPtr
- [LLVMdev] Accessing constant indexes in GetElementPtr
- [LLVMdev] Dynamic Creation of a simple program
- [LLVMdev] SignlessTypes: Removal of Constant[SU]Int
- [LLVMdev] Compile error in InstrSelectionSupport.cpp