ConsistentProgrammer
ConsistentProgrammer

Reputation: 1324

Reading variable pointed by a pointer in llvm

Pointer type can be deduced through:

Value* v= i->getOperand(0);
.......    
if(PointerType* pt=dyn_cast<PointerType>(v->getType())){
      pt->getElementType()->getTypeID();

How can I read the value that this pointer points to?

I is a CallInst.

Upvotes: 0

Views: 697

Answers (1)

Oak
Oak

Reputation: 26898

Given a CallInst, you can get an argument via getArgOperand() or iterate over all of them with arg_operands(). The arguments you get this way are just Values, and you can do anything you can do with other Values on them.

In particular, if those Values are constants, you can get the actual values used in the compiler - see this related stackoverflow question: LLVM get constant integer back from Value*

Upvotes: 1

Related Questions