2

I have a Value* type named indexValue, and the type is i32. I think indexValue must hold a number which type is int. Now I want to use the exact number which pointed by indexValue , so I do like this:

ConstantInt* CI = llvm::cast<llvm::ConstantInt>(indexValue); //This is wrong, so is dyn_cast.

uint64_t index = indexValue->getZExtValue();

uint64_t size = index + 1;

I don't know if it is the right way. So, could anybody tell the way to get the integer content from a Value* which type is i32?

I'll be very very grateful if there is any answer.

TobiMcNamobi
  • 4,687
  • 3
  • 33
  • 52
gongweixue
  • 155
  • 2
  • 11
  • These are [`llvm::ConstantInt`](http://llvm.org/docs/doxygen/html/classllvm_1_1ConstantInt.html) and [`llvm::Value`](http://llvm.org/docs/doxygen/html/classllvm_1_1Value.html). Is that correct ? – WhozCraig Sep 06 '13 at 02:54

1 Answers1

0

The way you outline is more or less correct - there's also a more complete answer in this related question. But that is of course assuming the value is a ConstantInt.

If you expect some value to be a constant but it isn't, you should make sure you're running one of the constant propagation passes first. If the value is still not a constant there's nothing much you can do, except for maybe writing your own specialized constant propagation pass...

Community
  • 1
  • 1
Oak
  • 26,231
  • 8
  • 93
  • 152
  • You are right, I am not sure that the Value is Constant, so I think my way to deal with this is not correct. I will think about another way. Thanks a lot – gongweixue Sep 06 '13 at 07:45