| 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 "src/base/bits.h" | 8 #include "src/base/bits.h" |
| 9 #include "src/compiler/js-graph.h" | 9 #include "src/compiler/js-graph.h" |
| 10 #include "src/compiler/machine-operator.h" | 10 #include "src/compiler/machine-operator.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 } | 44 } |
| 45 if ((use_type & rWord) && (output_type & rWord)) { | 45 if ((use_type & rWord) && (output_type & rWord)) { |
| 46 // Both are words less than or equal to 32-bits. | 46 // Both are words less than or equal to 32-bits. |
| 47 // Since loads of integers from memory implicitly sign or zero extend the | 47 // Since loads of integers from memory implicitly sign or zero extend the |
| 48 // value to the full machine word size and stores implicitly truncate, | 48 // value to the full machine word size and stores implicitly truncate, |
| 49 // no representation change is necessary. | 49 // no representation change is necessary. |
| 50 return node; | 50 return node; |
| 51 } | 51 } |
| 52 if (use_type & kRepTagged) { | 52 if (use_type & kRepTagged) { |
| 53 return GetTaggedRepresentationFor(node, output_type); | 53 return GetTaggedRepresentationFor(node, output_type); |
| 54 } else if (use_type & kRepFloat32) { |
| 55 return GetFloat32RepresentationFor(node, output_type); |
| 54 } else if (use_type & kRepFloat64) { | 56 } else if (use_type & kRepFloat64) { |
| 55 return GetFloat64RepresentationFor(node, output_type); | 57 return GetFloat64RepresentationFor(node, output_type); |
| 56 } else if (use_type & kRepFloat32) { | |
| 57 return TypeError(node, output_type, use_type); // TODO(titzer): handle | |
| 58 } else if (use_type & kRepBit) { | 58 } else if (use_type & kRepBit) { |
| 59 return GetBitRepresentationFor(node, output_type); | 59 return GetBitRepresentationFor(node, output_type); |
| 60 } else if (use_type & rWord) { | 60 } else if (use_type & rWord) { |
| 61 return GetWord32RepresentationFor(node, output_type, | 61 return GetWord32RepresentationFor(node, output_type, |
| 62 use_type & kTypeUint32); | 62 use_type & kTypeUint32); |
| 63 } else if (use_type & kRepWord64) { | 63 } else if (use_type & kRepWord64) { |
| 64 return GetWord64RepresentationFor(node, output_type); | 64 return GetWord64RepresentationFor(node, output_type); |
| 65 } else { | 65 } else { |
| 66 return node; | 66 return node; |
| 67 } | 67 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 96 if (output_type & kRepBit) { | 96 if (output_type & kRepBit) { |
| 97 op = simplified()->ChangeBitToBool(); | 97 op = simplified()->ChangeBitToBool(); |
| 98 } else if (output_type & rWord) { | 98 } else if (output_type & rWord) { |
| 99 if (output_type & kTypeUint32) { | 99 if (output_type & kTypeUint32) { |
| 100 op = simplified()->ChangeUint32ToTagged(); | 100 op = simplified()->ChangeUint32ToTagged(); |
| 101 } else if (output_type & kTypeInt32) { | 101 } else if (output_type & kTypeInt32) { |
| 102 op = simplified()->ChangeInt32ToTagged(); | 102 op = simplified()->ChangeInt32ToTagged(); |
| 103 } else { | 103 } else { |
| 104 return TypeError(node, output_type, kRepTagged); | 104 return TypeError(node, output_type, kRepTagged); |
| 105 } | 105 } |
| 106 } else if (output_type & kRepFloat32) { |
| 107 node = jsgraph()->graph()->NewNode(machine()->ChangeFloat32ToFloat64(), |
| 108 node); |
| 109 op = simplified()->ChangeFloat64ToTagged(); |
| 106 } else if (output_type & kRepFloat64) { | 110 } else if (output_type & kRepFloat64) { |
| 107 op = simplified()->ChangeFloat64ToTagged(); | 111 op = simplified()->ChangeFloat64ToTagged(); |
| 108 } else { | 112 } else { |
| 109 return TypeError(node, output_type, kRepTagged); | 113 return TypeError(node, output_type, kRepTagged); |
| 110 } | 114 } |
| 111 return jsgraph()->graph()->NewNode(op, node); | 115 return jsgraph()->graph()->NewNode(op, node); |
| 112 } | 116 } |
| 113 | 117 |
| 118 Node* GetFloat32RepresentationFor(Node* node, MachineTypeUnion output_type) { |
| 119 // Eagerly fold representation changes for constants. |
| 120 switch (node->opcode()) { |
| 121 // TODO(turbofan): NumberConstant, Int32Constant, and Float64Constant? |
| 122 case IrOpcode::kFloat32Constant: |
| 123 return node; // No change necessary. |
| 124 default: |
| 125 break; |
| 126 } |
| 127 // TODO(turbofan): Select the correct X -> Float32 operator. |
| 128 return TypeError(node, output_type, kRepFloat32); |
| 129 } |
| 130 |
| 114 Node* GetFloat64RepresentationFor(Node* node, MachineTypeUnion output_type) { | 131 Node* GetFloat64RepresentationFor(Node* node, MachineTypeUnion output_type) { |
| 115 // Eagerly fold representation changes for constants. | 132 // Eagerly fold representation changes for constants. |
| 116 switch (node->opcode()) { | 133 switch (node->opcode()) { |
| 117 case IrOpcode::kNumberConstant: | 134 case IrOpcode::kNumberConstant: |
| 118 return jsgraph()->Float64Constant(OpParameter<double>(node)); | 135 return jsgraph()->Float64Constant(OpParameter<double>(node)); |
| 119 case IrOpcode::kInt32Constant: | 136 case IrOpcode::kInt32Constant: |
| 120 if (output_type & kTypeUint32) { | 137 if (output_type & kTypeUint32) { |
| 121 uint32_t value = OpParameter<uint32_t>(node); | 138 uint32_t value = OpParameter<uint32_t>(node); |
| 122 return jsgraph()->Float64Constant(static_cast<double>(value)); | 139 return jsgraph()->Float64Constant(static_cast<double>(value)); |
| 123 } else { | 140 } else { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 134 if (output_type & kRepBit) { | 151 if (output_type & kRepBit) { |
| 135 return TypeError(node, output_type, kRepFloat64); | 152 return TypeError(node, output_type, kRepFloat64); |
| 136 } else if (output_type & rWord) { | 153 } else if (output_type & rWord) { |
| 137 if (output_type & kTypeUint32) { | 154 if (output_type & kTypeUint32) { |
| 138 op = machine()->ChangeUint32ToFloat64(); | 155 op = machine()->ChangeUint32ToFloat64(); |
| 139 } else { | 156 } else { |
| 140 op = machine()->ChangeInt32ToFloat64(); | 157 op = machine()->ChangeInt32ToFloat64(); |
| 141 } | 158 } |
| 142 } else if (output_type & kRepTagged) { | 159 } else if (output_type & kRepTagged) { |
| 143 op = simplified()->ChangeTaggedToFloat64(); | 160 op = simplified()->ChangeTaggedToFloat64(); |
| 161 } else if (output_type & kRepFloat32) { |
| 162 op = machine()->ChangeFloat32ToFloat64(); |
| 144 } else { | 163 } else { |
| 145 return TypeError(node, output_type, kRepFloat64); | 164 return TypeError(node, output_type, kRepFloat64); |
| 146 } | 165 } |
| 147 return jsgraph()->graph()->NewNode(op, node); | 166 return jsgraph()->graph()->NewNode(op, node); |
| 148 } | 167 } |
| 149 | 168 |
| 150 Node* GetWord32RepresentationFor(Node* node, MachineTypeUnion output_type, | 169 Node* GetWord32RepresentationFor(Node* node, MachineTypeUnion output_type, |
| 151 bool use_unsigned) { | 170 bool use_unsigned) { |
| 152 // Eagerly fold representation changes for constants. | 171 // Eagerly fold representation changes for constants. |
| 153 switch (node->opcode()) { | 172 switch (node->opcode()) { |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 use_str.c_str()); | 365 use_str.c_str()); |
| 347 } | 366 } |
| 348 return node; | 367 return node; |
| 349 } | 368 } |
| 350 | 369 |
| 351 JSGraph* jsgraph() { return jsgraph_; } | 370 JSGraph* jsgraph() { return jsgraph_; } |
| 352 Isolate* isolate() { return isolate_; } | 371 Isolate* isolate() { return isolate_; } |
| 353 SimplifiedOperatorBuilder* simplified() { return simplified_; } | 372 SimplifiedOperatorBuilder* simplified() { return simplified_; } |
| 354 MachineOperatorBuilder* machine() { return jsgraph()->machine(); } | 373 MachineOperatorBuilder* machine() { return jsgraph()->machine(); } |
| 355 }; | 374 }; |
| 356 } | 375 |
| 357 } | 376 } // namespace compiler |
| 358 } // namespace v8::internal::compiler | 377 } // namespace internal |
| 378 } // namespace v8 |
| 359 | 379 |
| 360 #endif // V8_COMPILER_REPRESENTATION_CHANGE_H_ | 380 #endif // V8_COMPILER_REPRESENTATION_CHANGE_H_ |
| OLD | NEW |