[turbofan] Some more cleanup on the intrinsics.
Remove unused obsolete %_StringGetStringLength intrinsic, and properly optimize the %_SubString, %_RegExpExec, %_RegExpFlags, %_RegExpSource and %_RegExpConstructResult intrinsics. Review URL: https://codereview.chromium.org/1516753006 Cr-Commit-Position: refs/heads/master@{#32782}
This commit is contained in:
parent
eaac00b4e7
commit
7e5ff19ee2
@ -196,6 +196,13 @@ Callable CodeFactory::RegExpConstructResult(Isolate* isolate) {
|
||||
}
|
||||
|
||||
|
||||
// static
|
||||
Callable CodeFactory::RegExpExec(Isolate* isolate) {
|
||||
RegExpExecStub stub(isolate);
|
||||
return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
|
||||
}
|
||||
|
||||
|
||||
// static
|
||||
Callable CodeFactory::StringAdd(Isolate* isolate, StringAddFlags flags,
|
||||
PretenureFlag pretenure_flag) {
|
||||
@ -211,6 +218,13 @@ Callable CodeFactory::StringCompare(Isolate* isolate) {
|
||||
}
|
||||
|
||||
|
||||
// static
|
||||
Callable CodeFactory::SubString(Isolate* isolate) {
|
||||
SubStringStub stub(isolate);
|
||||
return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
|
||||
}
|
||||
|
||||
|
||||
// static
|
||||
Callable CodeFactory::Typeof(Isolate* isolate) {
|
||||
TypeofStub stub(isolate);
|
||||
|
@ -75,10 +75,12 @@ class CodeFactory final {
|
||||
static Callable NumberToString(Isolate* isolate);
|
||||
|
||||
static Callable RegExpConstructResult(Isolate* isolate);
|
||||
static Callable RegExpExec(Isolate* isolate);
|
||||
|
||||
static Callable StringAdd(Isolate* isolate, StringAddFlags flags,
|
||||
PretenureFlag pretenure_flag);
|
||||
static Callable StringCompare(Isolate* isolate);
|
||||
static Callable SubString(Isolate* isolate);
|
||||
|
||||
static Callable Typeof(Isolate* isolate);
|
||||
|
||||
|
@ -128,6 +128,24 @@ FieldAccess AccessBuilder::ForJSDateField(JSDate::FieldIndex index) {
|
||||
}
|
||||
|
||||
|
||||
// static
|
||||
FieldAccess AccessBuilder::ForJSRegExpFlags() {
|
||||
FieldAccess access = {kTaggedBase, JSRegExp::kFlagsOffset,
|
||||
MaybeHandle<Name>(), Type::Tagged(),
|
||||
MachineType::AnyTagged()};
|
||||
return access;
|
||||
}
|
||||
|
||||
|
||||
// static
|
||||
FieldAccess AccessBuilder::ForJSRegExpSource() {
|
||||
FieldAccess access = {kTaggedBase, JSRegExp::kSourceOffset,
|
||||
MaybeHandle<Name>(), Type::Tagged(),
|
||||
MachineType::AnyTagged()};
|
||||
return access;
|
||||
}
|
||||
|
||||
|
||||
// static
|
||||
FieldAccess AccessBuilder::ForFixedArrayLength() {
|
||||
FieldAccess access = {
|
||||
|
@ -55,6 +55,12 @@ class AccessBuilder final : public AllStatic {
|
||||
// Provides access to JSDate fields.
|
||||
static FieldAccess ForJSDateField(JSDate::FieldIndex index);
|
||||
|
||||
// Provides access to JSRegExp::flags() field.
|
||||
static FieldAccess ForJSRegExpFlags();
|
||||
|
||||
// Provides access to JSRegExp::source() field.
|
||||
static FieldAccess ForJSRegExpSource();
|
||||
|
||||
// Provides access to FixedArray::length() field.
|
||||
static FieldAccess ForFixedArrayLength();
|
||||
|
||||
|
@ -73,8 +73,6 @@ Reduction JSIntrinsicLowering::Reduce(Node* node) {
|
||||
return ReduceMathFloor(node);
|
||||
case Runtime::kInlineMathSqrt:
|
||||
return ReduceMathSqrt(node);
|
||||
case Runtime::kInlineStringGetLength:
|
||||
return ReduceStringGetLength(node);
|
||||
case Runtime::kInlineValueOf:
|
||||
return ReduceValueOf(node);
|
||||
case Runtime::kInlineIsMinusZero:
|
||||
@ -83,6 +81,16 @@ Reduction JSIntrinsicLowering::Reduce(Node* node) {
|
||||
return ReduceFixedArrayGet(node);
|
||||
case Runtime::kInlineFixedArraySet:
|
||||
return ReduceFixedArraySet(node);
|
||||
case Runtime::kInlineRegExpConstructResult:
|
||||
return ReduceRegExpConstructResult(node);
|
||||
case Runtime::kInlineRegExpExec:
|
||||
return ReduceRegExpExec(node);
|
||||
case Runtime::kInlineRegExpFlags:
|
||||
return ReduceRegExpFlags(node);
|
||||
case Runtime::kInlineRegExpSource:
|
||||
return ReduceRegExpSource(node);
|
||||
case Runtime::kInlineSubString:
|
||||
return ReduceSubString(node);
|
||||
case Runtime::kInlineToInteger:
|
||||
return ReduceToInteger(node);
|
||||
case Runtime::kInlineToLength:
|
||||
@ -326,15 +334,6 @@ Reduction JSIntrinsicLowering::ReduceMathSqrt(Node* node) {
|
||||
}
|
||||
|
||||
|
||||
Reduction JSIntrinsicLowering::ReduceStringGetLength(Node* node) {
|
||||
Node* value = NodeProperties::GetValueInput(node, 0);
|
||||
Node* effect = NodeProperties::GetEffectInput(node);
|
||||
Node* control = NodeProperties::GetControlInput(node);
|
||||
return Change(node, simplified()->LoadField(AccessBuilder::ForStringLength()),
|
||||
value, effect, control);
|
||||
}
|
||||
|
||||
|
||||
Reduction JSIntrinsicLowering::ReduceValueOf(Node* node) {
|
||||
// if (%_IsSmi(value)) {
|
||||
// return value;
|
||||
@ -459,6 +458,42 @@ Reduction JSIntrinsicLowering::ReduceFixedArraySet(Node* node) {
|
||||
}
|
||||
|
||||
|
||||
Reduction JSIntrinsicLowering::ReduceRegExpConstructResult(Node* node) {
|
||||
// TODO(bmeurer): Introduce JSCreateRegExpResult?
|
||||
return Change(node, CodeFactory::RegExpConstructResult(isolate()), 0);
|
||||
}
|
||||
|
||||
|
||||
Reduction JSIntrinsicLowering::ReduceRegExpExec(Node* node) {
|
||||
return Change(node, CodeFactory::RegExpExec(isolate()), 4);
|
||||
}
|
||||
|
||||
|
||||
Reduction JSIntrinsicLowering::ReduceRegExpFlags(Node* node) {
|
||||
Node* const receiver = NodeProperties::GetValueInput(node, 0);
|
||||
Node* const effect = NodeProperties::GetEffectInput(node);
|
||||
Node* const control = NodeProperties::GetControlInput(node);
|
||||
Operator const* const op =
|
||||
simplified()->LoadField(AccessBuilder::ForJSRegExpFlags());
|
||||
return Change(node, op, receiver, effect, control);
|
||||
}
|
||||
|
||||
|
||||
Reduction JSIntrinsicLowering::ReduceRegExpSource(Node* node) {
|
||||
Node* const receiver = NodeProperties::GetValueInput(node, 0);
|
||||
Node* const effect = NodeProperties::GetEffectInput(node);
|
||||
Node* const control = NodeProperties::GetControlInput(node);
|
||||
Operator const* const op =
|
||||
simplified()->LoadField(AccessBuilder::ForJSRegExpSource());
|
||||
return Change(node, op, receiver, effect, control);
|
||||
}
|
||||
|
||||
|
||||
Reduction JSIntrinsicLowering::ReduceSubString(Node* node) {
|
||||
return Change(node, CodeFactory::SubString(isolate()), 3);
|
||||
}
|
||||
|
||||
|
||||
Reduction JSIntrinsicLowering::ReduceThrowNotDateError(Node* node) {
|
||||
if (mode() != kDeoptimizationEnabled) return NoChange();
|
||||
Node* const frame_state = NodeProperties::GetFrameStateInput(node, 1);
|
||||
@ -532,14 +567,7 @@ Reduction JSIntrinsicLowering::ReduceToLength(Node* node) {
|
||||
ReplaceWithValue(node, value);
|
||||
return Replace(value);
|
||||
}
|
||||
Callable callable = CodeFactory::ToLength(isolate());
|
||||
CallDescriptor const* const desc = Linkage::GetStubCallDescriptor(
|
||||
isolate(), graph()->zone(), callable.descriptor(), 0,
|
||||
CallDescriptor::kNeedsFrameState, node->op()->properties());
|
||||
node->InsertInput(graph()->zone(), 0,
|
||||
jsgraph()->HeapConstant(callable.code()));
|
||||
NodeProperties::ChangeOp(node, common()->Call(desc));
|
||||
return Changed(node);
|
||||
return Change(node, CodeFactory::ToLength(isolate()), 0);
|
||||
}
|
||||
|
||||
|
||||
@ -628,6 +656,18 @@ Reduction JSIntrinsicLowering::ChangeToUndefined(Node* node, Node* effect) {
|
||||
}
|
||||
|
||||
|
||||
Reduction JSIntrinsicLowering::Change(Node* node, Callable const& callable,
|
||||
int stack_parameter_count) {
|
||||
CallDescriptor const* const desc = Linkage::GetStubCallDescriptor(
|
||||
isolate(), graph()->zone(), callable.descriptor(), stack_parameter_count,
|
||||
CallDescriptor::kNeedsFrameState, node->op()->properties());
|
||||
node->InsertInput(graph()->zone(), 0,
|
||||
jsgraph()->HeapConstant(callable.code()));
|
||||
NodeProperties::ChangeOp(node, common()->Call(desc));
|
||||
return Changed(node);
|
||||
}
|
||||
|
||||
|
||||
Graph* JSIntrinsicLowering::graph() const { return jsgraph()->graph(); }
|
||||
|
||||
|
||||
|
@ -12,6 +12,7 @@ namespace v8 {
|
||||
namespace internal {
|
||||
|
||||
// Forward declarations.
|
||||
class Callable;
|
||||
class TypeCache;
|
||||
|
||||
|
||||
@ -53,10 +54,14 @@ class JSIntrinsicLowering final : public AdvancedReducer {
|
||||
Reduction ReduceMathClz32(Node* node);
|
||||
Reduction ReduceMathFloor(Node* node);
|
||||
Reduction ReduceMathSqrt(Node* node);
|
||||
Reduction ReduceStringGetLength(Node* node);
|
||||
Reduction ReduceValueOf(Node* node);
|
||||
Reduction ReduceFixedArrayGet(Node* node);
|
||||
Reduction ReduceFixedArraySet(Node* node);
|
||||
Reduction ReduceRegExpConstructResult(Node* node);
|
||||
Reduction ReduceRegExpExec(Node* node);
|
||||
Reduction ReduceRegExpFlags(Node* node);
|
||||
Reduction ReduceRegExpSource(Node* node);
|
||||
Reduction ReduceSubString(Node* node);
|
||||
Reduction ReduceThrowNotDateError(Node* node);
|
||||
Reduction ReduceToInteger(Node* node);
|
||||
Reduction ReduceToLength(Node* node);
|
||||
@ -74,6 +79,8 @@ class JSIntrinsicLowering final : public AdvancedReducer {
|
||||
Reduction Change(Node* node, const Operator* op, Node* a, Node* b, Node* c,
|
||||
Node* d);
|
||||
Reduction ChangeToUndefined(Node* node, Node* effect = nullptr);
|
||||
Reduction Change(Node* node, Callable const& callable,
|
||||
int stack_parameter_count);
|
||||
|
||||
Graph* graph() const;
|
||||
JSGraph* jsgraph() const { return jsgraph_; }
|
||||
|
@ -177,6 +177,7 @@ int Linkage::FrameStateInputCount(Runtime::FunctionId function) {
|
||||
case Runtime::kInlineArgumentsLength:
|
||||
case Runtime::kInlineDefaultConstructorCallSuper:
|
||||
case Runtime::kInlineGetPrototype:
|
||||
case Runtime::kInlineRegExpConstructResult:
|
||||
case Runtime::kInlineRegExpExec:
|
||||
case Runtime::kInlineSubString:
|
||||
case Runtime::kInlineToInteger:
|
||||
|
@ -1563,8 +1563,10 @@ Type* Typer::Visitor::TypeJSCallRuntime(Node* node) {
|
||||
return Type::Number();
|
||||
case Runtime::kInlineMathClz32:
|
||||
return Type::Range(0, 32, zone());
|
||||
case Runtime::kInlineStringGetLength:
|
||||
return Type::Range(0, String::kMaxLength, zone());
|
||||
case Runtime::kInlineRegExpConstructResult:
|
||||
return Type::OtherObject();
|
||||
case Runtime::kInlineSubString:
|
||||
return Type::String();
|
||||
case Runtime::kInlineToInteger:
|
||||
return TypeUnaryOp(node, ToInteger);
|
||||
case Runtime::kInlineToLength:
|
||||
|
@ -12596,15 +12596,6 @@ void HOptimizedGraphBuilder::GenerateSubString(CallRuntime* call) {
|
||||
}
|
||||
|
||||
|
||||
void HOptimizedGraphBuilder::GenerateStringGetLength(CallRuntime* call) {
|
||||
DCHECK(call->arguments()->length() == 1);
|
||||
CHECK_ALIVE(VisitForValue(call->arguments()->at(0)));
|
||||
HValue* string = Pop();
|
||||
HInstruction* result = BuildLoadStringLength(string);
|
||||
return ast_context()->ReturnInstruction(result, call->id());
|
||||
}
|
||||
|
||||
|
||||
// Support for direct calls from JavaScript to native RegExp code.
|
||||
void HOptimizedGraphBuilder::GenerateRegExpExec(CallRuntime* call) {
|
||||
DCHECK_EQ(4, call->arguments()->length());
|
||||
|
@ -2266,8 +2266,6 @@ class HOptimizedGraphBuilder : public HGraphBuilder, public AstVisitor {
|
||||
F(CreateIterResultObject) \
|
||||
/* Arrays */ \
|
||||
F(HasFastPackedElements) \
|
||||
/* Strings */ \
|
||||
F(StringGetLength) \
|
||||
/* JSValue */ \
|
||||
F(JSValueGetValue)
|
||||
|
||||
|
@ -1245,12 +1245,5 @@ RUNTIME_FUNCTION(Runtime_StringCharCodeAt) {
|
||||
return __RT_impl_Runtime_StringCharCodeAtRT(args, isolate);
|
||||
}
|
||||
|
||||
|
||||
RUNTIME_FUNCTION(Runtime_StringGetLength) {
|
||||
HandleScope scope(isolate);
|
||||
DCHECK(args.length() == 1);
|
||||
CONVERT_ARG_HANDLE_CHECKED(String, s, 0);
|
||||
return Smi::FromInt(s->length());
|
||||
}
|
||||
} // namespace internal
|
||||
} // namespace v8
|
||||
|
@ -893,36 +893,35 @@ namespace internal {
|
||||
F(Bool8x16Shuffle, 18, 1)
|
||||
|
||||
|
||||
#define FOR_EACH_INTRINSIC_STRINGS(F) \
|
||||
F(StringReplaceOneCharWithString, 3, 1) \
|
||||
F(StringIndexOf, 3, 1) \
|
||||
F(StringLastIndexOf, 3, 1) \
|
||||
F(StringLocaleCompare, 2, 1) \
|
||||
F(SubString, 3, 1) \
|
||||
F(StringAdd, 2, 1) \
|
||||
F(InternalizeString, 1, 1) \
|
||||
F(StringMatch, 3, 1) \
|
||||
F(StringCharCodeAtRT, 2, 1) \
|
||||
F(StringCompare, 2, 1) \
|
||||
F(StringBuilderConcat, 3, 1) \
|
||||
F(StringBuilderJoin, 3, 1) \
|
||||
F(SparseJoinWithSeparator, 3, 1) \
|
||||
F(StringToArray, 2, 1) \
|
||||
F(StringToLowerCase, 1, 1) \
|
||||
F(StringToUpperCase, 1, 1) \
|
||||
F(StringTrim, 3, 1) \
|
||||
F(TruncateString, 2, 1) \
|
||||
F(NewString, 2, 1) \
|
||||
F(StringEquals, 2, 1) \
|
||||
F(FlattenString, 1, 1) \
|
||||
F(StringCharFromCode, 1, 1) \
|
||||
F(StringCharAt, 2, 1) \
|
||||
F(OneByteSeqStringGetChar, 2, 1) \
|
||||
F(OneByteSeqStringSetChar, 3, 1) \
|
||||
F(TwoByteSeqStringGetChar, 2, 1) \
|
||||
F(TwoByteSeqStringSetChar, 3, 1) \
|
||||
F(StringCharCodeAt, 2, 1) \
|
||||
F(StringGetLength, 1, 1)
|
||||
#define FOR_EACH_INTRINSIC_STRINGS(F) \
|
||||
F(StringReplaceOneCharWithString, 3, 1) \
|
||||
F(StringIndexOf, 3, 1) \
|
||||
F(StringLastIndexOf, 3, 1) \
|
||||
F(StringLocaleCompare, 2, 1) \
|
||||
F(SubString, 3, 1) \
|
||||
F(StringAdd, 2, 1) \
|
||||
F(InternalizeString, 1, 1) \
|
||||
F(StringMatch, 3, 1) \
|
||||
F(StringCharCodeAtRT, 2, 1) \
|
||||
F(StringCompare, 2, 1) \
|
||||
F(StringBuilderConcat, 3, 1) \
|
||||
F(StringBuilderJoin, 3, 1) \
|
||||
F(SparseJoinWithSeparator, 3, 1) \
|
||||
F(StringToArray, 2, 1) \
|
||||
F(StringToLowerCase, 1, 1) \
|
||||
F(StringToUpperCase, 1, 1) \
|
||||
F(StringTrim, 3, 1) \
|
||||
F(TruncateString, 2, 1) \
|
||||
F(NewString, 2, 1) \
|
||||
F(StringEquals, 2, 1) \
|
||||
F(FlattenString, 1, 1) \
|
||||
F(StringCharFromCode, 1, 1) \
|
||||
F(StringCharAt, 2, 1) \
|
||||
F(OneByteSeqStringGetChar, 2, 1) \
|
||||
F(OneByteSeqStringSetChar, 3, 1) \
|
||||
F(TwoByteSeqStringGetChar, 2, 1) \
|
||||
F(TwoByteSeqStringSetChar, 3, 1) \
|
||||
F(StringCharCodeAt, 2, 1)
|
||||
|
||||
|
||||
#define FOR_EACH_INTRINSIC_SYMBOL(F) \
|
||||
|
@ -396,24 +396,6 @@ TEST_F(JSIntrinsicLoweringTest, InlineMathSqrt) {
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// %_StringGetLength
|
||||
|
||||
|
||||
TEST_F(JSIntrinsicLoweringTest, InlineStringGetLength) {
|
||||
Node* const input = Parameter(0);
|
||||
Node* const context = Parameter(1);
|
||||
Node* const effect = graph()->start();
|
||||
Node* const control = graph()->start();
|
||||
Reduction const r = Reduce(graph()->NewNode(
|
||||
javascript()->CallRuntime(Runtime::kInlineStringGetLength, 1), input,
|
||||
context, effect, control));
|
||||
ASSERT_TRUE(r.Changed());
|
||||
EXPECT_THAT(r.replacement(), IsLoadField(AccessBuilder::ForStringLength(),
|
||||
input, effect, control));
|
||||
}
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// %_MathClz32
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user