Commit 4dfff4ab authored by mstarzinger's avatar mstarzinger Committed by Commit bot

[turbofan] Introduce builders for property access.

This introduces a choke point in the AstGraphBuilder for property
access creation. This makes it easier to enrich all such nodes with
additional side-table or debugging information.

R=titzer@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#27157}
parent 83245abb
...@@ -1556,10 +1556,8 @@ void AstGraphBuilder::VisitObjectLiteral(ObjectLiteral* expr) { ...@@ -1556,10 +1556,8 @@ void AstGraphBuilder::VisitObjectLiteral(ObjectLiteral* expr) {
if (property->emit_store()) { if (property->emit_store()) {
VisitForValue(property->value()); VisitForValue(property->value());
Node* value = environment()->Pop(); Node* value = environment()->Pop();
Unique<Name> name = MakeUnique(key->AsPropertyName()); Handle<Name> name = key->AsPropertyName();
Node* store = Node* store = BuildNamedStore(literal, name, value);
NewNode(javascript()->StoreNamed(language_mode(), name),
literal, value);
PrepareFrameState(store, key->id()); PrepareFrameState(store, key->id());
BuildSetHomeObject(value, literal, property->value()); BuildSetHomeObject(value, literal, property->value());
} else { } else {
...@@ -1731,8 +1729,7 @@ void AstGraphBuilder::VisitArrayLiteral(ArrayLiteral* expr) { ...@@ -1731,8 +1729,7 @@ void AstGraphBuilder::VisitArrayLiteral(ArrayLiteral* expr) {
VisitForValue(subexpr); VisitForValue(subexpr);
Node* value = environment()->Pop(); Node* value = environment()->Pop();
Node* index = jsgraph()->Constant(i); Node* index = jsgraph()->Constant(i);
Node* store = NewNode(javascript()->StoreProperty(language_mode()), literal, Node* store = BuildKeyedStore(literal, index, value);
index, value);
PrepareFrameState(store, expr->GetIdForElement(i)); PrepareFrameState(store, expr->GetIdForElement(i));
} }
...@@ -1761,10 +1758,8 @@ void AstGraphBuilder::VisitForInAssignment(Expression* expr, Node* value, ...@@ -1761,10 +1758,8 @@ void AstGraphBuilder::VisitForInAssignment(Expression* expr, Node* value,
VisitForValue(property->obj()); VisitForValue(property->obj());
Node* object = environment()->Pop(); Node* object = environment()->Pop();
value = environment()->Pop(); value = environment()->Pop();
Unique<Name> name = Handle<Name> name = property->key()->AsLiteral()->AsPropertyName();
MakeUnique(property->key()->AsLiteral()->AsPropertyName()); Node* store = BuildNamedStore(object, name, value);
Node* store = NewNode(javascript()->StoreNamed(language_mode(), name),
object, value);
PrepareFrameState(store, bailout_id); PrepareFrameState(store, bailout_id);
break; break;
} }
...@@ -1775,8 +1770,7 @@ void AstGraphBuilder::VisitForInAssignment(Expression* expr, Node* value, ...@@ -1775,8 +1770,7 @@ void AstGraphBuilder::VisitForInAssignment(Expression* expr, Node* value,
Node* key = environment()->Pop(); Node* key = environment()->Pop();
Node* object = environment()->Pop(); Node* object = environment()->Pop();
value = environment()->Pop(); value = environment()->Pop();
Node* store = NewNode(javascript()->StoreProperty(language_mode()), Node* store = BuildKeyedStore(object, key, value);
object, key, value);
PrepareFrameState(store, bailout_id); PrepareFrameState(store, bailout_id);
break; break;
} }
...@@ -1820,11 +1814,10 @@ void AstGraphBuilder::VisitAssignment(Assignment* expr) { ...@@ -1820,11 +1814,10 @@ void AstGraphBuilder::VisitAssignment(Assignment* expr) {
} }
case NAMED_PROPERTY: { case NAMED_PROPERTY: {
Node* object = environment()->Top(); Node* object = environment()->Top();
Unique<Name> name = Handle<Name> name = property->key()->AsLiteral()->AsPropertyName();
MakeUnique(property->key()->AsLiteral()->AsPropertyName());
VectorSlotPair pair = VectorSlotPair pair =
CreateVectorSlotPair(property->PropertyFeedbackSlot()); CreateVectorSlotPair(property->PropertyFeedbackSlot());
old_value = NewNode(javascript()->LoadNamed(name, pair), object); old_value = BuildNamedLoad(object, name, pair);
PrepareFrameState(old_value, property->LoadId(), PrepareFrameState(old_value, property->LoadId(),
OutputFrameStateCombine::Push()); OutputFrameStateCombine::Push());
break; break;
...@@ -1834,7 +1827,7 @@ void AstGraphBuilder::VisitAssignment(Assignment* expr) { ...@@ -1834,7 +1827,7 @@ void AstGraphBuilder::VisitAssignment(Assignment* expr) {
Node* object = environment()->Peek(1); Node* object = environment()->Peek(1);
VectorSlotPair pair = VectorSlotPair pair =
CreateVectorSlotPair(property->PropertyFeedbackSlot()); CreateVectorSlotPair(property->PropertyFeedbackSlot());
old_value = NewNode(javascript()->LoadProperty(pair), object, key); old_value = BuildKeyedLoad(object, key, pair);
PrepareFrameState(old_value, property->LoadId(), PrepareFrameState(old_value, property->LoadId(),
OutputFrameStateCombine::Push()); OutputFrameStateCombine::Push());
break; break;
...@@ -1865,18 +1858,15 @@ void AstGraphBuilder::VisitAssignment(Assignment* expr) { ...@@ -1865,18 +1858,15 @@ void AstGraphBuilder::VisitAssignment(Assignment* expr) {
} }
case NAMED_PROPERTY: { case NAMED_PROPERTY: {
Node* object = environment()->Pop(); Node* object = environment()->Pop();
Unique<Name> name = Handle<Name> name = property->key()->AsLiteral()->AsPropertyName();
MakeUnique(property->key()->AsLiteral()->AsPropertyName()); Node* store = BuildNamedStore(object, name, value);
Node* store = NewNode(javascript()->StoreNamed(language_mode(), name),
object, value);
PrepareFrameState(store, expr->id(), ast_context()->GetStateCombine()); PrepareFrameState(store, expr->id(), ast_context()->GetStateCombine());
break; break;
} }
case KEYED_PROPERTY: { case KEYED_PROPERTY: {
Node* key = environment()->Pop(); Node* key = environment()->Pop();
Node* object = environment()->Pop(); Node* object = environment()->Pop();
Node* store = NewNode(javascript()->StoreProperty(language_mode()), Node* store = BuildKeyedStore(object, key, value);
object, key, value);
PrepareFrameState(store, expr->id(), ast_context()->GetStateCombine()); PrepareFrameState(store, expr->id(), ast_context()->GetStateCombine());
break; break;
} }
...@@ -1907,14 +1897,14 @@ void AstGraphBuilder::VisitProperty(Property* expr) { ...@@ -1907,14 +1897,14 @@ void AstGraphBuilder::VisitProperty(Property* expr) {
if (expr->key()->IsPropertyName()) { if (expr->key()->IsPropertyName()) {
VisitForValue(expr->obj()); VisitForValue(expr->obj());
Node* object = environment()->Pop(); Node* object = environment()->Pop();
Unique<Name> name = MakeUnique(expr->key()->AsLiteral()->AsPropertyName()); Handle<Name> name = expr->key()->AsLiteral()->AsPropertyName();
value = NewNode(javascript()->LoadNamed(name, pair), object); value = BuildNamedLoad(object, name, pair);
} else { } else {
VisitForValue(expr->obj()); VisitForValue(expr->obj());
VisitForValue(expr->key()); VisitForValue(expr->key());
Node* key = environment()->Pop(); Node* key = environment()->Pop();
Node* object = environment()->Pop(); Node* object = environment()->Pop();
value = NewNode(javascript()->LoadProperty(pair), object, key); value = BuildKeyedLoad(object, key, pair);
} }
PrepareFrameState(value, expr->id(), ast_context()->GetStateCombine()); PrepareFrameState(value, expr->id(), ast_context()->GetStateCombine());
ast_context()->ProduceValue(value); ast_context()->ProduceValue(value);
...@@ -1961,13 +1951,12 @@ void AstGraphBuilder::VisitCall(Call* expr) { ...@@ -1961,13 +1951,12 @@ void AstGraphBuilder::VisitCall(Call* expr) {
VectorSlotPair pair = VectorSlotPair pair =
CreateVectorSlotPair(property->PropertyFeedbackSlot()); CreateVectorSlotPair(property->PropertyFeedbackSlot());
if (property->key()->IsPropertyName()) { if (property->key()->IsPropertyName()) {
Unique<Name> name = Handle<Name> name = property->key()->AsLiteral()->AsPropertyName();
MakeUnique(property->key()->AsLiteral()->AsPropertyName()); callee_value = BuildNamedLoad(object, name, pair);
callee_value = NewNode(javascript()->LoadNamed(name, pair), object);
} else { } else {
VisitForValue(property->key()); VisitForValue(property->key());
Node* key = environment()->Pop(); Node* key = environment()->Pop();
callee_value = NewNode(javascript()->LoadProperty(pair), object, key); callee_value = BuildKeyedLoad(object, key, pair);
} }
PrepareFrameState(callee_value, property->LoadId(), PrepareFrameState(callee_value, property->LoadId(),
OutputFrameStateCombine::Push()); OutputFrameStateCombine::Push());
...@@ -2062,10 +2051,8 @@ void AstGraphBuilder::VisitCallJSRuntime(CallRuntime* expr) { ...@@ -2062,10 +2051,8 @@ void AstGraphBuilder::VisitCallJSRuntime(CallRuntime* expr) {
// before arguments are being evaluated. // before arguments are being evaluated.
CallFunctionFlags flags = NO_CALL_FUNCTION_FLAGS; CallFunctionFlags flags = NO_CALL_FUNCTION_FLAGS;
Node* receiver_value = BuildLoadBuiltinsObject(); Node* receiver_value = BuildLoadBuiltinsObject();
Unique<String> unique = MakeUnique(name);
VectorSlotPair pair = CreateVectorSlotPair(expr->CallRuntimeFeedbackSlot()); VectorSlotPair pair = CreateVectorSlotPair(expr->CallRuntimeFeedbackSlot());
Node* callee_value = Node* callee_value = BuildNamedLoad(receiver_value, name, pair);
NewNode(javascript()->LoadNamed(unique, pair), receiver_value);
// TODO(jarin): Find/create a bailout id to deoptimize to (crankshaft // TODO(jarin): Find/create a bailout id to deoptimize to (crankshaft
// refuses to optimize functions with jsruntime calls). // refuses to optimize functions with jsruntime calls).
PrepareFrameState(callee_value, BailoutId::None(), PrepareFrameState(callee_value, BailoutId::None(),
...@@ -2150,11 +2137,10 @@ void AstGraphBuilder::VisitCountOperation(CountOperation* expr) { ...@@ -2150,11 +2137,10 @@ void AstGraphBuilder::VisitCountOperation(CountOperation* expr) {
case NAMED_PROPERTY: { case NAMED_PROPERTY: {
VisitForValue(property->obj()); VisitForValue(property->obj());
Node* object = environment()->Top(); Node* object = environment()->Top();
Unique<Name> name = Handle<Name> name = property->key()->AsLiteral()->AsPropertyName();
MakeUnique(property->key()->AsLiteral()->AsPropertyName());
VectorSlotPair pair = VectorSlotPair pair =
CreateVectorSlotPair(property->PropertyFeedbackSlot()); CreateVectorSlotPair(property->PropertyFeedbackSlot());
old_value = NewNode(javascript()->LoadNamed(name, pair), object); old_value = BuildNamedLoad(object, name, pair);
PrepareFrameState(old_value, property->LoadId(), PrepareFrameState(old_value, property->LoadId(),
OutputFrameStateCombine::Push()); OutputFrameStateCombine::Push());
stack_depth = 1; stack_depth = 1;
...@@ -2167,7 +2153,7 @@ void AstGraphBuilder::VisitCountOperation(CountOperation* expr) { ...@@ -2167,7 +2153,7 @@ void AstGraphBuilder::VisitCountOperation(CountOperation* expr) {
Node* object = environment()->Peek(1); Node* object = environment()->Peek(1);
VectorSlotPair pair = VectorSlotPair pair =
CreateVectorSlotPair(property->PropertyFeedbackSlot()); CreateVectorSlotPair(property->PropertyFeedbackSlot());
old_value = NewNode(javascript()->LoadProperty(pair), object, key); old_value = BuildKeyedLoad(object, key, pair);
PrepareFrameState(old_value, property->LoadId(), PrepareFrameState(old_value, property->LoadId(),
OutputFrameStateCombine::Push()); OutputFrameStateCombine::Push());
stack_depth = 2; stack_depth = 2;
...@@ -2204,10 +2190,8 @@ void AstGraphBuilder::VisitCountOperation(CountOperation* expr) { ...@@ -2204,10 +2190,8 @@ void AstGraphBuilder::VisitCountOperation(CountOperation* expr) {
} }
case NAMED_PROPERTY: { case NAMED_PROPERTY: {
Node* object = environment()->Pop(); Node* object = environment()->Pop();
Unique<Name> name = Handle<Name> name = property->key()->AsLiteral()->AsPropertyName();
MakeUnique(property->key()->AsLiteral()->AsPropertyName()); Node* store = BuildNamedStore(object, name, value);
Node* store = NewNode(javascript()->StoreNamed(language_mode(), name),
object, value);
environment()->Push(value); environment()->Push(value);
PrepareFrameState(store, expr->AssignmentId()); PrepareFrameState(store, expr->AssignmentId());
environment()->Pop(); environment()->Pop();
...@@ -2216,8 +2200,7 @@ void AstGraphBuilder::VisitCountOperation(CountOperation* expr) { ...@@ -2216,8 +2200,7 @@ void AstGraphBuilder::VisitCountOperation(CountOperation* expr) {
case KEYED_PROPERTY: { case KEYED_PROPERTY: {
Node* key = environment()->Pop(); Node* key = environment()->Pop();
Node* object = environment()->Pop(); Node* object = environment()->Pop();
Node* store = NewNode(javascript()->StoreProperty(language_mode()), Node* store = BuildKeyedStore(object, key, value);
object, key, value);
environment()->Push(value); environment()->Push(value);
PrepareFrameState(store, expr->AssignmentId()); PrepareFrameState(store, expr->AssignmentId());
environment()->Pop(); environment()->Pop();
...@@ -2621,10 +2604,8 @@ Node* AstGraphBuilder::BuildVariableLoad(Variable* variable, ...@@ -2621,10 +2604,8 @@ Node* AstGraphBuilder::BuildVariableLoad(Variable* variable,
case Variable::UNALLOCATED: { case Variable::UNALLOCATED: {
// Global var, const, or let variable. // Global var, const, or let variable.
Node* global = BuildLoadGlobalObject(); Node* global = BuildLoadGlobalObject();
Unique<Name> name = MakeUnique(variable->name()); Handle<Name> name = variable->name();
const Operator* op = Node* node = BuildNamedLoad(global, name, feedback, contextual_mode);
javascript()->LoadNamed(name, feedback, contextual_mode);
Node* node = NewNode(op, global);
PrepareFrameState(node, bailout_id, OutputFrameStateCombine::Push()); PrepareFrameState(node, bailout_id, OutputFrameStateCombine::Push());
return node; return node;
} }
...@@ -2730,9 +2711,8 @@ Node* AstGraphBuilder::BuildVariableAssignment( ...@@ -2730,9 +2711,8 @@ Node* AstGraphBuilder::BuildVariableAssignment(
case Variable::UNALLOCATED: { case Variable::UNALLOCATED: {
// Global var, const, or let variable. // Global var, const, or let variable.
Node* global = BuildLoadGlobalObject(); Node* global = BuildLoadGlobalObject();
Unique<Name> name = MakeUnique(variable->name()); Handle<Name> name = variable->name();
const Operator* op = javascript()->StoreNamed(language_mode(), name); Node* store = BuildNamedStore(global, name, value);
Node* store = NewNode(op, global, value);
PrepareFrameState(store, bailout_id, combine); PrepareFrameState(store, bailout_id, combine);
return store; return store;
} }
...@@ -2828,6 +2808,36 @@ Node* AstGraphBuilder::BuildVariableAssignment( ...@@ -2828,6 +2808,36 @@ Node* AstGraphBuilder::BuildVariableAssignment(
} }
Node* AstGraphBuilder::BuildKeyedLoad(Node* object, Node* key,
const VectorSlotPair& feedback) {
const Operator* op = javascript()->LoadProperty(feedback);
return NewNode(op, object, key);
}
Node* AstGraphBuilder::BuildNamedLoad(Node* object, Handle<Name> name,
const VectorSlotPair& feedback,
ContextualMode mode) {
const Operator* op =
javascript()->LoadNamed(MakeUnique(name), feedback, mode);
return NewNode(op, object);
}
Node* AstGraphBuilder::BuildKeyedStore(Node* object, Node* key, Node* value) {
const Operator* op = javascript()->StoreProperty(language_mode());
return NewNode(op, object, key, value);
}
Node* AstGraphBuilder::BuildNamedStore(Node* object, Handle<Name> name,
Node* value) {
const Operator* op =
javascript()->StoreNamed(language_mode(), MakeUnique(name));
return NewNode(op, object, value);
}
Node* AstGraphBuilder::BuildLoadObjectField(Node* object, int offset) { Node* AstGraphBuilder::BuildLoadObjectField(Node* object, int offset) {
return NewNode(jsgraph()->machine()->Load(kMachAnyTagged), object, return NewNode(jsgraph()->machine()->Load(kMachAnyTagged), object,
jsgraph()->IntPtrConstant(offset - kHeapObjectTag)); jsgraph()->IntPtrConstant(offset - kHeapObjectTag));
...@@ -2912,9 +2922,8 @@ Node* AstGraphBuilder::BuildToName(Node* input, BailoutId bailout_id) { ...@@ -2912,9 +2922,8 @@ Node* AstGraphBuilder::BuildToName(Node* input, BailoutId bailout_id) {
Node* AstGraphBuilder::BuildSetHomeObject(Node* value, Node* home_object, Node* AstGraphBuilder::BuildSetHomeObject(Node* value, Node* home_object,
Expression* expr) { Expression* expr) {
if (!FunctionLiteral::NeedsHomeObject(expr)) return value; if (!FunctionLiteral::NeedsHomeObject(expr)) return value;
Unique<Name> name = MakeUnique(isolate()->factory()->home_object_symbol()); Handle<Name> name = isolate()->factory()->home_object_symbol();
const Operator* op = javascript()->StoreNamed(language_mode(), name); Node* store = BuildNamedStore(value, name, home_object);
Node* store = NewNode(op, value, home_object);
PrepareFrameState(store, BailoutId::None()); PrepareFrameState(store, BailoutId::None());
return store; return store;
} }
......
...@@ -224,6 +224,15 @@ class AstGraphBuilder : public AstVisitor { ...@@ -224,6 +224,15 @@ class AstGraphBuilder : public AstVisitor {
const VectorSlotPair& feedback, const VectorSlotPair& feedback,
ContextualMode mode = CONTEXTUAL); ContextualMode mode = CONTEXTUAL);
// Builders for property loads and stores.
Node* BuildKeyedLoad(Node* receiver, Node* key,
const VectorSlotPair& feedback);
Node* BuildNamedLoad(Node* receiver, Handle<Name> name,
const VectorSlotPair& feedback,
ContextualMode mode = NOT_CONTEXTUAL);
Node* BuildKeyedStore(Node* receiver, Node* key, Node* value);
Node* BuildNamedStore(Node* receiver, Handle<Name>, Node* value);
// Builders for accessing the function context. // Builders for accessing the function context.
Node* BuildLoadBuiltinsObject(); Node* BuildLoadBuiltinsObject();
Node* BuildLoadGlobalObject(); Node* BuildLoadGlobalObject();
......
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