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/simplified-operator-reducer.h" | 5 #include "src/compiler/simplified-operator-reducer.h" |
6 | 6 |
7 #include "src/compiler/js-graph.h" | 7 #include "src/compiler/js-graph.h" |
8 #include "src/compiler/machine-operator.h" | 8 #include "src/compiler/machine-operator.h" |
9 #include "src/compiler/node-matchers.h" | 9 #include "src/compiler/node-matchers.h" |
10 #include "src/compiler/operator-properties.h" | 10 #include "src/compiler/operator-properties.h" |
| 11 #include "src/compiler/simplified-operator.h" |
11 #include "src/conversions-inl.h" | 12 #include "src/conversions-inl.h" |
12 #include "src/type-cache.h" | 13 #include "src/type-cache.h" |
13 | 14 |
14 namespace v8 { | 15 namespace v8 { |
15 namespace internal { | 16 namespace internal { |
16 namespace compiler { | 17 namespace compiler { |
17 | 18 |
18 SimplifiedOperatorReducer::SimplifiedOperatorReducer(JSGraph* jsgraph) | 19 SimplifiedOperatorReducer::SimplifiedOperatorReducer(JSGraph* jsgraph) |
19 : jsgraph_(jsgraph), type_cache_(TypeCache::Get()) {} | 20 : jsgraph_(jsgraph), type_cache_(TypeCache::Get()) {} |
20 | 21 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 case IrOpcode::kNumberTrunc: { | 115 case IrOpcode::kNumberTrunc: { |
115 Node* const input = NodeProperties::GetValueInput(node, 0); | 116 Node* const input = NodeProperties::GetValueInput(node, 0); |
116 Type* const input_type = NodeProperties::GetType(input); | 117 Type* const input_type = NodeProperties::GetType(input); |
117 if (input_type->Is(type_cache_.kIntegerOrMinusZeroOrNaN)) { | 118 if (input_type->Is(type_cache_.kIntegerOrMinusZeroOrNaN)) { |
118 return Replace(input); | 119 return Replace(input); |
119 } | 120 } |
120 break; | 121 break; |
121 } | 122 } |
122 case IrOpcode::kReferenceEqual: | 123 case IrOpcode::kReferenceEqual: |
123 return ReduceReferenceEqual(node); | 124 return ReduceReferenceEqual(node); |
| 125 case IrOpcode::kTypeGuard: |
| 126 return ReduceTypeGuard(node); |
124 default: | 127 default: |
125 break; | 128 break; |
126 } | 129 } |
127 return NoChange(); | 130 return NoChange(); |
128 } | 131 } |
129 | 132 |
130 Reduction SimplifiedOperatorReducer::ReduceReferenceEqual(Node* node) { | 133 Reduction SimplifiedOperatorReducer::ReduceReferenceEqual(Node* node) { |
131 DCHECK_EQ(IrOpcode::kReferenceEqual, node->opcode()); | 134 DCHECK_EQ(IrOpcode::kReferenceEqual, node->opcode()); |
132 Node* const left = NodeProperties::GetValueInput(node, 0); | 135 Node* const left = NodeProperties::GetValueInput(node, 0); |
133 Node* const right = NodeProperties::GetValueInput(node, 1); | 136 Node* const right = NodeProperties::GetValueInput(node, 1); |
134 HeapObjectMatcher match_left(left); | 137 HeapObjectMatcher match_left(left); |
135 HeapObjectMatcher match_right(right); | 138 HeapObjectMatcher match_right(right); |
136 if (match_left.HasValue() && match_right.HasValue()) { | 139 if (match_left.HasValue() && match_right.HasValue()) { |
137 if (match_left.Value().is_identical_to(match_right.Value())) { | 140 if (match_left.Value().is_identical_to(match_right.Value())) { |
138 return Replace(jsgraph()->TrueConstant()); | 141 return Replace(jsgraph()->TrueConstant()); |
139 } else { | 142 } else { |
140 return Replace(jsgraph()->FalseConstant()); | 143 return Replace(jsgraph()->FalseConstant()); |
141 } | 144 } |
142 } | 145 } |
143 return NoChange(); | 146 return NoChange(); |
144 } | 147 } |
145 | 148 |
| 149 Reduction SimplifiedOperatorReducer::ReduceTypeGuard(Node* node) { |
| 150 DCHECK_EQ(IrOpcode::kTypeGuard, node->opcode()); |
| 151 Node* const input = NodeProperties::GetValueInput(node, 0); |
| 152 Type* const input_type = NodeProperties::GetTypeOrAny(input); |
| 153 Type* const guard_type = TypeOf(node->op()); |
| 154 if (input_type->Is(guard_type)) return Replace(input); |
| 155 return NoChange(); |
| 156 } |
146 | 157 |
147 Reduction SimplifiedOperatorReducer::Change(Node* node, const Operator* op, | 158 Reduction SimplifiedOperatorReducer::Change(Node* node, const Operator* op, |
148 Node* a) { | 159 Node* a) { |
149 DCHECK_EQ(node->InputCount(), OperatorProperties::GetTotalInputCount(op)); | 160 DCHECK_EQ(node->InputCount(), OperatorProperties::GetTotalInputCount(op)); |
150 DCHECK_LE(1, node->InputCount()); | 161 DCHECK_LE(1, node->InputCount()); |
151 node->ReplaceInput(0, a); | 162 node->ReplaceInput(0, a); |
152 NodeProperties::ChangeOp(node, op); | 163 NodeProperties::ChangeOp(node, op); |
153 return Changed(node); | 164 return Changed(node); |
154 } | 165 } |
155 | 166 |
(...skipping 21 matching lines...) Expand all Loading... |
177 Graph* SimplifiedOperatorReducer::graph() const { return jsgraph()->graph(); } | 188 Graph* SimplifiedOperatorReducer::graph() const { return jsgraph()->graph(); } |
178 | 189 |
179 | 190 |
180 MachineOperatorBuilder* SimplifiedOperatorReducer::machine() const { | 191 MachineOperatorBuilder* SimplifiedOperatorReducer::machine() const { |
181 return jsgraph()->machine(); | 192 return jsgraph()->machine(); |
182 } | 193 } |
183 | 194 |
184 } // namespace compiler | 195 } // namespace compiler |
185 } // namespace internal | 196 } // namespace internal |
186 } // namespace v8 | 197 } // namespace v8 |
OLD | NEW |