Commit 8dfe1855 authored by mstarzinger's avatar mstarzinger Committed by Commit bot

[turbofan] Pass scope infos as static operator parameters.

This changes the operators for JSCreate[Block|Script]Context to take
their ScopeInfo as a static parameter as opposed to a value input and
in turn allows for easier access to that parameter during lowerings.

R=jarin@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#31009}
parent f20d6461
......@@ -3132,9 +3132,9 @@ Node* AstGraphBuilder::BuildLocalScriptContext(Scope* scope) {
DCHECK(scope->is_script_scope());
// Allocate a new local context.
const Operator* op = javascript()->CreateScriptContext();
Node* scope_info = jsgraph()->Constant(scope->GetScopeInfo(isolate()));
Node* local_context = NewNode(op, GetFunctionClosure(), scope_info);
Handle<ScopeInfo> scope_info = scope->GetScopeInfo(isolate());
const Operator* op = javascript()->CreateScriptContext(scope_info);
Node* local_context = NewNode(op, GetFunctionClosure());
PrepareFrameState(local_context, BailoutId::Prologue());
return local_context;
......@@ -3145,9 +3145,9 @@ Node* AstGraphBuilder::BuildLocalBlockContext(Scope* scope) {
DCHECK(scope->is_block_scope());
// Allocate a new local context.
const Operator* op = javascript()->CreateBlockContext();
Node* scope_info = jsgraph()->Constant(scope->GetScopeInfo(isolate()));
Node* local_context = NewNode(op, scope_info, GetFunctionClosureForContext());
Handle<ScopeInfo> scope_info = scope->GetScopeInfo(isolate());
const Operator* op = javascript()->CreateBlockContext(scope_info);
Node* local_context = NewNode(op, GetFunctionClosureForContext());
return local_context;
}
......
......@@ -114,21 +114,12 @@ REPLACE_COMPARE_IC_CALL_WITH_LANGUAGE_MODE(JSGreaterThanOrEqual, Token::GTE)
void JSGenericLowering::Lower##op(Node* node) { \
ReplaceWithRuntimeCall(node, fun); \
}
REPLACE_RUNTIME_CALL(JSCreate, Runtime::kAbort)
REPLACE_RUNTIME_CALL(JSCreateFunctionContext, Runtime::kNewFunctionContext)
REPLACE_RUNTIME_CALL(JSCreateWithContext, Runtime::kPushWithContext)
REPLACE_RUNTIME_CALL(JSCreateBlockContext, Runtime::kPushBlockContext)
REPLACE_RUNTIME_CALL(JSCreateModuleContext, Runtime::kPushModuleContext)
REPLACE_RUNTIME_CALL(JSCreateScriptContext, Runtime::kNewScriptContext)
#undef REPLACE_RUNTIME
#define REPLACE_UNIMPLEMENTED(op) \
void JSGenericLowering::Lower##op(Node* node) { UNIMPLEMENTED(); }
REPLACE_UNIMPLEMENTED(JSYield)
#undef REPLACE_UNIMPLEMENTED
static CallDescriptor::Flags FlagsForNode(Node* node) {
CallDescriptor::Flags result = CallDescriptor::kNoFlags;
if (OperatorProperties::GetFrameStateInputCount(node->op()) > 0) {
......@@ -491,6 +482,9 @@ void JSGenericLowering::LowerJSLoadDynamicContext(Node* node) {
}
void JSGenericLowering::LowerJSCreate(Node* node) { UNIMPLEMENTED(); }
void JSGenericLowering::LowerJSCreateArguments(Node* node) {
const CreateArgumentsParameters& p = CreateArgumentsParametersOf(node->op());
switch (p.type()) {
......@@ -537,6 +531,20 @@ void JSGenericLowering::LowerJSCreateCatchContext(Node* node) {
}
void JSGenericLowering::LowerJSCreateBlockContext(Node* node) {
Handle<ScopeInfo> scope_info = OpParameter<Handle<ScopeInfo>>(node);
node->InsertInput(zone(), 0, jsgraph()->HeapConstant(scope_info));
ReplaceWithRuntimeCall(node, Runtime::kPushBlockContext);
}
void JSGenericLowering::LowerJSCreateScriptContext(Node* node) {
Handle<ScopeInfo> scope_info = OpParameter<Handle<ScopeInfo>>(node);
node->InsertInput(zone(), 1, jsgraph()->HeapConstant(scope_info));
ReplaceWithRuntimeCall(node, Runtime::kNewScriptContext);
}
void JSGenericLowering::LowerJSCallConstruct(Node* node) {
int arity = OpParameter<int>(node);
CallConstructStub stub(isolate(), SUPER_CONSTRUCTOR_CALL);
......@@ -786,6 +794,9 @@ void JSGenericLowering::LowerJSForInStep(Node* node) {
}
void JSGenericLowering::LowerJSYield(Node* node) { UNIMPLEMENTED(); }
void JSGenericLowering::LowerJSStackCheck(Node* node) {
Node* effect = NodeProperties::GetEffectInput(node);
Node* control = NodeProperties::GetControlInput(node);
......
......@@ -474,9 +474,7 @@ const CreateClosureParameters& CreateClosureParametersOf(const Operator* op) {
V(StackCheck, Operator::kNoProperties, 0, 0) \
V(CreateFunctionContext, Operator::kNoProperties, 1, 1) \
V(CreateWithContext, Operator::kNoProperties, 2, 1) \
V(CreateBlockContext, Operator::kNoProperties, 2, 1) \
V(CreateModuleContext, Operator::kNoProperties, 2, 1) \
V(CreateScriptContext, Operator::kNoProperties, 2, 1)
V(CreateModuleContext, Operator::kNoProperties, 2, 1)
#define CACHED_OP_LIST_WITH_LANGUAGE_MODE(V) \
......@@ -785,6 +783,28 @@ const Operator* JSOperatorBuilder::CreateCatchContext(
name); // parameter
}
const Operator* JSOperatorBuilder::CreateBlockContext(
const Handle<ScopeInfo>& scpope_info) {
return new (zone()) Operator1<Handle<ScopeInfo>, Handle<ScopeInfo>::equal_to,
Handle<ScopeInfo>::hash>( // --
IrOpcode::kJSCreateBlockContext, Operator::kNoProperties, // opcode
"JSCreateBlockContext", // name
1, 1, 1, 1, 1, 2, // counts
scpope_info); // parameter
}
const Operator* JSOperatorBuilder::CreateScriptContext(
const Handle<ScopeInfo>& scpope_info) {
return new (zone()) Operator1<Handle<ScopeInfo>, Handle<ScopeInfo>::equal_to,
Handle<ScopeInfo>::hash>( // --
IrOpcode::kJSCreateScriptContext, Operator::kNoProperties, // opcode
"JSCreateScriptContext", // name
1, 1, 1, 1, 1, 2, // counts
scpope_info); // parameter
}
} // namespace compiler
} // namespace internal
} // namespace v8
......@@ -559,13 +559,12 @@ class JSOperatorBuilder final : public ZoneObject {
const Operator* StackCheck();
// TODO(titzer): nail down the static parts of each of these context flavors.
const Operator* CreateFunctionContext();
const Operator* CreateCatchContext(const Handle<String>& name);
const Operator* CreateWithContext();
const Operator* CreateBlockContext();
const Operator* CreateBlockContext(const Handle<ScopeInfo>& scpope_info);
const Operator* CreateModuleContext();
const Operator* CreateScriptContext();
const Operator* CreateScriptContext(const Handle<ScopeInfo>& scpope_info);
private:
Zone* zone() const { return zone_; }
......
......@@ -1296,16 +1296,15 @@ Reduction JSTypedLowering::ReduceJSCreateWithContext(Node* node) {
Reduction JSTypedLowering::ReduceJSCreateBlockContext(Node* node) {
DCHECK_EQ(IrOpcode::kJSCreateBlockContext, node->opcode());
Node* const input = NodeProperties::GetValueInput(node, 0);
HeapObjectMatcher minput(input);
DCHECK(minput.HasValue()); // TODO(mstarzinger): Make ScopeInfo static.
int context_length = Handle<ScopeInfo>::cast(minput.Value())->ContextLength();
Handle<ScopeInfo> scope_info = OpParameter<Handle<ScopeInfo>>(node);
int context_length = scope_info->ContextLength();
if (FLAG_turbo_allocate && context_length < kBlockContextAllocationLimit) {
// JSCreateBlockContext(s:scope[length < limit], f)
Node* const effect = NodeProperties::GetEffectInput(node);
Node* const control = NodeProperties::GetControlInput(node);
Node* const closure = NodeProperties::GetValueInput(node, 1);
Node* const context = NodeProperties::GetContextInput(node);
Node* const extension = jsgraph()->Constant(scope_info);
Node* const load = graph()->NewNode(
simplified()->LoadField(
AccessBuilder::ForContextSlot(Context::GLOBAL_OBJECT_INDEX)),
......@@ -1315,7 +1314,7 @@ Reduction JSTypedLowering::ReduceJSCreateBlockContext(Node* node) {
a.AllocateArray(context_length, factory()->block_context_map());
a.Store(AccessBuilder::ForContextSlot(Context::CLOSURE_INDEX), closure);
a.Store(AccessBuilder::ForContextSlot(Context::PREVIOUS_INDEX), context);
a.Store(AccessBuilder::ForContextSlot(Context::EXTENSION_INDEX), input);
a.Store(AccessBuilder::ForContextSlot(Context::EXTENSION_INDEX), extension);
a.Store(AccessBuilder::ForContextSlot(Context::GLOBAL_OBJECT_INDEX), load);
for (int i = Context::MIN_CONTEXT_SLOTS; i < context_length; ++i) {
a.Store(AccessBuilder::ForContextSlot(i), jsgraph()->TheHoleConstant());
......
......@@ -217,6 +217,13 @@ inline Handle<String> const& OpParameter(const Operator* op) {
->parameter();
}
template <>
inline Handle<ScopeInfo> const& OpParameter(const Operator* op) {
return reinterpret_cast<
const Operator1<Handle<ScopeInfo>, Handle<ScopeInfo>::equal_to,
Handle<ScopeInfo>::hash>*>(op)->parameter();
}
} // namespace compiler
} // namespace internal
} // namespace v8
......
......@@ -201,11 +201,12 @@ TEST_F(JSContextRelaxationTest,
Node* const input1 = Parameter(1);
Node* const context = Parameter(2);
Node* const outer_context = Parameter(3);
const Operator* op = javascript()->CreateBlockContext();
Handle<ScopeInfo> scope_info = Handle<ScopeInfo>::null();
const Operator* op = javascript()->CreateBlockContext(scope_info);
Node* const effect = graph()->start();
Node* const control = graph()->start();
Node* nested_context = graph()->NewNode(
op, graph()->start(), graph()->start(), outer_context, effect, control);
Node* nested_context =
graph()->NewNode(op, graph()->start(), outer_context, effect, control);
Node* const frame_state_2 =
ShallowFrameStateChain(nested_context, CALL_MAINTAINS_NATIVE_CONTEXT);
Node* node =
......@@ -224,14 +225,14 @@ TEST_F(JSContextRelaxationTest,
Node* const input1 = Parameter(1);
Node* const context = Parameter(2);
Node* const outer_context = Parameter(3);
const Operator* op = javascript()->CreateScriptContext();
Handle<ScopeInfo> scope_info = Handle<ScopeInfo>::null();
const Operator* op = javascript()->CreateScriptContext(scope_info);
Node* const frame_state_1 =
ShallowFrameStateChain(outer_context, CALL_MAINTAINS_NATIVE_CONTEXT);
Node* const effect = graph()->start();
Node* const control = graph()->start();
Node* nested_context =
graph()->NewNode(op, graph()->start(), graph()->start(), outer_context,
frame_state_1, effect, control);
Node* nested_context = graph()->NewNode(op, graph()->start(), outer_context,
frame_state_1, effect, control);
Node* const frame_state_2 =
ShallowFrameStateChain(nested_context, CALL_MAINTAINS_NATIVE_CONTEXT);
Node* node =
......
......@@ -84,9 +84,7 @@ const SharedOperator kSharedOperators[] = {
SHARED(InstanceOf, Operator::kNoProperties, 2, 1, 1, 1, 1, 1, 2),
SHARED(CreateFunctionContext, Operator::kNoProperties, 1, 0, 1, 1, 1, 1, 2),
SHARED(CreateWithContext, Operator::kNoProperties, 2, 1, 1, 1, 1, 1, 2),
SHARED(CreateBlockContext, Operator::kNoProperties, 2, 0, 1, 1, 1, 1, 2),
SHARED(CreateModuleContext, Operator::kNoProperties, 2, 0, 1, 1, 1, 1, 2),
SHARED(CreateScriptContext, Operator::kNoProperties, 2, 1, 1, 1, 1, 1, 2)
#undef SHARED
};
......
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