| 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 } | 135 } |
| 136 } | 136 } |
| 137 | 137 |
| 138 switch (use_info.representation()) { | 138 switch (use_info.representation()) { |
| 139 case MachineRepresentation::kTaggedSigned: | 139 case MachineRepresentation::kTaggedSigned: |
| 140 DCHECK(use_info.type_check() == TypeCheckKind::kNone || | 140 DCHECK(use_info.type_check() == TypeCheckKind::kNone || |
| 141 use_info.type_check() == TypeCheckKind::kSignedSmall); | 141 use_info.type_check() == TypeCheckKind::kSignedSmall); |
| 142 return GetTaggedSignedRepresentationFor(node, output_rep, output_type, | 142 return GetTaggedSignedRepresentationFor(node, output_rep, output_type, |
| 143 use_node, use_info); | 143 use_node, use_info); |
| 144 case MachineRepresentation::kTaggedPointer: | 144 case MachineRepresentation::kTaggedPointer: |
| 145 DCHECK(use_info.type_check() == TypeCheckKind::kNone); | 145 DCHECK(use_info.type_check() == TypeCheckKind::kNone || |
| 146 return GetTaggedPointerRepresentationFor(node, output_rep, output_type); | 146 use_info.type_check() == TypeCheckKind::kHeapObject); |
| 147 return GetTaggedPointerRepresentationFor(node, output_rep, output_type, |
| 148 use_node, use_info); |
| 147 case MachineRepresentation::kTagged: | 149 case MachineRepresentation::kTagged: |
| 148 DCHECK(use_info.type_check() == TypeCheckKind::kNone); | 150 DCHECK(use_info.type_check() == TypeCheckKind::kNone); |
| 149 return GetTaggedRepresentationFor(node, output_rep, output_type, | 151 return GetTaggedRepresentationFor(node, output_rep, output_type, |
| 150 use_info.truncation()); | 152 use_info.truncation()); |
| 151 case MachineRepresentation::kFloat32: | 153 case MachineRepresentation::kFloat32: |
| 152 DCHECK(use_info.type_check() == TypeCheckKind::kNone); | 154 DCHECK(use_info.type_check() == TypeCheckKind::kNone); |
| 153 return GetFloat32RepresentationFor(node, output_rep, output_type, | 155 return GetFloat32RepresentationFor(node, output_rep, output_type, |
| 154 use_info.truncation()); | 156 use_info.truncation()); |
| 155 case MachineRepresentation::kFloat64: | 157 case MachineRepresentation::kFloat64: |
| 156 return GetFloat64RepresentationFor(node, output_rep, output_type, | 158 return GetFloat64RepresentationFor(node, output_rep, output_type, |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 node = InsertChangeBitToTagged(node); | 280 node = InsertChangeBitToTagged(node); |
| 279 op = simplified()->CheckedTaggedToTaggedSigned(); | 281 op = simplified()->CheckedTaggedToTaggedSigned(); |
| 280 } else { | 282 } else { |
| 281 return TypeError(node, output_rep, output_type, | 283 return TypeError(node, output_rep, output_type, |
| 282 MachineRepresentation::kTaggedSigned); | 284 MachineRepresentation::kTaggedSigned); |
| 283 } | 285 } |
| 284 return InsertConversion(node, op, use_node); | 286 return InsertConversion(node, op, use_node); |
| 285 } | 287 } |
| 286 | 288 |
| 287 Node* RepresentationChanger::GetTaggedPointerRepresentationFor( | 289 Node* RepresentationChanger::GetTaggedPointerRepresentationFor( |
| 288 Node* node, MachineRepresentation output_rep, Type* output_type) { | 290 Node* node, MachineRepresentation output_rep, Type* output_type, |
| 291 Node* use_node, UseInfo use_info) { |
| 289 // Eagerly fold representation changes for constants. | 292 // Eagerly fold representation changes for constants. |
| 290 switch (node->opcode()) { | 293 switch (node->opcode()) { |
| 291 case IrOpcode::kHeapConstant: | 294 case IrOpcode::kHeapConstant: |
| 292 return node; // No change necessary. | 295 return node; // No change necessary. |
| 293 case IrOpcode::kInt32Constant: | 296 case IrOpcode::kInt32Constant: |
| 294 case IrOpcode::kFloat64Constant: | 297 case IrOpcode::kFloat64Constant: |
| 295 case IrOpcode::kFloat32Constant: | 298 case IrOpcode::kFloat32Constant: |
| 296 UNREACHABLE(); | 299 UNREACHABLE(); |
| 297 default: | 300 default: |
| 298 break; | 301 break; |
| 299 } | 302 } |
| 300 // Select the correct X -> Tagged operator. | 303 // Select the correct X -> TaggedPointer operator. |
| 304 Operator const* op; |
| 301 if (output_type->Is(Type::None())) { | 305 if (output_type->Is(Type::None())) { |
| 302 // This is an impossible value; it should not be used at runtime. | 306 // This is an impossible value; it should not be used at runtime. |
| 303 // We just provide a dummy value here. | 307 // We just provide a dummy value here. |
| 304 return jsgraph()->TheHoleConstant(); | 308 return jsgraph()->TheHoleConstant(); |
| 309 } else if (output_rep == MachineRepresentation::kBit) { |
| 310 return node; |
| 311 } else if (IsWord(output_rep)) { |
| 312 if (output_type->Is(Type::Unsigned32())) { |
| 313 // uint32 -> float64 -> tagged |
| 314 node = InsertChangeUint32ToFloat64(node); |
| 315 } else if (output_type->Is(Type::Signed32())) { |
| 316 // int32 -> float64 -> tagged |
| 317 node = InsertChangeInt32ToFloat64(node); |
| 318 } else { |
| 319 return TypeError(node, output_rep, output_type, |
| 320 MachineRepresentation::kTaggedPointer); |
| 321 } |
| 322 op = simplified()->ChangeFloat64ToTaggedPointer(); |
| 323 } else if (output_rep == MachineRepresentation::kFloat32) { |
| 324 // float32 -> float64 -> tagged |
| 325 node = InsertChangeFloat32ToFloat64(node); |
| 326 op = simplified()->ChangeFloat64ToTaggedPointer(); |
| 327 } else if (output_rep == MachineRepresentation::kFloat64) { |
| 328 // float64 -> tagged |
| 329 op = simplified()->ChangeFloat64ToTaggedPointer(); |
| 330 } else if (CanBeTaggedSigned(output_rep) && |
| 331 use_info.type_check() == TypeCheckKind::kHeapObject) { |
| 332 if (!output_type->Maybe(Type::SignedSmall())) { |
| 333 return node; |
| 334 } |
| 335 // TODO(turbofan): Consider adding a Bailout operator that just deopts |
| 336 // for TaggedSigned output representation. |
| 337 op = simplified()->CheckedTaggedToTaggedPointer(); |
| 338 } else { |
| 339 return TypeError(node, output_rep, output_type, |
| 340 MachineRepresentation::kTaggedPointer); |
| 305 } | 341 } |
| 306 return TypeError(node, output_rep, output_type, | 342 return InsertConversion(node, op, use_node); |
| 307 MachineRepresentation::kTaggedPointer); | |
| 308 } | 343 } |
| 309 | 344 |
| 310 Node* RepresentationChanger::GetTaggedRepresentationFor( | 345 Node* RepresentationChanger::GetTaggedRepresentationFor( |
| 311 Node* node, MachineRepresentation output_rep, Type* output_type, | 346 Node* node, MachineRepresentation output_rep, Type* output_type, |
| 312 Truncation truncation) { | 347 Truncation truncation) { |
| 313 // Eagerly fold representation changes for constants. | 348 // Eagerly fold representation changes for constants. |
| 314 switch (node->opcode()) { | 349 switch (node->opcode()) { |
| 315 case IrOpcode::kNumberConstant: | 350 case IrOpcode::kNumberConstant: |
| 316 case IrOpcode::kHeapConstant: | 351 case IrOpcode::kHeapConstant: |
| 317 return node; // No change necessary. | 352 return node; // No change necessary. |
| (...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 946 } | 981 } |
| 947 | 982 |
| 948 Node* RepresentationChanger::InsertChangeFloat64ToUint32(Node* node) { | 983 Node* RepresentationChanger::InsertChangeFloat64ToUint32(Node* node) { |
| 949 return jsgraph()->graph()->NewNode(machine()->ChangeFloat64ToUint32(), node); | 984 return jsgraph()->graph()->NewNode(machine()->ChangeFloat64ToUint32(), node); |
| 950 } | 985 } |
| 951 | 986 |
| 952 Node* RepresentationChanger::InsertChangeFloat64ToInt32(Node* node) { | 987 Node* RepresentationChanger::InsertChangeFloat64ToInt32(Node* node) { |
| 953 return jsgraph()->graph()->NewNode(machine()->ChangeFloat64ToInt32(), node); | 988 return jsgraph()->graph()->NewNode(machine()->ChangeFloat64ToInt32(), node); |
| 954 } | 989 } |
| 955 | 990 |
| 991 Node* RepresentationChanger::InsertChangeInt32ToFloat64(Node* node) { |
| 992 return jsgraph()->graph()->NewNode(machine()->ChangeInt32ToFloat64(), node); |
| 993 } |
| 994 |
| 956 Node* RepresentationChanger::InsertChangeTaggedSignedToInt32(Node* node) { | 995 Node* RepresentationChanger::InsertChangeTaggedSignedToInt32(Node* node) { |
| 957 return jsgraph()->graph()->NewNode(simplified()->ChangeTaggedSignedToInt32(), | 996 return jsgraph()->graph()->NewNode(simplified()->ChangeTaggedSignedToInt32(), |
| 958 node); | 997 node); |
| 959 } | 998 } |
| 960 | 999 |
| 961 Node* RepresentationChanger::InsertChangeTaggedToFloat64(Node* node) { | 1000 Node* RepresentationChanger::InsertChangeTaggedToFloat64(Node* node) { |
| 962 return jsgraph()->graph()->NewNode(simplified()->ChangeTaggedToFloat64(), | 1001 return jsgraph()->graph()->NewNode(simplified()->ChangeTaggedToFloat64(), |
| 963 node); | 1002 node); |
| 964 } | 1003 } |
| 965 | 1004 |
| 1005 Node* RepresentationChanger::InsertChangeUint32ToFloat64(Node* node) { |
| 1006 return jsgraph()->graph()->NewNode(machine()->ChangeUint32ToFloat64(), node); |
| 1007 } |
| 1008 |
| 966 } // namespace compiler | 1009 } // namespace compiler |
| 967 } // namespace internal | 1010 } // namespace internal |
| 968 } // namespace v8 | 1011 } // namespace v8 |
| OLD | NEW |