5 #ifndef V8_COMPILER_LOAD_ELIMINATION_H_ 6 #define V8_COMPILER_LOAD_ELIMINATION_H_ 8 #include "src/base/compiler-specific.h" 9 #include "src/compiler/graph-reducer.h" 10 #include "src/globals.h" 11 #include "src/machine-type.h" 12 #include "src/maybe-handles.h" 13 #include "src/zone/zone-handle-set.h" 24 class CommonOperatorBuilder;
30 :
public NON_EXPORTED_BASE(AdvancedReducer) {
36 const char* reducer_name()
const override {
return "LoadElimination"; }
41 static const size_t kMaxTrackedElements = 8;
45 class AbstractElements final :
public ZoneObject {
47 explicit AbstractElements(
Zone* zone) {
48 for (
size_t i = 0;
i < arraysize(elements_); ++
i) {
49 elements_[
i] = Element();
53 MachineRepresentation representation,
Zone* zone)
54 : AbstractElements(zone) {
55 elements_[next_index_++] = Element(
object, index, value, representation);
58 AbstractElements
const* Extend(
Node*
object,
Node* index,
Node* value,
59 MachineRepresentation representation,
61 AbstractElements* that =
new (zone) AbstractElements(*
this);
62 that->elements_[that->next_index_] =
63 Element(
object, index, value, representation);
64 that->next_index_ = (that->next_index_ + 1) % arraysize(elements_);
68 MachineRepresentation representation)
const;
69 AbstractElements
const* Kill(
Node*
object,
Node* index,
Zone* zone)
const;
70 bool Equals(AbstractElements
const* that)
const;
71 AbstractElements
const* Merge(AbstractElements
const* that,
80 MachineRepresentation representation)
84 representation(representation) {}
86 Node*
object =
nullptr;
87 Node* index =
nullptr;
88 Node* value =
nullptr;
89 MachineRepresentation representation = MachineRepresentation::kNone;
92 Element elements_[kMaxTrackedElements];
93 size_t next_index_ = 0;
103 class AbstractField final :
public ZoneObject {
105 explicit AbstractField(
Zone* zone) : info_for_node_(zone) {}
107 : info_for_node_(zone) {
108 info_for_node_.insert(std::make_pair(
object, Field(value, name)));
111 AbstractField
const* Extend(
Node*
object,
Node* value,
113 AbstractField* that =
new (zone) AbstractField(zone);
114 that->info_for_node_ = this->info_for_node_;
115 that->info_for_node_.insert(std::make_pair(
object, Field(value, name)));
121 bool Equals(AbstractField
const* that)
const {
122 return this == that || this->info_for_node_ == that->info_for_node_;
124 AbstractField
const* Merge(AbstractField
const* that,
Zone* zone)
const {
125 if (this->Equals(that))
return this;
126 AbstractField* copy =
new (zone) AbstractField(zone);
127 for (
auto this_it : this->info_for_node_) {
128 Node* this_object = this_it.first;
129 Field this_second = this_it.second;
130 if (this_object->IsDead())
continue;
131 auto that_it = that->info_for_node_.find(this_object);
132 if (that_it != that->info_for_node_.end() &&
133 that_it->second == this_second) {
134 copy->info_for_node_.insert(this_it);
147 bool operator==(
const Field& other)
const {
148 return value == other.value && name.address() == other.name.address();
151 Node* value =
nullptr;
158 static size_t const kMaxTrackedFields = 32;
162 class AbstractMaps final :
public ZoneObject {
164 explicit AbstractMaps(
Zone* zone);
172 bool Equals(AbstractMaps
const* that)
const {
173 return this == that || this->info_for_node_ == that->info_for_node_;
175 AbstractMaps
const* Merge(AbstractMaps
const* that,
Zone* zone)
const;
183 class AbstractState final :
public ZoneObject {
186 for (
size_t i = 0;
i < arraysize(fields_); ++
i) {
187 fields_[
i] =
nullptr;
191 bool Equals(AbstractState
const* that)
const;
192 void Merge(AbstractState
const* that,
Zone* zone);
196 AbstractState
const* KillMaps(
Node*
object,
Zone* zone)
const;
201 AbstractState
const* AddField(
Node*
object,
size_t index,
Node* value,
206 AbstractState
const* KillField(
Node*
object,
size_t index,
210 Node* LookupField(
Node*
object,
size_t index)
const;
212 AbstractState
const* AddElement(
Node*
object,
Node* index,
Node* value,
213 MachineRepresentation representation,
215 AbstractState
const* KillElement(
Node*
object,
Node* index,
218 MachineRepresentation representation)
const;
223 AbstractElements
const* elements_ =
nullptr;
224 AbstractField
const* fields_[kMaxTrackedFields];
225 AbstractMaps
const* maps_ =
nullptr;
228 class AbstractStateForEffectNodes final :
public ZoneObject {
230 explicit AbstractStateForEffectNodes(
Zone* zone) : info_for_node_(zone) {}
231 AbstractState
const* Get(
Node* node)
const;
232 void Set(
Node* node, AbstractState
const* state);
234 Zone* zone()
const {
return info_for_node_.get_allocator().zone(); }
256 Reduction UpdateState(
Node* node, AbstractState
const* state);
258 AbstractState
const* ComputeLoopState(
Node* node,
259 AbstractState
const* state)
const;
260 AbstractState
const* UpdateStateForPhi(AbstractState
const* state,
263 static int FieldIndexOf(
int offset);
264 static int FieldIndexOf(
FieldAccess const& access);
267 AbstractState
const* empty_state()
const {
return &empty_state_; }
270 Graph* graph()
const;
271 JSGraph* jsgraph()
const {
return jsgraph_; }
272 Zone* zone()
const {
return node_states_.zone(); }
274 AbstractState
const empty_state_;
275 AbstractStateForEffectNodes node_states_;
285 #endif // V8_COMPILER_LOAD_ELIMINATION_H_