OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/control-flow-optimizer.h" | 5 #include "src/compiler/control-flow-optimizer.h" |
6 | 6 |
7 #include "src/compiler/js-graph.h" | 7 #include "src/compiler/js-graph.h" |
8 #include "src/compiler/node-matchers.h" | 8 #include "src/compiler/node-matchers.h" |
9 #include "src/compiler/node-properties.h" | 9 #include "src/compiler/node-properties.h" |
10 | 10 |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 cond->Kill(); | 197 cond->Kill(); |
198 merge->Kill(); | 198 merge->Kill(); |
199 return true; | 199 return true; |
200 } | 200 } |
201 | 201 |
202 | 202 |
203 bool ControlFlowOptimizer::TryBuildSwitch(Node* node) { | 203 bool ControlFlowOptimizer::TryBuildSwitch(Node* node) { |
204 DCHECK_EQ(IrOpcode::kBranch, node->opcode()); | 204 DCHECK_EQ(IrOpcode::kBranch, node->opcode()); |
205 | 205 |
206 Node* branch = node; | 206 Node* branch = node; |
| 207 if (BranchHintOf(branch->op()) != BranchHint::kNone) return false; |
207 Node* cond = NodeProperties::GetValueInput(branch, 0); | 208 Node* cond = NodeProperties::GetValueInput(branch, 0); |
208 if (cond->opcode() != IrOpcode::kWord32Equal) return false; | 209 if (cond->opcode() != IrOpcode::kWord32Equal) return false; |
209 Int32BinopMatcher m(cond); | 210 Int32BinopMatcher m(cond); |
210 Node* index = m.left().node(); | 211 Node* index = m.left().node(); |
211 if (!m.right().HasValue()) return false; | 212 if (!m.right().HasValue()) return false; |
212 int32_t value = m.right().Value(); | 213 int32_t value = m.right().Value(); |
213 ZoneSet<int32_t> values(zone()); | 214 ZoneSet<int32_t> values(zone()); |
214 values.insert(value); | 215 values.insert(value); |
215 | 216 |
216 Node* if_false; | 217 Node* if_false; |
217 Node* if_true; | 218 Node* if_true; |
218 while (true) { | 219 while (true) { |
219 Node* control_projections[2]; | 220 Node* control_projections[2]; |
220 NodeProperties::CollectControlProjections(branch, control_projections, 2); | 221 NodeProperties::CollectControlProjections(branch, control_projections, 2); |
221 if_true = control_projections[0]; | 222 if_true = control_projections[0]; |
222 if_false = control_projections[1]; | 223 if_false = control_projections[1]; |
223 DCHECK_EQ(IrOpcode::kIfTrue, if_true->opcode()); | 224 DCHECK_EQ(IrOpcode::kIfTrue, if_true->opcode()); |
224 DCHECK_EQ(IrOpcode::kIfFalse, if_false->opcode()); | 225 DCHECK_EQ(IrOpcode::kIfFalse, if_false->opcode()); |
225 | 226 |
226 auto it = if_false->uses().begin(); | 227 auto it = if_false->uses().begin(); |
227 if (it == if_false->uses().end()) break; | 228 if (it == if_false->uses().end()) break; |
228 Node* branch1 = *it++; | 229 Node* branch1 = *it++; |
229 if (branch1->opcode() != IrOpcode::kBranch) break; | 230 if (branch1->opcode() != IrOpcode::kBranch) break; |
| 231 if (BranchHintOf(branch1->op()) != BranchHint::kNone) break; |
230 if (it != if_false->uses().end()) break; | 232 if (it != if_false->uses().end()) break; |
231 Node* cond1 = branch1->InputAt(0); | 233 Node* cond1 = branch1->InputAt(0); |
232 if (cond1->opcode() != IrOpcode::kWord32Equal) break; | 234 if (cond1->opcode() != IrOpcode::kWord32Equal) break; |
233 Int32BinopMatcher m1(cond1); | 235 Int32BinopMatcher m1(cond1); |
234 if (m1.left().node() != index) break; | 236 if (m1.left().node() != index) break; |
235 if (!m1.right().HasValue()) break; | 237 if (!m1.right().HasValue()) break; |
236 int32_t value1 = m1.right().Value(); | 238 int32_t value1 = m1.right().Value(); |
237 if (values.find(value1) != values.end()) break; | 239 if (values.find(value1) != values.end()) break; |
238 DCHECK_NE(value, value1); | 240 DCHECK_NE(value, value1); |
239 | 241 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 Graph* ControlFlowOptimizer::graph() const { return jsgraph()->graph(); } | 284 Graph* ControlFlowOptimizer::graph() const { return jsgraph()->graph(); } |
283 | 285 |
284 | 286 |
285 MachineOperatorBuilder* ControlFlowOptimizer::machine() const { | 287 MachineOperatorBuilder* ControlFlowOptimizer::machine() const { |
286 return jsgraph()->machine(); | 288 return jsgraph()->machine(); |
287 } | 289 } |
288 | 290 |
289 } // namespace compiler | 291 } // namespace compiler |
290 } // namespace internal | 292 } // namespace internal |
291 } // namespace v8 | 293 } // namespace v8 |
OLD | NEW |