[LLVMdev] Printing Function Arguments

Nick Lewycky nicholas at mxc.ca
Sun Sep 27 17:20:10 PDT 2009


ivtm wrote:
> I am processing the LLVM instructions and right now I am at the 'call'
> instruction.
> For now I just want to print the argument type.
> 
> For example in the following:
> 
> 	%0 = tail call i32 (...)* @__FFF (i32 8) nounwind; <i32> [#uses=1]
> 
> I need to get access to 'i32' and '8' separately.
> 
> I do:
> 
> CallInst *CI = dyn_cast<CallInst>(I);  
> Value *v = CI->getOperand(1)
> 
> I can get the type via v->getType() and that returns 'i32', which is good.
> 
> But I also need to get the value '8'.
> 
> I can get it via v->getValueID(), but in the documentation it says not to
> use that function.

Heh. No, getValueID() returns '8' as the "ConstantIntVal" enum, not the 
actual argument number.

> Any other ideas what is the proper way to access the value '8' ?

It's a ConstantInt, so cast it and retrieve the APInt then pull out the 
number. Here:

   unsigned val;
   if (ConstantInt *CI = dyn_cast<ConstantInt>(v)) {
     val = CI->getValue()->getSExtValue();
   }

Nick



More information about the llvm-dev mailing list