v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
wasm-load-elimination.h
Go to the documentation of this file.
1// Copyright 2023 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_LOAD_ELIMINATION_H_
6#define V8_COMPILER_WASM_LOAD_ELIMINATION_H_
7
13
14namespace v8::internal::compiler {
15
16// Forward declarations.
17class CommonOperatorBuilder;
18class TFGraph;
19class JSGraph;
20class MachineOperatorBuilder;
21struct ObjectAccess;
22
24 : public NON_EXPORTED_BASE(AdvancedReducer) {
25 public:
26 WasmLoadElimination(Editor* editor, JSGraph* jsgraph, Zone* zone);
27 ~WasmLoadElimination() final = default;
29 WasmLoadElimination& operator=(const WasmLoadElimination&) = delete;
30
31 const char* reducer_name() const override { return "WasmLoadElimination"; }
32
33 Reduction Reduce(Node* node) final;
34
35 private:
38 explicit FieldOrElementValue(Node* value) : value(value) {}
39
40 bool operator==(const FieldOrElementValue& other) const {
41 return value == other.value;
42 }
43
44 bool operator!=(const FieldOrElementValue& other) const {
45 return !(*this == other);
46 }
47
48 bool IsEmpty() const { return value == nullptr; }
49
50 Node* value = nullptr;
51 };
52
53 class HalfState final : public ZoneObject {
54 public:
55 explicit HalfState(Zone* zone)
56 : zone_(zone),
57 fields_(zone, InnerMap(zone)),
58 elements_(zone, InnerMap(zone)) {}
59
60 bool Equals(HalfState const* that) const {
61 return fields_ == that->fields_ && elements_ == that->elements_;
62 }
63 bool IsEmpty() const {
64 return fields_.begin() == fields_.end() &&
65 elements_.begin() == elements_.end();
66 }
67 void IntersectWith(HalfState const* that);
68 HalfState const* KillField(int field_index, Node* object) const;
69 HalfState const* AddField(int field_index, Node* object, Node* value) const;
70 FieldOrElementValue LookupField(int field_index, Node* object) const;
71 void Print() const;
72
73 private:
75 template <typename OuterKey>
77 // offset -> object -> info
79 // object -> offset -> info
81
82 // Update {map} so that {map.Get(outer_key).Get(inner_key)} returns {info}.
83 template <typename OuterKey>
84 static void Update(OuterMap<OuterKey>& map, OuterKey outer_key,
85 Node* inner_key, FieldOrElementValue info) {
86 InnerMap map_copy(map.Get(outer_key));
87 map_copy.Set(inner_key, info);
88 map.Set(outer_key, map_copy);
89 }
90
91 static void Print(const FieldInfos& infos);
92 static void Print(const ElementInfos& infos);
93
97 };
98
99 // An {AbstractState} consists of two {HalfState}s, representing the sets of
100 // known mutable and immutable struct fields, respectively. The two
101 // half-states should not overlap.
102 struct AbstractState : public ZoneObject {
103 explicit AbstractState(Zone* zone)
104 : mutable_state(zone), immutable_state(zone) {}
105 explicit AbstractState(HalfState mutable_state, HalfState immutable_state)
106 : mutable_state(mutable_state), immutable_state(immutable_state) {}
107
108 bool Equals(AbstractState const* that) const {
109 return this->immutable_state.Equals(&that->immutable_state) &&
110 this->mutable_state.Equals(&that->mutable_state);
111 }
112 void IntersectWith(AbstractState const* that) {
113 mutable_state.IntersectWith(&that->mutable_state);
114 immutable_state.IntersectWith(&that->immutable_state);
115 }
116
119 };
120
121 Reduction ReduceWasmStructGet(Node* node);
122 Reduction ReduceWasmStructSet(Node* node);
123 Reduction ReduceWasmArrayLength(Node* node);
124 Reduction ReduceWasmArrayInitializeLength(Node* node);
125 Reduction ReduceStringPrepareForGetCodeunit(Node* node);
126 Reduction ReduceStringAsWtf16(Node* node);
127 Reduction ReduceAnyConvertExtern(Node* node);
128 Reduction ReduceEffectPhi(Node* node);
129 Reduction ReduceStart(Node* node);
130 Reduction ReduceOtherNode(Node* node);
131
132 // Reduce an operation that could be treated as a load from an immutable
133 // object.
134 Reduction ReduceLoadLikeFromImmutable(Node* node, int index);
135
136 Reduction UpdateState(Node* node, AbstractState const* state);
137
138 AbstractState const* ComputeLoopState(Node* node,
139 AbstractState const* state) const;
140 // Returns the replacement value and effect for a load given an initial value
141 // node, after optional {TypeGuard}ing and i8/i16 adaptation to i32.
142 std::tuple<Node*, Node*> TruncateAndExtendOrType(Node* value, Node* effect,
143 Node* control,
144 wasm::ValueType field_type,
145 bool is_signed);
147
148 CommonOperatorBuilder* common() const;
149 MachineOperatorBuilder* machine() const;
150 Isolate* isolate() const;
151 TFGraph* graph() const;
152 JSGraph* jsgraph() const { return jsgraph_; }
153 Node* dead() const { return dead_; }
154 Zone* zone() const { return zone_; }
155 AbstractState const* empty_state() const { return &empty_state_; }
156
162};
163
164} // namespace v8::internal::compiler
165
166#endif // V8_COMPILER_WASM_LOAD_ELIMINATION_H_
TFGraph * graph
JSGraph * jsgraph
static void Update(OuterMap< OuterKey > &map, OuterKey outer_key, Node *inner_key, FieldOrElementValue info)
static void Print(const ElementInfos &infos)
static void Print(const FieldInfos &infos)
NodeAuxData< AbstractState const * > node_states_
Zone * zone_
Isolate * isolate
Handle< FixedArray > elements_
Definition isolate.cc:1119
#define NON_EXPORTED_BASE(code)
#define V8_EXPORT_PRIVATE
Definition macros.h:460
AbstractState(HalfState mutable_state, HalfState immutable_state)