Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 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 { |
| 23 | 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 | void Merge(EffectPathChecks const* that); |
| 33 | |
| 34 | EffectPathChecks const* AddCheck(Zone* zone, Node* node) const; |
| 35 | Node* LookupCheck(Node* node) const; |
| 36 | |
| 37 | private: |
| 38 | EffectPathChecks(Check* head, size_t size) : head_(head), size_(size) {} |
| 39 | |
| 40 | // We keep track of the list length so that we can find the longest |
| 41 | // common tail easily. |
| 42 | Check* head_; |
| 43 | size_t size_; |
| 44 | }; |
| 45 | |
| 46 | class PathChecksForEffectNodes final { |
| 47 | public: |
| 48 | explicit PathChecksForEffectNodes(Zone* zone) : info_for_node_(zone) {} |
| 49 | EffectPathChecks const* Get(Node* node) const; |
| 50 | void Set(Node* node, EffectPathChecks const* checks); |
| 51 | |
| 52 | private: |
| 53 | ZoneVector<EffectPathChecks const*> info_for_node_; |
| 54 | }; |
| 55 | |
| 56 | Reduction ReduceCheckNode(Node* node); |
| 57 | Reduction ReduceEffectPhi(Node* node); |
| 58 | Reduction ReduceStart(Node* node); |
| 59 | Reduction ReduceOtherNode(Node* node); |
| 60 | |
| 61 | Reduction TakeChecksFromFirstEffect(Node* node); |
| 62 | Reduction UpdateChecks(Node* node, EffectPathChecks const* checks); |
| 63 | |
| 64 | Zone* zone() const { return zone_; } |
| 65 | |
| 66 | PathChecksForEffectNodes node_checks_; |
| 67 | Zone* const zone_; |
| 68 | |
| 69 | DISALLOW_COPY_AND_ASSIGN(RedundancyElimination); |
| 70 | }; |
| 71 | |
| 72 | } // namespace compiler |
| 73 | } // namespace internal |
| 74 | } // namespace v8 |
| 75 | |
| 76 | #endif // V8_COMPILER_REDUNDANCY_ELIMINATION_H_ |