[flang-commits] [flang] e718ce0 - Revert "[flang][cuda] Do not create global for derived-type with allocatable device components (#146780)"

Valentin Clement via flang-commits flang-commits at lists.llvm.org
Wed Jul 2 17:52:26 PDT 2025


Author: Valentin Clement
Date: 2025-07-02T17:51:55-07:00
New Revision: e718ce00374db478f2387cfe6214d167ec8d309a

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

LOG: Revert "[flang][cuda] Do not create global for derived-type with allocatable device components (#146780)"

This reverts commit e873ce31ae0e875081c8e5480c9c4925c97469ce.

Added: 
    

Modified: 
    flang/include/flang/Evaluate/tools.h
    flang/include/flang/Semantics/tools.h
    flang/lib/Evaluate/tools.cpp
    flang/lib/Semantics/tools.cpp

Removed: 
    flang/test/Lower/CUDA/cuda-derived.cuf


################################################################################
diff  --git a/flang/include/flang/Evaluate/tools.h b/flang/include/flang/Evaluate/tools.h
index 814fe4cccede6..cad1b634f8924 100644
--- a/flang/include/flang/Evaluate/tools.h
+++ b/flang/include/flang/Evaluate/tools.h
@@ -1286,7 +1286,16 @@ bool CheckForCoindexedObject(parser::ContextualMessages &,
     const std::optional<ActualArgument> &, const std::string &procName,
     const std::string &argName);
 
