From 70ef83a93bfdff7fd4eb5091ecb8b5ca8307b62b Mon Sep 17 00:00:00 2001 From: Michael Kruse Date: Fri, 27 Sep 2024 12:40:40 +0200 Subject: [PATCH 01/13] [Flang] Split common headers --- flang/include/flang/Common/Fortran-consts.h | 44 ++++++++++++++++++++ flang/include/flang/Common/Fortran.h | 26 +----------- flang/include/flang/Common/format.h | 2 +- flang/include/flang/Common/target-rounding.h | 37 ++++++++++++++++ flang/include/flang/Evaluate/common.h | 8 ++-- flang/include/flang/Evaluate/target.h | 15 +------ flang/include/flang/Runtime/cpp-type.h | 2 +- flang/include/flang/Runtime/type-code.h | 2 +- flang/runtime/format.h | 2 +- flang/runtime/non-tbp-dio.h | 3 +- flang/runtime/type-info.h | 4 +- flang/unittests/Evaluate/fp-testing.cpp | 2 +- flang/unittests/Evaluate/fp-testing.h | 6 +-- flang/unittests/Runtime/Complex.cpp | 2 +- 14 files changed, 100 insertions(+), 55 deletions(-) create mode 100644 flang/include/flang/Common/Fortran-consts.h create mode 100644 flang/include/flang/Common/target-rounding.h diff --git a/flang/include/flang/Common/Fortran-consts.h b/flang/include/flang/Common/Fortran-consts.h new file mode 100644 index 0000000000000..3d4377dd5a076 --- /dev/null +++ b/flang/include/flang/Common/Fortran-consts.h @@ -0,0 +1,44 @@ +//===-- include/flang/Common/Fortran-consts.h -------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef FORTRAN_COMMON_FORTRAN_CONSTS_H_ +#define FORTRAN_COMMON_FORTRAN_CONSTS_H_ + +#include "flang/Common/enum-class.h" +#include + +namespace Fortran::common { + +// Fortran has five kinds of intrinsic data types, plus the derived types. +ENUM_CLASS(TypeCategory, Integer, Real, Complex, Character, Logical, Derived) +ENUM_CLASS(VectorElementCategory, Integer, Unsigned, Real) + +ENUM_CLASS(IoStmtKind, None, Backspace, Close, Endfile, Flush, Inquire, Open, + Print, Read, Rewind, Wait, Write) + +// Defined I/O variants +ENUM_CLASS( + DefinedIo, ReadFormatted, ReadUnformatted, WriteFormatted, WriteUnformatted) + +// Fortran arrays may have up to 15 dimensions (See Fortran 2018 section 5.4.6). +static constexpr int maxRank{15}; + +// Floating-point rounding modes; these are packed into a byte to save +// room in the runtime's format processing context structure. These +// enumerators are defined with the corresponding values returned from +// llvm.get.rounding. +enum class RoundingMode : std::uint8_t { + ToZero, // ROUND=ZERO, RZ - truncation + TiesToEven, // ROUND=NEAREST, RN - default IEEE rounding + Up, // ROUND=UP, RU + Down, // ROUND=DOWN, RD + TiesAwayFromZero, // ROUND=COMPATIBLE, RC - ties round away from zero +}; + +} // namespace Fortran::common +#endif // FORTRAN_COMMON_FORTRAN_CONSTS_H_ diff --git a/flang/include/flang/Common/Fortran.h b/flang/include/flang/Common/Fortran.h index 5b2ed43a8f99c..7c8d788dd563d 100644 --- a/flang/include/flang/Common/Fortran.h +++ b/flang/include/flang/Common/Fortran.h @@ -12,6 +12,7 @@ // Fortran language concepts that are used in many phases are defined // once here to avoid redundancy and needless translation. +#include "flang/Common/Fortran-consts.h" #include "enum-set.h" #include "idioms.h" #include @@ -21,10 +22,6 @@ namespace Fortran::common { class LanguageFeatureControl; -// Fortran has five kinds of intrinsic data types, plus the derived types. -ENUM_CLASS(TypeCategory, Integer, Real, Complex, Character, Logical, Derived) -ENUM_CLASS(VectorElementCategory, Integer, Unsigned, Real) - constexpr bool IsNumericTypeCategory(TypeCategory category) { return category == TypeCategory::Integer || category == TypeCategory::Real || category == TypeCategory::Complex; @@ -47,9 +44,6 @@ const char *AsFortran(RelationalOperator); ENUM_CLASS(Intent, Default, In, Out, InOut) -ENUM_CLASS(IoStmtKind, None, Backspace, Close, Endfile, Flush, Inquire, Open, - Print, Read, Rewind, Wait, Write) - // Union of specifiers for all I/O statements. ENUM_CLASS(IoSpecKind, Access, Action, Advance, Asynchronous, Blank, Decimal, Delim, Direct, Encoding, End, Eor, Err, Exist, File, Fmt, Form, Formatted, @@ -61,29 +55,11 @@ ENUM_CLASS(IoSpecKind, Access, Action, Advance, Asynchronous, Blank, Decimal, Dispose, // nonstandard ) -// Defined I/O variants -ENUM_CLASS( - DefinedIo, ReadFormatted, ReadUnformatted, WriteFormatted, WriteUnformatted) const char *AsFortran(DefinedIo); -// Floating-point rounding modes; these are packed into a byte to save -// room in the runtime's format processing context structure. These -// enumerators are defined with the corresponding values returned from -// llvm.get.rounding. -enum class RoundingMode : std::uint8_t { - ToZero, // ROUND=ZERO, RZ - truncation - TiesToEven, // ROUND=NEAREST, RN - default IEEE rounding - Up, // ROUND=UP, RU - Down, // ROUND=DOWN, RD - TiesAwayFromZero, // ROUND=COMPATIBLE, RC - ties round away from zero -}; - // Fortran label. Must be in [1..99999]. using Label = std::uint64_t; -// Fortran arrays may have up to 15 dimensions (See Fortran 2018 section 5.4.6). -static constexpr int maxRank{15}; - // CUDA subprogram attribute combinations ENUM_CLASS(CUDASubprogramAttrs, Host, Device, HostDevice, Global, Grid_Global) diff --git a/flang/include/flang/Common/format.h b/flang/include/flang/Common/format.h index 2374ff6983cf4..138e84b72b733 100644 --- a/flang/include/flang/Common/format.h +++ b/flang/include/flang/Common/format.h @@ -10,7 +10,7 @@ #define FORTRAN_COMMON_FORMAT_H_ #include "enum-set.h" -#include "flang/Common/Fortran.h" +#include "flang/Common/Fortran-consts.h" #include // Define a FormatValidator class template to validate a format expression diff --git a/flang/include/flang/Common/target-rounding.h b/flang/include/flang/Common/target-rounding.h new file mode 100644 index 0000000000000..e31920f5f6343 --- /dev/null +++ b/flang/include/flang/Common/target-rounding.h @@ -0,0 +1,37 @@ +//===-- include/flang/Common/target-rounding.h ------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef FORTRAN_COMMON_TARGET_ROUNDING_H_ +#define FORTRAN_COMMON_TARGET_ROUNDING_H_ + +#include "flang/Common/Fortran-consts.h" +#include "flang/Common/enum-set.h" + +namespace Fortran::common { + +// Floating-point rounding control +struct Rounding { + common::RoundingMode mode{common::RoundingMode::TiesToEven}; + // When set, emulate status flag behavior peculiar to x86 + // (viz., fail to set the Underflow flag when an inexact product of a + // multiplication is rounded up to a normal number from a subnormal + // in some rounding modes) +#if __x86_64__ || __riscv || __loongarch__ + bool x86CompatibleBehavior{true}; +#else + bool x86CompatibleBehavior{false}; +#endif +}; + +// These are ordered like the bits in a common fenv.h header file. +ENUM_CLASS(RealFlag, InvalidArgument, Denorm, DivideByZero, Overflow, Underflow, + Inexact) +using RealFlags = common::EnumSet; + +} // namespace Fortran::common +#endif // FORTRAN_COMMON_TARGET_ROUNDING_H_ diff --git a/flang/include/flang/Evaluate/common.h b/flang/include/flang/Evaluate/common.h index d493e5fe04417..915e95169c7f8 100644 --- a/flang/include/flang/Evaluate/common.h +++ b/flang/include/flang/Evaluate/common.h @@ -16,6 +16,7 @@ #include "flang/Common/idioms.h" #include "flang/Common/indirection.h" #include "flang/Common/restorer.h" +#include "flang/Common/target-rounding.h" #include "flang/Parser/char-block.h" #include "flang/Parser/message.h" #include @@ -32,6 +33,8 @@ class IntrinsicProcTable; class TargetCharacteristics; using common::ConstantSubscript; +using common::RealFlag; +using common::RealFlags; using common::RelationalOperator; // Integers are always ordered; reals may not be. @@ -128,11 +131,6 @@ static constexpr bool Satisfies(RelationalOperator op, Relation relation) { return false; // silence g++ warning } -// These are ordered like the bits in a common fenv.h header file. -ENUM_CLASS(RealFlag, InvalidArgument, Denorm, DivideByZero, Overflow, Underflow, - Inexact) -using RealFlags = common::EnumSet; - template struct ValueWithRealFlags { A AccumulateFlags(RealFlags &f) { f |= flags; diff --git a/flang/include/flang/Evaluate/target.h b/flang/include/flang/Evaluate/target.h index d076fcbf08307..1950a4cb6bfc7 100644 --- a/flang/include/flang/Evaluate/target.h +++ b/flang/include/flang/Evaluate/target.h @@ -15,24 +15,13 @@ #include "flang/Common/Fortran.h" #include "flang/Common/enum-class.h" #include "flang/Common/enum-set.h" +#include "flang/Common/target-rounding.h" #include "flang/Evaluate/common.h" #include namespace Fortran::evaluate { -// Floating-point rounding control -struct Rounding { - common::RoundingMode mode{common::RoundingMode::TiesToEven}; - // When set, emulate status flag behavior peculiar to x86 - // (viz., fail to set the Underflow flag when an inexact product of a - // multiplication is rounded up to a normal number from a subnormal - // in some rounding modes) -#if __x86_64__ || __riscv || __loongarch__ - bool x86CompatibleBehavior{true}; -#else - bool x86CompatibleBehavior{false}; -#endif -}; +using common::Rounding; ENUM_CLASS(IeeeFeature, Denormal, Divide, Flags, Halting, Inf, Io, NaN, Rounding, Sqrt, Standard, Subnormal, UnderflowControl) diff --git a/flang/include/flang/Runtime/cpp-type.h b/flang/include/flang/Runtime/cpp-type.h index fe21dd544cf7d..27b43de7d0f0f 100644 --- a/flang/include/flang/Runtime/cpp-type.h +++ b/flang/include/flang/Runtime/cpp-type.h @@ -11,7 +11,7 @@ #ifndef FORTRAN_RUNTIME_CPP_TYPE_H_ #define FORTRAN_RUNTIME_CPP_TYPE_H_ -#include "flang/Common/Fortran.h" +#include "flang/Common/Fortran-consts.h" #include "flang/Common/float128.h" #include "flang/Common/uint128.h" #include diff --git a/flang/include/flang/Runtime/type-code.h b/flang/include/flang/Runtime/type-code.h index 8e7314e0af1ef..dd3a9f2690ee7 100644 --- a/flang/include/flang/Runtime/type-code.h +++ b/flang/include/flang/Runtime/type-code.h @@ -9,7 +9,7 @@ #ifndef FORTRAN_RUNTIME_TYPE_CODE_H_ #define FORTRAN_RUNTIME_TYPE_CODE_H_ -#include "flang/Common/Fortran.h" +#include "flang/Common/Fortran-consts.h" #include "flang/Common/optional.h" #include "flang/ISO_Fortran_binding_wrapper.h" #include diff --git a/flang/runtime/format.h b/flang/runtime/format.h index 5329f2482d3e4..815bf70685e64 100644 --- a/flang/runtime/format.h +++ b/flang/runtime/format.h @@ -13,7 +13,7 @@ #include "environment.h" #include "io-error.h" -#include "flang/Common/Fortran.h" +#include "flang/Common/Fortran-consts.h" #include "flang/Common/optional.h" #include "flang/Decimal/decimal.h" #include "flang/Runtime/freestanding-tools.h" diff --git a/flang/runtime/non-tbp-dio.h b/flang/runtime/non-tbp-dio.h index 05038a264ed99..8429d790fea57 100644 --- a/flang/runtime/non-tbp-dio.h +++ b/flang/runtime/non-tbp-dio.h @@ -22,7 +22,8 @@ #ifndef FORTRAN_RUNTIME_NON_TBP_DIO_H_ #define FORTRAN_RUNTIME_NON_TBP_DIO_H_ -#include "flang/Common/Fortran.h" +#include "flang/Common/Fortran-consts.h" +#include "flang/Common/api-attrs.h" #include namespace Fortran::runtime::typeInfo { diff --git a/flang/runtime/type-info.h b/flang/runtime/type-info.h index c3f3595e32ef2..3ccab0ff73ed2 100644 --- a/flang/runtime/type-info.h +++ b/flang/runtime/type-info.h @@ -12,11 +12,11 @@ // A C++ perspective of the derived type description schemata in // flang/module/__fortran_type_info.f90. -#include "terminator.h" -#include "flang/Common/Fortran.h" +#include "flang/Common/Fortran-consts.h" #include "flang/Common/bit-population-count.h" #include "flang/Common/optional.h" #include "flang/Runtime/descriptor.h" +#include "terminator.h" #include #include diff --git a/flang/unittests/Evaluate/fp-testing.cpp b/flang/unittests/Evaluate/fp-testing.cpp index 94d8d5086d000..893b10899181a 100644 --- a/flang/unittests/Evaluate/fp-testing.cpp +++ b/flang/unittests/Evaluate/fp-testing.cpp @@ -8,7 +8,7 @@ #endif using Fortran::common::RoundingMode; -using Fortran::evaluate::RealFlag; +using Fortran::common::RealFlag; ScopedHostFloatingPointEnvironment::ScopedHostFloatingPointEnvironment( #if __x86_64__ diff --git a/flang/unittests/Evaluate/fp-testing.h b/flang/unittests/Evaluate/fp-testing.h index 22dfa2d7d80c6..5801eb2e86b74 100644 --- a/flang/unittests/Evaluate/fp-testing.h +++ b/flang/unittests/Evaluate/fp-testing.h @@ -1,12 +1,12 @@ #ifndef FORTRAN_TEST_EVALUATE_FP_TESTING_H_ #define FORTRAN_TEST_EVALUATE_FP_TESTING_H_ -#include "flang/Evaluate/target.h" +#include "flang/Common/target-rounding.h" #include using Fortran::common::RoundingMode; -using Fortran::evaluate::RealFlags; -using Fortran::evaluate::Rounding; +using Fortran::common::RealFlags; +using Fortran::common::Rounding; class ScopedHostFloatingPointEnvironment { public: diff --git a/flang/unittests/Runtime/Complex.cpp b/flang/unittests/Runtime/Complex.cpp index 46f3ad2f2712b..d714da24dc4e5 100644 --- a/flang/unittests/Runtime/Complex.cpp +++ b/flang/unittests/Runtime/Complex.cpp @@ -13,7 +13,7 @@ #pragma clang diagnostic ignored "-Wc99-extensions" #endif -#include "flang/Common/Fortran.h" +#include "flang/Common/Fortran-consts.h" #include "flang/Runtime/cpp-type.h" #include "flang/Runtime/entry-names.h" From 6071ac6cf02cef644c0a60249308c90e82d781b6 Mon Sep 17 00:00:00 2001 From: Michael Kruse Date: Fri, 27 Sep 2024 13:26:54 +0200 Subject: [PATCH 02/13] clang-format --- flang/include/flang/Common/Fortran.h | 2 +- flang/runtime/type-info.h | 2 +- flang/unittests/Evaluate/fp-testing.cpp | 2 +- flang/unittests/Evaluate/fp-testing.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/flang/include/flang/Common/Fortran.h b/flang/include/flang/Common/Fortran.h index 7c8d788dd563d..623607d4fad26 100644 --- a/flang/include/flang/Common/Fortran.h +++ b/flang/include/flang/Common/Fortran.h @@ -12,9 +12,9 @@ // Fortran language concepts that are used in many phases are defined // once here to avoid redundancy and needless translation. -#include "flang/Common/Fortran-consts.h" #include "enum-set.h" #include "idioms.h" +#include "flang/Common/Fortran-consts.h" #include #include #include diff --git a/flang/runtime/type-info.h b/flang/runtime/type-info.h index 3ccab0ff73ed2..32403b1db5169 100644 --- a/flang/runtime/type-info.h +++ b/flang/runtime/type-info.h @@ -12,11 +12,11 @@ // A C++ perspective of the derived type description schemata in // flang/module/__fortran_type_info.f90. +#include "terminator.h" #include "flang/Common/Fortran-consts.h" #include "flang/Common/bit-population-count.h" #include "flang/Common/optional.h" #include "flang/Runtime/descriptor.h" -#include "terminator.h" #include #include diff --git a/flang/unittests/Evaluate/fp-testing.cpp b/flang/unittests/Evaluate/fp-testing.cpp index 893b10899181a..1a1d7425d5824 100644 --- a/flang/unittests/Evaluate/fp-testing.cpp +++ b/flang/unittests/Evaluate/fp-testing.cpp @@ -7,8 +7,8 @@ #include #endif -using Fortran::common::RoundingMode; using Fortran::common::RealFlag; +using Fortran::common::RoundingMode; ScopedHostFloatingPointEnvironment::ScopedHostFloatingPointEnvironment( #if __x86_64__ diff --git a/flang/unittests/Evaluate/fp-testing.h b/flang/unittests/Evaluate/fp-testing.h index 5801eb2e86b74..9091963a99b32 100644 --- a/flang/unittests/Evaluate/fp-testing.h +++ b/flang/unittests/Evaluate/fp-testing.h @@ -4,9 +4,9 @@ #include "flang/Common/target-rounding.h" #include -using Fortran::common::RoundingMode; using Fortran::common::RealFlags; using Fortran::common::Rounding; +using Fortran::common::RoundingMode; class ScopedHostFloatingPointEnvironment { public: From 98c71d8b21084841d068fe77d117b506f1809e69 Mon Sep 17 00:00:00 2001 From: "U-BERGUFFLEN\\meinersbur" Date: Fri, 27 Sep 2024 17:16:16 +0200 Subject: [PATCH 03/13] Normlize header guards --- flang/include/flang/Common/Fortran-consts.h | 2 +- flang/include/flang/Common/target-rounding.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/flang/include/flang/Common/Fortran-consts.h b/flang/include/flang/Common/Fortran-consts.h index 3d4377dd5a076..eedcdae335c40 100644 --- a/flang/include/flang/Common/Fortran-consts.h +++ b/flang/include/flang/Common/Fortran-consts.h @@ -41,4 +41,4 @@ enum class RoundingMode : std::uint8_t { }; } // namespace Fortran::common -#endif // FORTRAN_COMMON_FORTRAN_CONSTS_H_ +#endif /* FORTRAN_COMMON_FORTRAN_CONSTS_H_ */ diff --git a/flang/include/flang/Common/target-rounding.h b/flang/include/flang/Common/target-rounding.h index e31920f5f6343..c0c9f6c49b26a 100644 --- a/flang/include/flang/Common/target-rounding.h +++ b/flang/include/flang/Common/target-rounding.h @@ -34,4 +34,4 @@ ENUM_CLASS(RealFlag, InvalidArgument, Denorm, DivideByZero, Overflow, Underflow, using RealFlags = common::EnumSet; } // namespace Fortran::common -#endif // FORTRAN_COMMON_TARGET_ROUNDING_H_ +#endif /* FORTRAN_COMMON_TARGET_ROUNDING_H_ */ From 42e5abb5b291e78aeb152d7c636c75fe4d90492a Mon Sep 17 00:00:00 2001 From: Michael Kruse Date: Mon, 14 Oct 2024 13:55:16 +0200 Subject: [PATCH 04/13] Split headers in preparation for cross-compilation. NFC. --- flang/include/flang/Lower/Allocatable.h | 2 +- .../flang/Optimizer/Builder/MutableBox.h | 2 +- .../flang/Optimizer/CodeGen/DescriptorModel.h | 2 +- flang/include/flang/Runtime/CUDA/allocator.h | 2 +- flang/include/flang/Runtime/CUDA/descriptor.h | 2 +- .../flang/Runtime/allocator-registry-consts.h | 20 +++++ .../flang/Runtime/allocator-registry.h | 9 +-- .../flang/Runtime/array-constructor-consts.h | 54 +++++++++++++ .../include/flang/Runtime/array-constructor.h | 80 +++---------------- .../include/flang/Runtime/descriptor-consts.h | 72 +++++++++++++++++ flang/include/flang/Runtime/descriptor.h | 15 +--- flang/include/flang/Runtime/io-api-funcs.h | 39 +++++++++ flang/include/flang/Runtime/io-api.h | 3 - flang/include/flang/Runtime/iostat-funcs.h | 23 ++++++ flang/include/flang/Runtime/iostat.h | 2 - flang/lib/Lower/ConvertVariable.cpp | 2 +- .../Builder/Runtime/ArrayConstructor.cpp | 6 +- flang/lib/Optimizer/CodeGen/CodeGen.cpp | 18 ++--- flang/lib/Semantics/compute-offsets.cpp | 8 +- flang/runtime/environment-default-list.h | 0 flang/runtime/extensions.cpp | 2 +- flang/runtime/internal-unit.cpp | 2 + flang/runtime/io-api-common.h | 2 +- flang/runtime/io-api-minimal.cpp | 2 +- flang/runtime/io-api.cpp | 2 +- flang/runtime/io-error.h | 2 +- flang/runtime/io-stmt.h | 2 +- flang/runtime/iostat.cpp | 2 +- flang/runtime/namelist.cpp | 2 +- .../Builder/Runtime/AllocatableTest.cpp | 2 +- 30 files changed, 254 insertions(+), 127 deletions(-) create mode 100644 flang/include/flang/Runtime/allocator-registry-consts.h create mode 100644 flang/include/flang/Runtime/array-constructor-consts.h create mode 100644 flang/include/flang/Runtime/descriptor-consts.h create mode 100644 flang/include/flang/Runtime/io-api-funcs.h create mode 100644 flang/include/flang/Runtime/iostat-funcs.h mode change 100755 => 100644 flang/runtime/environment-default-list.h diff --git a/flang/include/flang/Lower/Allocatable.h b/flang/include/flang/Lower/Allocatable.h index 1209b157ed1f4..0e89af94af40f 100644 --- a/flang/include/flang/Lower/Allocatable.h +++ b/flang/include/flang/Lower/Allocatable.h @@ -15,7 +15,7 @@ #include "flang/Lower/AbstractConverter.h" #include "flang/Optimizer/Builder/MutableBox.h" -#include "flang/Runtime/allocator-registry.h" +#include "flang/Runtime/allocator-registry-consts.h" #include "llvm/ADT/StringRef.h" namespace mlir { diff --git a/flang/include/flang/Optimizer/Builder/MutableBox.h b/flang/include/flang/Optimizer/Builder/MutableBox.h index fea7c7204837b..39657ddaf6e03 100644 --- a/flang/include/flang/Optimizer/Builder/MutableBox.h +++ b/flang/include/flang/Optimizer/Builder/MutableBox.h @@ -14,7 +14,7 @@ #define FORTRAN_OPTIMIZER_BUILDER_MUTABLEBOX_H #include "flang/Optimizer/Builder/BoxValue.h" -#include "flang/Runtime/allocator-registry.h" +#include "flang/Runtime/allocator-registry-consts.h" #include "llvm/ADT/StringRef.h" namespace mlir { diff --git a/flang/include/flang/Optimizer/CodeGen/DescriptorModel.h b/flang/include/flang/Optimizer/CodeGen/DescriptorModel.h index ff0cf29e8073e..9cccf8db87270 100644 --- a/flang/include/flang/Optimizer/CodeGen/DescriptorModel.h +++ b/flang/include/flang/Optimizer/CodeGen/DescriptorModel.h @@ -23,7 +23,7 @@ #define OPTIMIZER_DESCRIPTOR_MODEL_H #include "flang/ISO_Fortran_binding_wrapper.h" -#include "flang/Runtime/descriptor.h" +#include "flang/Runtime/descriptor-consts.h" #include "mlir/Dialect/LLVMIR/LLVMTypes.h" #include "mlir/IR/BuiltinTypes.h" #include "llvm/Support/ErrorHandling.h" diff --git a/flang/include/flang/Runtime/CUDA/allocator.h b/flang/include/flang/Runtime/CUDA/allocator.h index 4527c9f18fa05..cc88896b1f0bd 100644 --- a/flang/include/flang/Runtime/CUDA/allocator.h +++ b/flang/include/flang/Runtime/CUDA/allocator.h @@ -9,7 +9,7 @@ #ifndef FORTRAN_RUNTIME_CUDA_ALLOCATOR_H_ #define FORTRAN_RUNTIME_CUDA_ALLOCATOR_H_ -#include "flang/Runtime/descriptor.h" +#include "flang/Runtime/descriptor-consts.h" #include "flang/Runtime/entry-names.h" #define CUDA_REPORT_IF_ERROR(expr) \ diff --git a/flang/include/flang/Runtime/CUDA/descriptor.h b/flang/include/flang/Runtime/CUDA/descriptor.h index d593989420420..501a834f43bd4 100644 --- a/flang/include/flang/Runtime/CUDA/descriptor.h +++ b/flang/include/flang/Runtime/CUDA/descriptor.h @@ -9,7 +9,7 @@ #ifndef FORTRAN_RUNTIME_CUDA_DESCRIPTOR_H_ #define FORTRAN_RUNTIME_CUDA_DESCRIPTOR_H_ -#include "flang/Runtime/descriptor.h" +#include "flang/Runtime/descriptor-consts.h" #include "flang/Runtime/entry-names.h" #include diff --git a/flang/include/flang/Runtime/allocator-registry-consts.h b/flang/include/flang/Runtime/allocator-registry-consts.h new file mode 100644 index 0000000000000..70735c2fc7a71 --- /dev/null +++ b/flang/include/flang/Runtime/allocator-registry-consts.h @@ -0,0 +1,20 @@ +//===-- include/flang/Runtime/allocator-registry-consts.h -------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef FORTRAN_RUNTIME_ALLOCATOR_REGISTRY_CONSTS_H_ +#define FORTRAN_RUNTIME_ALLOCATOR_REGISTRY_CONSTS_H_ + +static constexpr unsigned kDefaultAllocator = 0; + +// Allocator used for CUF +static constexpr unsigned kPinnedAllocatorPos = 1; +static constexpr unsigned kDeviceAllocatorPos = 2; +static constexpr unsigned kManagedAllocatorPos = 3; +static constexpr unsigned kUnifiedAllocatorPos = 4; + +#endif /* FORTRAN_RUNTIME_ALLOCATOR_REGISTRY_CONSTS_H_ */ diff --git a/flang/include/flang/Runtime/allocator-registry.h b/flang/include/flang/Runtime/allocator-registry.h index acfada506fafc..c5db7b2b1f201 100644 --- a/flang/include/flang/Runtime/allocator-registry.h +++ b/flang/include/flang/Runtime/allocator-registry.h @@ -10,17 +10,10 @@ #define FORTRAN_RUNTIME_ALLOCATOR_H_ #include "flang/Common/api-attrs.h" +#include "flang/Runtime/allocator-registry-consts.h" #include #include -static constexpr unsigned kDefaultAllocator = 0; - -// Allocator used for CUF -static constexpr unsigned kPinnedAllocatorPos = 1; -static constexpr unsigned kDeviceAllocatorPos = 2; -static constexpr unsigned kManagedAllocatorPos = 3; -static constexpr unsigned kUnifiedAllocatorPos = 4; - #define MAX_ALLOCATOR 7 // 3 bits are reserved in the descriptor. namespace Fortran::runtime { diff --git a/flang/include/flang/Runtime/array-constructor-consts.h b/flang/include/flang/Runtime/array-constructor-consts.h new file mode 100644 index 0000000000000..da058874e5048 --- /dev/null +++ b/flang/include/flang/Runtime/array-constructor-consts.h @@ -0,0 +1,54 @@ +//===-- include/flang/Runtime/array-constructor-consts.h --------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// External APIs to create temporary storage for array constructors when their +// final extents or length parameters cannot be pre-computed. + +#ifndef FORTRAN_RUNTIME_ARRAY_CONSTRUCTOR_CONSTS_H_ +#define FORTRAN_RUNTIME_ARRAY_CONSTRUCTOR_CONSTS_H_ + +#include "flang/Runtime/descriptor-consts.h" +#include "flang/Runtime/entry-names.h" +#include + +namespace Fortran::runtime { +struct ArrayConstructorVector; + +// Max sizeof(ArrayConstructorVector) and sizeof(ArrayConstructorVector) for any +// target. +// TODO: Use target-specific size/alignment instead of overapproximation. +constexpr std::size_t MaxArrayConstructorVectorSizeInBytes = 2 * 40; +constexpr std::size_t MaxArrayConstructorVectorAlignInBytes = 8; + +extern "C" { +// API to initialize an ArrayConstructorVector before any values are pushed to +// it. Inlined code is only expected to allocate the "ArrayConstructorVector" +// class instance storage with sufficient size (using +// "2*sizeof(ArrayConstructorVector)" on the host should be safe regardless of +// the target the runtime is compiled for). This avoids the need for the runtime +// to maintain a state, or to use dynamic allocation for it. "vectorClassSize" +// is used to validate that lowering allocated enough space for it. +void RTDECL(InitArrayConstructorVector)(ArrayConstructorVector &vector, + Descriptor &to, bool useValueLengthParameters, int vectorClassSize, + const char *sourceFile = nullptr, int sourceLine = 0); + +// Generic API to push any kind of entity into the array constructor (any +// Fortran type and any rank). +void RTDECL(PushArrayConstructorValue)( + ArrayConstructorVector &vector, const Descriptor &from); + +// API to push scalar array constructor value of: +// - a numerical or logical type, +// - or a derived type that has no length parameters, and no allocatable +// component (that would require deep copies). +// It requires no descriptor for the value that is passed via its base address. +void RTDECL(PushArrayConstructorSimpleScalar)( + ArrayConstructorVector &vector, void *from); +} // extern "C" +} // namespace Fortran::runtime +#endif /* FORTRAN_RUNTIME_ARRAY_CONSTRUCTOR_CONSTS_H_ */ diff --git a/flang/include/flang/Runtime/array-constructor.h b/flang/include/flang/Runtime/array-constructor.h index 46fc0418c7991..c068af9ba120c 100644 --- a/flang/include/flang/Runtime/array-constructor.h +++ b/flang/include/flang/Runtime/array-constructor.h @@ -12,6 +12,7 @@ #ifndef FORTRAN_RUNTIME_ARRAYCONSTRUCTOR_H_ #define FORTRAN_RUNTIME_ARRAYCONSTRUCTOR_H_ +#include "flang/Runtime/array-constructor-consts.h" #include "flang/Runtime/descriptor.h" #include "flang/Runtime/entry-names.h" #include @@ -42,77 +43,14 @@ struct ArrayConstructorVector { private: unsigned char useValueLengthParameters_ : 1; }; +static_assert(sizeof(Fortran::runtime::ArrayConstructorVector) <= + MaxArrayConstructorVectorSizeInBytes, + "ABI requires sizeof(ArrayConstructorVector) to be smaller than " + "MaxArrayConstructorVectorSizeInBytes"); +static_assert(alignof(Fortran::runtime::ArrayConstructorVector) <= + MaxArrayConstructorVectorAlignInBytes, + "ABI requires alignof(ArrayConstructorVector) to be smaller than " + "MaxArrayConstructorVectorAlignInBytes"); -// This file defines an API to "push" an evaluated array constructor value -// "from" into some storage "to" of an array constructor. It can be seen as a -// form of std::vector::push_back() implementation for Fortran array -// constructors. In the APIs and ArrayConstructorVector struct above: -// -// - "to" is a ranked-1 descriptor whose declared type is already set to the -// array constructor derived type. It may be already allocated, even before the -// first call to this API, or it may be unallocated. "to" extent is increased -// every time a "from" is pushed past its current extent. At this end of the -// API calls, its extent is the extent of the array constructor. If "to" is -// unallocated and its extent is not null, it is assumed this is the final array -// constructor extent value, and the first allocation already "reserves" storage -// space accordingly to avoid reallocations. -// - "from" is a scalar or array descriptor for the evaluated array -// constructor value that must be copied into the storage of "to" at -// "nextValuePosition". -// - "useValueLengthParameters" must be set to true if the array constructor -// has length parameters and no type spec. If it is true and "to" is -// unallocated, "to" will take the length parameters of "from". If it is true -// and "to" is an allocated character array constructor, it will be checked -// that "from" length matches the one from "to". When it is false, the -// character length must already be set in "to" before the first call to this -// API and "from" character lengths are allowed to mismatch from "to". -// - "nextValuePosition" is the zero based sequence position of "from" in the -// array constructor. It is updated after this call by the number of "from" -// elements. It should be set to zero by the caller of this API before the first -// call. -// - "actualAllocationSize" is the current allocation size of "to" storage. It -// may be bigger than "to" extent for reallocation optimization purposes, but -// should never be smaller, unless this is the first call and "to" is -// unallocated. It is updated by the runtime after each successful allocation or -// reallocation. It should be set to "to" extent if "to" is allocated before the -// first call of this API, and can be left undefined otherwise. -// -// Note that this API can be used with "to" being a variable (that can be -// discontiguous). This can be done when the variable is the left hand side of -// an assignment from an array constructor as long as: -// - none of the ac-value overlaps with the variable, -// - this is an intrinsic assignment that is not a whole allocatable -// assignment, *and* for a type that has no components requiring user defined -// assignments, -// - the variable is properly finalized before using this API if its need to, -// - "useValueLengthParameters" should be set to false in this case, even if -// the array constructor has no type-spec, since the variable may have a -// different character length than the array constructor values. - -extern "C" { -// API to initialize an ArrayConstructorVector before any values are pushed to -// it. Inlined code is only expected to allocate the "ArrayConstructorVector" -// class instance storage with sufficient size (using -// "2*sizeof(ArrayConstructorVector)" on the host should be safe regardless of -// the target the runtime is compiled for). This avoids the need for the runtime -// to maintain a state, or to use dynamic allocation for it. "vectorClassSize" -// is used to validate that lowering allocated enough space for it. -void RTDECL(InitArrayConstructorVector)(ArrayConstructorVector &vector, - Descriptor &to, bool useValueLengthParameters, int vectorClassSize, - const char *sourceFile = nullptr, int sourceLine = 0); - -// Generic API to push any kind of entity into the array constructor (any -// Fortran type and any rank). -void RTDECL(PushArrayConstructorValue)( - ArrayConstructorVector &vector, const Descriptor &from); - -// API to push scalar array constructor value of: -// - a numerical or logical type, -// - or a derived type that has no length parameters, and no allocatable -// component (that would require deep copies). -// It requires no descriptor for the value that is passed via its base address. -void RTDECL(PushArrayConstructorSimpleScalar)( - ArrayConstructorVector &vector, void *from); -} // extern "C" } // namespace Fortran::runtime #endif // FORTRAN_RUNTIME_ARRAYCONSTRUCTOR_H_ diff --git a/flang/include/flang/Runtime/descriptor-consts.h b/flang/include/flang/Runtime/descriptor-consts.h new file mode 100644 index 0000000000000..098eb59ca01b2 --- /dev/null +++ b/flang/include/flang/Runtime/descriptor-consts.h @@ -0,0 +1,72 @@ +//===-- include/flang/Runtime/descriptor-consts.h ---------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef FORTRAN_RUNTIME_DESCRIPTOR_CONSTS_H_ +#define FORTRAN_RUNTIME_DESCRIPTOR_CONSTS_H_ + +#include "flang/Common/api-attrs.h" +#include "flang/ISO_Fortran_binding_wrapper.h" +#include +#include + +// Value of the addendum presence flag. +#define _CFI_ADDENDUM_FLAG 1 +// Number of bits needed to be shifted when manipulating the allocator index. +#define _CFI_ALLOCATOR_IDX_SHIFT 1 +// Allocator index mask. +#define _CFI_ALLOCATOR_IDX_MASK 0b00001110 + +namespace Fortran::runtime::typeInfo { +using TypeParameterValue = std::int64_t; +class DerivedType; +} // namespace Fortran::runtime::typeInfo + +namespace Fortran::runtime { +class Descriptor; + +/// Returns size in bytes of the descriptor (not the data) +/// This must be at least as large as the largest descriptor of any target +/// triple. +static constexpr RT_API_ATTRS std::size_t MaxDescriptorSizeInBytes( + int rank, bool addendum = false, int lengthTypeParameters = 0) { + // Layout: + // + // fortran::runtime::Descriptor { + // ISO::CFI_cdesc_t { + // void *base_addr; (pointer -> up to 8 bytes) + // size_t elem_len; (up to 8 bytes) + // int version; (up to 4 bytes) + // CFI_rank_t rank; (unsigned char -> 1 byte) + // CFI_type_t type; (signed char -> 1 byte) + // CFI_attribute_t attribute; (unsigned char -> 1 byte) + // unsigned char extra; (1 byte) + // } + // } + // fortran::runtime::Dimension[rank] { + // ISO::CFI_dim_t { + // CFI_index_t lower_bound; (ptrdiff_t -> up to 8 bytes) + // CFI_index_t extent; (ptrdiff_t -> up to 8 bytes) + // CFI_index_t sm; (ptrdiff_t -> up to 8 bytes) + // } + // } + // fortran::runtime::DescriptorAddendum { + // const typeInfo::DerivedType *derivedType_; (pointer -> up to 8 + // bytes) typeInfo::TypeParameterValue len_[lenParameters]; (int64_t -> 8 + // bytes) + // } + std::size_t bytes{24u + rank * 24u}; + if (addendum || lengthTypeParameters > 0) { + if (lengthTypeParameters < 1) + lengthTypeParameters = 1; + bytes += 8u + static_cast(lengthTypeParameters) * 8u; + } + return bytes; +} + +} // namespace Fortran::runtime +#endif /* FORTRAN_RUNTIME_DESCRIPTOR_CONSTS_H_ */ diff --git a/flang/include/flang/Runtime/descriptor.h b/flang/include/flang/Runtime/descriptor.h index 030d0c1031fba..6d0f09c79508c 100644 --- a/flang/include/flang/Runtime/descriptor.h +++ b/flang/include/flang/Runtime/descriptor.h @@ -19,6 +19,7 @@ // but should never reference this internal header. #include "flang/ISO_Fortran_binding_wrapper.h" +#include "flang/Runtime/descriptor-consts.h" #include "flang/Runtime/memory.h" #include "flang/Runtime/type-code.h" #include @@ -28,11 +29,6 @@ #include #include -namespace Fortran::runtime::typeInfo { -using TypeParameterValue = std::int64_t; -class DerivedType; -} // namespace Fortran::runtime::typeInfo - namespace Fortran::runtime { using SubscriptValue = ISO::CFI_index_t; @@ -420,13 +416,6 @@ class Descriptor { void Dump(FILE * = stdout) const; -// Value of the addendum presence flag. -#define _CFI_ADDENDUM_FLAG 1 -// Number of bits needed to be shifted when manipulating the allocator index. -#define _CFI_ALLOCATOR_IDX_SHIFT 1 -// Allocator index mask. -#define _CFI_ALLOCATOR_IDX_MASK 0b00001110 - RT_API_ATTRS inline bool HasAddendum() const { return raw_.extra & _CFI_ADDENDUM_FLAG; } @@ -464,6 +453,8 @@ class alignas(Descriptor) StaticDescriptor { static constexpr bool hasAddendum{ADDENDUM || MAX_LEN_PARMS > 0}; static constexpr std::size_t byteSize{ Descriptor::SizeInBytes(maxRank, hasAddendum, maxLengthTypeParameters)}; + static_assert(byteSize <= + MaxDescriptorSizeInBytes(maxRank, hasAddendum, maxLengthTypeParameters)); RT_OFFLOAD_VAR_GROUP_END RT_API_ATTRS Descriptor &descriptor() { diff --git a/flang/include/flang/Runtime/io-api-funcs.h b/flang/include/flang/Runtime/io-api-funcs.h new file mode 100644 index 0000000000000..e81c3cb8156c4 --- /dev/null +++ b/flang/include/flang/Runtime/io-api-funcs.h @@ -0,0 +1,39 @@ +//===-- include/flang/Runtime/io-api-funcs.h --------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// Defines API between compiled code and I/O runtime library. + +#ifndef FORTRAN_RUNTIME_IO_API_FUNCS_H_ +#define FORTRAN_RUNTIME_IO_API_FUNCS_H_ + +#include "flang/Common/uint128.h" +#include "flang/Runtime/entry-names.h" +#include "flang/Runtime/io-api.h" +#include "flang/Runtime/iostat.h" +#include "flang/Runtime/magic-numbers.h" +#include +#include + +namespace Fortran::runtime { +class Descriptor; +} // namespace Fortran::runtime + +namespace Fortran::runtime::io { + +struct NonTbpDefinedIoTable; +class NamelistGroup; +class IoStatementState; +using Cookie = IoStatementState *; +using ExternalUnit = int; +using AsynchronousId = int; + +RT_API_ATTRS const char *InquiryKeywordHashDecode( + char *buffer, std::size_t, InquiryKeywordHash); + +} // namespace Fortran::runtime::io +#endif /* FORTRAN_RUNTIME_IO_API_FUNCS_H_ */ diff --git a/flang/include/flang/Runtime/io-api.h b/flang/include/flang/Runtime/io-api.h index 328afc715a3f1..e588b46dc4b3a 100644 --- a/flang/include/flang/Runtime/io-api.h +++ b/flang/include/flang/Runtime/io-api.h @@ -51,9 +51,6 @@ constexpr InquiryKeywordHash HashInquiryKeyword(const char *p) { return hash; } -RT_API_ATTRS const char *InquiryKeywordHashDecode( - char *buffer, std::size_t, InquiryKeywordHash); - extern "C" { #define IONAME(name) RTNAME(io##name) diff --git a/flang/include/flang/Runtime/iostat-funcs.h b/flang/include/flang/Runtime/iostat-funcs.h new file mode 100644 index 0000000000000..3ab4527ea829a --- /dev/null +++ b/flang/include/flang/Runtime/iostat-funcs.h @@ -0,0 +1,23 @@ +//===-- include/flang/Runtime/iostat-funcs.h --------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +// Defines the values returned by the runtime for IOSTAT= specifiers +// on I/O statements. + +#ifndef FORTRAN_RUNTIME_IOSTAT_FUNCS_H_ +#define FORTRAN_RUNTIME_IOSTAT_FUNCS_H_ + +#include "flang/Common/api-attrs.h" +#include "flang/Runtime/iostat.h" + +namespace Fortran::runtime::io { + +RT_API_ATTRS const char *IostatErrorString(int); + +} // namespace Fortran::runtime::io +#endif /* FORTRAN_RUNTIME_IOSTAT_FUNCS_H_ */ diff --git a/flang/include/flang/Runtime/iostat.h b/flang/include/flang/Runtime/iostat.h index 6ce7c82b424eb..0565718f6c103 100644 --- a/flang/include/flang/Runtime/iostat.h +++ b/flang/include/flang/Runtime/iostat.h @@ -89,7 +89,5 @@ enum Iostat { IostatNonExternalDefinedUnformattedIo, }; -RT_API_ATTRS const char *IostatErrorString(int); - } // namespace Fortran::runtime::io #endif // FORTRAN_RUNTIME_IOSTAT_H_ diff --git a/flang/lib/Lower/ConvertVariable.cpp b/flang/lib/Lower/ConvertVariable.cpp index f76d44f5479d3..82bedca7bd41d 100644 --- a/flang/lib/Lower/ConvertVariable.cpp +++ b/flang/lib/Lower/ConvertVariable.cpp @@ -39,7 +39,7 @@ #include "flang/Optimizer/Support/FatalError.h" #include "flang/Optimizer/Support/InternalNames.h" #include "flang/Optimizer/Support/Utils.h" -#include "flang/Runtime/allocator-registry.h" +#include "flang/Runtime/allocator-registry-consts.h" #include "flang/Semantics/runtime-type-info.h" #include "flang/Semantics/tools.h" #include "llvm/Support/CommandLine.h" diff --git a/flang/lib/Optimizer/Builder/Runtime/ArrayConstructor.cpp b/flang/lib/Optimizer/Builder/Runtime/ArrayConstructor.cpp index c786bef5cb1c4..b7c6dc5fb2bf6 100644 --- a/flang/lib/Optimizer/Builder/Runtime/ArrayConstructor.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/ArrayConstructor.cpp @@ -9,7 +9,7 @@ #include "flang/Optimizer/Builder/Runtime/ArrayConstructor.h" #include "flang/Optimizer/Builder/FIRBuilder.h" #include "flang/Optimizer/Builder/Runtime/RTBuilder.h" -#include "flang/Runtime/array-constructor.h" +#include "flang/Runtime/array-constructor-consts.h" using namespace Fortran::runtime; @@ -29,8 +29,8 @@ mlir::Value fir::runtime::genInitArrayConstructorVector( // the target. The "cookieSize" argument is used to validate this wild // assumption until runtime interfaces are improved. std::size_t arrayVectorStructBitSize = - 2 * sizeof(Fortran::runtime::ArrayConstructorVector) * 8; - std::size_t alignLike = alignof(Fortran::runtime::ArrayConstructorVector) * 8; + MaxArrayConstructorVectorSizeInBytes * 8; + std::size_t alignLike = MaxArrayConstructorVectorAlignInBytes * 8; fir::SequenceType::Extent numElem = (arrayVectorStructBitSize + alignLike - 1) / alignLike; mlir::Type intType = builder.getIntegerType(alignLike); diff --git a/flang/lib/Optimizer/CodeGen/CodeGen.cpp b/flang/lib/Optimizer/CodeGen/CodeGen.cpp index 88293bcf36a78..eed389380f7cc 100644 --- a/flang/lib/Optimizer/CodeGen/CodeGen.cpp +++ b/flang/lib/Optimizer/CodeGen/CodeGen.cpp @@ -23,8 +23,8 @@ #include "flang/Optimizer/Support/InternalNames.h" #include "flang/Optimizer/Support/TypeCode.h" #include "flang/Optimizer/Support/Utils.h" -#include "flang/Runtime/allocator-registry.h" -#include "flang/Runtime/descriptor.h" +#include "flang/Runtime/allocator-registry-consts.h" +#include "flang/Runtime/descriptor-consts.h" #include "flang/Semantics/runtime-type-info.h" #include "mlir/Conversion/ArithCommon/AttrToLLVMConverter.h" #include "mlir/Conversion/ArithToLLVM/ArithToLLVM.h" @@ -1273,16 +1273,12 @@ struct EmboxCommonConversion : public fir::FIROpConversion { insertField(rewriter, loc, descriptor, {kExtraPosInBox}, extraField); } else { // Compute the value of the extra field based on allocator_idx and - // addendum present using a Descriptor object. - Fortran::runtime::StaticDescriptor staticDescriptor; - Fortran::runtime::Descriptor &desc{staticDescriptor.descriptor()}; - desc.raw().extra = 0; - desc.SetAllocIdx(allocatorIdx); + // addendum present. + unsigned extra = allocatorIdx << _CFI_ALLOCATOR_IDX_SHIFT; if (hasAddendum) - desc.SetHasAddendum(); - descriptor = - insertField(rewriter, loc, descriptor, {kExtraPosInBox}, - this->genI32Constant(loc, rewriter, desc.raw().extra)); + extra |= _CFI_ADDENDUM_FLAG; + descriptor = insertField(rewriter, loc, descriptor, {kExtraPosInBox}, + this->genI32Constant(loc, rewriter, extra)); } if (hasAddendum) { diff --git a/flang/lib/Semantics/compute-offsets.cpp b/flang/lib/Semantics/compute-offsets.cpp index b5a58ddca0ecd..c5774ed30de74 100644 --- a/flang/lib/Semantics/compute-offsets.cpp +++ b/flang/lib/Semantics/compute-offsets.cpp @@ -11,7 +11,7 @@ #include "flang/Evaluate/fold.h" #include "flang/Evaluate/shape.h" #include "flang/Evaluate/type.h" -#include "flang/Runtime/descriptor.h" +#include "flang/Runtime/descriptor-consts.h" #include "flang/Semantics/scope.h" #include "flang/Semantics/semantics.h" #include "flang/Semantics/symbol.h" @@ -341,8 +341,12 @@ auto ComputeOffsetsHelper::GetSizeAndAlignment( const auto *derived{evaluate::GetDerivedTypeSpec(dyType)}; int lenParams{derived ? CountLenParameters(*derived) : 0}; bool needAddendum{derived || (dyType && dyType->IsUnlimitedPolymorphic())}; - std::size_t size{runtime::Descriptor::SizeInBytes( + + // FIXME: Get descriptor size from targetCharacteristics instead + // overapproximation + std::size_t size{runtime::MaxDescriptorSizeInBytes( symbol.Rank(), needAddendum, lenParams)}; + return {size, targetCharacteristics.descriptorAlignment()}; } if (IsProcedurePointer(symbol)) { diff --git a/flang/runtime/environment-default-list.h b/flang/runtime/environment-default-list.h old mode 100755 new mode 100644 diff --git a/flang/runtime/extensions.cpp b/flang/runtime/extensions.cpp index be3833db88b07..8cd5f3ce696b4 100644 --- a/flang/runtime/extensions.cpp +++ b/flang/runtime/extensions.cpp @@ -15,7 +15,7 @@ #include "flang/Runtime/command.h" #include "flang/Runtime/descriptor.h" #include "flang/Runtime/entry-names.h" -#include "flang/Runtime/io-api.h" +#include "flang/Runtime/io-api-funcs.h" #include #include #include diff --git a/flang/runtime/internal-unit.cpp b/flang/runtime/internal-unit.cpp index f28700ee01581..f8f3877efb20e 100644 --- a/flang/runtime/internal-unit.cpp +++ b/flang/runtime/internal-unit.cpp @@ -36,6 +36,8 @@ RT_API_ATTRS InternalDescriptorUnit::InternalDescriptorUnit( Descriptor &d{descriptor()}; RUNTIME_CHECK( terminator, that.SizeInBytes() <= d.SizeInBytes(maxRank, true, 0)); + RUNTIME_CHECK(terminator, + that.SizeInBytes() <= MaxDescriptorSizeInBytes(maxRank, true, 0)); new (&d) Descriptor{that}; d.Check(); internalIoCharKind = thatType->second; diff --git a/flang/runtime/io-api-common.h b/flang/runtime/io-api-common.h index c7b86cab73a52..b4ac9a61c09ec 100644 --- a/flang/runtime/io-api-common.h +++ b/flang/runtime/io-api-common.h @@ -14,7 +14,7 @@ #include "unit.h" #include "flang/Common/api-attrs.h" #include "flang/Common/optional.h" -#include "flang/Runtime/io-api.h" +#include "flang/Runtime/io-api-funcs.h" namespace Fortran::runtime::io { diff --git a/flang/runtime/io-api-minimal.cpp b/flang/runtime/io-api-minimal.cpp index ad76fe3de0324..82376cf964166 100644 --- a/flang/runtime/io-api-minimal.cpp +++ b/flang/runtime/io-api-minimal.cpp @@ -16,7 +16,7 @@ #include "terminator.h" #include "tools.h" #include "unit.h" -#include "flang/Runtime/io-api.h" +#include "flang/Runtime/io-api-funcs.h" namespace Fortran::runtime::io { RT_EXT_API_GROUP_BEGIN diff --git a/flang/runtime/io-api.cpp b/flang/runtime/io-api.cpp index e3c6b9e5ca895..0fe69c981d17c 100644 --- a/flang/runtime/io-api.cpp +++ b/flang/runtime/io-api.cpp @@ -13,7 +13,6 @@ // OutputReal{32,64}, OutputComplex{32,64}, OutputAscii, & EndIoStatement() // are in runtime/io-api-minimal.cpp. -#include "flang/Runtime/io-api.h" #include "descriptor-io.h" #include "edit-input.h" #include "edit-output.h" @@ -26,6 +25,7 @@ #include "unit.h" #include "flang/Common/optional.h" #include "flang/Runtime/descriptor.h" +#include "flang/Runtime/io-api-funcs.h" #include "flang/Runtime/memory.h" #include #include diff --git a/flang/runtime/io-error.h b/flang/runtime/io-error.h index 426573e2faf00..22e43db710288 100644 --- a/flang/runtime/io-error.h +++ b/flang/runtime/io-error.h @@ -16,7 +16,7 @@ #define FORTRAN_RUNTIME_IO_ERROR_H_ #include "terminator.h" -#include "flang/Runtime/iostat.h" +#include "flang/Runtime/iostat-funcs.h" #include "flang/Runtime/memory.h" #include diff --git a/flang/runtime/io-stmt.h b/flang/runtime/io-stmt.h index 2e0ca46078ecd..30d7bd86c54b3 100644 --- a/flang/runtime/io-stmt.h +++ b/flang/runtime/io-stmt.h @@ -20,7 +20,7 @@ #include "flang/Common/reference-wrapper.h" #include "flang/Common/visit.h" #include "flang/Runtime/descriptor.h" -#include "flang/Runtime/io-api.h" +#include "flang/Runtime/io-api-funcs.h" #include #include #include diff --git a/flang/runtime/iostat.cpp b/flang/runtime/iostat.cpp index 39e224cb01286..0d71eb09e0a50 100644 --- a/flang/runtime/iostat.cpp +++ b/flang/runtime/iostat.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "flang/Runtime/iostat.h" +#include "flang/Runtime/iostat-funcs.h" namespace Fortran::runtime::io { RT_OFFLOAD_API_GROUP_BEGIN diff --git a/flang/runtime/namelist.cpp b/flang/runtime/namelist.cpp index af092de70f781..cfed7f2c6bf97 100644 --- a/flang/runtime/namelist.cpp +++ b/flang/runtime/namelist.cpp @@ -10,7 +10,7 @@ #include "descriptor-io.h" #include "emit-encoded.h" #include "io-stmt.h" -#include "flang/Runtime/io-api.h" +#include "flang/Runtime/io-api-funcs.h" #include #include #include diff --git a/flang/unittests/Optimizer/Builder/Runtime/AllocatableTest.cpp b/flang/unittests/Optimizer/Builder/Runtime/AllocatableTest.cpp index 1db43cacc90f0..f618e72d7b7f3 100644 --- a/flang/unittests/Optimizer/Builder/Runtime/AllocatableTest.cpp +++ b/flang/unittests/Optimizer/Builder/Runtime/AllocatableTest.cpp @@ -9,7 +9,7 @@ #include "flang/Optimizer/Builder/Runtime/Allocatable.h" #include "RuntimeCallTestBase.h" #include "gtest/gtest.h" -#include "flang/Runtime/descriptor.h" +#include "flang/Runtime/descriptor-consts.h" using namespace Fortran::runtime; From 8757eb974fcc57630e85ed1ad838bb2dbbb5a162 Mon Sep 17 00:00:00 2001 From: Michael Kruse Date: Mon, 14 Oct 2024 16:51:07 +0200 Subject: [PATCH 05/13] Move SubscriptValue to public header --- flang/include/flang/Runtime/descriptor-consts.h | 1 + flang/include/flang/Runtime/descriptor.h | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/flang/include/flang/Runtime/descriptor-consts.h b/flang/include/flang/Runtime/descriptor-consts.h index 098eb59ca01b2..c08e5018d0af5 100644 --- a/flang/include/flang/Runtime/descriptor-consts.h +++ b/flang/include/flang/Runtime/descriptor-consts.h @@ -28,6 +28,7 @@ class DerivedType; namespace Fortran::runtime { class Descriptor; +using SubscriptValue = ISO::CFI_index_t; /// Returns size in bytes of the descriptor (not the data) /// This must be at least as large as the largest descriptor of any target diff --git a/flang/include/flang/Runtime/descriptor.h b/flang/include/flang/Runtime/descriptor.h index 6d0f09c79508c..dd36fba157ca9 100644 --- a/flang/include/flang/Runtime/descriptor.h +++ b/flang/include/flang/Runtime/descriptor.h @@ -31,7 +31,6 @@ namespace Fortran::runtime { -using SubscriptValue = ISO::CFI_index_t; class Terminator; RT_VAR_GROUP_BEGIN From 2c310718a60315603ab83eabf2246cb4d682b360 Mon Sep 17 00:00:00 2001 From: Michael Kruse Date: Wed, 16 Oct 2024 17:27:08 +0200 Subject: [PATCH 06/13] Restore API explanation comment --- .../flang/Runtime/array-constructor-consts.h | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/flang/include/flang/Runtime/array-constructor-consts.h b/flang/include/flang/Runtime/array-constructor-consts.h index da058874e5048..15fd4ae2d3203 100644 --- a/flang/include/flang/Runtime/array-constructor-consts.h +++ b/flang/include/flang/Runtime/array-constructor-consts.h @@ -25,6 +25,52 @@ struct ArrayConstructorVector; constexpr std::size_t MaxArrayConstructorVectorSizeInBytes = 2 * 40; constexpr std::size_t MaxArrayConstructorVectorAlignInBytes = 8; +// This file defines an API to "push" an evaluated array constructor value +// "from" into some storage "to" of an array constructor. It can be seen as a +// form of std::vector::push_back() implementation for Fortran array +// constructors. In the APIs and ArrayConstructorVector struct above: +// +// - "to" is a ranked-1 descriptor whose declared type is already set to the +// array constructor derived type. It may be already allocated, even before the +// first call to this API, or it may be unallocated. "to" extent is increased +// every time a "from" is pushed past its current extent. At this end of the +// API calls, its extent is the extent of the array constructor. If "to" is +// unallocated and its extent is not null, it is assumed this is the final array +// constructor extent value, and the first allocation already "reserves" storage +// space accordingly to avoid reallocations. +// - "from" is a scalar or array descriptor for the evaluated array +// constructor value that must be copied into the storage of "to" at +// "nextValuePosition". +// - "useValueLengthParameters" must be set to true if the array constructor +// has length parameters and no type spec. If it is true and "to" is +// unallocated, "to" will take the length parameters of "from". If it is true +// and "to" is an allocated character array constructor, it will be checked +// that "from" length matches the one from "to". When it is false, the +// character length must already be set in "to" before the first call to this +// API and "from" character lengths are allowed to mismatch from "to". +// - "nextValuePosition" is the zero based sequence position of "from" in the +// array constructor. It is updated after this call by the number of "from" +// elements. It should be set to zero by the caller of this API before the first +// call. +// - "actualAllocationSize" is the current allocation size of "to" storage. It +// may be bigger than "to" extent for reallocation optimization purposes, but +// should never be smaller, unless this is the first call and "to" is +// unallocated. It is updated by the runtime after each successful allocation or +// reallocation. It should be set to "to" extent if "to" is allocated before the +// first call of this API, and can be left undefined otherwise. +// +// Note that this API can be used with "to" being a variable (that can be +// discontiguous). This can be done when the variable is the left hand side of +// an assignment from an array constructor as long as: +// - none of the ac-value overlaps with the variable, +// - this is an intrinsic assignment that is not a whole allocatable +// assignment, *and* for a type that has no components requiring user defined +// assignments, +// - the variable is properly finalized before using this API if its need to, +// - "useValueLengthParameters" should be set to false in this case, even if +// the array constructor has no type-spec, since the variable may have a +// different character length than the array constructor values. + extern "C" { // API to initialize an ArrayConstructorVector before any values are pushed to // it. Inlined code is only expected to allocate the "ArrayConstructorVector" From 5ce28b58bf9b1456b8d6039178f80471d09149f6 Mon Sep 17 00:00:00 2001 From: Michael Kruse Date: Wed, 16 Oct 2024 19:26:07 +0200 Subject: [PATCH 07/13] Remove vectorClassSize parameter --- .../flang/Runtime/array-constructor-consts.h | 11 +++++------ .../Optimizer/Builder/Runtime/ArrayConstructor.cpp | 13 ++++++------- flang/runtime/array-constructor.cpp | 9 +++------ .../test/Lower/HLFIR/array-ctor-as-runtime-temp.f90 | 7 +++---- flang/test/Lower/HLFIR/array-ctor-character.f90 | 2 +- flang/test/Lower/HLFIR/array-ctor-derived.f90 | 4 ++-- flang/test/Lower/HLFIR/structure-constructor.f90 | 3 +-- flang/unittests/Runtime/ArrayConstructor.cpp | 12 ++++-------- 8 files changed, 25 insertions(+), 36 deletions(-) diff --git a/flang/include/flang/Runtime/array-constructor-consts.h b/flang/include/flang/Runtime/array-constructor-consts.h index 15fd4ae2d3203..36699afd405e3 100644 --- a/flang/include/flang/Runtime/array-constructor-consts.h +++ b/flang/include/flang/Runtime/array-constructor-consts.h @@ -74,13 +74,12 @@ constexpr std::size_t MaxArrayConstructorVectorAlignInBytes = 8; extern "C" { // API to initialize an ArrayConstructorVector before any values are pushed to // it. Inlined code is only expected to allocate the "ArrayConstructorVector" -// class instance storage with sufficient size (using -// "2*sizeof(ArrayConstructorVector)" on the host should be safe regardless of -// the target the runtime is compiled for). This avoids the need for the runtime -// to maintain a state, or to use dynamic allocation for it. "vectorClassSize" -// is used to validate that lowering allocated enough space for it. +// class instance storage with sufficient size +// (MaxArrayConstructorVectorSizeInBytes is expected to be large enough for all +// supported targets). This avoids the need for the runtime to maintain a state, +// or to use dynamic allocation for it. void RTDECL(InitArrayConstructorVector)(ArrayConstructorVector &vector, - Descriptor &to, bool useValueLengthParameters, int vectorClassSize, + Descriptor &to, bool useValueLengthParameters, const char *sourceFile = nullptr, int sourceLine = 0); // Generic API to push any kind of entity into the array constructor (any diff --git a/flang/lib/Optimizer/Builder/Runtime/ArrayConstructor.cpp b/flang/lib/Optimizer/Builder/Runtime/ArrayConstructor.cpp index b7c6dc5fb2bf6..0d56cd2edc99b 100644 --- a/flang/lib/Optimizer/Builder/Runtime/ArrayConstructor.cpp +++ b/flang/lib/Optimizer/Builder/Runtime/ArrayConstructor.cpp @@ -25,9 +25,10 @@ mlir::Value fir::runtime::genInitArrayConstructorVector( mlir::Location loc, fir::FirOpBuilder &builder, mlir::Value toBox, mlir::Value useValueLengthParameters) { // Allocate storage for the runtime cookie for the array constructor vector. - // Use the "host" size and alignment, but double them to be safe regardless of - // the target. The "cookieSize" argument is used to validate this wild - // assumption until runtime interfaces are improved. + // Use pessimistic values for size and alignment that are valid for all + // supported targets. Whether the actual ArrayConstructorVector object fits + // into the available MaxArrayConstructorVectorSizeInBytes is verified when + // building clang-rt. std::size_t arrayVectorStructBitSize = MaxArrayConstructorVectorSizeInBytes * 8; std::size_t alignLike = MaxArrayConstructorVectorAlignInBytes * 8; @@ -43,14 +44,12 @@ mlir::Value fir::runtime::genInitArrayConstructorVector( loc, builder); mlir::FunctionType funcType = func.getFunctionType(); cookie = builder.createConvert(loc, funcType.getInput(0), cookie); - mlir::Value cookieSize = builder.createIntegerConstant( - loc, funcType.getInput(3), numElem * alignLike / 8); mlir::Value sourceFile = fir::factory::locationToFilename(builder, loc); mlir::Value sourceLine = - fir::factory::locationToLineNo(builder, loc, funcType.getInput(5)); + fir::factory::locationToLineNo(builder, loc, funcType.getInput(4)); auto args = fir::runtime::createArguments(builder, loc, funcType, cookie, toBox, useValueLengthParameters, - cookieSize, sourceFile, sourceLine); + sourceFile, sourceLine); builder.create(loc, func, args); return cookie; } diff --git a/flang/runtime/array-constructor.cpp b/flang/runtime/array-constructor.cpp index 72e08feff7fd1..c6953167f5fb2 100644 --- a/flang/runtime/array-constructor.cpp +++ b/flang/runtime/array-constructor.cpp @@ -92,13 +92,10 @@ extern "C" { RT_EXT_API_GROUP_BEGIN void RTDEF(InitArrayConstructorVector)(ArrayConstructorVector &vector, - Descriptor &to, bool useValueLengthParameters, int vectorClassSize, - const char *sourceFile, int sourceLine) { + Descriptor &to, bool useValueLengthParameters, const char *sourceFile, + int sourceLine) { Terminator terminator{vector.sourceFile, vector.sourceLine}; - RUNTIME_CHECK(terminator, - to.rank() == 1 && - sizeof(ArrayConstructorVector) <= - static_cast(vectorClassSize)); + RUNTIME_CHECK(terminator, to.rank() == 1); SubscriptValue actualAllocationSize{ to.IsAllocated() ? static_cast(to.Elements()) : 0}; (void)new (&vector) ArrayConstructorVector{to, /*nextValuePosition=*/0, diff --git a/flang/test/Lower/HLFIR/array-ctor-as-runtime-temp.f90 b/flang/test/Lower/HLFIR/array-ctor-as-runtime-temp.f90 index e1e65fc48baba..727eff7613e48 100644 --- a/flang/test/Lower/HLFIR/array-ctor-as-runtime-temp.f90 +++ b/flang/test/Lower/HLFIR/array-ctor-as-runtime-temp.f90 @@ -17,12 +17,11 @@ subroutine test_loops() ! CHECK: fir.store %[[VAL_6]] to %[[VAL_2]] : !fir.ref>>> ! CHECK: %[[VAL_7:.*]] = arith.constant false ! CHECK: %[[VAL_8:.*]] = fir.convert %[[VAL_1]] : (!fir.ref>) -> !fir.llvm_ptr -! CHECK: %[[VAL_9:.*]] = arith.constant 80 : i32 ! CHECK: %[[VAL_10:.*]] = fir.address_of(@_QQclX{{.*}}) : !fir.ref> ! CHECK: %[[VAL_11:.*]] = arith.constant 7 : i32 ! CHECK: %[[VAL_12:.*]] = fir.convert %[[VAL_2]] : (!fir.ref>>>) -> !fir.ref> ! CHECK: %[[VAL_13:.*]] = fir.convert %[[VAL_10]] : (!fir.ref>) -> !fir.ref -! CHECK: %[[VAL_14:.*]] = fir.call @_FortranAInitArrayConstructorVector(%[[VAL_8]], %[[VAL_12]], %[[VAL_7]], %[[VAL_9]], %[[VAL_13]], %[[VAL_11]]) fastmath : (!fir.llvm_ptr, !fir.ref>, i1, i32, !fir.ref, i32) -> none +! CHECK: %[[VAL_14:.*]] = fir.call @_FortranAInitArrayConstructorVector(%[[VAL_8]], %[[VAL_12]], %[[VAL_7]], %[[VAL_13]], %[[VAL_11]]) fastmath : (!fir.llvm_ptr, !fir.ref>, i1, !fir.ref, i32) -> none ! CHECK: %[[VAL_15:.*]] = arith.constant 1 : i64 ! CHECK: %[[VAL_16:.*]] = fir.convert %[[VAL_15]] : (i64) -> index ! CHECK: %[[VAL_17:.*]] = fir.call @_QMarrayctorPibar() fastmath : () -> i32 @@ -86,7 +85,7 @@ subroutine test_arrays(a) ! CHECK: %[[VAL_26:.*]] = arith.constant false ! CHECK: %[[VAL_27:.*]] = fir.convert %[[VAL_1]] : (!fir.ref>) -> !fir.llvm_ptr ! CHECK: %[[VAL_31:.*]] = fir.convert %[[VAL_2]] : (!fir.ref>>>) -> !fir.ref> -! CHECK: %[[VAL_33:.*]] = fir.call @_FortranAInitArrayConstructorVector(%[[VAL_27]], %[[VAL_31]], %[[VAL_26]], %{{.*}}, %{{.*}}, %{{.*}}) {{.*}}: (!fir.llvm_ptr, !fir.ref>, i1, i32, !fir.ref, i32) -> none +! CHECK: %[[VAL_33:.*]] = fir.call @_FortranAInitArrayConstructorVector(%[[VAL_27]], %[[VAL_31]], %[[VAL_26]], %{{.*}}, %{{.*}}) {{.*}}: (!fir.llvm_ptr, !fir.ref>, i1, !fir.ref, i32) -> none ! CHECK: %[[VAL_34:.*]] = fir.convert %[[VAL_3]]#1 : (!fir.box>) -> !fir.box ! CHECK: %[[VAL_35:.*]] = fir.call @_FortranAPushArrayConstructorValue(%[[VAL_27]], %[[VAL_34]]) {{.*}}: (!fir.llvm_ptr, !fir.box) -> none ! CHECK: %[[VAL_36:.*]] = fir.convert %[[VAL_3]]#1 : (!fir.box>) -> !fir.box @@ -107,7 +106,7 @@ subroutine test_arrays_unpredictable_size() ! CHECK: %[[VAL_9:.*]] = arith.constant false ! CHECK: %[[VAL_10:.*]] = fir.convert %[[VAL_3]] : (!fir.ref>) -> !fir.llvm_ptr ! CHECK: %[[VAL_14:.*]] = fir.convert %[[VAL_4]] : (!fir.ref>>>) -> !fir.ref> -! CHECK: %[[VAL_16:.*]] = fir.call @_FortranAInitArrayConstructorVector(%[[VAL_10]], %[[VAL_14]], %[[VAL_9]], %{{.*}}, %{{.*}}, %{{.*}}) {{.*}}: (!fir.llvm_ptr, !fir.ref>, i1, i32, !fir.ref, i32) -> none +! CHECK: %[[VAL_16:.*]] = fir.call @_FortranAInitArrayConstructorVector(%[[VAL_10]], %[[VAL_14]], %[[VAL_9]], %{{.*}}, %{{.*}}) {{.*}}: (!fir.llvm_ptr, !fir.ref>, i1, !fir.ref, i32) -> none ! CHECK: fir.call @_QMarrayctorPrank1() {{.*}}: () -> !fir.box>> ! CHECK: %[[VAL_21:.*]] = fir.call @_FortranAPushArrayConstructorValue(%[[VAL_10]], %{{.*}}) {{.*}}: (!fir.llvm_ptr, !fir.box) -> none ! CHECK: fir.call @_QMarrayctorPrank3() {{.*}}: () -> !fir.box>> diff --git a/flang/test/Lower/HLFIR/array-ctor-character.f90 b/flang/test/Lower/HLFIR/array-ctor-character.f90 index 881085b370ffe..7cbad5218f588 100644 --- a/flang/test/Lower/HLFIR/array-ctor-character.f90 +++ b/flang/test/Lower/HLFIR/array-ctor-character.f90 @@ -52,7 +52,7 @@ subroutine test_dynamic_length() ! CHECK: %[[VAL_15:.*]] = arith.constant true ! CHECK: %[[VAL_16:.*]] = fir.convert %[[VAL_2]] : (!fir.ref>) -> !fir.llvm_ptr ! CHECK: %[[VAL_20:.*]] = fir.convert %[[VAL_3]] : (!fir.ref>>>>) -> !fir.ref> -! CHECK: %[[VAL_22:.*]] = fir.call @_FortranAInitArrayConstructorVector(%[[VAL_16]], %[[VAL_20]], %[[VAL_15]], %{{.*}}, %{{.*}}, %{{.*}}) {{.*}}: (!fir.llvm_ptr, !fir.ref>, i1, i32, !fir.ref, i32) -> none +! CHECK: %[[VAL_22:.*]] = fir.call @_FortranAInitArrayConstructorVector(%[[VAL_16]], %[[VAL_20]], %[[VAL_15]], %{{.*}}, %{{.*}}) {{.*}}: (!fir.llvm_ptr, !fir.ref>, i1, !fir.ref, i32) -> none ! CHECK: fir.call @_QMchararrayctorPchar_pointer( ! CHECK: fir.call @_FortranAPushArrayConstructorValue(%[[VAL_16]], %{{.*}}) {{.*}}: (!fir.llvm_ptr, !fir.box) -> none ! CHECK: fir.call @_QMchararrayctorPchar_pointer( diff --git a/flang/test/Lower/HLFIR/array-ctor-derived.f90 b/flang/test/Lower/HLFIR/array-ctor-derived.f90 index 111225462a4bb..22f7fbd72cb59 100644 --- a/flang/test/Lower/HLFIR/array-ctor-derived.f90 +++ b/flang/test/Lower/HLFIR/array-ctor-derived.f90 @@ -28,7 +28,7 @@ subroutine test_simple(s1, s2) ! CHECK: %[[VAL_11:.*]] = arith.constant false ! CHECK: %[[VAL_12:.*]] = fir.convert %[[VAL_2]] : (!fir.ref>) -> !fir.llvm_ptr ! CHECK: %[[VAL_16:.*]] = fir.convert %[[VAL_3]] : (!fir.ref>>>>) -> !fir.ref> -! CHECK: %[[VAL_18:.*]] = fir.call @_FortranAInitArrayConstructorVector(%[[VAL_12]], %[[VAL_16]], %[[VAL_11]], %{{.*}}, %{{.*}}, %{{.*}}) {{.*}}: (!fir.llvm_ptr, !fir.ref>, i1, i32, !fir.ref, i32) -> none +! CHECK: %[[VAL_18:.*]] = fir.call @_FortranAInitArrayConstructorVector(%[[VAL_12]], %[[VAL_16]], %[[VAL_11]], %{{.*}}, %{{.*}}) {{.*}}: (!fir.llvm_ptr, !fir.ref>, i1, !fir.ref, i32) -> none ! CHECK: %[[VAL_19:.*]] = fir.convert %[[VAL_4]]#1 : (!fir.ref>) -> !fir.llvm_ptr ! CHECK: %[[VAL_20:.*]] = fir.call @_FortranAPushArrayConstructorSimpleScalar(%[[VAL_12]], %[[VAL_19]]) {{.*}}: (!fir.llvm_ptr, !fir.llvm_ptr) -> none ! CHECK: %[[VAL_21:.*]] = fir.convert %[[VAL_5]]#1 : (!fir.ref>) -> !fir.llvm_ptr @@ -56,7 +56,7 @@ subroutine test_with_polymorphic(s1, s2) ! CHECK: %[[VAL_11:.*]] = arith.constant false ! CHECK: %[[VAL_12:.*]] = fir.convert %[[VAL_2]] : (!fir.ref>) -> !fir.llvm_ptr ! CHECK: %[[VAL_16:.*]] = fir.convert %[[VAL_3]] : (!fir.ref>>>>) -> !fir.ref> -! CHECK: %[[VAL_18:.*]] = fir.call @_FortranAInitArrayConstructorVector(%[[VAL_12]], %[[VAL_16]], %[[VAL_11]], %{{.*}}, %{{.*}}, %{{.*}}) {{.*}}: (!fir.llvm_ptr, !fir.ref>, i1, i32, !fir.ref, i32) -> none +! CHECK: %[[VAL_18:.*]] = fir.call @_FortranAInitArrayConstructorVector(%[[VAL_12]], %[[VAL_16]], %[[VAL_11]], %{{.*}}, %{{.*}}) {{.*}}: (!fir.llvm_ptr, !fir.ref>, i1, !fir.ref, i32) -> none ! CHECK: %[[VAL_19A:.*]] = fir.box_addr %[[VAL_4]]#1 : (!fir.class>) -> !fir.ref> ! CHECK: %[[VAL_19:.*]] = fir.convert %[[VAL_19A]] : (!fir.ref>) -> !fir.llvm_ptr ! CHECK: %[[VAL_20:.*]] = fir.call @_FortranAPushArrayConstructorSimpleScalar(%[[VAL_12]], %[[VAL_19]]) {{.*}}: (!fir.llvm_ptr, !fir.llvm_ptr) -> none diff --git a/flang/test/Lower/HLFIR/structure-constructor.f90 b/flang/test/Lower/HLFIR/structure-constructor.f90 index 41d08c14f5fa9..ed9ee5d0ac363 100644 --- a/flang/test/Lower/HLFIR/structure-constructor.f90 +++ b/flang/test/Lower/HLFIR/structure-constructor.f90 @@ -273,12 +273,11 @@ end subroutine test6 ! CHECK: fir.store %[[VAL_49]] to %[[VAL_4]] : !fir.ref}>>>>> ! CHECK: %[[VAL_50:.*]] = arith.constant false ! CHECK: %[[VAL_51:.*]] = fir.convert %[[VAL_3]] : (!fir.ref>) -> !fir.llvm_ptr -! CHECK: %[[VAL_52:.*]] = arith.constant 80 : i32 ! CHECK: %[[VAL_53:.*]] = fir.address_of(@_QQclX{{.*}}) : !fir.ref> ! CHECK: %[[VAL_54:.*]] = arith.constant {{[0-9]*}} : i32 ! CHECK: %[[VAL_55:.*]] = fir.convert %[[VAL_4]] : (!fir.ref}>>>>>) -> !fir.ref> ! CHECK: %[[VAL_56:.*]] = fir.convert %[[VAL_53]] : (!fir.ref>) -> !fir.ref -! CHECK: %[[VAL_57:.*]] = fir.call @_FortranAInitArrayConstructorVector(%[[VAL_51]], %[[VAL_55]], %[[VAL_50]], %[[VAL_52]], %[[VAL_56]], %[[VAL_54]]) fastmath : (!fir.llvm_ptr, !fir.ref>, i1, i32, !fir.ref, i32) -> none +! CHECK: %[[VAL_57:.*]] = fir.call @_FortranAInitArrayConstructorVector(%[[VAL_51]], %[[VAL_55]], %[[VAL_50]], %[[VAL_56]], %[[VAL_54]]) fastmath : (!fir.llvm_ptr, !fir.ref>, i1, !fir.ref, i32) -> none ! CHECK: %[[VAL_58:.*]]:2 = hlfir.declare %[[VAL_2]] {uniq_name = "ctor.temp"} : (!fir.ref}>>) -> (!fir.ref}>>, !fir.ref}>>) ! CHECK: %[[VAL_59:.*]] = fir.embox %[[VAL_58]]#0 : (!fir.ref}>>) -> !fir.box}>> ! CHECK: %[[VAL_60:.*]] = fir.address_of(@_QQclX{{.*}}) : !fir.ref> diff --git a/flang/unittests/Runtime/ArrayConstructor.cpp b/flang/unittests/Runtime/ArrayConstructor.cpp index 9d78da7962361..62e3b780a27e7 100644 --- a/flang/unittests/Runtime/ArrayConstructor.cpp +++ b/flang/unittests/Runtime/ArrayConstructor.cpp @@ -43,8 +43,7 @@ TEST(ArrayConstructor, Basic) { result.GetDimension(0).SetBounds(1, 0); RTNAME(InitArrayConstructorVector) - (*acVector, result, /*useValueLengthParameters=*/false, - /*vectorClassSize=*/sizeof(ArrayConstructorVector)); + (*acVector, result, /*useValueLengthParameters=*/false); for (std::int32_t i{0}; i <= 99; ++i) { RTNAME(PushArrayConstructorSimpleScalar)(*acVector, &i); RTNAME(PushArrayConstructorValue)(*acVector, *x); @@ -71,8 +70,7 @@ TEST(ArrayConstructor, Basic) { // and is allocated when the first value is pushed. result.GetDimension(0).SetBounds(1, 1234); RTNAME(InitArrayConstructorVector) - (*acVector, result, /*useValueLengthParameters=*/false, - /*vectorClassSize=*/sizeof(ArrayConstructorVector)); + (*acVector, result, /*useValueLengthParameters=*/false); EXPECT_EQ(0, acVector->actualAllocationSize); std::int32_t i{42}; RTNAME(PushArrayConstructorSimpleScalar)(*acVector, &i); @@ -109,8 +107,7 @@ TEST(ArrayConstructor, Character) { static constexpr std::size_t expectedElements{10 * (1 + 4 + 2 * 3)}; result.GetDimension(0).SetBounds(1, 0); RTNAME(InitArrayConstructorVector) - (*acVector, result, /*useValueLengthParameters=*/true, - /*vectorClassSize=*/sizeof(ArrayConstructorVector)); + (*acVector, result, /*useValueLengthParameters=*/true); for (std::int32_t i{1}; i <= 10; ++i) { RTNAME(PushArrayConstructorValue)(*acVector, *c); RTNAME(PushArrayConstructorValue)(*acVector, *x); @@ -151,8 +148,7 @@ TEST(ArrayConstructor, CharacterRuntimeCheck) { result.GetDimension(0).SetBounds(1, 0); RTNAME(InitArrayConstructorVector) - (*acVector, result, /*useValueLengthParameters=*/true, - /*vectorClassSize=*/sizeof(ArrayConstructorVector)); + (*acVector, result, /*useValueLengthParameters=*/true); RTNAME(PushArrayConstructorValue)(*acVector, *c2); ASSERT_DEATH(RTNAME(PushArrayConstructorValue)(*acVector, *c3), "Array constructor: mismatched character lengths"); From e4f9d08c82e98d3b2b887a4c2729c57d60b608c8 Mon Sep 17 00:00:00 2001 From: Michael Kruse Date: Fri, 15 Nov 2024 13:33:55 +0100 Subject: [PATCH 08/13] Post-merge fixes --- flang/include/flang/Runtime/CUDA/allocatable.h | 2 +- flang/include/flang/Runtime/CUDA/common.h | 2 +- flang/include/flang/Runtime/CUDA/memory.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/flang/include/flang/Runtime/CUDA/allocatable.h b/flang/include/flang/Runtime/CUDA/allocatable.h index e986ad910a3f3..cc762e1e6c0c7 100644 --- a/flang/include/flang/Runtime/CUDA/allocatable.h +++ b/flang/include/flang/Runtime/CUDA/allocatable.h @@ -9,7 +9,7 @@ #ifndef FORTRAN_RUNTIME_CUDA_ALLOCATABLE_H_ #define FORTRAN_RUNTIME_CUDA_ALLOCATABLE_H_ -#include "flang/Runtime/descriptor.h" +#include "flang/Runtime/descriptor-consts.h" #include "flang/Runtime/entry-names.h" namespace Fortran::runtime::cuda { diff --git a/flang/include/flang/Runtime/CUDA/common.h b/flang/include/flang/Runtime/CUDA/common.h index cb8681da161f0..c0d50f27edf1f 100644 --- a/flang/include/flang/Runtime/CUDA/common.h +++ b/flang/include/flang/Runtime/CUDA/common.h @@ -9,7 +9,7 @@ #ifndef FORTRAN_RUNTIME_CUDA_COMMON_H_ #define FORTRAN_RUNTIME_CUDA_COMMON_H_ -#include "flang/Runtime/descriptor.h" +#include "flang/Runtime/descriptor-consts.h" #include "flang/Runtime/entry-names.h" static constexpr unsigned kHostToDevice = 0; diff --git a/flang/include/flang/Runtime/CUDA/memory.h b/flang/include/flang/Runtime/CUDA/memory.h index 33947248dc483..39651b96fcccb 100644 --- a/flang/include/flang/Runtime/CUDA/memory.h +++ b/flang/include/flang/Runtime/CUDA/memory.h @@ -9,7 +9,7 @@ #ifndef FORTRAN_RUNTIME_CUDA_MEMORY_H_ #define FORTRAN_RUNTIME_CUDA_MEMORY_H_ -#include "flang/Runtime/descriptor.h" +#include "flang/Runtime/descriptor-consts.h" #include "flang/Runtime/entry-names.h" #include From c9b1c294dc55296da9fcea929b2ddadfe0091c53 Mon Sep 17 00:00:00 2001 From: Michael Kruse Date: Thu, 5 Dec 2024 13:25:52 +0100 Subject: [PATCH 09/13] io-api.h -> io-api-consts.h --- .../include/flang/Runtime/{io-api.h => io-api-consts.h} | 9 +++++---- flang/include/flang/Runtime/io-api-funcs.h | 2 +- flang/lib/Lower/IO.cpp | 2 +- flang/unittests/Runtime/ExternalIOTest.cpp | 2 +- flang/unittests/Runtime/ListInputTest.cpp | 2 +- flang/unittests/Runtime/LogicalFormatTest.cpp | 2 +- flang/unittests/Runtime/Namelist.cpp | 2 +- flang/unittests/Runtime/NumericalFormatTest.cpp | 2 +- flang/unittests/Runtime/RuntimeCrashTest.cpp | 2 +- 9 files changed, 13 insertions(+), 12 deletions(-) rename flang/include/flang/Runtime/{io-api.h => io-api-consts.h} (98%) diff --git a/flang/include/flang/Runtime/io-api.h b/flang/include/flang/Runtime/io-api-consts.h similarity index 98% rename from flang/include/flang/Runtime/io-api.h rename to flang/include/flang/Runtime/io-api-consts.h index e588b46dc4b3a..e620440914253 100644 --- a/flang/include/flang/Runtime/io-api.h +++ b/flang/include/flang/Runtime/io-api-consts.h @@ -1,4 +1,4 @@ -//===-- include/flang/Runtime/io-api.h --------------------------*- C++ -*-===// +//===-- include/flang/Runtime/io-api-consts.h -------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -8,8 +8,8 @@ // Defines API between compiled code and I/O runtime library. -#ifndef FORTRAN_RUNTIME_IO_API_H_ -#define FORTRAN_RUNTIME_IO_API_H_ +#ifndef FORTRAN_RUNTIME_IO_API_CONSTS_H_ +#define FORTRAN_RUNTIME_IO_API_CONSTS_H_ #include "flang/Common/uint128.h" #include "flang/Runtime/entry-names.h" @@ -366,4 +366,5 @@ enum Iostat IODECL(EndIoStatement)(Cookie); } // extern "C" } // namespace Fortran::runtime::io -#endif + +#endif /* FORTRAN_RUNTIME_IO_API_CONSTS_H_ */ diff --git a/flang/include/flang/Runtime/io-api-funcs.h b/flang/include/flang/Runtime/io-api-funcs.h index 1f55b5c795d61..c45b8e3417d66 100644 --- a/flang/include/flang/Runtime/io-api-funcs.h +++ b/flang/include/flang/Runtime/io-api-funcs.h @@ -13,7 +13,7 @@ #include "flang/Common/uint128.h" #include "flang/Runtime/entry-names.h" -#include "flang/Runtime/io-api.h" +#include "flang/Runtime/io-api-consts.h" #include "flang/Runtime/iostat.h" #include "flang/Runtime/magic-numbers.h" #include diff --git a/flang/lib/Lower/IO.cpp b/flang/lib/Lower/IO.cpp index 1894b0cfd1bec..6a918d844c12e 100644 --- a/flang/lib/Lower/IO.cpp +++ b/flang/lib/Lower/IO.cpp @@ -33,7 +33,7 @@ #include "flang/Optimizer/Dialect/FIRDialect.h" #include "flang/Optimizer/Dialect/Support/FIRContext.h" #include "flang/Parser/parse-tree.h" -#include "flang/Runtime/io-api.h" +#include "flang/Runtime/io-api-consts.h" #include "flang/Semantics/runtime-type-info.h" #include "flang/Semantics/tools.h" #include "mlir/Dialect/ControlFlow/IR/ControlFlowOps.h" diff --git a/flang/unittests/Runtime/ExternalIOTest.cpp b/flang/unittests/Runtime/ExternalIOTest.cpp index 13327964e12a4..b9407b5e7a591 100644 --- a/flang/unittests/Runtime/ExternalIOTest.cpp +++ b/flang/unittests/Runtime/ExternalIOTest.cpp @@ -13,7 +13,7 @@ #include "CrashHandlerFixture.h" #include "gtest/gtest.h" #include "flang/Runtime/descriptor.h" -#include "flang/Runtime/io-api.h" +#include "flang/Runtime/io-api-consts.h" #include "flang/Runtime/main.h" #include "flang/Runtime/stop.h" #include "llvm/Support/raw_ostream.h" diff --git a/flang/unittests/Runtime/ListInputTest.cpp b/flang/unittests/Runtime/ListInputTest.cpp index a4eba5283add6..38c758b7ef966 100644 --- a/flang/unittests/Runtime/ListInputTest.cpp +++ b/flang/unittests/Runtime/ListInputTest.cpp @@ -9,7 +9,7 @@ #include "CrashHandlerFixture.h" #include "../../runtime/io-error.h" #include "flang/Runtime/descriptor.h" -#include "flang/Runtime/io-api.h" +#include "flang/Runtime/io-api-consts.h" using namespace Fortran::runtime; using namespace Fortran::runtime::io; diff --git a/flang/unittests/Runtime/LogicalFormatTest.cpp b/flang/unittests/Runtime/LogicalFormatTest.cpp index a2c19d1e1ca94..c4fbfc81f06a4 100644 --- a/flang/unittests/Runtime/LogicalFormatTest.cpp +++ b/flang/unittests/Runtime/LogicalFormatTest.cpp @@ -8,7 +8,7 @@ #include "CrashHandlerFixture.h" #include "flang/Runtime/descriptor.h" -#include "flang/Runtime/io-api.h" +#include "flang/Runtime/io-api-consts.h" #include #include #include diff --git a/flang/unittests/Runtime/Namelist.cpp b/flang/unittests/Runtime/Namelist.cpp index 9037fa15a97cb..0a28f3590b86e 100644 --- a/flang/unittests/Runtime/Namelist.cpp +++ b/flang/unittests/Runtime/Namelist.cpp @@ -10,7 +10,7 @@ #include "CrashHandlerFixture.h" #include "tools.h" #include "flang/Runtime/descriptor.h" -#include "flang/Runtime/io-api.h" +#include "flang/Runtime/io-api-consts.h" #include #include #include diff --git a/flang/unittests/Runtime/NumericalFormatTest.cpp b/flang/unittests/Runtime/NumericalFormatTest.cpp index f005515320350..274498b8e8695 100644 --- a/flang/unittests/Runtime/NumericalFormatTest.cpp +++ b/flang/unittests/Runtime/NumericalFormatTest.cpp @@ -8,7 +8,7 @@ #include "CrashHandlerFixture.h" #include "flang/Runtime/descriptor.h" -#include "flang/Runtime/io-api.h" +#include "flang/Runtime/io-api-consts.h" #include #include #include diff --git a/flang/unittests/Runtime/RuntimeCrashTest.cpp b/flang/unittests/Runtime/RuntimeCrashTest.cpp index a649051fdca0c..72a0b290cf864 100644 --- a/flang/unittests/Runtime/RuntimeCrashTest.cpp +++ b/flang/unittests/Runtime/RuntimeCrashTest.cpp @@ -13,7 +13,7 @@ #include "CrashHandlerFixture.h" #include "tools.h" #include "../../runtime/terminator.h" -#include "flang/Runtime/io-api.h" +#include "flang/Runtime/io-api-consts.h" #include "flang/Runtime/transformational.h" #include From bd392d22ef084d32c5b82af1010d3a4591bda0f0 Mon Sep 17 00:00:00 2001 From: Michael Kruse Date: Thu, 5 Dec 2024 13:31:17 +0100 Subject: [PATCH 10/13] io-api-funcs.h -> io-api.h --- flang/include/flang/Runtime/{io-api-funcs.h => io-api.h} | 6 +++--- flang/runtime/extensions.cpp | 2 +- flang/runtime/io-api-common.h | 2 +- flang/runtime/io-api-minimal.cpp | 2 +- flang/runtime/io-api.cpp | 2 +- flang/runtime/io-stmt.h | 2 +- flang/runtime/namelist.cpp | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) rename flang/include/flang/Runtime/{io-api-funcs.h => io-api.h} (89%) diff --git a/flang/include/flang/Runtime/io-api-funcs.h b/flang/include/flang/Runtime/io-api.h similarity index 89% rename from flang/include/flang/Runtime/io-api-funcs.h rename to flang/include/flang/Runtime/io-api.h index c45b8e3417d66..e5dcbfa981ad0 100644 --- a/flang/include/flang/Runtime/io-api-funcs.h +++ b/flang/include/flang/Runtime/io-api.h @@ -8,8 +8,8 @@ // Defines API between compiled code and I/O runtime library. -#ifndef FORTRAN_RUNTIME_IO_API_FUNCS_H_ -#define FORTRAN_RUNTIME_IO_API_FUNCS_H_ +#ifndef FORTRAN_RUNTIME_IO_API_H_ +#define FORTRAN_RUNTIME_IO_API_H_ #include "flang/Common/uint128.h" #include "flang/Runtime/entry-names.h" @@ -37,4 +37,4 @@ RT_API_ATTRS const char *InquiryKeywordHashDecode( } // namespace Fortran::runtime::io -#endif /* FORTRAN_RUNTIME_IO_API_FUNCS_H_ */ +#endif /* FORTRAN_RUNTIME_IO_API_H_ */ diff --git a/flang/runtime/extensions.cpp b/flang/runtime/extensions.cpp index 6b4acccce2c19..50d3c72fe650d 100644 --- a/flang/runtime/extensions.cpp +++ b/flang/runtime/extensions.cpp @@ -15,7 +15,7 @@ #include "flang/Runtime/command.h" #include "flang/Runtime/descriptor.h" #include "flang/Runtime/entry-names.h" -#include "flang/Runtime/io-api-funcs.h" +#include "flang/Runtime/io-api.h" #include #include #include diff --git a/flang/runtime/io-api-common.h b/flang/runtime/io-api-common.h index b4ac9a61c09ec..c7b86cab73a52 100644 --- a/flang/runtime/io-api-common.h +++ b/flang/runtime/io-api-common.h @@ -14,7 +14,7 @@ #include "unit.h" #include "flang/Common/api-attrs.h" #include "flang/Common/optional.h" -#include "flang/Runtime/io-api-funcs.h" +#include "flang/Runtime/io-api.h" namespace Fortran::runtime::io { diff --git a/flang/runtime/io-api-minimal.cpp b/flang/runtime/io-api-minimal.cpp index 82376cf964166..ad76fe3de0324 100644 --- a/flang/runtime/io-api-minimal.cpp +++ b/flang/runtime/io-api-minimal.cpp @@ -16,7 +16,7 @@ #include "terminator.h" #include "tools.h" #include "unit.h" -#include "flang/Runtime/io-api-funcs.h" +#include "flang/Runtime/io-api.h" namespace Fortran::runtime::io { RT_EXT_API_GROUP_BEGIN diff --git a/flang/runtime/io-api.cpp b/flang/runtime/io-api.cpp index 84ca3dded87a3..39ac8c9eb6def 100644 --- a/flang/runtime/io-api.cpp +++ b/flang/runtime/io-api.cpp @@ -13,6 +13,7 @@ // OutputReal{32,64}, OutputComplex{32,64}, OutputAscii, & EndIoStatement() // are in runtime/io-api-minimal.cpp. +#include "flang/Runtime/io-api.h" #include "descriptor-io.h" #include "edit-input.h" #include "edit-output.h" @@ -25,7 +26,6 @@ #include "unit.h" #include "flang/Common/optional.h" #include "flang/Runtime/descriptor.h" -#include "flang/Runtime/io-api-funcs.h" #include "flang/Runtime/memory.h" #include #include diff --git a/flang/runtime/io-stmt.h b/flang/runtime/io-stmt.h index 9ce7295dac3c0..1f1419b249e5e 100644 --- a/flang/runtime/io-stmt.h +++ b/flang/runtime/io-stmt.h @@ -20,7 +20,7 @@ #include "flang/Common/reference-wrapper.h" #include "flang/Common/visit.h" #include "flang/Runtime/descriptor.h" -#include "flang/Runtime/io-api-funcs.h" +#include "flang/Runtime/io-api.h" #include #include #include diff --git a/flang/runtime/namelist.cpp b/flang/runtime/namelist.cpp index cfed7f2c6bf97..af092de70f781 100644 --- a/flang/runtime/namelist.cpp +++ b/flang/runtime/namelist.cpp @@ -10,7 +10,7 @@ #include "descriptor-io.h" #include "emit-encoded.h" #include "io-stmt.h" -#include "flang/Runtime/io-api-funcs.h" +#include "flang/Runtime/io-api.h" #include #include #include From c4faf0574a3cb4ec3ade2fa9b7e78125217b23d1 Mon Sep 17 00:00:00 2001 From: Michael Kruse Date: Thu, 5 Dec 2024 13:59:22 +0100 Subject: [PATCH 11/13] iostat.h -> iostat-consts.h --- flang/include/flang/Optimizer/Builder/IntrinsicCall.h | 2 +- flang/include/flang/Runtime/array-constructor.h | 1 + flang/include/flang/Runtime/io-api-consts.h | 2 +- flang/include/flang/Runtime/io-api.h | 7 +++---- .../flang/Runtime/{iostat.h => iostat-consts.h} | 11 +++++++---- flang/include/flang/Runtime/iostat-funcs.h | 2 +- flang/lib/Lower/Bridge.cpp | 2 +- flang/lib/Optimizer/Builder/IntrinsicCall.cpp | 2 +- 8 files changed, 16 insertions(+), 13 deletions(-) rename flang/include/flang/Runtime/{iostat.h => iostat-consts.h} (94%) diff --git a/flang/include/flang/Optimizer/Builder/IntrinsicCall.h b/flang/include/flang/Optimizer/Builder/IntrinsicCall.h index e7955c2fc0314..bc0020e614db2 100644 --- a/flang/include/flang/Optimizer/Builder/IntrinsicCall.h +++ b/flang/include/flang/Optimizer/Builder/IntrinsicCall.h @@ -16,7 +16,7 @@ #include "flang/Optimizer/Builder/Runtime/Numeric.h" #include "flang/Optimizer/Builder/Runtime/RTBuilder.h" #include "flang/Runtime/entry-names.h" -#include "flang/Runtime/iostat.h" +#include "flang/Runtime/iostat-consts.h" #include "mlir/Dialect/Complex/IR/Complex.h" #include "mlir/Dialect/LLVMIR/LLVMDialect.h" #include "mlir/Dialect/Math/IR/Math.h" diff --git a/flang/include/flang/Runtime/array-constructor.h b/flang/include/flang/Runtime/array-constructor.h index c068af9ba120c..2f6aaae17c650 100644 --- a/flang/include/flang/Runtime/array-constructor.h +++ b/flang/include/flang/Runtime/array-constructor.h @@ -43,6 +43,7 @@ struct ArrayConstructorVector { private: unsigned char useValueLengthParameters_ : 1; }; + static_assert(sizeof(Fortran::runtime::ArrayConstructorVector) <= MaxArrayConstructorVectorSizeInBytes, "ABI requires sizeof(ArrayConstructorVector) to be smaller than " diff --git a/flang/include/flang/Runtime/io-api-consts.h b/flang/include/flang/Runtime/io-api-consts.h index e620440914253..a57de12724980 100644 --- a/flang/include/flang/Runtime/io-api-consts.h +++ b/flang/include/flang/Runtime/io-api-consts.h @@ -13,7 +13,7 @@ #include "flang/Common/uint128.h" #include "flang/Runtime/entry-names.h" -#include "flang/Runtime/iostat.h" +#include "flang/Runtime/iostat-consts.h" #include "flang/Runtime/magic-numbers.h" #include #include diff --git a/flang/include/flang/Runtime/io-api.h b/flang/include/flang/Runtime/io-api.h index e5dcbfa981ad0..b86c3cecb32c5 100644 --- a/flang/include/flang/Runtime/io-api.h +++ b/flang/include/flang/Runtime/io-api.h @@ -1,4 +1,4 @@ -//===-- include/flang/Runtime/io-api-funcs.h --------------------*- C++ -*-===// +//===-- include/flang/Runtime/io-api.h --------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -14,7 +14,7 @@ #include "flang/Common/uint128.h" #include "flang/Runtime/entry-names.h" #include "flang/Runtime/io-api-consts.h" -#include "flang/Runtime/iostat.h" +#include "flang/Runtime/iostat-consts.h" #include "flang/Runtime/magic-numbers.h" #include #include @@ -36,5 +36,4 @@ RT_API_ATTRS const char *InquiryKeywordHashDecode( char *buffer, std::size_t, InquiryKeywordHash); } // namespace Fortran::runtime::io - -#endif /* FORTRAN_RUNTIME_IO_API_H_ */ +#endif diff --git a/flang/include/flang/Runtime/iostat.h b/flang/include/flang/Runtime/iostat-consts.h similarity index 94% rename from flang/include/flang/Runtime/iostat.h rename to flang/include/flang/Runtime/iostat-consts.h index 0565718f6c103..0010154603145 100644 --- a/flang/include/flang/Runtime/iostat.h +++ b/flang/include/flang/Runtime/iostat-consts.h @@ -1,4 +1,4 @@ -//===-- include/flang/Runtime/iostat.h --------------------------*- C++ -*-===// +//===-- include/flang/Runtime/iostat-consts.h -------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -9,10 +9,12 @@ // Defines the values returned by the runtime for IOSTAT= specifiers // on I/O statements. -#ifndef FORTRAN_RUNTIME_IOSTAT_H_ -#define FORTRAN_RUNTIME_IOSTAT_H_ +#ifndef FORTRAN_RUNTIME_IOSTAT_CONSTS_H_ +#define FORTRAN_RUNTIME_IOSTAT_CONSTS_H_ + #include "flang/Common/api-attrs.h" #include "flang/Runtime/magic-numbers.h" + namespace Fortran::runtime::io { // The value of IOSTAT= is zero when no error, end-of-record, @@ -90,4 +92,5 @@ enum Iostat { }; } // namespace Fortran::runtime::io -#endif // FORTRAN_RUNTIME_IOSTAT_H_ + +#endif // FORTRAN_RUNTIME_IOSTAT_CONSTS_H_ diff --git a/flang/include/flang/Runtime/iostat-funcs.h b/flang/include/flang/Runtime/iostat-funcs.h index 96eef2b6411f4..3eab4a44f02c7 100644 --- a/flang/include/flang/Runtime/iostat-funcs.h +++ b/flang/include/flang/Runtime/iostat-funcs.h @@ -13,7 +13,7 @@ #define FORTRAN_RUNTIME_IOSTAT_FUNCS_H_ #include "flang/Common/api-attrs.h" -#include "flang/Runtime/iostat.h" +#include "flang/Runtime/iostat-consts.h" namespace Fortran::runtime::io { diff --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp index f518599125e89..d89dea5c93bbe 100644 --- a/flang/lib/Lower/Bridge.cpp +++ b/flang/lib/Lower/Bridge.cpp @@ -56,7 +56,7 @@ #include "flang/Optimizer/Support/InternalNames.h" #include "flang/Optimizer/Transforms/Passes.h" #include "flang/Parser/parse-tree.h" -#include "flang/Runtime/iostat.h" +#include "flang/Runtime/iostat-consts.h" #include "flang/Semantics/runtime-type-info.h" #include "flang/Semantics/symbol.h" #include "flang/Semantics/tools.h" diff --git a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp index 2758da48bceca..547cebefd2df4 100644 --- a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp +++ b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp @@ -41,7 +41,7 @@ #include "flang/Optimizer/Support/FatalError.h" #include "flang/Optimizer/Support/Utils.h" #include "flang/Runtime/entry-names.h" -#include "flang/Runtime/iostat.h" +#include "flang/Runtime/iostat-consts.h" #include "mlir/Dialect/Complex/IR/Complex.h" #include "mlir/Dialect/LLVMIR/LLVMDialect.h" #include "mlir/Dialect/Math/IR/Math.h" From 64bade38fd6a3e5c8c081bae92ce02f58cab799f Mon Sep 17 00:00:00 2001 From: Michael Kruse Date: Thu, 5 Dec 2024 14:02:45 +0100 Subject: [PATCH 12/13] iostat-funcs.h -> iostat.h --- flang/include/flang/Runtime/{iostat-funcs.h => iostat.h} | 8 ++++---- flang/runtime/io-error.h | 2 +- flang/runtime/iostat.cpp | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) rename flang/include/flang/Runtime/{iostat-funcs.h => iostat.h} (75%) diff --git a/flang/include/flang/Runtime/iostat-funcs.h b/flang/include/flang/Runtime/iostat.h similarity index 75% rename from flang/include/flang/Runtime/iostat-funcs.h rename to flang/include/flang/Runtime/iostat.h index 3eab4a44f02c7..a3ccd975564ff 100644 --- a/flang/include/flang/Runtime/iostat-funcs.h +++ b/flang/include/flang/Runtime/iostat.h @@ -1,4 +1,4 @@ -//===-- include/flang/Runtime/iostat-funcs.h --------------------*- C++ -*-===// +//===-- include/flang/Runtime/iostat.h --------------------------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -9,8 +9,8 @@ // Defines the values returned by the runtime for IOSTAT= specifiers // on I/O statements. -#ifndef FORTRAN_RUNTIME_IOSTAT_FUNCS_H_ -#define FORTRAN_RUNTIME_IOSTAT_FUNCS_H_ +#ifndef FORTRAN_RUNTIME_IOSTAT_H_ +#define FORTRAN_RUNTIME_IOSTAT_H_ #include "flang/Common/api-attrs.h" #include "flang/Runtime/iostat-consts.h" @@ -21,4 +21,4 @@ RT_API_ATTRS const char *IostatErrorString(int); } // namespace Fortran::runtime::io -#endif /* FORTRAN_RUNTIME_IOSTAT_FUNCS_H_ */ +#endif /* FORTRAN_RUNTIME_IOSTAT_H_ */ diff --git a/flang/runtime/io-error.h b/flang/runtime/io-error.h index 22e43db710288..426573e2faf00 100644 --- a/flang/runtime/io-error.h +++ b/flang/runtime/io-error.h @@ -16,7 +16,7 @@ #define FORTRAN_RUNTIME_IO_ERROR_H_ #include "terminator.h" -#include "flang/Runtime/iostat-funcs.h" +#include "flang/Runtime/iostat.h" #include "flang/Runtime/memory.h" #include diff --git a/flang/runtime/iostat.cpp b/flang/runtime/iostat.cpp index 0d71eb09e0a50..39e224cb01286 100644 --- a/flang/runtime/iostat.cpp +++ b/flang/runtime/iostat.cpp @@ -6,7 +6,7 @@ // //===----------------------------------------------------------------------===// -#include "flang/Runtime/iostat-funcs.h" +#include "flang/Runtime/iostat.h" namespace Fortran::runtime::io { RT_OFFLOAD_API_GROUP_BEGIN From eda72ac037db0ab20dbf839c80498caab117b4f3 Mon Sep 17 00:00:00 2001 From: Michael Kruse Date: Thu, 5 Dec 2024 14:08:37 +0100 Subject: [PATCH 13/13] formatting --- flang/include/flang/Runtime/array-constructor-consts.h | 3 --- flang/include/flang/Runtime/io-api-consts.h | 2 -- flang/include/flang/Runtime/iostat-consts.h | 3 --- flang/include/flang/Runtime/iostat.h | 3 +-- 4 files changed, 1 insertion(+), 10 deletions(-) diff --git a/flang/include/flang/Runtime/array-constructor-consts.h b/flang/include/flang/Runtime/array-constructor-consts.h index f7460e9318ef2..ad3583eef29aa 100644 --- a/flang/include/flang/Runtime/array-constructor-consts.h +++ b/flang/include/flang/Runtime/array-constructor-consts.h @@ -6,9 +6,6 @@ // //===----------------------------------------------------------------------===// -// External APIs to create temporary storage for array constructors when their -// final extents or length parameters cannot be pre-computed. - #ifndef FORTRAN_RUNTIME_ARRAY_CONSTRUCTOR_CONSTS_H_ #define FORTRAN_RUNTIME_ARRAY_CONSTRUCTOR_CONSTS_H_ diff --git a/flang/include/flang/Runtime/io-api-consts.h b/flang/include/flang/Runtime/io-api-consts.h index a57de12724980..7ed8bf1489b3c 100644 --- a/flang/include/flang/Runtime/io-api-consts.h +++ b/flang/include/flang/Runtime/io-api-consts.h @@ -6,8 +6,6 @@ // //===----------------------------------------------------------------------===// -// Defines API between compiled code and I/O runtime library. - #ifndef FORTRAN_RUNTIME_IO_API_CONSTS_H_ #define FORTRAN_RUNTIME_IO_API_CONSTS_H_ diff --git a/flang/include/flang/Runtime/iostat-consts.h b/flang/include/flang/Runtime/iostat-consts.h index 0010154603145..26bf75f59fa0d 100644 --- a/flang/include/flang/Runtime/iostat-consts.h +++ b/flang/include/flang/Runtime/iostat-consts.h @@ -6,9 +6,6 @@ // //===----------------------------------------------------------------------===// -// Defines the values returned by the runtime for IOSTAT= specifiers -// on I/O statements. - #ifndef FORTRAN_RUNTIME_IOSTAT_CONSTS_H_ #define FORTRAN_RUNTIME_IOSTAT_CONSTS_H_ diff --git a/flang/include/flang/Runtime/iostat.h b/flang/include/flang/Runtime/iostat.h index a3ccd975564ff..d8db68a3a1c2e 100644 --- a/flang/include/flang/Runtime/iostat.h +++ b/flang/include/flang/Runtime/iostat.h @@ -20,5 +20,4 @@ namespace Fortran::runtime::io { RT_API_ATTRS const char *IostatErrorString(int); } // namespace Fortran::runtime::io - -#endif /* FORTRAN_RUNTIME_IOSTAT_H_ */ +#endif // FORTRAN_RUNTIME_IOSTAT_H_