[compiler] Inline StringCodePointAt in LowerStringCodePointAt
In LowerStringCodePointAt, rather than call StringCodePointAt builtin, we could inline it using StringCharCodeAt. Bug: v8:11743 Change-Id: I924f4180ffcfd583cfcbba57b2e0cf114adef068 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3517935 Reviewed-by: Tobias Tebbi <tebbi@chromium.org> Reviewed-by: Leszek Swirski <leszeks@chromium.org> Commit-Queue: Leszek Swirski <leszeks@chromium.org> Cr-Commit-Position: refs/heads/main@{#79598}
This commit is contained in:
parent
09b7f78692
commit
19c6bd12b0
@ -165,7 +165,6 @@ namespace internal {
|
||||
ASM(ResumeGeneratorTrampoline, ResumeGenerator) \
|
||||
\
|
||||
/* String helpers */ \
|
||||
TFC(StringCodePointAt, StringAt) \
|
||||
TFC(StringFromCodePointAt, StringAtAsString) \
|
||||
TFC(StringEqual, Compare) \
|
||||
TFC(StringGreaterThan, Compare) \
|
||||
|
@ -751,21 +751,6 @@ TF_BUILTIN(StringGreaterThanOrEqual, StringBuiltinsAssembler) {
|
||||
Operation::kGreaterThanOrEqual);
|
||||
}
|
||||
|
||||
TF_BUILTIN(StringCodePointAt, StringBuiltinsAssembler) {
|
||||
auto receiver = Parameter<String>(Descriptor::kReceiver);
|
||||
auto position = UncheckedParameter<IntPtrT>(Descriptor::kPosition);
|
||||
|
||||
// TODO(sigurds) Figure out if passing length as argument pays off.
|
||||
TNode<IntPtrT> length = LoadStringLengthAsWord(receiver);
|
||||
// Load the character code at the {position} from the {receiver}.
|
||||
TNode<Int32T> code =
|
||||
LoadSurrogatePairAt(receiver, length, position, UnicodeEncoding::UTF32);
|
||||
// And return it as TaggedSigned value.
|
||||
// TODO(turbofan): Allow builtins to return values untagged.
|
||||
TNode<Smi> result = SmiFromInt32(code);
|
||||
Return(result);
|
||||
}
|
||||
|
||||
TF_BUILTIN(StringFromCodePointAt, StringBuiltinsAssembler) {
|
||||
auto receiver = Parameter<String>(Descriptor::kReceiver);
|
||||
auto position = UncheckedParameter<IntPtrT>(Descriptor::kPosition);
|
||||
|
@ -114,7 +114,6 @@ namespace internal {
|
||||
V(StoreGlobalWithVector) \
|
||||
V(StoreTransition) \
|
||||
V(StoreWithVector) \
|
||||
V(StringAt) \
|
||||
V(StringAtAsString) \
|
||||
V(StringSubstring) \
|
||||
IF_TSAN(V, TSANStore) \
|
||||
@ -1553,19 +1552,6 @@ class BinarySmiOp_BaselineDescriptor
|
||||
static constexpr inline auto registers();
|
||||
};
|
||||
|
||||
// This desciptor is shared among String.p.charAt/charCodeAt/codePointAt
|
||||
// as they all have the same interface.
|
||||
class StringAtDescriptor final
|
||||
: public StaticCallInterfaceDescriptor<StringAtDescriptor> {
|
||||
public:
|
||||
DEFINE_PARAMETERS(kReceiver, kPosition)
|
||||
// TODO(turbofan): Return untagged value here.
|
||||
DEFINE_RESULT_AND_PARAMETER_TYPES(MachineType::TaggedSigned(), // result 1
|
||||
MachineType::AnyTagged(), // kReceiver
|
||||
MachineType::IntPtr()) // kPosition
|
||||
DECLARE_DESCRIPTOR(StringAtDescriptor)
|
||||
};
|
||||
|
||||
class StringAtAsStringDescriptor final
|
||||
: public StaticCallInterfaceDescriptor<StringAtAsStringDescriptor> {
|
||||
public:
|
||||
|
@ -162,6 +162,7 @@ class EffectControlLinearizer {
|
||||
Node* LowerStringConcat(Node* node);
|
||||
Node* LowerStringToNumber(Node* node);
|
||||
Node* LowerStringCharCodeAt(Node* node);
|
||||
Node* StringCharCodeAt(Node* receiver, Node* position);
|
||||
Node* LowerStringCodePointAt(Node* node);
|
||||
Node* LowerStringToLowerCaseIntl(Node* node);
|
||||
Node* LowerStringToUpperCaseIntl(Node* node);
|
||||
@ -3828,10 +3829,8 @@ Node* EffectControlLinearizer::LowerStringToNumber(Node* node) {
|
||||
__ NoContextConstant());
|
||||
}
|
||||
|
||||
Node* EffectControlLinearizer::LowerStringCharCodeAt(Node* node) {
|
||||
Node* receiver = node->InputAt(0);
|
||||
Node* position = node->InputAt(1);
|
||||
|
||||
Node* EffectControlLinearizer::StringCharCodeAt(Node* receiver,
|
||||
Node* position) {
|
||||
// We need a loop here to properly deal with indirect strings
|
||||
// (SlicedString, ConsString and ThinString).
|
||||
auto loop = __ MakeLoopLabel(MachineRepresentation::kTagged,
|
||||
@ -3977,19 +3976,41 @@ Node* EffectControlLinearizer::LowerStringCharCodeAt(Node* node) {
|
||||
return loop_done.PhiAt(0);
|
||||
}
|
||||
|
||||
Node* EffectControlLinearizer::LowerStringCharCodeAt(Node* node) {
|
||||
Node* receiver = node->InputAt(0);
|
||||
Node* position = node->InputAt(1);
|
||||
return StringCharCodeAt(receiver, position);
|
||||
}
|
||||
|
||||
Node* EffectControlLinearizer::LowerStringCodePointAt(Node* node) {
|
||||
Node* receiver = node->InputAt(0);
|
||||
Node* position = node->InputAt(1);
|
||||
|
||||
Callable const callable =
|
||||
Builtins::CallableFor(isolate(), Builtin::kStringCodePointAt);
|
||||
Operator::Properties properties = Operator::kNoThrow | Operator::kNoWrite;
|
||||
CallDescriptor::Flags flags = CallDescriptor::kNoFlags;
|
||||
auto call_descriptor = Linkage::GetStubCallDescriptor(
|
||||
graph()->zone(), callable.descriptor(),
|
||||
callable.descriptor().GetStackParameterCount(), flags, properties);
|
||||
return __ Call(call_descriptor, __ HeapConstant(callable.code()), receiver,
|
||||
position, __ NoContextConstant());
|
||||
auto return_result = __ MakeLabel(MachineRepresentation::kWord32);
|
||||
Node* first_code_unit = StringCharCodeAt(receiver, position);
|
||||
|
||||
__ GotoIfNot(
|
||||
__ Word32Equal(__ Word32And(first_code_unit, __ Int32Constant(0xFC00)),
|
||||
__ Int32Constant(0xD800)),
|
||||
&return_result, BranchHint::kFalse, first_code_unit);
|
||||
|
||||
auto length = __ LoadField(AccessBuilder::ForStringLength(), receiver);
|
||||
auto next_index = __ IntAdd(position, __ IntPtrConstant(1));
|
||||
__ GotoIfNot(__ IntLessThan(next_index, length), &return_result,
|
||||
first_code_unit);
|
||||
Node* second_code_unit = StringCharCodeAt(receiver, next_index);
|
||||
__ GotoIfNot(
|
||||
__ Word32Equal(__ Word32And(second_code_unit, __ Int32Constant(0xFC00)),
|
||||
__ Int32Constant(0xDC00)),
|
||||
&return_result, first_code_unit);
|
||||
|
||||
auto surrogate_offset = __ Int32Constant(0x10000 - (0xD800 << 10) - 0xDC00);
|
||||
auto result = __ Int32Add(__ Word32Shl(first_code_unit, __ Int32Constant(10)),
|
||||
__ Int32Add(second_code_unit, surrogate_offset));
|
||||
__ Goto(&return_result, result);
|
||||
|
||||
__ Bind(&return_result);
|
||||
return return_result.PhiAt(0);
|
||||
}
|
||||
|
||||
Node* EffectControlLinearizer::LoadFromSeqString(Node* receiver, Node* position,
|
||||
|
@ -3211,7 +3211,7 @@ class RepresentationSelector {
|
||||
}
|
||||
case IrOpcode::kStringCodePointAt: {
|
||||
return VisitBinop<T>(node, UseInfo::AnyTagged(), UseInfo::Word(),
|
||||
MachineRepresentation::kTaggedSigned);
|
||||
MachineRepresentation::kWord32);
|
||||
}
|
||||
case IrOpcode::kStringFromSingleCharCode: {
|
||||
VisitUnop<T>(node, UseInfo::TruncatingWord32(),
|
||||
|
Loading…
Reference in New Issue
Block a user