Skip to content

Commit e718ce0

Browse files
committed
Revert "[flang][cuda] Do not create global for derived-type with allocatable device components (#146780)"
This reverts commit e873ce3.
1 parent a535078 commit e718ce0

File tree

5 files changed

+16
-67
lines changed

5 files changed

+16
-67
lines changed

flang/include/flang/Evaluate/tools.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1286,7 +1286,16 @@ bool CheckForCoindexedObject(parser::ContextualMessages &,
12861286
const std::optional<ActualArgument> &, const std::string &procName,
12871287
const std::string &argName);
12881288

1289-
bool CanCUDASymbolHaveSaveAttr(const Symbol &sym);
1289+
inline bool CanCUDASymbolHaveSaveAttr(const Symbol &sym) {
1290+
if (const auto *details =
1291+
sym.GetUltimate().detailsIf<semantics::ObjectEntityDetails>()) {
1292+
if (details->cudaDataAttr() &&
1293+
*details->cudaDataAttr() != common::CUDADataAttr::Unified) {
1294+
return false;
1295+
}
1296+
}
1297+
return true;
1298+
}
12901299

12911300
inline bool IsCUDADeviceSymbol(const Symbol &sym) {
12921301
if (const auto *details =

flang/include/flang/Semantics/tools.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -654,8 +654,6 @@ DirectComponentIterator::const_iterator FindAllocatableOrPointerDirectComponent(
654654
const DerivedTypeSpec &);
655655
PotentialComponentIterator::const_iterator
656656
FindPolymorphicAllocatablePotentialComponent(const DerivedTypeSpec &);
657-
UltimateComponentIterator::const_iterator
658-
FindCUDADeviceAllocatableUltimateComponent(const DerivedTypeSpec &);
659657

660658
// The LabelEnforce class (given a set of labels) provides an error message if
661659
// there is a branch to a label which is not in the given set.

flang/lib/Evaluate/tools.cpp

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2173,25 +2173,6 @@ bool IsAutomatic(const Symbol &original) {
21732173
return false;
21742174
}
21752175

2176-
bool CanCUDASymbolHaveSaveAttr(const Symbol &sym) {
2177-
if (const auto *details{
2178-
sym.GetUltimate().detailsIf<semantics::ObjectEntityDetails>()}) {
2179-
const Fortran::semantics::DeclTypeSpec *type{details->type()};
2180-
const Fortran::semantics::DerivedTypeSpec *derived{
2181-
type ? type->AsDerived() : nullptr};
2182-
if (derived) {
2183-
if (FindCUDADeviceAllocatableUltimateComponent(*derived)) {
2184-
return false;
2185-
}
2186-
}
2187-
if (details->cudaDataAttr() &&
2188-
*details->cudaDataAttr() != common::CUDADataAttr::Unified) {
2189-
return false;
2190-
}
2191-
}
2192-
return true;
2193-
}
2194-
21952176
bool IsSaved(const Symbol &original) {
21962177
const Symbol &symbol{GetAssociationRoot(original)};
21972178
const Scope &scope{symbol.owner()};
@@ -2214,7 +2195,7 @@ bool IsSaved(const Symbol &original) {
22142195
} else if (scopeKind == Scope::Kind::Module ||
22152196
(scopeKind == Scope::Kind::MainProgram &&
22162197
(symbol.attrs().test(Attr::TARGET) || evaluate::IsCoarray(symbol)) &&
2217-
CanCUDASymbolHaveSaveAttr(symbol))) {
2198+
Fortran::evaluate::CanCUDASymbolHaveSaveAttr(symbol))) {
22182199
// 8.5.16p4
22192200
// In main programs, implied SAVE matters only for pointer
22202201
// initialization targets and coarrays.
@@ -2224,7 +2205,7 @@ bool IsSaved(const Symbol &original) {
22242205
(features.IsEnabled(
22252206
common::LanguageFeature::SaveBigMainProgramVariables) &&
22262207
symbol.size() > 32)) &&
2227-
CanCUDASymbolHaveSaveAttr(symbol)) {
2208+
Fortran::evaluate::CanCUDASymbolHaveSaveAttr(symbol)) {
22282209
// With SaveBigMainProgramVariables, keeping all unsaved main program
22292210
// variables of 32 bytes or less on the stack allows keeping numerical and
22302211
// logical scalars, small scalar characters or derived, small arrays, and
@@ -2242,15 +2223,15 @@ bool IsSaved(const Symbol &original) {
22422223
} else if (symbol.test(Symbol::Flag::InDataStmt)) {
22432224
return true;
22442225
} else if (const auto *object{symbol.detailsIf<ObjectEntityDetails>()};
2245-
object && object->init()) {
2226+
object && object->init()) {
22462227
return true;
22472228
} else if (IsProcedurePointer(symbol) && symbol.has<ProcEntityDetails>() &&
22482229
symbol.get<ProcEntityDetails>().init()) {
22492230
return true;
22502231
} else if (scope.hasSAVE()) {
22512232
return true; // bare SAVE statement
2252-
} else if (const Symbol *block{FindCommonBlockContaining(symbol)};
2253-
block && block->attrs().test(Attr::SAVE)) {
2233+
} else if (const Symbol * block{FindCommonBlockContaining(symbol)};
2234+
block && block->attrs().test(Attr::SAVE)) {
22542235
return true; // in COMMON with SAVE
22552236
} else {
22562237
return false;

flang/lib/Semantics/tools.cpp

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,19 +1081,6 @@ const Scope *FindCUDADeviceContext(const Scope *scope) {
10811081
});
10821082
}
10831083

1084-
bool IsDeviceAllocatable(const Symbol &symbol) {
1085-
if (IsAllocatable(symbol)) {
1086-
if (const auto *details{
1087-
symbol.GetUltimate().detailsIf<semantics::ObjectEntityDetails>()}) {
1088-
if (details->cudaDataAttr() &&
1089-
*details->cudaDataAttr() != common::CUDADataAttr::Pinned) {
1090-
return true;
1091-
}
1092-
}
1093-
}
1094-
return false;
1095-
}
1096-
10971084
std::optional<common::CUDADataAttr> GetCUDADataAttr(const Symbol *symbol) {
10981085
const auto *object{
10991086
symbol ? symbol->detailsIf<ObjectEntityDetails>() : nullptr};
@@ -1439,12 +1426,6 @@ FindPolymorphicAllocatablePotentialComponent(const DerivedTypeSpec &derived) {
14391426
potentials.begin(), potentials.end(), IsPolymorphicAllocatable);
14401427
}
14411428

1442-
UltimateComponentIterator::const_iterator
1443-
FindCUDADeviceAllocatableUltimateComponent(const DerivedTypeSpec &derived) {
1444-
UltimateComponentIterator ultimates{derived};
1445-
return std::find_if(ultimates.begin(), ultimates.end(), IsDeviceAllocatable);
1446-
}
1447-
14481429
const Symbol *FindUltimateComponent(const DerivedTypeSpec &derived,
14491430
const std::function<bool(const Symbol &)> &predicate) {
14501431
UltimateComponentIterator ultimates{derived};
@@ -1807,4 +1788,4 @@ bool HadUseError(
18071788
}
18081789
}
18091790

1810-
} // namespace Fortran::semantics
1791+
} // namespace Fortran::semantics

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

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)