Skip to content

Commit

Permalink
minor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike-Leo-Smith committed Jan 10, 2025
1 parent f1b1c56 commit 0103272
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/backends/fallback/fallback_codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3203,6 +3203,24 @@ class FallbackCodegen {
}
// translate body
static_cast<void>(_translate_basic_block(current, f->body_block()));
// we should hoist all alloca instructions to the beginning of the function
{
luisa::vector<llvm::AllocaInst *> alloca_insts;
for (auto &&llvm_bb : *llvm_func) {
for (auto &&llvm_inst : llvm_bb) {
if (auto alloca_inst = llvm::dyn_cast<llvm::AllocaInst>(&llvm_inst)) {
alloca_insts.emplace_back(alloca_inst);
}
}
}
// reverse the order of alloca instructions for better readability
std::reverse(alloca_insts.begin(), alloca_insts.end());
// move alloca instructions to the beginning of the function
auto &llvm_entry = llvm_func->getEntryBlock();
for (auto inst : alloca_insts) {
inst->moveBefore(&llvm_entry.front());
}
}
// return
return llvm_func;
}
Expand Down

0 comments on commit 0103272

Please sign in to comment.