[flang-commits] [flang] cc505c0 - [Flang] Notify conversion failure for Proc ops, types

Kiran Chandramohan via flang-commits flang-commits at lists.llvm.org
Thu Nov 18 04:27:50 PST 2021


Author: Kiran Chandramohan
Date: 2021-11-18T12:27:25Z
New Revision: cc505c0bb7335102eea98517e5ad0e9ca831133f

URL: https://github.com/llvm/llvm-project/commit/cc505c0bb7335102eea98517e5ad0e9ca831133f
DIFF: https://github.com/llvm/llvm-project/commit/cc505c0bb7335102eea98517e5ad0e9ca831133f.diff

LOG: [Flang] Notify conversion failure for Proc ops, types

Add the FIR to LLVM conversion patterns for the BoxProcHostOp, EmboxProcOp,
and UnboxProcOp ops and the boxproc type. These are currently unimplemented.
Implementation will come at a later time when support for Fortran 2003
procedure pointer feature is added.

Reviewed By: clementval, rovka

Differential Revision: https://reviews.llvm.org/D113879

Co-authored-by: Eric Schweitz <eschweitz at nvidia.com>

Added: 
    

Modified: 
    flang/lib/Optimizer/CodeGen/CodeGen.cpp
    flang/lib/Optimizer/CodeGen/TypeConverter.h
    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 cd7dbb66c4533..f14c0a612a890 100644
--- a/flang/lib/Optimizer/CodeGen/CodeGen.cpp
+++ b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
@@ -532,6 +532,20 @@ struct StringLitOpConversion : public FIROpConversion<fir::StringLitOp> {
   }
 };
 
+/// Lower `fir.boxproc_host` operation. Extracts the host pointer from the
+/// boxproc.
+/// TODO: Part of supporting Fortran 2003 procedure pointers.
+struct BoxProcHostOpConversion : public FIROpConversion<fir::BoxProcHostOp> {
+  using FIROpConversion::FIROpConversion;
+
+  mlir::LogicalResult
+  matchAndRewrite(fir::BoxProcHostOp boxprochost, OpAdaptor adaptor,
+                  mlir::ConversionPatternRewriter &rewriter) const override {
+    return rewriter.notifyMatchFailure(
+        boxprochost, "fir.boxproc_host codegen is not implemented yet");
+  }
+};
+
 /// Lower `fir.box_tdesc` to the sequence of operations to extract the type
 /// descriptor from the box.
 struct BoxTypeDescOpConversion : public FIROpConversion<fir::BoxTypeDescOp> {
@@ -1529,6 +1543,20 @@ struct EmboxOpConversion : public EmboxCommonConversion<fir::EmboxOp> {
   }
 };
 
+/// Lower `fir.emboxproc` operation. Creates a procedure box.
+/// TODO: Part of supporting Fortran 2003 procedure pointers.
+struct EmboxProcOpConversion : public FIROpConversion<fir::EmboxProcOp> {
+  using FIROpConversion::FIROpConversion;
+
+  mlir::LogicalResult
+  matchAndRewrite(fir::EmboxProcOp emboxproc, OpAdaptor adaptor,
+                  mlir::ConversionPatternRewriter &rewriter) const override {
+    return rewriter.notifyMatchFailure(
+        emboxproc, "fir.emboxproc codegen is not implemented yet");
+  }
+};
+
+
 // Code shared between insert_value and extract_value Ops.
 struct ValueOpCommon {
   // Translate the arguments pertaining to any multidimensional array to
@@ -2035,6 +2063,20 @@ struct UnboxCharOpConversion : public FIROpConversion<fir::UnboxCharOp> {
   }
 };
 
