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/graph-reducer.h" | 8 #include "src/compiler/graph-reducer.h" |
9 #include "src/compiler/js-graph.h" | 9 #include "src/compiler/js-graph.h" |
10 #include "src/compiler/node-marker.h" | 10 #include "src/compiler/node-marker.h" |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 result = ReduceEnd(node); | 80 result = ReduceEnd(node); |
81 break; | 81 break; |
82 default: | 82 default: |
83 break; | 83 break; |
84 } | 84 } |
85 | 85 |
86 return result == node ? NoChange() : Replace(result); | 86 return result == node ? NoChange() : Replace(result); |
87 } | 87 } |
88 | 88 |
89 // Try to statically fold a condition. | 89 // Try to statically fold a condition. |
90 Decision DecideCondition(Node* cond, bool recurse = true) { | 90 Decision DecideCondition(Node* cond) { |
91 switch (cond->opcode()) { | 91 switch (cond->opcode()) { |
92 case IrOpcode::kInt32Constant: | 92 case IrOpcode::kInt32Constant: |
93 return Int32Matcher(cond).Is(0) ? kFalse : kTrue; | 93 return Int32Matcher(cond).Is(0) ? kFalse : kTrue; |
94 case IrOpcode::kInt64Constant: | 94 case IrOpcode::kInt64Constant: |
95 return Int64Matcher(cond).Is(0) ? kFalse : kTrue; | 95 return Int64Matcher(cond).Is(0) ? kFalse : kTrue; |
96 case IrOpcode::kHeapConstant: { | 96 case IrOpcode::kHeapConstant: { |
97 Handle<Object> object = | 97 Handle<Object> object = |
98 HeapObjectMatcher<Object>(cond).Value().handle(); | 98 HeapObjectMatcher<Object>(cond).Value().handle(); |
99 return object->BooleanValue() ? kTrue : kFalse; | 99 return object->BooleanValue() ? kTrue : kFalse; |
100 } | 100 } |
101 case IrOpcode::kPhi: { | |
102 if (!recurse) return kUnknown; // Only go one level deep checking phis. | |
103 Decision result = kUnknown; | |
104 // Check if all inputs to a phi result in the same decision. | |
105 for (int i = cond->op()->ValueInputCount() - 1; i >= 0; i--) { | |
106 // Recurse only one level, since phis can be involved in cycles. | |
107 Decision decision = DecideCondition(cond->InputAt(i), false); | |
108 if (decision == kUnknown) return kUnknown; | |
109 if (result == kUnknown) result = decision; | |
110 if (result != decision) return kUnknown; | |
111 } | |
112 return result; | |
113 } | |
114 default: | 101 default: |
115 break; | 102 break; |
116 } | 103 } |
117 return kUnknown; | 104 return kUnknown; |
118 } | 105 } |
119 | 106 |
120 // Reduce redundant selects. | 107 // Reduce redundant selects. |
121 Node* ReduceSelect(Node* const node) { | 108 Node* ReduceSelect(Node* const node) { |
122 Node* const tvalue = node->InputAt(1); | 109 Node* const tvalue = node->InputAt(1); |
123 Node* const fvalue = node->InputAt(2); | 110 Node* const fvalue = node->InputAt(2); |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 case IrOpcode::kIfFalse: | 360 case IrOpcode::kIfFalse: |
374 return impl.ReduceIfProjection(node, kFalse); | 361 return impl.ReduceIfProjection(node, kFalse); |
375 default: | 362 default: |
376 return node; | 363 return node; |
377 } | 364 } |
378 } | 365 } |
379 | 366 |
380 } // namespace compiler | 367 } // namespace compiler |
381 } // namespace internal | 368 } // namespace internal |
382 } // namespace v8 | 369 } // namespace v8 |
OLD | NEW |