Merge pull request #1 from drcut/MICRO_dev

fix bug for AllocaInst that are wrapped in a PR
This commit is contained in:
Ruobing Han 2023-04-01 17:08:50 -04:00 committed by GitHub
commit 50d615da64
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 0 deletions

View File

@ -319,6 +319,7 @@ void handle_local_variable_intra_warp(std::vector<ParallelRegion> PRs,
// we should handle allocation generated by PHI // we should handle allocation generated by PHI
{ {
std::vector<llvm::Instruction *> instruction_to_fix; std::vector<llvm::Instruction *> instruction_to_fix;
std::vector<llvm::AllocaInst *> instruction_to_move;
auto F = PRs[0].start_block->getParent(); auto F = PRs[0].start_block->getParent();
for (auto bb = F->begin(); bb != F->end(); bb++) { for (auto bb = F->begin(); bb != F->end(); bb++) {
for (auto ii = bb->begin(); ii != bb->end(); ii++) { for (auto ii = bb->begin(); ii != bb->end(); ii++) {
@ -343,6 +344,7 @@ void handle_local_variable_intra_warp(std::vector<ParallelRegion> PRs,
} }
} }
if (allStoreNonDivergence) { if (allStoreNonDivergence) {
instruction_to_move.push_back(alloc);
continue; continue;
} }
// Do not duplicate var used outside PRs // Do not duplicate var used outside PRs
@ -366,6 +368,8 @@ void handle_local_variable_intra_warp(std::vector<ParallelRegion> PRs,
} }
if (!used_in_non_PR) { if (!used_in_non_PR) {
instruction_to_fix.push_back(alloc); instruction_to_fix.push_back(alloc);
} else {
instruction_to_move.push_back(alloc);
} }
} }
} }
@ -373,6 +377,18 @@ void handle_local_variable_intra_warp(std::vector<ParallelRegion> PRs,
for (auto inst : instruction_to_fix) { for (auto inst : instruction_to_fix) {
AddContextSaveRestore(inst, intra_warp_loop); AddContextSaveRestore(inst, intra_warp_loop);
} }
for (auto alloc : instruction_to_move) {
// need to move all allocInst to the entry basic block
IRBuilder<> builder(&*(alloc->getParent()
->getParent()
->getEntryBlock()
.getFirstInsertionPt()));
auto newAllocInst =
builder.CreateAlloca(alloc->getType()->getElementType(),
alloc->getArraySize(), alloc->getName());
alloc->replaceAllUsesWith(newAllocInst);
alloc->removeFromParent();
}
} }
for (auto parallel_regions : PRs) { for (auto parallel_regions : PRs) {