Skip to content

Commit 35d552a

Browse files
authored
[flang-rt] Fix recently added memcpy that need runtime wrappers (llvm#3219)
2 parents 327e337 + 2a62bc2 commit 35d552a

File tree

6 files changed

+20
-18
lines changed

6 files changed

+20
-18
lines changed

flang-rt/include/flang-rt/runtime/descriptor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@
3535
RT_OFFLOAD_VAR_GROUP_BEGIN
3636
/// Value used for asyncId when no specific stream is specified.
3737
static constexpr std::int64_t kNoAsyncId = -1;
38-
RT_OFFLOAD_VAR_GROUP_END
3938
/// Value used for asyncObject when no specific stream is specified.
4039
static constexpr std::int64_t *kNoAsyncObject = nullptr;
40+
RT_OFFLOAD_VAR_GROUP_END
4141

4242
namespace Fortran::runtime {
4343

flang-rt/include/flang-rt/runtime/work-queue.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ class Elementwise {
127127
const Descriptor &instance_, *from_{nullptr};
128128
std::size_t elements_{instance_.InlineElements()};
129129
std::size_t elementAt_{0};
130-
SubscriptValue subscripts_[common::maxRank];
131-
SubscriptValue fromSubscripts_[common::maxRank];
130+
SubscriptValue subscripts_[maxRank];
131+
SubscriptValue fromSubscripts_[maxRank];
132132
};
133133

134134
// Base class for ticket workers that operate over derived type components.
@@ -162,7 +162,7 @@ class Componentwise {
162162
const typeInfo::DerivedType &derived_;
163163
std::size_t components_{0}, componentAt_{0};
164164
const typeInfo::Component *component_{nullptr};
165-
StaticDescriptor<common::maxRank, true, 0> componentDescriptor_;
165+
StaticDescriptor<maxRank, true, 0> componentDescriptor_;
166166

167167
private:
168168
RT_API_ATTRS void GetFirstComponent() {
@@ -275,7 +275,7 @@ class InitializeCloneTicket
275275
const Descriptor &clone_;
276276
bool hasStat_{false};
277277
const Descriptor *errMsg_{nullptr};
278-
StaticDescriptor<common::maxRank, true, 0> cloneComponentDescriptor_;
278+
StaticDescriptor<maxRank, true, 0> cloneComponentDescriptor_;
279279
};
280280

281281
// Implements derived type instance finalization
@@ -331,7 +331,7 @@ class AssignTicket : public ImmediateTicketRunner<AssignTicket> {
331331
const Descriptor *from_{nullptr};
332332
int flags_{0}; // enum AssignFlags
333333
MemmoveFct memmoveFct_{nullptr};
334-
StaticDescriptor<common::maxRank, true, 0> tempDescriptor_;
334+
StaticDescriptor<maxRank, true, 0> tempDescriptor_;
335335
const typeInfo::DerivedType *declaredType_{nullptr};
336336
const typeInfo::DerivedType *toDerived_{nullptr};
337337
Descriptor *toDeallocate_{nullptr};
@@ -364,7 +364,7 @@ class DerivedAssignTicket
364364
int flags_{0};
365365
MemmoveFct memmoveFct_{nullptr};
366366
Descriptor *deallocateAfter_{nullptr};
367-
StaticDescriptor<common::maxRank, true, 0> fromComponentDescriptor_;
367+
StaticDescriptor<maxRank, true, 0> fromComponentDescriptor_;
368368
};
369369

370370
namespace io::descr {
@@ -392,7 +392,7 @@ class DescriptorIoTicket
392392
common::optional<typeInfo::SpecialBinding> nonTbpSpecial_;
393393
const typeInfo::DerivedType *derived_{nullptr};
394394
const typeInfo::SpecialBinding *special_{nullptr};
395-
StaticDescriptor<common::maxRank, true, 0> elementDescriptor_;
395+
StaticDescriptor<maxRank, true, 0> elementDescriptor_;
396396
};
397397

398398
template <io::Direction DIR>

flang-rt/lib/runtime/assign.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ RT_API_ATTRS int AssignTicket::Begin(WorkQueue &workQueue) {
279279
if (mustDeallocateLHS) {
280280
// Convert the LHS into a temporary, then make it look deallocated.
281281
toDeallocate_ = &tempDescriptor_.descriptor();
282-
std::memcpy(
282+
Fortran::runtime::memcpy(
283283
reinterpret_cast<void *>(toDeallocate_), &to_, to_.SizeInBytes());
284284
to_.set_base_addr(nullptr);
285285
if (toDerived_ && (flags_ & NeedFinalization)) {
@@ -298,7 +298,7 @@ RT_API_ATTRS int AssignTicket::Begin(WorkQueue &workQueue) {
298298
auto descBytes{from_->SizeInBytes()};
299299
Descriptor &newFrom{tempDescriptor_.descriptor()};
300300
persist_ = true; // tempDescriptor_ state must outlive child tickets
301-
std::memcpy(reinterpret_cast<void *>(&newFrom), from_, descBytes);
301+
Fortran::runtime::memcpy(reinterpret_cast<void *>(&newFrom), from_, descBytes);
302302
// Pretend the temporary descriptor is for an ALLOCATABLE
303303
// entity, otherwise, the Deallocate() below will not
304304
// free the descriptor memory.

flang-rt/lib/runtime/derived.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ RT_API_ATTRS int InitializeTicket::Continue(WorkQueue &workQueue) {
7171
// Explicit initialization of data pointers and
7272
// non-allocatable non-automatic components
7373
std::size_t bytes{component_->SizeInBytes(instance_)};
74-
std::memcpy(rawComponent, init, bytes);
74+
Fortran::runtime::memcpy(rawComponent, init, bytes);
7575
} else if (component_->genre() == typeInfo::Component::Genre::Pointer) {
7676
// Data pointers without explicit initialization are established
7777
// so that they are valid right-hand side targets of pointer
@@ -108,20 +108,20 @@ RT_API_ATTRS int InitializeTicket::Continue(WorkQueue &workQueue) {
108108
chunk = done;
109109
}
110110
char *uninitialized{rawInstance + done * *stride};
111-
std::memcpy(uninitialized, rawInstance, chunk * *stride);
111+
Fortran::runtime::memcpy(uninitialized, rawInstance, chunk * *stride);
112112
done += chunk;
113113
}
114114
} else {
115115
for (std::size_t done{1}; done < elements_; ++done) {
116116
char *uninitialized{rawInstance + done * *stride};
117-
std::memcpy(uninitialized, rawInstance, elementBytes);
117+
Fortran::runtime::memcpy(uninitialized, rawInstance, elementBytes);
118118
}
119119
}
120120
} else { // one at a time with subscription
121121
for (Elementwise::Advance(); !Elementwise::IsComplete();
122122
Elementwise::Advance()) {
123123
char *element{instance_.Element<char>(subscripts_)};
124-
std::memcpy(element, rawInstance, elementBytes);
124+
Fortran::runtime::memcpy(element, rawInstance, elementBytes);
125125
}
126126
}
127127
}

flang-rt/lib/runtime/unit.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
#include "flang-rt/runtime/lock.h"
2222
#include "flang-rt/runtime/memory.h"
2323
#include "flang-rt/runtime/terminator.h"
24+
RT_OFFLOAD_VAR_GROUP_BEGIN
2425
#include "flang/Common/constexpr-bitset.h"
26+
RT_OFFLOAD_VAR_GROUP_END
2527
#include "flang/Common/optional.h"
2628
#include <cstdlib>
2729
#include <cstring>

flang-rt/lib/runtime/work-queue.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
namespace Fortran::runtime {
1616

17-
#if !defined(RT_DEVICE_COMPILATION)
17+
#if !defined(RT_DEVICE_COMPILATION) && !defined(OMP_OFFLOAD_BUILD)
1818
// FLANG_RT_DEBUG code is disabled when false.
1919
static constexpr bool enableDebugOutput{false};
2020
#endif
@@ -79,7 +79,7 @@ RT_API_ATTRS Ticket &WorkQueue::StartTicket() {
7979
last_ = newTicket;
8080
}
8181
newTicket->ticket.begun = false;
82-
#if !defined(RT_DEVICE_COMPILATION)
82+
#if !defined(RT_DEVICE_COMPILATION) && !defined(OMP_OFFLOAD_BUILD)
8383
if (enableDebugOutput &&
8484
(executionEnvironment.internalDebugging &
8585
ExecutionEnvironment::WorkQueue)) {
@@ -93,7 +93,7 @@ RT_API_ATTRS int WorkQueue::Run() {
9393
while (last_) {
9494
TicketList *at{last_};
9595
insertAfter_ = last_;
96-
#if !defined(RT_DEVICE_COMPILATION)
96+
#if !defined(RT_DEVICE_COMPILATION) && !defined(OMP_OFFLOAD_BUILD)
9797
if (enableDebugOutput &&
9898
(executionEnvironment.internalDebugging &
9999
ExecutionEnvironment::WorkQueue)) {
@@ -102,7 +102,7 @@ RT_API_ATTRS int WorkQueue::Run() {
102102
}
103103
#endif
104104
int stat{at->ticket.Continue(*this)};
105-
#if !defined(RT_DEVICE_COMPILATION)
105+
#if !defined(RT_DEVICE_COMPILATION) && !defined(OMP_OFFLOAD_BUILD)
106106
if (enableDebugOutput &&
107107
(executionEnvironment.internalDebugging &
108108
ExecutionEnvironment::WorkQueue)) {

0 commit comments

Comments
 (0)