Commit 942f255f authored by cbruni's avatar cbruni Committed by Commit bot

Adding %_NewObject intrinsic

This should help speeding up Promise and RegExp instantiations substantially.

BUG=

Review URL: https://codereview.chromium.org/1850643002

Cr-Commit-Position: refs/heads/master@{#35200}
parent 3dd3beb0
...@@ -84,6 +84,8 @@ Reduction JSIntrinsicLowering::Reduce(Node* node) { ...@@ -84,6 +84,8 @@ Reduction JSIntrinsicLowering::Reduce(Node* node) {
return ReduceToString(node); return ReduceToString(node);
case Runtime::kInlineCall: case Runtime::kInlineCall:
return ReduceCall(node); return ReduceCall(node);
case Runtime::kInlineNewObject:
return ReduceNewObject(node);
case Runtime::kInlineGetSuperConstructor: case Runtime::kInlineGetSuperConstructor:
return ReduceGetSuperConstructor(node); return ReduceGetSuperConstructor(node);
case Runtime::kInlineGetOrdinaryHasInstance: case Runtime::kInlineGetOrdinaryHasInstance:
...@@ -401,6 +403,17 @@ Reduction JSIntrinsicLowering::ReduceCall(Node* node) { ...@@ -401,6 +403,17 @@ Reduction JSIntrinsicLowering::ReduceCall(Node* node) {
return Changed(node); return Changed(node);
} }
Reduction JSIntrinsicLowering::ReduceNewObject(Node* node) {
Node* constructor = NodeProperties::GetValueInput(node, 0);
Node* new_target = NodeProperties::GetValueInput(node, 1);
Node* context = NodeProperties::GetContextInput(node);
Node* effect = NodeProperties::GetEffectInput(node);
Node* frame_state = NodeProperties::GetFrameStateInput(node, 0);
Node* value = graph()->NewNode(javascript()->Create(), constructor,
new_target, context, frame_state, effect);
ReplaceWithValue(node, value, value);
return Replace(value);
}
Reduction JSIntrinsicLowering::ReduceGetSuperConstructor(Node* node) { Reduction JSIntrinsicLowering::ReduceGetSuperConstructor(Node* node) {
Node* active_function = NodeProperties::GetValueInput(node, 0); Node* active_function = NodeProperties::GetValueInput(node, 0);
......
...@@ -62,6 +62,7 @@ class JSIntrinsicLowering final : public AdvancedReducer { ...@@ -62,6 +62,7 @@ class JSIntrinsicLowering final : public AdvancedReducer {
Reduction ReduceToPrimitive(Node* node); Reduction ReduceToPrimitive(Node* node);
Reduction ReduceToString(Node* node); Reduction ReduceToString(Node* node);
Reduction ReduceCall(Node* node); Reduction ReduceCall(Node* node);
Reduction ReduceNewObject(Node* node);
Reduction ReduceGetSuperConstructor(Node* node); Reduction ReduceGetSuperConstructor(Node* node);
Reduction ReduceGetOrdinaryHasInstance(Node* node); Reduction ReduceGetOrdinaryHasInstance(Node* node);
......
...@@ -170,6 +170,7 @@ int Linkage::FrameStateInputCount(Runtime::FunctionId function) { ...@@ -170,6 +170,7 @@ int Linkage::FrameStateInputCount(Runtime::FunctionId function) {
case Runtime::kTraceExit: case Runtime::kTraceExit:
return 0; return 0;
case Runtime::kInlineGetPrototype: case Runtime::kInlineGetPrototype:
case Runtime::kInlineNewObject:
case Runtime::kInlineRegExpConstructResult: case Runtime::kInlineRegExpConstructResult:
case Runtime::kInlineRegExpExec: case Runtime::kInlineRegExpExec:
case Runtime::kInlineSubString: case Runtime::kInlineSubString:
...@@ -178,9 +179,9 @@ int Linkage::FrameStateInputCount(Runtime::FunctionId function) { ...@@ -178,9 +179,9 @@ int Linkage::FrameStateInputCount(Runtime::FunctionId function) {
case Runtime::kInlineToName: case Runtime::kInlineToName:
case Runtime::kInlineToNumber: case Runtime::kInlineToNumber:
case Runtime::kInlineToObject: case Runtime::kInlineToObject:
case Runtime::kInlineToPrimitive:
case Runtime::kInlineToPrimitive_Number: case Runtime::kInlineToPrimitive_Number:
case Runtime::kInlineToPrimitive_String: case Runtime::kInlineToPrimitive_String:
case Runtime::kInlineToPrimitive:
case Runtime::kInlineToString: case Runtime::kInlineToString:
return 1; return 1;
case Runtime::kInlineCall: case Runtime::kInlineCall:
......
...@@ -12534,6 +12534,18 @@ void HOptimizedGraphBuilder::GenerateSubString(CallRuntime* call) { ...@@ -12534,6 +12534,18 @@ void HOptimizedGraphBuilder::GenerateSubString(CallRuntime* call) {
return ast_context()->ReturnInstruction(result, call->id()); return ast_context()->ReturnInstruction(result, call->id());
} }
// Support for direct creation of new objects.
void HOptimizedGraphBuilder::GenerateNewObject(CallRuntime* call) {
DCHECK_EQ(2, call->arguments()->length());
CHECK_ALIVE(VisitExpressions(call->arguments()));
FastNewObjectStub stub(isolate());
FastNewObjectDescriptor descriptor(isolate());
HValue* values[] = {context(), Pop(), Pop()};
HConstant* stub_value = Add<HConstant>(stub.GetCode());
HInstruction* result = New<HCallWithDescriptor>(
stub_value, 0, descriptor, Vector<HValue*>(values, arraysize(values)));
return ast_context()->ReturnInstruction(result, call->id());
}
// Support for direct calls from JavaScript to native RegExp code. // Support for direct calls from JavaScript to native RegExp code.
void HOptimizedGraphBuilder::GenerateRegExpExec(CallRuntime* call) { void HOptimizedGraphBuilder::GenerateRegExpExec(CallRuntime* call) {
......
...@@ -2230,6 +2230,7 @@ class HOptimizedGraphBuilder : public HGraphBuilder, public AstVisitor { ...@@ -2230,6 +2230,7 @@ class HOptimizedGraphBuilder : public HGraphBuilder, public AstVisitor {
F(IsRegExp) \ F(IsRegExp) \
F(IsJSProxy) \ F(IsJSProxy) \
F(Call) \ F(Call) \
F(NewObject) \
F(ValueOf) \ F(ValueOf) \
F(StringCharFromCode) \ F(StringCharFromCode) \
F(StringCharAt) \ F(StringCharAt) \
......
...@@ -568,6 +568,9 @@ void FullCodeGenerator::EmitIntrinsicAsStubCall(CallRuntime* expr, ...@@ -568,6 +568,9 @@ void FullCodeGenerator::EmitIntrinsicAsStubCall(CallRuntime* expr,
context()->Plug(result_register()); context()->Plug(result_register());
} }
void FullCodeGenerator::EmitNewObject(CallRuntime* expr) {
EmitIntrinsicAsStubCall(expr, CodeFactory::FastNewObject(isolate()));
}
void FullCodeGenerator::EmitNumberToString(CallRuntime* expr) { void FullCodeGenerator::EmitNumberToString(CallRuntime* expr) {
EmitIntrinsicAsStubCall(expr, CodeFactory::NumberToString(isolate())); EmitIntrinsicAsStubCall(expr, CodeFactory::NumberToString(isolate()));
......
...@@ -503,6 +503,7 @@ class FullCodeGenerator: public AstVisitor { ...@@ -503,6 +503,7 @@ class FullCodeGenerator: public AstVisitor {
F(IsRegExp) \ F(IsRegExp) \
F(IsJSProxy) \ F(IsJSProxy) \
F(Call) \ F(Call) \
F(NewObject) \
F(ValueOf) \ F(ValueOf) \
F(StringCharFromCode) \ F(StringCharFromCode) \
F(StringCharAt) \ F(StringCharAt) \
......
...@@ -61,13 +61,13 @@ function CreateResolvingFunctions(promise) { ...@@ -61,13 +61,13 @@ function CreateResolvingFunctions(promise) {
var GlobalPromise = function Promise(resolver) { var GlobalPromise = function Promise(resolver) {
if (resolver === promiseRawSymbol) { if (resolver === promiseRawSymbol) {
return %NewObject(GlobalPromise, new.target); return %_NewObject(GlobalPromise, new.target);
} }
if (IS_UNDEFINED(new.target)) throw MakeTypeError(kNotAPromise, this); if (IS_UNDEFINED(new.target)) throw MakeTypeError(kNotAPromise, this);
if (!IS_CALLABLE(resolver)) if (!IS_CALLABLE(resolver))
throw MakeTypeError(kResolverNotAFunction, resolver); throw MakeTypeError(kResolverNotAFunction, resolver);
var promise = PromiseInit(%NewObject(GlobalPromise, new.target)); var promise = PromiseInit(%_NewObject(GlobalPromise, new.target));
var callbacks = CreateResolvingFunctions(promise); var callbacks = CreateResolvingFunctions(promise);
try { try {
......
...@@ -109,7 +109,7 @@ function RegExpConstructor(pattern, flags) { ...@@ -109,7 +109,7 @@ function RegExpConstructor(pattern, flags) {
if (IS_UNDEFINED(flags)) flags = input_pattern.flags; if (IS_UNDEFINED(flags)) flags = input_pattern.flags;
} }
var object = %NewObject(GlobalRegExp, newtarget); var object = %_NewObject(GlobalRegExp, newtarget);
return RegExpInitialize(object, pattern, flags); return RegExpInitialize(object, pattern, flags);
} }
......
...@@ -162,7 +162,7 @@ function StringMatchJS(pattern) { ...@@ -162,7 +162,7 @@ function StringMatchJS(pattern) {
var subject = TO_STRING(this); var subject = TO_STRING(this);
// Equivalent to RegExpCreate (ES#sec-regexpcreate) // Equivalent to RegExpCreate (ES#sec-regexpcreate)
var regexp = %NewObject(GlobalRegExp, GlobalRegExp); var regexp = %_NewObject(GlobalRegExp, GlobalRegExp);
RegExpInitialize(regexp, pattern); RegExpInitialize(regexp, pattern);
return regexp[matchSymbol](subject); return regexp[matchSymbol](subject);
} }
...@@ -360,7 +360,7 @@ function StringSearch(pattern) { ...@@ -360,7 +360,7 @@ function StringSearch(pattern) {
var subject = TO_STRING(this); var subject = TO_STRING(this);
// Equivalent to RegExpCreate (ES#sec-regexpcreate) // Equivalent to RegExpCreate (ES#sec-regexpcreate)
var regexp = %NewObject(GlobalRegExp, GlobalRegExp); var regexp = %_NewObject(GlobalRegExp, GlobalRegExp);
RegExpInitialize(regexp, pattern); RegExpInitialize(regexp, pattern);
return %_Call(regexp[searchSymbol], regexp, subject); return %_Call(regexp[searchSymbol], regexp, subject);
} }
......
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