Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_COMPILER_STORE_STORE_ELIMINATION_H_ | 5 #ifndef V8_COMPILER_STORE_STORE_ELIMINATION_H_ |
| 6 #define V8_COMPILER_STORE_STORE_ELIMINATION_H_ | 6 #define V8_COMPILER_STORE_STORE_ELIMINATION_H_ |
| 7 | 7 |
| 8 #include "src/compiler/common-operator.h" | 8 #include "src/compiler/common-operator.h" |
| 9 #include "src/compiler/graph-reducer.h" | 9 #include "src/compiler/graph-reducer.h" |
| 10 #include "src/compiler/js-graph.h" | 10 #include "src/compiler/js-graph.h" |
| 11 #include "src/zone-containers.h" | |
| 11 | 12 |
| 12 namespace v8 { | 13 namespace v8 { |
| 13 namespace internal { | 14 namespace internal { |
| 14 namespace compiler { | 15 namespace compiler { |
| 15 | 16 |
| 16 // Forward declarations. | |
| 17 class CommonOperatorBuilder; | |
| 18 class JSGraph; | |
| 19 | |
| 20 class StoreStoreElimination final { | 17 class StoreStoreElimination final { |
| 21 public: | 18 public: |
| 22 StoreStoreElimination(JSGraph* js_graph, Zone* temp_zone); | 19 static void Run(JSGraph* js_graph, Zone* temp_zone); |
| 23 ~StoreStoreElimination(); | 20 }; |
|
Jarin
2016/07/20 11:43:33
All the stuff below should go to the .cc file sinc
bgeron
2016/07/20 16:27:17
Done. I put it in an anonymous namespace.
| |
| 24 void Run(); | 21 |
| 22 // 16 bits was chosen fairly arbitrarily; it seems enough now. 8 bits is too | |
| 23 // few. | |
| 24 typedef uint16_t StoreOffset; | |
| 25 | |
| 26 struct StoreObservation { | |
|
Jarin
2016/07/20 11:43:33
The name is a bit confusing because it seems to de
bgeron
2016/07/20 16:27:17
Changed to UnobservableStore.
| |
| 27 NodeId id_; | |
| 28 StoreOffset offset_; | |
| 29 }; | |
| 30 | |
| 31 bool operator==(StoreObservation, StoreObservation); | |
| 32 bool operator<(StoreObservation, StoreObservation); | |
| 33 std::ostream& operator<<(std::ostream&, StoreObservation); | |
| 34 | |
| 35 // Instances of UnobservablesSet are immutable. They represent either a set of | |
| 36 // StoreObservations, or the "undetermined empty set". | |
| 37 // | |
| 38 // The size of an instance should be the size of a pointer, plus additional | |
| 39 // space in the zone for determined UnobservablesSets. Copying an | |
| 40 // UnobservablesSet allocates no memory. | |
| 41 class UnobservablesSet final { | |
| 42 public: | |
| 43 static UnobservablesSet Undetermined(); | |
| 44 static UnobservablesSet DeterminedEmpty(Zone* zone); | |
| 45 UnobservablesSet(); // undetermined | |
| 46 UnobservablesSet(const UnobservablesSet& other) : set_(other.set_) {} | |
| 47 ~UnobservablesSet() {} | |
|
Jarin
2016/07/20 11:43:33
Why is the destructor here?
bgeron
2016/07/20 16:27:17
Because I thought that the implicitly generated de
| |
| 48 | |
| 49 UnobservablesSet Intersect(UnobservablesSet other, Zone* zone) const; | |
| 50 UnobservablesSet Add(StoreObservation obs, Zone* zone) const; | |
| 51 UnobservablesSet RemoveSameOffset(StoreOffset off, Zone* zone) const; | |
| 52 | |
| 53 const ZoneSet<StoreObservation>* set() const { return set_; } | |
| 54 | |
| 55 bool IsUndetermined() const { return set_ == nullptr; } | |
| 56 bool IsEmpty() const { return set_ == nullptr || set_->empty(); } | |
| 57 bool Contains(StoreObservation obs) const { | |
| 58 return set_ != nullptr && (set_->find(obs) != set_->end()); | |
| 59 } | |
| 60 | |
| 61 bool operator==(const UnobservablesSet& other) const; | |
| 62 bool operator!=(const UnobservablesSet& other) const; | |
| 63 | |
| 64 private: | |
| 65 explicit UnobservablesSet(const ZoneSet<StoreObservation>* set) : set_(set) {} | |
| 66 const ZoneSet<StoreObservation>* set_; | |
| 67 }; | |
| 68 | |
| 69 std::ostream& operator<<(std::ostream& os, UnobservablesSet set); | |
| 70 | |
| 71 class StoreStoreFinder final : public AdvancedReducer { | |
| 72 public: | |
| 73 StoreStoreFinder(Editor* editor, JSGraph* js_graph, Zone* temp_zone); | |
| 74 ~StoreStoreFinder(); | |
| 75 | |
| 76 const ZoneSet<Node*>& to_remove_const() { return to_remove_; } | |
| 77 | |
| 78 virtual Reduction Reduce(Node* node); | |
|
Jarin
2016/07/20 11:43:33
I have difficulty understanding why this is a redu
bgeron
2016/07/20 16:27:17
Changed as discussed.
| |
| 25 | 79 |
| 26 private: | 80 private: |
| 27 static bool IsEligibleNode(Node* node); | 81 static bool IsEligibleNode(Node* node); |
| 28 void ReduceEligibleNode(Node* node); | 82 Reduction ReduceEligibleNode(Node* node); |
| 83 UnobservablesSet RecomputeUseIntersection(Node* node); | |
| 84 UnobservablesSet RecomputeSet(Node* node, UnobservablesSet uses); | |
| 85 static bool CanObserveNothing(Node* node); | |
| 86 static bool CanObserveAnything(Node* node); | |
| 87 | |
| 29 JSGraph* jsgraph() const { return jsgraph_; } | 88 JSGraph* jsgraph() const { return jsgraph_; } |
| 30 Zone* temp_zone() const { return temp_zone_; } | 89 Zone* temp_zone() const { return temp_zone_; } |
| 90 ZoneVector<UnobservablesSet>& unobservable() { return unobservable_; } | |
| 91 ZoneSet<Node*>& to_remove() { return to_remove_; } | |
| 31 | 92 |
| 32 JSGraph* const jsgraph_; | 93 JSGraph* const jsgraph_; |
| 33 Zone* const temp_zone_; | 94 Zone* const temp_zone_; |
| 95 // Maps node IDs to UnobservableNodeSets. | |
| 96 ZoneVector<UnobservablesSet> unobservable_; | |
| 97 ZoneSet<Node*> to_remove_; | |
| 34 }; | 98 }; |
| 35 | 99 |
| 36 } // namespace compiler | 100 } // namespace compiler |
| 37 } // namespace internal | 101 } // namespace internal |
| 38 } // namespace v8 | 102 } // namespace v8 |
| 39 | 103 |
| 40 #endif // V8_COMPILER_STORE_STORE_ELIMINATION_H_ | 104 #endif // V8_COMPILER_STORE_STORE_ELIMINATION_H_ |
| OLD | NEW |