v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
js-inlining.h
Go to the documentation of this file.
1// Copyright 2014 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_H_
6#define V8_COMPILER_JS_INLINING_H_
7
11
12#if V8_ENABLE_WEBASSEMBLY
16#endif // V8_ENABLE_WEBASSEMBLY
17
18namespace v8 {
19namespace internal {
20
21class BytecodeOffset;
22class OptimizedCompilationInfo;
23
24namespace compiler {
25
26class SourcePositionTable;
27class JSWasmCallParameters;
29
30// The JSInliner provides the core graph inlining machinery. Note that this
31// class only deals with the mechanics of how to inline one graph into another,
32// heuristics that decide what and how much to inline are beyond its scope.
33class JSInliner final : public AdvancedReducer {
34 public:
35 JSInliner(Editor* editor, Zone* local_zone, OptimizedCompilationInfo* info,
38 NodeOriginTable* node_origins, const wasm::WasmModule* wasm_module,
40 bool inline_wasm_fct_if_supported)
41 : AdvancedReducer(editor),
42 local_zone_(local_zone),
43 info_(info),
47 node_origins_(node_origins),
48 wasm_module_(wasm_module),
50 inline_wasm_fct_if_supported_(inline_wasm_fct_if_supported) {
51 // In case WebAssembly is disabled.
56 }
57
58 const char* reducer_name() const override { return "JSInliner"; }
59
60 Reduction Reduce(Node* node) final { UNREACHABLE(); }
61
62 // Can be used by inlining heuristics or by testing code directly, without
63 // using the above generic reducer interface of the inlining machinery.
65
66#if V8_ENABLE_WEBASSEMBLY
67 Reduction ReduceJSWasmCall(Node* node);
68 void InlineWasmFunction(Node* call, Node* inlinee_start, Node* inlinee_end,
69 Node* frame_state,
70 SharedFunctionInfoRef shared_fct_info,
71 int argument_count, Node* context);
72 static std::string WasmFunctionNameForTrace(wasm::NativeModule* native_module,
73 int fct_index) {
74 wasm::StringBuilder builder;
75 native_module->GetNamesProvider()->PrintFunctionName(builder, fct_index);
76 if (builder.length() == 0) return "<no name>";
77 return {builder.start(), builder.length()};
78 }
79#endif // V8_ENABLE_WEBASSEMBLY
80
81 private:
82 Zone* zone() const { return local_zone_; }
86 TFGraph* graph() const;
87 JSGraph* jsgraph() const { return jsgraph_; }
88 // TODO(neis): Make heap broker a component of JSGraph?
89 JSHeapBroker* broker() const { return broker_; }
90 Isolate* isolate() const { return jsgraph_->isolate(); }
91
100
101 // Inline not only the wasm wrapper but also the wasm function itself if
102 // inlining into JavaScript is supported and the function is small enough.
104
105 OptionalSharedFunctionInfoRef DetermineCallTarget(Node* node);
106 FeedbackCellRef DetermineCallContext(Node* node, Node** context_out);
107
108 // TODO(victorgomes): This function is used to create 3 *quite* different
109 // artificial frame states, we should perhaps split it into three different
110 // functions.
113 FrameStateType frame_state_type, SharedFunctionInfoRef shared,
114 OptionalBytecodeArrayRef maybe_bytecode_array, Node* context = nullptr,
115 Node* callee = nullptr);
116
117 Reduction InlineCall(Node* call, Node* new_target, Node* context,
118 Node* frame_state, StartNode start, Node* end,
119 Node* exception_target,
120 const NodeVector& uncaught_subcalls, int argument_count);
121
122#if V8_ENABLE_WEBASSEMBLY
123 struct WasmInlineResult {
124 bool can_inline_body = false;
125 Node* body_start = nullptr;
126 Node* body_end = nullptr;
127 };
128 WasmInlineResult TryWasmInlining(const JSWasmCallNode& call_node);
129 Reduction InlineJSWasmCall(Node* call, Node* new_target, Node* context,
130 Node* frame_state, StartNode start, Node* end,
131 Node* exception_target,
132 const NodeVector& uncaught_subcalls);
133#endif // V8_ENABLE_WEBASSEMBLY
134};
135
136} // namespace compiler
137} // namespace internal
138} // namespace v8
139
140#endif // V8_COMPILER_JS_INLINING_H_
int16_t parameter_count
Definition builtins.cc:67
Isolate * isolate() const
Definition js-graph.h:106
Reduction ReduceJSCall(Node *node)
JSHeapBroker * broker() const
Definition js-inlining.h:89
FrameState CreateArtificialFrameState(Node *node, FrameState outer_frame_state, int parameter_count, FrameStateType frame_state_type, SharedFunctionInfoRef shared, OptionalBytecodeArrayRef maybe_bytecode_array, Node *context=nullptr, Node *callee=nullptr)
Reduction InlineCall(Node *call, Node *new_target, Node *context, Node *frame_state, StartNode start, Node *end, Node *exception_target, const NodeVector &uncaught_subcalls, int argument_count)
Reduction Reduce(Node *node) final
Definition js-inlining.h:60
CommonOperatorBuilder * common() const
NodeOriginTable *const node_origins_
Definition js-inlining.h:97
JSInliner(Editor *editor, Zone *local_zone, OptimizedCompilationInfo *info, JSGraph *jsgraph, JSHeapBroker *broker, SourcePositionTable *source_positions, NodeOriginTable *node_origins, const wasm::WasmModule *wasm_module, JsWasmCallsSidetable *js_wasm_calls_sidetable, bool inline_wasm_fct_if_supported)
Definition js-inlining.h:35
SimplifiedOperatorBuilder * simplified() const
JSOperatorBuilder * javascript() const
JsWasmCallsSidetable * js_wasm_calls_sidetable_
Definition js-inlining.h:99
const wasm::WasmModule * wasm_module_
Definition js-inlining.h:98
OptionalSharedFunctionInfoRef DetermineCallTarget(Node *node)
FeedbackCellRef DetermineCallContext(Node *node, Node **context_out)
const char * reducer_name() const override
Definition js-inlining.h:58
OptimizedCompilationInfo * info_
Definition js-inlining.h:93
SourcePositionTable *const source_positions_
Definition js-inlining.h:96
void PrintFunctionName(StringBuilder &out, uint32_t function_index, FunctionNamesBehavior behavior=kWasmInternal, IndexAsComment index_as_comment=kDontPrintIndex)
int start
int end
DirectHandle< Object > new_target
Definition execution.cc:75
JsWasmCallsSidetable * js_wasm_calls_sidetable
SourcePositionTable * source_positions
FrameState outer_frame_state
#define DCHECK_IMPLIES(v1, v2)
Definition logging.h:493
#define USE(...)
Definition macros.h:293