Skip to content

Commit 46fd7fd

Browse files
[Flang] Replace notifyMatchFailure with TODO hard failures
For unimplemented patterns we revert to using TODO hard failures instead of notifyMatchFailure. For fir.select_type revert to using mlir::emiterror. For the fir.embox TODO on a type with len params we cannot add a test since the type cannot be converted to llvm. Adding negative tests using not and checking for the error message. TODO exits with an error in a build without assertion but aborts in a build with assertions. Abort requires using not with the --crash option. The two different usages of not is handled by using a custom command %not_todo_cmd which is converted to not or not --crash depending on the presence or absence of assertions. Using llvm-config to check the presence of assertions. Reviewed By: clementval, awarzynski Differential Revision: https://reviews.llvm.org/D114371
1 parent 3666cd0 commit 46fd7fd

14 files changed

+176
-154
lines changed

flang/lib/Optimizer/CodeGen/CodeGen.cpp

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -541,8 +541,8 @@ struct BoxProcHostOpConversion : public FIROpConversion<fir::BoxProcHostOp> {
541541
mlir::LogicalResult
542542
matchAndRewrite(fir::BoxProcHostOp boxprochost, OpAdaptor adaptor,
543543
mlir::ConversionPatternRewriter &rewriter) const override {
544-
return rewriter.notifyMatchFailure(
545-
boxprochost, "fir.boxproc_host codegen is not implemented yet");
544+
TODO(boxprochost.getLoc(), "fir.boxproc_host codegen");
545+
return failure();
546546
}
547547
};
548548

@@ -783,8 +783,8 @@ struct DispatchOpConversion : public FIROpConversion<fir::DispatchOp> {
783783
mlir::LogicalResult
784784
matchAndRewrite(fir::DispatchOp dispatch, OpAdaptor adaptor,
785785
mlir::ConversionPatternRewriter &rewriter) const override {
786-
return rewriter.notifyMatchFailure(
787-
dispatch, "fir.dispatch codegen is not implemented yet");
786+
TODO(dispatch.getLoc(), "fir.dispatch codegen");
787+
return failure();
788788
}
789789
};
790790

@@ -797,8 +797,8 @@ struct DispatchTableOpConversion
797797
mlir::LogicalResult
798798
matchAndRewrite(fir::DispatchTableOp dispTab, OpAdaptor adaptor,
799799
mlir::ConversionPatternRewriter &rewriter) const override {
800-
return rewriter.notifyMatchFailure(
801-
dispTab, "fir.dispatch_table codegen is not implemented yet");
800+
TODO(dispTab.getLoc(), "fir.dispatch_table codegen");
801+
return failure();
802802
}
803803
};
804804

@@ -810,8 +810,8 @@ struct DTEntryOpConversion : public FIROpConversion<fir::DTEntryOp> {
810810
mlir::LogicalResult
811811
matchAndRewrite(fir::DTEntryOp dtEnt, OpAdaptor adaptor,
812812
mlir::ConversionPatternRewriter &rewriter) const override {
813-
return rewriter.notifyMatchFailure(
814-
dtEnt, "fir.dt_entry codegen is not implemented yet");
813+
TODO(dtEnt.getLoc(), "fir.dt_entry codegen");
814+
return failure();
815815
}
816816
};
817817

@@ -822,8 +822,8 @@ struct GlobalLenOpConversion : public FIROpConversion<fir::GlobalLenOp> {
822822
mlir::LogicalResult
823823
matchAndRewrite(fir::GlobalLenOp globalLen, OpAdaptor adaptor,
824824
mlir::ConversionPatternRewriter &rewriter) const override {
825-
return rewriter.notifyMatchFailure(
826-
globalLen, "fir.global_len codegen is not implemented yet");
825+
TODO(globalLen.getLoc(), "fir.global_len codegen");
826+
return failure();
827827
}
828828
};
829829

@@ -836,8 +836,7 @@ struct LenParamIndexOpConversion
836836
mlir::LogicalResult
837837
matchAndRewrite(fir::LenParamIndexOp lenp, OpAdaptor,
838838
mlir::ConversionPatternRewriter &rewriter) const override {
839-
return rewriter.notifyMatchFailure(
840-
lenp, "fir.len_param_index codegen is not implemented yet");
839+
TODO(lenp.getLoc(), "fir.len_param_index codegen");
841840
}
842841
};
843842

