Trevor Harmon
2010-Oct-21 00:16 UTC
[LLVMdev] Splitting basic blocks while preserving machine code
Hi, I'm writing a pass that does some static analysis on C code. A critical requirement of the pass is that it must preserve not only the correctness of the code but also its timing -- It cannot add or remove even one CPU cycle from the resulting machine code. To put it another way, the binary executable that is produced when the pass is present must be identical to what is produced when the pass is not present. That said, I have run into a situation where it would help to split certain basic blocks, probably by calling BasicBlock::splitBasicBlock. But this method adds an unconditional branch instruction. Would this new instruction alter the machine code that is later generated, or would the additional branch somehow be optimized away in subsequent passes? Thanks, Trevor
Jim Grosbach
2010-Oct-21 00:19 UTC
[LLVMdev] Splitting basic blocks while preserving machine code
On Oct 20, 2010, at 5:16 PM, Trevor Harmon wrote:> I'm writing a pass that does some static analysis on C code. A > critical requirement of the pass is that it must preserve not only the > correctness of the code but also its timing -- It cannot add or remove > even one CPU cycle from the resulting machine code. To put it another > way, the binary executable that is produced when the pass is present > must be identical to what is produced when the pass is not present. > > That said, I have run into a situation where it would help to split > certain basic blocks, probably by calling BasicBlock::splitBasicBlock. > But this method adds an unconditional branch instruction. Would this > new instruction alter the machine code that is later generated, or > would the additional branch somehow be optimized away in subsequent > passes?It probably would be optimized away, yes, but I would recommend against counting on it with requirements as strict as yours. -Jim
Kenneth Uildriks
2010-Oct-21 00:26 UTC
[LLVMdev] Splitting basic blocks while preserving machine code
On Wed, Oct 20, 2010 at 7:19 PM, Jim Grosbach <grosbach at apple.com> wrote:> > On Oct 20, 2010, at 5:16 PM, Trevor Harmon wrote: >> I'm writing a pass that does some static analysis on C code. A >> critical requirement of the pass is that it must preserve not only the >> correctness of the code but also its timing -- It cannot add or remove >> even one CPU cycle from the resulting machine code. To put it another >> way, the binary executable that is produced when the pass is present >> must be identical to what is produced when the pass is not present. >> >> That said, I have run into a situation where it would help to split >> certain basic blocks, probably by calling BasicBlock::splitBasicBlock. >> But this method adds an unconditional branch instruction. Would this >> new instruction alter the machine code that is later generated, or >> would the additional branch somehow be optimized away in subsequent >> passes? > > It probably would be optimized away, yes, but I would recommend against counting on it with requirements as strict as yours. > > -Jim > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >You could always undo the split right before your pass finishes.
Maybe Matching Threads
- [LLVMdev] Splitting basic blocks while preserving machine code
- [LLVMdev] Splitting basic blocks while preserving machine code
- [LLVMdev] Splitting a basic block creates an instruction without debug metadata
- [LLVMdev] Splitting basic blocks while preserving machine code
- [LLVMdev] Splitting a basic block creates an instruction without debug metadata