Skip to content

Commit

Permalink
Better ordering of LLVM blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
dstogov committed Feb 27, 2025
1 parent f590a65 commit 9b2a0ac
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion ir_load_llvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1862,7 +1862,13 @@ static int llvm2ir_func_ex(ir_ctx *ctx, LLVMValueRef func, LLVMModuleRef module,
opcode = LLVMGetInstructionOpcode(insn);
if (opcode == LLVMBr || opcode == LLVMSwitch) {
n = LLVMGetNumSuccessors(insn);
for (j = 0; j < n; j++) {
/*
* LLVM BB Successors are not aspecially ordered, but processing them in reverse order
* leads to the better result (closer to the original and keeping loop blocks together).
*/
j = n;
while (j > 0) {
j--;
succ = ir_addrtab_find(&bb_hash, (uintptr_t)LLVMGetSuccessor(insn, j));
IR_ASSERT(succ < bb_count);
if (ir_worklist_push(&worklist, succ)) {
Expand Down

0 comments on commit 9b2a0ac

Please sign in to comment.