[flang-commits] [flang] [flang][runtime] Delete CharacterAssign() (PR #74621)
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Wed Dec 6 08:23:17 PST 2023
https://github.com/klausler created https://github.com/llvm/llvm-project/pull/74621
Lowering doesn't use it, and won't need it in the future; it emits in-line code for conversions and for assignments to scalars, and uses the general Assign() routine for arrays.
>From da24e46117dd226367f6e83370d8189d4ead060a Mon Sep 17 00:00:00 2001
From: Peter Klausler <pklausler at nvidia.com>
Date: Wed, 6 Dec 2023 08:20:28 -0800
Subject: [PATCH] [flang][runtime] Delete CharacterAssign()
Lowering doesn't use it, and won't need it in the future;
it emits in-line code for conversions and for assignments
to scalars, and uses the general Assign() routine for
arrays.
---
flang/include/flang/Runtime/character.h | 11 --
flang/runtime/character.cpp | 142 ------------------------
2 files changed, 153 deletions(-)
diff --git a/flang/include/flang/Runtime/character.h b/flang/include/flang/Runtime/character.h
index 24f26920bdd2c..768de75b639c5 100644
--- a/flang/include/flang/Runtime/character.h
+++ b/flang/include/flang/Runtime/character.h
@@ -44,17 +44,6 @@ void RTNAME(CharacterConcatenate)(Descriptor &accumulator,
void RTNAME(CharacterConcatenateScalar1)(
Descriptor &accumulator, const char *from, std::size_t chars);
-// Copies the value(s) of 'rhs' to 'lhs'. Handles reallocation,
-// truncation, or padding ss necessary. Crashes when not conforming and
-// the LHS is not allocatable. Assumes independence of data.
-// The LHS and RHS need not have the same kind of character;
-// so when the LHS is a deallocated allocatable temporary result, this
-// function can be used as a simple conversion routine.
-// Call MoveAlloc() instead as an optimization when a temporary value is
-// being assigned to a deferred-length allocatable.
-void RTNAME(CharacterAssign)(Descriptor &lhs, const Descriptor &rhs,
- const char *sourceFile = nullptr, int sourceLine = 0);
-
// CHARACTER comparisons. The kinds must match. Like std::memcmp(),
// the result is less than zero, zero, or greater than zero if the first
// argument is less than the second, equal to the second, or greater than
diff --git a/flang/runtime/character.cpp b/flang/runtime/character.cpp
index 571f64ec42f42..2afde7cd5e833 100644
--- a/flang/runtime/character.cpp
+++ b/flang/runtime/character.cpp
@@ -629,148 +629,6 @@ void RTNAME(CharacterConcatenateScalar1)(
FreeMemory(old);
}
-void RTNAME(CharacterAssign)(Descriptor &lhs, const Descriptor &rhs,
- const char *sourceFile, int sourceLine) {
- Terminator terminator{sourceFile, sourceLine};
- int rank{lhs.rank()};
- RUNTIME_CHECK(terminator, rhs.rank() == 0 || rhs.rank() == rank);
- SubscriptValue ub[maxRank], lhsAt[maxRank], rhsAt[maxRank];
- SubscriptValue elements{1};
- std::size_t lhsBytes{lhs.ElementBytes()};
- std::size_t rhsBytes{rhs.ElementBytes()};
- bool reallocate{lhs.IsAllocatable() &&
- (lhs.raw().base_addr == nullptr || lhsBytes != rhsBytes)};
- for (int j{0}; j < rank; ++j) {
- lhsAt[j] = lhs.GetDimension(j).LowerBound();
- if (rhs.rank() > 0) {
- SubscriptValue lhsExt{lhs.GetDimension(j).Extent()};
- SubscriptValue rhsExt{rhs.GetDimension(j).Extent()};
- ub[j] = lhsAt[j] + rhsExt - 1;
- if (lhsExt != rhsExt) {
- if (lhs.IsAllocatable()) {
- reallocate = true;
- } else {
- terminator.Crash("Character array assignment: operands are not "
- "conforming on dimension %d (%jd != %jd)",
- j + 1, static_cast<std::intmax_t>(lhsExt),
- static_cast<std::intmax_t>(rhsExt));
- }
- }
- rhsAt[j] = rhs.GetDimension(j).LowerBound();
- } else {
- ub[j] = lhs.GetDimension(j).UpperBound();
- }
- elements *= ub[j] - lhsAt[j] + 1;
- }
- void *old{nullptr};
- if (reallocate) {
- old = lhs.raw().base_addr;
- lhs.set_base_addr(nullptr);
- lhs.raw().elem_len = lhsBytes = rhsBytes;
- if (rhs.rank() > 0) {
- // When the RHS is not scalar, the LHS acquires its bounds.
- for (int j{0}; j < rank; ++j) {
- lhsAt[j] = rhsAt[j];
- ub[j] = rhs.GetDimension(j).UpperBound();
- lhs.GetDimension(j).SetBounds(lhsAt[j], ub[j]);
- }
- }
- RUNTIME_CHECK(terminator, lhs.Allocate() == CFI_SUCCESS);
- }
- switch (lhs.raw().type) {
- case CFI_type_char:
- switch (rhs.raw().type) {
- case CFI_type_char:
- for (; elements-- > 0;
- lhs.IncrementSubscripts(lhsAt), rhs.IncrementSubscripts(rhsAt)) {
- CopyAndPad(lhs.Element<char>(lhsAt), rhs.Element<char>(rhsAt), lhsBytes,
- rhsBytes);
- }
- break;
- case CFI_type_char16_t:
- for (; elements-- > 0;
- lhs.IncrementSubscripts(lhsAt), rhs.IncrementSubscripts(rhsAt)) {
- CopyAndPad(lhs.Element<char>(lhsAt), rhs.Element<char16_t>(rhsAt),
- lhsBytes, rhsBytes >> 1);
- }
- break;
- case CFI_type_char32_t:
- for (; elements-- > 0;
- lhs.IncrementSubscripts(lhsAt), rhs.IncrementSubscripts(rhsAt)) {
- CopyAndPad(lhs.Element<char>(lhsAt), rhs.Element<char32_t>(rhsAt),
- lhsBytes, rhsBytes >> 2);
- }
- break;
- default:
- terminator.Crash(
- "RHS of character assignment does not have a character type");
- }
- break;
- case CFI_type_char16_t:
- switch (rhs.raw().type) {
- case CFI_type_char:
- for (; elements-- > 0;
- lhs.IncrementSubscripts(lhsAt), rhs.IncrementSubscripts(rhsAt)) {
- CopyAndPad(lhs.Element<char16_t>(lhsAt), rhs.Element<char>(rhsAt),
- lhsBytes >> 1, rhsBytes);
- }
- break;
- case CFI_type_char16_t:
- for (; elements-- > 0;
- lhs.IncrementSubscripts(lhsAt), rhs.IncrementSubscripts(rhsAt)) {
- CopyAndPad(lhs.Element<char16_t>(lhsAt), rhs.Element<char16_t>(rhsAt),
- lhsBytes >> 1, rhsBytes >> 1);
- }
- break;
- case CFI_type_char32_t:
- for (; elements-- > 0;
- lhs.IncrementSubscripts(lhsAt), rhs.IncrementSubscripts(rhsAt)) {
- CopyAndPad(lhs.Element<char16_t>(lhsAt), rhs.Element<char32_t>(rhsAt),
- lhsBytes >> 1, rhsBytes >> 2);
- }
- break;
- default:
- terminator.Crash(
- "RHS of character assignment does not have a character type");
- }
- break;
- case CFI_type_char32_t:
- switch (rhs.raw().type) {
- case CFI_type_char:
- for (; elements-- > 0;
- lhs.IncrementSubscripts(lhsAt), rhs.IncrementSubscripts(rhsAt)) {
- CopyAndPad(lhs.Element<char32_t>(lhsAt), rhs.Element<char>(rhsAt),
- lhsBytes >> 2, rhsBytes);
- }
- break;
- case CFI_type_char16_t:
- for (; elements-- > 0;
- lhs.IncrementSubscripts(lhsAt), rhs.IncrementSubscripts(rhsAt)) {
- CopyAndPad(lhs.Element<char32_t>(lhsAt), rhs.Element<char16_t>(rhsAt),
- lhsBytes >> 2, rhsBytes >> 1);
- }
- break;
- case CFI_type_char32_t:
- for (; elements-- > 0;
- lhs.IncrementSubscripts(lhsAt), rhs.IncrementSubscripts(rhsAt)) {
- CopyAndPad(lhs.Element<char32_t>(lhsAt), rhs.Element<char32_t>(rhsAt),
- lhsBytes >> 2, rhsBytes >> 2);
- }
- break;
- default:
- terminator.Crash(
- "RHS of character assignment does not have a character type");
- }
- break;
- default:
- terminator.Crash(
- "LHS of character assignment does not have a character type");
- }
- if (reallocate) {
- FreeMemory(old);
- }
-}
-
int RTNAME(CharacterCompareScalar)(const Descriptor &x, const Descriptor &y) {
Terminator terminator{__FILE__, __LINE__};
RUNTIME_CHECK(terminator, x.rank() == 0);
More information about the flang-commits
mailing list