Chuck Zhao
2011-Jan-19 16:24 UTC
[LLVMdev] know if individual LLVM's Instruction has a result, and how to obtain it?
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>
Duncan Sands
2011-Jan-19 16:53 UTC
[LLVMdev] know if individual LLVM's Instruction has a result, and how to obtain it?
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
Chuck Zhao
2011-Jan-19 17:10 UTC
[LLVMdev] know if individual LLVM's Instruction has a result, and how to obtain it?
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
Chuck Zhao
2011-Jan-19 17:11 UTC
[LLVMdev] know if individual LLVM's Instruction has a result, and how to obtain it?
Duncan, Thank you for the answer. I think it also makes sense for void return type function calls, as its result(s) will never be used. 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
Seemingly Similar Threads
- [LLVMdev] know if individual LLVM's Instruction has a result, and how to obtain it?
- [LLVMdev] Why function pointer is different from other data type?
- [LLVMdev] Why function pointer is different from other data type?
- [LLVMdev] What are all the LLVM IRs that will write into memory?
- RFC: Add "operand bundles" to calls and invokes