weixuegong
2013-Sep-30 07:15 UTC
[LLVMdev] Will it be slow much if a lot of BasicBlock been created?
Hi, all I am doing some work about instruction translating. and the IR is sort of:(whatever it is) %v1 = alloca i32 store i32 10, i32* %v1 %v0 = alloca i32 store i32 0, i32* %v0 %0 = load i32* %v0 %1 = add i32 %0, 1 store i32 %1, i32* %v0 %2 = load i32* %v1 %3 = add i32 %2, -1 store i32 %3, i32* %v1 %4 = load i32* %v0 ret i32 %4 I want to know that if I create a basic block for every instruction in IR, like: Label0: ; No predecessors! %v1 = alloca i32 store i32 10, i32* %v1 Label2: ; No predecessors! %v0 = alloca i32 store i32 0, i32* %v0 Label3: ; preds = %Label9 Label5: ; No predecessors! %0 = load i32* %v0 %1 = add i32 %0, 1 store i32 %1, i32* %v0 Label7: ; No predecessors! %2 = load i32* %v1 %3 = add i32 %2, -1 store i32 %3, i32* %v1 Label9: ; No predecessors! br label %Label3 Label10: ; No predecessors! %4 = load i32* %v0 ret i32 %4 Will it be slow too much than before OR make no difference? What is BasicBlock treated as in llvm? Just an address of bitcode or a kind of structure which contained some informations? Any suggestion will be appreciated. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130930/c82ea7b1/attachment.html>
Tim Northover
2013-Sep-30 07:38 UTC
[LLVMdev] Will it be slow much if a lot of BasicBlock been created?
Hi,> Will it be slow too much than before OR make no difference?It's likely to have significant impact.> What is BasicBlock treated as in llvm? Just an address of bitcode or a kind > of structure which contained some informations?It's got structure. Each basic block has to end with an explicit branching instruction to its followers ("br i1 %nextLabel" in your case, by the looks of it), and many optimisation passes may well stop at their boundaries. The backend also does virtually all of its instruction-selection at a purely basic-block level; very few IR-level instructions will be combined into a single target-instruction if they occur in different blocks. Finally, alloca instructions are only well-optimised if they occur in the first basic-block of a function. This optimisation (mem2reg) is key to making many others effective, even if they are willing to look beyond a single basic-block. That said, there are passes which recombine basic-blocks. If you only want to separate them for the convenience of implementing your own pass then you may be able to avoid most of these bad effects by running appropriate cleanup passes afterwards that undo it. Cheers. Tim.