[llvm-dev] Force casting a Value*
Tim Northover via llvm-dev
llvm-dev at lists.llvm.org
Sun Jun 11 19:13:19 PDT 2017
On 11 June 2017 at 18:36, Dipanjan Das via llvm-dev
<llvm-dev at lists.llvm.org> wrote:
> You are dispatching call to different functions depending on if it's a
> LoadInst/StoreInst/CallInst. I am using a similar structure in my project,
> too. However, irrespective of the Type of the argument (i.e.
> i32/i32*/i32**), I just need its value (store_inst->getValueOperand() which
> is the same as store_inst->getOperand(0)).
Since you're after the runtime value you're going to have to convert
whatever you get to an i64 (and hope/verify that that's how a uint64_t
actually gets passed; a good bet, but not guaranteed).
So if you're storing a pointer you're going to have to insert a
ptrtoint instruction and then a call instruction using that result; if
you're storing an i32 you're going to have to insert a zext followed
by the call, etc. If you're storing an i128 or a 128-bit vector,
> I want to ignore the type in this case. I feel there should be some unified means to deal all the cases in a
> single function.
There isn't, because it's rarely actually useful; the type is
important. The closest thing is IRBuilder::CreateZExtOrTrunc which
will handle integer types in many cases, but not pointers or vectors
or structs or arrays or ...
More information about the llvm-dev