-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[flang][runtime][NFC] Allow different memmove function in assign #114301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-flang-runtime Author: Valentin Clement (バレンタイン クレメン) (clementval) Changes
Full diff: https://github.com/llvm/llvm-project/pull/114301.diff 2 Files Affected:
diff --git a/flang/include/flang/Runtime/assign.h b/flang/include/flang/Runtime/assign.h
index a1cc9eaf4355f6..ddd4d46f99ce3d 100644
--- a/flang/include/flang/Runtime/assign.h
+++ b/flang/include/flang/Runtime/assign.h
@@ -24,11 +24,34 @@
#define FORTRAN_RUNTIME_ASSIGN_H_
#include "flang/Runtime/entry-names.h"
+#include "flang/Runtime/freestanding-tools.h"
namespace Fortran::runtime {
class Descriptor;
+class Terminator;
+
+enum AssignFlags {
+ NoAssignFlags = 0,
+ MaybeReallocate = 1 << 0,
+ NeedFinalization = 1 << 1,
+ CanBeDefinedAssignment = 1 << 2,
+ ComponentCanBeDefinedAssignment = 1 << 3,
+ ExplicitLengthCharacterLHS = 1 << 4,
+ PolymorphicLHS = 1 << 5,
+ DeallocateLHS = 1 << 6
+};
+
+using MemmoveFct = void *(*)(void *, const void *, std::size_t);
+
+static void *MemmoveWrapper(void *dest, const void *src, std::size_t count) {
+ return Fortran::runtime::memmove(dest, src, count);
+}
+
+RT_API_ATTRS void Assign(Descriptor &to, const Descriptor &from,
+ Terminator &terminator, int flags, MemmoveFct memmoveFct = &MemmoveWrapper);
extern "C" {
+
// API for lowering assignment
void RTDECL(Assign)(Descriptor &to, const Descriptor &from,
const char *sourceFile = nullptr, int sourceLine = 0);
diff --git a/flang/runtime/assign.cpp b/flang/runtime/assign.cpp
index d558ada51cd21a..8f31fc4d127168 100644
--- a/flang/runtime/assign.cpp
+++ b/flang/runtime/assign.cpp
@@ -17,17 +17,6 @@
namespace Fortran::runtime {
-enum AssignFlags {
- NoAssignFlags = 0,
- MaybeReallocate = 1 << 0,
- NeedFinalization = 1 << 1,
- CanBeDefinedAssignment = 1 << 2,
- ComponentCanBeDefinedAssignment = 1 << 3,
- ExplicitLengthCharacterLHS = 1 << 4,
- PolymorphicLHS = 1 << 5,
- DeallocateLHS = 1 << 6
-};
-
// Predicate: is the left-hand side of an assignment an allocated allocatable
// that must be deallocated?
static inline RT_API_ATTRS bool MustDeallocateLHS(
@@ -250,8 +239,8 @@ static RT_API_ATTRS void BlankPadCharacterAssignment(Descriptor &to,
// of elements, but their shape need not to conform (the assignment is done in
// element sequence order). This facilitates some internal usages, like when
// dealing with array constructors.
-RT_API_ATTRS static void Assign(
- Descriptor &to, const Descriptor &from, Terminator &terminator, int flags) {
+RT_API_ATTRS void Assign(Descriptor &to, const Descriptor &from,
+ Terminator &terminator, int flags, MemmoveFct memmoveFct) {
bool mustDeallocateLHS{(flags & DeallocateLHS) ||
MustDeallocateLHS(to, from, terminator, flags)};
DescriptorAddendum *toAddendum{to.Addendum()};
@@ -423,14 +412,14 @@ RT_API_ATTRS static void Assign(
Assign(toCompDesc, fromCompDesc, terminator, nestedFlags);
} else { // Component has intrinsic type; simply copy raw bytes
std::size_t componentByteSize{comp.SizeInBytes(to)};
- Fortran::runtime::memmove(to.Element<char>(toAt) + comp.offset(),
+ memmoveFct(to.Element<char>(toAt) + comp.offset(),
from.Element<const char>(fromAt) + comp.offset(),
componentByteSize);
}
break;
case typeInfo::Component::Genre::Pointer: {
std::size_t componentByteSize{comp.SizeInBytes(to)};
- Fortran::runtime::memmove(to.Element<char>(toAt) + comp.offset(),
+ memmoveFct(to.Element<char>(toAt) + comp.offset(),
from.Element<const char>(fromAt) + comp.offset(),
componentByteSize);
} break;
@@ -476,14 +465,14 @@ RT_API_ATTRS static void Assign(
const auto &procPtr{
*procPtrDesc.ZeroBasedIndexedElement<typeInfo::ProcPtrComponent>(
k)};
- Fortran::runtime::memmove(to.Element<char>(toAt) + procPtr.offset,
+ memmoveFct(to.Element<char>(toAt) + procPtr.offset,
from.Element<const char>(fromAt) + procPtr.offset,
sizeof(typeInfo::ProcedurePointer));
}
}
} else { // intrinsic type, intrinsic assignment
if (isSimpleMemmove()) {
- Fortran::runtime::memmove(to.raw().base_addr, from.raw().base_addr,
+ memmoveFct(to.raw().base_addr, from.raw().base_addr,
toElements * toElementBytes);
} else if (toElementBytes > fromElementBytes) { // blank padding
switch (to.type().raw()) {
@@ -507,8 +496,8 @@ RT_API_ATTRS static void Assign(
} else { // elemental copies, possibly with character truncation
for (std::size_t n{toElements}; n-- > 0;
to.IncrementSubscripts(toAt), from.IncrementSubscripts(fromAt)) {
- Fortran::runtime::memmove(to.Element<char>(toAt),
- from.Element<const char>(fromAt), toElementBytes);
+ memmoveFct(to.Element<char>(toAt), from.Element<const char>(fromAt),
+ toElementBytes);
}
}
}
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me. I know that you talked to Peter who has approved the design and with Jean off, maybe you can do a post commit review if needed.
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/152/builds/583 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/89/builds/9626 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/157/builds/11656 Here is the relevant piece of the build log for the reference
|
|
||
using MemmoveFct = void *(*)(void *, const void *, std::size_t); | ||
|
||
static RT_API_ATTRS void *MemmoveWrapper( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the wrapper necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When building on the device the compiler is complaining when we address directly std:: function. Same was done in the allocator-registry
llvm-project/flang/include/flang/Runtime/allocator-registry.h
Lines 37 to 40 in c1df376
static RT_API_ATTRS void *MallocWrapper(std::size_t size) { | |
return std::malloc(size); | |
} | |
static RT_API_ATTRS void FreeWrapper(void *p) { return std::free(p); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the one that landed 7792dbe. Wrapper is not used on the host build.
…m#114301) - Add a parameter to the `Assign` function to be able to use a different `memmove` function. This is preparatory work to be able to use the `Assign` function between host and device data. - Expose the `Assign` function so it can be used from different files. - The new `memmoveFct` is not used in `BlankPadCharacterAssignment` yet since it is not clear if there is a need. It will be updated in case it is needed.
…m#114301) - Add a parameter to the `Assign` function to be able to use a different `memmove` function. This is preparatory work to be able to use the `Assign` function between host and device data. - Expose the `Assign` function so it can be used from different files. - The new `memmoveFct` is not used in `BlankPadCharacterAssignment` yet since it is not clear if there is a need. It will be updated in case it is needed.
Add a parameter to the
Assign
function to be able to use a differentmemmove
function. This is preparatory work to be able to use theAssign
function between host and device data.Expose the
Assign
function so it can be used from different files.The new
memmoveFct
is not used inBlankPadCharacterAssignment
yet since it is not clear if there is a need. It will be updated in case it is needed.