Commit 86e2a199 authored by bmeurer's avatar bmeurer Committed by Commit bot

[turbofan] Lower StringCharCodeAt to a dedicated builtin.

Introduce a dedicated StringCharCodeAt builtin, that performs the core
logic of String.prototype.charCodeAt and lower the StringCharCodeAt
simplified operator to a call to this builtin rather than inlining the
full functionality into each and every TurboFan graph using it. This can
significantly reduce compile time in some cases (i.e. can easily shave
off over 50% of compile time overhead for small functions that call
String.prototype.charCodeAt).

Currently it returns the char code as TaggedSigned value, but
middle-term we should make it possible to return untagged values
from builtins.

R=yangguo@chromium.org

Review-Url: https://codereview.chromium.org/2600443002
Cr-Commit-Position: refs/heads/master@{#41912}
parent 38108216
......@@ -480,6 +480,24 @@ void Builtins::Generate_StringCharAt(compiler::CodeAssemblerState* state) {
assembler.Return(result);
}
// static
void Builtins::Generate_StringCharCodeAt(compiler::CodeAssemblerState* state) {
typedef compiler::Node Node;
CodeStubAssembler assembler(state);
Node* receiver = assembler.Parameter(0);
Node* position = assembler.Parameter(1);
// Load the character code at the {position} from the {receiver}.
Node* code = assembler.StringCharCodeAt(receiver, position,
CodeStubAssembler::INTPTR_PARAMETERS);
// And return it as TaggedSigned value.
// TODO(turbofan): Allow builtins to return values untagged.
Node* result = assembler.SmiFromWord32(code);
assembler.Return(result);
}
// -----------------------------------------------------------------------------
// ES6 section 21.1 String Objects
......
......@@ -105,6 +105,7 @@ namespace internal {
TFS(StringGreaterThan, BUILTIN, kNoExtraICState, Compare) \
TFS(StringGreaterThanOrEqual, BUILTIN, kNoExtraICState, Compare) \
TFS(StringCharAt, BUILTIN, kNoExtraICState, StringCharAt) \
TFS(StringCharCodeAt, BUILTIN, kNoExtraICState, StringCharCodeAt) \
\
/* Interpreter */ \
ASM(InterpreterEntryTrampoline) \
......
......@@ -253,6 +253,7 @@ TFS_BUILTIN(NewRestParameterElements)
TFS_BUILTIN(PromiseHandleReject)
TFS_BUILTIN(GetSuperConstructor)
TFS_BUILTIN(StringCharAt)
TFS_BUILTIN(StringCharCodeAt)
#undef TFS_BUILTIN
......
......@@ -119,6 +119,7 @@ class V8_EXPORT_PRIVATE CodeFactory final {
static Callable StringAdd(Isolate* isolate, StringAddFlags flags,
PretenureFlag pretenure_flag);
static Callable StringCharAt(Isolate* isolate);
static Callable StringCharCodeAt(Isolate* isolate);
static Callable StringCompare(Isolate* isolate, Token::Value token);
static Callable StringEqual(Isolate* isolate);
static Callable StringNotEqual(Isolate* isolate);
......
This diff is collapsed.
......@@ -2202,8 +2202,9 @@ class RepresentationSelector {
return;
}
case IrOpcode::kStringCharCodeAt: {
// TODO(turbofan): Allow builtins to return untagged values.
VisitBinop(node, UseInfo::AnyTagged(), UseInfo::TruncatingWord32(),
MachineRepresentation::kWord32);
MachineRepresentation::kTaggedSigned);
return;
}
case IrOpcode::kStringFromCharCode: {
......
......@@ -198,6 +198,21 @@ void StringCharAtDescriptor::InitializePlatformSpecific(
DefaultInitializePlatformSpecific(data, kParameterCount);
}
void StringCharCodeAtDescriptor::InitializePlatformIndependent(
CallInterfaceDescriptorData* data) {
// kReceiver, kPosition
// TODO(turbofan): Allow builtins to return untagged values.
MachineType machine_types[] = {MachineType::AnyTagged(),
MachineType::IntPtr()};
data->InitializePlatformIndependent(arraysize(machine_types), 0,
machine_types);
}
void StringCharCodeAtDescriptor::InitializePlatformSpecific(
CallInterfaceDescriptorData* data) {
DefaultInitializePlatformSpecific(data, kParameterCount);
}
void StringCompareDescriptor::InitializePlatformSpecific(
CallInterfaceDescriptorData* data) {
Register registers[] = {LeftRegister(), RightRegister()};
......
......@@ -74,6 +74,7 @@ class PlatformInterfaceDescriptor;
V(CountOp) \
V(StringAdd) \
V(StringCharAt) \
V(StringCharCodeAt) \
V(StringCompare) \
V(SubString) \
V(Keyed) \
......@@ -697,6 +698,13 @@ class StringCharAtDescriptor final : public CallInterfaceDescriptor {
CallInterfaceDescriptor)
};
class StringCharCodeAtDescriptor final : public CallInterfaceDescriptor {
public:
DEFINE_PARAMETERS(kReceiver, kPosition)
DECLARE_DESCRIPTOR_WITH_CUSTOM_FUNCTION_TYPE(StringCharCodeAtDescriptor,
CallInterfaceDescriptor)
};
class StringCompareDescriptor : public CallInterfaceDescriptor {
public:
DEFINE_PARAMETERS(kLeft, kRight)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment