[flang-commits] [flang] 9534e36 - [fir] Add placeholder conversion pattern for disptach operations
Valentin Clement via flang-commits
flang-commits at lists.llvm.org
Thu Nov 11 04:59:06 PST 2021
Author: Valentin Clement
Date: 2021-11-11T13:58:59+01:00
New Revision: 9534e361ea12aaecde52b8ac4c947f9a301d0c9b
URL: https://github.com/llvm/llvm-project/commit/9534e361ea12aaecde52b8ac4c947f9a301d0c9b
DIFF: https://github.com/llvm/llvm-project/commit/9534e361ea12aaecde52b8ac4c947f9a301d0c9b.diff
LOG: [fir] Add placeholder conversion pattern for disptach operations
`fir.dispatch`, `fir.dispatch_table` and `fir.dt_entry` are operations
for type-bound procedures. This patch just adds placeholder conversion
pattern that currently fails since F2003 is not implemented yet.
This patch is part of the upstreaming effort from fir-dev branch.
Reviewed By: kiranchandramohan
Differential Revision: https://reviews.llvm.org/D113662
Added:
Modified:
flang/lib/Optimizer/CodeGen/CodeGen.cpp
flang/test/Fir/convert-to-llvm-invalid.fir
Removed:
################################################################################
diff --git a/flang/lib/Optimizer/CodeGen/CodeGen.cpp b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
index a95306983ae1..4e20d3d0c9ef 100644
--- a/flang/lib/Optimizer/CodeGen/CodeGen.cpp
+++ b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
@@ -560,6 +560,46 @@ struct ConvertOpConversion : public FIROpConversion<fir::ConvertOp> {
}
};
+/// Lower `fir.dispatch` operation. A virtual call to a method in a dispatch
+/// table.
+struct DispatchOpConversion : public FIROpConversion<fir::DispatchOp> {
+ using FIROpConversion::FIROpConversion;
+
+ mlir::LogicalResult
+ matchAndRewrite(fir::DispatchOp dispatch, OpAdaptor adaptor,
+ mlir::ConversionPatternRewriter &rewriter) const override {
+ return rewriter.notifyMatchFailure(
+ dispatch, "fir.dispatch codegen is not implemented yet");
+ }
+};
+
+/// Lower `fir.dispatch_table` operation. The dispatch table for a Fortran
+/// derived type.
+struct DispatchTableOpConversion
+ : public FIROpConversion<fir::DispatchTableOp> {
+ using FIROpConversion::FIROpConversion;
+
+ mlir::LogicalResult
+ matchAndRewrite(fir::DispatchTableOp dispTab, OpAdaptor adaptor,
+ mlir::ConversionPatternRewriter &rewriter) const override {
+ return rewriter.notifyMatchFailure(
+ dispTab, "fir.dispatch_table codegen is not implemented yet");
+ }
+};
+
+/// Lower `fir.dt_entry` operation. An entry in a dispatch table; binds a
+/// method-name to a function.
+struct DTEntryOpConversion : public FIROpConversion<fir::DTEntryOp> {
+ using FIROpConversion::FIROpConversion;
+
+ mlir::LogicalResult
+ matchAndRewrite(fir::DTEntryOp dtEnt, OpAdaptor adaptor,
+ mlir::ConversionPatternRewriter &rewriter) const override {
+ return rewriter.notifyMatchFailure(
+ dtEnt, "fir.dt_entry codegen is not implemented yet");
+ }
+};
+
/// Lower `fir.has_value` operation to `llvm.return` operation.
struct HasValueOpConversion : public FIROpConversion<fir::HasValueOp> {
using FIROpConversion::FIROpConversion;
@@ -1189,6 +1229,7 @@ class FIRToLLVMLowering : public fir::FIRToLLVMLoweringBase<FIRToLLVMLowering> {
BoxAddrOpConversion, BoxDimsOpConversion, BoxEleSizeOpConversion,
BoxIsAllocOpConversion, BoxIsArrayOpConversion, BoxIsPtrOpConversion,
BoxRankOpConversion, CallOpConversion, ConvertOpConversion,
+ DispatchOpConversion, DispatchTableOpConversion, DTEntryOpConversion,
DivcOpConversion, ExtractValueOpConversion, HasValueOpConversion,
GlobalOpConversion, InsertOnRangeOpConversion, InsertValueOpConversion,
LoadOpConversion, NegcOpConversion, MulcOpConversion,
diff --git a/flang/test/Fir/convert-to-llvm-invalid.fir b/flang/test/Fir/convert-to-llvm-invalid.fir
index 66b44034c59c..c56168002e9f 100644
--- a/flang/test/Fir/convert-to-llvm-invalid.fir
+++ b/flang/test/Fir/convert-to-llvm-invalid.fir
@@ -8,3 +8,22 @@ func @zero_aggregate() {
return
}
+// -----
+
+// Test that `fir.dispatch` fails to be legalized. Not implemented yet.
+
+func @dispatch(%arg0: !fir.box<!fir.type<derived3{f:f32}>>) {
+ // expected-error at +1{{failed to legalize operation 'fir.dispatch'}}
+ %0 = fir.dispatch "method"(%arg0) : (!fir.box<!fir.type<derived3{f:f32}>>) -> i32
+ return
+}
+
+// -----
+
+// Test that `fir.dispatch_table`/`fir.dt_entry` fails to be legalized.
+// Not implemented yet.
+
+// expected-error at +1{{failed to legalize operation 'fir.dispatch_table'}}
+fir.dispatch_table @dispatch_tbl {
+ fir.dt_entry "method", @method_impl
+}
More information about the flang-commits
mailing list