OLD | NEW |
(Empty) | |
| 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_LOOP_VARIABLE_OPTIMIZER_H_ |
| 6 #define V8_COMPILER_LOOP_VARIABLE_OPTIMIZER_H_ |
| 7 |
| 8 #include "src/zone-containers.h" |
| 9 |
| 10 namespace v8 { |
| 11 namespace internal { |
| 12 namespace compiler { |
| 13 |
| 14 class CommonOperatorBuilder; |
| 15 class Graph; |
| 16 class Node; |
| 17 |
| 18 class InductionVariable : public ZoneObject { |
| 19 public: |
| 20 Node* phi() const { return phi_; } |
| 21 Node* arith() const { return arith_; } |
| 22 Node* increment() const { return increment_; } |
| 23 Node* init_value() const { return init_value_; } |
| 24 |
| 25 enum ConstraintKind { kStrict, kNonStrict }; |
| 26 struct Bound { |
| 27 Bound(Node* bound, ConstraintKind kind) : bound(bound), kind(kind) {} |
| 28 |
| 29 Node* bound; |
| 30 ConstraintKind kind; |
| 31 }; |
| 32 |
| 33 const ZoneVector<Bound>& lower_bounds() { return lower_bounds_; } |
| 34 const ZoneVector<Bound>& upper_bounds() { return upper_bounds_; } |
| 35 |
| 36 private: |
| 37 friend class LoopVariableOptimizer; |
| 38 |
| 39 InductionVariable(Node* phi, Node* arith, Node* increment, Node* init_value, |
| 40 Zone* zone) |
| 41 : phi_(phi), |
| 42 arith_(arith), |
| 43 increment_(increment), |
| 44 init_value_(init_value), |
| 45 lower_bounds_(zone), |
| 46 upper_bounds_(zone) {} |
| 47 |
| 48 void AddUpperBound(Node* bound, ConstraintKind kind, Zone* graph_zone); |
| 49 void AddLowerBound(Node* bound, ConstraintKind kind, Zone* graph_zone); |
| 50 |
| 51 Node* phi_; |
| 52 Node* arith_; |
| 53 Node* increment_; |
| 54 Node* init_value_; |
| 55 ZoneVector<Bound> lower_bounds_; |
| 56 ZoneVector<Bound> upper_bounds_; |
| 57 }; |
| 58 |
| 59 class LoopVariableOptimizer { |
| 60 public: |
| 61 void Run(); |
| 62 |
| 63 LoopVariableOptimizer(Graph* graph, CommonOperatorBuilder* common, |
| 64 Zone* zone); |
| 65 |
| 66 const ZoneMap<int, InductionVariable*>& induction_variables() { |
| 67 return induction_vars_; |
| 68 } |
| 69 |
| 70 void ChangeToInductionVariablePhis(); |
| 71 void ChangeFromInductionVariablePhis(); |
| 72 |
| 73 private: |
| 74 const int kAssumedLoopEntryIndex = 0; |
| 75 const int kFirstBackedge = 1; |
| 76 |
| 77 class Constraint; |
| 78 class VariableLimits; |
| 79 |
| 80 void VisitBackedge(Node* from, Node* loop); |
| 81 void VisitNode(Node* node); |
| 82 void VisitMerge(Node* node); |
| 83 void VisitLoop(Node* node); |
| 84 void VisitIf(Node* node, bool polarity); |
| 85 void VisitStart(Node* node); |
| 86 void VisitLoopExit(Node* node); |
| 87 void VisitOtherControl(Node* node); |
| 88 |
| 89 void AddCmpToLimits(VariableLimits* limits, Node* node, |
| 90 InductionVariable::ConstraintKind kind, bool polarity); |
| 91 |
| 92 void TakeConditionsFromFirstControl(Node* node); |
| 93 const InductionVariable* FindInductionVariable(Node* node); |
| 94 InductionVariable* TryGetInductionVariable(Node* phi); |
| 95 void DetectInductionVariables(Node* loop); |
| 96 |
| 97 Graph* graph() { return graph_; } |
| 98 CommonOperatorBuilder* common() { return common_; } |
| 99 Zone* zone() { return zone_; } |
| 100 |
| 101 Graph* graph_; |
| 102 CommonOperatorBuilder* common_; |
| 103 Zone* zone_; |
| 104 ZoneMap<int, const VariableLimits*> limits_; |
| 105 ZoneMap<int, InductionVariable*> induction_vars_; |
| 106 }; |
| 107 |
| 108 } // namespace compiler |
| 109 } // namespace internal |
| 110 } // namespace v8 |
| 111 |
| 112 #endif // V8_COMPILER_LOOP_VARIABLE_OPTIMIZER_H_ |
OLD | NEW |