Mahwish
Mahwish

Reputation: 101

LLVM IR instumentation. how to get the element value the pointer arg is pointing to?

I am trying to instrument LLVM IR call instruction. What I want to achieve is to get the arguments of a function call. If the argument is pointer type, then I want to get the element/variable that pointer is pointing to. I know that if I have the argument, I can use

getPointerElementType to get the type of element the pointer is pointing to.

But how to access the value of element?

Upvotes: 5

Views: 4451

Answers (2)

Eugenos_Programos
Eugenos_Programos

Reputation: 15

You can use load function from IRBuilder package. Here is reference from official llvmlite documentation:

• IRBuilder.load(ptr, name='', align=None) Load value from pointer ptr. If align is passed, it should be a Python integer specifying the guaranteed pointer alignment.

Upvotes: 0

Oak
Oak

Reputation: 26868

You want to

get the element/variable that pointer is pointing to

This is also called "dereferencing a pointer". This is not something you can do at compile time, but what you can do is insert an instruction which does the dereferencing - in other words, a load instruction.

Upvotes: 5

Related Questions