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"
|
|
|
|
#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"
|
2015-07-24 10:11:46 +00:00
|
|
|
#include "src/full-codegen/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
|
|
|
class CopyVisitor {
|
2014-09-12 11:06:37 +00:00
|
|
|
public:
|
|
|
|
CopyVisitor(Graph* source_graph, Graph* target_graph, Zone* temp_zone)
|
[turbofan] Proper dead code elimination as regular reducer.
The three different concerns that the ControlReducer used to deal with
are now properly separated into
a.) DeadCodeElimination, which is a regular AdvancedReducer, that
propagates Dead via control edges,
b.) CommonOperatorReducer, which does strength reduction on common
operators (i.e. Branch, Phi, and friends), and
c.) GraphTrimming, which removes dead->live edges from the graph.
This will make it possible to run the DeadCodeElimination together with
other passes that actually introduce Dead nodes, i.e. typed lowering;
and it opens the door for general inlining without two stage fix point
iteration.
To make the DeadCodeElimination easier and more uniform, we basically
reverted the introduction of DeadValue and DeadEffect, and changed the
Dead operator to produce control, value and effect. Note however that
this is not a requirement, but merely a way to make dead propagation
easier and more uniform. We could always go back and decide to have
different Dead operators if some other change requires that.
Note that there are several additional opportunities for cleanup now,
i.e. OSR deconstruction could be a regular reducer now, and we don't
need to use TheHole as dead value marker in the GraphReducer. And we can
actually run the dead code elimination together with the other passes
instead of using separate passes over the graph. We will do this in
follow up CLs.
R=jarin@chromium.org, mstarzinger@chromium.org
Review URL: https://codereview.chromium.org/1193833002
Cr-Commit-Position: refs/heads/master@{#29146}
2015-06-19 12:07:17 +00:00
|
|
|
: sentinel_op_(IrOpcode::kDead, Operator::kNoProperties, "Sentinel", 0, 0,
|
|
|
|
0, 0, 0, 0),
|
2015-02-20 10:11:45 +00:00
|
|
|
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-07-06 12:56:05 +00:00
|
|
|
Reduction JSInliner::InlineCall(Node* call, Node* context, Node* frame_state,
|
|
|
|
Node* start, Node* end) {
|
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.
|
2015-05-21 13:02:18 +00:00
|
|
|
int const inlinee_context_index =
|
|
|
|
static_cast<int>(start->op()->ValueOutputCount()) - 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.
|
2015-05-21 13:02:18 +00:00
|
|
|
for (Edge edge : start->use_edges()) {
|
2014-12-02 14:38:55 +00:00
|
|
|
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.
|
2015-07-06 12:56:05 +00:00
|
|
|
Replace(use, call->InputAt(index));
|
2014-08-20 13:05:03 +00:00
|
|
|
} else if (index == inlinee_context_index) {
|
2015-07-06 12:56:05 +00:00
|
|
|
Replace(use, context);
|
2014-08-20 13:05:03 +00:00
|
|
|
} else if (index < inlinee_context_index) {
|
|
|
|
// Call has fewer arguments than required, fill with undefined.
|
2015-07-06 12:56:05 +00:00
|
|
|
Replace(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);
|
2015-05-27 11:01:51 +00:00
|
|
|
} else if (NodeProperties::IsFrameStateEdge(edge)) {
|
|
|
|
edge.UpdateTo(frame_state);
|
2014-08-20 13:05:03 +00:00
|
|
|
} else {
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-26 10:31:55 +00:00
|
|
|
NodeVector values(local_zone_);
|
|
|
|
NodeVector effects(local_zone_);
|
|
|
|
NodeVector controls(local_zone_);
|
|
|
|
for (Node* const input : end->inputs()) {
|
|
|
|
switch (input->opcode()) {
|
|
|
|
case IrOpcode::kReturn:
|
|
|
|
values.push_back(NodeProperties::GetValueInput(input, 0));
|
|
|
|
effects.push_back(NodeProperties::GetEffectInput(input));
|
|
|
|
controls.push_back(NodeProperties::GetControlInput(input));
|
|
|
|
break;
|
2015-05-26 12:17:57 +00:00
|
|
|
case IrOpcode::kDeoptimize:
|
|
|
|
case IrOpcode::kTerminate:
|
|
|
|
case IrOpcode::kThrow:
|
|
|
|
jsgraph_->graph()->end()->AppendInput(jsgraph_->zone(), input);
|
|
|
|
jsgraph_->graph()->end()->set_op(
|
|
|
|
jsgraph_->common()->End(jsgraph_->graph()->end()->InputCount()));
|
|
|
|
break;
|
2015-05-26 10:31:55 +00:00
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
break;
|
2015-05-21 13:02:18 +00:00
|
|
|
}
|
|
|
|
}
|
2015-05-26 10:31:55 +00:00
|
|
|
DCHECK_NE(0u, values.size());
|
|
|
|
DCHECK_EQ(values.size(), effects.size());
|
|
|
|
DCHECK_EQ(values.size(), controls.size());
|
|
|
|
int const input_count = static_cast<int>(controls.size());
|
|
|
|
Node* control_output = jsgraph_->graph()->NewNode(
|
|
|
|
jsgraph_->common()->Merge(input_count), input_count, &controls.front());
|
|
|
|
values.push_back(control_output);
|
|
|
|
effects.push_back(control_output);
|
|
|
|
Node* value_output = jsgraph_->graph()->NewNode(
|
|
|
|
jsgraph_->common()->Phi(kMachAnyTagged, input_count),
|
|
|
|
static_cast<int>(values.size()), &values.front());
|
|
|
|
Node* effect_output = jsgraph_->graph()->NewNode(
|
|
|
|
jsgraph_->common()->EffectPhi(input_count),
|
|
|
|
static_cast<int>(effects.size()), &effects.front());
|
2015-05-21 13:02:18 +00:00
|
|
|
|
|
|
|
ReplaceWithValue(call, value_output, effect_output, control_output);
|
2015-03-03 13:09:49 +00:00
|
|
|
|
2015-05-21 13:02:18 +00:00
|
|
|
return Changed(value_output);
|
2014-08-20 13:05:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-10 11:52:35 +00:00
|
|
|
Node* JSInliner::CreateArgumentsAdaptorFrameState(
|
|
|
|
JSCallFunctionAccessor* call, Handle<SharedFunctionInfo> shared_info,
|
|
|
|
Zone* temp_zone) {
|
2015-06-23 07:17:07 +00:00
|
|
|
const FrameStateFunctionInfo* state_info =
|
|
|
|
jsgraph_->common()->CreateFrameStateFunctionInfo(
|
|
|
|
FrameStateType::kArgumentsAdaptor,
|
[turbofan]: Add a context relaxation Reducer
In many cases, the context that TurboFan's ASTGraphBuilder or subsequent
reduction operations attaches to nodes does not need to be that exact
context, but rather only needs to be one with the same native context,
because it is used internally only to fetch the native context, e.g. for
creating and throwing exceptions.
This reducer recognizes common cases where the context that is specified
for a node can be relaxed to a canonical, less specific one. This
relaxed context can either be the enclosing function's context or a specific
Module or Script context that is explicitly created within the function.
This optimization is especially important for TurboFan-generated code stubs
which use context specialization and inlining to generate optimal code.
Without context relaxation, many extraneous moves are generated to pass
exactly the right context to internal functions like ToNumber and
AllocateHeapNumber, which only need the native context. By turning context
relaxation on, these moves disappear because all these common internal
context uses are unified to the context passed into the stub function, which
is typically already in the correct context register and remains there for
short stubs. It also eliminates the explicit use of a specialized context
constant in the code stub in these cases, which could cause memory leaks.
Review URL: https://codereview.chromium.org/1244583003
Cr-Commit-Position: refs/heads/master@{#29763}
2015-07-20 17:15:59 +00:00
|
|
|
static_cast<int>(call->formal_arguments()) + 1, 0, shared_info,
|
|
|
|
CALL_MAINTAINS_NATIVE_CONTEXT);
|
2015-06-23 07:17:07 +00:00
|
|
|
|
2014-09-29 13:37:58 +00:00
|
|
|
const Operator* op = jsgraph_->common()->FrameState(
|
2015-06-23 07:17:07 +00:00
|
|
|
BailoutId(-1), OutputFrameStateCombine::Ignore(), state_info);
|
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(),
|
2015-05-15 12:17:15 +00:00
|
|
|
call->jsfunction(), call->frame_state());
|
2014-09-18 08:56:52 +00:00
|
|
|
}
|
|
|
|
|
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);
|
2015-06-19 12:48:58 +00:00
|
|
|
HeapObjectMatcher match(call.jsfunction());
|
2015-02-20 10:11:45 +00:00
|
|
|
if (!match.HasValue()) return NoChange();
|
|
|
|
|
2015-08-31 08:24:52 +00:00
|
|
|
if (!match.Value()->IsJSFunction()) return NoChange();
|
|
|
|
Handle<JSFunction> function = Handle<JSFunction>::cast(match.Value());
|
2015-05-20 12:48:02 +00:00
|
|
|
if (mode_ == kRestrictedInlining && !function->shared()->force_inline()) {
|
2015-03-09 08:05:24 +00:00
|
|
|
return NoChange();
|
|
|
|
}
|
2015-02-20 10:11:45 +00:00
|
|
|
|
2015-07-20 14:53:28 +00:00
|
|
|
if (function->shared()->HasDebugInfo()) {
|
|
|
|
// Function contains break points.
|
|
|
|
TRACE("Not inlining %s into %s because callee may contain break points\n",
|
|
|
|
function->shared()->DebugName()->ToCString().get(),
|
|
|
|
info_->shared_info()->DebugName()->ToCString().get());
|
|
|
|
return NoChange();
|
|
|
|
}
|
|
|
|
|
2015-06-30 11:38:19 +00:00
|
|
|
// Disallow cross native-context inlining for now. This means that all parts
|
|
|
|
// of the resulting code will operate on the same global object.
|
|
|
|
// This also prevents cross context leaks for asm.js code, where we could
|
|
|
|
// inline functions from a different context and hold on to that context (and
|
|
|
|
// closure) from the code object.
|
|
|
|
// TODO(turbofan): We might want to revisit this restriction later when we
|
|
|
|
// have a need for this, and we know how to model different native contexts
|
|
|
|
// in the same graph in a compositional way.
|
|
|
|
if (function->context()->native_context() !=
|
|
|
|
info_->context()->native_context()) {
|
|
|
|
TRACE("Not inlining %s into %s because of different native contexts\n",
|
|
|
|
function->shared()->DebugName()->ToCString().get(),
|
|
|
|
info_->shared_info()->DebugName()->ToCString().get());
|
|
|
|
return NoChange();
|
|
|
|
}
|
|
|
|
|
2015-06-30 11:05:03 +00:00
|
|
|
// TODO(turbofan): TranslatedState::GetAdaptedArguments() currently relies on
|
|
|
|
// not inlining recursive functions. We might want to relax that at some
|
|
|
|
// point.
|
|
|
|
for (Node* frame_state = call.frame_state();
|
|
|
|
frame_state->opcode() == IrOpcode::kFrameState;
|
|
|
|
frame_state = frame_state->InputAt(kFrameStateOuterStateInput)) {
|
|
|
|
FrameStateInfo const& info = OpParameter<FrameStateInfo>(frame_state);
|
|
|
|
Handle<SharedFunctionInfo> shared_info;
|
|
|
|
if (info.shared_info().ToHandle(&shared_info) &&
|
|
|
|
*shared_info == function->shared()) {
|
|
|
|
TRACE("Not inlining %s into %s because call is recursive\n",
|
|
|
|
function->shared()->DebugName()->ToCString().get(),
|
|
|
|
info_->shared_info()->DebugName()->ToCString().get());
|
|
|
|
return NoChange();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-24 14:17:05 +00:00
|
|
|
Zone zone;
|
|
|
|
ParseInfo parse_info(&zone, function);
|
|
|
|
CompilationInfo info(&parse_info);
|
2015-05-21 11:33:42 +00:00
|
|
|
if (info_->is_deoptimization_enabled()) info.MarkAsDeoptimizationEnabled();
|
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-06-30 11:38:19 +00:00
|
|
|
TRACE("Not inlining %s into %s because inlinee uses arguments array\n",
|
2015-03-17 18:51:08 +00:00
|
|
|
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());
|
2015-07-06 12:56:05 +00:00
|
|
|
AstGraphBuilder graph_builder(local_zone_, &info, &jsgraph);
|
|
|
|
graph_builder.CreateGraph(false);
|
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.
|
2015-07-06 12:56:05 +00:00
|
|
|
Node* context = jsgraph_->Constant(handle(function->context()));
|
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
|
|
|
|
2015-05-21 13:02:18 +00:00
|
|
|
Node* start = visitor.GetCopy(graph.start());
|
|
|
|
Node* end = visitor.GetCopy(graph.end());
|
2014-09-18 08:56:52 +00:00
|
|
|
|
2015-05-27 11:01:51 +00:00
|
|
|
Node* frame_state = call.frame_state();
|
2015-05-21 13:02:18 +00:00
|
|
|
size_t const inlinee_formal_parameters = start->op()->ValueOutputCount() - 3;
|
2015-04-23 09:04:37 +00:00
|
|
|
// Insert argument adaptor frame if required.
|
2015-05-21 13:02:18 +00:00
|
|
|
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()) &&
|
2015-05-21 13:02:18 +00:00
|
|
|
call.formal_arguments() < inlinee_formal_parameters) {
|
2015-05-11 17:20:43 +00:00
|
|
|
return NoChange();
|
|
|
|
}
|
2015-06-10 11:52:35 +00:00
|
|
|
frame_state = CreateArgumentsAdaptorFrameState(&call, info.shared_info(),
|
|
|
|
info.zone());
|
2015-04-23 09:04:37 +00:00
|
|
|
}
|
2014-09-18 08:56:52 +00:00
|
|
|
|
2015-06-11 05:23:06 +00:00
|
|
|
// Remember that we inlined this function.
|
|
|
|
info_->AddInlinedFunction(info.shared_info());
|
|
|
|
|
2015-07-06 12:56:05 +00:00
|
|
|
return InlineCall(node, context, frame_state, start, end);
|
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
|