Skip to content

Commit 854e951

Browse files
committed
Revert "[mlir][OpenMP] implement SIMD reduction (llvm#146671)"
This reverts commit 16b75c8. breaks: hpc2021: 519.clvleaf_t, accel2023: 450.md, 453.clvrleaf, smoke-fort: flang-nestred
1 parent 954810d commit 854e951

File tree

4 files changed

+32
-266
lines changed

4 files changed

+32
-266
lines changed

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

Lines changed: 1 addition & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ static LogicalResult checkImplementationStatus(Operation &op) {
234234
}
235235
};
236236
auto checkReduction = [&todo](auto op, LogicalResult &result) {
237-
if (isa<omp::TeamsOp>(op))
237+
if (isa<omp::TeamsOp>(op) || isa<omp::SimdOp>(op))
238238
if (!op.getReductionVars().empty() || op.getReductionByref() ||
239239
op.getReductionSyms())
240240
result = todo("reduction");
@@ -2704,17 +2704,6 @@ convertOmpSimd(Operation &opInst, llvm::IRBuilderBase &builder,
27042704

27052705
PrivateVarsInfo privateVarsInfo(simdOp);
27062706

2707-
MutableArrayRef<BlockArgument> reductionArgs =
2708-
cast<omp::BlockArgOpenMPOpInterface>(opInst).getReductionBlockArgs();
2709-
DenseMap<Value, llvm::Value *> reductionVariableMap;
2710-
SmallVector<llvm::Value *> privateReductionVariables(
2711-
simdOp.getNumReductionVars());
2712-
SmallVector<DeferredStore> deferredStores;
2713-
SmallVector<omp::DeclareReductionOp> reductionDecls;
2714-
collectReductionDecls(simdOp, reductionDecls);
2715-
llvm::ArrayRef<bool> isByRef = getIsByRef(simdOp.getReductionByref());
2716-
assert(isByRef.size() == simdOp.getNumReductionVars());
2717-
27182707
llvm::OpenMPIRBuilder::InsertPointTy allocaIP =
27192708
findAllocaInsertPoint(builder, moduleTranslation);
27202709

@@ -2723,27 +2712,11 @@ convertOmpSimd(Operation &opInst, llvm::IRBuilderBase &builder,
27232712
if (handleError(afterAllocas, opInst).failed())
27242713
return failure();
27252714

2726-
if (failed(allocReductionVars(simdOp, reductionArgs, builder,
2727-
moduleTranslation, allocaIP, reductionDecls,
2728-
privateReductionVariables, reductionVariableMap,
2729-
deferredStores, isByRef)))
2730-
return failure();
2731-
27322715
if (handleError(initPrivateVars(builder, moduleTranslation, privateVarsInfo),
27332716
opInst)
27342717
.failed())
27352718
return failure();
27362719

2737-
// TODO: no call to copyFirstPrivateVars?
2738-
2739-
assert(afterAllocas.get()->getSinglePredecessor());
2740-
if (failed(initReductionVars(simdOp, reductionArgs, builder,
2741-
moduleTranslation,
2742-
afterAllocas.get()->getSinglePredecessor(),
2743-
reductionDecls, privateReductionVariables,
2744-
reductionVariableMap, isByRef, deferredStores)))
2745-
return failure();
2746-
27472720
llvm::ConstantInt *simdlen = nullptr;
27482721
if (std::optional<uint64_t> simdlenVar = simdOp.getSimdlen())
27492722
simdlen = builder.getInt64(simdlenVar.value());
@@ -2788,50 +2761,6 @@ convertOmpSimd(Operation &opInst, llvm::IRBuilderBase &builder,
27882761
: nullptr,
27892762
order, simdlen, safelen);
27902763

2791-
// We now need to reduce the per-simd-lane reduction variable into the
2792-
// original variable. This works a bit differently to other reductions (e.g.
2793-
// wsloop) because we don't need to call into the OpenMP runtime to handle
2794-
// threads: everything happened in this one thread.
2795-
for (auto [i, tuple] : llvm::enumerate(
2796-
llvm::zip(reductionDecls, isByRef, simdOp.getReductionVars(),
2797-
privateReductionVariables))) {
2798-
auto [decl, byRef, reductionVar, privateReductionVar] = tuple;
2799-
2800-
OwningReductionGen gen = makeReductionGen(decl, builder, moduleTranslation);
2801-
llvm::Value *originalVariable = moduleTranslation.lookupValue(reductionVar);
2802-
llvm::Type *reductionType = moduleTranslation.convertType(decl.getType());
2803-
2804-
// We have one less load for by-ref case because that load is now inside of
2805-
// the reduction region.
2806-
llvm::Value *redValue = originalVariable;
2807-
if (!byRef)
2808-
redValue =
2809-
builder.CreateLoad(reductionType, redValue, "red.value." + Twine(i));
2810-
llvm::Value *privateRedValue = builder.CreateLoad(
2811-
reductionType, privateReductionVar, "red.private.value." + Twine(i));
2812-
llvm::Value *reduced;
2813-
2814-
auto res = gen(builder.saveIP(), redValue, privateRedValue, reduced);
2815-
if (failed(handleError(res, opInst)))
2816-
return failure();
2817-
builder.restoreIP(res.get());
2818-
2819-
// For by-ref case, the store is inside of the reduction region.
2820-
if (!byRef)
2821-
builder.CreateStore(reduced, originalVariable);
2822-
}
2823-
2824-
// After the construct, deallocate private reduction variables.
2825-
SmallVector<Region *> reductionRegions;
2826-
llvm::transform(reductionDecls, std::back_inserter(reductionRegions),
2827-
[](omp::DeclareReductionOp reductionDecl) {
2828-
return &reductionDecl.getCleanupRegion();
2829-
});
2830-
if (failed(inlineOmpRegionCleanup(reductionRegions, privateReductionVariables,
2831-
moduleTranslation, builder,
2832-
"omp.reduction.cleanup")))
2833-
return failure();
2834-
28352764
return cleanupPrivateVars(builder, moduleTranslation, simdOp.getLoc(),
28362765
privateVarsInfo.llvmVars,
28372766
privateVarsInfo.privatizers);

mlir/test/Target/LLVMIR/openmp-simd-reduction-byref.mlir

Lines changed: 0 additions & 98 deletions
This file was deleted.

mlir/test/Target/LLVMIR/openmp-simd-reduction-simple.mlir

Lines changed: 0 additions & 96 deletions
This file was deleted.

mlir/test/Target/LLVMIR/openmp-todo.mlir

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: mlir-translate -mlir-to-llvmir -split-input-file -verify-diagnostics %s
2+
// XFAIL: *
23

34
llvm.func @atomic_hint(%v : !llvm.ptr, %x : !llvm.ptr, %expr : i32) {
45
// expected-warning@below {{hint clause discarded}}
@@ -140,6 +141,36 @@ llvm.func @simd_linear(%lb : i32, %ub : i32, %step : i32, %x : !llvm.ptr) {
140141

141142
// -----
142143

144+
omp.declare_reduction @add_f32 : f32
145+
init {
146+
^bb0(%arg: f32):
147+
%0 = llvm.mlir.constant(0.0 : f32) : f32
148+
omp.yield (%0 : f32)
149+
}
150+
combiner {
151+
^bb1(%arg0: f32, %arg1: f32):
152+
%1 = llvm.fadd %arg0, %arg1 : f32
153+
omp.yield (%1 : f32)
154+
}
155+
atomic {
156+
^bb2(%arg2: !llvm.ptr, %arg3: !llvm.ptr):
157+
%2 = llvm.load %arg3 : !llvm.ptr -> f32
158+
llvm.atomicrmw fadd %arg2, %2 monotonic : !llvm.ptr, f32
159+
omp.yield
160+
}
161+
llvm.func @simd_reduction(%lb : i32, %ub : i32, %step : i32, %x : !llvm.ptr) {
162+
// expected-error@below {{not yet implemented: Unhandled clause reduction in omp.simd operation}}
163+
// expected-error@below {{LLVM Translation failed for operation: omp.simd}}
164+
omp.simd reduction(@add_f32 %x -> %prv : !llvm.ptr) {
165+
omp.loop_nest (%iv) : i32 = (%lb) to (%ub) step (%step) {
166+
omp.yield
167+
}
168+
}
169+
llvm.return
170+
}
171+
172+
// -----
173+
143174
omp.declare_reduction @add_f32 : f32
144175
init {
145176
^bb0(%arg: f32):

0 commit comments

Comments
 (0)