v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
wasm-gc-operator-reducer.h
Go to the documentation of this file.
1// Copyright 2022 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_WASM_GC_OPERATOR_REDUCER_H_
6#define V8_COMPILER_WASM_GC_OPERATOR_REDUCER_H_
7
8#if !V8_ENABLE_WEBASSEMBLY
9#error This header should only be included if WebAssembly is enabled.
10#endif // !V8_ENABLE_WEBASSEMBLY
11
16
17namespace v8 {
18namespace internal {
19namespace compiler {
20
21class MachineGraph;
22class SourcePositionTable;
23
25 NodeWithType() : node(nullptr), type(wasm::kWasmVoid, nullptr) {}
26 NodeWithType(Node* node, wasm::TypeInModule type) : node(node), type(type) {}
27
28 bool operator==(const NodeWithType& other) const {
29 return node == other.node && type == other.type;
30 }
31 bool operator!=(const NodeWithType& other) const { return !(*this == other); }
32
33 bool IsSet() { return node != nullptr; }
34
37};
38
39// This class optimizes away wasm-gc type checks and casts. Two types of
40// information are used:
41// - Types already marked on graph nodes.
42// - Path-dependent type information that is inferred when a type check is used
43// as a branch condition.
45 : public AdvancedReducerWithControlPathState<NodeWithType,
46 kMultipleInstances> {
47 public:
48 WasmGCOperatorReducer(Editor* editor, Zone* temp_zone_, MachineGraph* mcgraph,
49 const wasm::WasmModule* module,
50 SourcePositionTable* source_position_table);
51
52 const char* reducer_name() const override { return "WasmGCOperatorReducer"; }
53
54 Reduction Reduce(Node* node) final;
55
56 private:
58
70 Reduction ReduceIf(Node* node, bool condition);
72
73 Node* SetType(Node* node, wasm::ValueType type);
74 void UpdateSourcePosition(Node* new_node, Node* old_node);
75 // Returns the intersection of the type marked on {object} and the type
76 // information about object tracked on {control}'s control path (if present).
77 // If {allow_non_wasm}, we bail out if the object's type is not a wasm type
78 // by returning bottom.
80 bool allow_non_wasm = false);
82 ControlPathTypes parent_state, Node* node,
84 bool in_new_block);
85
86 TFGraph* graph() { return mcgraph_->graph(); }
89
94};
95
96} // namespace compiler
97} // namespace internal
98} // namespace v8
99
100#endif // V8_COMPILER_WASM_GC_OPERATOR_REDUCER_H_
CommonOperatorBuilder * common() const
void UpdateSourcePosition(Node *new_node, Node *old_node)
WasmGCOperatorReducer(Editor *editor, Zone *temp_zone_, MachineGraph *mcgraph, const wasm::WasmModule *module, SourcePositionTable *source_position_table)
Node * SetType(Node *node, wasm::ValueType type)
wasm::TypeInModule ObjectTypeFromContext(Node *object, Node *control, bool allow_non_wasm=false)
Reduction UpdateNodeAndAliasesTypes(Node *state_owner, ControlPathTypes parent_state, Node *node, wasm::TypeInModule type, bool in_new_block)
SimplifiedOperatorBuilder * simplified() override
Definition c-api.cc:87
bool operator==(const NodeWithType &other) const
bool operator!=(const NodeWithType &other) const
NodeWithType(Node *node, wasm::TypeInModule type)