Skip to content

Commit 42e5abb

Browse files
committed
Split headers in preparation for cross-compilation. NFC.
1 parent 98c71d8 commit 42e5abb

30 files changed

+254
-127
lines changed

flang/include/flang/Lower/Allocatable.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
#include "flang/Lower/AbstractConverter.h"
1717
#include "flang/Optimizer/Builder/MutableBox.h"
18-
#include "flang/Runtime/allocator-registry.h"
18+
#include "flang/Runtime/allocator-registry-consts.h"
1919
#include "llvm/ADT/StringRef.h"
2020

2121
namespace mlir {

flang/include/flang/Optimizer/Builder/MutableBox.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#define FORTRAN_OPTIMIZER_BUILDER_MUTABLEBOX_H
1515

1616
#include "flang/Optimizer/Builder/BoxValue.h"
17-
#include "flang/Runtime/allocator-registry.h"
17+
#include "flang/Runtime/allocator-registry-consts.h"
1818
#include "llvm/ADT/StringRef.h"
1919

2020
namespace mlir {

flang/include/flang/Optimizer/CodeGen/DescriptorModel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#define OPTIMIZER_DESCRIPTOR_MODEL_H
2424

2525
#include "flang/ISO_Fortran_binding_wrapper.h"
26-
#include "flang/Runtime/descriptor.h"
26+
#include "flang/Runtime/descriptor-consts.h"
2727
#include "mlir/Dialect/LLVMIR/LLVMTypes.h"
2828
#include "mlir/IR/BuiltinTypes.h"
2929
#include "llvm/Support/ErrorHandling.h"

flang/include/flang/Runtime/CUDA/allocator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#ifndef FORTRAN_RUNTIME_CUDA_ALLOCATOR_H_
1010
#define FORTRAN_RUNTIME_CUDA_ALLOCATOR_H_
1111

12-
#include "flang/Runtime/descriptor.h"
12+
#include "flang/Runtime/descriptor-consts.h"
1313
#include "flang/Runtime/entry-names.h"
1414

1515
#define CUDA_REPORT_IF_ERROR(expr) \

flang/include/flang/Runtime/CUDA/descriptor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#ifndef FORTRAN_RUNTIME_CUDA_DESCRIPTOR_H_
1010
#define FORTRAN_RUNTIME_CUDA_DESCRIPTOR_H_
1111

12-
#include "flang/Runtime/descriptor.h"
12+
#include "flang/Runtime/descriptor-consts.h"
1313
#include "flang/Runtime/entry-names.h"
1414
#include <cstddef>
1515

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//===-- include/flang/Runtime/allocator-registry-consts.h -------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef FORTRAN_RUNTIME_ALLOCATOR_REGISTRY_CONSTS_H_
10+
#define FORTRAN_RUNTIME_ALLOCATOR_REGISTRY_CONSTS_H_
11+
12+
static constexpr unsigned kDefaultAllocator = 0;
13+
14+
// Allocator used for CUF
15+
static constexpr unsigned kPinnedAllocatorPos = 1;
16+
static constexpr unsigned kDeviceAllocatorPos = 2;
17+
static constexpr unsigned kManagedAllocatorPos = 3;
18+
static constexpr unsigned kUnifiedAllocatorPos = 4;
19+
20+
#endif /* FORTRAN_RUNTIME_ALLOCATOR_REGISTRY_CONSTS_H_ */

flang/include/flang/Runtime/allocator-registry.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,10 @@
1010
#define FORTRAN_RUNTIME_ALLOCATOR_H_
1111

1212
#include "flang/Common/api-attrs.h"
13+
#include "flang/Runtime/allocator-registry-consts.h"
1314
#include <cstdlib>
1415
#include <vector>
1516

16-
static constexpr unsigned kDefaultAllocator = 0;
17-
18-
// Allocator used for CUF
19-
static constexpr unsigned kPinnedAllocatorPos = 1;
20-
static constexpr unsigned kDeviceAllocatorPos = 2;
21-
static constexpr unsigned kManagedAllocatorPos = 3;
22-
static constexpr unsigned kUnifiedAllocatorPos = 4;
23-
2417
#define MAX_ALLOCATOR 7 // 3 bits are reserved in the descriptor.
2518

2619
namespace Fortran::runtime {
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//===-- include/flang/Runtime/array-constructor-consts.h --------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// External APIs to create temporary storage for array constructors when their
10+
// final extents or length parameters cannot be pre-computed.
11+
12+
#ifndef FORTRAN_RUNTIME_ARRAY_CONSTRUCTOR_CONSTS_H_
13+
#define FORTRAN_RUNTIME_ARRAY_CONSTRUCTOR_CONSTS_H_
14+
15+
#include "flang/Runtime/descriptor-consts.h"
16+
#include "flang/Runtime/entry-names.h"
17+
#include <cstdint>
18+
19+
namespace Fortran::runtime {
20+
struct ArrayConstructorVector;
21+
22+
// Max sizeof(ArrayConstructorVector) and sizeof(ArrayConstructorVector) for any
23+
// target.
24+
// TODO: Use target-specific size/alignment instead of overapproximation.
25+
constexpr std::size_t MaxArrayConstructorVectorSizeInBytes = 2 * 40;
26+
constexpr std::size_t MaxArrayConstructorVectorAlignInBytes = 8;
27+
28+
extern "C" {
29+
// API to initialize an ArrayConstructorVector before any values are pushed to
30+
// it. Inlined code is only expected to allocate the "ArrayConstructorVector"
31+
// class instance storage with sufficient size (using
32+
// "2*sizeof(ArrayConstructorVector)" on the host should be safe regardless of
33+
// the target the runtime is compiled for). This avoids the need for the runtime
34+
// to maintain a state, or to use dynamic allocation for it. "vectorClassSize"
35+
// is used to validate that lowering allocated enough space for it.
36+
void RTDECL(InitArrayConstructorVector)(ArrayConstructorVector &vector,
37+
Descriptor &to, bool useValueLengthParameters, int vectorClassSize,
38+
const char *sourceFile = nullptr, int sourceLine = 0);
39+
40+
// Generic API to push any kind of entity into the array constructor (any
41+
// Fortran type and any rank).
42+
void RTDECL(PushArrayConstructorValue)(
43+
ArrayConstructorVector &vector, const Descriptor &from);
44+
45+
// API to push scalar array constructor value of:
46+
// - a numerical or logical type,
47+
// - or a derived type that has no length parameters, and no allocatable
48+
// component (that would require deep copies).
49+
// It requires no descriptor for the value that is passed via its base address.
50+
void RTDECL(PushArrayConstructorSimpleScalar)(
51+
ArrayConstructorVector &vector, void *from);
52+
} // extern "C"
53+
} // namespace Fortran::runtime
54+
#endif /* FORTRAN_RUNTIME_ARRAY_CONSTRUCTOR_CONSTS_H_ */

flang/include/flang/Runtime/array-constructor.h

Lines changed: 9 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#ifndef FORTRAN_RUNTIME_ARRAYCONSTRUCTOR_H_
1313
#define FORTRAN_RUNTIME_ARRAYCONSTRUCTOR_H_
1414

15+
#include "flang/Runtime/array-constructor-consts.h"
1516
#include "flang/Runtime/descriptor.h"
1617
#include "flang/Runtime/entry-names.h"
1718
#include <cstdint>
@@ -42,77 +43,14 @@ struct ArrayConstructorVector {
4243
private:
4344
unsigned char useValueLengthParameters_ : 1;
4445
};
46+
static_assert(sizeof(Fortran::runtime::ArrayConstructorVector) <=
47+
MaxArrayConstructorVectorSizeInBytes,
48+
"ABI requires sizeof(ArrayConstructorVector) to be smaller than "
49+
"MaxArrayConstructorVectorSizeInBytes");
50+
static_assert(alignof(Fortran::runtime::ArrayConstructorVector) <=
51+
MaxArrayConstructorVectorAlignInBytes,
52+
"ABI requires alignof(ArrayConstructorVector) to be smaller than "
53+
"MaxArrayConstructorVectorAlignInBytes");
4554

46-
// This file defines an API to "push" an evaluated array constructor value
47-
// "from" into some storage "to" of an array constructor. It can be seen as a
48-
// form of std::vector::push_back() implementation for Fortran array
49-
// constructors. In the APIs and ArrayConstructorVector struct above:
50-
//
51-
// - "to" is a ranked-1 descriptor whose declared type is already set to the
52-
// array constructor derived type. It may be already allocated, even before the
53-
// first call to this API, or it may be unallocated. "to" extent is increased
54-
// every time a "from" is pushed past its current extent. At this end of the
55-
// API calls, its extent is the extent of the array constructor. If "to" is
56-
// unallocated and its extent is not null, it is assumed this is the final array
57-
// constructor extent value, and the first allocation already "reserves" storage
58-
// space accordingly to avoid reallocations.
59-
// - "from" is a scalar or array descriptor for the evaluated array
60-
// constructor value that must be copied into the storage of "to" at
61-
// "nextValuePosition".
62-
// - "useValueLengthParameters" must be set to true if the array constructor
63-
// has length parameters and no type spec. If it is true and "to" is
64-
// unallocated, "to" will take the length parameters of "from". If it is true
65-
// and "to" is an allocated character array constructor, it will be checked
66-
// that "from" length matches the one from "to". When it is false, the
67-
// character length must already be set in "to" before the first call to this
68-
// API and "from" character lengths are allowed to mismatch from "to".
69-
// - "nextValuePosition" is the zero based sequence position of "from" in the
70-
// array constructor. It is updated after this call by the number of "from"
71-
// elements. It should be set to zero by the caller of this API before the first
72-
// call.
73-
// - "actualAllocationSize" is the current allocation size of "to" storage. It
74-
// may be bigger than "to" extent for reallocation optimization purposes, but
75-
// should never be smaller, unless this is the first call and "to" is
76-
// unallocated. It is updated by the runtime after each successful allocation or
77-
// reallocation. It should be set to "to" extent if "to" is allocated before the
78-
// first call of this API, and can be left undefined otherwise.
79-
//
80-
// Note that this API can be used with "to" being a variable (that can be
81-
// discontiguous). This can be done when the variable is the left hand side of
82-
// an assignment from an array constructor as long as:
83-
// - none of the ac-value overlaps with the variable,
84-
// - this is an intrinsic assignment that is not a whole allocatable
85-
// assignment, *and* for a type that has no components requiring user defined
86-
// assignments,
87-
// - the variable is properly finalized before using this API if its need to,
88-
// - "useValueLengthParameters" should be set to false in this case, even if
89-
// the array constructor has no type-spec, since the variable may have a
90-
// different character length than the array constructor values.
91-
92-
extern "C" {
93-
// API to initialize an ArrayConstructorVector before any values are pushed to
94-
// it. Inlined code is only expected to allocate the "ArrayConstructorVector"
95-
// class instance storage with sufficient size (using
96-
// "2*sizeof(ArrayConstructorVector)" on the host should be safe regardless of
97-
// the target the runtime is compiled for). This avoids the need for the runtime
98-
// to maintain a state, or to use dynamic allocation for it. "vectorClassSize"
99-
// is used to validate that lowering allocated enough space for it.
100-
void RTDECL(InitArrayConstructorVector)(ArrayConstructorVector &vector,
101-
Descriptor &to, bool useValueLengthParameters, int vectorClassSize,
102-
const char *sourceFile = nullptr, int sourceLine = 0);
103-
104-
// Generic API to push any kind of entity into the array constructor (any
105-
// Fortran type and any rank).
106-
void RTDECL(PushArrayConstructorValue)(
107-
ArrayConstructorVector &vector, const Descriptor &from);
108-
109-
// API to push scalar array constructor value of:
110-
// - a numerical or logical type,
111-
// - or a derived type that has no length parameters, and no allocatable
112-
// component (that would require deep copies).
113-
// It requires no descriptor for the value that is passed via its base address.
114-
void RTDECL(PushArrayConstructorSimpleScalar)(
115-
ArrayConstructorVector &vector, void *from);
116-
} // extern "C"
11755
} // namespace Fortran::runtime
11856
#endif // FORTRAN_RUNTIME_ARRAYCONSTRUCTOR_H_
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
//===-- include/flang/Runtime/descriptor-consts.h ---------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef FORTRAN_RUNTIME_DESCRIPTOR_CONSTS_H_
10+
#define FORTRAN_RUNTIME_DESCRIPTOR_CONSTS_H_
11+
12+
#include "flang/Common/api-attrs.h"
13+
#include "flang/ISO_Fortran_binding_wrapper.h"
14+
#include <cstddef>
15+
#include <cstdint>
16+
17+
// Value of the addendum presence flag.
18+
#define _CFI_ADDENDUM_FLAG 1
19+
// Number of bits needed to be shifted when manipulating the allocator index.
20+
#define _CFI_ALLOCATOR_IDX_SHIFT 1
21+
// Allocator index mask.
22+
#define _CFI_ALLOCATOR_IDX_MASK 0b00001110
23+
24+
namespace Fortran::runtime::typeInfo {
25+
using TypeParameterValue = std::int64_t;
26+
class DerivedType;
27+
} // namespace Fortran::runtime::typeInfo
28+
29+
namespace Fortran::runtime {
30+
class Descriptor;
31+
32+
/// Returns size in bytes of the descriptor (not the data)
33+
/// This must be at least as large as the largest descriptor of any target
34+
/// triple.
35+
static constexpr RT_API_ATTRS std::size_t MaxDescriptorSizeInBytes(
36+
int rank, bool addendum = false, int lengthTypeParameters = 0) {
37+
// Layout:
38+
//
39+
// fortran::runtime::Descriptor {
40+
// ISO::CFI_cdesc_t {
41+
// void *base_addr; (pointer -> up to 8 bytes)
42+
// size_t elem_len; (up to 8 bytes)
43+
// int version; (up to 4 bytes)
44+
// CFI_rank_t rank; (unsigned char -> 1 byte)
45+
// CFI_type_t type; (signed char -> 1 byte)
46+
// CFI_attribute_t attribute; (unsigned char -> 1 byte)
47+
// unsigned char extra; (1 byte)
48+
// }
49+
// }
50+
// fortran::runtime::Dimension[rank] {
51+
// ISO::CFI_dim_t {
52+
// CFI_index_t lower_bound; (ptrdiff_t -> up to 8 bytes)
53+
// CFI_index_t extent; (ptrdiff_t -> up to 8 bytes)
54+
// CFI_index_t sm; (ptrdiff_t -> up to 8 bytes)
55+
// }
56+
// }
57+
// fortran::runtime::DescriptorAddendum {
58+
// const typeInfo::DerivedType *derivedType_; (pointer -> up to 8
59+
// bytes) typeInfo::TypeParameterValue len_[lenParameters]; (int64_t -> 8
60+
// bytes)
61+
// }
62+
std::size_t bytes{24u + rank * 24u};
63+
if (addendum || lengthTypeParameters > 0) {
64+
if (lengthTypeParameters < 1)
65+
lengthTypeParameters = 1;
66+
bytes += 8u + static_cast<std::size_t>(lengthTypeParameters) * 8u;
67+
}
68+
return bytes;
69+
}
70+
71+
} // namespace Fortran::runtime
72+
#endif /* FORTRAN_RUNTIME_DESCRIPTOR_CONSTS_H_ */

0 commit comments

Comments
 (0)