• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
8 #include "src/base/compiler-specific.h"
9 #include "src/codegen/machine-type.h"
10 #include "src/common/globals.h"
11 #include "src/compiler/graph-reducer.h"
12 #include "src/compiler/js-graph.h"
13 #include "src/compiler/node-aux-data.h"
14 #include "src/compiler/persistent-map.h"
15 #include "src/handles/maybe-handles.h"
16 #include "src/zone/zone-handle-set.h"
17 
18 namespace v8 {
19 namespace internal {
20 
21 namespace compiler {
22 
23 // Forward declarations.
24 class CommonOperatorBuilder;
25 struct ObjectAccess;
26 class Graph;
27 class JSGraph;
28 
29 class V8_EXPORT_PRIVATE CsaLoadElimination final
NON_EXPORTED_BASE(AdvancedReducer)30     : public NON_EXPORTED_BASE(AdvancedReducer) {
31  public:
32   CsaLoadElimination(Editor* editor, JSGraph* jsgraph, Zone* zone)
33       : AdvancedReducer(editor),
34         empty_state_(zone),
35         node_states_(jsgraph->graph()->NodeCount(), zone),
36         jsgraph_(jsgraph),
37         zone_(zone) {}
38   ~CsaLoadElimination() final = default;
39   CsaLoadElimination(const CsaLoadElimination&) = delete;
40   CsaLoadElimination& operator=(const CsaLoadElimination&) = delete;
41 
42   const char* reducer_name() const override { return "CsaLoadElimination"; }
43 
44   Reduction Reduce(Node* node) final;
45 
46  private:
47   struct FieldInfo {
48     FieldInfo() = default;
49     FieldInfo(Node* value, MachineRepresentation representation)
50         : value(value), representation(representation) {}
51 
52     bool operator==(const FieldInfo& other) const {
53       return value == other.value && representation == other.representation;
54     }
55 
56     bool operator!=(const FieldInfo& other) const { return !(*this == other); }
57 
58     bool IsEmpty() const { return value == nullptr; }
59 
60     Node* value = nullptr;
61     MachineRepresentation representation = MachineRepresentation::kNone;
62   };
63 
64   class AbstractState final : public ZoneObject {
65    public:
66     explicit AbstractState(Zone* zone) : field_infos_(zone) {}
67 
68     bool Equals(AbstractState const* that) const {
69       return field_infos_ == that->field_infos_;
70     }
71     void Merge(AbstractState const* that, Zone* zone);
72 
73     AbstractState const* KillField(Node* object, Node* offset,
74                                    MachineRepresentation repr,
75                                    Zone* zone) const;
76     AbstractState const* AddField(Node* object, Node* offset, FieldInfo info,
77                                   Zone* zone) const;
78     FieldInfo Lookup(Node* object, Node* offset) const;
79 
80     void Print() const;
81 
82    private:
83     using Field = std::pair<Node*, Node*>;
84     using FieldInfos = PersistentMap<Field, FieldInfo>;
85     FieldInfos field_infos_;
86   };
87 
88   Reduction ReduceLoadFromObject(Node* node, ObjectAccess const& access);
89   Reduction ReduceStoreToObject(Node* node, ObjectAccess const& access);
90   Reduction ReduceEffectPhi(Node* node);
91   Reduction ReduceStart(Node* node);
92   Reduction ReduceCall(Node* node);
93   Reduction ReduceOtherNode(Node* node);
94 
95   Reduction UpdateState(Node* node, AbstractState const* state);
96   Reduction PropagateInputState(Node* node);
97 
98   AbstractState const* ComputeLoopState(Node* node,
99                                         AbstractState const* state) const;
100 
101   CommonOperatorBuilder* common() const;
102   Isolate* isolate() const;
103   Graph* graph() const;
104   JSGraph* jsgraph() const { return jsgraph_; }
105   Zone* zone() const { return zone_; }
106   AbstractState const* empty_state() const { return &empty_state_; }
107 
108   AbstractState const empty_state_;
109   NodeAuxData<AbstractState const*> node_states_;
110   JSGraph* const jsgraph_;
111   Zone* zone_;
112 };
113 
114 }  // namespace compiler
115 }  // namespace internal
116 }  // namespace v8
117 
118 #endif  // V8_COMPILER_CSA_LOAD_ELIMINATION_H_
119