Commit a19cfb0e authored by bmeurer's avatar bmeurer Committed by Commit bot

[turbofan] Support inlining of unguarded loops.

Also allow inlining of native functions.

R=mstarzinger@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#26959}
parent d0b8839b
......@@ -79,6 +79,11 @@ class Inlinee {
Node* value_output() {
return NodeProperties::GetValueInput(unique_return(), 0);
}
// 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);
}
// Return the unique return statement of the graph.
Node* unique_return() {
Node* unique_return = NodeProperties::GetControlInput(end_);
......@@ -263,7 +268,19 @@ Reduction Inlinee::InlineAtCall(JSGraph* jsgraph, Node* call) {
}
}
NodeProperties::ReplaceWithValue(call, value_output(), effect_output());
for (Edge edge : call->use_edges()) {
if (NodeProperties::IsControlEdge(edge)) {
// TODO(turbofan): Handle kIfException uses.
DCHECK_EQ(IrOpcode::kIfSuccess, edge.from()->opcode());
edge.from()->ReplaceUses(control_output());
edge.UpdateTo(nullptr);
} else if (NodeProperties::IsEffectEdge(edge)) {
edge.UpdateTo(effect_output());
} else {
edge.UpdateTo(value_output());
}
}
return Reducer::Replace(value_output());
}
......@@ -312,16 +329,6 @@ Reduction JSInliner::Reduce(Node* node) {
Handle<JSFunction> function = match.Value().handle();
if (function->shared()->native()) {
if (FLAG_trace_turbo_inlining) {
SmartArrayPointer<char> name =
function->shared()->DebugName()->ToCString();
PrintF("Not Inlining %s into %s because inlinee is native\n", name.get(),
info_->shared_info()->DebugName()->ToCString().get());
}
return NoChange();
}
CompilationInfoWithZone info(function);
if (!Compiler::ParseAndAnalyze(&info)) return NoChange();
......
......@@ -320,6 +320,53 @@ TEST(InlineLoopGuardedTwice) {
}
TEST(InlineLoopUnguardedEmpty) {
FLAG_turbo_deoptimization = true;
FunctionTester T(
"(function () {"
" function foo(s) { AssertInlineCount(2); while (s); return s; };"
" function bar(s, t) { return foo(s); };"
" return bar;"
"})();",
kInlineFlags);
InstallAssertInlineCountHelper(CcTest::isolate());
T.CheckCall(T.Val(0.0), T.Val(0.0), T.Val(4));
}
TEST(InlineLoopUnguardedOnce) {
FLAG_turbo_deoptimization = true;
FunctionTester T(
"(function () {"
" function foo(s) { AssertInlineCount(2); while (s) {"
" s = s - 1; }; return s; };"
" function bar(s, t) { return foo(s); };"
" return bar;"
"})();",
kInlineFlags);
InstallAssertInlineCountHelper(CcTest::isolate());
T.CheckCall(T.Val(0.0), T.Val(0.0), T.Val(4));
}
TEST(InlineLoopUnguardedTwice) {
FLAG_turbo_deoptimization = true;
FunctionTester T(
"(function () {"
" function foo(s) { AssertInlineCount(2); while (s > 0) {"
" s = s - 1; }; return s; };"
" function bar(s,t) { return foo(foo(s,t),t); };"
" return bar;"
"})();",
kInlineFlags);
InstallAssertInlineCountHelper(CcTest::isolate());
T.CheckCall(T.Val(0.0), T.Val(0.0), T.Val(4));
}
TEST(InlineStrictIntoNonStrict) {
FLAG_turbo_deoptimization = true;
FunctionTester T(
......
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