Skip to content

Commit 76facde

Browse files
authored
[flang][runtime] Enable more APIs in the offload build. (#76486)
1 parent 9c39d9b commit 76facde

31 files changed

+580
-409
lines changed

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,17 @@ namespace Fortran::runtime {
2121
// Runtime data structure to hold information about the storage of
2222
// an array constructor being constructed.
2323
struct ArrayConstructorVector {
24-
ArrayConstructorVector(class Descriptor &to, SubscriptValue nextValuePosition,
25-
SubscriptValue actualAllocationSize, const char *sourceFile,
26-
int sourceLine, bool useValueLengthParameters)
24+
RT_API_ATTRS ArrayConstructorVector(class Descriptor &to,
25+
SubscriptValue nextValuePosition, SubscriptValue actualAllocationSize,
26+
const char *sourceFile, int sourceLine, bool useValueLengthParameters)
2727
: to{to}, nextValuePosition{nextValuePosition},
2828
actualAllocationSize{actualAllocationSize}, sourceFile{sourceFile},
29-
sourceLine{sourceLine}, useValueLengthParameters_{
30-
useValueLengthParameters} {}
29+
sourceLine{sourceLine},
30+
useValueLengthParameters_{useValueLengthParameters} {}
3131

32-
bool useValueLengthParameters() const { return useValueLengthParameters_; }
32+
RT_API_ATTRS bool useValueLengthParameters() const {
33+
return useValueLengthParameters_;
34+
}
3335

3436
class Descriptor &to;
3537
SubscriptValue nextValuePosition;
@@ -95,21 +97,21 @@ extern "C" {
9597
// the target the runtime is compiled for). This avoids the need for the runtime
9698
// to maintain a state, or to use dynamic allocation for it. "vectorClassSize"
9799
// is used to validate that lowering allocated enough space for it.
98-
void RTNAME(InitArrayConstructorVector)(ArrayConstructorVector &vector,
100+
void RTDECL(InitArrayConstructorVector)(ArrayConstructorVector &vector,
99101
Descriptor &to, bool useValueLengthParameters, int vectorClassSize,
100102
const char *sourceFile = nullptr, int sourceLine = 0);
101103

102104
// Generic API to push any kind of entity into the array constructor (any
103105
// Fortran type and any rank).
104-
void RTNAME(PushArrayConstructorValue)(
106+
void RTDECL(PushArrayConstructorValue)(
105107
ArrayConstructorVector &vector, const Descriptor &from);
106108

107109
// API to push scalar array constructor value of:
108110
// - a numerical or logical type,
109111
// - or a derived type that has no length parameters, and no allocatable
110112
// component (that would require deep copies).
111113
// It requires no descriptor for the value that is passed via its base address.
112-
void RTNAME(PushArrayConstructorSimpleScalar)(
114+
void RTDECL(PushArrayConstructorSimpleScalar)(
113115
ArrayConstructorVector &vector, void *from);
114116
} // extern "C"
115117
} // namespace Fortran::runtime

flang/include/flang/Runtime/character.h

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,16 @@ namespace Fortran::runtime {
2020
class Descriptor;
2121

2222
template <typename CHAR>
23-
int CharacterScalarCompare(
23+
RT_API_ATTRS int CharacterScalarCompare(
2424
const CHAR *x, const CHAR *y, std::size_t xChars, std::size_t yChars);
25-
extern template int CharacterScalarCompare<char>(
25+
extern template RT_API_ATTRS int CharacterScalarCompare<char>(
2626
const char *x, const char *y, std::size_t xChars, std::size_t yChars);
27-
extern template int CharacterScalarCompare<char16_t>(const char16_t *x,
28-
const char16_t *y, std::size_t xChars, std::size_t yChars);
29-
extern template int CharacterScalarCompare<char32_t>(const char32_t *x,
30-
const char32_t *y, std::size_t xChars, std::size_t yChars);
27+
extern template RT_API_ATTRS int CharacterScalarCompare<char16_t>(
28+
const char16_t *x, const char16_t *y, std::size_t xChars,
29+
std::size_t yChars);
30+
extern template RT_API_ATTRS int CharacterScalarCompare<char32_t>(
31+
const char32_t *x, const char32_t *y, std::size_t xChars,
32+
std::size_t yChars);
3133

3234
extern "C" {
3335

@@ -36,12 +38,12 @@ extern "C" {
3638
// initialized CHARACTER allocatable scalar or array descriptor -- use
3739
// AllocatableInitCharacter() to set one up. Crashes when not
3840
// conforming. Assumes independence of data.
39-
void RTNAME(CharacterConcatenate)(Descriptor &accumulator,
41+
void RTDECL(CharacterConcatenate)(Descriptor &accumulator,
4042
const Descriptor &from, const char *sourceFile = nullptr,
4143
int sourceLine = 0);
4244

4345
// Convenience specialization for ASCII scalars concatenation.
44-
void RTNAME(CharacterConcatenateScalar1)(
46+
void RTDECL(CharacterConcatenateScalar1)(
4547
Descriptor &accumulator, const char *from, std::size_t chars);
4648

4749
// CHARACTER comparisons. The kinds must match. Like std::memcmp(),
@@ -52,77 +54,77 @@ void RTNAME(CharacterConcatenateScalar1)(
5254
// N.B.: Calls to the restricted specific intrinsic functions LGE, LGT, LLE,
5355
// & LLT are converted into calls to these during lowering; they don't have
5456
// to be able to be passed as actual procedure arguments.
55-
int RTNAME(CharacterCompareScalar)(const Descriptor &, const Descriptor &);
56-
int RTNAME(CharacterCompareScalar1)(
57+
int RTDECL(CharacterCompareScalar)(const Descriptor &, const Descriptor &);
58+
int RTDECL(CharacterCompareScalar1)(
5759
const char *x, const char *y, std::size_t xChars, std::size_t yChars);
58-
int RTNAME(CharacterCompareScalar2)(const char16_t *x, const char16_t *y,
60+
int RTDECL(CharacterCompareScalar2)(const char16_t *x, const char16_t *y,
5961
std::size_t xChars, std::size_t yChars);
60-
int RTNAME(CharacterCompareScalar4)(const char32_t *x, const char32_t *y,
62+
int RTDECL(CharacterCompareScalar4)(const char32_t *x, const char32_t *y,
6163
std::size_t xChars, std::size_t yChars);
6264

6365
// General CHARACTER comparison; the result is a LOGICAL(KIND=1) array that
6466
// is established and populated.
65-
void RTNAME(CharacterCompare)(
67+
void RTDECL(CharacterCompare)(
6668
Descriptor &result, const Descriptor &, const Descriptor &);
6769

6870
// Special-case support for optimized ASCII scalar expressions.
6971

7072
// Copies data from 'rhs' to the remaining space (lhsLength - offset)
7173
// in 'lhs', if any. Returns the new offset. Assumes independence.
72-
std::size_t RTNAME(CharacterAppend1)(char *lhs, std::size_t lhsBytes,
74+
std::size_t RTDECL(CharacterAppend1)(char *lhs, std::size_t lhsBytes,
7375
std::size_t offset, const char *rhs, std::size_t rhsBytes);
7476

7577
// Appends any necessary spaces to a CHARACTER(KIND=1) scalar.
76-
void RTNAME(CharacterPad1)(char *lhs, std::size_t bytes, std::size_t offset);
78+
void RTDECL(CharacterPad1)(char *lhs, std::size_t bytes, std::size_t offset);
7779

7880
// Intrinsic functions
7981
// The result descriptors below are all established by the runtime.
80-
void RTNAME(Adjustl)(Descriptor &result, const Descriptor &,
82+
void RTDECL(Adjustl)(Descriptor &result, const Descriptor &,
8183
const char *sourceFile = nullptr, int sourceLine = 0);
82-
void RTNAME(Adjustr)(Descriptor &result, const Descriptor &,
84+
void RTDECL(Adjustr)(Descriptor &result, const Descriptor &,
8385
const char *sourceFile = nullptr, int sourceLine = 0);
84-
std::size_t RTNAME(LenTrim1)(const char *, std::size_t);
85-
std::size_t RTNAME(LenTrim2)(const char16_t *, std::size_t);
86-
std::size_t RTNAME(LenTrim4)(const char32_t *, std::size_t);
87-
void RTNAME(LenTrim)(Descriptor &result, const Descriptor &, int kind,
86+
std::size_t RTDECL(LenTrim1)(const char *, std::size_t);
87+
std::size_t RTDECL(LenTrim2)(const char16_t *, std::size_t);
88+
std::size_t RTDECL(LenTrim4)(const char32_t *, std::size_t);
89+
void RTDECL(LenTrim)(Descriptor &result, const Descriptor &, int kind,
8890
const char *sourceFile = nullptr, int sourceLine = 0);
89-
void RTNAME(Repeat)(Descriptor &result, const Descriptor &string,
91+
void RTDECL(Repeat)(Descriptor &result, const Descriptor &string,
9092
std::int64_t ncopies, const char *sourceFile = nullptr, int sourceLine = 0);
91-
void RTNAME(Trim)(Descriptor &result, const Descriptor &string,
93+
void RTDECL(Trim)(Descriptor &result, const Descriptor &string,
9294
const char *sourceFile = nullptr, int sourceLine = 0);
9395

94-
void RTNAME(CharacterMax)(Descriptor &accumulator, const Descriptor &x,
96+
void RTDECL(CharacterMax)(Descriptor &accumulator, const Descriptor &x,
9597
const char *sourceFile = nullptr, int sourceLine = 0);
96-
void RTNAME(CharacterMin)(Descriptor &accumulator, const Descriptor &x,
98+
void RTDECL(CharacterMin)(Descriptor &accumulator, const Descriptor &x,
9799
const char *sourceFile = nullptr, int sourceLine = 0);
98100

99-
std::size_t RTNAME(Index1)(const char *, std::size_t, const char *substring,
101+
std::size_t RTDECL(Index1)(const char *, std::size_t, const char *substring,
100102
std::size_t, bool back = false);
101-
std::size_t RTNAME(Index2)(const char16_t *, std::size_t,
103+
std::size_t RTDECL(Index2)(const char16_t *, std::size_t,
102104
const char16_t *substring, std::size_t, bool back = false);
103-
std::size_t RTNAME(Index4)(const char32_t *, std::size_t,
105+
std::size_t RTDECL(Index4)(const char32_t *, std::size_t,
104106
const char32_t *substring, std::size_t, bool back = false);
105-
void RTNAME(Index)(Descriptor &result, const Descriptor &string,
107+
void RTDECL(Index)(Descriptor &result, const Descriptor &string,
106108
const Descriptor &substring, const Descriptor *back /*can be null*/,
107109
int kind, const char *sourceFile = nullptr, int sourceLine = 0);
108110

109-
std::size_t RTNAME(Scan1)(
111+
std::size_t RTDECL(Scan1)(
110112
const char *, std::size_t, const char *set, std::size_t, bool back = false);
111-
std::size_t RTNAME(Scan2)(const char16_t *, std::size_t, const char16_t *set,
113+
std::size_t RTDECL(Scan2)(const char16_t *, std::size_t, const char16_t *set,
112114
std::size_t, bool back = false);
113-
std::size_t RTNAME(Scan4)(const char32_t *, std::size_t, const char32_t *set,
115+
std::size_t RTDECL(Scan4)(const char32_t *, std::size_t, const char32_t *set,
114116
std::size_t, bool back = false);
115-
void RTNAME(Scan)(Descriptor &result, const Descriptor &string,
117+
void RTDECL(Scan)(Descriptor &result, const Descriptor &string,
116118
const Descriptor &set, const Descriptor *back /*can be null*/, int kind,
117119
const char *sourceFile = nullptr, int sourceLine = 0);
118120

119-
std::size_t RTNAME(Verify1)(
121+
std::size_t RTDECL(Verify1)(
120122
const char *, std::size_t, const char *set, std::size_t, bool back = false);
121-
std::size_t RTNAME(Verify2)(const char16_t *, std::size_t, const char16_t *set,
123+
std::size_t RTDECL(Verify2)(const char16_t *, std::size_t, const char16_t *set,
122124
std::size_t, bool back = false);
123-
std::size_t RTNAME(Verify4)(const char32_t *, std::size_t, const char32_t *set,
125+
std::size_t RTDECL(Verify4)(const char32_t *, std::size_t, const char32_t *set,
124126
std::size_t, bool back = false);
125-
void RTNAME(Verify)(Descriptor &result, const Descriptor &string,
127+
void RTDECL(Verify)(Descriptor &result, const Descriptor &string,
126128
const Descriptor &set, const Descriptor *back /*can be null*/, int kind,
127129
const char *sourceFile = nullptr, int sourceLine = 0);
128130
}

flang/include/flang/Runtime/descriptor.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,16 @@ class Dimension {
6767
}
6868
// Do not use this API to cause the LB of an empty dimension
6969
// to be anything other than 1. Use SetBounds() instead if you can.
70-
Dimension &SetLowerBound(SubscriptValue lower) {
70+
RT_API_ATTRS Dimension &SetLowerBound(SubscriptValue lower) {
7171
raw_.lower_bound = lower;
7272
return *this;
7373
}
74-
Dimension &SetUpperBound(SubscriptValue upper) {
74+
RT_API_ATTRS Dimension &SetUpperBound(SubscriptValue upper) {
7575
auto lower{raw_.lower_bound};
7676
raw_.extent = upper >= lower ? upper - lower + 1 : 0;
7777
return *this;
7878
}
79-
Dimension &SetExtent(SubscriptValue extent) {
79+
RT_API_ATTRS Dimension &SetExtent(SubscriptValue extent) {
8080
raw_.extent = extent;
8181
return *this;
8282
}
@@ -467,5 +467,6 @@ class alignas(Descriptor) StaticDescriptor {
467467
private:
468468
char storage_[byteSize]{};
469469
};
470+
470471
} // namespace Fortran::runtime
471472
#endif // FORTRAN_RUNTIME_DESCRIPTOR_H_

flang/include/flang/Runtime/inquiry.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ class Descriptor;
2121

2222
extern "C" {
2323

24-
std::int64_t RTNAME(LboundDim)(const Descriptor &array, int dim,
24+
std::int64_t RTDECL(LboundDim)(const Descriptor &array, int dim,
2525
const char *sourceFile = nullptr, int line = 0);
26-
void RTNAME(Ubound)(Descriptor &result, const Descriptor &array, int kind,
26+
void RTDECL(Ubound)(Descriptor &result, const Descriptor &array, int kind,
2727
const char *sourceFile = nullptr, int line = 0);
28-
std::int64_t RTNAME(Size)(
28+
std::int64_t RTDECL(Size)(
2929
const Descriptor &array, const char *sourceFile = nullptr, int line = 0);
30-
std::int64_t RTNAME(SizeDim)(const Descriptor &array, int dim,
30+
std::int64_t RTDECL(SizeDim)(const Descriptor &array, int dim,
3131
const char *sourceFile = nullptr, int line = 0);
3232

3333
} // extern "C"

flang/include/flang/Runtime/memory.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,17 @@ class Terminator;
2323

2424
[[nodiscard]] RT_API_ATTRS void *AllocateMemoryOrCrash(
2525
const Terminator &, std::size_t bytes);
26-
template <typename A> [[nodiscard]] A &AllocateOrCrash(const Terminator &t) {
26+
template <typename A>
27+
[[nodiscard]] RT_API_ATTRS A &AllocateOrCrash(const Terminator &t) {
2728
return *reinterpret_cast<A *>(AllocateMemoryOrCrash(t, sizeof(A)));
2829
}
30+
RT_API_ATTRS void *ReallocateMemoryOrCrash(
31+
const Terminator &, void *ptr, std::size_t newByteSize);
2932
RT_API_ATTRS void FreeMemory(void *);
3033
template <typename A> RT_API_ATTRS void FreeMemory(A *p) {
3134
FreeMemory(reinterpret_cast<void *>(p));
3235
}
33-
template <typename A> void FreeMemoryAndNullify(A *&p) {
36+
template <typename A> RT_API_ATTRS void FreeMemoryAndNullify(A *&p) {
3437
FreeMemory(p);
3538
p = nullptr;
3639
}

flang/include/flang/Runtime/misc-intrinsic.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ namespace Fortran::runtime {
1919
class Descriptor;
2020

2121
extern "C" {
22-
void RTNAME(Transfer)(Descriptor &result, const Descriptor &source,
22+
void RTDECL(Transfer)(Descriptor &result, const Descriptor &source,
2323
const Descriptor &mold, const char *sourceFile, int line);
24-
void RTNAME(TransferSize)(Descriptor &result, const Descriptor &source,
24+
void RTDECL(TransferSize)(Descriptor &result, const Descriptor &source,
2525
const Descriptor &mold, const char *sourceFile, int line,
2626
std::int64_t size);
2727
} // extern "C"

flang/include/flang/Runtime/pointer.h

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,45 +21,45 @@ extern "C" {
2121
// Data pointer initialization for NULLIFY(), "p=>NULL()`, & for ALLOCATE().
2222

2323
// Initializes a pointer to a disassociated state for NULLIFY() or "p=>NULL()".
24-
void RTNAME(PointerNullifyIntrinsic)(
24+
void RTDECL(PointerNullifyIntrinsic)(
2525
Descriptor &, TypeCategory, int kind, int rank = 0, int corank = 0);
26-
void RTNAME(PointerNullifyCharacter)(Descriptor &, SubscriptValue length = 0,
26+
void RTDECL(PointerNullifyCharacter)(Descriptor &, SubscriptValue length = 0,
2727
int kind = 1, int rank = 0, int corank = 0);
28-
void RTNAME(PointerNullifyDerived)(
28+
void RTDECL(PointerNullifyDerived)(
2929
Descriptor &, const typeInfo::DerivedType &, int rank = 0, int corank = 0);
3030

3131
// Explicitly sets the bounds of an initialized disassociated pointer.
3232
// The upper cobound is ignored for the last codimension.
33-
void RTNAME(PointerSetBounds)(
33+
void RTDECL(PointerSetBounds)(
3434
Descriptor &, int zeroBasedDim, SubscriptValue lower, SubscriptValue upper);
35-
void RTNAME(PointerSetCoBounds)(Descriptor &, int zeroBasedCoDim,
35+
void RTDECL(PointerSetCoBounds)(Descriptor &, int zeroBasedCoDim,
3636
SubscriptValue lower, SubscriptValue upper = 0);
3737

3838
// Length type parameters are indexed in declaration order; i.e., 0 is the
3939
// first length type parameter in the deepest base type. (Not for use
4040
// with CHARACTER; see above.)
41-
void RTNAME(PointerSetDerivedLength)(Descriptor &, int which, SubscriptValue);
41+
void RTDECL(PointerSetDerivedLength)(Descriptor &, int which, SubscriptValue);
4242

4343
// For MOLD= allocation: acquires information from another descriptor
4444
// to initialize a null data pointer.
45-
void RTNAME(PointerApplyMold)(
45+
void RTDECL(PointerApplyMold)(
4646
Descriptor &, const Descriptor &mold, int rank = 0);
4747

4848
// Data pointer association for "p=>TARGET"
4949

5050
// Associates a scalar pointer with a simple scalar target.
51-
void RTNAME(PointerAssociateScalar)(Descriptor &, void *);
51+
void RTDECL(PointerAssociateScalar)(Descriptor &, void *);
5252

5353
// Associates a pointer with a target of the same rank, possibly with new lower
5454
// bounds, which are passed in a vector whose length must equal the rank.
55-
void RTNAME(PointerAssociate)(Descriptor &, const Descriptor &target);
56-
void RTNAME(PointerAssociateLowerBounds)(
55+
void RTDECL(PointerAssociate)(Descriptor &, const Descriptor &target);
56+
void RTDECL(PointerAssociateLowerBounds)(
5757
Descriptor &, const Descriptor &target, const Descriptor &lowerBounds);
5858

5959
// Associates a pointer with a target with bounds remapping. The target must be
6060
// simply contiguous &/or of rank 1. The bounds constitute a [2,newRank]
6161
// integer array whose columns are [lower bound, upper bound] on each dimension.
62-
void RTNAME(PointerAssociateRemapping)(Descriptor &, const Descriptor &target,
62+
void RTDECL(PointerAssociateRemapping)(Descriptor &, const Descriptor &target,
6363
const Descriptor &bounds, const char *sourceFile = nullptr,
6464
int sourceLine = 0);
6565

@@ -70,7 +70,7 @@ void RTNAME(PointerAssociateRemapping)(Descriptor &, const Descriptor &target,
7070
// a derived type or CHARACTER value, the explicit value has to match
7171
// the length type parameter's value. This API checks that requirement.
7272
// Returns 0 for success, or the STAT= value on failure with hasStat==true.
73-
int RTNAME(PointerCheckLengthParameter)(Descriptor &,
73+
int RTDECL(PointerCheckLengthParameter)(Descriptor &,
7474
int which /* 0 for CHARACTER length */, SubscriptValue other,
7575
bool hasStat = false, const Descriptor *errMsg = nullptr,
7676
const char *sourceFile = nullptr, int sourceLine = 0);
@@ -83,10 +83,10 @@ int RTNAME(PointerCheckLengthParameter)(Descriptor &,
8383
// Successfully allocated memory is initialized if the pointer has a
8484
// derived type, and is always initialized by PointerAllocateSource().
8585
// Performs all necessary coarray synchronization and validation actions.
86-
int RTNAME(PointerAllocate)(Descriptor &, bool hasStat = false,
86+
int RTDECL(PointerAllocate)(Descriptor &, bool hasStat = false,
8787
const Descriptor *errMsg = nullptr, const char *sourceFile = nullptr,
8888
int sourceLine = 0);
89-
int RTNAME(PointerAllocateSource)(Descriptor &, const Descriptor &source,
89+
int RTDECL(PointerAllocateSource)(Descriptor &, const Descriptor &source,
9090
bool hasStat = false, const Descriptor *errMsg = nullptr,
9191
const char *sourceFile = nullptr, int sourceLine = 0);
9292

@@ -95,24 +95,24 @@ int RTNAME(PointerAllocateSource)(Descriptor &, const Descriptor &source,
9595
// Finalizes elements &/or components as needed. The pointer is left
9696
// in an initialized disassociated state suitable for reallocation
9797
// with the same bounds, cobounds, and length type parameters.
98-
int RTNAME(PointerDeallocate)(Descriptor &, bool hasStat = false,
98+
int RTDECL(PointerDeallocate)(Descriptor &, bool hasStat = false,
9999
const Descriptor *errMsg = nullptr, const char *sourceFile = nullptr,
100100
int sourceLine = 0);
101101

102102
// Same as PointerDeallocate but also set the dynamic type as the declared type
103103
// as mentioned in 7.3.2.3 note 7.
104-
int RTNAME(PointerDeallocatePolymorphic)(Descriptor &,
104+
int RTDECL(PointerDeallocatePolymorphic)(Descriptor &,
105105
const typeInfo::DerivedType *, bool hasStat = false,
106106
const Descriptor *errMsg = nullptr, const char *sourceFile = nullptr,
107107
int sourceLine = 0);
108108

109109
// Association inquiries for ASSOCIATED()
110110

111111
// True when the pointer is not disassociated.
112-
bool RTNAME(PointerIsAssociated)(const Descriptor &);
112+
bool RTDECL(PointerIsAssociated)(const Descriptor &);
113113

114114
// True when the pointer is associated with a specific target.
115-
bool RTNAME(PointerIsAssociatedWith)(
115+
bool RTDECL(PointerIsAssociatedWith)(
116116
const Descriptor &, const Descriptor *target);
117117

118118
} // extern "C"

0 commit comments

Comments
 (0)