[LLVMdev] know if individual LLVM's Instruction has a result, and how to obtain it?

Chuck Zhao czhao at eecg.toronto.edu
Wed Jan 19 08:24:48 PST 2011


Most LLVM IR instructions have a result field, according to the Language 
Reference.

I want to know, for all LLVM Instructions, is there an easy and 
consistent way to know if the current Inst has a result field?
And if yes, what is the best way to obtain it?

E.g.:

   <result>  = add<ty>  <op1>,<op2>           /; yields {ty}:result

/

All ADD instruction will have a result field, regardless of whether its 
result is used.

I checked the source code for Instruction.h/.cpp, getOperand(int) is for 
obtaining the operands only. There is no dedicated method to obtain the 
result.
{I was expecting something like Instruction->getResult().}


Instruction * Inst;
...
Value * Res = Inst;

Is the above the right way to do the work?

For an other example:

  <result>  = [tail] call [cconv  <http://llvm.org/docs/LangRef.html#callingconv>] [ret attrs  <http://llvm.org/docs/LangRef.html#paramattrs>]<ty>  [<fnty>*]<fnptrval>(<function args>) [fn attrs  <http://llvm.org/docs/LangRef.html#fnattrs>]


According to the LLVM Language reference, CallInst should always have a 
result.
But for void bar(int) types, there will be no return. So the generated 
IR will be similar to:

   call void @bar(i32 %2) nounwind

instead of

   %3 = call void @bar(i32 %2) nounwind

How can I handle this or similar case?

Are there special handling for certain Instructions? (E.g. LoadInst, 
StoreInst, etc.)

Thank you very much

Chuck




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110119/e8e68530/attachment.html>


More information about the llvm-dev mailing list