[flang-commits] [flang] [flang][runtime] Delete CharacterAssign() (PR #74621)
via flang-commits
flang-commits at lists.llvm.org
Wed Dec 6 08:23:46 PST 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-runtime
Author: Peter Klausler (klausler)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/74621.diff
2 Files Affected:
- (modified) flang/include/flang/Runtime/character.h (-11)
- (modified) flang/runtime/character.cpp (-142)
``````````diff
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);
``````````
</details>
https://github.com/llvm/llvm-project/pull/74621
More information about the flang-commits
mailing list