-bool CanCUDASymbolHaveSaveAttr(const Symbol &sym);
+inline bool CanCUDASymbolHaveSaveAttr(const Symbol &sym) {
+  if (const auto *details =
+          sym.GetUltimate().detailsIf<semantics::ObjectEntityDetails>()) {
+    if (details->cudaDataAttr() &&
+        *details->cudaDataAttr() != common::CUDADataAttr::Unified) {
+      return false;
+    }
+  }
+  return true;
+}
 
 inline bool IsCUDADeviceSymbol(const Symbol &sym) {
   if (const auto *details =

diff  --git a/flang/include/flang/Semantics/tools.h b/flang/include/flang/Semantics/tools.h
index ca58e1065d3e5..f3cfa9b99fb4d 100644
--- a/flang/include/flang/Semantics/tools.h
+++ b/flang/include/flang/Semantics/tools.h
@@ -654,8 +654,6 @@ DirectComponentIterator::const_iterator FindAllocatableOrPointerDirectComponent(
     const DerivedTypeSpec &);
 PotentialComponentIterator::const_iterator
 FindPolymorphicAllocatablePotentialComponent(const DerivedTypeSpec &);
-UltimateComponentIterator::const_iterator
-FindCUDADeviceAllocatableUltimateComponent(const DerivedTypeSpec &);
 
 // The LabelEnforce class (given a set of labels) provides an error message if
 // there is a branch to a label which is not in the given set.

diff  --git a/flang/lib/Evaluate/tools.cpp b/flang/lib/Evaluate/tools.cpp
index d912fc167a62e..fcacdb93d662b 100644
--- a/flang/lib/Evaluate/tools.cpp
+++ b/flang/lib/Evaluate/tools.cpp
@@ -2173,25 +2173,6 @@ bool IsAutomatic(const Symbol &original) {
   return false;
 }
 
-bool CanCUDASymbolHaveSaveAttr(const Symbol &sym) {
-  if (const auto *details{
-          sym.GetUltimate().detailsIf<semantics::ObjectEntityDetails>()}) {
-    const Fortran::semantics::DeclTypeSpec *type{details->type()};
-    const Fortran::semantics::DerivedTypeSpec *derived{
-        type ? type->AsDerived() : nullptr};
-    if (derived) {
-      if (FindCUDADeviceAllocatableUltimateComponent(*derived)) {
-        return false;
-      }
-    }
-    if (details->cudaDataAttr() &&
-        *details->cudaDataAttr() != common::CUDADataAttr::Unified) {
-      return false;
-    }
-  }
-  return true;
-}
-
 bool IsSaved(const Symbol &original) {
   const Symbol &symbol{GetAssociationRoot(original)};
   const Scope &scope{symbol.owner()};
@@ -2214,7 +2195,7 @@ bool IsSaved(const Symbol &original) {
   } else if (scopeKind == Scope::Kind::Module ||
       (scopeKind == Scope::Kind::MainProgram &&
           (symbol.attrs().test(Attr::TARGET) || evaluate::IsCoarray(symbol)) &&
-          CanCUDASymbolHaveSaveAttr(symbol))) {
+          Fortran::evaluate::CanCUDASymbolHaveSaveAttr(symbol))) {
     // 8.5.16p4
     // In main programs, implied SAVE matters only for pointer
     // initialization targets and coarrays.
@@ -2224,7 +2205,7 @@ bool IsSaved(const Symbol &original) {
           (features.IsEnabled(
                common::LanguageFeature::SaveBigMainProgramVariables) &&
               symbol.size() > 32)) &&
-      CanCUDASymbolHaveSaveAttr(symbol)) {
+      Fortran::evaluate::CanCUDASymbolHaveSaveAttr(symbol)) {
     // With SaveBigMainProgramVariables, keeping all unsaved main program
     // variables of 32 bytes or less on the stack allows keeping numerical and
     // logical scalars, small scalar characters or derived, small arrays, and
@@ -2242,15 +2223,15 @@ bool IsSaved(const Symbol &original) {
   } else if (symbol.test(Symbol::Flag::InDataStmt)) {
     return true;
   } else if (const auto *object{symbol.detailsIf<ObjectEntityDetails>()};
-      object && object->init()) {
+             object && object->init()) {
     return true;
   } else if (IsProcedurePointer(symbol) && symbol.has<ProcEntityDetails>() &&
       symbol.get<ProcEntityDetails>().init()) {
     return true;
   } else if (scope.hasSAVE()) {
     return true; // bare SAVE statement
-  } else if (const Symbol *block{FindCommonBlockContaining(symbol)};
-      block && block->attrs().test(Attr::SAVE)) {
+  } else if (const Symbol * block{FindCommonBlockContaining(symbol)};
+             block && block->attrs().test(Attr::SAVE)) {
     return true; // in COMMON with SAVE
   } else {
     return false;

diff  --git a/flang/lib/Semantics/tools.cpp b/flang/lib/Semantics/tools.cpp
index 498bbc18709ab..d053179448c00 100644
--- a/flang/lib/Semantics/tools.cpp
+++ b/flang/lib/Semantics/tools.cpp
@@ -1081,19 +1081,6 @@ const Scope *FindCUDADeviceContext(const Scope *scope) {
   });
 }
 
-bool IsDeviceAllocatable(const Symbol &symbol) {
-  if (IsAllocatable(symbol)) {
-    if (const auto *details{
-            symbol.GetUltimate().detailsIf<semantics::ObjectEntityDetails>()}) {
-      if (details->cudaDataAttr() &&
-          *details->cudaDataAttr() != common::CUDADataAttr::Pinned) {
-        return true;
-      }
-    }
-  }
-  return false;
-}
-
 std::optional<common::CUDADataAttr> GetCUDADataAttr(const Symbol *symbol) {
   const auto *object{
       symbol ? symbol->detailsIf<ObjectEntityDetails>() : nullptr};
@@ -1439,12 +1426,6 @@ FindPolymorphicAllocatablePotentialComponent(const DerivedTypeSpec &derived) {
       potentials.begin(), potentials.end(), IsPolymorphicAllocatable);
 }
 
-UltimateComponentIterator::const_iterator
-FindCUDADeviceAllocatableUltimateComponent(const DerivedTypeSpec &derived) {
-  UltimateComponentIterator ultimates{derived};
-  return std::find_if(ultimates.begin(), ultimates.end(), IsDeviceAllocatable);
-}
-
 const Symbol *FindUltimateComponent(const DerivedTypeSpec &derived,
     const std::function<bool(const Symbol &)> &predicate) {
   UltimateComponentIterator ultimates{derived};
@@ -1807,4 +1788,4 @@ bool HadUseError(
   }
 }
 
-} // namespace Fortran::semantics
+} // namespace Fortran::semantics
\ No newline at end of file

diff  --git a/flang/test/Lower/CUDA/cuda-derived.cuf b/flang/test/Lower/CUDA/cuda-derived.cuf
deleted file mode 100644
index d280ac722d08f..0000000000000
--- a/flang/test/Lower/CUDA/cuda-derived.cuf
+++ /dev/null
@@ -1,20 +0,0 @@
-! RUN: bbc -emit-hlfir -fcuda %s -o - | FileCheck %s
-
-module m1
-  type ty_device
-    integer, device, allocatable, dimension(:) :: x
-  end type
-
-  type t1; real, device, allocatable :: a(:); end type
-  type t2; type(t1) :: b; end type
-end module
-
-program main
-  use m1
-  type(ty_device) :: a
-  type(t2) :: b
-end
-
-! CHECK-LABEL: func.func @_QQmain() attributes {fir.bindc_name = "main"}
-! CHECK: %{{.*}} = fir.alloca !fir.type<_QMm1Tty_device{x:!fir.box<!fir.heap<!fir.array<?xi32>>>}> {bindc_name = "a", uniq_name = "_QFEa"}
-! CHECK: %{{.*}} = fir.alloca !fir.type<_QMm1Tt2{b:!fir.type<_QMm1Tt1{a:!fir.box<!fir.heap<!fir.array<?xf32>>>}>}> {bindc_name = "b", uniq_name = "_QFEb"}


        


More information about the flang-commits mailing list