| 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 #include "src/compiler/loop-variable-optimizer.h" | 5 #include "src/compiler/loop-variable-optimizer.h" |
| 6 | 6 |
| 7 #include "src/compiler/common-operator.h" | 7 #include "src/compiler/common-operator.h" |
| 8 #include "src/compiler/graph.h" | 8 #include "src/compiler/graph.h" |
| 9 #include "src/compiler/node-marker.h" | 9 #include "src/compiler/node-marker.h" |
| 10 #include "src/compiler/node-properties.h" | 10 #include "src/compiler/node-properties.h" |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 private: | 142 private: |
| 143 VariableLimits() {} | 143 VariableLimits() {} |
| 144 explicit VariableLimits(const VariableLimits* other) | 144 explicit VariableLimits(const VariableLimits* other) |
| 145 : head_(other->head_), limit_count_(other->limit_count_) {} | 145 : head_(other->head_), limit_count_(other->limit_count_) {} |
| 146 | 146 |
| 147 const Constraint* head_ = nullptr; | 147 const Constraint* head_ = nullptr; |
| 148 size_t limit_count_ = 0; | 148 size_t limit_count_ = 0; |
| 149 }; | 149 }; |
| 150 | 150 |
| 151 void InductionVariable::AddUpperBound(Node* bound, | 151 void InductionVariable::AddUpperBound(Node* bound, |
| 152 InductionVariable::ConstraintKind kind, | 152 InductionVariable::ConstraintKind kind) { |
| 153 Zone* graph_zone) { | |
| 154 if (FLAG_trace_turbo_loop) { | 153 if (FLAG_trace_turbo_loop) { |
| 155 OFStream os(stdout); | 154 OFStream os(stdout); |
| 156 os << "New upper bound for " << phi()->id() << " (loop " | 155 os << "New upper bound for " << phi()->id() << " (loop " |
| 157 << NodeProperties::GetControlInput(phi())->id() << "): " << *bound | 156 << NodeProperties::GetControlInput(phi())->id() << "): " << *bound |
| 158 << std::endl; | 157 << std::endl; |
| 159 } | 158 } |
| 160 upper_bounds_.push_back(Bound(bound, kind)); | 159 upper_bounds_.push_back(Bound(bound, kind)); |
| 161 } | 160 } |
| 162 | 161 |
| 163 void InductionVariable::AddLowerBound(Node* bound, | 162 void InductionVariable::AddLowerBound(Node* bound, |
| 164 InductionVariable::ConstraintKind kind, | 163 InductionVariable::ConstraintKind kind) { |
| 165 Zone* graph_zone) { | |
| 166 if (FLAG_trace_turbo_loop) { | 164 if (FLAG_trace_turbo_loop) { |
| 167 OFStream os(stdout); | 165 OFStream os(stdout); |
| 168 os << "New lower bound for " << phi()->id() << " (loop " | 166 os << "New lower bound for " << phi()->id() << " (loop " |
| 169 << NodeProperties::GetControlInput(phi())->id() << "): " << *bound; | 167 << NodeProperties::GetControlInput(phi())->id() << "): " << *bound; |
| 170 } | 168 } |
| 171 lower_bounds_.push_back(Bound(bound, kind)); | 169 lower_bounds_.push_back(Bound(bound, kind)); |
| 172 } | 170 } |
| 173 | 171 |
| 174 void LoopVariableOptimizer::VisitBackedge(Node* from, Node* loop) { | 172 void LoopVariableOptimizer::VisitBackedge(Node* from, Node* loop) { |
| 175 if (loop->op()->ControlInputCount() != 2) return; | 173 if (loop->op()->ControlInputCount() != 2) return; |
| 176 | 174 |
| 177 // Go through the constraints, and update the induction variables in | 175 // Go through the constraints, and update the induction variables in |
| 178 // this loop if they are involved in the constraint. | 176 // this loop if they are involved in the constraint. |
| 179 const VariableLimits* limits = limits_[from->id()]; | 177 const VariableLimits* limits = limits_[from->id()]; |
| 180 for (const Constraint* constraint = limits->head(); constraint != nullptr; | 178 for (const Constraint* constraint = limits->head(); constraint != nullptr; |
| 181 constraint = constraint->next()) { | 179 constraint = constraint->next()) { |
| 182 if (constraint->left()->opcode() == IrOpcode::kPhi && | 180 if (constraint->left()->opcode() == IrOpcode::kPhi && |
| 183 NodeProperties::GetControlInput(constraint->left()) == loop) { | 181 NodeProperties::GetControlInput(constraint->left()) == loop) { |
| 184 auto var = induction_vars_.find(constraint->left()->id()); | 182 auto var = induction_vars_.find(constraint->left()->id()); |
| 185 if (var != induction_vars_.end()) { | 183 if (var != induction_vars_.end()) { |
| 186 var->second->AddUpperBound(constraint->right(), constraint->kind(), | 184 var->second->AddUpperBound(constraint->right(), constraint->kind()); |
| 187 graph()->zone()); | |
| 188 } | 185 } |
| 189 } | 186 } |
| 190 if (constraint->right()->opcode() == IrOpcode::kPhi && | 187 if (constraint->right()->opcode() == IrOpcode::kPhi && |
| 191 NodeProperties::GetControlInput(constraint->right()) == loop) { | 188 NodeProperties::GetControlInput(constraint->right()) == loop) { |
| 192 auto var = induction_vars_.find(constraint->right()->id()); | 189 auto var = induction_vars_.find(constraint->right()->id()); |
| 193 if (var != induction_vars_.end()) { | 190 if (var != induction_vars_.end()) { |
| 194 var->second->AddUpperBound(constraint->left(), constraint->kind(), | 191 var->second->AddUpperBound(constraint->left(), constraint->kind()); |
| 195 graph()->zone()); | |
| 196 } | 192 } |
| 197 } | 193 } |
| 198 } | 194 } |
| 199 } | 195 } |
| 200 | 196 |
| 201 void LoopVariableOptimizer::VisitNode(Node* node) { | 197 void LoopVariableOptimizer::VisitNode(Node* node) { |
| 202 switch (node->opcode()) { | 198 switch (node->opcode()) { |
| 203 case IrOpcode::kMerge: | 199 case IrOpcode::kMerge: |
| 204 return VisitMerge(node); | 200 return VisitMerge(node); |
| 205 case IrOpcode::kLoop: | 201 case IrOpcode::kLoop: |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 backedge_value, backedge_control); | 391 backedge_value, backedge_control); |
| 396 induction_var->phi()->ReplaceInput(1, rename); | 392 induction_var->phi()->ReplaceInput(1, rename); |
| 397 } | 393 } |
| 398 } | 394 } |
| 399 } | 395 } |
| 400 } | 396 } |
| 401 | 397 |
| 402 } // namespace compiler | 398 } // namespace compiler |
| 403 } // namespace internal | 399 } // namespace internal |
| 404 } // namespace v8 | 400 } // namespace v8 |
| OLD | NEW |