Skip to content

Commit ca781ae

Browse files
authored
Merge pull request #1096 from flang-compiler/jpr-cherry-pick-09-27-21
Cherry pick all flang commits from LLVM since last cherry-picking
2 parents 2761c7a + 4eda99c commit ca781ae

File tree

595 files changed

+2682
-1692
lines changed

Some content is hidden

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

595 files changed

+2682
-1692
lines changed

flang/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,14 @@ if (FLANG_REPOSITORY_STRING)
302302
add_definitions(-DFLANG_REPOSITORY_STRING="${FLANG_REPOSITORY_STRING}")
303303
endif()
304304

305+
include(TestBigEndian)
306+
test_big_endian(IS_BIGENDIAN)
307+
if (IS_BIGENDIAN)
308+
add_compile_definitions(FLANG_BIG_ENDIAN=1)
309+
else ()
310+
add_compile_definitions(FLANG_LITTLE_ENDIAN=1)
311+
endif ()
312+
305313
# Configure Flang's Version.inc file.
306314
configure_file(
307315
${CMAKE_CURRENT_SOURCE_DIR}/include/flang/Version.inc.in

flang/docs/Intrinsics.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ This phase currently supports all the intrinsic procedures listed above but the
746746

747747
| Intrinsic Category | Intrinsic Procedures Lacking Support |
748748
| --- | --- |
749-
| Coarray intrinsic functions | LCOBOUND, UCOBOUND, FAILED_IMAGES, GET_TEAM, IMAGE_INDEX, STOPPED_IMAGES, TEAM_NUMBER, THIS_IMAGE, COSHAPE |
749+
| Coarray intrinsic functions | LCOBOUND, UCOBOUND, FAILED_IMAGES, GET_TEAM, IMAGE_INDEX, STOPPED_IMAGES, TEAM_NUMBER, COSHAPE |
750750
| Object characteristic inquiry functions | ALLOCATED, ASSOCIATED, EXTENDS_TYPE_OF, IS_CONTIGUOUS, PRESENT, RANK, SAME_TYPE, STORAGE_SIZE |
751751
| Type inquiry intrinsic functions | BIT_SIZE, DIGITS, EPSILON, HUGE, KIND, MAXEXPONENT, MINEXPONENT, NEW_LINE, PRECISION, RADIX, RANGE, TINY|
752752
| Non-standard intrinsic functions | AND, OR, XOR, LSHIFT, RSHIFT, SHIFT, ZEXT, IZEXT, COSD, SIND, TAND, ACOSD, ASIND, ATAND, ATAN2D, COMPL, DCMPLX, EQV, NEQV, INT8, JINT, JNINT, KNINT, LOC, QCMPLX, DREAL, DFLOAT, QEXT, QFLOAT, QREAL, DNUM, NUM, JNUM, KNUM, QNUM, RNUM, RAN, RANF, ILEN, SIZEOF, MCLOCK, SECNDS, COTAN, IBCHNG, ISHA, ISHC, ISHL, IXOR, IARG, IARGC, NARGS, NUMARG, BADDRESS, IADDR, CACHESIZE, EOF, FP_CLASS, INT_PTR_KIND, ISNAN, MALLOC |

flang/include/flang/Evaluate/common.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ struct Rounding {
133133

134134
static constexpr Rounding defaultRounding;
135135

136-
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
136+
#if FLANG_BIG_ENDIAN
137137
constexpr bool isHostLittleEndian{false};
138-
#elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
138+
#elif FLANG_LITTLE_ENDIAN
139139
constexpr bool isHostLittleEndian{true};
140140
#else
141141
#error host endianness is not known

flang/include/flang/Evaluate/expression.h

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,10 @@ class Operation {
118118
public:
119119
using Derived = DERIVED;
120120
using Result = RESULT;
121-
static_assert(IsSpecificIntrinsicType<Result>);
122121
static constexpr std::size_t operands{sizeof...(OPERANDS)};
122+
// Allow specific intrinsic types and Parentheses<SomeDerived>
123+
static_assert(IsSpecificIntrinsicType<Result> ||
124+
(operands == 1 && std::is_same_v<Result, SomeDerived>));
123125
template <int J> using Operand = std::tuple_element_t<J, OperandTypes>;
124126

125127
// Unary operations wrap a single Expr with a CopyableIndirection.
@@ -174,7 +176,9 @@ class Operation {
174176
}
175177
}
176178

177-
static constexpr std::optional<DynamicType> GetType() {
179+
static constexpr std::conditional_t<Result::category != TypeCategory::Derived,
180+
std::optional<DynamicType>, void>
181+
GetType() {
178182
return Result::GetType();
179183
}
180184
int Rank() const {
@@ -224,6 +228,17 @@ struct Parentheses : public Operation<Parentheses<A>, A, A> {
224228
using Base::Base;
225229
};
226230

231+
template <>
232+
struct Parentheses<SomeDerived>
233+
: public Operation<Parentheses<SomeDerived>, SomeDerived, SomeDerived> {
234+
public:
235+
using Result = SomeDerived;
236+
using Operand = SomeDerived;
237+
using Base = Operation<Parentheses, SomeDerived, SomeDerived>;
238+
using Base::Base;
239+
DynamicType GetType() const;
240+
};
241+
227242
template <typename A> struct Negate : public Operation<Negate<A>, A, A> {
228243
using Result = A;
229244
using Operand = A;
@@ -732,7 +747,7 @@ template <> class Expr<SomeDerived> : public ExpressionBase<SomeDerived> {
732747
using Result = SomeDerived;
733748
EVALUATE_UNION_CLASS_BOILERPLATE(Expr)
734749
std::variant<Constant<Result>, ArrayConstructor<Result>, StructureConstructor,
735-
Designator<Result>, FunctionRef<Result>>
750+
Designator<Result>, FunctionRef<Result>, Parentheses<Result>>
736751
u;
737752
};
738753

@@ -849,6 +864,8 @@ struct GenericExprWrapper {
849864
struct GenericAssignmentWrapper {
850865
GenericAssignmentWrapper() {}
851866
explicit GenericAssignmentWrapper(Assignment &&x) : v{std::move(x)} {}
867+
explicit GenericAssignmentWrapper(std::optional<Assignment> &&x)
868+
: v{std::move(x)} {}
852869
~GenericAssignmentWrapper();
853870
static void Deleter(GenericAssignmentWrapper *);
854871
std::optional<Assignment> v; // vacant if error

flang/include/flang/Evaluate/real.h

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -219,21 +219,26 @@ class Real : public common::RealDetails<PREC> {
219219
return result;
220220
}
221221
ValueWithRealFlags<Real> intPart{ToWholeNumber(mode)};
222-
int exponent{intPart.value.Exponent()};
223-
result.flags.set(
224-
RealFlag::Overflow, exponent >= exponentBias + result.value.bits);
225222
result.flags |= intPart.flags;
226-
int shift{
227-
exponent - exponentBias - binaryPrecision + 1}; // positive -> left
228-
result.value =
229-
result.value.ConvertUnsigned(intPart.value.GetFraction().SHIFTR(-shift))
230-
.value.SHIFTL(shift);
223+
int exponent{intPart.value.Exponent()};
224+
// shift positive -> left shift, negative -> right shift
225+
int shift{exponent - exponentBias - binaryPrecision + 1};
226+
// Apply any right shift before moving to the result type
227+
auto rshifted{intPart.value.GetFraction().SHIFTR(-shift)};
228+
auto converted{result.value.ConvertUnsigned(rshifted)};
229+
if (converted.overflow) {
230+
result.flags.set(RealFlag::Overflow);
231+
}
232+
result.value = converted.value.SHIFTL(shift);
233+
if (converted.value.CompareUnsigned(result.value.SHIFTR(shift)) !=
234+
Ordering::Equal) {
235+
result.flags.set(RealFlag::Overflow);
236+
}
231237
if (IsSignBitSet()) {
232-
auto negated{result.value.Negate()};
233-
result.value = negated.value;
234-
if (negated.overflow) {
235-
result.flags.set(RealFlag::Overflow);
236-
}
238+
result.value = result.value.Negate().value;
239+
}
240+
if (IsSignBitSet() != result.value.IsNegative()) {
241+
result.flags.set(RealFlag::Overflow);
237242
}
238243
if (result.flags.test(RealFlag::Overflow)) {
239244
result.value =

flang/include/flang/Evaluate/tools.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,22 @@ template <typename A> bool IsAssumedRank(const std::optional<A> &x) {
8989
return x && IsAssumedRank(*x);
9090
}
9191

92+
// Predicate: true when an expression is a coarray (corank > 0)
93+
bool IsCoarray(const ActualArgument &);
94+
template <typename A> bool IsCoarray(const A &) { return false; }
95+
template <typename A> bool IsCoarray(const Designator<A> &designator) {
96+
if (const auto *symbol{std::get_if<SymbolRef>(&designator.u)}) {
97+
return symbol->get().Corank() > 0;
98+
}
99+
return false;
100+
}
101+
template <typename T> bool IsCoarray(const Expr<T> &expr) {
102+
return std::visit([](const auto &x) { return IsCoarray(x); }, expr.u);
103+
}
104+
template <typename A> bool IsCoarray(const std::optional<A> &x) {
105+
return x && IsCoarray(*x);
106+
}
107+
92108
// Generalizing packagers: these take operations and expressions of more
93109
// specific types and wrap them in Expr<> containers of more abstract types.
94110

@@ -282,6 +298,9 @@ std::optional<DataRef> ExtractDataRef(const A *p, bool intoSubstring = false) {
282298
return std::nullopt;
283299
}
284300
}
301+
std::optional<DataRef> ExtractDataRef(
302+
const ActualArgument &, bool intoSubstring = false);
303+
285304
std::optional<DataRef> ExtractSubstringBase(const Substring &);
286305

287306
// Predicate: is an expression is an array element reference?

flang/include/flang/Runtime/io-api.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,10 @@ bool IONAME(SetFile)(Cookie, const char *, std::size_t chars);
283283
bool IONAME(GetNewUnit)(Cookie, int &, int kind = 4);
284284

285285
// READ(SIZE=), after all input items
286-
bool IONAME(GetSize)(Cookie, std::int64_t, int kind = 8);
286+
std::size_t IONAME(GetSize)(Cookie);
287287

288288
// INQUIRE(IOLENGTH=), after all output items
289-
bool IONAME(GetIoLength)(Cookie, std::int64_t, int kind = 8);
289+
std::size_t IONAME(GetIoLength)(Cookie);
290290

291291
// GetIoMsg() does not modify its argument unless an error or
292292
// end-of-record/file condition is present.

flang/include/flang/Semantics/symbol.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ class Symbol {
511511
// OpenMP data-copying attribute
512512
OmpCopyIn, OmpCopyPrivate,
513513
// OpenMP miscellaneous flags
514-
OmpCommonBlock, OmpReduction, OmpAligned, OmpAllocate,
514+
OmpCommonBlock, OmpReduction, OmpAligned, OmpNontemporal, OmpAllocate,
515515
OmpDeclarativeAllocateDirective, OmpExecutableAllocateDirective,
516516
OmpDeclareSimd, OmpDeclareTarget, OmpThreadprivate, OmpDeclareReduction,
517517
OmpFlushed, OmpCriticalLock, OmpIfSpecified, OmpNone, OmpPreDetermined);

flang/include/flang/Semantics/tools.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,6 @@ inline bool IsAssumedSizeArray(const Symbol &symbol) {
179179
const auto *details{symbol.detailsIf<ObjectEntityDetails>()};
180180
return details && details->IsAssumedSize();
181181
}
182-
inline bool IsAssumedRankArray(const Symbol &symbol) {
183-
const auto *details{symbol.detailsIf<ObjectEntityDetails>()};
184-
return details && details->IsAssumedRank();
185-
}
186182
bool IsAssumedLengthCharacter(const Symbol &);
187183
bool IsExternal(const Symbol &);
188184
bool IsModuleProcedure(const Symbol &);

flang/lib/Evaluate/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ add_flang_library(FortranEvaluate
3434
fold-integer.cpp
3535
fold-logical.cpp
3636
fold-real.cpp
37+
fold-reduction.cpp
3738
formatting.cpp
3839
host.cpp
3940
initial-image.cpp

0 commit comments

Comments
 (0)