Skip to content

Commit b85cfe2

Browse files
committed
[OpenMP][IRBuilder] Change the default constructor for OpenMPIRBuilder::LocationDescription
This patch changes the argument from template-IRBuilder to IRBuilderBase thus allowing us to write less code while getting the location from a builder. Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D119717
1 parent a766545 commit b85cfe2

File tree

2 files changed

+13
-37
lines changed

2 files changed

+13
-37
lines changed

llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,7 @@ class OpenMPIRBuilder {
145145
/// Description of a LLVM-IR insertion point (IP) and a debug/source location
146146
/// (filename, line, column, ...).
147147
struct LocationDescription {
148-
template <typename T, typename U>
149-
LocationDescription(const IRBuilder<T, U> &IRB)
148+
LocationDescription(const IRBuilderBase &IRB)
150149
: IP(IRB.saveIP()), DL(IRB.getCurrentDebugLocation()) {}
151150
LocationDescription(const InsertPointTy &IP) : IP(IP) {}
152151
LocationDescription(const InsertPointTy &IP, const DebugLoc &DL)

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

Lines changed: 12 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,7 @@ convertOmpParallel(omp::ParallelOp opInst, llvm::IRBuilderBase &builder,
264264
builder.CreateBr(entryBB);
265265
builder.SetInsertPoint(entryBB);
266266
}
267-
llvm::OpenMPIRBuilder::LocationDescription ompLoc(
268-
builder.saveIP(), builder.getCurrentDebugLocation());
267+
llvm::OpenMPIRBuilder::LocationDescription ompLoc(builder);
269268
builder.restoreIP(moduleTranslation.getOpenMPBuilder()->createParallel(
270269
ompLoc, findAllocaInsertPoint(builder, moduleTranslation), bodyGenCB,
271270
privCB, finiCB, ifCond, numThreads, pbKind, isCancellable));
@@ -295,8 +294,7 @@ convertOmpMaster(Operation &opInst, llvm::IRBuilderBase &builder,
295294
// called for variables which have destructors/finalizers.
296295
auto finiCB = [&](InsertPointTy codeGenIP) {};
297296

298-
llvm::OpenMPIRBuilder::LocationDescription ompLoc(
299-
builder.saveIP(), builder.getCurrentDebugLocation());
297+
llvm::OpenMPIRBuilder::LocationDescription ompLoc(builder);
300298
builder.restoreIP(moduleTranslation.getOpenMPBuilder()->createMaster(
301299
ompLoc, bodyGenCB, finiCB));
302300
return success();
@@ -325,8 +323,7 @@ convertOmpCritical(Operation &opInst, llvm::IRBuilderBase &builder,
325323
// called for variables which have destructors/finalizers.
326324
auto finiCB = [&](InsertPointTy codeGenIP) {};
327325

328-
llvm::OpenMPIRBuilder::LocationDescription ompLoc(
329-
builder.saveIP(), builder.getCurrentDebugLocation());
326+
llvm::OpenMPIRBuilder::LocationDescription ompLoc(builder);
330327
llvm::LLVMContext &llvmContext = moduleTranslation.getLLVMContext();
331328
llvm::Constant *hint = nullptr;
332329

@@ -520,8 +517,7 @@ convertOmpOrdered(Operation &opInst, llvm::IRBuilderBase &builder,
520517
SmallVector<llvm::Value *> vecValues =
521518
moduleTranslation.lookupValues(orderedOp.depend_vec_vars());
522519

523-
llvm::OpenMPIRBuilder::LocationDescription ompLoc(
524-
builder.saveIP(), builder.getCurrentDebugLocation());
520+
llvm::OpenMPIRBuilder::LocationDescription ompLoc(builder);
525521
size_t indexVecValues = 0;
526522
while (indexVecValues < vecValues.size()) {
527523
SmallVector<llvm::Value *> storeValues;
@@ -566,8 +562,7 @@ convertOmpOrderedRegion(Operation &opInst, llvm::IRBuilderBase &builder,
566562
// called for variables which have destructors/finalizers.
567563
auto finiCB = [&](InsertPointTy codeGenIP) {};
568564

569-
llvm::OpenMPIRBuilder::LocationDescription ompLoc(
570-
builder.saveIP(), builder.getCurrentDebugLocation());
565+
llvm::OpenMPIRBuilder::LocationDescription ompLoc(builder);
571566
builder.restoreIP(
572567
moduleTranslation.getOpenMPBuilder()->createOrderedThreadsSimd(
573568
ompLoc, bodyGenCB, finiCB, !orderedRegionOp.simd()));
@@ -637,8 +632,7 @@ convertOmpSections(Operation &opInst, llvm::IRBuilderBase &builder,
637632
// called for variables which have destructors/finalizers.
638633
auto finiCB = [&](InsertPointTy codeGenIP) {};
639634

640-
llvm::OpenMPIRBuilder::LocationDescription ompLoc(
641-
builder.saveIP(), builder.getCurrentDebugLocation());
635+
llvm::OpenMPIRBuilder::LocationDescription ompLoc(builder);
642636
builder.restoreIP(moduleTranslation.getOpenMPBuilder()->createSections(
643637
ompLoc, findAllocaInsertPoint(builder, moduleTranslation), sectionCBs,
644638
privCB, finiCB, false, sectionsOp.nowait()));
@@ -720,12 +714,7 @@ convertOmpWsLoop(Operation &opInst, llvm::IRBuilderBase &builder,
720714
}
721715

722716
// Set up the source location value for OpenMP runtime.
723-
llvm::DISubprogram *subprogram =
724-
builder.GetInsertBlock()->getParent()->getSubprogram();
725-
const llvm::DILocation *diLoc =
726-
moduleTranslation.translateLoc(opInst.getLoc(), subprogram);
727-
llvm::OpenMPIRBuilder::LocationDescription ompLoc(builder.saveIP(),
728-
llvm::DebugLoc(diLoc));
717+
llvm::OpenMPIRBuilder::LocationDescription ompLoc(builder);
729718

730719
// Generator of the canonical loop body.
731720
// TODO: support error propagation in OpenMPIRBuilder and use it instead of
@@ -772,8 +761,7 @@ convertOmpWsLoop(Operation &opInst, llvm::IRBuilderBase &builder,
772761
llvm::OpenMPIRBuilder::LocationDescription loc = ompLoc;
773762
llvm::OpenMPIRBuilder::InsertPointTy computeIP = ompLoc.IP;
774763
if (i != 0) {
775-
loc = llvm::OpenMPIRBuilder::LocationDescription(bodyInsertPoints.back(),
776-
llvm::DebugLoc(diLoc));
764+
loc = llvm::OpenMPIRBuilder::LocationDescription(bodyInsertPoints.back());
777765
computeIP = loopInfos.front()->getPreheaderIP();
778766
}
779767
loopInfos.push_back(ompBuilder->createCanonicalLoop(
@@ -788,7 +776,7 @@ convertOmpWsLoop(Operation &opInst, llvm::IRBuilderBase &builder,
788776
// invalidated.
789777
llvm::IRBuilderBase::InsertPoint afterIP = loopInfos.front()->getAfterIP();
790778
llvm::CanonicalLoopInfo *loopInfo =
791-
ompBuilder->collapseLoops(diLoc, loopInfos, {});
779+
ompBuilder->collapseLoops(ompLoc.DL, loopInfos, {});
792780

793781
allocaIP = findAllocaInsertPoint(builder, moduleTranslation);
794782

@@ -922,13 +910,8 @@ convertOmpAtomicRead(Operation &opInst, llvm::IRBuilderBase &builder,
922910
auto readOp = cast<omp::AtomicReadOp>(opInst);
923911
llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
924912

925-
// Set up the source location value for OpenMP runtime.
926-
llvm::DISubprogram *subprogram =
927-
builder.GetInsertBlock()->getParent()->getSubprogram();
928-
const llvm::DILocation *diLoc =
929-
moduleTranslation.translateLoc(opInst.getLoc(), subprogram);
930-
llvm::OpenMPIRBuilder::LocationDescription ompLoc(builder.saveIP(),
931-
llvm::DebugLoc(diLoc));
913+
llvm::OpenMPIRBuilder::LocationDescription ompLoc(builder);
914+
932915
llvm::AtomicOrdering AO = convertAtomicOrdering(readOp.memory_order());
933916
llvm::Value *x = moduleTranslation.lookupValue(readOp.x());
934917
Type xTy = readOp.x().getType().cast<omp::PointerLikeType>().getElementType();
@@ -949,13 +932,7 @@ convertOmpAtomicWrite(Operation &opInst, llvm::IRBuilderBase &builder,
949932
auto writeOp = cast<omp::AtomicWriteOp>(opInst);
950933
llvm::OpenMPIRBuilder *ompBuilder = moduleTranslation.getOpenMPBuilder();
951934

952-
// Set up the source location value for OpenMP runtime.
953-
llvm::DISubprogram *subprogram =
954-
builder.GetInsertBlock()->getParent()->getSubprogram();
955-
const llvm::DILocation *diLoc =
956-
moduleTranslation.translateLoc(opInst.getLoc(), subprogram);
957-
llvm::OpenMPIRBuilder::LocationDescription ompLoc(builder.saveIP(),
958-
llvm::DebugLoc(diLoc));
935+
llvm::OpenMPIRBuilder::LocationDescription ompLoc(builder);
959936
llvm::AtomicOrdering ao = convertAtomicOrdering(writeOp.memory_order());
960937
llvm::Value *expr = moduleTranslation.lookupValue(writeOp.value());
961938
llvm::Value *dest = moduleTranslation.lookupValue(writeOp.address());

0 commit comments

Comments
 (0)