v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
js-inlining-heuristic.h
Go to the documentation of this file.
1// Copyright 2015 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_COMPILER_JS_INLINING_HEURISTIC_H_
6#define V8_COMPILER_JS_INLINING_HEURISTIC_H_
7
9
10namespace v8 {
11namespace internal {
12namespace compiler {
13
15 public:
16 enum Mode {
17 kJSOnly, // Inline JS calls only.
18 kWasmWrappersOnly, // Inline wasm wrappers only.
19 kWasmFullInlining, // Inline wasm wrappers and (if supported) whole wasm
20 // functions.
21 };
22
23 JSInliningHeuristic(Editor* editor, Zone* local_zone,
27 NodeOriginTable* node_origins, Mode mode,
28 // The two following arguments should be `nullptr` iff
29 // inlining with `mode == kJSOnly`.
30 const wasm::WasmModule* wasm_module,
32 : AdvancedReducer(editor),
33 inliner_(editor, local_zone, info, jsgraph, broker, source_positions,
34 node_origins, wasm_module, js_wasm_calls_sidetable,
35 mode == kWasmFullInlining),
36 candidates_(local_zone),
37 seen_(local_zone),
41 info_(info),
42 mode_(mode),
44 v8_flags.max_inlined_bytecode_size_cumulative),
48 wasm_module != nullptr && js_wasm_calls_sidetable != nullptr);
49 }
50
51 const char* reducer_name() const override { return "JSInliningHeuristic"; }
52
53 Reduction Reduce(Node* node) final;
54
55 // Processes the list of candidates gathered while the reducer was running,
56 // and inlines call sites that the heuristic determines to be important.
57 void Finalize() final;
58
62
63 private:
64 // This limit currently matches what the old compiler did. We may want to
65 // re-evaluate and come up with a proper limit for TurboFan.
66 static const int kMaxCallPolymorphism = 4;
67
68 struct Candidate {
69 OptionalJSFunctionRef functions[kMaxCallPolymorphism];
70 // In the case of polymorphic inlining, this tells if each of the
71 // functions could be inlined.
73 // Strong references to bytecode to ensure it is not flushed from SFI
74 // while choosing inlining candidates.
75 OptionalBytecodeArrayRef bytecode[kMaxCallPolymorphism];
76 // TODO(2206): For now polymorphic inlining is treated orthogonally to
77 // inlining based on SharedFunctionInfo. This should be unified and the
78 // above array should be switched to SharedFunctionInfo instead. Currently
79 // we use {num_functions == 1 && functions[0].is_null()} as an indicator.
80 OptionalSharedFunctionInfoRef shared_info;
82 Node* node = nullptr; // The call site at which to inline.
83 CallFrequency frequency; // Relative frequency of this call site.
84 int total_size = 0;
85 };
86
87 // Comparator for candidates.
89 bool operator()(const Candidate& left, const Candidate& right) const;
90 };
91
92 // Candidates are kept in a sorted set of unique candidates.
94
95 // Dumps candidates to console.
96 void PrintCandidates();
97 Reduction InlineCandidate(Candidate const& candidate, bool small_function);
98 void CreateOrReuseDispatch(Node* node, Node* callee,
99 Candidate const& candidate, Node** if_successes,
100 Node** calls, Node** inputs, int input_count,
101 int* num_calls);
102 bool TryReuseDispatch(Node* node, Node* callee, Node** if_successes,
103 Node** calls, Node** inputs, int input_count,
104 int* num_calls);
107 Node* to, StateCloneMode mode);
108 Node* DuplicateStateValuesAndRename(Node* state_values, Node* from, Node* to,
109 StateCloneMode mode);
110 Candidate CollectFunctions(Node* node, int functions_size);
111
113 TFGraph* graph() const;
114 JSGraph* jsgraph() const { return jsgraph_; }
115 // TODO(neis): Make heap broker a component of JSGraph?
116 JSHeapBroker* broker() const { return broker_; }
118 Isolate* isolate() const { return jsgraph_->isolate(); }
120 Mode mode() const { return mode_; }
121
130 const Mode mode_;
133};
134
135} // namespace compiler
136} // namespace internal
137} // namespace v8
138
139#endif // V8_COMPILER_JS_INLINING_HEURISTIC_H_
Isolate * isolate() const
Definition js-graph.h:106
SimplifiedOperatorBuilder * simplified() const
Node * DuplicateStateValuesAndRename(Node *state_values, Node *from, Node *to, StateCloneMode mode)
JSInliningHeuristic(Editor *editor, Zone *local_zone, OptimizedCompilationInfo *info, JSGraph *jsgraph, JSHeapBroker *broker, SourcePositionTable *source_positions, NodeOriginTable *node_origins, Mode mode, const wasm::WasmModule *wasm_module, JsWasmCallsSidetable *js_wasm_calls_sidetable)
CompilationDependencies * dependencies() const
bool TryReuseDispatch(Node *node, Node *callee, Node **if_successes, Node **calls, Node **inputs, int input_count, int *num_calls)
void CreateOrReuseDispatch(Node *node, Node *callee, Candidate const &candidate, Node **if_successes, Node **calls, Node **inputs, int input_count, int *num_calls)
Candidate CollectFunctions(Node *node, int functions_size)
Reduction InlineCandidate(Candidate const &candidate, bool small_function)
FrameState DuplicateFrameStateAndRename(FrameState frame_state, Node *from, Node *to, StateCloneMode mode)
JsWasmCallsSidetable * js_wasm_calls_sidetable
SourcePositionTable * source_positions
too high values may cause the compiler to set high thresholds for inlining to as much as possible max_inlined_bytecode_size_absolute
Definition flags.cc:1377
V8_EXPORT_PRIVATE FlagValues v8_flags
#define DCHECK_EQ(v1, v2)
Definition logging.h:485
bool operator()(const Candidate &left, const Candidate &right) const