seventh moon
2009-May-05 14:00 UTC
[LLVMdev] A problem creating operands for a new IR instruction to the mailing list
I have a question about inserting instructions into the LLVM IR. I can insert instructions, but my operands do not have the right type, so it fails an assertion at runtime. I am trying to insert an immediate load instructions, as a means of claiming a new register. Here is what I do: Builder.SetInsertPoint(LLVMBB, I); // The following line looks to me like it would have a chance of loading either // address 5, or else immediate value 5. Unfortunately, it does neither. It compiles // but crashes at runtime, that the type of the operand is incompatible Instruction *newI=Builder.CreateLoad(5,""); // I also tested this, just to do a little sanity check. It also compiles then // crashes, for the obvious reason that the operand is a register, but an address // or an immediate value is expected. //Instruction *newI=Builder.CreateLoad(I->getOperand(1),""); // also wrong So to say it simply, my question is, "How can I create a new Value*, which indicates an immediate value, such as immediate value 5?" Thank you for your assistance, Kao Chang _________________________________________________________________ 用部落格分享照片、影音、趣味小工具和最愛清單,盡情秀出你自己 — Windows Live Spaces http://home.spaces.live.com/?showUnauth=1&lc=1028 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20090505/1affa5a3/attachment.html>
To"ro"k Edwin
2009-May-05 14:07 UTC
[LLVMdev] A problem creating operands for a new IR instruction to the mailing list
On 2009-05-05 17:00, seventh moon wrote:> I have a question about inserting instructions into the LLVM IR. I can > insert instructions, but my operands do not have the right type, so it > fails an assertion at runtime. > > I am trying to insert an immediate load instructions, as a means of > claiming a new register. > > Here is what I do: > Builder.SetInsertPoint(LLVMBB, I); > > // The following line looks to me like it would have a chance o! f > loading either > // address 5, or else immediate value 5. Unfortunately, it does > neither. It compiles > // but crashes at runtime, that the type of the operand is incompatible > Instruction *newI=Builder.CreateLoad(5,""); > > // I also tested this, just to do a little sanity check. It also > compiles then > // crashes, for the obvious reason that the operand is a register, but > an address > // or an immediate value is expected. > //Instruction *newI=Builder.CreateLoad(I->getOperand(1),""); // also > wrong > > So to say it simply, my question is, "How can I create a new Value*, > which indicates > an immediate value, such as immediate value 5?"You should use a constant instead of a load: Constant *C = ConstantInt::get(Type::Int32Ty, 5); Note that the constant is not an instruction, but it can be used like any other Value*. Best regards, --Edwin
Olivier Meurant
2009-May-05 14:07 UTC
[LLVMdev] A problem creating operands for a new IR instruction to the mailing list
If you want an immediate constant value, ConstantInt::get(APInt(32, 5, false)) will perhaps help you ? Olivier. 2009/5/5 seventh moon <suigintou_ at hotmail.com>> I have a question about inserting instructions into the LLVM IR. I can > insert instructions, but my operands do not have the right type, so it fails > an assertion at runtime. > > I am trying to insert an immediate load instructions, as a means of > claiming a new register. > > Here is what I do: > Builder.SetInsertPoint(LLVMBB, I); > > // The following line looks to me like it would have a chance o! f loading > either > // address 5, or else immediate value 5. Unfortunately, it does neither. It > compiles > // but crashes at runtime, that the type of the operand is incompatible > Instruction *newI=Builder.CreateLoad(5,""); > > // I also tested this, just to do a little sanity check. It also compiles > then > // crashes, for the obvious reason that the operand is a register, but an > address > // or an immediate value is expected. > //Instruction *newI=Builder.CreateLoad(I->getOperand(1),""); // > also wrong > > So to say it simply, my question is, "How can I create a new Value*, which > indicates > an immediate value, such as immediate value 5?" > > Thank you for your assistance, > Kao Chang > ------------------------------ > 用部落格分享照片、影音、趣味小工具和最愛清單,盡情秀出! 你自己 — Windows Live Spaces<http://home.spaces.live.com/?showUnauth=1&lc=1028> > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20090505/ba9c9881/attachment.html>
John Criswell
2009-May-05 16:42 UTC
[LLVMdev] A problem creating operands for a new IR instruction to the mailing list
seventh moon wrote:> [snip] > > So to say it simply, my question is, "How can I create a new Value*, which indicates > an immediate value, such as immediate value 5?" >I don't know much about LLVM's code generators, but if all you need is to create a Value * for an immediate constant, you might try using the ConstantInt::get() method (http://llvm.org/doxygen/classllvm_1_1ConstantInt.html#77cd822480bc78732c84a9619e49e14a). A ConstantInt is a subclass of Value, and you can use it to create constant integer values in the LLVM IR. -- John T.
seventh moon
2009-May-06 03:59 UTC
[LLVMdev] A problem creating operands for a new IR instruction to the mailing list
Thank you for your answer. But there is still a problem. You seem correct about how to define a constant operand. So I added it into my code, like so: Builder.SetInsertPoint(LLVMBB, I); Constant *C = ConstantInt::get(APInt(32, 5, false)); Instruction *newI=Builder.CreateLoad(C,""); It compiles. But it still aborts at runtime with a complaint that the type is not right. This leads me to think that immediate loads are not generated with the CreateLoad instruction? Another person's reply to my question indicated that a way to avoid inserting the immediate load entirely; but that is also not what I want, because my explicit purpose in inserting this load is to claim a register. Thank you, Kao Chang Date: Tue, 5 May 2009 16:07:33 +0200 From: meurant.olivier at gmail.com To: llvmdev at cs.uiuc.edu Subject: Re: [LLVMdev] A problem creating operands for a new IR instruction to the mailing list If you want an immediate constant value, ConstantInt::get(APInt(32, 5, false)) will perhaps help you ? Olivier. 2009/5/5 seventh moon <suigintou_ at hotmail.com> I have a question about inserting instructions into the LLVM IR. I can insert instructions, but my operands do not have the right type, so it fails an assertion at runtime. I am trying to insert an immediate load instructions, as a means of claiming a new register. Here is what I do: Builder.SetInsertPoint(LLVMBB, I); // The following line looks to me like it would have a chance o! f loading either // address 5, or else immediate value 5. Unfortunately, it does neither. It compiles // but crashes at runtime, that the type of the operand is incompatible Instruction *newI=Builder.CreateLoad(5,""); // I also tested this, just to do a little sanity check. It also compiles then // crashes, for the obvious reason that the operand is a register, but an address // or an immediate value is expected. //Instruction *newI=Builder.CreateLoad(I->getOperand(1),""); // also wrong So to say it simply, my question is, "How can I create a new Value*, which indicates an immediate value, such as immediate value 5?" Thank you for your assistance, Kao Chang 用部落格分享照片、影音、趣味小工具和最愛清單,盡情秀出! 你自己 — Windows Live Spaces _______________________________________________ LLVM Developers mailing list LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev _________________________________________________________________ 隨身的 Windows Live Messenger 和 Hotmail,不限時地掌握資訊盡在指間 — Windows Live for Mobile http://3c.msn.com.tw/mobile/ -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20090506/3a96d73d/attachment.html>
Possibly Parallel Threads
- [LLVMdev] A problem creating operands for a new IR instruction to the mailing list
- [LLVMdev] A problem creating operands for a new IR instruction to the mailing list
- [LLVMdev] A question about printout the SeletionDAG
- [LLVMdev] how can I compile an ARM assembly file produced by llc into ARM binary ?
- [LLVMdev] Need help in converting int to double