Commit 0a6863f0 authored by mstarzinger's avatar mstarzinger Committed by Commit bot

[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}
parent 465caac8
...@@ -761,6 +761,8 @@ source_set("v8_base") { ...@@ -761,6 +761,8 @@ source_set("v8_base") {
"src/compiler/js-graph.h", "src/compiler/js-graph.h",
"src/compiler/js-inlining.cc", "src/compiler/js-inlining.cc",
"src/compiler/js-inlining.h", "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.cc",
"src/compiler/js-intrinsic-lowering.h", "src/compiler/js-intrinsic-lowering.h",
"src/compiler/js-operator.cc", "src/compiler/js-operator.cc",
......
// 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
// 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_
...@@ -246,13 +246,17 @@ Reduction JSInliner::Reduce(Node* node) { ...@@ -246,13 +246,17 @@ Reduction JSInliner::Reduce(Node* node) {
JSCallFunctionAccessor call(node); JSCallFunctionAccessor call(node);
HeapObjectMatcher match(call.jsfunction()); HeapObjectMatcher match(call.jsfunction());
if (!match.HasValue()) return NoChange(); if (!match.HasValue() || !match.Value()->IsJSFunction()) return NoChange();
if (!match.Value()->IsJSFunction()) return NoChange();
Handle<JSFunction> function = Handle<JSFunction>::cast(match.Value()); 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()) { if (!function->shared()->IsInlineable()) {
// Function must be inlineable. // Function must be inlineable.
......
...@@ -19,22 +19,26 @@ namespace compiler { ...@@ -19,22 +19,26 @@ namespace compiler {
// Forward declarations. // Forward declarations.
class JSCallFunctionAccessor; 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 { class JSInliner final : public AdvancedReducer {
public: public:
enum Mode { kRestrictedInlining, kGeneralInlining }; JSInliner(Editor* editor, Zone* local_zone, CompilationInfo* info,
JSInliner(Editor* editor, Mode mode, Zone* local_zone, CompilationInfo* info,
JSGraph* jsgraph) JSGraph* jsgraph)
: AdvancedReducer(editor), : AdvancedReducer(editor),
mode_(mode),
local_zone_(local_zone), local_zone_(local_zone),
info_(info), info_(info),
jsgraph_(jsgraph) {} jsgraph_(jsgraph) {}
// Reducer interface, eagerly inlines everything.
Reduction Reduce(Node* node) final; 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: private:
Mode const mode_;
Zone* local_zone_; Zone* local_zone_;
CompilationInfo* info_; CompilationInfo* info_;
JSGraph* jsgraph_; JSGraph* jsgraph_;
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
#include "src/compiler/js-frame-specialization.h" #include "src/compiler/js-frame-specialization.h"
#include "src/compiler/js-generic-lowering.h" #include "src/compiler/js-generic-lowering.h"
#include "src/compiler/js-global-specialization.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-intrinsic-lowering.h"
#include "src/compiler/js-type-feedback.h" #include "src/compiler/js-type-feedback.h"
#include "src/compiler/js-type-feedback-lowering.h" #include "src/compiler/js-type-feedback-lowering.h"
...@@ -526,9 +526,10 @@ struct InliningPhase { ...@@ -526,9 +526,10 @@ struct InliningPhase {
? handle(data->info()->global_object()) ? handle(data->info()->global_object())
: Handle<GlobalObject>(), : Handle<GlobalObject>(),
data->info()->dependencies()); data->info()->dependencies());
JSInliner inliner(&graph_reducer, data->info()->is_inlining_enabled() JSInliningHeuristic inlining(&graph_reducer,
? JSInliner::kGeneralInlining data->info()->is_inlining_enabled()
: JSInliner::kRestrictedInlining, ? JSInliningHeuristic::kGeneralInlining
: JSInliningHeuristic::kRestrictedInlining,
temp_zone, data->info(), data->jsgraph()); temp_zone, data->info(), data->jsgraph());
AddReducer(data, &graph_reducer, &dead_code_elimination); AddReducer(data, &graph_reducer, &dead_code_elimination);
AddReducer(data, &graph_reducer, &common_reducer); AddReducer(data, &graph_reducer, &common_reducer);
...@@ -539,7 +540,7 @@ struct InliningPhase { ...@@ -539,7 +540,7 @@ struct InliningPhase {
AddReducer(data, &graph_reducer, &global_specialization); AddReducer(data, &graph_reducer, &global_specialization);
} }
AddReducer(data, &graph_reducer, &context_specialization); AddReducer(data, &graph_reducer, &context_specialization);
AddReducer(data, &graph_reducer, &inliner); AddReducer(data, &graph_reducer, &inlining);
graph_reducer.ReduceGraph(); graph_reducer.ReduceGraph();
} }
}; };
......
...@@ -526,6 +526,8 @@ ...@@ -526,6 +526,8 @@
'../../src/compiler/js-graph.h', '../../src/compiler/js-graph.h',
'../../src/compiler/js-inlining.cc', '../../src/compiler/js-inlining.cc',
'../../src/compiler/js-inlining.h', '../../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.cc',
'../../src/compiler/js-intrinsic-lowering.h', '../../src/compiler/js-intrinsic-lowering.h',
'../../src/compiler/js-operator.cc', '../../src/compiler/js-operator.cc',
......
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