[LLVMdev] Figuring out the parameters of the Call Instruction

Duncan Sands baldrick at free.fr
Fri Jul 16 08:57:16 PDT 2010

Hi Shankha,

> %1 = load a;
> %2 = load b;
> call foo(%1, %2)
> call bar(@var1)
> CallInst.getOperand(1).getNameStr() on foo, returns null,
> but on bar returns var1.

names are of no interest.  They are only there to help developers
see where the IR may have come from in the original source code,
and cannot be relied upon to exist.

> CallInst.getOperand(1).getNameStr(),  return abc and type returns i64,
> How do I figure the operand is a const expression and a cast operator
> was used to generate it.

You can determine if it is a constant expression by

If it is a constant expression, you determine if it is a cast by

These can be combined into
   if (ConstantExpr *CE = dyn_cast<ConstantExpr>(CallInst.getOperand(1)))
     if (CE->isCast())

> More generally, When I use Instruction iterator on BasicBlock, I get
> the RHS of instruction
> but not  the LHS.

There is no LHS, the apparent LHS in the human readable IR is only there to
make it easier for humans to read.

How do I get name of nameless LHS registers(%1, %2).

They don't have a name, but you don't need one: just use the instruction

> C Code :    p_ptr ((unsigned long)&abc);
> LLVM IR : call void @p_ptr(i64 ptrtoint (%struct.my_struct* @abc to
> i64)) nounwind, !dbg !52
> I think by the call CI->getArgOperand(0) you mean CI->getOperand(0).

Probably getArgOperand doesn't exist in the version of LLVM you are using:
it was only introduced recently.  In older versions you probably want
CI->getOperand(1) since operand 0 is the callee IIRC.

> That doesn't return the ptrtoint constant expression. The CI instruction
> has shows two operands.  The first operand is the function name.

The first operand is the function (not the function name).

> second operand
> prints NULL.

Try CI->getOperand(1)->dump()



More information about the llvm-dev mailing list