Skip to content

Commit 7199f6e

Browse files
SC llvm teamSC llvm team
authored andcommitted
Merged main:211c9752c820 into amd-gfx:1dd68fefc1fa
Local branch amd-gfx 1dd68fe Merged main:d325c5d00b14 into amd-gfx:ff50e60be1c7 Remote branch main 211c975 [mlir][NVVM] Adds the NVVM target attribute.
2 parents 1dd68fe + 211c975 commit 7199f6e

File tree

109 files changed

+37704
-14454
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+37704
-14454
lines changed

flang/include/flang/Evaluate/initial-image.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,7 @@ namespace Fortran::evaluate {
2222

2323
class InitialImage {
2424
public:
25-
enum Result {
26-
Ok,
27-
NotAConstant,
28-
OutOfRange,
29-
SizeMismatch,
30-
};
25+
enum Result { Ok, NotAConstant, OutOfRange, SizeMismatch };
3126

3227
explicit InitialImage(std::size_t bytes) : data_(bytes) {}
3328
InitialImage(InitialImage &&that) = default;

flang/lib/Evaluate/fold-character.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ Expr<Type<TypeCategory::Character, KIND>> FoldIntrinsicFunction(
8080
return FoldMaxvalMinval<T>(
8181
context, std::move(funcRef), RelationalOperator::GT, *identity);
8282
}
83-
} else if (name == "merge") {
84-
return FoldMerge<T>(context, std::move(funcRef));
8583
} else if (name == "min") {
8684
return FoldMINorMAX(context, std::move(funcRef), Ordering::Less);
8785
} else if (name == "minval") {

flang/lib/Evaluate/fold-complex.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ Expr<Type<TypeCategory::Complex, KIND>> FoldIntrinsicFunction(
6464
}
6565
} else if (name == "dot_product") {
6666
return FoldDotProduct<T>(context, std::move(funcRef));
67-
} else if (name == "merge") {
68-
return FoldMerge<T>(context, std::move(funcRef));
6967
} else if (name == "product") {
7068
auto one{Scalar<Part>::FromInteger(value::Integer<8>{1}).value};
7169
return FoldProduct<T>(context, std::move(funcRef), Scalar<T>{one});

flang/lib/Evaluate/fold-implementation.h

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ template <typename T> class Folder {
6464

6565
Expr<T> CSHIFT(FunctionRef<T> &&);
6666
Expr<T> EOSHIFT(FunctionRef<T> &&);
67+
Expr<T> MERGE(FunctionRef<T> &&);
6768
Expr<T> PACK(FunctionRef<T> &&);
6869
Expr<T> RESHAPE(FunctionRef<T> &&);
6970
Expr<T> SPREAD(FunctionRef<T> &&);
@@ -397,9 +398,11 @@ template <typename T> Expr<T> Folder<T>::Folding(Designator<T> &&designator) {
397398
template <typename T>
398399
Constant<T> *Folder<T>::Folding(std::optional<ActualArgument> &arg) {
399400
if (auto *expr{UnwrapExpr<Expr<SomeType>>(arg)}) {
400-
if (!UnwrapExpr<Expr<T>>(*expr)) {
401-
if (auto converted{ConvertToType(T::GetType(), std::move(*expr))}) {
402-
*expr = Fold(context_, std::move(*converted));
401+
if constexpr (T::category != TypeCategory::Derived) {
402+
if (!UnwrapExpr<Expr<T>>(*expr)) {
403+
if (auto converted{ConvertToType(T::GetType(), std::move(*expr))}) {
404+
*expr = Fold(context_, std::move(*converted));
405+
}
403406
}
404407
}
405408
return UnwrapConstantValue<T>(*expr);
@@ -411,8 +414,6 @@ template <typename... A, std::size_t... I>
411414
std::optional<std::tuple<const Constant<A> *...>> GetConstantArgumentsHelper(
412415
FoldingContext &context, ActualArguments &arguments,
413416
std::index_sequence<I...>) {
414-
static_assert(
415-
(... && IsSpecificIntrinsicType<A>)); // TODO derived types for MERGE?
416417
static_assert(sizeof...(A) > 0);
417418
std::tuple<const Constant<A> *...> args{
418419
Folder<A>{context}.Folding(arguments.at(I))...};
@@ -489,7 +490,6 @@ Expr<TR> FoldElementalIntrinsicHelper(FoldingContext &context,
489490
}
490491
}
491492
CHECK(rank == GetRank(shape));
492-
493493
// Compute all the scalar values of the results
494494
std::vector<Scalar<TR>> results;
495495
if (TotalElementCount(shape) > 0) {
@@ -513,6 +513,13 @@ Expr<TR> FoldElementalIntrinsicHelper(FoldingContext &context,
513513
auto len{static_cast<ConstantSubscript>(
514514
results.empty() ? 0 : results[0].length())};
515515
return Expr<TR>{Constant<TR>{len, std::move(results), std::move(shape)}};
516+
} else if constexpr (TR::category == TypeCategory::Derived) {
517+
if (!results.empty()) {
518+
return Expr<TR>{rank == 0
519+
? Constant<TR>{results.front()}
520+
: Constant<TR>{results.front().derivedTypeSpec(),
521+
std::move(results), std::move(shape)}};
522+
}
516523
} else {
517524
return Expr<TR>{Constant<TR>{std::move(results), std::move(shape)}};
518525
}
@@ -780,6 +787,16 @@ template <typename T> Expr<T> Folder<T>::EOSHIFT(FunctionRef<T> &&funcRef) {
780787
return MakeInvalidIntrinsic(std::move(funcRef));
781788
}
782789

790+
template <typename T> Expr<T> Folder<T>::MERGE(FunctionRef<T> &&funcRef) {
791+
return FoldElementalIntrinsic<T, T, T, LogicalResult>(context_,
792+
std::move(funcRef),
793+
ScalarFunc<T, T, T, LogicalResult>(
794+
[](const Scalar<T> &ifTrue, const Scalar<T> &ifFalse,
795+
const Scalar<LogicalResult> &predicate) -> Scalar<T> {
796+
return predicate.IsTrue() ? ifTrue : ifFalse;
797+
}));
798+
}
799+
783800
template <typename T> Expr<T> Folder<T>::PACK(FunctionRef<T> &&funcRef) {
784801
auto args{funcRef.arguments()};
785802
CHECK(args.size() == 3);
@@ -1126,6 +1143,8 @@ Expr<T> FoldOperation(FoldingContext &context, FunctionRef<T> &&funcRef) {
11261143
return Folder<T>{context}.CSHIFT(std::move(funcRef));
11271144
} else if (name == "eoshift") {
11281145
return Folder<T>{context}.EOSHIFT(std::move(funcRef));
1146+
} else if (name == "merge") {
1147+
return Folder<T>{context}.MERGE(std::move(funcRef));
11291148
} else if (name == "pack") {
11301149
return Folder<T>{context}.PACK(std::move(funcRef));
11311150
} else if (name == "reshape") {
@@ -1147,17 +1166,6 @@ Expr<T> FoldOperation(FoldingContext &context, FunctionRef<T> &&funcRef) {
11471166
return Expr<T>{std::move(funcRef)};
11481167
}
11491168

1150-
template <typename T>
1151-
Expr<T> FoldMerge(FoldingContext &context, FunctionRef<T> &&funcRef) {
1152-
return FoldElementalIntrinsic<T, T, T, LogicalResult>(context,
1153-
std::move(funcRef),
1154-
ScalarFunc<T, T, T, LogicalResult>(
1155-
[](const Scalar<T> &ifTrue, const Scalar<T> &ifFalse,
1156-
const Scalar<LogicalResult> &predicate) -> Scalar<T> {
1157-
return predicate.IsTrue() ? ifTrue : ifFalse;
1158-
}));
1159-
}
1160-
11611169
Expr<ImpliedDoIndex::Result> FoldOperation(FoldingContext &, ImpliedDoIndex &&);
11621170

11631171
// Array constructor folding
@@ -1349,6 +1357,7 @@ std::optional<Expr<T>> FromArrayConstructor(
13491357
template <typename RESULT, typename OPERAND>
13501358
std::optional<Expr<RESULT>> MapOperation(FoldingContext &context,
13511359
std::function<Expr<RESULT>(Expr<OPERAND> &&)> &&f, const Shape &shape,
1360+
[[maybe_unused]] std::optional<Expr<SubscriptInteger>> &&length,
13521361
Expr<OPERAND> &&values) {
13531362
ArrayConstructor<RESULT> result{values};
13541363
if constexpr (common::HasMember<OPERAND, AllIntrinsicCategoryTypes>) {
@@ -1369,6 +1378,11 @@ std::optional<Expr<RESULT>> MapOperation(FoldingContext &context,
13691378
result.Push(Fold(context, f(std::move(scalar))));
13701379
}
13711380
}
1381+
if constexpr (RESULT::category == TypeCategory::Character) {
1382+
if (length) {
1383+
result.set_LEN(std::move(*length));
1384+
}
1385+
}
13721386
return FromArrayConstructor(context, std::move(result), shape);
13731387
}
13741388

@@ -1506,9 +1520,9 @@ auto MapOperation(FoldingContext &context,
15061520
return FromArrayConstructor(context, std::move(result), shape);
15071521
}
15081522

1509-
template <typename DERIVED, typename RESULT, typename LEFT, typename RIGHT>
1523+
template <typename DERIVED, typename RESULT, typename... OPD>
15101524
std::optional<Expr<SubscriptInteger>> ComputeResultLength(
1511-
Operation<DERIVED, RESULT, LEFT, RIGHT> &operation) {
1525+
Operation<DERIVED, RESULT, OPD...> &operation) {
15121526
if constexpr (RESULT::category == TypeCategory::Character) {
15131527
return Expr<RESULT>{operation.derived()}.LEN();
15141528
}
@@ -1529,7 +1543,8 @@ auto ApplyElementwise(FoldingContext &context,
15291543
if (expr.Rank() > 0) {
15301544
if (std::optional<Shape> shape{GetShape(context, expr)}) {
15311545
if (auto values{AsFlatArrayConstructor(expr)}) {
1532-
return MapOperation(context, std::move(f), *shape, std::move(*values));
1546+
return MapOperation(context, std::move(f), *shape,
1547+
ComputeResultLength(operation), std::move(*values));
15331548
}
15341549
}
15351550
}

flang/lib/Evaluate/fold-integer.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,8 +1038,6 @@ Expr<Type<TypeCategory::Integer, KIND>> FoldIntrinsicFunction(
10381038
} else if (name == "maxval") {
10391039
return FoldMaxvalMinval<T>(context, std::move(funcRef),
10401040
RelationalOperator::GT, T::Scalar::Least());
1041-
} else if (name == "merge") {
1042-
return FoldMerge<T>(context, std::move(funcRef));
10431041
} else if (name == "merge_bits") {
10441042
return FoldElementalIntrinsic<T, T, T, T>(
10451043
context, std::move(funcRef), &Scalar<T>::MERGE_BITS);

flang/lib/Evaluate/fold-logical.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,6 @@ Expr<Type<TypeCategory::Logical, KIND>> FoldIntrinsicFunction(
215215
if (auto *expr{UnwrapExpr<Expr<SomeLogical>>(args[0])}) {
216216
return Fold(context, ConvertToType<T>(std::move(*expr)));
217217
}
218-
} else if (name == "merge") {
219-
return FoldMerge<T>(context, std::move(funcRef));
220218
} else if (name == "parity") {
221219
return FoldAllAnyParity(
222220
context, std::move(funcRef), &Scalar<T>::NEQV, Scalar<T>{false});

flang/lib/Evaluate/fold-real.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,6 @@ Expr<Type<TypeCategory::Real, KIND>> FoldIntrinsicFunction(
184184
} else if (name == "maxval") {
185185
return FoldMaxvalMinval<T>(context, std::move(funcRef),
186186
RelationalOperator::GT, T::Scalar::HUGE().Negate());
187-
} else if (name == "merge") {
188-
return FoldMerge<T>(context, std::move(funcRef));
189187
} else if (name == "min") {
190188
return FoldMINorMAX(context, std::move(funcRef), Ordering::Less);
191189
} else if (name == "minval") {

flang/lib/Evaluate/fold.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,11 +275,15 @@ std::optional<Expr<SomeType>> FoldTransfer(
275275
if (totalBytes < std::size_t{1000000} &&
276276
(elements == 0 || totalBytes / elements == *sourceBytes)) {
277277
InitialImage image{*sourceBytes};
278-
InitialImage::Result imageResult{
279-
image.Add(0, *sourceBytes, *source, context)};
280-
CHECK(imageResult == InitialImage::Ok);
281-
return image.AsConstant(
282-
context, *moldType, moldLength, *extents, true /*pad with 0*/);
278+
auto status{image.Add(0, *sourceBytes, *source, context)};
279+
if (status == InitialImage::Ok) {
280+
return image.AsConstant(
281+
context, *moldType, moldLength, *extents, true /*pad with 0*/);
282+
} else {
283+
// Can fail due to an allocatable or automatic component;
284+
// a warning will also have been produced.
285+
CHECK(status == InitialImage::NotAConstant);
286+
}
283287
}
284288
}
285289
return std::nullopt;

flang/lib/Evaluate/initial-image.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,10 @@ auto InitialImage::Add(ConstantSubscript offset, std::size_t bytes,
3535
AddPointer(offset + component.offset(), indExpr.value());
3636
} else if (IsAllocatable(component) || IsAutomatic(component)) {
3737
return NotAConstant;
38-
} else {
39-
Result added{Add(offset + component.offset(), component.size(),
40-
indExpr.value(), context)};
41-
if (added != Ok) {
42-
return added;
43-
}
38+
} else if (auto result{Add(offset + component.offset(),
39+
component.size(), indExpr.value(), context)};
40+
result != Ok) {
41+
return result;
4442
}
4543
}
4644
offset += elementBytes;

flang/lib/Evaluate/type.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,23 @@ static bool IsDescriptor(const DeclTypeSpec *type) {
3434
}
3535

3636
static bool IsDescriptor(const ObjectEntityDetails &details) {
37-
if (IsDescriptor(details.type())) {
37+
if (IsDescriptor(details.type()) || details.IsAssumedRank()) {
3838
return true;
3939
}
40+
std::size_t j{0};
4041
for (const ShapeSpec &shapeSpec : details.shape()) {
41-
const auto &lb{shapeSpec.lbound().GetExplicit()};
42-
const auto &ub{shapeSpec.ubound().GetExplicit()};
43-
if (!lb || !ub || !IsConstantExpr(*lb) || !IsConstantExpr(*ub)) {
42+
++j;
43+
if (const auto &lb{shapeSpec.lbound().GetExplicit()};
44+
!lb || !IsConstantExpr(*lb)) {
45+
return true;
46+
}
47+
if (const auto &ub{shapeSpec.ubound().GetExplicit()}) {
48+
if (!IsConstantExpr(*ub)) {
49+
return true;
50+
}
51+
} else if (j == details.shape().size() && details.isDummy()) {
52+
// assumed size array
53+
} else {
4454
return true;
4555
}
4656
}

0 commit comments

Comments
 (0)