Susan Horwitz
2009-Sep-08 21:46 UTC
[LLVMdev] how to change one operand of an LLVM instruction
I am trying to implement node splitting to transform irreducible CFGS to reducible ones. This means making copies of some basic blocks, which in turn means making copies of individual instructions. I can use the "clone" function to make an exact copy, but then I need to change some operands. For example, when I copy %1 = ... %2 = add %1, 5 I get %3 = ... %4 = add %1, 5 and I need to change the %1 operand in the copy to be %3. The only way I see to do this is to create a new instruction instead of a clone, using a big switch on the opcode (since different instructions' constructors have different parameters). Anyone know of an easier way to do this?
Chris Lattner
2009-Sep-08 21:55 UTC
[LLVMdev] how to change one operand of an LLVM instruction
On Sep 8, 2009, at 2:46 PM, Susan Horwitz wrote:> I am trying to implement node splitting to transform irreducible > CFGS to > reducible ones. This means making copies of some basic blocks, > which in > turn means making copies of individual instructions. I can use the > "clone" function to make an exact copy, but then I need to change some > operands. For example, when I copy > %1 = ... > %2 = add %1, 5 > > I get > %3 = ... > %4 = add %1, 5 > > and I need to change the %1 operand in the copy to be %3. > > The only way I see to do this is to create a new instruction instead > of a > clone, using a big switch on the opcode (since different instructions' > constructors have different parameters).Hi Susan, Because LLVM IR is in SSA form, you shouldn't think of the "name" (like %2) as being a property of the instruction... the name *is* the instruction. If you need to duplicate blocks like this, you should probably demote the cross-block values to memory (using the reg2mem utilities), perform your transformation, then use the mem2reg pass to eliminate the temporary memory accesses and reconstruct SSA form. One example pass that does this is lib/Transforms/Scalar/ JumpThreading.cpp. Search for "DemoteRegToStack". -Chris
Tanya Lattner
2009-Sep-08 21:57 UTC
[LLVMdev] how to change one operand of an LLVM instruction
On Sep 8, 2009, at 2:46 PM, Susan Horwitz wrote:> I am trying to implement node splitting to transform irreducible > CFGS to > reducible ones. This means making copies of some basic blocks, > which in > turn means making copies of individual instructions. I can use the > "clone" function to make an exact copy, but then I need to change some > operands. For example, when I copy > %1 = ... > %2 = add %1, 5 > > I get > %3 = ... > %4 = add %1, 5 > > and I need to change the %1 operand in the copy to be %3. > > The only way I see to do this is to create a new instruction instead > of a > clone, using a big switch on the opcode (since different instructions' > constructors have different parameters). > > Anyone know of an easier way to do this? >Are you using CloneBasicBlock? If so, you should pass it a ValueMap. You can then iterate over the instructions in the new basicblock and update the instruction operand references. Check out CloneFunction.cpp for some examples. -Tanya> _______________________________________________ > 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/20090908/d2a47689/attachment.html>
Apparently Analagous Threads
- [LLVMdev] Irreducible CFG from tail duplication
- [LLVMdev] Irreducible CFG from tail duplication
- [LLVMdev] problem trying to write an LLVM register-allocation pass
- [LLVMdev] problem trying to write an LLVM register-allocation pass
- [LLVMdev] problem trying to write an LLVM register-allocation pass