Skip to content

Commit 5cd1a43

Browse files
Make it work for both MLIR and Flang tests
1 parent 629f578 commit 5cd1a43

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed

llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2157,10 +2157,9 @@ OpenMPIRBuilder::createReductions(const LocationDescription &Loc,
21572157
unsigned NumReductions = ReductionInfos.size();
21582158
Type *RedArrayTy = ArrayType::get(Builder.getPtrTy(), NumReductions);
21592159
Builder.SetInsertPoint(AllocaIP.getBlock()->getTerminator());
2160-
// Builder.restoreIP(AllocaIP);
21612160
Value *RedArray = Builder.CreateAlloca(RedArrayTy, nullptr, "red.array");
21622161

2163-
Builder.SetInsertPoint(InsertBlock, InsertBlock->end());
2162+
Builder.SetInsertPoint(InsertBlock, InsertBlock->begin());
21642163

21652164
for (auto En : enumerate(ReductionInfos)) {
21662165
unsigned Index = En.index();
@@ -2558,8 +2557,6 @@ OpenMPIRBuilder::applyStaticWorkshareLoop(DebugLoc DL, CanonicalLoopInfo *CLI,
25582557
getOrCreateRuntimeFunction(M, omp::OMPRTL___kmpc_for_static_fini);
25592558

25602559
// Allocate space for computed loop bounds as expected by the "init" function.
2561-
2562-
// Builder.restoreIP(AllocaIP);
25632560
Builder.SetInsertPoint(AllocaIP.getBlock()->getTerminator());
25642561

25652562
Type *I32Type = Type::getInt32Ty(M.getContext());

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1155,6 +1155,7 @@ convertOmpParallel(omp::ParallelOp opInst, llvm::IRBuilderBase &builder,
11551155
opInst.getRegion().getArguments().take_back(
11561156
opInst.getNumReductionVars());
11571157

1158+
llvm::BasicBlock *initBlock = nullptr;
11581159
SmallVector<llvm::Value *> byRefVars;
11591160
if (isByRef) {
11601161
for (unsigned i = 0; i < opInst.getNumReductionVars(); ++i) {
@@ -1163,6 +1164,9 @@ convertOmpParallel(omp::ParallelOp opInst, llvm::IRBuilderBase &builder,
11631164
byRefVars.push_back(builder.CreateAlloca(
11641165
moduleTranslation.convertType(reductionDecls[i].getType())));
11651166
}
1167+
1168+
initBlock = splitBB(builder, true, "omp.reduction.init");
1169+
allocaIP = InsertPointTy(allocaIP.getBlock(), allocaIP.getBlock()->end());
11661170
}
11671171

11681172
for (unsigned i = 0; i < opInst.getNumReductionVars(); ++i) {
@@ -1177,7 +1181,10 @@ convertOmpParallel(omp::ParallelOp opInst, llvm::IRBuilderBase &builder,
11771181
assert(phis.size() == 1 &&
11781182
"expected one value to be yielded from the "
11791183
"reduction neutral element declaration region");
1180-
1184+
if (initBlock)
1185+
builder.SetInsertPoint(initBlock->getTerminator());
1186+
else
1187+
builder.restoreIP(allocaIP);
11811188
if (isByRef) {
11821189
// Store the result of the inlined region to the allocated reduction var
11831190
// ptr

mlir/test/Target/LLVMIR/openmp-parallel-reduction-cleanup.mlir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@
5555

5656
// Private reduction variable and its initialization.
5757
// CHECK: %tid.addr.local = alloca i32
58-
// CHECK: %[[MALLOC_I:.+]] = call ptr @malloc(i64 4)
5958
// CHECK: %[[PRIV_PTR_I:.+]] = alloca ptr
59+
// CHECK: %[[PRIV_PTR_J:.+]] = alloca ptr
60+
// CHECK: %[[MALLOC_I:.+]] = call ptr @malloc(i64 4)
6061
// CHECK: store ptr %[[MALLOC_I]], ptr %[[PRIV_PTR_I]]
6162
// CHECK: %[[MALLOC_J:.+]] = call ptr @malloc(i64 4)
62-
// CHECK: %[[PRIV_PTR_J:.+]] = alloca ptr
6363
// CHECK: store ptr %[[MALLOC_J]], ptr %[[PRIV_PTR_J]]
6464

6565
// Call to the reduction function.

mlir/test/Target/LLVMIR/openmp-reduction-init-arg.mlir

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,15 @@ module {
5959
// CHECK: %[[VAL_17:.*]] = load i32, ptr %[[VAL_18:.*]], align 4
6060
// CHECK: store i32 %[[VAL_17]], ptr %[[VAL_16]], align 4
6161
// CHECK: %[[VAL_19:.*]] = load i32, ptr %[[VAL_16]], align 4
62-
// CHECK: %[[VAL_20:.*]] = load { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %[[VAL_13]], align 8
6362
// CHECK: %[[VAL_21:.*]] = alloca ptr, align 8
63+
// CHECK: %[[VAL_23:.*]] = alloca ptr, align 8
64+
// CHECK: %[[VAL_20:.*]] = load { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %[[VAL_13]], align 8
65+
// CHECK: %[[VAL_24:.*]] = alloca [2 x ptr], align 8
66+
// CHECK: br label %[[INIT_LABEL:.*]]
67+
// CHECK: [[INIT_LABEL]]:
6468
// CHECK: store ptr %[[VAL_13]], ptr %[[VAL_21]], align 8
6569
// CHECK: %[[VAL_22:.*]] = load { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %[[VAL_15]], align 8
66-
// CHECK: %[[VAL_23:.*]] = alloca ptr, align 8
6770
// CHECK: store ptr %[[VAL_15]], ptr %[[VAL_23]], align 8
68-
// CHECK: %[[VAL_24:.*]] = alloca [2 x ptr], align 8
6971
// CHECK: br label %[[VAL_25:.*]]
7072
// CHECK: omp.par.region: ; preds = %[[VAL_26:.*]]
7173
// CHECK: br label %[[VAL_27:.*]]

0 commit comments

Comments
 (0)