[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 09:10:30 PST 2011
Duncan,
I think your answer.
I think also makes sense for void return type function calls, as its
result(s) will never be used.
Thank you again
Chuck
On 1/19/2011 11:53 AM, Duncan Sands wrote:
> Hi Chuck,
>
>> 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?
> the instruction is the result! So everywhere you though you needed to use
> Instruction->getResult(), just use Instruction. Thus your question about
> whether there is a result field doesn't make sense. The closest thing is
> probably: the instruction does not have void type.
>
> Ciao, Duncan.
>
>> 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
>>
>>
>>
>>
>>
>>
>> _______________________________________________
>> LLVM Developers mailing list
>> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
More information about the llvm-dev
mailing list