Skip to content

Commit 0d71df4

Browse files
authored
[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.
1 parent 06b3144 commit 0d71df4

File tree

2 files changed

+0
-153
lines changed

2 files changed

+0
-153
lines changed

flang/include/flang/Runtime/character.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,6 @@ void RTNAME(CharacterConcatenate)(Descriptor &accumulator,
4444
void RTNAME(CharacterConcatenateScalar1)(
4545
Descriptor &accumulator, const char *from, std::size_t chars);
4646

47-
// Copies the value(s) of 'rhs' to 'lhs'. Handles reallocation,
48-
// truncation, or padding ss necessary. Crashes when not conforming and
49-
// the LHS is not allocatable. Assumes independence of data.
50-
// The LHS and RHS need not have the same kind of character;
51-
// so when the LHS is a deallocated allocatable temporary result, this
52-
// function can be used as a simple conversion routine.
53-
// Call MoveAlloc() instead as an optimization when a temporary value is
54-
// being assigned to a deferred-length allocatable.
55-
void RTNAME(CharacterAssign)(Descriptor &lhs, const Descriptor &rhs,
56-
const char *sourceFile = nullptr, int sourceLine = 0);
57-
5847
// CHARACTER comparisons. The kinds must match. Like std::memcmp(),
5948
// the result is less than zero, zero, or greater than zero if the first
6049
// argument is less than the second, equal to the second, or greater than

flang/runtime/character.cpp

Lines changed: 0 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -629,148 +629,6 @@ void RTNAME(CharacterConcatenateScalar1)(
629629
FreeMemory(old);
630630
}
631631

632-
void RTNAME(CharacterAssign)(Descriptor &lhs, const Descriptor &rhs,
633-
const char *sourceFile, int sourceLine) {
634-
Terminator terminator{sourceFile, sourceLine};
635-
int rank{lhs.rank()};
636-
RUNTIME_CHECK(terminator, rhs.rank() == 0 || rhs.rank() == rank);
637-
SubscriptValue ub[maxRank], lhsAt[maxRank], rhsAt[maxRank];
638-
SubscriptValue elements{1};
639-
std::size_t lhsBytes{lhs.ElementBytes()};
640-
std::size_t rhsBytes{rhs.ElementBytes()};
641-
bool reallocate{lhs.IsAllocatable() &&
642-
(lhs.raw().base_addr == nullptr || lhsBytes != rhsBytes)};
643-
for (int j{0}; j < rank; ++j) {
644-
lhsAt[j] = lhs.GetDimension(j).LowerBound();
645-
if (rhs.rank() > 0) {
646-
SubscriptValue lhsExt{lhs.GetDimension(j).Extent()};
647-
SubscriptValue rhsExt{rhs.GetDimension(j).Extent()};
648-
ub[j] = lhsAt[j] + rhsExt - 1;
649-
if (lhsExt != rhsExt) {
650-
if (lhs.IsAllocatable()) {
651-
reallocate = true;
652-
} else {
653-
terminator.Crash("Character array assignment: operands are not "
654-
"conforming on dimension %d (%jd != %jd)",
655-
j + 1, static_cast<std::intmax_t>(lhsExt),
656-
static_cast<std::intmax_t>(rhsExt));
657-
}
658-
}
659-
rhsAt[j] = rhs.GetDimension(j).LowerBound();
660-
} else {
661-
ub[j] = lhs.GetDimension(j).UpperBound();
662-
}
663-
elements *= ub[j] - lhsAt[j] + 1;
664-
}
665-
void *old{nullptr};
666-
if (reallocate) {
667-
old = lhs.raw().base_addr;
668-
lhs.set_base_addr(nullptr);
669-
lhs.raw().elem_len = lhsBytes = rhsBytes;
670-
if (rhs.rank() > 0) {
671-
// When the RHS is not scalar, the LHS acquires its bounds.
672-
for (int j{0}; j < rank; ++j) {
673-
lhsAt[j] = rhsAt[j];
674-
ub[j] = rhs.GetDimension(j).UpperBound();
675-
lhs.GetDimension(j).SetBounds(lhsAt[j], ub[j]);
676-
}
677-
}
678-
RUNTIME_CHECK(terminator, lhs.Allocate() == CFI_SUCCESS);
679-
}
680-
switch (lhs.raw().type) {
681-
case CFI_type_char:
682-
switch (rhs.raw().type) {
683-
case CFI_type_char:
684-
for (; elements-- > 0;
685-
lhs.IncrementSubscripts(lhsAt), rhs.IncrementSubscripts(rhsAt)) {
686-
CopyAndPad(lhs.Element<char>(lhsAt), rhs.Element<char>(rhsAt), lhsBytes,
687-
rhsBytes);
688-
}
689-
break;
690-
case CFI_type_char16_t:
691-
for (; elements-- > 0;
692-
lhs.IncrementSubscripts(lhsAt), rhs.IncrementSubscripts(rhsAt)) {
693-
CopyAndPad(lhs.Element<char>(lhsAt), rhs.Element<char16_t>(rhsAt),
694-
lhsBytes, rhsBytes >> 1);
695-
}
696-
break;
697-
case CFI_type_char32_t:
698-
for (; elements-- > 0;
699-
lhs.IncrementSubscripts(lhsAt), rhs.IncrementSubscripts(rhsAt)) {
700-
CopyAndPad(lhs.Element<char>(lhsAt), rhs.Element<char32_t>(rhsAt),
701-
lhsBytes, rhsBytes >> 2);
702-
}
703-
break;
704-
default:
705-
terminator.Crash(
706-
"RHS of character assignment does not have a character type");
707-
}
708-
break;
709-
case CFI_type_char16_t:
710-
switch (rhs.raw().type) {
711-
case CFI_type_char:
712-
for (; elements-- > 0;
713-
lhs.IncrementSubscripts(lhsAt), rhs.IncrementSubscripts(rhsAt)) {
714-
CopyAndPad(lhs.Element<char16_t>(lhsAt), rhs.Element<char>(rhsAt),
715-
lhsBytes >> 1, rhsBytes);
716-
}
717-
break;
718-
case CFI_type_char16_t:
719-
for (; elements-- > 0;
720-
lhs.IncrementSubscripts(lhsAt), rhs.IncrementSubscripts(rhsAt)) {
721-
CopyAndPad(lhs.Element<char16_t>(lhsAt), rhs.Element<char16_t>(rhsAt),
722-
lhsBytes >> 1, rhsBytes >> 1);
723-
}
724-
break;
725-
case CFI_type_char32_t:
726-
for (; elements-- > 0;
727-
lhs.IncrementSubscripts(lhsAt), rhs.IncrementSubscripts(rhsAt)) {
728-
CopyAndPad(lhs.Element<char16_t>(lhsAt), rhs.Element<char32_t>(rhsAt),
729-
lhsBytes >> 1, rhsBytes >> 2);
730-
}
731-
break;
732-
default:
733-
terminator.Crash(
734-
"RHS of character assignment does not have a character type");
735-
}
736-
break;
737-
case CFI_type_char32_t:
738-
switch (rhs.raw().type) {
739-
case CFI_type_char:
740-
for (; elements-- > 0;
741-
lhs.IncrementSubscripts(lhsAt), rhs.IncrementSubscripts(rhsAt)) {
742-
CopyAndPad(lhs.Element<char32_t>(lhsAt), rhs.Element<char>(rhsAt),
743-
lhsBytes >> 2, rhsBytes);
744-
}
745-
break;
746-
case CFI_type_char16_t:
747-
for (; elements-- > 0;
748-
lhs.IncrementSubscripts(lhsAt), rhs.IncrementSubscripts(rhsAt)) {
749-
CopyAndPad(lhs.Element<char32_t>(lhsAt), rhs.Element<char16_t>(rhsAt),
750-
lhsBytes >> 2, rhsBytes >> 1);
751-
}
752-
break;
753-
case CFI_type_char32_t:
754-
for (; elements-- > 0;
755-
lhs.IncrementSubscripts(lhsAt), rhs.IncrementSubscripts(rhsAt)) {
756-
CopyAndPad(lhs.Element<char32_t>(lhsAt), rhs.Element<char32_t>(rhsAt),
757-
lhsBytes >> 2, rhsBytes >> 2);
758-
}
759-
break;
760-
default:
761-
terminator.Crash(
762-
"RHS of character assignment does not have a character type");
763-
}
764-
break;
765-
default:
766-
terminator.Crash(
767-
"LHS of character assignment does not have a character type");
768-
}
769-
if (reallocate) {
770-
FreeMemory(old);
771-
}
772-
}
773-
774632
int RTNAME(CharacterCompareScalar)(const Descriptor &x, const Descriptor &y) {
775633
Terminator terminator{__FILE__, __LINE__};
776634
RUNTIME_CHECK(terminator, x.rank() == 0);

0 commit comments

Comments
 (0)