diff --git a/flang/lib/Optimizer/CodeGen/CodeGen.cpp b/flang/lib/Optimizer/CodeGen/CodeGen.cpp --- a/flang/lib/Optimizer/CodeGen/CodeGen.cpp +++ b/flang/lib/Optimizer/CodeGen/CodeGen.cpp @@ -371,6 +371,49 @@ } }; +/// Lower of `fir.dispatch` operation. A virtual call to a method in a dispatch +/// table. +/// TODO: F2003 features. +struct DispatchOpConversion : public FIROpConversion { + 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 of `fir.dispatch_table` operation. The dispatch table for a Fortran +/// derived type. +/// TODO: F2003 features. +struct DispatchTableOpConversion + : public FIROpConversion { + 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 of `fir.dt_entry` operation. An entry in a dispatch table; binds a +/// method-name to a function. +/// TODO: F2003 features. +struct DTEntryOpConversion : public FIROpConversion { + 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 { using FIROpConversion::FIROpConversion; @@ -999,6 +1042,7 @@ AddcOpConversion, AddrOfOpConversion, BoxAddrOpConversion, BoxDimsOpConversion, BoxEleSizeOpConversion, BoxRankOpConversion, CallOpConversion, ConvertOpConversion, DivcOpConversion, + DispatchOpConversion, DispatchTableOpConversion, DTEntryOpConversion, ExtractValueOpConversion, HasValueOpConversion, GlobalOpConversion, InsertOnRangeOpConversion, InsertValueOpConversion, LoadOpConversion, NegcOpConversion, MulcOpConversion, SelectOpConversion, diff --git a/flang/test/Fir/convert-to-llvm-invalid.fir b/flang/test/Fir/convert-to-llvm-invalid.fir --- a/flang/test/Fir/convert-to-llvm-invalid.fir +++ b/flang/test/Fir/convert-to-llvm-invalid.fir @@ -8,3 +8,22 @@ return } +// ----- + +// Test that `fir.dispatch` fails to be legalized. Not implemented yet. + +func @dispatch(%arg0: !fir.box>) { + // expected-error@+1{{failed to legalize operation 'fir.dispatch'}} + %0 = fir.dispatch "method"(%arg0) : (!fir.box>) -> i32 + return +} + +// ----- + +// Test that `fir.dispatch_table`/`fir.dt_entry` fails to be legalized. +// Not implemented yet. + +// expected-error@+1{{failed to legalize operation 'fir.dispatch_table'}} +fir.dispatch_table @dispatch_tbl { + fir.dt_entry "method", @method_impl +}