[llvm-branch-commits] [flang] 748b17c - Revert "[flang] Align runtime info and lowering regarding passing ABIs (#81166)"

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Fri Feb 9 00:37:18 PST 2024


Author: jeanPerier
Date: 2024-02-09T09:37:12+01:00
New Revision: 748b17c66400aaf6fe85eaf8dde56de80322b73e

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

LOG: Revert "[flang] Align runtime info and lowering regarding passing ABIs (#81166)"

This reverts commit b477d39bf6811ac12a1e7e98f308cf4c9a8de26f.

Added: 
    

Modified: 
    flang/include/flang/Evaluate/characteristics.h
    flang/lib/Evaluate/characteristics.cpp
    flang/lib/Lower/CallInterface.cpp
    flang/lib/Semantics/runtime-type-info.cpp

Removed: 
    flang/test/Semantics/typeinfo09.f90


################################################################################
diff  --git a/flang/include/flang/Evaluate/characteristics.h b/flang/include/flang/Evaluate/characteristics.h
index 04a0d71e1adebe..fd4af157f79374 100644
--- a/flang/include/flang/Evaluate/characteristics.h
+++ b/flang/include/flang/Evaluate/characteristics.h
@@ -229,7 +229,6 @@ struct DummyDataObject {
   static std::optional<DummyDataObject> Characterize(
       const semantics::Symbol &, FoldingContext &);
   bool CanBePassedViaImplicitInterface(std::string *whyNot = nullptr) const;
-  bool IsPassedByDescriptor(bool isBindC) const;
   llvm::raw_ostream &Dump(llvm::raw_ostream &) const;
 
   TypeAndShape type;

diff  --git a/flang/lib/Evaluate/characteristics.cpp b/flang/lib/Evaluate/characteristics.cpp
index c14a422ad038f0..d480050d354fb9 100644
--- a/flang/lib/Evaluate/characteristics.cpp
+++ b/flang/lib/Evaluate/characteristics.cpp
@@ -461,30 +461,6 @@ bool DummyDataObject::CanBePassedViaImplicitInterface(
   }
 }
 
