| 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 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 } else if (output_type & kRepTagged) { | 204 } else if (output_type & kRepTagged) { |
| 205 op = simplified()->ChangeTaggedToFloat64(); | 205 op = simplified()->ChangeTaggedToFloat64(); |
| 206 } else if (output_type & kRepFloat32) { | 206 } else if (output_type & kRepFloat32) { |
| 207 op = machine()->ChangeFloat32ToFloat64(); | 207 op = machine()->ChangeFloat32ToFloat64(); |
| 208 } else { | 208 } else { |
| 209 return TypeError(node, output_type, kRepFloat64); | 209 return TypeError(node, output_type, kRepFloat64); |
| 210 } | 210 } |
| 211 return jsgraph()->graph()->NewNode(op, node); | 211 return jsgraph()->graph()->NewNode(op, node); |
| 212 } | 212 } |
| 213 | 213 |
| 214 Node* MakeInt32Constant(double value) { | 214 Node* MakeTruncatedInt32Constant(double value) { |
| 215 if (value < 0) { | 215 return jsgraph()->Int32Constant(DoubleToInt32(value)); |
| 216 DCHECK(IsInt32Double(value)); | |
| 217 int32_t iv = static_cast<int32_t>(value); | |
| 218 return jsgraph()->Int32Constant(iv); | |
| 219 } else { | |
| 220 DCHECK(IsUint32Double(value)); | |
| 221 int32_t iv = static_cast<int32_t>(static_cast<uint32_t>(value)); | |
| 222 return jsgraph()->Int32Constant(iv); | |
| 223 } | |
| 224 } | 216 } |
| 225 | 217 |
| 226 Node* GetTruncatedWord32For(Node* node, MachineTypeUnion output_type) { | 218 Node* GetTruncatedWord32For(Node* node, MachineTypeUnion output_type) { |
| 227 // Eagerly fold truncations for constants. | 219 // Eagerly fold truncations for constants. |
| 228 switch (node->opcode()) { | 220 switch (node->opcode()) { |
| 229 case IrOpcode::kInt32Constant: | 221 case IrOpcode::kInt32Constant: |
| 230 return node; // No change necessary. | 222 return node; // No change necessary. |
| 231 case IrOpcode::kFloat32Constant: | 223 case IrOpcode::kFloat32Constant: |
| 232 return jsgraph()->Int32Constant( | 224 return jsgraph()->Int32Constant( |
| 233 DoubleToInt32(OpParameter<float>(node))); | 225 DoubleToInt32(OpParameter<float>(node))); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 253 } | 245 } |
| 254 return jsgraph()->graph()->NewNode(op, node); | 246 return jsgraph()->graph()->NewNode(op, node); |
| 255 } | 247 } |
| 256 | 248 |
| 257 Node* GetWord32RepresentationFor(Node* node, MachineTypeUnion output_type) { | 249 Node* GetWord32RepresentationFor(Node* node, MachineTypeUnion output_type) { |
| 258 // Eagerly fold representation changes for constants. | 250 // Eagerly fold representation changes for constants. |
| 259 switch (node->opcode()) { | 251 switch (node->opcode()) { |
| 260 case IrOpcode::kInt32Constant: | 252 case IrOpcode::kInt32Constant: |
| 261 return node; // No change necessary. | 253 return node; // No change necessary. |
| 262 case IrOpcode::kFloat32Constant: | 254 case IrOpcode::kFloat32Constant: |
| 263 return MakeInt32Constant(OpParameter<float>(node)); | 255 return MakeTruncatedInt32Constant(OpParameter<float>(node)); |
| 264 case IrOpcode::kNumberConstant: | 256 case IrOpcode::kNumberConstant: |
| 265 case IrOpcode::kFloat64Constant: | 257 case IrOpcode::kFloat64Constant: |
| 266 return MakeInt32Constant(OpParameter<double>(node)); | 258 return MakeTruncatedInt32Constant(OpParameter<double>(node)); |
| 267 default: | 259 default: |
| 268 break; | 260 break; |
| 269 } | 261 } |
| 270 // Select the correct X -> Word32 operator. | 262 // Select the correct X -> Word32 operator. |
| 271 const Operator* op; | 263 const Operator* op; |
| 272 Type* type = NodeProperties::GetType(node); | 264 Type* type = NodeProperties::GetType(node); |
| 273 | 265 |
| 274 if (output_type & kRepBit) { | 266 if (output_type & kRepBit) { |
| 275 return node; // Sloppy comparison -> word32 | 267 return node; // Sloppy comparison -> word32 |
| 276 } else if (output_type & kRepFloat64) { | 268 } else if (output_type & kRepFloat64) { |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 Factory* factory() const { return isolate()->factory(); } | 467 Factory* factory() const { return isolate()->factory(); } |
| 476 SimplifiedOperatorBuilder* simplified() { return jsgraph()->simplified(); } | 468 SimplifiedOperatorBuilder* simplified() { return jsgraph()->simplified(); } |
| 477 MachineOperatorBuilder* machine() { return jsgraph()->machine(); } | 469 MachineOperatorBuilder* machine() { return jsgraph()->machine(); } |
| 478 }; | 470 }; |
| 479 | 471 |
| 480 } // namespace compiler | 472 } // namespace compiler |
| 481 } // namespace internal | 473 } // namespace internal |
| 482 } // namespace v8 | 474 } // namespace v8 |
| 483 | 475 |
| 484 #endif // V8_COMPILER_REPRESENTATION_CHANGE_H_ | 476 #endif // V8_COMPILER_REPRESENTATION_CHANGE_H_ |
| OLD | NEW |