Skip to content

Commit eb27031

Browse files
Continue filling out DetermineCopyInOutArgument(). Implemented IsExplicitShape(const Shape&)
1 parent 58764a6 commit eb27031

File tree

3 files changed

+43
-5
lines changed

3 files changed

+43
-5
lines changed

flang/include/flang/Evaluate/shape.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ using Shape = std::vector<MaybeExtentExpr>;
3535

3636
bool IsImpliedShape(const Symbol &);
3737
bool IsExplicitShape(const Symbol &);
38+
bool IsExplicitShape(const Shape &);
3839

3940
// Conversions between various representations of shapes.
4041
std::optional<ExtentExpr> AsExtentArrayExpr(const Shape &);

flang/lib/Evaluate/call.cpp

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -281,17 +281,43 @@ static void DetermineCopyInOutArgument(
281281
if (actual.isAlternateReturn()) {
282282
return;
283283
}
284-
const auto *dummyObj =
285-
std::get_if<characteristics::DummyDataObject>(&dummy.u);
284+
const auto *dummyObj{
285+
std::get_if<characteristics::DummyDataObject>(&dummy.u)};
286286
if (!dummyObj) {
287287
// Only DummyDataObject has the information we need
288288
return;
289289
}
290+
291+
bool dummyIsValue{
292+
dummyObj->attrs.test(characteristics::DummyDataObject::Attr::Value)};
293+
if (dummyIsValue) {
294+
actual.SetMayNeedCopyIn();
295+
return;
296+
}
297+
290298
// Check actual contiguity, unless dummy doesn't care
291-
bool actualContiguous =
299+
bool actualTreatAsContiguous{
292300
dummyObj->ignoreTKR.test(common::IgnoreTKR::Contiguous) ||
293-
IsSimplyContiguous(actual, sc.foldingContext());
294-
bool actualVectorSubscript = HasVectorSubscript(actual);
301+
IsSimplyContiguous(actual, sc.foldingContext())};
302+
303+
bool actualHasVectorSubscript{HasVectorSubscript(actual)};
304+
bool actualIsArray{actual.Rank() > 0};
305+
306+
bool dummyIsArray{dummyObj->type.Rank() > 0};
307+
bool dummyIsExplicitShape{
308+
dummyIsArray ? IsExplicitShape(*dummyObj->type.shape()) : false};
309+
bool dummyIsAssumedSize{dummyObj->type.attrs().test(
310+
characteristics::TypeAndShape::Attr::AssumedSize)};
311+
bool dummyNeedsContiguity{dummyIsArray &&
312+
(dummyIsExplicitShape || dummyIsAssumedSize ||
313+
dummyObj->attrs.test(characteristics::DummyDataObject::Attr::Contiguous))};
314+
if (!actualTreatAsContiguous && dummyNeedsContiguity) {
315+
actual.SetMayNeedCopyIn();
316+
if (!actualHasVectorSubscript) {
317+
actual.SetMayNeedCopyOut();
318+
}
319+
}
320+
295321

296322
// TODO
297323
}

flang/lib/Evaluate/shape.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@ bool IsExplicitShape(const Symbol &original) {
4747
}
4848
}
4949

50+
bool IsExplicitShape(const Shape &shape) {
51+
// If extent expression is present for all dimensions, then assume
52+
// explicit shape.
53+
for (const auto &dim : shape) {
54+
if (!dim) {
55+
return false;
56+
}
57+
}
58+
return true;
59+
}
60+
5061
Shape GetShapeHelper::ConstantShape(const Constant<ExtentType> &arrayConstant) {
5162
CHECK(arrayConstant.Rank() == 1);
5263
Shape result;

0 commit comments

Comments
 (0)