@@ -848,8 +847,8 @@ struct GenTypeDescOpConversion : public FIROpConversion<fir::GenTypeDescOp> {
848847
mlir::LogicalResult
849848
matchAndRewrite(fir::GenTypeDescOp gentypedesc, OpAdaptor adaptor,
850849
mlir::ConversionPatternRewriter &rewriter) const override {
851-
return rewriter.notifyMatchFailure(
852-
gentypedesc, "fir.fir.gentypedesc codegen is not implemented yet");
850+
TODO(gentypedesc.getLoc(), "fir.gentypedesc codegen");
851+
return failure();
853852
}
854853
};
855854

@@ -860,8 +859,8 @@ struct FirEndOpConversion : public FIROpConversion<fir::FirEndOp> {
860859
mlir::LogicalResult
861860
matchAndRewrite(fir::FirEndOp firEnd, OpAdaptor,
862861
mlir::ConversionPatternRewriter &rewriter) const override {
863-
return rewriter.notifyMatchFailure(
864-
firEnd, "fir.end codegen is not implemented yet");
862+
TODO(firEnd.getLoc(), "fir.end codegen");
863+
return failure();
865864
}
866865
};
867866

@@ -1021,11 +1020,11 @@ struct SelectCaseOpConversion : public FIROpConversion<fir::SelectCaseOp> {
10211020
unsigned conds = caseOp.getNumConditions();
10221021
llvm::ArrayRef<mlir::Attribute> cases = caseOp.getCases().getValue();
10231022
// Type can be CHARACTER, INTEGER, or LOGICAL (C1145)
1024-
LLVM_ATTRIBUTE_UNUSED auto ty = caseOp.getSelector().getType();
1025-
if (ty.isa<fir::CharacterType>())
1026-
return rewriter.notifyMatchFailure(caseOp,
1027-
"conversion of fir.select_case with "
1028-
"character type not implemented yet");
1023+
auto ty = caseOp.getSelector().getType();
1024+
if (ty.isa<fir::CharacterType>()) {
1025+
TODO(caseOp.getLoc(), "fir.select_case codegen with character type");
1026+
return failure();
1027+
}
10291028
mlir::Value selector = caseOp.getSelector(adaptor.getOperands());
10301029
auto loc = caseOp.getLoc();
10311030
for (unsigned t = 0; t != conds; ++t) {
@@ -1182,8 +1181,9 @@ struct SelectTypeOpConversion : public FIROpConversion<fir::SelectTypeOp> {
11821181
mlir::LogicalResult
11831182
matchAndRewrite(fir::SelectTypeOp select, OpAdaptor adaptor,
11841183
mlir::ConversionPatternRewriter &rewriter) const override {
1185-
return rewriter.notifyMatchFailure(
1186-
select, "fir.select_type codegen is not implemented yet");
1184+
mlir::emitError(select.getLoc(),
1185+
"fir.select_type should have already been converted");
1186+
return failure();
11871187
}
11881188
};
11891189

@@ -1254,7 +1254,7 @@ struct ZeroOpConversion : public FIROpConversion<fir::ZeroOp> {
12541254
mlir::LogicalResult
12551255
matchAndRewrite(fir::ZeroOp zero, OpAdaptor,
12561256
mlir::ConversionPatternRewriter &rewriter) const override {
1257-
auto ty = convertType(zero.getType());
1257+
mlir::Type ty = convertType(zero.getType());
12581258
if (ty.isa<mlir::LLVM::LLVMPointerType>()) {
12591259
rewriter.replaceOpWithNewOp<mlir::LLVM::NullOp>(zero, ty);
12601260
} else if (ty.isa<mlir::IntegerType>()) {
@@ -1575,10 +1575,11 @@ struct EmboxOpConversion : public EmboxCommonConversion<fir::EmboxOp> {
15751575
/*lenParams=*/adaptor.getOperands().drop_front(1));
15761576
dest = insertBaseAddress(rewriter, embox.getLoc(), dest,
15771577
adaptor.getOperands()[0]);
1578-
if (isDerivedTypeWithLenParams(boxTy))
1579-
return rewriter.notifyMatchFailure(
1580-
embox, "fir.embox codegen of derived with length parameters not "
1581-
"implemented yet");
1578+
if (isDerivedTypeWithLenParams(boxTy)) {
1579+
TODO(embox.getLoc(),
1580+
"fir.embox codegen of derived with length parameters");
1581+
return failure();
1582+
}
15821583
auto result = placeInMemoryIfNotGlobalInit(rewriter, embox.getLoc(), dest);
15831584
rewriter.replaceOp(embox, result);
15841585
return success();
@@ -1593,12 +1594,11 @@ struct EmboxProcOpConversion : public FIROpConversion<fir::EmboxProcOp> {
15931594
mlir::LogicalResult
15941595
matchAndRewrite(fir::EmboxProcOp emboxproc, OpAdaptor adaptor,
15951596
mlir::ConversionPatternRewriter &rewriter) const override {
1596-
return rewriter.notifyMatchFailure(
1597-
emboxproc, "fir.emboxproc codegen is not implemented yet");
1597+
TODO(emboxproc.getLoc(), "fir.emboxproc codegen");
1598+
return failure();
15981599
}
15991600
};
16001601

1601-
16021602
// Code shared between insert_value and extract_value Ops.
16031603
struct ValueOpCommon {
16041604
// Translate the arguments pertaining to any multidimensional array to
@@ -2110,8 +2110,8 @@ struct UnboxProcOpConversion : public FIROpConversion<fir::UnboxProcOp> {
21102110
mlir::LogicalResult
21112111
matchAndRewrite(fir::UnboxProcOp unboxproc, OpAdaptor adaptor,
21122112
mlir::ConversionPatternRewriter &rewriter) const override {
2113-
return rewriter.notifyMatchFailure(
2114-
unboxproc, "fir.unboxproc codegen is not implemented yet");
2113+
TODO(unboxproc.getLoc(), "fir.unboxproc codegen");
2114+
return failure();
21152115
}
21162116
};
21172117

flang/test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ set(FLANG_TEST_PARAMS
4646
flang_site_config=${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py)
4747

4848
set(FLANG_TEST_DEPENDS
49-
flang-new FileCheck count not module_files fir-opt tco
49+
flang-new llvm-config FileCheck count not module_files fir-opt tco
5050
)
5151

5252
if (FLANG_INCLUDE_TESTS)

flang/test/Fir/Todo/boxproc_host.fir

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: not fir-opt --fir-to-llvm-ir="target=x86_64-unknown-linux-gnu" %s 2>&1 | FileCheck %s
2+
3+
// Test that `fir.boxproc_host` fails conversion to llvm.
4+
// At the moment this test fails since `fir.boxproc` type does not have a conversion.
5+
6+
// CHECK: failed to legalize operation 'builtin.func'
7+
func @test(%bproc: !fir.boxproc<(i32) -> ()>) {
8+
%tuple = fir.boxproc_host %bproc : (!fir.boxproc<(i32) -> ()>) -> (!fir.ref<tuple<i32,f64>>)
9+
return
10+
}

flang/test/Fir/Todo/dispatch.fir

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %not_todo_cmd fir-opt --fir-to-llvm-ir="target=x86_64-unknown-linux-gnu" %s 2>&1 | FileCheck %s
2+
3+
// Test `fir.dispatch` conversion to llvm.
4+
// Not implemented yet.
5+
6+
func @dispatch(%arg0: !fir.box<!fir.type<derived3{f:f32}>>) {
7+
// CHECK: not yet implemented fir.dispatch codegen
8+
%0 = fir.dispatch "method"(%arg0) : (!fir.box<!fir.type<derived3{f:f32}>>) -> i32
9+
return
10+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %not_todo_cmd fir-opt --fir-to-llvm-ir="target=x86_64-unknown-linux-gnu" %s 2>&1 | FileCheck %s
2+
3+
// Test fir.dispatch_table conversion to llvm.
4+
// Not implemented yet.
5+
6+
// CHECK: not yet implemented fir.dispatch_table codegen
7+
fir.dispatch_table @dispatch_tbl {
8+
fir.dt_entry "method", @method_impl
9+
}

flang/test/Fir/Todo/emboxproc.fir

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %not_todo_cmd fir-opt --fir-to-llvm-ir="target=x86_64-unknown-linux-gnu" %s 2>&1 | FileCheck %s
2+
3+
// Test `fir.emboxproc` conversion to llvm.
4+
// Not implemented yet.
5+
6+
func @emboxproc_test() {
7+
%host_vars = fir.alloca tuple<i32,f64>
8+
// CHECK: not yet implemented fir.emboxproc codegen
9+
%bproc = fir.emboxproc @method_impl, %host_vars : ((i32) -> (), !fir.ref<tuple<i32,f64>>) -> !fir.boxproc<(i32) -> ()>
10+
return
11+
}

flang/test/Fir/Todo/end.fir

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %not_todo_cmd fir-opt --fir-to-llvm-ir="target=x86_64-unknown-linux-gnu" %s 2>&1 | FileCheck %s
2+
3+
// Test `fir.end` conversion to llvm.
4+
// Not implemented yet.
5+
6+
func @end_test() {
7+
// CHECK: not yet implemented fir.end codegen
8+
"fir.end"() : () -> ()
9+
}

flang/test/Fir/Todo/gentypedesc.fir

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %not_todo_cmd fir-opt --fir-to-llvm-ir="target=x86_64-unknown-linux-gnu" %s 2>&1 | FileCheck %s
2+
3+
// Test `fir.gentypedesc` conversion to llvm.
4+
// Not implemented yet.
5+
6+
func @gentypedesc() {
7+
// CHECK: not yet implemented fir.gentypedesc codegen
8+
%0 = fir.gentypedesc !fir.type<derived3>
9+
return
10+
}

flang/test/Fir/Todo/global_len.fir

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %not_todo_cmd fir-opt --fir-to-llvm-ir="target=x86_64-unknown-linux-gnu" %s 2>&1 | FileCheck %s
2+
3+
// Test `fir.global_len` conversion to llvm.
4+
// Not implemented yet.
5+
6+
fir.global @global_derived : !fir.type<minez(f:i32)> {
7+
// CHECK: not yet implemented fir.global_len codegen
8+
fir.global_len f, 1 : i32
9+
%0 = fir.undefined !fir.type<minez>
10+
fir.has_value %0 : !fir.type<minez>
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %not_todo_cmd fir-opt --fir-to-llvm-ir="target=x86_64-unknown-linux-gnu" %s 2>&1 | FileCheck %s
2+
3+
// Test `fir.len_param_index` conversion to llvm.
4+
// Not implemented yet.
5+
6+
func @lenparamindex() {
7+
// CHECK: not yet implemented fir.len_param_index codegen
8+
%0 = fir.len_param_index l1, !fir.type<twolens(l1:i32, l2:i32){i:i32, f:f32, l:i64}>
9+
return
10+
}
11+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %not_todo_cmd fir-opt --fir-to-llvm-ir="target=x86_64-unknown-linux-gnu" %s 2>&1 | FileCheck %s
2+
3+
// Test `fir.select_case` conversion to llvm with character type.
4+
// Not implemented yet.
5+
6+
func @select_case_charachter(%arg0: !fir.char<2, 10>, %arg1: !fir.char<2, 10>, %arg2: !fir.char<2, 10>) {
7+
// CHECK: not yet implemented fir.select_case codegen with character type
8+
fir.select_case %arg0 : !fir.char<2, 10> [#fir.point, %arg1, ^bb1,
9+
#fir.point, %arg2, ^bb2,
10+
unit, ^bb3]
11+
^bb1:
12+
%c1_i32 = arith.constant 1 : i32
13+
br ^bb3
14+
^bb2:
15+
%c2_i32 = arith.constant 2 : i32
16+
br ^bb3
17+
^bb3:
18+
return
19+
}

flang/test/Fir/Todo/unboxproc.fir

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: not fir-opt --fir-to-llvm-ir="target=x86_64-unknown-linux-gnu" %s 2>&1 | FileCheck %s
2+
3+
// Test `fir.unboxproc` conversion to llvm.
4+
// Not implemented yet.
5+
// Currently fails since coversion for boxproc type is not implemented.
6+
7+
// CHECK: failed to legalize operation 'builtin.func'
8+
func @boxing_match(%bproc: !fir.boxproc<(i32) -> ()>) {
9+
%ubproc:2 = fir.unboxproc %bproc : (!fir.boxproc<(i32) -> ()>) -> ((i32) -> (), !fir.ref<tuple<i32,f64>>)
10+
return
11+
}

0 commit comments

Comments
 (0)