Chromium Code Reviews| Index: src/compiler/representation-change.h |
| diff --git a/src/compiler/representation-change.h b/src/compiler/representation-change.h |
| index e9486f332a3f77aa09cc449419a23bfaa665a1f8..7e5603e02a8b4018dd71402aecfc40cd536d2dc5 100644 |
| --- a/src/compiler/representation-change.h |
| +++ b/src/compiler/representation-change.h |
| @@ -88,6 +88,8 @@ class RepresentationChanger { |
| } |
| case IrOpcode::kFloat64Constant: |
| return jsgraph()->Constant(OpParameter<double>(node)); |
| + case IrOpcode::kFloat32Constant: |
| + return jsgraph()->Constant(OpParameter<float>(node)); |
| default: |
| break; |
| } |
| @@ -103,9 +105,8 @@ class RepresentationChanger { |
| } else { |
| return TypeError(node, output_type, kRepTagged); |
| } |
| - } else if (output_type & kRepFloat32) { |
| - node = jsgraph()->graph()->NewNode(machine()->ChangeFloat32ToFloat64(), |
| - node); |
| + } else if (output_type & kRepFloat32) { // float32 -> float64 -> tagged |
| + node = InsertChangeFloat32ToFloat64(node); |
| op = simplified()->ChangeFloat64ToTagged(); |
| } else if (output_type & kRepFloat64) { |
| op = simplified()->ChangeFloat64ToTagged(); |
| @@ -118,14 +119,46 @@ class RepresentationChanger { |
| Node* GetFloat32RepresentationFor(Node* node, MachineTypeUnion output_type) { |
| // Eagerly fold representation changes for constants. |
| switch (node->opcode()) { |
| - // TODO(turbofan): NumberConstant, Int32Constant, and Float64Constant? |
| + case IrOpcode::kFloat64Constant: |
| + case IrOpcode::kNumberConstant: |
| + return jsgraph()->Float32Constant(OpParameter<float>(node)); |
|
Benedikt Meurer
2014/09/24 11:43:31
DoubleToFloat32(OpParameter<double>(node))
titzer
2014/09/24 11:52:40
Done.
|
| + case IrOpcode::kInt32Constant: |
| + if (output_type & kTypeUint32) { |
| + uint32_t value = OpParameter<uint32_t>(node); |
| + return jsgraph()->Float32Constant(static_cast<float>(value)); |
|
Benedikt Meurer
2014/09/24 11:43:31
is that static_cast<float> necessary?
titzer
2014/09/24 11:52:40
Done.
|
| + } else { |
| + int32_t value = OpParameter<int32_t>(node); |
| + return jsgraph()->Float32Constant(value); |
| + } |
| case IrOpcode::kFloat32Constant: |
| return node; // No change necessary. |
| default: |
| break; |
| } |
| - // TODO(turbofan): Select the correct X -> Float32 operator. |
| - return TypeError(node, output_type, kRepFloat32); |
| + // Select the correct X -> Float32 operator. |
| + const Operator* op; |
| + if (output_type & kRepBit) { |
| + return TypeError(node, output_type, kRepFloat32); |
| + } else if (output_type & rWord) { |
| + if (output_type & kTypeUint32) { |
| + op = machine()->ChangeUint32ToFloat64(); |
| + } else { |
| + op = machine()->ChangeInt32ToFloat64(); |
| + } |
| + // int32 -> float64 -> float32 |
| + node = jsgraph()->graph()->NewNode(op, node); |
| + op = machine()->TruncateFloat64ToFloat32(); |
| + } else if (output_type & kRepTagged) { |
| + op = simplified() |
| + ->ChangeTaggedToFloat64(); // tagged -> float64 -> float32 |
| + node = jsgraph()->graph()->NewNode(op, node); |
| + op = machine()->TruncateFloat64ToFloat32(); |
| + } else if (output_type & kRepFloat64) { |
| + op = machine()->ChangeFloat32ToFloat64(); |
| + } else { |
| + return TypeError(node, output_type, kRepFloat32); |
| + } |
| + return jsgraph()->graph()->NewNode(op, node); |
| } |
| Node* GetFloat64RepresentationFor(Node* node, MachineTypeUnion output_type) { |
| @@ -143,6 +176,8 @@ class RepresentationChanger { |
| } |
| case IrOpcode::kFloat64Constant: |
| return node; // No change necessary. |
| + case IrOpcode::kFloat32Constant: |
| + return jsgraph()->Float64Constant(OpParameter<float>(node)); |
| default: |
| break; |
| } |
| @@ -166,6 +201,18 @@ class RepresentationChanger { |
| return jsgraph()->graph()->NewNode(op, node); |
| } |
| + Node* MakeInt32Constant(double value) { |
| + if (value < 0) { |
| + DCHECK(IsInt32Double(value)); |
| + int32_t iv = static_cast<int32_t>(value); |
| + return jsgraph()->Int32Constant(iv); |
| + } else { |
| + DCHECK(IsUint32Double(value)); |
| + int32_t iv = static_cast<int32_t>(static_cast<uint32_t>(value)); |
| + return jsgraph()->Int32Constant(iv); |
| + } |
| + } |
| + |
| Node* GetWord32RepresentationFor(Node* node, MachineTypeUnion output_type, |
| bool use_unsigned) { |
| // Eagerly fold representation changes for constants. |
| @@ -173,18 +220,10 @@ class RepresentationChanger { |
| case IrOpcode::kInt32Constant: |
| return node; // No change necessary. |
| case IrOpcode::kNumberConstant: |
| - case IrOpcode::kFloat64Constant: { |
| - double value = OpParameter<double>(node); |
| - if (value < 0) { |
| - DCHECK(IsInt32Double(value)); |
| - int32_t iv = static_cast<int32_t>(value); |
| - return jsgraph()->Int32Constant(iv); |
| - } else { |
| - DCHECK(IsUint32Double(value)); |
| - int32_t iv = static_cast<int32_t>(static_cast<uint32_t>(value)); |
| - return jsgraph()->Int32Constant(iv); |
| - } |
| - } |
| + case IrOpcode::kFloat32Constant: |
| + return MakeInt32Constant(OpParameter<float>(node)); |
| + case IrOpcode::kFloat64Constant: |
| + return MakeInt32Constant(OpParameter<double>(node)); |
| default: |
| break; |
| } |
| @@ -196,6 +235,13 @@ class RepresentationChanger { |
| } else { |
| op = machine()->ChangeFloat64ToInt32(); |
| } |
| + } else if (output_type & kRepFloat32) { |
| + node = InsertChangeFloat32ToFloat64(node); // float32 -> float64 -> int32 |
| + if (output_type & kTypeUint32 || use_unsigned) { |
| + op = machine()->ChangeFloat64ToUint32(); |
| + } else { |
| + op = machine()->ChangeFloat64ToInt32(); |
| + } |
| } else if (output_type & kRepTagged) { |
| if (output_type & kTypeUint32 || use_unsigned) { |
| op = simplified()->ChangeTaggedToUint32(); |
| @@ -367,6 +413,11 @@ class RepresentationChanger { |
| return node; |
| } |
| + Node* InsertChangeFloat32ToFloat64(Node* node) { |
| + return jsgraph()->graph()->NewNode(machine()->ChangeFloat32ToFloat64(), |
| + node); |
| + } |
| + |
| JSGraph* jsgraph() { return jsgraph_; } |
| Isolate* isolate() { return isolate_; } |
| SimplifiedOperatorBuilder* simplified() { return simplified_; } |