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 #ifndef V8_COMPILER_REPRESENTATION_CHANGE_H_ | 5 #ifndef V8_COMPILER_REPRESENTATION_CHANGE_H_ |
6 #define V8_COMPILER_REPRESENTATION_CHANGE_H_ | 6 #define V8_COMPILER_REPRESENTATION_CHANGE_H_ |
7 | 7 |
8 #include <sstream> | 8 #include <sstream> |
9 | 9 |
10 #include "src/base/bits.h" | 10 #include "src/base/bits.h" |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 DCHECK(IsInt32Double(value)); | 209 DCHECK(IsInt32Double(value)); |
210 int32_t iv = static_cast<int32_t>(value); | 210 int32_t iv = static_cast<int32_t>(value); |
211 return jsgraph()->Int32Constant(iv); | 211 return jsgraph()->Int32Constant(iv); |
212 } else { | 212 } else { |
213 DCHECK(IsUint32Double(value)); | 213 DCHECK(IsUint32Double(value)); |
214 int32_t iv = static_cast<int32_t>(static_cast<uint32_t>(value)); | 214 int32_t iv = static_cast<int32_t>(static_cast<uint32_t>(value)); |
215 return jsgraph()->Int32Constant(iv); | 215 return jsgraph()->Int32Constant(iv); |
216 } | 216 } |
217 } | 217 } |
218 | 218 |
| 219 Node* GetTruncatedWord32For(Node* node, MachineTypeUnion output_type) { |
| 220 // Eagerly fold truncations for constants. |
| 221 switch (node->opcode()) { |
| 222 case IrOpcode::kInt32Constant: |
| 223 return node; // No change necessary. |
| 224 case IrOpcode::kFloat32Constant: |
| 225 return jsgraph()->Int32Constant( |
| 226 DoubleToInt32(OpParameter<float>(node))); |
| 227 case IrOpcode::kNumberConstant: |
| 228 case IrOpcode::kFloat64Constant: |
| 229 return jsgraph()->Int32Constant( |
| 230 DoubleToInt32(OpParameter<double>(node))); |
| 231 default: |
| 232 break; |
| 233 } |
| 234 // Select the correct X -> Word32 truncation operator. |
| 235 const Operator* op = NULL; |
| 236 if (output_type & kRepFloat64) { |
| 237 op = machine()->TruncateFloat64ToInt32(); |
| 238 } else if (output_type & kRepFloat32) { |
| 239 node = InsertChangeFloat32ToFloat64(node); |
| 240 op = machine()->TruncateFloat64ToInt32(); |
| 241 } else if (output_type & kRepTagged) { |
| 242 node = InsertChangeTaggedToFloat64(node); |
| 243 op = machine()->TruncateFloat64ToInt32(); |
| 244 } else { |
| 245 return TypeError(node, output_type, kRepWord32); |
| 246 } |
| 247 return jsgraph()->graph()->NewNode(op, node); |
| 248 } |
| 249 |
219 Node* GetWord32RepresentationFor(Node* node, MachineTypeUnion output_type, | 250 Node* GetWord32RepresentationFor(Node* node, MachineTypeUnion output_type, |
220 bool use_unsigned) { | 251 bool use_unsigned) { |
221 // Eagerly fold representation changes for constants. | 252 // Eagerly fold representation changes for constants. |
222 switch (node->opcode()) { | 253 switch (node->opcode()) { |
223 case IrOpcode::kInt32Constant: | 254 case IrOpcode::kInt32Constant: |
224 return node; // No change necessary. | 255 return node; // No change necessary. |
225 case IrOpcode::kFloat32Constant: | 256 case IrOpcode::kFloat32Constant: |
226 return MakeInt32Constant(OpParameter<float>(node)); | 257 return MakeInt32Constant(OpParameter<float>(node)); |
227 case IrOpcode::kNumberConstant: | 258 case IrOpcode::kNumberConstant: |
228 case IrOpcode::kFloat64Constant: | 259 case IrOpcode::kFloat64Constant: |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 use_str.str().c_str()); | 445 use_str.str().c_str()); |
415 } | 446 } |
416 return node; | 447 return node; |
417 } | 448 } |
418 | 449 |
419 Node* InsertChangeFloat32ToFloat64(Node* node) { | 450 Node* InsertChangeFloat32ToFloat64(Node* node) { |
420 return jsgraph()->graph()->NewNode(machine()->ChangeFloat32ToFloat64(), | 451 return jsgraph()->graph()->NewNode(machine()->ChangeFloat32ToFloat64(), |
421 node); | 452 node); |
422 } | 453 } |
423 | 454 |
| 455 Node* InsertChangeTaggedToFloat64(Node* node) { |
| 456 return jsgraph()->graph()->NewNode(simplified()->ChangeTaggedToFloat64(), |
| 457 node); |
| 458 } |
| 459 |
424 JSGraph* jsgraph() { return jsgraph_; } | 460 JSGraph* jsgraph() { return jsgraph_; } |
425 Isolate* isolate() { return isolate_; } | 461 Isolate* isolate() { return isolate_; } |
426 SimplifiedOperatorBuilder* simplified() { return simplified_; } | 462 SimplifiedOperatorBuilder* simplified() { return simplified_; } |
427 MachineOperatorBuilder* machine() { return jsgraph()->machine(); } | 463 MachineOperatorBuilder* machine() { return jsgraph()->machine(); } |
428 }; | 464 }; |
429 | 465 |
430 } // namespace compiler | 466 } // namespace compiler |
431 } // namespace internal | 467 } // namespace internal |
432 } // namespace v8 | 468 } // namespace v8 |
433 | 469 |
434 #endif // V8_COMPILER_REPRESENTATION_CHANGE_H_ | 470 #endif // V8_COMPILER_REPRESENTATION_CHANGE_H_ |
OLD | NEW |