+/// Lower `fir.unboxproc` operation. Unbox a procedure box value, yielding its
+/// components.
+/// TODO: Part of supporting Fortran 2003 procedure pointers.
+struct UnboxProcOpConversion : public FIROpConversion<fir::UnboxProcOp> {
+  using FIROpConversion::FIROpConversion;
+
+  mlir::LogicalResult
+  matchAndRewrite(fir::UnboxProcOp unboxproc, OpAdaptor adaptor,
+                  mlir::ConversionPatternRewriter &rewriter) const override {
+    return rewriter.notifyMatchFailure(
+        unboxproc, "fir.unboxproc codegen is not implemented yet");
+  }
+};
+
 } // namespace
 
 namespace {
@@ -2061,20 +2103,21 @@ class FIRToLLVMLowering : public fir::FIRToLLVMLoweringBase<FIRToLLVMLowering> {
         AbsentOpConversion, AddcOpConversion, AddrOfOpConversion,
         AllocaOpConversion, BoxAddrOpConversion, BoxCharLenOpConversion,
         BoxDimsOpConversion, BoxEleSizeOpConversion, BoxIsAllocOpConversion,
-        BoxIsArrayOpConversion, BoxIsPtrOpConversion, BoxRankOpConversion,
-        BoxTypeDescOpConversion, CallOpConversion, CmpcOpConversion,
-        ConstcOpConversion, ConvertOpConversion, DispatchOpConversion,
-        DispatchTableOpConversion, DTEntryOpConversion, DivcOpConversion,
-        EmboxOpConversion, EmboxCharOpConversion, ExtractValueOpConversion,
-        HasValueOpConversion, GenTypeDescOpConversion, GlobalLenOpConversion,
-        GlobalOpConversion, InsertOnRangeOpConversion, InsertValueOpConversion,
+        BoxIsArrayOpConversion, BoxIsPtrOpConversion, BoxProcHostOpConversion,
+        BoxRankOpConversion, BoxTypeDescOpConversion, CallOpConversion,
+        CmpcOpConversion, ConstcOpConversion, ConvertOpConversion,
+        DispatchOpConversion, DispatchTableOpConversion, DTEntryOpConversion,
+        DivcOpConversion, EmboxOpConversion, EmboxCharOpConversion,
+        EmboxProcOpConversion, ExtractValueOpConversion, HasValueOpConversion,
+        GenTypeDescOpConversion, GlobalLenOpConversion, GlobalOpConversion,
+        InsertOnRangeOpConversion, InsertValueOpConversion,
         IsPresentOpConversion, LoadOpConversion, NegcOpConversion,
         MulcOpConversion, SelectCaseOpConversion, SelectOpConversion,
         SelectRankOpConversion, SelectTypeOpConversion, ShapeOpConversion,
         ShapeShiftOpConversion, ShiftOpConversion, SliceOpConversion,
         StoreOpConversion, StringLitOpConversion, SubcOpConversion,
-        UnboxCharOpConversion, UndefOpConversion, UnreachableOpConversion,
-        ZeroOpConversion>(typeConverter);
+        UnboxCharOpConversion, UnboxProcOpConversion, UndefOpConversion,
+        UnreachableOpConversion, ZeroOpConversion>(typeConverter);
     mlir::populateStdToLLVMConversionPatterns(typeConverter, pattern);
     mlir::arith::populateArithmeticToLLVMConversionPatterns(typeConverter,
                                                             pattern);

diff  --git a/flang/lib/Optimizer/CodeGen/TypeConverter.h b/flang/lib/Optimizer/CodeGen/TypeConverter.h
index 0f112c630d8f6..c05017423b667 100644
--- a/flang/lib/Optimizer/CodeGen/TypeConverter.h
+++ b/flang/lib/Optimizer/CodeGen/TypeConverter.h
@@ -54,6 +54,11 @@ class LLVMTypeConverter : public mlir::LLVMTypeConverter {
       LLVM_DEBUG(llvm::dbgs() << "type convert: " << boxchar << '\n');
       return convertType(specifics->boxcharMemoryType(boxchar.getEleTy()));
     });
+    addConversion([&](BoxProcType boxproc) {
+      // TODO: Support for this type will be added later when the Fortran 2003
+      // procedure pointer feature is implemented.
+      return llvm::None;
+    });
     addConversion(
         [&](fir::CharacterType charTy) { return convertCharType(charTy); });
     addConversion([&](HeapType heap) { return convertPointerLike(heap); });

diff  --git a/flang/test/Fir/convert-to-llvm-invalid.fir b/flang/test/Fir/convert-to-llvm-invalid.fir
index c8ee4e94b91ee..3c657d3f3a017 100644
--- a/flang/test/Fir/convert-to-llvm-invalid.fir
+++ b/flang/test/Fir/convert-to-llvm-invalid.fir
@@ -148,3 +148,28 @@ func @shape_shift_not_dead(%arg0: !fir.ref<!fir.array<?x?xf32>>, %i: index, %j:
   %1 = fir.array_coor %arg0(%0) %i, %j : (!fir.ref<!fir.array<?x?xf32>>, !fir.shapeshift<2>, index, index) -> !fir.ref<f32>
   return
 }
+
+// -----
+
+// Test that the type `fir.boxproc` fails to be legalized.
+// Not implemented yet.
+
+// expected-error at +1{{failed to legalize operation 'builtin.func'}}
+func private @foo0(%arg0: !fir.boxproc<() -> ()>)
+
+// -----
+
+// Test that `fir.emboxproc` fails to be legalized.
+// Not implemented yet.
+
+func private @method_impl(i32)
+
+func @emboxproc_test() {
+  %host_vars = fir.alloca tuple<i32,f64>
+// expected-error at +1{{failed to legalize operation 'fir.emboxproc'}}
+  %bproc = fir.emboxproc @method_impl, %host_vars : ((i32) -> (), !fir.ref<tuple<i32,f64>>) -> !fir.boxproc<(i32) -> ()>
+  return
+}
+
+// Test that `fir.unboxproc` and `fir.boxproc_host` also fails to be legalized.
+// At the moment these cannot be tested since the `fir.boxproc` type does not have a conversion.


        


More information about the flang-commits mailing list