-bool DummyDataObject::IsPassedByDescriptor(bool isBindC) const {
-  constexpr TypeAndShape::Attrs shapeRequiringBox = {
-      TypeAndShape::Attr::AssumedShape, TypeAndShape::Attr::DeferredShape,
-      TypeAndShape::Attr::AssumedRank, TypeAndShape::Attr::Coarray};
-  if ((attrs & Attrs{Attr::Allocatable, Attr::Pointer}).any()) {
-    return true;
-  } else if ((type.attrs() & shapeRequiringBox).any()) {
-    // Need to pass shape/coshape info in a descriptor.
-    return true;
-  } else if (type.type().IsPolymorphic() && !type.type().IsAssumedType()) {
-    // Need to pass dynamic type info in a descriptor.
-    return true;
-  } else if (const auto *derived{GetDerivedTypeSpec(type.type())}) {
-    if (const semantics::Scope *scope = derived->scope()) {
-      // Need to pass length type parameters in a descriptor if any.
-      return scope->IsDerivedTypeWithLengthParameter();
-    }
-  } else if (isBindC && type.type().IsAssumedLengthCharacter()) {
-    // Fortran 2018 18.3.6 point 2 (5)
-    return true;
-  }
-  return false;
-}
-
 llvm::raw_ostream &DummyDataObject::Dump(llvm::raw_ostream &o) const {
   attrs.Dump(o, EnumToString);
   if (intent != common::Intent::Default) {

diff  --git a/flang/lib/Lower/CallInterface.cpp b/flang/lib/Lower/CallInterface.cpp
index f67ee880a2ff7b..4c297ceffc536d 100644
--- a/flang/lib/Lower/CallInterface.cpp
+++ b/flang/lib/Lower/CallInterface.cpp
@@ -916,6 +916,31 @@ class Fortran::lower::CallInterfaceImpl {
     }
   }
 
+  // Define when an explicit argument must be passed in a fir.box.
+  bool dummyRequiresBox(
+      const Fortran::evaluate::characteristics::DummyDataObject &obj,
+      bool isBindC) {
+    using ShapeAttr = Fortran::evaluate::characteristics::TypeAndShape::Attr;
+    using ShapeAttrs = Fortran::evaluate::characteristics::TypeAndShape::Attrs;
+    constexpr ShapeAttrs shapeRequiringBox = {
+        ShapeAttr::AssumedShape, ShapeAttr::DeferredShape,
+        ShapeAttr::AssumedRank, ShapeAttr::Coarray};
+    if ((obj.type.attrs() & shapeRequiringBox).any())
+      // Need to pass shape/coshape info in fir.box.
+      return true;
+    if (obj.type.type().IsPolymorphic() && !obj.type.type().IsAssumedType())
+      // Need to pass dynamic type info in fir.box.
+      return true;
+    if (const Fortran::semantics::DerivedTypeSpec *derived =
+            Fortran::evaluate::GetDerivedTypeSpec(obj.type.type()))
+      if (const Fortran::semantics::Scope *scope = derived->scope())
+        // Need to pass length type parameters in fir.box if any.
+        return scope->IsDerivedTypeWithLengthParameter();
+    if (isBindC && obj.type.type().IsAssumedLengthCharacter())
+      return true; // Fortran 2018 18.3.6 point 2 (5)
+    return false;
+  }
+
   mlir::Type
   translateDynamicType(const Fortran::evaluate::DynamicType &dynamicType) {
     Fortran::common::TypeCategory cat = dynamicType.category();
@@ -1002,7 +1027,7 @@ class Fortran::lower::CallInterfaceImpl {
       addFirOperand(boxRefType, nextPassedArgPosition(), Property::MutableBox,
                     attrs);
       addPassedArg(PassEntityBy::MutableBox, entity, characteristics);
-    } else if (obj.IsPassedByDescriptor(isBindC)) {
+    } else if (dummyRequiresBox(obj, isBindC)) {
       // Pass as fir.box or fir.class
       if (isValueAttr &&
           !getConverter().getLoweringOptions().getLowerToHighLevelFIR())

diff  --git a/flang/lib/Semantics/runtime-type-info.cpp b/flang/lib/Semantics/runtime-type-info.cpp
index 66c42160ee9e9a..de71083a21ff50 100644
--- a/flang/lib/Semantics/runtime-type-info.cpp
+++ b/flang/lib/Semantics/runtime-type-info.cpp
@@ -1144,7 +1144,7 @@ void RuntimeTableBuilder::DescribeSpecialProc(
           which = scalarFinalEnum_;
           if (int rank{evaluate::GetRank(typeAndShape.shape())}; rank > 0) {
             which = IntExpr<1>(ToInt64(which).value() + rank);
-            if (dummyData.IsPassedByDescriptor(proc->IsBindC())) {
+            if (!proc->dummyArguments[0].CanBePassedViaImplicitInterface()) {
               argThatMightBeDescriptor = 1;
             }
             if (!typeAndShape.attrs().test(evaluate::characteristics::
@@ -1187,14 +1187,10 @@ void RuntimeTableBuilder::DescribeSpecialProc(
         break;
       }
     }
-    if (argThatMightBeDescriptor != 0) {
-      if (const auto *dummyData{
-              std::get_if<evaluate::characteristics::DummyDataObject>(
-                  &proc->dummyArguments.at(argThatMightBeDescriptor - 1).u)}) {
-        if (dummyData->IsPassedByDescriptor(proc->IsBindC())) {
-          isArgDescriptorSet |= 1 << (argThatMightBeDescriptor - 1);
-        }
-      }
+    if (argThatMightBeDescriptor != 0 &&
+        !proc->dummyArguments.at(argThatMightBeDescriptor - 1)
+             .CanBePassedViaImplicitInterface()) {
+      isArgDescriptorSet |= 1 << (argThatMightBeDescriptor - 1);
     }
     evaluate::StructureConstructorValues values;
     auto index{evaluate::ToInt64(which)};

diff  --git a/flang/test/Semantics/typeinfo09.f90 b/flang/test/Semantics/typeinfo09.f90
deleted file mode 100644
index 3527ee6058ad80..00000000000000
--- a/flang/test/Semantics/typeinfo09.f90
+++ /dev/null
@@ -1,20 +0,0 @@
-!RUN: bbc --dump-symbols %s | FileCheck %s
-!RUN: %flang_fc1 -fdebug-dump-symbols %s | FileCheck %s
-! test setting of isargdescriptorset in the runtime type info.
-
-module m
- type :: sometype
- contains
-  procedure :: copy => copy_impl
-  generic :: assignment(=) => copy
- end type
-interface
-  subroutine copy_impl(this, x)
-    import
-    class(sometype), intent(out) :: this
-    type(sometype), target, intent(in) :: x
-  end subroutine
-end interface
-end module
-
-!CHECK: .s.sometype, SAVE, TARGET (CompilerCreated, ReadOnly): ObjectEntity type: TYPE(specialbinding) shape: 0_8:0_8 init:[specialbinding::specialbinding(which=1_1,isargdescriptorset=1_1,istypebound=1_1,isargcontiguousset=0_1,proc=copy_impl)]


        


More information about the llvm-branch-commits mailing list