2014-08-20 13:05:03 +00:00
|
|
|
// Copyright 2014 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2015-02-20 10:11:45 +00:00
|
|
|
#include "src/compiler/js-inlining.h"
|
|
|
|
|
2014-10-21 12:16:37 +00:00
|
|
|
#include "src/ast.h"
|
|
|
|
#include "src/ast-numbering.h"
|
2015-02-20 10:11:45 +00:00
|
|
|
#include "src/compiler/all-nodes.h"
|
2014-08-20 13:05:03 +00:00
|
|
|
#include "src/compiler/ast-graph-builder.h"
|
|
|
|
#include "src/compiler/common-operator.h"
|
2015-03-10 08:37:16 +00:00
|
|
|
#include "src/compiler/js-context-specialization.h"
|
2014-08-20 13:05:03 +00:00
|
|
|
#include "src/compiler/js-operator.h"
|
|
|
|
#include "src/compiler/node-matchers.h"
|
2015-01-29 09:17:45 +00:00
|
|
|
#include "src/compiler/node-properties.h"
|
2015-03-09 08:37:01 +00:00
|
|
|
#include "src/compiler/operator-properties.h"
|
2014-09-18 08:56:52 +00:00
|
|
|
#include "src/full-codegen.h"
|
2014-08-20 13:05:03 +00:00
|
|
|
#include "src/parser.h"
|
|
|
|
#include "src/rewriter.h"
|
|
|
|
#include "src/scopes.h"
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace compiler {
|
|
|
|
|
2015-03-17 18:51:08 +00:00
|
|
|
#define TRACE(...) \
|
|
|
|
do { \
|
|
|
|
if (FLAG_trace_turbo_inlining) PrintF(__VA_ARGS__); \
|
|
|
|
} while (false)
|
|
|
|
|
2015-02-17 10:30:54 +00:00
|
|
|
|
|
|
|
// Provides convenience accessors for calls to JS functions.
|
|
|
|
class JSCallFunctionAccessor {
|
2014-08-20 13:05:03 +00:00
|
|
|
public:
|
2015-02-17 10:30:54 +00:00
|
|
|
explicit JSCallFunctionAccessor(Node* call) : call_(call) {
|
|
|
|
DCHECK_EQ(IrOpcode::kJSCallFunction, call->opcode());
|
|
|
|
}
|
2014-08-20 13:05:03 +00:00
|
|
|
|
2015-02-17 10:30:54 +00:00
|
|
|
Node* jsfunction() { return call_->InputAt(0); }
|
|
|
|
|
|
|
|
Node* receiver() { return call_->InputAt(1); }
|
|
|
|
|
|
|
|
Node* formal_argument(size_t index) {
|
|
|
|
DCHECK(index < formal_arguments());
|
|
|
|
return call_->InputAt(static_cast<int>(2 + index));
|
2014-08-20 13:05:03 +00:00
|
|
|
}
|
|
|
|
|
2015-02-17 10:30:54 +00:00
|
|
|
size_t formal_arguments() {
|
|
|
|
// {value_inputs} includes jsfunction and receiver.
|
|
|
|
size_t value_inputs = call_->op()->ValueInputCount();
|
|
|
|
DCHECK_GE(call_->InputCount(), 2);
|
|
|
|
return value_inputs - 2;
|
|
|
|
}
|
|
|
|
|
2015-03-09 08:37:01 +00:00
|
|
|
Node* frame_state() { return NodeProperties::GetFrameStateInput(call_, 0); }
|
2015-02-17 10:30:54 +00:00
|
|
|
|
2014-08-20 13:05:03 +00:00
|
|
|
private:
|
2015-02-17 10:30:54 +00:00
|
|
|
Node* call_;
|
2014-08-20 13:05:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-02-20 10:11:45 +00:00
|
|
|
namespace {
|
2014-08-20 13:05:03 +00:00
|
|
|
|
2015-05-11 17:20:43 +00:00
|
|
|
// A facade on a JSFunction's graph to facilitate inlining. It assumes
|
2014-08-20 13:05:03 +00:00
|
|
|
// that the function graph has only one return statement, and provides
|
|
|
|
// {UnifyReturn} to convert a function graph to that end.
|
|
|
|
class Inlinee {
|
|
|
|
public:
|
2014-09-12 11:06:37 +00:00
|
|
|
Inlinee(Node* start, Node* end) : start_(start), end_(end) {}
|
2014-08-20 13:05:03 +00:00
|
|
|
|
|
|
|
// Returns the last regular control node, that is
|
|
|
|
// the last control node before the end node.
|
|
|
|
Node* end_block() { return NodeProperties::GetControlInput(unique_return()); }
|
|
|
|
|
|
|
|
// Return the effect output of the graph,
|
|
|
|
// that is the effect input of the return statement of the inlinee.
|
|
|
|
Node* effect_output() {
|
|
|
|
return NodeProperties::GetEffectInput(unique_return());
|
|
|
|
}
|
|
|
|
// Return the value output of the graph,
|
|
|
|
// that is the value input of the return statement of the inlinee.
|
|
|
|
Node* value_output() {
|
|
|
|
return NodeProperties::GetValueInput(unique_return(), 0);
|
|
|
|
}
|
2015-03-03 13:09:49 +00:00
|
|
|
// Return the control output of the graph,
|
|
|
|
// that is the control input of the return statement of the inlinee.
|
|
|
|
Node* control_output() {
|
|
|
|
return NodeProperties::GetControlInput(unique_return(), 0);
|
|
|
|
}
|
2014-08-20 13:05:03 +00:00
|
|
|
// Return the unique return statement of the graph.
|
|
|
|
Node* unique_return() {
|
2014-09-12 11:06:37 +00:00
|
|
|
Node* unique_return = NodeProperties::GetControlInput(end_);
|
2014-08-20 13:05:03 +00:00
|
|
|
DCHECK_EQ(IrOpcode::kReturn, unique_return->opcode());
|
|
|
|
return unique_return;
|
|
|
|
}
|
2014-09-18 08:56:52 +00:00
|
|
|
|
|
|
|
// Counts JSFunction, Receiver, arguments, context but not effect, control.
|
2014-11-18 15:45:22 +00:00
|
|
|
size_t total_parameters() { return start_->op()->ValueOutputCount(); }
|
2014-09-18 08:56:52 +00:00
|
|
|
|
|
|
|
// Counts only formal parameters.
|
|
|
|
size_t formal_parameters() {
|
2015-01-30 09:29:25 +00:00
|
|
|
DCHECK_GE(total_parameters(), 3u);
|
2014-09-18 08:56:52 +00:00
|
|
|
return total_parameters() - 3;
|
|
|
|
}
|
|
|
|
|
2014-08-20 13:05:03 +00:00
|
|
|
// Inline this graph at {call}, use {jsgraph} and its zone to create
|
|
|
|
// any new nodes.
|
2015-03-10 08:37:16 +00:00
|
|
|
Reduction InlineAtCall(JSGraph* jsgraph, Node* call);
|
2014-09-12 11:06:37 +00:00
|
|
|
|
2014-08-20 13:05:03 +00:00
|
|
|
// Ensure that only a single return reaches the end node.
|
2014-09-12 11:06:37 +00:00
|
|
|
static void UnifyReturn(JSGraph* jsgraph);
|
2014-08-20 13:05:03 +00:00
|
|
|
|
|
|
|
private:
|
2014-09-12 11:06:37 +00:00
|
|
|
Node* start_;
|
|
|
|
Node* end_;
|
2014-08-20 13:05:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-12 11:06:37 +00:00
|
|
|
void Inlinee::UnifyReturn(JSGraph* jsgraph) {
|
|
|
|
Graph* graph = jsgraph->graph();
|
2014-08-20 13:05:03 +00:00
|
|
|
|
|
|
|
Node* final_merge = NodeProperties::GetControlInput(graph->end(), 0);
|
|
|
|
if (final_merge->opcode() == IrOpcode::kReturn) {
|
|
|
|
// nothing to do
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
DCHECK_EQ(IrOpcode::kMerge, final_merge->opcode());
|
|
|
|
|
2014-10-29 18:46:44 +00:00
|
|
|
int predecessors = final_merge->op()->ControlInputCount();
|
2014-08-20 13:05:03 +00:00
|
|
|
|
2014-09-12 11:06:37 +00:00
|
|
|
const Operator* op_phi = jsgraph->common()->Phi(kMachAnyTagged, predecessors);
|
|
|
|
const Operator* op_ephi = jsgraph->common()->EffectPhi(predecessors);
|
|
|
|
|
|
|
|
NodeVector values(jsgraph->zone());
|
|
|
|
NodeVector effects(jsgraph->zone());
|
2014-08-20 13:05:03 +00:00
|
|
|
// Iterate over all control flow predecessors,
|
|
|
|
// which must be return statements.
|
2014-12-02 14:38:55 +00:00
|
|
|
for (Edge edge : final_merge->input_edges()) {
|
|
|
|
Node* input = edge.to();
|
2014-08-20 13:05:03 +00:00
|
|
|
switch (input->opcode()) {
|
|
|
|
case IrOpcode::kReturn:
|
|
|
|
values.push_back(NodeProperties::GetValueInput(input, 0));
|
|
|
|
effects.push_back(NodeProperties::GetEffectInput(input));
|
2014-12-02 14:38:55 +00:00
|
|
|
edge.UpdateTo(NodeProperties::GetControlInput(input));
|
2015-03-24 12:40:01 +00:00
|
|
|
input->NullAllInputs();
|
2014-08-20 13:05:03 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
values.push_back(final_merge);
|
|
|
|
effects.push_back(final_merge);
|
|
|
|
Node* phi =
|
|
|
|
graph->NewNode(op_phi, static_cast<int>(values.size()), &values.front());
|
|
|
|
Node* ephi = graph->NewNode(op_ephi, static_cast<int>(effects.size()),
|
|
|
|
&effects.front());
|
|
|
|
Node* new_return =
|
2014-09-12 11:06:37 +00:00
|
|
|
graph->NewNode(jsgraph->common()->Return(), phi, ephi, final_merge);
|
2014-08-20 13:05:03 +00:00
|
|
|
graph->end()->ReplaceInput(0, new_return);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-02-20 10:11:45 +00:00
|
|
|
class CopyVisitor {
|
2014-09-12 11:06:37 +00:00
|
|
|
public:
|
|
|
|
CopyVisitor(Graph* source_graph, Graph* target_graph, Zone* temp_zone)
|
2015-02-20 10:11:45 +00:00
|
|
|
: sentinel_op_(IrOpcode::kDead, Operator::kNoProperties, "Sentinel", 0, 0,
|
|
|
|
0, 0, 0, 0),
|
|
|
|
sentinel_(target_graph->NewNode(&sentinel_op_)),
|
|
|
|
copies_(source_graph->NodeCount(), sentinel_, temp_zone),
|
2014-09-12 11:06:37 +00:00
|
|
|
source_graph_(source_graph),
|
|
|
|
target_graph_(target_graph),
|
2015-02-20 10:11:45 +00:00
|
|
|
temp_zone_(temp_zone) {}
|
|
|
|
|
|
|
|
Node* GetCopy(Node* orig) { return copies_[orig->id()]; }
|
2014-09-12 11:06:37 +00:00
|
|
|
|
2015-02-20 10:11:45 +00:00
|
|
|
void CopyGraph() {
|
2014-09-12 11:06:37 +00:00
|
|
|
NodeVector inputs(temp_zone_);
|
2015-02-20 10:11:45 +00:00
|
|
|
// TODO(bmeurer): AllNodes should be turned into something like
|
|
|
|
// Graph::CollectNodesReachableFromEnd() and the gray set stuff should be
|
|
|
|
// removed since it's only needed by the visualizer.
|
|
|
|
AllNodes all(temp_zone_, source_graph_);
|
|
|
|
// Copy all nodes reachable from end.
|
|
|
|
for (Node* orig : all.live) {
|
|
|
|
Node* copy = GetCopy(orig);
|
|
|
|
if (copy != sentinel_) {
|
|
|
|
// Mapping already exists.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// Copy the node.
|
|
|
|
inputs.clear();
|
|
|
|
for (Node* input : orig->inputs()) inputs.push_back(copies_[input->id()]);
|
|
|
|
copy = target_graph_->NewNode(orig->op(), orig->InputCount(),
|
|
|
|
inputs.empty() ? nullptr : &inputs[0]);
|
|
|
|
copies_[orig->id()] = copy;
|
2014-09-12 11:06:37 +00:00
|
|
|
}
|
2015-02-20 10:11:45 +00:00
|
|
|
// For missing inputs.
|
|
|
|
for (Node* orig : all.live) {
|
|
|
|
Node* copy = copies_[orig->id()];
|
|
|
|
for (int i = 0; i < copy->InputCount(); ++i) {
|
|
|
|
Node* input = copy->InputAt(i);
|
|
|
|
if (input == sentinel_) {
|
|
|
|
copy->ReplaceInput(i, GetCopy(orig->InputAt(i)));
|
|
|
|
}
|
|
|
|
}
|
2014-09-12 11:06:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-20 10:11:45 +00:00
|
|
|
const NodeVector& copies() const { return copies_; }
|
2014-09-12 11:06:37 +00:00
|
|
|
|
|
|
|
private:
|
2015-02-20 10:11:45 +00:00
|
|
|
Operator const sentinel_op_;
|
|
|
|
Node* const sentinel_;
|
2014-09-12 11:06:37 +00:00
|
|
|
NodeVector copies_;
|
2015-02-20 10:11:45 +00:00
|
|
|
Graph* const source_graph_;
|
|
|
|
Graph* const target_graph_;
|
|
|
|
Zone* const temp_zone_;
|
2014-09-12 11:06:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-03-10 08:37:16 +00:00
|
|
|
Reduction Inlinee::InlineAtCall(JSGraph* jsgraph, Node* call) {
|
2014-08-28 12:18:25 +00:00
|
|
|
// The scheduler is smart enough to place our code; we just ensure {control}
|
2015-03-09 13:01:30 +00:00
|
|
|
// becomes the control input of the start of the inlinee, and {effect} becomes
|
|
|
|
// the effect input of the start of the inlinee.
|
2014-08-20 13:05:03 +00:00
|
|
|
Node* control = NodeProperties::GetControlInput(call);
|
2015-03-09 13:01:30 +00:00
|
|
|
Node* effect = NodeProperties::GetEffectInput(call);
|
2014-08-20 13:05:03 +00:00
|
|
|
|
|
|
|
// Context is last argument.
|
2014-09-18 08:56:52 +00:00
|
|
|
int inlinee_context_index = static_cast<int>(total_parameters()) - 1;
|
2014-08-20 13:05:03 +00:00
|
|
|
// {inliner_inputs} counts JSFunction, Receiver, arguments, but not
|
|
|
|
// context, effect, control.
|
2014-10-29 18:46:44 +00:00
|
|
|
int inliner_inputs = call->op()->ValueInputCount();
|
2014-08-20 13:05:03 +00:00
|
|
|
// Iterate over all uses of the start node.
|
2014-12-02 14:38:55 +00:00
|
|
|
for (Edge edge : start_->use_edges()) {
|
|
|
|
Node* use = edge.from();
|
2014-08-20 13:05:03 +00:00
|
|
|
switch (use->opcode()) {
|
|
|
|
case IrOpcode::kParameter: {
|
2015-04-22 11:34:43 +00:00
|
|
|
int index = 1 + ParameterIndexOf(use->op());
|
2014-08-20 13:05:03 +00:00
|
|
|
if (index < inliner_inputs && index < inlinee_context_index) {
|
|
|
|
// There is an input from the call, and the index is a value
|
|
|
|
// projection but not the context, so rewire the input.
|
2014-12-02 14:38:55 +00:00
|
|
|
NodeProperties::ReplaceWithValue(use, call->InputAt(index));
|
2014-08-20 13:05:03 +00:00
|
|
|
} else if (index == inlinee_context_index) {
|
2015-03-10 08:37:16 +00:00
|
|
|
// TODO(turbofan): We always context specialize inlinees currently, so
|
|
|
|
// we should never get here.
|
|
|
|
UNREACHABLE();
|
2014-08-20 13:05:03 +00:00
|
|
|
} else if (index < inlinee_context_index) {
|
|
|
|
// Call has fewer arguments than required, fill with undefined.
|
2014-12-02 14:38:55 +00:00
|
|
|
NodeProperties::ReplaceWithValue(use, jsgraph->UndefinedConstant());
|
2014-08-20 13:05:03 +00:00
|
|
|
} else {
|
|
|
|
// We got too many arguments, discard for now.
|
|
|
|
// TODO(sigurds): Fix to treat arguments array correctly.
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2014-12-02 14:38:55 +00:00
|
|
|
if (NodeProperties::IsEffectEdge(edge)) {
|
2015-03-09 13:01:30 +00:00
|
|
|
edge.UpdateTo(effect);
|
2014-12-02 14:38:55 +00:00
|
|
|
} else if (NodeProperties::IsControlEdge(edge)) {
|
|
|
|
edge.UpdateTo(control);
|
2014-08-20 13:05:03 +00:00
|
|
|
} else {
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-09 13:01:30 +00:00
|
|
|
NodeProperties::ReplaceWithValue(call, value_output(), effect_output(),
|
|
|
|
control_output());
|
2015-03-03 13:09:49 +00:00
|
|
|
|
2015-02-17 10:30:54 +00:00
|
|
|
return Reducer::Replace(value_output());
|
2014-08-20 13:05:03 +00:00
|
|
|
}
|
|
|
|
|
2015-02-20 10:11:45 +00:00
|
|
|
} // namespace
|
|
|
|
|
2014-08-20 13:05:03 +00:00
|
|
|
|
2014-09-18 08:56:52 +00:00
|
|
|
void JSInliner::AddClosureToFrameState(Node* frame_state,
|
|
|
|
Handle<JSFunction> jsfunction) {
|
|
|
|
FrameStateCallInfo call_info = OpParameter<FrameStateCallInfo>(frame_state);
|
|
|
|
const Operator* op = jsgraph_->common()->FrameState(
|
|
|
|
FrameStateType::JS_FRAME, call_info.bailout_id(),
|
|
|
|
call_info.state_combine(), jsfunction);
|
|
|
|
frame_state->set_op(op);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Node* JSInliner::CreateArgumentsAdaptorFrameState(JSCallFunctionAccessor* call,
|
|
|
|
Handle<JSFunction> jsfunction,
|
|
|
|
Zone* temp_zone) {
|
2014-09-29 13:37:58 +00:00
|
|
|
const Operator* op = jsgraph_->common()->FrameState(
|
|
|
|
FrameStateType::ARGUMENTS_ADAPTOR, BailoutId(-1),
|
|
|
|
OutputFrameStateCombine::Ignore(), jsfunction);
|
2014-09-18 08:56:52 +00:00
|
|
|
const Operator* op0 = jsgraph_->common()->StateValues(0);
|
|
|
|
Node* node0 = jsgraph_->graph()->NewNode(op0);
|
|
|
|
NodeVector params(temp_zone);
|
|
|
|
params.push_back(call->receiver());
|
|
|
|
for (size_t argument = 0; argument != call->formal_arguments(); ++argument) {
|
|
|
|
params.push_back(call->formal_argument(argument));
|
|
|
|
}
|
|
|
|
const Operator* op_param =
|
|
|
|
jsgraph_->common()->StateValues(static_cast<int>(params.size()));
|
|
|
|
Node* params_node = jsgraph_->graph()->NewNode(
|
|
|
|
op_param, static_cast<int>(params.size()), ¶ms.front());
|
|
|
|
return jsgraph_->graph()->NewNode(op, params_node, node0, node0,
|
|
|
|
jsgraph_->UndefinedConstant(),
|
|
|
|
call->frame_state());
|
|
|
|
}
|
|
|
|
|
2014-08-20 13:05:03 +00:00
|
|
|
|
2015-02-20 10:11:45 +00:00
|
|
|
Reduction JSInliner::Reduce(Node* node) {
|
|
|
|
if (node->opcode() != IrOpcode::kJSCallFunction) return NoChange();
|
|
|
|
|
|
|
|
JSCallFunctionAccessor call(node);
|
|
|
|
HeapObjectMatcher<JSFunction> match(call.jsfunction());
|
|
|
|
if (!match.HasValue()) return NoChange();
|
|
|
|
|
|
|
|
Handle<JSFunction> function = match.Value().handle();
|
2015-03-09 08:05:24 +00:00
|
|
|
if (!function->IsJSFunction()) return NoChange();
|
|
|
|
if (mode_ == kBuiltinsInlining && !function->shared()->inline_builtin()) {
|
|
|
|
return NoChange();
|
|
|
|
}
|
2015-02-20 10:11:45 +00:00
|
|
|
|
2015-03-24 14:17:05 +00:00
|
|
|
Zone zone;
|
|
|
|
ParseInfo parse_info(&zone, function);
|
|
|
|
CompilationInfo info(&parse_info);
|
2015-02-17 10:30:54 +00:00
|
|
|
|
2015-03-09 14:51:13 +00:00
|
|
|
if (!Compiler::ParseAndAnalyze(info.parse_info())) return NoChange();
|
2015-02-17 10:30:54 +00:00
|
|
|
if (!Compiler::EnsureDeoptimizationSupport(&info)) return NoChange();
|
2014-08-20 13:05:03 +00:00
|
|
|
|
2015-02-04 09:34:05 +00:00
|
|
|
if (info.scope()->arguments() != NULL && is_sloppy(info.language_mode())) {
|
2014-08-20 13:05:03 +00:00
|
|
|
// For now do not inline functions that use their arguments array.
|
2015-03-17 18:51:08 +00:00
|
|
|
TRACE("Not Inlining %s into %s because inlinee uses arguments array\n",
|
|
|
|
function->shared()->DebugName()->ToCString().get(),
|
|
|
|
info_->shared_info()->DebugName()->ToCString().get());
|
2015-02-17 10:30:54 +00:00
|
|
|
return NoChange();
|
2014-08-20 13:05:03 +00:00
|
|
|
}
|
|
|
|
|
2015-03-17 18:51:08 +00:00
|
|
|
TRACE("Inlining %s into %s\n",
|
|
|
|
function->shared()->DebugName()->ToCString().get(),
|
|
|
|
info_->shared_info()->DebugName()->ToCString().get());
|
2014-08-20 13:05:03 +00:00
|
|
|
|
2014-09-12 11:06:37 +00:00
|
|
|
Graph graph(info.zone());
|
2015-01-23 15:19:34 +00:00
|
|
|
JSGraph jsgraph(info.isolate(), &graph, jsgraph_->common(),
|
|
|
|
jsgraph_->javascript(), jsgraph_->machine());
|
2014-08-20 13:05:03 +00:00
|
|
|
|
2015-03-10 08:37:16 +00:00
|
|
|
// The inlinee specializes to the context from the JSFunction object.
|
|
|
|
// 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
|
|
|
|
// type feedback in the compiler.
|
2014-10-21 14:44:50 +00:00
|
|
|
AstGraphBuilder graph_builder(local_zone_, &info, &jsgraph);
|
2015-03-10 08:37:16 +00:00
|
|
|
graph_builder.CreateGraph(true, false);
|
|
|
|
JSContextSpecializer context_specializer(&jsgraph);
|
|
|
|
GraphReducer graph_reducer(&graph, local_zone_);
|
|
|
|
graph_reducer.AddReducer(&context_specializer);
|
|
|
|
graph_reducer.ReduceGraph();
|
2014-09-12 11:06:37 +00:00
|
|
|
Inlinee::UnifyReturn(&jsgraph);
|
2014-08-20 13:05:03 +00:00
|
|
|
|
2014-09-12 11:06:37 +00:00
|
|
|
CopyVisitor visitor(&graph, jsgraph_->graph(), info.zone());
|
|
|
|
visitor.CopyGraph();
|
2014-08-20 13:05:03 +00:00
|
|
|
|
2014-09-12 11:06:37 +00:00
|
|
|
Inlinee inlinee(visitor.GetCopy(graph.start()), visitor.GetCopy(graph.end()));
|
2014-09-18 08:56:52 +00:00
|
|
|
|
2015-04-23 09:04:37 +00:00
|
|
|
Node* outer_frame_state = call.frame_state();
|
|
|
|
// Insert argument adaptor frame if required.
|
|
|
|
if (call.formal_arguments() != inlinee.formal_parameters()) {
|
2015-05-11 17:20:43 +00:00
|
|
|
// In strong mode, in case of too few arguments we need to throw a
|
|
|
|
// TypeError so we must not inline this call.
|
|
|
|
if (is_strong(info.language_mode()) &&
|
|
|
|
call.formal_arguments() < inlinee.formal_parameters()) {
|
|
|
|
return NoChange();
|
|
|
|
}
|
2015-04-23 09:04:37 +00:00
|
|
|
outer_frame_state =
|
|
|
|
CreateArgumentsAdaptorFrameState(&call, function, info.zone());
|
|
|
|
}
|
2014-09-18 08:56:52 +00:00
|
|
|
|
2015-04-23 09:04:37 +00:00
|
|
|
for (Node* node : visitor.copies()) {
|
|
|
|
if (node && node->opcode() == IrOpcode::kFrameState) {
|
|
|
|
DCHECK_EQ(1, OperatorProperties::GetFrameStateInputCount(node->op()));
|
|
|
|
AddClosureToFrameState(node, function);
|
|
|
|
NodeProperties::ReplaceFrameStateInput(node, 0, outer_frame_state);
|
2014-09-18 08:56:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-10 08:37:16 +00:00
|
|
|
return inlinee.InlineAtCall(jsgraph_, node);
|
2014-08-20 13:05:03 +00:00
|
|
|
}
|
2014-10-20 07:56:50 +00:00
|
|
|
|
2015-01-26 09:05:47 +00:00
|
|
|
} // namespace compiler
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|