Commit 4b4c354b authored by bgeron's avatar bgeron Committed by Commit bot

[turbofan] Refactor js-inlining.cc to use more graph(), jsgraph(), javascript(), common().

BUG=

Review-Url: https://codereview.chromium.org/2211963002
Cr-Commit-Position: refs/heads/master@{#38363}
parent 11d0d16e
...@@ -106,13 +106,13 @@ Reduction JSInliner::InlineCall(Node* call, Node* new_target, Node* context, ...@@ -106,13 +106,13 @@ Reduction JSInliner::InlineCall(Node* call, Node* new_target, Node* context,
Replace(use, new_target); Replace(use, new_target);
} else if (index == inlinee_arity_index) { } else if (index == inlinee_arity_index) {
// The projection is requesting the number of arguments. // The projection is requesting the number of arguments.
Replace(use, jsgraph_->Int32Constant(inliner_inputs - 2)); Replace(use, jsgraph()->Int32Constant(inliner_inputs - 2));
} else if (index == inlinee_context_index) { } else if (index == inlinee_context_index) {
// The projection is requesting the inlinee function context. // The projection is requesting the inlinee function context.
Replace(use, context); Replace(use, context);
} else { } else {
// Call has fewer arguments than required, fill with undefined. // Call has fewer arguments than required, fill with undefined.
Replace(use, jsgraph_->UndefinedConstant()); Replace(use, jsgraph()->UndefinedConstant());
} }
break; break;
} }
...@@ -143,9 +143,8 @@ Reduction JSInliner::InlineCall(Node* call, Node* new_target, Node* context, ...@@ -143,9 +143,8 @@ Reduction JSInliner::InlineCall(Node* call, Node* new_target, Node* context,
case IrOpcode::kDeoptimize: case IrOpcode::kDeoptimize:
case IrOpcode::kTerminate: case IrOpcode::kTerminate:
case IrOpcode::kThrow: case IrOpcode::kThrow:
NodeProperties::MergeControlToEnd(jsgraph_->graph(), jsgraph_->common(), NodeProperties::MergeControlToEnd(graph(), common(), input);
input); Revisit(graph()->end());
Revisit(jsgraph_->graph()->end());
break; break;
default: default:
UNREACHABLE(); UNREACHABLE();
...@@ -159,20 +158,20 @@ Reduction JSInliner::InlineCall(Node* call, Node* new_target, Node* context, ...@@ -159,20 +158,20 @@ Reduction JSInliner::InlineCall(Node* call, Node* new_target, Node* context,
// uses with said value or kill value uses if no value can be returned. // uses with said value or kill value uses if no value can be returned.
if (values.size() > 0) { if (values.size() > 0) {
int const input_count = static_cast<int>(controls.size()); int const input_count = static_cast<int>(controls.size());
Node* control_output = jsgraph_->graph()->NewNode( Node* control_output = graph()->NewNode(common()->Merge(input_count),
jsgraph_->common()->Merge(input_count), input_count, &controls.front()); input_count, &controls.front());
values.push_back(control_output); values.push_back(control_output);
effects.push_back(control_output); effects.push_back(control_output);
Node* value_output = jsgraph_->graph()->NewNode( Node* value_output = graph()->NewNode(
jsgraph_->common()->Phi(MachineRepresentation::kTagged, input_count), common()->Phi(MachineRepresentation::kTagged, input_count),
static_cast<int>(values.size()), &values.front()); static_cast<int>(values.size()), &values.front());
Node* effect_output = jsgraph_->graph()->NewNode( Node* effect_output =
jsgraph_->common()->EffectPhi(input_count), graph()->NewNode(common()->EffectPhi(input_count),
static_cast<int>(effects.size()), &effects.front()); static_cast<int>(effects.size()), &effects.front());
ReplaceWithValue(call, value_output, effect_output, control_output); ReplaceWithValue(call, value_output, effect_output, control_output);
return Changed(value_output); return Changed(value_output);
} else { } else {
ReplaceWithValue(call, call, call, jsgraph_->Dead()); ReplaceWithValue(call, call, call, jsgraph()->Dead());
return Changed(call); return Changed(call);
} }
} }
...@@ -183,24 +182,24 @@ Node* JSInliner::CreateArtificialFrameState(Node* node, Node* outer_frame_state, ...@@ -183,24 +182,24 @@ Node* JSInliner::CreateArtificialFrameState(Node* node, Node* outer_frame_state,
FrameStateType frame_state_type, FrameStateType frame_state_type,
Handle<SharedFunctionInfo> shared) { Handle<SharedFunctionInfo> shared) {
const FrameStateFunctionInfo* state_info = const FrameStateFunctionInfo* state_info =
jsgraph_->common()->CreateFrameStateFunctionInfo( common()->CreateFrameStateFunctionInfo(frame_state_type,
frame_state_type, parameter_count + 1, 0, shared); parameter_count + 1, 0, shared);
const Operator* op = jsgraph_->common()->FrameState( const Operator* op = common()->FrameState(
BailoutId(-1), OutputFrameStateCombine::Ignore(), state_info); BailoutId(-1), OutputFrameStateCombine::Ignore(), state_info);
const Operator* op0 = jsgraph_->common()->StateValues(0); const Operator* op0 = common()->StateValues(0);
Node* node0 = jsgraph_->graph()->NewNode(op0); Node* node0 = graph()->NewNode(op0);
NodeVector params(local_zone_); NodeVector params(local_zone_);
for (int parameter = 0; parameter < parameter_count + 1; ++parameter) { for (int parameter = 0; parameter < parameter_count + 1; ++parameter) {
params.push_back(node->InputAt(1 + parameter)); params.push_back(node->InputAt(1 + parameter));
} }
const Operator* op_param = const Operator* op_param =
jsgraph_->common()->StateValues(static_cast<int>(params.size())); common()->StateValues(static_cast<int>(params.size()));
Node* params_node = jsgraph_->graph()->NewNode( Node* params_node = graph()->NewNode(
op_param, static_cast<int>(params.size()), &params.front()); op_param, static_cast<int>(params.size()), &params.front());
return jsgraph_->graph()->NewNode(op, params_node, node0, node0, return graph()->NewNode(op, params_node, node0, node0,
jsgraph_->UndefinedConstant(), jsgraph()->UndefinedConstant(), node->InputAt(0),
node->InputAt(0), outer_frame_state); outer_frame_state);
} }
Node* JSInliner::CreateTailCallerFrameState(Node* node, Node* frame_state) { Node* JSInliner::CreateTailCallerFrameState(Node* node, Node* frame_state) {
...@@ -221,15 +220,15 @@ Node* JSInliner::CreateTailCallerFrameState(Node* node, Node* frame_state) { ...@@ -221,15 +220,15 @@ Node* JSInliner::CreateTailCallerFrameState(Node* node, Node* frame_state) {
} }
const FrameStateFunctionInfo* state_info = const FrameStateFunctionInfo* state_info =
jsgraph_->common()->CreateFrameStateFunctionInfo( common()->CreateFrameStateFunctionInfo(
FrameStateType::kTailCallerFunction, 0, 0, shared); FrameStateType::kTailCallerFunction, 0, 0, shared);
const Operator* op = jsgraph_->common()->FrameState( const Operator* op = common()->FrameState(
BailoutId(-1), OutputFrameStateCombine::Ignore(), state_info); BailoutId(-1), OutputFrameStateCombine::Ignore(), state_info);
const Operator* op0 = jsgraph_->common()->StateValues(0); const Operator* op0 = common()->StateValues(0);
Node* node0 = jsgraph_->graph()->NewNode(op0); Node* node0 = graph()->NewNode(op0);
return jsgraph_->graph()->NewNode(op, node0, node0, node0, return graph()->NewNode(op, node0, node0, node0,
jsgraph_->UndefinedConstant(), function, jsgraph()->UndefinedConstant(), function,
frame_state); frame_state);
} }
...@@ -417,7 +416,7 @@ Reduction JSInliner::ReduceJSCall(Node* node, Handle<JSFunction> function) { ...@@ -417,7 +416,7 @@ Reduction JSInliner::ReduceJSCall(Node* node, Handle<JSFunction> function) {
} }
Node* frame_state = call.frame_state(); Node* frame_state = call.frame_state();
Node* new_target = jsgraph_->UndefinedConstant(); Node* new_target = jsgraph()->UndefinedConstant();
// Inline {JSCallConstruct} requires some additional magic. // Inline {JSCallConstruct} requires some additional magic.
if (node->opcode() == IrOpcode::kJSCallConstruct) { if (node->opcode() == IrOpcode::kJSCallConstruct) {
...@@ -425,24 +424,24 @@ Reduction JSInliner::ReduceJSCall(Node* node, Handle<JSFunction> function) { ...@@ -425,24 +424,24 @@ Reduction JSInliner::ReduceJSCall(Node* node, Handle<JSFunction> function) {
// constructor dispatch (allocate implicit receiver and check return value). // constructor dispatch (allocate implicit receiver and check return value).
// This models the behavior usually accomplished by our {JSConstructStub}. // This models the behavior usually accomplished by our {JSConstructStub}.
// Note that the context has to be the callers context (input to call node). // Note that the context has to be the callers context (input to call node).
Node* receiver = jsgraph_->UndefinedConstant(); // Implicit receiver. Node* receiver = jsgraph()->UndefinedConstant(); // Implicit receiver.
if (NeedsImplicitReceiver(shared_info)) { if (NeedsImplicitReceiver(shared_info)) {
Node* frame_state_before = NodeProperties::FindFrameStateBefore(node); Node* frame_state_before = NodeProperties::FindFrameStateBefore(node);
Node* effect = NodeProperties::GetEffectInput(node); Node* effect = NodeProperties::GetEffectInput(node);
Node* context = NodeProperties::GetContextInput(node); Node* context = NodeProperties::GetContextInput(node);
Node* create = jsgraph_->graph()->NewNode( Node* create = graph()->NewNode(javascript()->Create(), call.target(),
jsgraph_->javascript()->Create(), call.target(), call.new_target(), call.new_target(), context,
context, frame_state_before, effect); frame_state_before, effect);
NodeProperties::ReplaceEffectInput(node, create); NodeProperties::ReplaceEffectInput(node, create);
// Insert a check of the return value to determine whether the return // Insert a check of the return value to determine whether the return
// value // value
// or the implicit receiver should be selected as a result of the call. // or the implicit receiver should be selected as a result of the call.
Node* check = jsgraph_->graph()->NewNode( Node* check = graph()->NewNode(
jsgraph_->javascript()->CallRuntime(Runtime::kInlineIsJSReceiver, 1), javascript()->CallRuntime(Runtime::kInlineIsJSReceiver, 1), node,
node, context, node, start); context, node, start);
Node* select = jsgraph_->graph()->NewNode( Node* select =
jsgraph_->common()->Select(MachineRepresentation::kTagged), check, graph()->NewNode(common()->Select(MachineRepresentation::kTagged),
node, create); check, node, create);
NodeProperties::ReplaceUses(node, select, check, node, node); NodeProperties::ReplaceUses(node, select, check, node, node);
NodeProperties::ReplaceValueInput(select, node, 1); NodeProperties::ReplaceValueInput(select, node, 1);
NodeProperties::ReplaceValueInput(check, node, 0); NodeProperties::ReplaceValueInput(check, node, 0);
...@@ -455,7 +454,7 @@ Reduction JSInliner::ReduceJSCall(Node* node, Handle<JSFunction> function) { ...@@ -455,7 +454,7 @@ Reduction JSInliner::ReduceJSCall(Node* node, Handle<JSFunction> function) {
// behaves as if we were dealing with a regular function invocation. // behaves as if we were dealing with a regular function invocation.
new_target = call.new_target(); // Retrieve new target value input. new_target = call.new_target(); // Retrieve new target value input.
node->RemoveInput(call.formal_arguments() + 1); // Drop new target. node->RemoveInput(call.formal_arguments() + 1); // Drop new target.
node->InsertInput(jsgraph_->graph()->zone(), 1, receiver); node->InsertInput(graph()->zone(), 1, receiver);
// Insert a construct stub frame into the chain of frame states. This will // Insert a construct stub frame into the chain of frame states. This will
// reconstruct the proper frame when deoptimizing within the constructor. // reconstruct the proper frame when deoptimizing within the constructor.
...@@ -468,7 +467,7 @@ Reduction JSInliner::ReduceJSCall(Node* node, Handle<JSFunction> function) { ...@@ -468,7 +467,7 @@ Reduction JSInliner::ReduceJSCall(Node* node, Handle<JSFunction> function) {
// TODO(turbofan): We might want to load the context from the JSFunction at // TODO(turbofan): We might want to load the context from the JSFunction at
// runtime in case we only know the SharedFunctionInfo once we have dynamic // runtime in case we only know the SharedFunctionInfo once we have dynamic
// type feedback in the compiler. // type feedback in the compiler.
Node* context = jsgraph_->Constant(handle(function->context())); Node* context = jsgraph()->Constant(handle(function->context()));
// Insert a JSConvertReceiver node for sloppy callees. Note that the context // Insert a JSConvertReceiver node for sloppy callees. Note that the context
// passed into this node has to be the callees context (loaded above). Note // passed into this node has to be the callees context (loaded above). Note
...@@ -481,9 +480,9 @@ Reduction JSInliner::ReduceJSCall(Node* node, Handle<JSFunction> function) { ...@@ -481,9 +480,9 @@ Reduction JSInliner::ReduceJSCall(Node* node, Handle<JSFunction> function) {
const CallFunctionParameters& p = CallFunctionParametersOf(node->op()); const CallFunctionParameters& p = CallFunctionParametersOf(node->op());
Node* frame_state_before = NodeProperties::FindFrameStateBefore(node); Node* frame_state_before = NodeProperties::FindFrameStateBefore(node);
Node* effect = NodeProperties::GetEffectInput(node); Node* effect = NodeProperties::GetEffectInput(node);
Node* convert = jsgraph_->graph()->NewNode( Node* convert = graph()->NewNode(
jsgraph_->javascript()->ConvertReceiver(p.convert_mode()), javascript()->ConvertReceiver(p.convert_mode()), call.receiver(),
call.receiver(), context, frame_state_before, effect, start); context, frame_state_before, effect, start);
NodeProperties::ReplaceValueInput(node, convert, 1); NodeProperties::ReplaceValueInput(node, convert, 1);
NodeProperties::ReplaceEffectInput(node, convert); NodeProperties::ReplaceEffectInput(node, convert);
} }
...@@ -519,6 +518,12 @@ Reduction JSInliner::ReduceJSCall(Node* node, Handle<JSFunction> function) { ...@@ -519,6 +518,12 @@ Reduction JSInliner::ReduceJSCall(Node* node, Handle<JSFunction> function) {
Graph* JSInliner::graph() const { return jsgraph()->graph(); } Graph* JSInliner::graph() const { return jsgraph()->graph(); }
JSOperatorBuilder* JSInliner::javascript() const {
return jsgraph()->javascript();
}
CommonOperatorBuilder* JSInliner::common() const { return jsgraph()->common(); }
} // namespace compiler } // namespace compiler
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
...@@ -36,6 +36,8 @@ class JSInliner final : public AdvancedReducer { ...@@ -36,6 +36,8 @@ class JSInliner final : public AdvancedReducer {
Reduction ReduceJSCall(Node* node, Handle<JSFunction> function); Reduction ReduceJSCall(Node* node, Handle<JSFunction> function);
private: private:
CommonOperatorBuilder* common() const;
JSOperatorBuilder* javascript() const;
Graph* graph() const; Graph* graph() const;
JSGraph* jsgraph() const { return jsgraph_; } JSGraph* jsgraph() const { return jsgraph_; }
......
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