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 3 // found in the LICENSE file. 4 5 #ifndef V8_COMPILER_REDUNDANCY_ELIMINATION_H_ 6 #define V8_COMPILER_REDUNDANCY_ELIMINATION_H_ 7 8 #include "src/compiler/graph-reducer.h" 9 10 namespace v8 { 11 namespace internal { 12 namespace compiler { 13 14 class RedundancyElimination final : public AdvancedReducer { 15 public: 16 RedundancyElimination(Editor* editor, Zone* zone); 17 ~RedundancyElimination() final; 18 19 Reduction Reduce(Node* node) final; 20 21 private: 22 struct Check { CheckCheck23 Check(Node* node, Check* next) : node(node), next(next) {} 24 Node* node; 25 Check* next; 26 }; 27 28 class EffectPathChecks final { 29 public: 30 static EffectPathChecks* Copy(Zone* zone, EffectPathChecks const* checks); 31 static EffectPathChecks const* Empty(Zone* zone); 32 bool Equals(EffectPathChecks const* that) const; 33 void Merge(EffectPathChecks const* that); 34 35 EffectPathChecks const* AddCheck(Zone* zone, Node* node) const; 36 Node* LookupCheck(Node* node) const; 37 38 private: EffectPathChecks(Check * head,size_t size)39 EffectPathChecks(Check* head, size_t size) : head_(head), size_(size) {} 40 41 // We keep track of the list length so that we can find the longest 42 // common tail easily. 43 Check* head_; 44 size_t size_; 45 }; 46 47 class PathChecksForEffectNodes final { 48 public: PathChecksForEffectNodes(Zone * zone)49 explicit PathChecksForEffectNodes(Zone* zone) : info_for_node_(zone) {} 50 EffectPathChecks const* Get(Node* node) const; 51 void Set(Node* node, EffectPathChecks const* checks); 52 53 private: 54 ZoneVector<EffectPathChecks const*> info_for_node_; 55 }; 56 57 Reduction ReduceCheckNode(Node* node); 58 Reduction ReduceEffectPhi(Node* node); 59 Reduction ReduceStart(Node* node); 60 Reduction ReduceOtherNode(Node* node); 61 62 Reduction TakeChecksFromFirstEffect(Node* node); 63 Reduction UpdateChecks(Node* node, EffectPathChecks const* checks); 64 zone()65 Zone* zone() const { return zone_; } 66 67 PathChecksForEffectNodes node_checks_; 68 Zone* const zone_; 69 70 DISALLOW_COPY_AND_ASSIGN(RedundancyElimination); 71 }; 72 73 } // namespace compiler 74 } // namespace internal 75 } // namespace v8 76 77 #endif // V8_COMPILER_REDUNDANCY_ELIMINATION_H_ 78