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/representation-change.h" | 5 #include "src/compiler/representation-change.h" |
6 | 6 |
7 #include <sstream> | 7 #include <sstream> |
8 | 8 |
9 #include "src/base/bits.h" | 9 #include "src/base/bits.h" |
10 #include "src/code-factory.h" | 10 #include "src/code-factory.h" |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 case IrOpcode::kFloat32Constant: | 183 case IrOpcode::kFloat32Constant: |
184 return jsgraph()->Constant(OpParameter<float>(node)); | 184 return jsgraph()->Constant(OpParameter<float>(node)); |
185 default: | 185 default: |
186 break; | 186 break; |
187 } | 187 } |
188 // Select the correct X -> Tagged operator. | 188 // Select the correct X -> Tagged operator. |
189 const Operator* op; | 189 const Operator* op; |
190 if (output_rep == MachineRepresentation::kBit) { | 190 if (output_rep == MachineRepresentation::kBit) { |
191 op = simplified()->ChangeBitToBool(); | 191 op = simplified()->ChangeBitToBool(); |
192 } else if (IsWord(output_rep)) { | 192 } else if (IsWord(output_rep)) { |
193 if (output_type->Is(Type::Unsigned32())) { | 193 if (output_type->Is(Type::Signed31())) { |
194 op = simplified()->ChangeUint32ToTagged(); | 194 op = simplified()->ChangeInt31ToTagged(); |
195 } else if (output_type->Is(Type::Signed32())) { | 195 } else if (output_type->Is(Type::Signed32())) { |
196 op = simplified()->ChangeInt32ToTagged(); | 196 op = simplified()->ChangeInt32ToTagged(); |
| 197 } else if (output_type->Is(Type::Unsigned32())) { |
| 198 op = simplified()->ChangeUint32ToTagged(); |
197 } else { | 199 } else { |
198 return TypeError(node, output_rep, output_type, | 200 return TypeError(node, output_rep, output_type, |
199 MachineRepresentation::kTagged); | 201 MachineRepresentation::kTagged); |
200 } | 202 } |
201 } else if (output_rep == | 203 } else if (output_rep == |
202 MachineRepresentation::kFloat32) { // float32 -> float64 -> tagged | 204 MachineRepresentation::kFloat32) { // float32 -> float64 -> tagged |
203 node = InsertChangeFloat32ToFloat64(node); | 205 node = InsertChangeFloat32ToFloat64(node); |
| 206 // TODO(bmeurer): Pass -0 hint to ChangeFloat64ToTagged. |
204 op = simplified()->ChangeFloat64ToTagged(); | 207 op = simplified()->ChangeFloat64ToTagged(); |
205 } else if (output_rep == MachineRepresentation::kFloat64) { | 208 } else if (output_rep == MachineRepresentation::kFloat64) { |
206 op = simplified()->ChangeFloat64ToTagged(); | 209 if (output_type->Is(Type::Signed31())) { // float64 -> int32 -> tagged |
| 210 node = InsertChangeFloat64ToInt32(node); |
| 211 op = simplified()->ChangeInt31ToTagged(); |
| 212 } else if (output_type->Is( |
| 213 Type::Signed32())) { // float64 -> int32 -> tagged |
| 214 node = InsertChangeFloat64ToInt32(node); |
| 215 op = simplified()->ChangeInt32ToTagged(); |
| 216 } else if (output_type->Is( |
| 217 Type::Unsigned32())) { // float64 -> uint32 -> tagged |
| 218 node = InsertChangeFloat64ToUint32(node); |
| 219 op = simplified()->ChangeUint32ToTagged(); |
| 220 } else { |
| 221 // TODO(bmeurer): Pass -0 hint to ChangeFloat64ToTagged. |
| 222 op = simplified()->ChangeFloat64ToTagged(); |
| 223 } |
207 } else { | 224 } else { |
208 return TypeError(node, output_rep, output_type, | 225 return TypeError(node, output_rep, output_type, |
209 MachineRepresentation::kTagged); | 226 MachineRepresentation::kTagged); |
210 } | 227 } |
211 return jsgraph()->graph()->NewNode(op, node); | 228 return jsgraph()->graph()->NewNode(op, node); |
212 } | 229 } |
213 | 230 |
214 | 231 |
215 Node* RepresentationChanger::GetFloat32RepresentationFor( | 232 Node* RepresentationChanger::GetFloat32RepresentationFor( |
216 Node* node, MachineRepresentation output_rep, Type* output_type, | 233 Node* node, MachineRepresentation output_rep, Type* output_type, |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 use_str.str().c_str()); | 538 use_str.str().c_str()); |
522 } | 539 } |
523 return node; | 540 return node; |
524 } | 541 } |
525 | 542 |
526 | 543 |
527 Node* RepresentationChanger::InsertChangeFloat32ToFloat64(Node* node) { | 544 Node* RepresentationChanger::InsertChangeFloat32ToFloat64(Node* node) { |
528 return jsgraph()->graph()->NewNode(machine()->ChangeFloat32ToFloat64(), node); | 545 return jsgraph()->graph()->NewNode(machine()->ChangeFloat32ToFloat64(), node); |
529 } | 546 } |
530 | 547 |
| 548 Node* RepresentationChanger::InsertChangeFloat64ToUint32(Node* node) { |
| 549 return jsgraph()->graph()->NewNode(machine()->ChangeFloat64ToUint32(), node); |
| 550 } |
| 551 |
| 552 Node* RepresentationChanger::InsertChangeFloat64ToInt32(Node* node) { |
| 553 return jsgraph()->graph()->NewNode(machine()->ChangeFloat64ToInt32(), node); |
| 554 } |
531 | 555 |
532 Node* RepresentationChanger::InsertChangeTaggedToFloat64(Node* node) { | 556 Node* RepresentationChanger::InsertChangeTaggedToFloat64(Node* node) { |
533 return jsgraph()->graph()->NewNode(simplified()->ChangeTaggedToFloat64(), | 557 return jsgraph()->graph()->NewNode(simplified()->ChangeTaggedToFloat64(), |
534 node); | 558 node); |
535 } | 559 } |
536 | 560 |
537 } // namespace compiler | 561 } // namespace compiler |
538 } // namespace internal | 562 } // namespace internal |
539 } // namespace v8 | 563 } // namespace v8 |
OLD | NEW |