OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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/common-operator.h" | 5 #include "src/compiler/common-operator.h" |
6 #include "src/compiler/control-reducer.h" | 6 #include "src/compiler/control-reducer.h" |
7 #include "src/compiler/graph.h" | 7 #include "src/compiler/graph.h" |
8 #include "src/compiler/js-graph.h" | 8 #include "src/compiler/js-graph.h" |
9 #include "src/compiler/node-matchers.h" | 9 #include "src/compiler/node-matchers.h" |
10 #include "src/compiler/node-properties-inl.h" | 10 #include "src/compiler/node-properties-inl.h" |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 } | 315 } |
316 } | 316 } |
317 | 317 |
318 // Reduce branches, phis, and merges. | 318 // Reduce branches, phis, and merges. |
319 switch (node->opcode()) { | 319 switch (node->opcode()) { |
320 case IrOpcode::kBranch: | 320 case IrOpcode::kBranch: |
321 return ReduceBranch(node); | 321 return ReduceBranch(node); |
322 case IrOpcode::kLoop: | 322 case IrOpcode::kLoop: |
323 case IrOpcode::kMerge: | 323 case IrOpcode::kMerge: |
324 return ReduceMerge(node); | 324 return ReduceMerge(node); |
| 325 case IrOpcode::kSelect: |
| 326 return ReduceSelect(node); |
325 case IrOpcode::kPhi: | 327 case IrOpcode::kPhi: |
326 case IrOpcode::kEffectPhi: | 328 case IrOpcode::kEffectPhi: |
327 return ReducePhi(node); | 329 return ReducePhi(node); |
328 default: | 330 default: |
329 return node; | 331 return node; |
330 } | 332 } |
331 } | 333 } |
332 | 334 |
| 335 // Reduce redundant selects. |
| 336 Node* ReduceSelect(Node* const node) { |
| 337 Node* const cond = node->InputAt(0); |
| 338 Node* const tvalue = node->InputAt(1); |
| 339 Node* const fvalue = node->InputAt(2); |
| 340 if (tvalue == fvalue) return tvalue; |
| 341 switch (cond->opcode()) { |
| 342 case IrOpcode::kInt32Constant: |
| 343 return Int32Matcher(cond).Is(0) ? fvalue : tvalue; |
| 344 case IrOpcode::kInt64Constant: |
| 345 return Int64Matcher(cond).Is(0) ? fvalue : tvalue; |
| 346 case IrOpcode::kNumberConstant: |
| 347 return NumberMatcher(cond).Is(0) ? fvalue : tvalue; |
| 348 case IrOpcode::kHeapConstant: { |
| 349 Handle<Object> object = |
| 350 HeapObjectMatcher<Object>(cond).Value().handle(); |
| 351 if (object->IsTrue()) return tvalue; |
| 352 if (object->IsFalse()) return fvalue; |
| 353 break; |
| 354 } |
| 355 default: |
| 356 break; |
| 357 } |
| 358 return node; |
| 359 } |
| 360 |
333 // Reduce redundant phis. | 361 // Reduce redundant phis. |
334 Node* ReducePhi(Node* node) { | 362 Node* ReducePhi(Node* node) { |
335 int n = node->InputCount(); | 363 int n = node->InputCount(); |
336 if (n <= 1) return dead(); // No non-control inputs. | 364 if (n <= 1) return dead(); // No non-control inputs. |
337 if (n == 2) return node->InputAt(0); // Only one non-control input. | 365 if (n == 2) return node->InputAt(0); // Only one non-control input. |
338 | 366 |
339 Node* replacement = NULL; | 367 Node* replacement = NULL; |
340 Node::Inputs inputs = node->inputs(); | 368 Node::Inputs inputs = node->inputs(); |
341 for (InputIter it = inputs.begin(); n > 1; --n, ++it) { | 369 for (InputIter it = inputs.begin(); n > 1; --n, ++it) { |
342 Node* input = *it; | 370 Node* input = *it; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 } | 427 } |
400 | 428 |
401 // Reduce branches if they have constant inputs. | 429 // Reduce branches if they have constant inputs. |
402 Node* ReduceBranch(Node* node) { | 430 Node* ReduceBranch(Node* node) { |
403 Node* cond = node->InputAt(0); | 431 Node* cond = node->InputAt(0); |
404 bool is_true; | 432 bool is_true; |
405 switch (cond->opcode()) { | 433 switch (cond->opcode()) { |
406 case IrOpcode::kInt32Constant: | 434 case IrOpcode::kInt32Constant: |
407 is_true = !Int32Matcher(cond).Is(0); | 435 is_true = !Int32Matcher(cond).Is(0); |
408 break; | 436 break; |
| 437 case IrOpcode::kInt64Constant: |
| 438 is_true = !Int64Matcher(cond).Is(0); |
| 439 break; |
409 case IrOpcode::kNumberConstant: | 440 case IrOpcode::kNumberConstant: |
410 is_true = !NumberMatcher(cond).Is(0); | 441 is_true = !NumberMatcher(cond).Is(0); |
411 break; | 442 break; |
412 case IrOpcode::kHeapConstant: { | 443 case IrOpcode::kHeapConstant: { |
413 Handle<Object> object = | 444 Handle<Object> object = |
414 HeapObjectMatcher<Object>(cond).Value().handle(); | 445 HeapObjectMatcher<Object>(cond).Value().handle(); |
415 if (object->IsTrue()) | 446 if (object->IsTrue()) |
416 is_true = true; | 447 is_true = true; |
417 else if (object->IsFalse()) | 448 else if (object->IsFalse()) |
418 is_true = false; | 449 is_true = false; |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 Node* ControlReducer::ReduceBranchForTesting(JSGraph* jsgraph, | 557 Node* ControlReducer::ReduceBranchForTesting(JSGraph* jsgraph, |
527 CommonOperatorBuilder* common, | 558 CommonOperatorBuilder* common, |
528 Node* node) { | 559 Node* node) { |
529 Zone zone(jsgraph->graph()->zone()->isolate()); | 560 Zone zone(jsgraph->graph()->zone()->isolate()); |
530 ControlReducerImpl impl(&zone, jsgraph, common); | 561 ControlReducerImpl impl(&zone, jsgraph, common); |
531 return impl.ReduceBranch(node); | 562 return impl.ReduceBranch(node); |
532 } | 563 } |
533 } | 564 } |
534 } | 565 } |
535 } // namespace v8::internal::compiler | 566 } // namespace v8::internal::compiler |
OLD | NEW |