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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 // TODO(titzer): should Word64 also be implicitly convertable to others? | 100 // TODO(titzer): should Word64 also be implicitly convertable to others? |
101 bool IsWord(MachineRepresentation rep) { | 101 bool IsWord(MachineRepresentation rep) { |
102 return rep == MachineRepresentation::kWord8 || | 102 return rep == MachineRepresentation::kWord8 || |
103 rep == MachineRepresentation::kWord16 || | 103 rep == MachineRepresentation::kWord16 || |
104 rep == MachineRepresentation::kWord32; | 104 rep == MachineRepresentation::kWord32; |
105 } | 105 } |
106 | 106 |
107 } // namespace | 107 } // namespace |
108 | 108 |
109 | 109 |
110 // Changes representation from {output_type} to {use_rep}. The {truncation} | 110 // Changes representation from {output_rep} to {use_rep}. The {truncation} |
111 // parameter is only used for sanity checking - if the changer cannot figure | 111 // parameter is only used for sanity checking - if the changer cannot figure |
112 // out signedness for the word32->float64 conversion, then we check that the | 112 // out signedness for the word32->float64 conversion, then we check that the |
113 // uses truncate to word32 (so they do not care about signedness). | 113 // uses truncate to word32 (so they do not care about signedness). |
114 Node* RepresentationChanger::GetRepresentationFor(Node* node, | 114 Node* RepresentationChanger::GetRepresentationFor( |
115 MachineType output_type, | 115 Node* node, MachineRepresentation output_rep, Type* output_type, |
116 MachineRepresentation use_rep, | 116 MachineRepresentation use_rep, Truncation truncation) { |
117 Truncation truncation) { | 117 if (output_rep == MachineRepresentation::kNone) { |
118 if (output_type.representation() == MachineRepresentation::kNone) { | |
119 // The output representation should be set. | 118 // The output representation should be set. |
120 return TypeError(node, output_type, use_rep); | 119 return TypeError(node, output_rep, output_type, use_rep); |
121 } | 120 } |
122 if (use_rep == output_type.representation()) { | 121 if (use_rep == output_rep) { |
123 // Representations are the same. That's a no-op. | 122 // Representations are the same. That's a no-op. |
124 return node; | 123 return node; |
125 } | 124 } |
126 if (IsWord(use_rep) && IsWord(output_type.representation())) { | 125 if (IsWord(use_rep) && IsWord(output_rep)) { |
127 // Both are words less than or equal to 32-bits. | 126 // Both are words less than or equal to 32-bits. |
128 // Since loads of integers from memory implicitly sign or zero extend the | 127 // Since loads of integers from memory implicitly sign or zero extend the |
129 // value to the full machine word size and stores implicitly truncate, | 128 // value to the full machine word size and stores implicitly truncate, |
130 // no representation change is necessary. | 129 // no representation change is necessary. |
131 return node; | 130 return node; |
132 } | 131 } |
133 switch (use_rep) { | 132 switch (use_rep) { |
134 case MachineRepresentation::kTagged: | 133 case MachineRepresentation::kTagged: |
135 return GetTaggedRepresentationFor(node, output_type); | 134 return GetTaggedRepresentationFor(node, output_rep, output_type); |
136 case MachineRepresentation::kFloat32: | 135 case MachineRepresentation::kFloat32: |
137 return GetFloat32RepresentationFor(node, output_type, truncation); | 136 return GetFloat32RepresentationFor(node, output_rep, output_type, |
| 137 truncation); |
138 case MachineRepresentation::kFloat64: | 138 case MachineRepresentation::kFloat64: |
139 return GetFloat64RepresentationFor(node, output_type, truncation); | 139 return GetFloat64RepresentationFor(node, output_rep, output_type, |
| 140 truncation); |
140 case MachineRepresentation::kBit: | 141 case MachineRepresentation::kBit: |
141 return GetBitRepresentationFor(node, output_type); | 142 return GetBitRepresentationFor(node, output_rep, output_type); |
142 case MachineRepresentation::kWord8: | 143 case MachineRepresentation::kWord8: |
143 case MachineRepresentation::kWord16: | 144 case MachineRepresentation::kWord16: |
144 case MachineRepresentation::kWord32: | 145 case MachineRepresentation::kWord32: |
145 return GetWord32RepresentationFor(node, output_type); | 146 return GetWord32RepresentationFor(node, output_rep, output_type); |
146 case MachineRepresentation::kWord64: | 147 case MachineRepresentation::kWord64: |
147 return GetWord64RepresentationFor(node, output_type); | 148 return GetWord64RepresentationFor(node, output_rep, output_type); |
148 case MachineRepresentation::kNone: | 149 case MachineRepresentation::kNone: |
149 return node; | 150 return node; |
150 } | 151 } |
151 UNREACHABLE(); | 152 UNREACHABLE(); |
152 return nullptr; | 153 return nullptr; |
153 } | 154 } |
154 | 155 |
155 | 156 |
156 Node* RepresentationChanger::GetTaggedRepresentationFor( | 157 Node* RepresentationChanger::GetTaggedRepresentationFor( |
157 Node* node, MachineType output_type) { | 158 Node* node, MachineRepresentation output_rep, Type* output_type) { |
158 // Eagerly fold representation changes for constants. | 159 // Eagerly fold representation changes for constants. |
159 switch (node->opcode()) { | 160 switch (node->opcode()) { |
160 case IrOpcode::kNumberConstant: | 161 case IrOpcode::kNumberConstant: |
161 case IrOpcode::kHeapConstant: | 162 case IrOpcode::kHeapConstant: |
162 return node; // No change necessary. | 163 return node; // No change necessary. |
163 case IrOpcode::kInt32Constant: | 164 case IrOpcode::kInt32Constant: |
164 if (output_type.semantic() == MachineSemantic::kUint32) { | 165 if (output_type->Is(Type::Signed32())) { |
| 166 int32_t value = OpParameter<int32_t>(node); |
| 167 return jsgraph()->Constant(value); |
| 168 } else if (output_type->Is(Type::Unsigned32())) { |
165 uint32_t value = static_cast<uint32_t>(OpParameter<int32_t>(node)); | 169 uint32_t value = static_cast<uint32_t>(OpParameter<int32_t>(node)); |
166 return jsgraph()->Constant(static_cast<double>(value)); | 170 return jsgraph()->Constant(static_cast<double>(value)); |
167 } else if (output_type.semantic() == MachineSemantic::kInt32) { | 171 } else if (output_rep == MachineRepresentation::kBit) { |
168 int32_t value = OpParameter<int32_t>(node); | |
169 return jsgraph()->Constant(value); | |
170 } else if (output_type.representation() == MachineRepresentation::kBit) { | |
171 return OpParameter<int32_t>(node) == 0 ? jsgraph()->FalseConstant() | 172 return OpParameter<int32_t>(node) == 0 ? jsgraph()->FalseConstant() |
172 : jsgraph()->TrueConstant(); | 173 : jsgraph()->TrueConstant(); |
173 } else { | 174 } else { |
174 return TypeError(node, output_type, MachineRepresentation::kTagged); | 175 return TypeError(node, output_rep, output_type, |
| 176 MachineRepresentation::kTagged); |
175 } | 177 } |
176 case IrOpcode::kFloat64Constant: | 178 case IrOpcode::kFloat64Constant: |
177 return jsgraph()->Constant(OpParameter<double>(node)); | 179 return jsgraph()->Constant(OpParameter<double>(node)); |
178 case IrOpcode::kFloat32Constant: | 180 case IrOpcode::kFloat32Constant: |
179 return jsgraph()->Constant(OpParameter<float>(node)); | 181 return jsgraph()->Constant(OpParameter<float>(node)); |
180 default: | 182 default: |
181 break; | 183 break; |
182 } | 184 } |
183 // Select the correct X -> Tagged operator. | 185 // Select the correct X -> Tagged operator. |
184 const Operator* op; | 186 const Operator* op; |
185 if (output_type.representation() == MachineRepresentation::kBit) { | 187 if (output_rep == MachineRepresentation::kBit) { |
186 op = simplified()->ChangeBitToBool(); | 188 op = simplified()->ChangeBitToBool(); |
187 } else if (IsWord(output_type.representation())) { | 189 } else if (IsWord(output_rep)) { |
188 if (output_type.semantic() == MachineSemantic::kUint32) { | 190 if (output_type->Is(Type::Unsigned32())) { |
189 op = simplified()->ChangeUint32ToTagged(); | 191 op = simplified()->ChangeUint32ToTagged(); |
190 } else if (output_type.semantic() == MachineSemantic::kInt32) { | 192 } else if (output_type->Is(Type::Signed32())) { |
191 op = simplified()->ChangeInt32ToTagged(); | 193 op = simplified()->ChangeInt32ToTagged(); |
192 } else { | 194 } else { |
193 return TypeError(node, output_type, MachineRepresentation::kTagged); | 195 return TypeError(node, output_rep, output_type, |
| 196 MachineRepresentation::kTagged); |
194 } | 197 } |
195 } else if (output_type.representation() == | 198 } else if (output_rep == |
196 MachineRepresentation::kFloat32) { // float32 -> float64 -> tagged | 199 MachineRepresentation::kFloat32) { // float32 -> float64 -> tagged |
197 node = InsertChangeFloat32ToFloat64(node); | 200 node = InsertChangeFloat32ToFloat64(node); |
198 op = simplified()->ChangeFloat64ToTagged(); | 201 op = simplified()->ChangeFloat64ToTagged(); |
199 } else if (output_type.representation() == MachineRepresentation::kFloat64) { | 202 } else if (output_rep == MachineRepresentation::kFloat64) { |
200 op = simplified()->ChangeFloat64ToTagged(); | 203 op = simplified()->ChangeFloat64ToTagged(); |
201 } else { | 204 } else { |
202 return TypeError(node, output_type, MachineRepresentation::kTagged); | 205 return TypeError(node, output_rep, output_type, |
| 206 MachineRepresentation::kTagged); |
203 } | 207 } |
204 return jsgraph()->graph()->NewNode(op, node); | 208 return jsgraph()->graph()->NewNode(op, node); |
205 } | 209 } |
206 | 210 |
207 | 211 |
208 Node* RepresentationChanger::GetFloat32RepresentationFor( | 212 Node* RepresentationChanger::GetFloat32RepresentationFor( |
209 Node* node, MachineType output_type, Truncation truncation) { | 213 Node* node, MachineRepresentation output_rep, Type* output_type, |
| 214 Truncation truncation) { |
210 // Eagerly fold representation changes for constants. | 215 // Eagerly fold representation changes for constants. |
211 switch (node->opcode()) { | 216 switch (node->opcode()) { |
212 case IrOpcode::kFloat64Constant: | 217 case IrOpcode::kFloat64Constant: |
213 case IrOpcode::kNumberConstant: | 218 case IrOpcode::kNumberConstant: |
214 return jsgraph()->Float32Constant( | 219 return jsgraph()->Float32Constant( |
215 DoubleToFloat32(OpParameter<double>(node))); | 220 DoubleToFloat32(OpParameter<double>(node))); |
216 case IrOpcode::kInt32Constant: | 221 case IrOpcode::kInt32Constant: |
217 if (output_type.semantic() == MachineSemantic::kUint32) { | 222 if (output_type->Is(Type::Unsigned32())) { |
218 uint32_t value = static_cast<uint32_t>(OpParameter<int32_t>(node)); | 223 uint32_t value = static_cast<uint32_t>(OpParameter<int32_t>(node)); |
219 return jsgraph()->Float32Constant(static_cast<float>(value)); | 224 return jsgraph()->Float32Constant(static_cast<float>(value)); |
220 } else { | 225 } else { |
221 int32_t value = OpParameter<int32_t>(node); | 226 int32_t value = OpParameter<int32_t>(node); |
222 return jsgraph()->Float32Constant(static_cast<float>(value)); | 227 return jsgraph()->Float32Constant(static_cast<float>(value)); |
223 } | 228 } |
224 case IrOpcode::kFloat32Constant: | 229 case IrOpcode::kFloat32Constant: |
225 return node; // No change necessary. | 230 return node; // No change necessary. |
226 default: | 231 default: |
227 break; | 232 break; |
228 } | 233 } |
229 // Select the correct X -> Float32 operator. | 234 // Select the correct X -> Float32 operator. |
230 const Operator* op; | 235 const Operator* op; |
231 if (output_type.representation() == MachineRepresentation::kBit) { | 236 if (output_rep == MachineRepresentation::kBit) { |
232 return TypeError(node, output_type, MachineRepresentation::kFloat32); | 237 return TypeError(node, output_rep, output_type, |
233 } else if (IsWord(output_type.representation())) { | 238 MachineRepresentation::kFloat32); |
234 if (output_type.semantic() == MachineSemantic::kUint32) { | 239 } else if (IsWord(output_rep)) { |
235 op = machine()->ChangeUint32ToFloat64(); | 240 if (output_type->Is(Type::Signed32())) { |
| 241 op = machine()->ChangeInt32ToFloat64(); |
236 } else { | 242 } else { |
237 // Either the output is int32 or the uses only care about the | 243 // Either the output is int32 or the uses only care about the |
238 // low 32 bits (so we can pick int32 safely). | 244 // low 32 bits (so we can pick int32 safely). |
239 DCHECK(output_type.semantic() == MachineSemantic::kInt32 || | 245 DCHECK(output_type->Is(Type::Unsigned32()) || |
240 truncation.TruncatesToWord32()); | 246 truncation.TruncatesToWord32()); |
241 op = machine()->ChangeInt32ToFloat64(); | 247 op = machine()->ChangeUint32ToFloat64(); |
242 } | 248 } |
243 // int32 -> float64 -> float32 | 249 // int32 -> float64 -> float32 |
244 node = jsgraph()->graph()->NewNode(op, node); | 250 node = jsgraph()->graph()->NewNode(op, node); |
245 op = machine()->TruncateFloat64ToFloat32(); | 251 op = machine()->TruncateFloat64ToFloat32(); |
246 } else if (output_type.representation() == MachineRepresentation::kTagged) { | 252 } else if (output_rep == MachineRepresentation::kTagged) { |
247 op = simplified()->ChangeTaggedToFloat64(); // tagged -> float64 -> float32 | 253 op = simplified()->ChangeTaggedToFloat64(); // tagged -> float64 -> float32 |
248 node = jsgraph()->graph()->NewNode(op, node); | 254 node = jsgraph()->graph()->NewNode(op, node); |
249 op = machine()->TruncateFloat64ToFloat32(); | 255 op = machine()->TruncateFloat64ToFloat32(); |
250 } else if (output_type.representation() == MachineRepresentation::kFloat64) { | 256 } else if (output_rep == MachineRepresentation::kFloat64) { |
251 op = machine()->TruncateFloat64ToFloat32(); | 257 op = machine()->TruncateFloat64ToFloat32(); |
252 } else { | 258 } else { |
253 return TypeError(node, output_type, MachineRepresentation::kFloat32); | 259 return TypeError(node, output_rep, output_type, |
| 260 MachineRepresentation::kFloat32); |
254 } | 261 } |
255 return jsgraph()->graph()->NewNode(op, node); | 262 return jsgraph()->graph()->NewNode(op, node); |
256 } | 263 } |
257 | 264 |
258 | 265 |
259 Node* RepresentationChanger::GetFloat64RepresentationFor( | 266 Node* RepresentationChanger::GetFloat64RepresentationFor( |
260 Node* node, MachineType output_type, Truncation truncation) { | 267 Node* node, MachineRepresentation output_rep, Type* output_type, |
| 268 Truncation truncation) { |
261 // Eagerly fold representation changes for constants. | 269 // Eagerly fold representation changes for constants. |
262 switch (node->opcode()) { | 270 switch (node->opcode()) { |
263 case IrOpcode::kNumberConstant: | 271 case IrOpcode::kNumberConstant: |
264 return jsgraph()->Float64Constant(OpParameter<double>(node)); | 272 return jsgraph()->Float64Constant(OpParameter<double>(node)); |
265 case IrOpcode::kInt32Constant: | 273 case IrOpcode::kInt32Constant: |
266 if (output_type.semantic() == MachineSemantic::kUint32) { | 274 if (output_type->Is(Type::Signed32())) { |
| 275 int32_t value = OpParameter<int32_t>(node); |
| 276 return jsgraph()->Float64Constant(value); |
| 277 } else { |
| 278 DCHECK(output_type->Is(Type::Unsigned32())); |
267 uint32_t value = static_cast<uint32_t>(OpParameter<int32_t>(node)); | 279 uint32_t value = static_cast<uint32_t>(OpParameter<int32_t>(node)); |
268 return jsgraph()->Float64Constant(static_cast<double>(value)); | 280 return jsgraph()->Float64Constant(static_cast<double>(value)); |
269 } else { | |
270 int32_t value = OpParameter<int32_t>(node); | |
271 return jsgraph()->Float64Constant(value); | |
272 } | 281 } |
273 case IrOpcode::kFloat64Constant: | 282 case IrOpcode::kFloat64Constant: |
274 return node; // No change necessary. | 283 return node; // No change necessary. |
275 case IrOpcode::kFloat32Constant: | 284 case IrOpcode::kFloat32Constant: |
276 return jsgraph()->Float64Constant(OpParameter<float>(node)); | 285 return jsgraph()->Float64Constant(OpParameter<float>(node)); |
277 default: | 286 default: |
278 break; | 287 break; |
279 } | 288 } |
280 // Select the correct X -> Float64 operator. | 289 // Select the correct X -> Float64 operator. |
281 const Operator* op; | 290 const Operator* op; |
282 if (output_type.representation() == MachineRepresentation::kBit) { | 291 if (output_rep == MachineRepresentation::kBit) { |
283 return TypeError(node, output_type, MachineRepresentation::kFloat64); | 292 return TypeError(node, output_rep, output_type, |
284 } else if (IsWord(output_type.representation())) { | 293 MachineRepresentation::kFloat64); |
285 if (output_type.semantic() == MachineSemantic::kUint32) { | 294 } else if (IsWord(output_rep)) { |
286 op = machine()->ChangeUint32ToFloat64(); | 295 if (output_type->Is(Type::Signed32())) { |
| 296 op = machine()->ChangeInt32ToFloat64(); |
287 } else { | 297 } else { |
288 // Either the output is int32 or the uses only care about the | 298 // Either the output is int32 or the uses only care about the |
289 // low 32 bits (so we can pick int32 safely). | 299 // low 32 bits (so we can pick int32 safely). |
290 DCHECK(output_type.semantic() == MachineSemantic::kInt32 || | 300 DCHECK(output_type->Is(Type::Unsigned32()) || |
291 truncation.TruncatesToWord32()); | 301 truncation.TruncatesToWord32()); |
292 op = machine()->ChangeInt32ToFloat64(); | 302 op = machine()->ChangeUint32ToFloat64(); |
293 } | 303 } |
294 } else if (output_type.representation() == MachineRepresentation::kTagged) { | 304 } else if (output_rep == MachineRepresentation::kTagged) { |
295 op = simplified()->ChangeTaggedToFloat64(); | 305 op = simplified()->ChangeTaggedToFloat64(); |
296 } else if (output_type.representation() == MachineRepresentation::kFloat32) { | 306 } else if (output_rep == MachineRepresentation::kFloat32) { |
297 op = machine()->ChangeFloat32ToFloat64(); | 307 op = machine()->ChangeFloat32ToFloat64(); |
298 } else { | 308 } else { |
299 return TypeError(node, output_type, MachineRepresentation::kFloat64); | 309 return TypeError(node, output_rep, output_type, |
| 310 MachineRepresentation::kFloat64); |
300 } | 311 } |
301 return jsgraph()->graph()->NewNode(op, node); | 312 return jsgraph()->graph()->NewNode(op, node); |
302 } | 313 } |
303 | 314 |
304 | 315 |
305 Node* RepresentationChanger::MakeTruncatedInt32Constant(double value) { | 316 Node* RepresentationChanger::MakeTruncatedInt32Constant(double value) { |
306 return jsgraph()->Int32Constant(DoubleToInt32(value)); | 317 return jsgraph()->Int32Constant(DoubleToInt32(value)); |
307 } | 318 } |
308 | 319 |
309 | 320 |
310 Node* RepresentationChanger::GetWord32RepresentationFor( | 321 Node* RepresentationChanger::GetWord32RepresentationFor( |
311 Node* node, MachineType output_type) { | 322 Node* node, MachineRepresentation output_rep, Type* output_type) { |
312 // Eagerly fold representation changes for constants. | 323 // Eagerly fold representation changes for constants. |
313 switch (node->opcode()) { | 324 switch (node->opcode()) { |
314 case IrOpcode::kInt32Constant: | 325 case IrOpcode::kInt32Constant: |
315 return node; // No change necessary. | 326 return node; // No change necessary. |
316 case IrOpcode::kFloat32Constant: | 327 case IrOpcode::kFloat32Constant: |
317 return MakeTruncatedInt32Constant(OpParameter<float>(node)); | 328 return MakeTruncatedInt32Constant(OpParameter<float>(node)); |
318 case IrOpcode::kNumberConstant: | 329 case IrOpcode::kNumberConstant: |
319 case IrOpcode::kFloat64Constant: | 330 case IrOpcode::kFloat64Constant: |
320 return MakeTruncatedInt32Constant(OpParameter<double>(node)); | 331 return MakeTruncatedInt32Constant(OpParameter<double>(node)); |
321 default: | 332 default: |
322 break; | 333 break; |
323 } | 334 } |
324 // Select the correct X -> Word32 operator. | 335 // Select the correct X -> Word32 operator. |
325 const Operator* op; | 336 const Operator* op; |
326 Type* type = NodeProperties::GetType(node); | 337 Type* type = NodeProperties::GetType(node); |
327 | 338 |
328 if (output_type.representation() == MachineRepresentation::kBit) { | 339 if (output_rep == MachineRepresentation::kBit) { |
329 return node; // Sloppy comparison -> word32 | 340 return node; // Sloppy comparison -> word32 |
330 } else if (output_type.representation() == MachineRepresentation::kFloat64) { | 341 } else if (output_rep == MachineRepresentation::kFloat64) { |
331 if (output_type.semantic() == MachineSemantic::kUint32 || | 342 // TODO(jarin) Use only output_type here, once we intersect it with the |
332 type->Is(Type::Unsigned32())) { | 343 // type inferred by the typer. |
| 344 if (output_type->Is(Type::Unsigned32()) || type->Is(Type::Unsigned32())) { |
333 op = machine()->ChangeFloat64ToUint32(); | 345 op = machine()->ChangeFloat64ToUint32(); |
334 } else if (output_type.semantic() == MachineSemantic::kInt32 || | 346 } else if (output_type->Is(Type::Signed32()) || |
335 type->Is(Type::Signed32())) { | 347 type->Is(Type::Signed32())) { |
336 op = machine()->ChangeFloat64ToInt32(); | 348 op = machine()->ChangeFloat64ToInt32(); |
337 } else { | 349 } else { |
338 op = machine()->TruncateFloat64ToInt32(TruncationMode::kJavaScript); | 350 op = machine()->TruncateFloat64ToInt32(TruncationMode::kJavaScript); |
339 } | 351 } |
340 } else if (output_type.representation() == MachineRepresentation::kFloat32) { | 352 } else if (output_rep == MachineRepresentation::kFloat32) { |
341 node = InsertChangeFloat32ToFloat64(node); // float32 -> float64 -> int32 | 353 node = InsertChangeFloat32ToFloat64(node); // float32 -> float64 -> int32 |
342 if (output_type.semantic() == MachineSemantic::kUint32 || | 354 if (output_type->Is(Type::Unsigned32()) || type->Is(Type::Unsigned32())) { |
343 type->Is(Type::Unsigned32())) { | |
344 op = machine()->ChangeFloat64ToUint32(); | 355 op = machine()->ChangeFloat64ToUint32(); |
345 } else if (output_type.semantic() == MachineSemantic::kInt32 || | 356 } else if (output_type->Is(Type::Signed32()) || |
346 type->Is(Type::Signed32())) { | 357 type->Is(Type::Signed32())) { |
347 op = machine()->ChangeFloat64ToInt32(); | 358 op = machine()->ChangeFloat64ToInt32(); |
348 } else { | 359 } else { |
349 op = machine()->TruncateFloat64ToInt32(TruncationMode::kJavaScript); | 360 op = machine()->TruncateFloat64ToInt32(TruncationMode::kJavaScript); |
350 } | 361 } |
351 } else if (output_type.representation() == MachineRepresentation::kTagged) { | 362 } else if (output_rep == MachineRepresentation::kTagged) { |
352 if (output_type.semantic() == MachineSemantic::kUint32 || | 363 if (output_type->Is(Type::Unsigned32()) || type->Is(Type::Unsigned32())) { |
353 type->Is(Type::Unsigned32())) { | |
354 op = simplified()->ChangeTaggedToUint32(); | 364 op = simplified()->ChangeTaggedToUint32(); |
355 } else if (output_type.semantic() == MachineSemantic::kInt32 || | 365 } else if (output_type->Is(Type::Signed32()) || |
356 type->Is(Type::Signed32())) { | 366 type->Is(Type::Signed32())) { |
357 op = simplified()->ChangeTaggedToInt32(); | 367 op = simplified()->ChangeTaggedToInt32(); |
358 } else { | 368 } else { |
359 node = InsertChangeTaggedToFloat64(node); | 369 node = InsertChangeTaggedToFloat64(node); |
360 op = machine()->TruncateFloat64ToInt32(TruncationMode::kJavaScript); | 370 op = machine()->TruncateFloat64ToInt32(TruncationMode::kJavaScript); |
361 } | 371 } |
362 } else { | 372 } else { |
363 return TypeError(node, output_type, MachineRepresentation::kWord32); | 373 return TypeError(node, output_rep, output_type, |
| 374 MachineRepresentation::kWord32); |
364 } | 375 } |
365 return jsgraph()->graph()->NewNode(op, node); | 376 return jsgraph()->graph()->NewNode(op, node); |
366 } | 377 } |
367 | 378 |
368 | 379 |
369 Node* RepresentationChanger::GetBitRepresentationFor(Node* node, | 380 Node* RepresentationChanger::GetBitRepresentationFor( |
370 MachineType output_type) { | 381 Node* node, MachineRepresentation output_rep, Type* output_type) { |
371 // Eagerly fold representation changes for constants. | 382 // Eagerly fold representation changes for constants. |
372 switch (node->opcode()) { | 383 switch (node->opcode()) { |
373 case IrOpcode::kHeapConstant: { | 384 case IrOpcode::kHeapConstant: { |
374 Handle<HeapObject> value = OpParameter<Handle<HeapObject>>(node); | 385 Handle<HeapObject> value = OpParameter<Handle<HeapObject>>(node); |
375 DCHECK(value.is_identical_to(factory()->true_value()) || | 386 DCHECK(value.is_identical_to(factory()->true_value()) || |
376 value.is_identical_to(factory()->false_value())); | 387 value.is_identical_to(factory()->false_value())); |
377 return jsgraph()->Int32Constant( | 388 return jsgraph()->Int32Constant( |
378 value.is_identical_to(factory()->true_value()) ? 1 : 0); | 389 value.is_identical_to(factory()->true_value()) ? 1 : 0); |
379 } | 390 } |
380 default: | 391 default: |
381 break; | 392 break; |
382 } | 393 } |
383 // Select the correct X -> Bit operator. | 394 // Select the correct X -> Bit operator. |
384 const Operator* op; | 395 const Operator* op; |
385 if (output_type.representation() == MachineRepresentation::kTagged) { | 396 if (output_rep == MachineRepresentation::kTagged) { |
386 op = simplified()->ChangeBoolToBit(); | 397 op = simplified()->ChangeBoolToBit(); |
387 } else { | 398 } else { |
388 return TypeError(node, output_type, MachineRepresentation::kBit); | 399 return TypeError(node, output_rep, output_type, |
| 400 MachineRepresentation::kBit); |
389 } | 401 } |
390 return jsgraph()->graph()->NewNode(op, node); | 402 return jsgraph()->graph()->NewNode(op, node); |
391 } | 403 } |
392 | 404 |
393 | 405 |
394 Node* RepresentationChanger::GetWord64RepresentationFor( | 406 Node* RepresentationChanger::GetWord64RepresentationFor( |
395 Node* node, MachineType output_type) { | 407 Node* node, MachineRepresentation output_rep, Type* output_type) { |
396 if (output_type.representation() == MachineRepresentation::kBit) { | 408 if (output_rep == MachineRepresentation::kBit) { |
397 return node; // Sloppy comparison -> word64 | 409 return node; // Sloppy comparison -> word64 |
398 } | 410 } |
399 // Can't really convert Word64 to anything else. Purported to be internal. | 411 // Can't really convert Word64 to anything else. Purported to be internal. |
400 return TypeError(node, output_type, MachineRepresentation::kWord64); | 412 return TypeError(node, output_rep, output_type, |
| 413 MachineRepresentation::kWord64); |
401 } | 414 } |
402 | 415 |
403 | 416 |
404 const Operator* RepresentationChanger::Int32OperatorFor( | 417 const Operator* RepresentationChanger::Int32OperatorFor( |
405 IrOpcode::Value opcode) { | 418 IrOpcode::Value opcode) { |
406 switch (opcode) { | 419 switch (opcode) { |
407 case IrOpcode::kNumberAdd: | 420 case IrOpcode::kNumberAdd: |
408 return machine()->Int32Add(); | 421 return machine()->Int32Add(); |
409 case IrOpcode::kNumberSubtract: | 422 case IrOpcode::kNumberSubtract: |
410 return machine()->Int32Sub(); | 423 return machine()->Int32Sub(); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 return machine()->Float64LessThan(); | 491 return machine()->Float64LessThan(); |
479 case IrOpcode::kNumberLessThanOrEqual: | 492 case IrOpcode::kNumberLessThanOrEqual: |
480 return machine()->Float64LessThanOrEqual(); | 493 return machine()->Float64LessThanOrEqual(); |
481 default: | 494 default: |
482 UNREACHABLE(); | 495 UNREACHABLE(); |
483 return nullptr; | 496 return nullptr; |
484 } | 497 } |
485 } | 498 } |
486 | 499 |
487 | 500 |
488 MachineSemantic RepresentationChanger::TypeFromUpperBound(Type* type) { | 501 Node* RepresentationChanger::TypeError(Node* node, |
489 CHECK(!type->Is(Type::None())); | 502 MachineRepresentation output_rep, |
490 if (type->Is(Type::Signed32())) return MachineSemantic::kInt32; | 503 Type* output_type, |
491 if (type->Is(Type::Unsigned32())) return MachineSemantic::kUint32; | |
492 if (type->Is(Type::Number())) return MachineSemantic::kNumber; | |
493 if (type->Is(Type::Boolean())) return MachineSemantic::kBool; | |
494 return MachineSemantic::kAny; | |
495 } | |
496 | |
497 | |
498 Node* RepresentationChanger::TypeError(Node* node, MachineType output_type, | |
499 MachineRepresentation use) { | 504 MachineRepresentation use) { |
500 type_error_ = true; | 505 type_error_ = true; |
501 if (!testing_type_errors_) { | 506 if (!testing_type_errors_) { |
502 std::ostringstream out_str; | 507 std::ostringstream out_str; |
503 out_str << output_type; | 508 out_str << output_rep << " ("; |
| 509 output_type->PrintTo(out_str, Type::SEMANTIC_DIM); |
| 510 out_str << ")"; |
504 | 511 |
505 std::ostringstream use_str; | 512 std::ostringstream use_str; |
506 use_str << use; | 513 use_str << use; |
507 | 514 |
508 V8_Fatal(__FILE__, __LINE__, | 515 V8_Fatal(__FILE__, __LINE__, |
509 "RepresentationChangerError: node #%d:%s of " | 516 "RepresentationChangerError: node #%d:%s of " |
510 "%s cannot be changed to %s", | 517 "%s cannot be changed to %s", |
511 node->id(), node->op()->mnemonic(), out_str.str().c_str(), | 518 node->id(), node->op()->mnemonic(), out_str.str().c_str(), |
512 use_str.str().c_str()); | 519 use_str.str().c_str()); |
513 } | 520 } |
514 return node; | 521 return node; |
515 } | 522 } |
516 | 523 |
517 | 524 |
518 Node* RepresentationChanger::InsertChangeFloat32ToFloat64(Node* node) { | 525 Node* RepresentationChanger::InsertChangeFloat32ToFloat64(Node* node) { |
519 return jsgraph()->graph()->NewNode(machine()->ChangeFloat32ToFloat64(), node); | 526 return jsgraph()->graph()->NewNode(machine()->ChangeFloat32ToFloat64(), node); |
520 } | 527 } |
521 | 528 |
522 | 529 |
523 Node* RepresentationChanger::InsertChangeTaggedToFloat64(Node* node) { | 530 Node* RepresentationChanger::InsertChangeTaggedToFloat64(Node* node) { |
524 return jsgraph()->graph()->NewNode(simplified()->ChangeTaggedToFloat64(), | 531 return jsgraph()->graph()->NewNode(simplified()->ChangeTaggedToFloat64(), |
525 node); | 532 node); |
526 } | 533 } |
527 | 534 |
528 } // namespace compiler | 535 } // namespace compiler |
529 } // namespace internal | 536 } // namespace internal |
530 } // namespace v8 | 537 } // namespace v8 |
OLD | NEW |