[turbofan] Separate JSInliningHeuristic into own class.

This separates the core machinery and the heuristics involved with
inlining functions calls. So far the heuristic only respects our
%SetForceInlineFlag hint, but it will the place where general inlining
heuristics can live without impeding clarity of the core machinery.

R=bmeurer@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#31150}
This commit is contained in:
mstarzinger 2015-10-07 05:18:21 -07:00 committed by Commit bot
parent 465caac813
commit 0a6863f029
7 changed files with 98 additions and 17 deletions

View File

@ -761,6 +761,8 @@ source_set("v8_base") {
"src/compiler/js-graph.h",
"src/compiler/js-inlining.cc",
"src/compiler/js-inlining.h",
"src/compiler/js-inlining-heuristic.cc",
"src/compiler/js-inlining-heuristic.h",
"src/compiler/js-intrinsic-lowering.cc",
"src/compiler/js-intrinsic-lowering.h",
"src/compiler/js-operator.cc",

View File

@ -0,0 +1,34 @@
// Copyright 2015 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.
#include "src/compiler/js-inlining-heuristic.h"
#include "src/compiler/node-matchers.h"
#include "src/objects-inl.h"
namespace v8 {
namespace internal {
namespace compiler {
Reduction JSInliningHeuristic::Reduce(Node* node) {
if (node->opcode() != IrOpcode::kJSCallFunction) return NoChange();
Node* callee = node->InputAt(0);
HeapObjectMatcher match(callee);
if (!match.HasValue() || !match.Value()->IsJSFunction()) return NoChange();
Handle<JSFunction> function = Handle<JSFunction>::cast(match.Value());
// Functions marked with %SetForceInlineFlag are immediately inlined.
if (function->shared()->force_inline()) {
return inliner_.ReduceJSCallFunction(node, function);
}
// All other functions are only handled with general inlining.
if (mode_ == kRestrictedInlining) return NoChange();
return inliner_.ReduceJSCallFunction(node, function);
}
} // namespace compiler
} // namespace internal
} // namespace v8

View File

@ -0,0 +1,34 @@
// Copyright 2015 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.
#ifndef V8_COMPILER_JS_INLINING_HEURISTIC_H_
#define V8_COMPILER_JS_INLINING_HEURISTIC_H_
#include "src/compiler/js-inlining.h"
namespace v8 {
namespace internal {
namespace compiler {
class JSInliningHeuristic final : public AdvancedReducer {
public:
enum Mode { kRestrictedInlining, kGeneralInlining };
JSInliningHeuristic(Editor* editor, Mode mode, Zone* local_zone,
CompilationInfo* info, JSGraph* jsgraph)
: AdvancedReducer(editor),
mode_(mode),
inliner_(editor, local_zone, info, jsgraph) {}
Reduction Reduce(Node* node) final;
private:
Mode const mode_;
JSInliner inliner_;
};
} // namespace compiler
} // namespace internal
} // namespace v8
#endif // V8_COMPILER_JS_INLINING_HEURISTIC_H_

View File

@ -246,13 +246,17 @@ Reduction JSInliner::Reduce(Node* node) {
JSCallFunctionAccessor call(node);
HeapObjectMatcher match(call.jsfunction());
if (!match.HasValue()) return NoChange();
if (!match.Value()->IsJSFunction()) return NoChange();
if (!match.HasValue() || !match.Value()->IsJSFunction()) return NoChange();
Handle<JSFunction> function = Handle<JSFunction>::cast(match.Value());
if (mode_ == kRestrictedInlining && !function->shared()->force_inline()) {
return NoChange();
}
return ReduceJSCallFunction(node, function);
}
Reduction JSInliner::ReduceJSCallFunction(Node* node,
Handle<JSFunction> function) {
DCHECK_EQ(IrOpcode::kJSCallFunction, node->opcode());
JSCallFunctionAccessor call(node);
if (!function->shared()->IsInlineable()) {
// Function must be inlineable.

View File

@ -19,22 +19,26 @@ namespace compiler {
// Forward declarations.
class JSCallFunctionAccessor;
// The JSInliner provides the core graph inlining machinery. Note that this
// class only deals with the mechanics of how to inline one graph into another,
// heuristics that decide what and how much to inline are beyond its scope.
class JSInliner final : public AdvancedReducer {
public:
enum Mode { kRestrictedInlining, kGeneralInlining };
JSInliner(Editor* editor, Mode mode, Zone* local_zone, CompilationInfo* info,
JSInliner(Editor* editor, Zone* local_zone, CompilationInfo* info,
JSGraph* jsgraph)
: AdvancedReducer(editor),
mode_(mode),
local_zone_(local_zone),
info_(info),
jsgraph_(jsgraph) {}
// Reducer interface, eagerly inlines everything.
Reduction Reduce(Node* node) final;
// Can be used by inlining heuristics or by testing code directly, without
// using the above generic reducer interface of the inlining machinery.
Reduction ReduceJSCallFunction(Node* node, Handle<JSFunction> function);
private:
Mode const mode_;
Zone* local_zone_;
CompilationInfo* info_;
JSGraph* jsgraph_;

View File

@ -31,7 +31,7 @@
#include "src/compiler/js-frame-specialization.h"
#include "src/compiler/js-generic-lowering.h"
#include "src/compiler/js-global-specialization.h"
#include "src/compiler/js-inlining.h"
#include "src/compiler/js-inlining-heuristic.h"
#include "src/compiler/js-intrinsic-lowering.h"
#include "src/compiler/js-type-feedback.h"
#include "src/compiler/js-type-feedback-lowering.h"
@ -526,10 +526,11 @@ struct InliningPhase {
? handle(data->info()->global_object())
: Handle<GlobalObject>(),
data->info()->dependencies());
JSInliner inliner(&graph_reducer, data->info()->is_inlining_enabled()
? JSInliner::kGeneralInlining
: JSInliner::kRestrictedInlining,
temp_zone, data->info(), data->jsgraph());
JSInliningHeuristic inlining(&graph_reducer,
data->info()->is_inlining_enabled()
? JSInliningHeuristic::kGeneralInlining
: JSInliningHeuristic::kRestrictedInlining,
temp_zone, data->info(), data->jsgraph());
AddReducer(data, &graph_reducer, &dead_code_elimination);
AddReducer(data, &graph_reducer, &common_reducer);
if (data->info()->is_frame_specializing()) {
@ -539,7 +540,7 @@ struct InliningPhase {
AddReducer(data, &graph_reducer, &global_specialization);
}
AddReducer(data, &graph_reducer, &context_specialization);
AddReducer(data, &graph_reducer, &inliner);
AddReducer(data, &graph_reducer, &inlining);
graph_reducer.ReduceGraph();
}
};

View File

@ -526,6 +526,8 @@
'../../src/compiler/js-graph.h',
'../../src/compiler/js-inlining.cc',
'../../src/compiler/js-inlining.h',
'../../src/compiler/js-inlining-heuristic.cc',
'../../src/compiler/js-inlining-heuristic.h',
'../../src/compiler/js-intrinsic-lowering.cc',
'../../src/compiler/js-intrinsic-lowering.h',
'../../src/compiler/js-operator.cc',