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/effect-control-linearizer.h" | 5 #include "src/compiler/effect-control-linearizer.h" |
6 | 6 |
7 #include "src/code-factory.h" | 7 #include "src/code-factory.h" |
8 #include "src/compiler/access-builder.h" | 8 #include "src/compiler/access-builder.h" |
9 #include "src/compiler/js-graph.h" | 9 #include "src/compiler/js-graph.h" |
10 #include "src/compiler/linkage.h" | 10 #include "src/compiler/linkage.h" |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 *effect = state.effect; | 286 *effect = state.effect; |
287 *control = state.control; | 287 *control = state.control; |
288 return true; | 288 return true; |
289 } | 289 } |
290 | 290 |
291 EffectControlLinearizer::ValueEffectControl | 291 EffectControlLinearizer::ValueEffectControl |
292 EffectControlLinearizer::LowerChangeFloat64ToTagged(Node* node, Node* effect, | 292 EffectControlLinearizer::LowerChangeFloat64ToTagged(Node* node, Node* effect, |
293 Node* control) { | 293 Node* control) { |
294 Node* value = node->InputAt(0); | 294 Node* value = node->InputAt(0); |
295 | 295 |
296 Type* const value_type = NodeProperties::GetType(value); | 296 Node* value32 = graph()->NewNode( |
297 Node* const value32 = graph()->NewNode( | |
298 machine()->TruncateFloat64ToInt32(TruncationMode::kRoundToZero), value); | 297 machine()->TruncateFloat64ToInt32(TruncationMode::kRoundToZero), value); |
299 // TODO(bmeurer): This fast case must be disabled until we kill the asm.js | |
300 // support in the generic JavaScript pipeline, because LoadBuffer is lying | |
301 // about its result. | |
302 // if (value_type->Is(Type::Signed32())) { | |
303 // return ChangeInt32ToTagged(value32, control); | |
304 // } | |
305 Node* check_same = graph()->NewNode( | 298 Node* check_same = graph()->NewNode( |
306 machine()->Float64Equal(), value, | 299 machine()->Float64Equal(), value, |
307 graph()->NewNode(machine()->ChangeInt32ToFloat64(), value32)); | 300 graph()->NewNode(machine()->ChangeInt32ToFloat64(), value32)); |
308 Node* branch_same = graph()->NewNode(common()->Branch(), check_same, control); | 301 Node* branch_same = graph()->NewNode(common()->Branch(), check_same, control); |
309 | 302 |
310 Node* if_smi = graph()->NewNode(common()->IfTrue(), branch_same); | 303 Node* if_smi = graph()->NewNode(common()->IfTrue(), branch_same); |
311 Node* vsmi; | 304 Node* vsmi; |
312 Node* if_box = graph()->NewNode(common()->IfFalse(), branch_same); | 305 Node* if_box = graph()->NewNode(common()->IfFalse(), branch_same); |
313 | 306 |
314 // We only need to check for -0 if the {value} can potentially contain -0. | 307 // Check if {value} is -0. |
315 if (value_type->Maybe(Type::MinusZero())) { | 308 Node* check_zero = graph()->NewNode(machine()->Word32Equal(), value32, |
316 Node* check_zero = graph()->NewNode(machine()->Word32Equal(), value32, | 309 jsgraph()->Int32Constant(0)); |
317 jsgraph()->Int32Constant(0)); | 310 Node* branch_zero = graph()->NewNode(common()->Branch(BranchHint::kFalse), |
318 Node* branch_zero = graph()->NewNode(common()->Branch(BranchHint::kFalse), | 311 check_zero, if_smi); |
319 check_zero, if_smi); | |
320 | 312 |
321 Node* if_zero = graph()->NewNode(common()->IfTrue(), branch_zero); | 313 Node* if_zero = graph()->NewNode(common()->IfTrue(), branch_zero); |
322 Node* if_notzero = graph()->NewNode(common()->IfFalse(), branch_zero); | 314 Node* if_notzero = graph()->NewNode(common()->IfFalse(), branch_zero); |
323 | 315 |
324 // In case of 0, we need to check the high bits for the IEEE -0 pattern. | 316 // In case of 0, we need to check the high bits for the IEEE -0 pattern. |
325 Node* check_negative = graph()->NewNode( | 317 Node* check_negative = graph()->NewNode( |
326 machine()->Int32LessThan(), | 318 machine()->Int32LessThan(), |
327 graph()->NewNode(machine()->Float64ExtractHighWord32(), value), | 319 graph()->NewNode(machine()->Float64ExtractHighWord32(), value), |
328 jsgraph()->Int32Constant(0)); | 320 jsgraph()->Int32Constant(0)); |
329 Node* branch_negative = graph()->NewNode( | 321 Node* branch_negative = graph()->NewNode(common()->Branch(BranchHint::kFalse), |
330 common()->Branch(BranchHint::kFalse), check_negative, if_zero); | 322 check_negative, if_zero); |
331 | 323 |
332 Node* if_negative = graph()->NewNode(common()->IfTrue(), branch_negative); | 324 Node* if_negative = graph()->NewNode(common()->IfTrue(), branch_negative); |
333 Node* if_notnegative = | 325 Node* if_notnegative = graph()->NewNode(common()->IfFalse(), branch_negative); |
334 graph()->NewNode(common()->IfFalse(), branch_negative); | |
335 | 326 |
336 // We need to create a box for negative 0. | 327 // We need to create a box for negative 0. |
337 if_smi = graph()->NewNode(common()->Merge(2), if_notzero, if_notnegative); | 328 if_smi = graph()->NewNode(common()->Merge(2), if_notzero, if_notnegative); |
338 if_box = graph()->NewNode(common()->Merge(2), if_box, if_negative); | 329 if_box = graph()->NewNode(common()->Merge(2), if_box, if_negative); |
339 } | |
340 | 330 |
341 // On 64-bit machines we can just wrap the 32-bit integer in a smi, for 32-bit | 331 // On 64-bit machines we can just wrap the 32-bit integer in a smi, for 32-bit |
342 // machines we need to deal with potential overflow and fallback to boxing. | 332 // machines we need to deal with potential overflow and fallback to boxing. |
343 if (machine()->Is64() || value_type->Is(Type::SignedSmall())) { | 333 if (machine()->Is64()) { |
344 vsmi = ChangeInt32ToSmi(value32); | 334 vsmi = ChangeInt32ToSmi(value32); |
345 } else { | 335 } else { |
346 Node* smi_tag = | 336 Node* smi_tag = |
347 graph()->NewNode(machine()->Int32AddWithOverflow(), value32, value32); | 337 graph()->NewNode(machine()->Int32AddWithOverflow(), value32, value32); |
348 | 338 |
349 Node* check_ovf = graph()->NewNode(common()->Projection(1), smi_tag); | 339 Node* check_ovf = graph()->NewNode(common()->Projection(1), smi_tag); |
350 Node* branch_ovf = graph()->NewNode(common()->Branch(BranchHint::kFalse), | 340 Node* branch_ovf = graph()->NewNode(common()->Branch(BranchHint::kFalse), |
351 check_ovf, if_smi); | 341 check_ovf, if_smi); |
352 | 342 |
353 Node* if_ovf = graph()->NewNode(common()->IfTrue(), branch_ovf); | 343 Node* if_ovf = graph()->NewNode(common()->IfTrue(), branch_ovf); |
(...skipping 12 matching lines...) Expand all Loading... |
366 effect = | 356 effect = |
367 graph()->NewNode(common()->EffectPhi(2), effect, box.effect, control); | 357 graph()->NewNode(common()->EffectPhi(2), effect, box.effect, control); |
368 return ValueEffectControl(value, effect, control); | 358 return ValueEffectControl(value, effect, control); |
369 } | 359 } |
370 | 360 |
371 EffectControlLinearizer::ValueEffectControl | 361 EffectControlLinearizer::ValueEffectControl |
372 EffectControlLinearizer::LowerChangeInt32ToTagged(Node* node, Node* effect, | 362 EffectControlLinearizer::LowerChangeInt32ToTagged(Node* node, Node* effect, |
373 Node* control) { | 363 Node* control) { |
374 Node* value = node->InputAt(0); | 364 Node* value = node->InputAt(0); |
375 | 365 |
376 if (machine()->Is64() || | 366 if (machine()->Is64()) { |
377 NodeProperties::GetType(value)->Is(Type::SignedSmall())) { | |
378 return ValueEffectControl(ChangeInt32ToSmi(value), effect, control); | 367 return ValueEffectControl(ChangeInt32ToSmi(value), effect, control); |
379 } | 368 } |
380 | 369 |
381 Node* add = graph()->NewNode(machine()->Int32AddWithOverflow(), value, value); | 370 Node* add = graph()->NewNode(machine()->Int32AddWithOverflow(), value, value); |
382 | 371 |
383 Node* ovf = graph()->NewNode(common()->Projection(1), add); | 372 Node* ovf = graph()->NewNode(common()->Projection(1), add); |
384 Node* branch = | 373 Node* branch = |
385 graph()->NewNode(common()->Branch(BranchHint::kFalse), ovf, control); | 374 graph()->NewNode(common()->Branch(BranchHint::kFalse), ovf, control); |
386 | 375 |
387 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); | 376 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
(...skipping 10 matching lines...) Expand all Loading... |
398 graph()->NewNode(common()->EffectPhi(2), alloc.effect, effect, merge); | 387 graph()->NewNode(common()->EffectPhi(2), alloc.effect, effect, merge); |
399 | 388 |
400 return ValueEffectControl(phi, ephi, merge); | 389 return ValueEffectControl(phi, ephi, merge); |
401 } | 390 } |
402 | 391 |
403 EffectControlLinearizer::ValueEffectControl | 392 EffectControlLinearizer::ValueEffectControl |
404 EffectControlLinearizer::LowerChangeUint32ToTagged(Node* node, Node* effect, | 393 EffectControlLinearizer::LowerChangeUint32ToTagged(Node* node, Node* effect, |
405 Node* control) { | 394 Node* control) { |
406 Node* value = node->InputAt(0); | 395 Node* value = node->InputAt(0); |
407 | 396 |
408 if (NodeProperties::GetType(value)->Is(Type::UnsignedSmall())) { | |
409 return ValueEffectControl(ChangeUint32ToSmi(value), effect, control); | |
410 } | |
411 | |
412 Node* check = graph()->NewNode(machine()->Uint32LessThanOrEqual(), value, | 397 Node* check = graph()->NewNode(machine()->Uint32LessThanOrEqual(), value, |
413 SmiMaxValueConstant()); | 398 SmiMaxValueConstant()); |
414 Node* branch = | 399 Node* branch = |
415 graph()->NewNode(common()->Branch(BranchHint::kTrue), check, control); | 400 graph()->NewNode(common()->Branch(BranchHint::kTrue), check, control); |
416 | 401 |
417 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); | 402 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
418 Node* vtrue = ChangeUint32ToSmi(value); | 403 Node* vtrue = ChangeUint32ToSmi(value); |
419 | 404 |
420 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); | 405 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); |
421 ValueEffectControl alloc = AllocateHeapNumberWithValue( | 406 ValueEffectControl alloc = AllocateHeapNumberWithValue( |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 return jsgraph()->Int32Constant(Smi::kMaxValue); | 458 return jsgraph()->Int32Constant(Smi::kMaxValue); |
474 } | 459 } |
475 | 460 |
476 Node* EffectControlLinearizer::SmiShiftBitsConstant() { | 461 Node* EffectControlLinearizer::SmiShiftBitsConstant() { |
477 return jsgraph()->IntPtrConstant(kSmiShiftSize + kSmiTagSize); | 462 return jsgraph()->IntPtrConstant(kSmiShiftSize + kSmiTagSize); |
478 } | 463 } |
479 | 464 |
480 } // namespace compiler | 465 } // namespace compiler |
481 } // namespace internal | 466 } // namespace internal |
482 } // namespace v8 | 467 } // namespace v8 |
OLD | NEW |