v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
csa-load-elimination.h
Go to the documentation of this file.
1// Copyright 2019 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_CSA_LOAD_ELIMINATION_H_
6#define V8_COMPILER_CSA_LOAD_ELIMINATION_H_
7
14
15namespace v8 {
16namespace internal {
17
18namespace compiler {
19
20// Forward declarations.
21class CommonOperatorBuilder;
22struct ObjectAccess;
23class TFGraph;
24class JSGraph;
25
27 : public NON_EXPORTED_BASE(AdvancedReducer) {
28 public:
29 CsaLoadElimination(Editor* editor, JSGraph* jsgraph, Zone* zone)
30 : AdvancedReducer(editor),
31 empty_state_(zone),
32 node_states_(jsgraph->graph()->NodeCount(), zone),
33 jsgraph_(jsgraph),
34 zone_(zone) {}
35 ~CsaLoadElimination() final = default;
37 CsaLoadElimination& operator=(const CsaLoadElimination&) = delete;
38
39 const char* reducer_name() const override { return "CsaLoadElimination"; }
40
41 Reduction Reduce(Node* node) final;
42
43 private:
44 struct FieldInfo {
45 FieldInfo() = default;
46 FieldInfo(Node* value, MachineRepresentation representation)
47 : value(value), representation(representation) {}
48
49 bool operator==(const FieldInfo& other) const {
50 return value == other.value && representation == other.representation;
51 }
52
53 bool operator!=(const FieldInfo& other) const { return !(*this == other); }
54
55 bool IsEmpty() const { return value == nullptr; }
56
57 Node* value = nullptr;
58 MachineRepresentation representation = MachineRepresentation::kNone;
59 };
60
61 // Design doc: https://bit.ly/36MfD6Y
62 class HalfState final : public ZoneObject {
63 public:
64 explicit HalfState(Zone* zone)
65 : zone_(zone),
66 fresh_entries_(zone, InnerMap(zone)),
67 constant_entries_(zone, InnerMap(zone)),
68 arbitrary_entries_(zone, InnerMap(zone)),
69 fresh_unknown_entries_(zone, InnerMap(zone)),
70 constant_unknown_entries_(zone, InnerMap(zone)),
71 arbitrary_unknown_entries_(zone, InnerMap(zone)) {}
72
73 bool Equals(HalfState const* that) const {
74 return fresh_entries_ == that->fresh_entries_ &&
75 constant_entries_ == that->constant_entries_ &&
76 arbitrary_entries_ == that->arbitrary_entries_ &&
77 fresh_unknown_entries_ == that->fresh_unknown_entries_ &&
78 constant_unknown_entries_ == that->constant_unknown_entries_ &&
79 arbitrary_unknown_entries_ == that->arbitrary_unknown_entries_;
80 }
81 void IntersectWith(HalfState const* that);
82 HalfState const* KillField(Node* object, Node* offset,
83 MachineRepresentation repr) const;
84 HalfState const* AddField(Node* object, Node* offset, Node* value,
85 MachineRepresentation repr) const;
86 FieldInfo Lookup(Node* object, Node* offset) const;
87 void Print() const;
88
89 private:
91 template <typename OuterKey>
93 // offset -> object -> info
95 // object -> offset -> info
97
98 // Update {map} so that {map.Get(outer_key).Get(inner_key)} returns {info}.
99 template <typename OuterKey>
100 static void Update(OuterMap<OuterKey>& map, OuterKey outer_key,
101 Node* inner_key, FieldInfo info) {
102 InnerMap map_copy(map.Get(outer_key));
103 map_copy.Set(inner_key, info);
104 map.Set(outer_key, map_copy);
105 }
106
107 // Kill all elements in {infos} which may alias with offset.
108 static void KillOffset(ConstantOffsetInfos& infos, uint32_t offset,
109 MachineRepresentation repr, Zone* zone);
110 void KillOffsetInFresh(Node* object, uint32_t offset,
112 template <typename OuterKey>
113 static void IntersectWith(OuterMap<OuterKey>& to,
114 const OuterMap<OuterKey>& from);
115 static void Print(const ConstantOffsetInfos& infos);
116 static void Print(const UnknownOffsetInfos& infos);
117
125 };
126
127 // An {AbstractState} consists of two {HalfState}s, representing the mutable
128 // and immutable sets of known fields, respectively. These sets correspond to
129 // LoadFromObject/StoreToObject and LoadImmutableFromObject/
130 // InitializeImmutableInObject respectively. The two half-states should not
131 // overlap.
132 struct AbstractState : public ZoneObject {
133 explicit AbstractState(Zone* zone)
134 : mutable_state(zone), immutable_state(zone) {}
135 explicit AbstractState(HalfState mutable_state, HalfState immutable_state)
136 : mutable_state(mutable_state), immutable_state(immutable_state) {}
137
138 bool Equals(AbstractState const* that) const {
139 return this->immutable_state.Equals(&that->immutable_state) &&
140 this->mutable_state.Equals(&that->mutable_state);
141 }
142 void IntersectWith(AbstractState const* that) {
143 mutable_state.IntersectWith(&that->mutable_state);
144 immutable_state.IntersectWith(&that->immutable_state);
145 }
146
149 };
150
151 Reduction ReduceLoadFromObject(Node* node, ObjectAccess const& access);
152 Reduction ReduceStoreToObject(Node* node, ObjectAccess const& access);
153 Reduction ReduceEffectPhi(Node* node);
154 Reduction ReduceStart(Node* node);
155 Reduction ReduceCall(Node* node);
156 Reduction ReduceOtherNode(Node* node);
157
158 Reduction UpdateState(Node* node, AbstractState const* state);
159 Reduction PropagateInputState(Node* node);
160
161 AbstractState const* ComputeLoopState(Node* node,
162 AbstractState const* state) const;
163 Node* TruncateAndExtend(Node* node, MachineRepresentation from,
164 MachineType to);
165 Reduction AssertUnreachable(Node* node);
166
167 CommonOperatorBuilder* common() const;
168 MachineOperatorBuilder* machine() const;
169 Isolate* isolate() const;
170 TFGraph* graph() const;
171 JSGraph* jsgraph() const { return jsgraph_; }
172 Zone* zone() const { return zone_; }
173 AbstractState const* empty_state() const { return &empty_state_; }
174
179};
180
181} // namespace compiler
182} // namespace internal
183} // namespace v8
184
185#endif // V8_COMPILER_CSA_LOAD_ELIMINATION_H_
TFGraph * graph
JSGraph * jsgraph
static void Update(OuterMap< OuterKey > &map, OuterKey outer_key, Node *inner_key, FieldInfo info)
NodeAuxData< AbstractState const * > node_states_
CsaLoadElimination(Editor *editor, JSGraph *jsgraph, Zone *zone)
Zone * zone_
Isolate * isolate
int32_t offset
#define NON_EXPORTED_BASE(code)
#define V8_EXPORT_PRIVATE
Definition macros.h:460
AbstractState(HalfState mutable_state, HalfState immutable_state)
FieldInfo(Node *value, MachineRepresentation representation)