mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-12-19 22:11:08 +00:00
[OpenMPIRBuilder] Detect and fix ambiguous InsertPoints for createSections.
Follow-up on D117226 for createSections. Reviewed By: shraiysh Differential Revision: https://reviews.llvm.org/D117835
This commit is contained in:
parent
bb3980ae9f
commit
c082ca16f1
@ -1064,6 +1064,8 @@ OpenMPIRBuilder::InsertPointTy OpenMPIRBuilder::createSections(
|
|||||||
const LocationDescription &Loc, InsertPointTy AllocaIP,
|
const LocationDescription &Loc, InsertPointTy AllocaIP,
|
||||||
ArrayRef<StorableBodyGenCallbackTy> SectionCBs, PrivatizeCallbackTy PrivCB,
|
ArrayRef<StorableBodyGenCallbackTy> SectionCBs, PrivatizeCallbackTy PrivCB,
|
||||||
FinalizeCallbackTy FiniCB, bool IsCancellable, bool IsNowait) {
|
FinalizeCallbackTy FiniCB, bool IsCancellable, bool IsNowait) {
|
||||||
|
assert(!isConflictIP(AllocaIP, Loc.IP) && "Dedicated IP allocas required");
|
||||||
|
|
||||||
if (!updateToLocation(Loc))
|
if (!updateToLocation(Loc))
|
||||||
return Loc.IP;
|
return Loc.IP;
|
||||||
|
|
||||||
|
@ -4077,7 +4077,12 @@ TEST_F(OpenMPIRBuilderTest, CreateSectionsSimple) {
|
|||||||
OMPBuilder.initialize();
|
OMPBuilder.initialize();
|
||||||
F->setName("func");
|
F->setName("func");
|
||||||
IRBuilder<> Builder(BB);
|
IRBuilder<> Builder(BB);
|
||||||
|
|
||||||
|
BasicBlock *EnterBB = BasicBlock::Create(Ctx, "sections.enter", F);
|
||||||
|
Builder.CreateBr(EnterBB);
|
||||||
|
Builder.SetInsertPoint(EnterBB);
|
||||||
OpenMPIRBuilder::LocationDescription Loc({Builder.saveIP(), DL});
|
OpenMPIRBuilder::LocationDescription Loc({Builder.saveIP(), DL});
|
||||||
|
|
||||||
llvm::SmallVector<BodyGenCallbackTy, 4> SectionCBVector;
|
llvm::SmallVector<BodyGenCallbackTy, 4> SectionCBVector;
|
||||||
llvm::SmallVector<BasicBlock *, 4> CaseBBs;
|
llvm::SmallVector<BasicBlock *, 4> CaseBBs;
|
||||||
|
|
||||||
@ -4232,7 +4237,11 @@ TEST_F(OpenMPIRBuilderTest, CreateSectionsNoWait) {
|
|||||||
F->setName("func");
|
F->setName("func");
|
||||||
IRBuilder<> Builder(BB);
|
IRBuilder<> Builder(BB);
|
||||||
|
|
||||||
|
BasicBlock *EnterBB = BasicBlock::Create(Ctx, "sections.enter", F);
|
||||||
|
Builder.CreateBr(EnterBB);
|
||||||
|
Builder.SetInsertPoint(EnterBB);
|
||||||
OpenMPIRBuilder::LocationDescription Loc({Builder.saveIP(), DL});
|
OpenMPIRBuilder::LocationDescription Loc({Builder.saveIP(), DL});
|
||||||
|
|
||||||
IRBuilder<>::InsertPoint AllocaIP(&F->getEntryBlock(),
|
IRBuilder<>::InsertPoint AllocaIP(&F->getEntryBlock(),
|
||||||
F->getEntryBlock().getFirstInsertionPt());
|
F->getEntryBlock().getFirstInsertionPt());
|
||||||
llvm::SmallVector<BodyGenCallbackTy, 4> SectionCBVector;
|
llvm::SmallVector<BodyGenCallbackTy, 4> SectionCBVector;
|
||||||
|
@ -72,6 +72,21 @@ findAllocaInsertPoint(llvm::IRBuilderBase &builder,
|
|||||||
return allocaInsertPoint;
|
return allocaInsertPoint;
|
||||||
|
|
||||||
// Otherwise, insert to the entry block of the surrounding function.
|
// Otherwise, insert to the entry block of the surrounding function.
|
||||||
|
// If the current IRBuilder InsertPoint is the function's entry, it cannot
|
||||||
|
// also be used for alloca insertion which would result in insertion order
|
||||||
|
// confusion. Create a new BasicBlock for the Builder and use the entry block
|
||||||
|
// for the allocs.
|
||||||
|
if (builder.GetInsertBlock() ==
|
||||||
|
&builder.GetInsertBlock()->getParent()->getEntryBlock()) {
|
||||||
|
assert(builder.GetInsertPoint() == builder.GetInsertBlock()->end() &&
|
||||||
|
"Assuming end of basic block");
|
||||||
|
llvm::BasicBlock *entryBB = llvm::BasicBlock::Create(
|
||||||
|
builder.getContext(), "entry", builder.GetInsertBlock()->getParent(),
|
||||||
|
builder.GetInsertBlock()->getNextNode());
|
||||||
|
builder.CreateBr(entryBB);
|
||||||
|
builder.SetInsertPoint(entryBB);
|
||||||
|
}
|
||||||
|
|
||||||
llvm::BasicBlock &funcEntryBlock =
|
llvm::BasicBlock &funcEntryBlock =
|
||||||
builder.GetInsertBlock()->getParent()->getEntryBlock();
|
builder.GetInsertBlock()->getParent()->getEntryBlock();
|
||||||
return llvm::OpenMPIRBuilder::InsertPointTy(
|
return llvm::OpenMPIRBuilder::InsertPointTy(
|
||||||
@ -255,23 +270,12 @@ convertOmpParallel(omp::ParallelOp opInst, llvm::IRBuilderBase &builder,
|
|||||||
// TODO: Is the Parallel construct cancellable?
|
// TODO: Is the Parallel construct cancellable?
|
||||||
bool isCancellable = false;
|
bool isCancellable = false;
|
||||||
|
|
||||||
// Ensure that the BasicBlock for the the parallel region is sparate from the
|
llvm::OpenMPIRBuilder::InsertPointTy allocaIP =
|
||||||
// function entry which we may need to insert allocas.
|
findAllocaInsertPoint(builder, moduleTranslation);
|
||||||
if (builder.GetInsertBlock() ==
|
|
||||||
&builder.GetInsertBlock()->getParent()->getEntryBlock()) {
|
|
||||||
assert(builder.GetInsertPoint() == builder.GetInsertBlock()->end() &&
|
|
||||||
"Assuming end of basic block");
|
|
||||||
llvm::BasicBlock *entryBB =
|
|
||||||
llvm::BasicBlock::Create(builder.getContext(), "parallel.entry",
|
|
||||||
builder.GetInsertBlock()->getParent(),
|
|
||||||
builder.GetInsertBlock()->getNextNode());
|
|
||||||
builder.CreateBr(entryBB);
|
|
||||||
builder.SetInsertPoint(entryBB);
|
|
||||||
}
|
|
||||||
llvm::OpenMPIRBuilder::LocationDescription ompLoc(builder);
|
llvm::OpenMPIRBuilder::LocationDescription ompLoc(builder);
|
||||||
builder.restoreIP(moduleTranslation.getOpenMPBuilder()->createParallel(
|
builder.restoreIP(moduleTranslation.getOpenMPBuilder()->createParallel(
|
||||||
ompLoc, findAllocaInsertPoint(builder, moduleTranslation), bodyGenCB,
|
ompLoc, allocaIP, bodyGenCB, privCB, finiCB, ifCond, numThreads, pbKind,
|
||||||
privCB, finiCB, ifCond, numThreads, pbKind, isCancellable));
|
isCancellable));
|
||||||
|
|
||||||
return bodyGenStatus;
|
return bodyGenStatus;
|
||||||
}
|
}
|
||||||
@ -522,7 +526,6 @@ convertOmpOrdered(Operation &opInst, llvm::IRBuilderBase &builder,
|
|||||||
SmallVector<llvm::Value *> vecValues =
|
SmallVector<llvm::Value *> vecValues =
|
||||||
moduleTranslation.lookupValues(orderedOp.depend_vec_vars());
|
moduleTranslation.lookupValues(orderedOp.depend_vec_vars());
|
||||||
|
|
||||||
llvm::OpenMPIRBuilder::LocationDescription ompLoc(builder);
|
|
||||||
size_t indexVecValues = 0;
|
size_t indexVecValues = 0;
|
||||||
while (indexVecValues < vecValues.size()) {
|
while (indexVecValues < vecValues.size()) {
|
||||||
SmallVector<llvm::Value *> storeValues;
|
SmallVector<llvm::Value *> storeValues;
|
||||||
@ -531,9 +534,11 @@ convertOmpOrdered(Operation &opInst, llvm::IRBuilderBase &builder,
|
|||||||
storeValues.push_back(vecValues[indexVecValues]);
|
storeValues.push_back(vecValues[indexVecValues]);
|
||||||
indexVecValues++;
|
indexVecValues++;
|
||||||
}
|
}
|
||||||
|
llvm::OpenMPIRBuilder::InsertPointTy allocaIP =
|
||||||
|
findAllocaInsertPoint(builder, moduleTranslation);
|
||||||
|
llvm::OpenMPIRBuilder::LocationDescription ompLoc(builder);
|
||||||
builder.restoreIP(moduleTranslation.getOpenMPBuilder()->createOrderedDepend(
|
builder.restoreIP(moduleTranslation.getOpenMPBuilder()->createOrderedDepend(
|
||||||
ompLoc, findAllocaInsertPoint(builder, moduleTranslation), numLoops,
|
ompLoc, allocaIP, numLoops, storeValues, ".cnt.addr", isDependSource));
|
||||||
storeValues, ".cnt.addr", isDependSource));
|
|
||||||
}
|
}
|
||||||
return success();
|
return success();
|
||||||
}
|
}
|
||||||
@ -634,10 +639,12 @@ convertOmpSections(Operation &opInst, llvm::IRBuilderBase &builder,
|
|||||||
// called for variables which have destructors/finalizers.
|
// called for variables which have destructors/finalizers.
|
||||||
auto finiCB = [&](InsertPointTy codeGenIP) {};
|
auto finiCB = [&](InsertPointTy codeGenIP) {};
|
||||||
|
|
||||||
|
llvm::OpenMPIRBuilder::InsertPointTy allocaIP =
|
||||||
|
findAllocaInsertPoint(builder, moduleTranslation);
|
||||||
llvm::OpenMPIRBuilder::LocationDescription ompLoc(builder);
|
llvm::OpenMPIRBuilder::LocationDescription ompLoc(builder);
|
||||||
builder.restoreIP(moduleTranslation.getOpenMPBuilder()->createSections(
|
builder.restoreIP(moduleTranslation.getOpenMPBuilder()->createSections(
|
||||||
ompLoc, findAllocaInsertPoint(builder, moduleTranslation), sectionCBs,
|
ompLoc, allocaIP, sectionCBs, privCB, finiCB, false,
|
||||||
privCB, finiCB, false, sectionsOp.nowait()));
|
sectionsOp.nowait()));
|
||||||
return bodyGenStatus;
|
return bodyGenStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1104,7 +1111,6 @@ convertOmpAtomicUpdate(omp::AtomicUpdateOp &opInst,
|
|||||||
llvm::IRBuilderBase &builder,
|
llvm::IRBuilderBase &builder,
|
||||||
LLVM::ModuleTranslation &moduleTranslation) {
|
LLVM::ModuleTranslation &moduleTranslation) {
|
||||||
llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
|
llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
|
||||||
llvm::OpenMPIRBuilder::LocationDescription ompLoc(builder);
|
|
||||||
|
|
||||||
// Convert values and types.
|
// Convert values and types.
|
||||||
auto &innerOpList = opInst.region().front().getOperations();
|
auto &innerOpList = opInst.region().front().getOperations();
|
||||||
@ -1164,17 +1170,10 @@ convertOmpAtomicUpdate(omp::AtomicUpdateOp &opInst,
|
|||||||
|
|
||||||
// Handle ambiguous alloca, if any.
|
// Handle ambiguous alloca, if any.
|
||||||
auto allocaIP = findAllocaInsertPoint(builder, moduleTranslation);
|
auto allocaIP = findAllocaInsertPoint(builder, moduleTranslation);
|
||||||
if (allocaIP.getPoint() == ompLoc.IP.getPoint()) {
|
llvm::OpenMPIRBuilder::LocationDescription ompLoc(builder);
|
||||||
// Same point => split basic block and make them unambigous.
|
|
||||||
llvm::UnreachableInst *unreachableInst = builder.CreateUnreachable();
|
|
||||||
builder.SetInsertPoint(builder.GetInsertBlock()->splitBasicBlock(
|
|
||||||
unreachableInst, "alloca_split"));
|
|
||||||
ompLoc.IP = builder.saveIP();
|
|
||||||
unreachableInst->eraseFromParent();
|
|
||||||
}
|
|
||||||
builder.restoreIP(ompBuilder->createAtomicUpdate(
|
builder.restoreIP(ompBuilder->createAtomicUpdate(
|
||||||
ompLoc, findAllocaInsertPoint(builder, moduleTranslation), llvmAtomicX,
|
ompLoc, allocaIP, llvmAtomicX, llvmExpr, atomicOrdering, binop, updateFn,
|
||||||
llvmExpr, atomicOrdering, binop, updateFn, isXBinopExpr));
|
isXBinopExpr));
|
||||||
return updateGenStatus;
|
return updateGenStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1183,7 +1182,6 @@ convertOmpAtomicCapture(omp::AtomicCaptureOp atomicCaptureOp,
|
|||||||
llvm::IRBuilderBase &builder,
|
llvm::IRBuilderBase &builder,
|
||||||
LLVM::ModuleTranslation &moduleTranslation) {
|
LLVM::ModuleTranslation &moduleTranslation) {
|
||||||
llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
|
llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
|
||||||
llvm::OpenMPIRBuilder::LocationDescription ompLoc(builder);
|
|
||||||
mlir::Value mlirExpr;
|
mlir::Value mlirExpr;
|
||||||
bool isXBinopExpr = false, isPostfixUpdate = false;
|
bool isXBinopExpr = false, isPostfixUpdate = false;
|
||||||
llvm::AtomicRMWInst::BinOp binop = llvm::AtomicRMWInst::BinOp::BAD_BINOP;
|
llvm::AtomicRMWInst::BinOp binop = llvm::AtomicRMWInst::BinOp::BAD_BINOP;
|
||||||
@ -1262,20 +1260,13 @@ convertOmpAtomicCapture(omp::AtomicCaptureOp atomicCaptureOp,
|
|||||||
"argument");
|
"argument");
|
||||||
return moduleTranslation.lookupValue(yieldop.results()[0]);
|
return moduleTranslation.lookupValue(yieldop.results()[0]);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handle ambiguous alloca, if any.
|
// Handle ambiguous alloca, if any.
|
||||||
auto allocaIP = findAllocaInsertPoint(builder, moduleTranslation);
|
auto allocaIP = findAllocaInsertPoint(builder, moduleTranslation);
|
||||||
if (allocaIP.getPoint() == ompLoc.IP.getPoint()) {
|
llvm::OpenMPIRBuilder::LocationDescription ompLoc(builder);
|
||||||
// Same point => split basic block and make them unambigous.
|
|
||||||
llvm::UnreachableInst *unreachableInst = builder.CreateUnreachable();
|
|
||||||
builder.SetInsertPoint(builder.GetInsertBlock()->splitBasicBlock(
|
|
||||||
unreachableInst, "alloca_split"));
|
|
||||||
ompLoc.IP = builder.saveIP();
|
|
||||||
unreachableInst->eraseFromParent();
|
|
||||||
}
|
|
||||||
builder.restoreIP(ompBuilder->createAtomicCapture(
|
builder.restoreIP(ompBuilder->createAtomicCapture(
|
||||||
ompLoc, findAllocaInsertPoint(builder, moduleTranslation), llvmAtomicX,
|
ompLoc, allocaIP, llvmAtomicX, llvmAtomicV, llvmExpr, atomicOrdering,
|
||||||
llvmAtomicV, llvmExpr, atomicOrdering, binop, updateFn, atomicUpdateOp,
|
binop, updateFn, atomicUpdateOp, isPostfixUpdate, isXBinopExpr));
|
||||||
isPostfixUpdate, isXBinopExpr));
|
|
||||||
return updateGenStatus;
|
return updateGenStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1854,6 +1854,9 @@ llvm.func @omp_sections_empty() -> () {
|
|||||||
|
|
||||||
// CHECK-LABEL: @omp_sections_trivial
|
// CHECK-LABEL: @omp_sections_trivial
|
||||||
llvm.func @omp_sections_trivial() -> () {
|
llvm.func @omp_sections_trivial() -> () {
|
||||||
|
// CHECK: br label %[[ENTRY:[a-zA-Z_.]+]]
|
||||||
|
|
||||||
|
// CHECK: [[ENTRY]]:
|
||||||
// CHECK: br label %[[PREHEADER:.*]]
|
// CHECK: br label %[[PREHEADER:.*]]
|
||||||
|
|
||||||
// CHECK: [[PREHEADER]]:
|
// CHECK: [[PREHEADER]]:
|
||||||
|
Loading…
Reference in New Issue
Block a user