Hi, I want to copy some dependent statements, like a = b, b = c, from one basicblock to another basicblocks. Because of SSA, a = b, will be like %1 = load %b, store %1, %a. If I just use clone() method in Instruction class, it will be like <badref> = load %b, store <badref>, %a. If I need remap the virtual registers, this map just will affect the whole module? And how to use it? I am a bit confused. Any suggestion will be appreciated. Best, Yuxi Uchicago -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150711/6e11f71a/attachment.html>
I'm Just a beginner so i may be wrong. Does Block Insert work? Create a new block with your instructions with (new BasicBlock) and (new BranchInst) , split using SplitBlock and insert. http://stackoverflow.com/questions/13275577/inserting-a-block-between-two-blocks-in-llvm If it is possible to just add instructions, can someone please suggest how this can be done. It must be possible for inline function instructions. Thank You. On Sat, Jul 11, 2015 at 11:13:16PM +0000, Yuxi Chen wrote:> Hi, > > I want to copy some dependent statements, like a = b, b = c, from one basicblock to another basicblocks. > Because of SSA, a = b, will be like %1 = load %b, store %1, %a. > If I just use clone() method in Instruction class, it will be like <badref> = load %b, store <badref>, %a. > If I need remap the virtual registers, this map just will affect the whole module? And how to use it? I am a bit confused. > > Any suggestion will be appreciated. > > Best, > Yuxi > Uchicago> _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev-- keutoi(k3ut0i) pub fpr D04E 573D 360D 8209 3261 550E 39BE 6531 C533 FD20 -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150712/8f7c6f91/attachment.sig>
I'm Just a beginner so i may be wrong. Does Block Insert work? Create a new block with your instructions with (new BasicBlock) and (new BranchInst) , split using SplitBlock and insert. http://stackoverflow.com/questions/13275577/inserting-a-block-between-two-blocks-in-llvm If it is possible to just add instructions, can someone please suggest how this can be done. It must be possible for inline function instructions. Thank You. On Sat, Jul 11, 2015 at 11:13:16PM +0000, Yuxi Chen wrote:> Hi, > > I want to copy some dependent statements, like a = b, b = c, from one basicblock to another basicblocks. > Because of SSA, a = b, will be like %1 = load %b, store %1, %a. > If I just use clone() method in Instruction class, it will be like <badref> = load %b, store <badref>, %a. > If I need remap the virtual registers, this map just will affect the whole module? And how to use it? I am a bit confused. > > Any suggestion will be appreciated. > > Best, > Yuxi > Uchicago> _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev-- keutoi(k3ut0i) pub fpr D04E 573D 360D 8209 3261 550E 39BE 6531 C533 FD20 -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150712/dd0d9c0a/attachment.sig>
Hi Yuxi, Yes, you need to remap virtual registers. In your example, the clone of "store %1, %a" still uses the old %1 right after cloning, so you need to set the first operand to the clone of "load %b". You may want to mimic llvm::CloneFunctionInto <http://llvm.org/docs/doxygen/html/CloneFunction_8cpp_source.html#l00077>. In particular, CloneBasicBlock clones instructions in a basic block and creates a mapping from original to cloned. Then, RemapInstruction applies the mapping to the operands of the cloned instructions. Jingyue On Sat, Jul 11, 2015 at 4:15 PM Yuxi Chen <chenyuxi at uchicago.edu> wrote:> Hi, > > I want to copy some dependent statements, like a = b, b = c, from one > basicblock to another basicblocks. > Because of SSA, a = b, will be like %1 = load %b, store %1, %a. > If I just use clone() method in Instruction class, it will be like > <badref> = load %b, store <badref>, %a. > If I need remap the virtual registers, this map just will affect the whole > module? And how to use it? I am a bit confused. > > Any suggestion will be appreciated. > > Best, > Yuxi > Uchicago > _______________________________________________ > 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/20150712/c98a8062/attachment.html>
Dear Yuxi, I haven't used the clone() method of the Instruction class, but if I had to guess, the problem is that you're not changing the operands of the new instructions to reference the new instructions. When you clone an instruction, the operands of the new instruction are identical to the operands of the old instruction. In your example, if you clone the store, the store is still referencing %1 from the original LoadInst in the original basic block. You need to change the new store's operand to be the new LoadInst that you created in your new BasicBlock. You may also want to look at the llvm::CloneBasicBlock() function. This utility function clones basic blocks; you can take a look at what it does and see how it works. Regards, John Criswell On 7/11/15 6:13 PM, Yuxi Chen wrote:> Hi, > > I want to copy some dependent statements, like a = b, b = c, from one > basicblock to another basicblocks. > Because of SSA, a = b, will be like %1 = load %b, store %1, %a. > If I just use clone() method in Instruction class, it will be like > <badref> = load %b, store <badref>, %a. > If I need remap the virtual registers, this map just will affect the > whole module? And how to use it? I am a bit confused. > > Any suggestion will be appreciated. > > Best, > Yuxi > Uchicago > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev-- John Criswell Assistant Professor Department of Computer Science, University of Rochester http://www.cs.rochester.edu/u/criswell -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150712/2d3746d3/attachment.html>
Hi Keutoi, Thanks for your reply. I get your point. But the problem when you copy instuctions, you need to remap the virtual register. A naive way is to keep a map of old virtual registers and new virtual registers, then iterate all cloned instruction, replace the old virtual registers with new virtual registers. Thanks again. Yuxi ________________________________________ From: keutoi [k3ut0i at gmail.com] Sent: Sunday, July 12, 2015 3:24 AM To: Yuxi Chen Subject: Re: [LLVMdev] instructions copy I'm Just a beginner so i may be wrong. Does Block Insert work? Create a new block with your instructions with (new BasicBlock) and (new BranchInst) , split using SplitBlock and insert. http://stackoverflow.com/questions/13275577/inserting-a-block-between-two-blocks-in-llvm If it is possible to just add instructions, can someone please suggest how this can be done. It must be possible for inline function instructions. Thank You. On Sat, Jul 11, 2015 at 11:13:16PM +0000, Yuxi Chen wrote:> Hi, > > I want to copy some dependent statements, like a = b, b = c, from one basicblock to another basicblocks. > Because of SSA, a = b, will be like %1 = load %b, store %1, %a. > If I just use clone() method in Instruction class, it will be like <badref> = load %b, store <badref>, %a. > If I need remap the virtual registers, this map just will affect the whole module? And how to use it? I am a bit confused. > > Any suggestion will be appreciated. > > Best, > Yuxi > Uchicago> _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev-- keutoi(k3ut0i) pub fpr D04E 573D 360D 8209 3261 550E 39BE 6531 C533 FD20
Hi Jingyue, Thanks for your reply. Yep, I just mimic some programming like llvm::CloneFUnctionInto. It works. Best, Yuxi ________________________________ From: Jingyue Wu [jingyue at google.com] Sent: Sunday, July 12, 2015 11:55 AM To: Yuxi Chen Cc: LLVM Developers Mailing List Subject: Re: [LLVMdev] instructions copy Hi Yuxi, Yes, you need to remap virtual registers. In your example, the clone of "store %1, %a" still uses the old %1 right after cloning, so you need to set the first operand to the clone of "load %b". You may want to mimic llvm::CloneFunctionInto<http://llvm.org/docs/doxygen/html/CloneFunction_8cpp_source.html#l00077>. In particular, CloneBasicBlock clones instructions in a basic block and creates a mapping from original to cloned. Then, RemapInstruction applies the mapping to the operands of the cloned instructions. Jingyue On Sat, Jul 11, 2015 at 4:15 PM Yuxi Chen <chenyuxi at uchicago.edu<mailto:chenyuxi at uchicago.edu>> wrote: Hi, I want to copy some dependent statements, like a = b, b = c, from one basicblock to another basicblocks. Because of SSA, a = b, will be like %1 = load %b, store %1, %a. If I just use clone() method in Instruction class, it will be like <badref> = load %b, store <badref>, %a. If I need remap the virtual registers, this map just will affect the whole module? And how to use it? I am a bit confused. Any suggestion will be appreciated. Best, Yuxi Uchicago _______________________________________________ LLVM Developers mailing list LLVMdev at cs.uiuc.edu<mailto: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/20150713/d2638891/attachment.html>
Hi John, I really appreciate your reply. Right now, I write some programming like CloneBasicBlock(), it works. Thanks, Yuxi ________________________________ From: John Criswell [jtcriswel at gmail.com] Sent: Sunday, July 12, 2015 11:59 AM To: Yuxi Chen; llvmdev at cs.uiuc.edu Cc: llvmdev-bounces at cs.uiuc.edu Subject: Re: [LLVMdev] instructions copy Dear Yuxi, I haven't used the clone() method of the Instruction class, but if I had to guess, the problem is that you're not changing the operands of the new instructions to reference the new instructions. When you clone an instruction, the operands of the new instruction are identical to the operands of the old instruction. In your example, if you clone the store, the store is still referencing %1 from the original LoadInst in the original basic block. You need to change the new store's operand to be the new LoadInst that you created in your new BasicBlock. You may also want to look at the llvm::CloneBasicBlock() function. This utility function clones basic blocks; you can take a look at what it does and see how it works. Regards, John Criswell On 7/11/15 6:13 PM, Yuxi Chen wrote: Hi, I want to copy some dependent statements, like a = b, b = c, from one basicblock to another basicblocks. Because of SSA, a = b, will be like %1 = load %b, store %1, %a. If I just use clone() method in Instruction class, it will be like <badref> = load %b, store <badref>, %a. If I need remap the virtual registers, this map just will affect the whole module? And how to use it? I am a bit confused. Any suggestion will be appreciated. Best, Yuxi Uchicago _______________________________________________ LLVM Developers mailing list LLVMdev at cs.uiuc.edu<mailto:LLVMdev at cs.uiuc.edu> http://llvm.cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev -- John Criswell Assistant Professor Department of Computer Science, University of Rochester http://www.cs.rochester.edu/u/criswell -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150713/f5733234/attachment.html>