[flang-commits] [flang] 9de831a - Add lowering TODO for bindings returning derived types or arrays

Valentin Clement via flang-commits flang-commits at lists.llvm.org
Tue Jun 14 01:48:56 PDT 2022


Author: Jean Perier
Date: 2022-06-14T10:48:44+02:00
New Revision: 9de831aa2cbc6ab94265ff8136fb36d9b6c1cfae

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

LOG: Add lowering TODO for bindings returning derived types or arrays

Codegen does not support fir.addressof of functions returning derived
types, arrays are descriptors inside GlobalOp region.

This is because the  abstract-result-opt is required to rewrite such
functions (a hidden argument must be added), but this pass is meant to
run in GlobalOp currently.

Such fir.address_of may be created when lowering procedure pointers
initial value (TODO), or when creating derived type descriptors for
types with bindings.

Add a TODO in lowering until abstract-result-opt is modified to run
on GlobalOp too.

This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: jeanPerier

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

Added: 
    

Modified: 
    flang/lib/Lower/ConvertExpr.cpp
    flang/lib/Optimizer/Transforms/AbstractResult.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Lower/ConvertExpr.cpp b/flang/lib/Lower/ConvertExpr.cpp
index 76a51abfdc913..660de0b88c02f 100644
--- a/flang/lib/Lower/ConvertExpr.cpp
+++ b/flang/lib/Lower/ConvertExpr.cpp
@@ -822,6 +822,13 @@ class ScalarExprLowering {
       std::string name = converter.mangleName(*symbol);
       mlir::func::FuncOp func =
           Fortran::lower::getOrDeclareFunction(name, proc, converter);
+      // Abstract results require later rewrite of the function type.
+      // This currently does not happen inside GloalOps, causing LLVM
+      // IR verification failure. This helper is only here to catch these
+      // cases and emit a TODOs for now.
+      if (inInitializer && fir::hasAbstractResult(func.getFunctionType()))
+        TODO(converter.genLocation(symbol->name()),
+             "static description of non trivial procedure bindings");
       funcPtr = builder.create<fir::AddrOfOp>(loc, func.getFunctionType(),
                                               builder.getSymbolRefAttr(name));
     }

diff  --git a/flang/lib/Optimizer/Transforms/AbstractResult.cpp b/flang/lib/Optimizer/Transforms/AbstractResult.cpp
index 1946ccdfd69f9..7dd821474698f 100644
--- a/flang/lib/Optimizer/Transforms/AbstractResult.cpp
+++ b/flang/lib/Optimizer/Transforms/AbstractResult.cpp
@@ -7,6 +7,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "PassDetail.h"
+#include "flang/Optimizer/Builder/Todo.h"
 #include "flang/Optimizer/Dialect/FIRDialect.h"
 #include "flang/Optimizer/Dialect/FIROps.h"
 #include "flang/Optimizer/Dialect/FIRType.h"
@@ -31,13 +32,6 @@ struct AbstractResultOptions {
   mlir::Value newArg;
 };
 
-static bool mustConvertCallOrFunc(mlir::FunctionType type) {
-  if (type.getNumResults() == 0)
-    return false;
-  auto resultType = type.getResult(0);
-  return resultType.isa<fir::SequenceType, fir::BoxType, fir::RecordType>();
-}
-
 static mlir::Type getResultArgumentType(mlir::Type resultType,
                                         const AbstractResultOptions &options) {
   return llvm::TypeSwitch<mlir::Type, mlir::Type>(resultType)
@@ -223,7 +217,7 @@ class AbstractResultOpt : public fir::AbstractResultOptBase<AbstractResultOpt> {
 
     // Convert function type itself if it has an abstract result
     auto funcTy = func.getFunctionType().cast<mlir::FunctionType>();
-    if (mustConvertCallOrFunc(funcTy)) {
+    if (hasAbstractResult(funcTy)) {
       func.setType(getNewFunctionType(funcTy, options));
       unsigned zero = 0;
       if (!func.empty()) {
@@ -252,11 +246,11 @@ class AbstractResultOpt : public fir::AbstractResultOptBase<AbstractResultOpt> {
                            mlir::func::FuncDialect>();
     target.addIllegalOp<fir::SaveResultOp>();
     target.addDynamicallyLegalOp<fir::CallOp>([](fir::CallOp call) {
-      return !mustConvertCallOrFunc(call.getFunctionType());
+      return !hasAbstractResult(call.getFunctionType());
     });
     target.addDynamicallyLegalOp<fir::AddrOfOp>([](fir::AddrOfOp addrOf) {
       if (auto funTy = addrOf.getType().dyn_cast<mlir::FunctionType>())
-        return !mustConvertCallOrFunc(funTy);
+        return !hasAbstractResult(funTy);
       return true;
     });
     target.addDynamicallyLegalOp<fir::DispatchOp>([](fir::DispatchOp dispatch) {
@@ -264,8 +258,7 @@ class AbstractResultOpt : public fir::AbstractResultOptBase<AbstractResultOpt> {
         return true;
       auto resultType = dispatch->getResult(0).getType();
       if (resultType.isa<fir::SequenceType, fir::BoxType, fir::RecordType>()) {
-        mlir::emitError(dispatch.getLoc(),
-                        "TODO: dispatchOp with abstract results");
+        TODO(dispatch.getLoc(), "dispatchOp with abstract results");
         return false;
       }
       return true;


        


More information about the flang-commits mailing list