Skip to content

Commit 55f26dc

Browse files
authored
[MLIR][OpenMP] Remove sinking of loop index allocas (llvm#840)
2 parents 777317e + a7c6530 commit 55f26dc

File tree

1 file changed

+1
-59
lines changed

1 file changed

+1
-59
lines changed

mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -578,50 +578,6 @@ convertIgnoredWrapper(omp::LoopWrapperInterface opInst,
578578
});
579579
}
580580

581-
/// Populate a set of previously created llvm.alloca instructions that are only
582-
/// used inside of the given region but defined outside of it. Allocations of
583-
/// non-primitive types are skipped by this function.
584-
static void getSinkableAllocas(LLVM::ModuleTranslation &moduleTranslation,
585-
Region &region,
586-
SetVector<llvm::AllocaInst *> &allocasToSink) {
587-
Operation *op = region.getParentOp();
588-
589-
for (auto storeOp : region.getOps<LLVM::StoreOp>()) {
590-
Value storeAddr = storeOp.getAddr();
591-
Operation *addrOp = storeAddr.getDefiningOp();
592-
593-
// The destination address is already defined in this region or it is not an
594-
// llvm.alloca operation, so skip it.
595-
if (!isa_and_present<LLVM::AllocaOp>(addrOp) || op->isAncestor(addrOp))
596-
continue;
597-
598-
// Get LLVM value to which the address is mapped. It has to be mapped to the
599-
// allocation instruction of a scalar type to be marked as sinkable by this
600-
// function.
601-
llvm::Value *llvmAddr = moduleTranslation.lookupValue(storeAddr);
602-
if (!isa_and_present<llvm::AllocaInst>(llvmAddr))
603-
continue;
604-
605-
auto *llvmAlloca = cast<llvm::AllocaInst>(llvmAddr);
606-
if (llvmAlloca->getAllocatedType()->getPrimitiveSizeInBits() == 0)
607-
continue;
608-
609-
// Check that the address is only used inside of the region.
610-
bool addressUsedOnlyInternally = true;
611-
for (auto &addrUse : storeAddr.getUses()) {
612-
if (!op->isAncestor(addrUse.getOwner())) {
613-
addressUsedOnlyInternally = false;
614-
break;
615-
}
616-
}
617-
618-
if (!addressUsedOnlyInternally)
619-
continue;
620-
621-
allocasToSink.insert(llvmAlloca);
622-
}
623-
}
624-
625581
/// Converts an OpenMP 'masked' operation into LLVM IR using OpenMPIRBuilder.
626582
static LogicalResult
627583
convertOmpMasked(Operation &opInst, llvm::IRBuilderBase &builder,
@@ -2452,9 +2408,6 @@ convertOmpLoopNest(Operation &opInst, llvm::IRBuilderBase &builder,
24522408
// Set up the source location value for OpenMP runtime.
24532409
llvm::OpenMPIRBuilder::LocationDescription ompLoc(builder);
24542410

2455-
SetVector<llvm::AllocaInst *> allocasToSink;
2456-
getSinkableAllocas(moduleTranslation, loopOp.getRegion(), allocasToSink);
2457-
24582411
// Generator of the canonical loop body.
24592412
SmallVector<llvm::CanonicalLoopInfo *> loopInfos;
24602413
SmallVector<llvm::OpenMPIRBuilder::InsertPointTy> bodyInsertPoints;
@@ -2472,25 +2425,14 @@ convertOmpLoopNest(Operation &opInst, llvm::IRBuilderBase &builder,
24722425
if (loopInfos.size() != loopOp.getNumLoops() - 1)
24732426
return llvm::Error::success();
24742427

2475-
// Convert the body of the loop, adding lifetime markers to allocations that
2476-
// can be sunk into the new block.
2428+
// Convert the body of the loop.
24772429
builder.restoreIP(ip);
2478-
for (auto *alloca : allocasToSink) {
2479-
unsigned size = alloca->getAllocatedType()->getPrimitiveSizeInBits() / 8;
2480-
builder.CreateLifetimeStart(alloca, builder.getInt64(size));
2481-
}
2482-
24832430
llvm::Expected<llvm::BasicBlock *> regionBlock = convertOmpOpRegions(
24842431
loopOp.getRegion(), "omp.loop_nest.region", builder, moduleTranslation);
24852432
if (!regionBlock)
24862433
return regionBlock.takeError();
24872434

24882435
builder.SetInsertPoint(*regionBlock, (*regionBlock)->begin());
2489-
2490-
for (auto *alloca : allocasToSink) {
2491-
unsigned size = alloca->getAllocatedType()->getPrimitiveSizeInBits() / 8;
2492-
builder.CreateLifetimeEnd(alloca, builder.getInt64(size));
2493-
}
24942436
return llvm::Error::success();
24952437
};
24962438

0 commit comments

Comments
 (0)