[flang-commits] [flang] 0d71df4 - [flang][runtime] Delete CharacterAssign() (#74621)
via flang-commits
flang-commits at lists.llvm.org
Mon Dec 11 12:38:43 PST 2023
Author: Peter Klausler
Date: 2023-12-11T12:38:39-08:00
New Revision: 0d71df4e6e88a707d5aa8c7c480248d0fbde112e
URL: https://github.com/llvm/llvm-project/commit/0d71df4e6e88a707d5aa8c7c480248d0fbde112e
DIFF: https://github.com/llvm/llvm-project/commit/0d71df4e6e88a707d5aa8c7c480248d0fbde112e.diff
LOG: [flang][runtime] Delete CharacterAssign() (#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.
Added:
Modified:
flang/include/flang/Runtime/character.h
flang/runtime/character.cpp
Removed:
################################################################################
diff --git a/flang/include/flang/Runtime/character.h b/flang/include/flang/Runtime/character.h
index 24f26920bdd2cc..768de75b639c55 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 571f64ec42f42c..2afde7cd5e833a 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