Skip to content

Commit 31f64e5

Browse files
authored
[MLIR][OpenMP] Fix failing Lit tests (#242)
The omptarget-threadprivate-device-lowering.mlir test is updated with a valid target triple to prevent triggering an assertion during translation to LLVM IR. The openmp-todo.mlir test is updated, since unsupported simd clauses no longer trigger errors but rather warnings. Messages triggered by these are also updated to avoid misleading users.
1 parent a1eead6 commit 31f64e5

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

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

+10-5
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "llvm/IR/IRBuilder.h"
3333
#include "llvm/IR/ReplaceConstant.h"
3434
#include "llvm/Support/FileSystem.h"
35+
#include "llvm/Support/FormatVariadic.h"
3536
#include "llvm/TargetParser/Triple.h"
3637
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
3738
#include "llvm/Transforms/Utils/ModuleUtils.h"
@@ -525,7 +526,8 @@ static llvm::omp::ProcBindKind getProcBindKind(omp::ClauseProcBindKind kind) {
525526
/// been mapped to LLVM IR values.
526527
static LogicalResult
527528
convertIgnoredWrapper(omp::LoopWrapperInterface opInst,
528-
LLVM::ModuleTranslation &moduleTranslation) {
529+
LLVM::ModuleTranslation &moduleTranslation,
530+
const char *warningFmt) {
529531
// Map block arguments directly to the LLVM value associated to the
530532
// corresponding operand. This is semantically equivalent to this wrapper not
531533
// being present.
@@ -542,11 +544,11 @@ convertIgnoredWrapper(omp::LoopWrapperInterface opInst,
542544
forwardArgs(blockArgIface.getPrivateBlockArgs(), op.getPrivateVars());
543545
forwardArgs(blockArgIface.getReductionBlockArgs(),
544546
op.getReductionVars());
545-
op.emitWarning() << "simd information on composite construct discarded";
547+
op.emitWarning() << llvm::formatv(warningFmt, "simd");
546548
return success();
547549
})
548550
.Default([&](Operation *op) {
549-
return op->emitError() << "cannot ignore nested wrapper";
551+
return op->emitError() << "cannot ignore wrapper";
550552
});
551553
}
552554

@@ -567,7 +569,9 @@ convertIgnoredWrappers(omp::LoopNestOp loopOp,
567569
for (auto it =
568570
std::next(std::find(wrappers.rbegin(), wrappers.rend(), parentOp));
569571
it != wrappers.rend(); ++it) {
570-
if (failed(convertIgnoredWrapper(*it, moduleTranslation)))
572+
if (failed(convertIgnoredWrapper(
573+
*it, moduleTranslation,
574+
"{0} information on composite construct discarded")))
571575
return failure();
572576
}
573577

@@ -2518,7 +2522,8 @@ convertOmpSimd(Operation &opInst, llvm::IRBuilderBase &builder,
25182522

25192523
// This is needed to make sure that uses of entry block arguments for clauses
25202524
// that are not going to be translated are mapped to the outside values.
2521-
if (failed(convertIgnoredWrapper(simdOp, moduleTranslation)))
2525+
if (failed(convertIgnoredWrapper(simdOp, moduleTranslation,
2526+
"{0} clauses ignored")))
25222527
return failure();
25232528

25242529
auto loopNestConversionResult = convertLoopNestHelper(

mlir/test/Target/LLVMIR/omptarget-threadprivate-device-lowering.mlir

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// omp.threadprivate does not crash on lowering during the OpenMP target device
55
// pass when used in conjunction with target code in the same module.
66

7-
module attributes {omp.is_target_device = true } {
7+
module attributes {omp.is_target_device = true, llvm.target_triple = "amdgcn-amd-amdhsa"} {
88
llvm.func @func() attributes {omp.declare_target = #omp.declaretarget<device_type = (host), capture_clause = (to)>} {
99
%0 = llvm.mlir.addressof @_QFEpointer2 : !llvm.ptr
1010
%1 = omp.threadprivate %0 : !llvm.ptr -> !llvm.ptr
@@ -23,7 +23,7 @@ module attributes {omp.is_target_device = true } {
2323
}
2424
}
2525

26-
// CHECK: define weak_odr protected void @{{.*}}(ptr %{{.*}}, ptr %[[ARG1:.*]]) {
26+
// CHECK: define weak_odr protected amdgpu_kernel void @{{.*}}(ptr %{{.*}}, ptr %[[ARG1:.*]]) #{{[0-9]+}} {
2727
// CHECK: %[[ALLOCA:.*]] = alloca ptr, align 8
2828
// CHECK: store ptr %[[ARG1]], ptr %[[ALLOCA]], align 8
2929
// CHECK: %[[LOAD_ALLOCA:.*]] = load ptr, ptr %[[ALLOCA]], align 8

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

+4-8
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,7 @@ llvm.func @sections_private(%x : !llvm.ptr) {
175175
// -----
176176

177177
llvm.func @simd_linear(%lb : i32, %ub : i32, %step : i32, %x : !llvm.ptr) {
178-
// expected-error@below {{not yet implemented: Unhandled clause linear in omp.simd operation}}
179-
// expected-error@below {{LLVM Translation failed for operation: omp.simd}}
178+
// expected-warning@below {{simd clauses ignored}}
180179
omp.simd linear(%x = %step : !llvm.ptr) {
181180
omp.loop_nest (%iv) : i32 = (%lb) to (%ub) step (%step) {
182181
omp.yield
@@ -188,8 +187,7 @@ llvm.func @simd_linear(%lb : i32, %ub : i32, %step : i32, %x : !llvm.ptr) {
188187
// -----
189188

190189
llvm.func @simd_nontemporal(%lb : i32, %ub : i32, %step : i32, %x : !llvm.ptr) {
191-
// expected-error@below {{not yet implemented: Unhandled clause nontemporal in omp.simd operation}}
192-
// expected-error@below {{LLVM Translation failed for operation: omp.simd}}
190+
// expected-warning@below {{simd clauses ignored}}
193191
omp.simd nontemporal(%x : !llvm.ptr) {
194192
omp.loop_nest (%iv) : i32 = (%lb) to (%ub) step (%step) {
195193
omp.yield
@@ -207,8 +205,7 @@ omp.private {type = private} @x.privatizer : !llvm.ptr alloc {
207205
omp.yield(%1 : !llvm.ptr)
208206
}
209207
llvm.func @simd_private(%lb : i32, %ub : i32, %step : i32, %x : !llvm.ptr) {
210-
// expected-error@below {{not yet implemented: Unhandled clause privatization in omp.simd operation}}
211-
// expected-error@below {{LLVM Translation failed for operation: omp.simd}}
208+
// expected-warning@below {{simd clauses ignored}}
212209
omp.simd private(@x.privatizer %x -> %arg0 : !llvm.ptr) {
213210
omp.loop_nest (%iv) : i32 = (%lb) to (%ub) step (%step) {
214211
omp.yield
@@ -237,8 +234,7 @@ atomic {
237234
omp.yield
238235
}
239236
llvm.func @simd_reduction(%lb : i32, %ub : i32, %step : i32, %x : !llvm.ptr) {
240-
// expected-error@below {{not yet implemented: Unhandled clause reduction in omp.simd operation}}
241-
// expected-error@below {{LLVM Translation failed for operation: omp.simd}}
237+
// expected-warning@below {{simd clauses ignored}}
242238
omp.simd reduction(@add_f32 %x -> %prv : !llvm.ptr) {
243239
omp.loop_nest (%iv) : i32 = (%lb) to (%ub) step (%step) {
244240
omp.yield

0 commit comments

Comments
 (0)