Xiaoguang Wang
2014-Oct-29 21:24 UTC
[LLVMdev] Emit a jump instruction to a place inside basicblock
Hi all, I'm a beginner in LLVM. Currently, I want to implement a pass that generates a jump table. The entry in that table is a jump to some place (may be an instruction) in a basic block. I'm reading the JumpTable code in llvm 3.5, there is a table which contains jump entries to functions. In AsmPrinter::doFinalization function from file lib/CodeGen/AsmPrinter/AsmPrinter.cpp, it gets a MCSymbolRefExpr from the function symbol. While my question is, is there a way to insert jump to place inside a basic block? Thanks! Xiaoguang -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20141029/91517789/attachment.html>
serge Guelton
2014-Oct-30 07:46 UTC
[LLVMdev] Emit a jump instruction to a place inside basicblock
On Wed, Oct 29, 2014 at 05:24:37PM -0400, Xiaoguang Wang wrote:> Hi all, > > I'm a beginner in LLVM. Currently, I want to implement a pass that generates a > jump table. The entry in that table is a jump to some place (may be an > instruction) in a basic block. > > I'm reading the JumpTable code in llvm 3.5, there is a table which contains > jump entries to functions. In AsmPrinter::doFinalization function from file > lib/CodeGen/AsmPrinter/AsmPrinter.cpp, it gets a MCSymbolRefExpr from the > function symbol. > > While my question is, is there a way to insert jump to place inside a basic > block? > > Thanks!ISTM you can split a basic bloc in two using ``llvm::SplitBlock'' then jump to the begining of the second part?
Robin Morisset
2014-Oct-30 18:33 UTC
[LLVMdev] Emit a jump instruction to a place inside basicblock
Hi,>From my understanding of the LLVM IR, it is impossible to jump to themiddle of a Basic Block, only to its beginning. But there is a splitBasicBlock function that seems like it might be useful to you, to make sure a basic block is starting at the exact place you want to jump. Best regards, Robin On Wed Oct 29 2014 at 2:28:09 PM Xiaoguang Wang <xgwang09 at gmail.com> wrote:> Hi all, > > I'm a beginner in LLVM. Currently, I want to implement a pass that > generates a jump table. The entry in that table is a jump to some place > (may be an instruction) in a basic block. > > I'm reading the JumpTable code in llvm 3.5, there is a table which > contains jump entries to functions. In AsmPrinter::doFinalization function > from file lib/CodeGen/AsmPrinter/AsmPrinter.cpp, it gets a MCSymbolRefExpr > from the function symbol. > > While my question is, is there a way to insert jump to place inside a > basic block? > > Thanks! > > Xiaoguang > _______________________________________________ > 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/20141030/174c96d6/attachment.html>
Xiaoguang Wang
2014-Oct-30 20:13 UTC
[LLVMdev] Emit a jump instruction to a place inside basicblock
On Thu, Oct 30, 2014 at 2:33 PM, Robin Morisset <morisset at google.com> wrote:> Hi, > > From my understanding of the LLVM IR, it is impossible to jump to the > middle of a Basic Block, only to its beginning. But there is a > splitBasicBlock function that seems like it might be useful to you, to make > sure a basic block is starting at the exact place you want to jump. > > Best regards, > Robin >Thanks you all! I'm looking at splitBasicBlock and trying to use that. BTW, is there a way at lower level of LLVM that can implement this functionality? E.g. MCBasicBlock or MCInst? Sincerely, Xiaoguang -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20141030/78d378da/attachment.html>
Xiaoguang Wang
2014-Nov-10 16:46 UTC
[LLVMdev] Emit a jump instruction to a place inside basicblock
On Thu, Oct 30, 2014 at 3:46 AM, serge Guelton < serge.guelton at enst-bretagne.fr> wrote:> On Wed, Oct 29, 2014 at 05:24:37PM -0400, Xiaoguang Wang wrote: > > Hi all, > > > > I'm a beginner in LLVM. Currently, I want to implement a pass that > generates a > > jump table. The entry in that table is a jump to some place (may be an > > instruction) in a basic block. > > > > I'm reading the JumpTable code in llvm 3.5, there is a table which > contains > > jump entries to functions. In AsmPrinter::doFinalization function from > file > > lib/CodeGen/AsmPrinter/AsmPrinter.cpp, it gets a MCSymbolRefExpr from the > > function symbol. > > > > While my question is, is there a way to insert jump to place inside a > basic > > block? > > > > Thanks! > > ISTM you can split a basic bloc in two using ``llvm::SplitBlock'' then > jump to the begining of the second part? >Hi, I tried splitBasicBlock after the specific place in IR, and saved the newly created BasicBlock*. This works well to create a basic block with a LABEL to jump back. Then I modified the doFinalization method in AsmPrinter to add a jump instruction to the LABEL. The result is it can create the jump to the LABEL, but the LABEL just disappeared. It is like: *The original IR before I use splitBasicBlock:* entry: %call = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([8 x i8]* @.str, i32 0, i32 0)) ret i32 0 *The transformed IR code by using splitBasicBlock:* entry: %call = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([8 x i8]* @.str, i32 0, i32 0)) br label %RET_TABLE_0 RET_TABLE_0: ; preds = %entry ret i32 0 *The final assembly when I modified AsmPrinter:doFinalization to print the jump instruction back to LABEL:* calll printf movl %eax, -4(%ebp) # 4-byte Spill # BB#1: # %.RET_TABLE_0 movl $0, %eax ... ... .align 8, 0x90 __LLVM_RET_TABLE_0: jmp .RET_TABLE_0 So the LLVM will optimize this branch in the pass? Can I disable this optimization or is there other way to reserve the LABEL? -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20141110/d36c0b74/attachment.html>
Seemingly Similar Threads
- [LLVMdev] Emit a jump instruction to a place inside basicblock
- [LLVMdev] Emit a jump instruction to a place inside basicblock
- [LLVMdev] Question about jumptable and indirect function call.
- How jump-table representated in DAG
- [LLVMdev] Regarding BasicBlock Cloning