| 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 #include "src/code-factory.h" | 5 #include "src/code-factory.h" |
| 6 #include "src/compilation-dependencies.h" | 6 #include "src/compilation-dependencies.h" |
| 7 #include "src/compiler/access-builder.h" | 7 #include "src/compiler/access-builder.h" |
| 8 #include "src/compiler/js-graph.h" | 8 #include "src/compiler/js-graph.h" |
| 9 #include "src/compiler/js-typed-lowering.h" | 9 #include "src/compiler/js-typed-lowering.h" |
| 10 #include "src/compiler/linkage.h" | 10 #include "src/compiler/linkage.h" |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 value->ReplaceInput(0, node_); | 130 value->ReplaceInput(0, node_); |
| 131 return lowering_->Replace(value); | 131 return lowering_->Replace(value); |
| 132 } | 132 } |
| 133 return lowering_->Changed(node_); | 133 return lowering_->Changed(node_); |
| 134 } | 134 } |
| 135 | 135 |
| 136 Reduction ChangeToPureOperator(const Operator* op, Type* type) { | 136 Reduction ChangeToPureOperator(const Operator* op, Type* type) { |
| 137 return ChangeToPureOperator(op, false, type); | 137 return ChangeToPureOperator(op, false, type); |
| 138 } | 138 } |
| 139 | 139 |
| 140 // TODO(turbofan): Strong mode should be killed soonish! | |
| 141 bool IsStrong() const { | |
| 142 if (node_->opcode() == IrOpcode::kJSLessThan || | |
| 143 node_->opcode() == IrOpcode::kJSLessThanOrEqual || | |
| 144 node_->opcode() == IrOpcode::kJSGreaterThan || | |
| 145 node_->opcode() == IrOpcode::kJSGreaterThanOrEqual) { | |
| 146 return is_strong(OpParameter<LanguageMode>(node_)); | |
| 147 } | |
| 148 return is_strong(BinaryOperationParametersOf(node_->op()).language_mode()); | |
| 149 } | |
| 150 | |
| 151 bool LeftInputIs(Type* t) { return left_type()->Is(t); } | 140 bool LeftInputIs(Type* t) { return left_type()->Is(t); } |
| 152 | 141 |
| 153 bool RightInputIs(Type* t) { return right_type()->Is(t); } | 142 bool RightInputIs(Type* t) { return right_type()->Is(t); } |
| 154 | 143 |
| 155 bool OneInputIs(Type* t) { return LeftInputIs(t) || RightInputIs(t); } | 144 bool OneInputIs(Type* t) { return LeftInputIs(t) || RightInputIs(t); } |
| 156 | 145 |
| 157 bool BothInputsAre(Type* t) { return LeftInputIs(t) && RightInputIs(t); } | 146 bool BothInputsAre(Type* t) { return LeftInputIs(t) && RightInputIs(t); } |
| 158 | 147 |
| 159 bool OneInputCannotBe(Type* t) { | 148 bool OneInputCannotBe(Type* t) { |
| 160 return !left_type()->Maybe(t) || !right_type()->Maybe(t); | 149 return !left_type()->Maybe(t) || !right_type()->Maybe(t); |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 | 358 |
| 370 | 359 |
| 371 Reduction JSTypedLowering::ReduceJSAdd(Node* node) { | 360 Reduction JSTypedLowering::ReduceJSAdd(Node* node) { |
| 372 if (flags() & kDisableBinaryOpReduction) return NoChange(); | 361 if (flags() & kDisableBinaryOpReduction) return NoChange(); |
| 373 | 362 |
| 374 JSBinopReduction r(this, node); | 363 JSBinopReduction r(this, node); |
| 375 if (r.BothInputsAre(Type::Number())) { | 364 if (r.BothInputsAre(Type::Number())) { |
| 376 // JSAdd(x:number, y:number) => NumberAdd(x, y) | 365 // JSAdd(x:number, y:number) => NumberAdd(x, y) |
| 377 return r.ChangeToPureOperator(simplified()->NumberAdd(), Type::Number()); | 366 return r.ChangeToPureOperator(simplified()->NumberAdd(), Type::Number()); |
| 378 } | 367 } |
| 379 if (r.NeitherInputCanBe(Type::StringOrReceiver()) && !r.IsStrong()) { | 368 if (r.NeitherInputCanBe(Type::StringOrReceiver())) { |
| 380 // JSAdd(x:-string, y:-string) => NumberAdd(ToNumber(x), ToNumber(y)) | 369 // JSAdd(x:-string, y:-string) => NumberAdd(ToNumber(x), ToNumber(y)) |
| 381 Node* frame_state = NodeProperties::GetFrameStateInput(node, 1); | 370 Node* frame_state = NodeProperties::GetFrameStateInput(node, 1); |
| 382 r.ConvertInputsToNumber(frame_state); | 371 r.ConvertInputsToNumber(frame_state); |
| 383 return r.ChangeToPureOperator(simplified()->NumberAdd(), Type::Number()); | 372 return r.ChangeToPureOperator(simplified()->NumberAdd(), Type::Number()); |
| 384 } | 373 } |
| 385 if (r.BothInputsAre(Type::String())) { | 374 if (r.BothInputsAre(Type::String())) { |
| 386 // JSAdd(x:string, y:string) => CallStub[StringAdd](x, y) | 375 // JSAdd(x:string, y:string) => CallStub[StringAdd](x, y) |
| 387 Callable const callable = | 376 Callable const callable = |
| 388 CodeFactory::StringAdd(isolate(), STRING_ADD_CHECK_NONE, NOT_TENURED); | 377 CodeFactory::StringAdd(isolate(), STRING_ADD_CHECK_NONE, NOT_TENURED); |
| 389 CallDescriptor const* const desc = Linkage::GetStubCallDescriptor( | 378 CallDescriptor const* const desc = Linkage::GetStubCallDescriptor( |
| (...skipping 21 matching lines...) Expand all Loading... |
| 411 } | 400 } |
| 412 return NoChange(); | 401 return NoChange(); |
| 413 } | 402 } |
| 414 | 403 |
| 415 | 404 |
| 416 Reduction JSTypedLowering::ReduceNumberBinop(Node* node, | 405 Reduction JSTypedLowering::ReduceNumberBinop(Node* node, |
| 417 const Operator* numberOp) { | 406 const Operator* numberOp) { |
| 418 if (flags() & kDisableBinaryOpReduction) return NoChange(); | 407 if (flags() & kDisableBinaryOpReduction) return NoChange(); |
| 419 | 408 |
| 420 JSBinopReduction r(this, node); | 409 JSBinopReduction r(this, node); |
| 421 if (r.IsStrong() || numberOp == simplified()->NumberModulus()) { | 410 if (numberOp == simplified()->NumberModulus()) { |
| 422 if (r.BothInputsAre(Type::Number())) { | 411 if (r.BothInputsAre(Type::Number())) { |
| 423 return r.ChangeToPureOperator(numberOp, Type::Number()); | 412 return r.ChangeToPureOperator(numberOp, Type::Number()); |
| 424 } | 413 } |
| 425 return NoChange(); | 414 return NoChange(); |
| 426 } | 415 } |
| 427 Node* frame_state = NodeProperties::GetFrameStateInput(node, 1); | 416 Node* frame_state = NodeProperties::GetFrameStateInput(node, 1); |
| 428 r.ConvertInputsToNumber(frame_state); | 417 r.ConvertInputsToNumber(frame_state); |
| 429 return r.ChangeToPureOperator(numberOp, Type::Number()); | 418 return r.ChangeToPureOperator(numberOp, Type::Number()); |
| 430 } | 419 } |
| 431 | 420 |
| 432 | 421 |
| 433 Reduction JSTypedLowering::ReduceInt32Binop(Node* node, const Operator* intOp) { | 422 Reduction JSTypedLowering::ReduceInt32Binop(Node* node, const Operator* intOp) { |
| 434 if (flags() & kDisableBinaryOpReduction) return NoChange(); | 423 if (flags() & kDisableBinaryOpReduction) return NoChange(); |
| 435 | 424 |
| 436 JSBinopReduction r(this, node); | 425 JSBinopReduction r(this, node); |
| 437 if (r.IsStrong()) { | |
| 438 if (r.BothInputsAre(Type::Number())) { | |
| 439 r.ConvertInputsToUI32(kSigned, kSigned); | |
| 440 return r.ChangeToPureOperator(intOp, Type::Integral32()); | |
| 441 } | |
| 442 return NoChange(); | |
| 443 } | |
| 444 Node* frame_state = NodeProperties::GetFrameStateInput(node, 1); | 426 Node* frame_state = NodeProperties::GetFrameStateInput(node, 1); |
| 445 r.ConvertInputsToNumber(frame_state); | 427 r.ConvertInputsToNumber(frame_state); |
| 446 r.ConvertInputsToUI32(kSigned, kSigned); | 428 r.ConvertInputsToUI32(kSigned, kSigned); |
| 447 return r.ChangeToPureOperator(intOp, Type::Integral32()); | 429 return r.ChangeToPureOperator(intOp, Type::Integral32()); |
| 448 } | 430 } |
| 449 | 431 |
| 450 | 432 |
| 451 Reduction JSTypedLowering::ReduceUI32Shift(Node* node, | 433 Reduction JSTypedLowering::ReduceUI32Shift(Node* node, |
| 452 Signedness left_signedness, | 434 Signedness left_signedness, |
| 453 const Operator* shift_op) { | 435 const Operator* shift_op) { |
| 454 if (flags() & kDisableBinaryOpReduction) return NoChange(); | 436 if (flags() & kDisableBinaryOpReduction) return NoChange(); |
| 455 | 437 |
| 456 JSBinopReduction r(this, node); | 438 JSBinopReduction r(this, node); |
| 457 if (r.IsStrong()) { | |
| 458 if (r.BothInputsAre(Type::Number())) { | |
| 459 r.ConvertInputsToUI32(left_signedness, kUnsigned); | |
| 460 return r.ChangeToPureOperator(shift_op); | |
| 461 } | |
| 462 return NoChange(); | |
| 463 } | |
| 464 Node* frame_state = NodeProperties::GetFrameStateInput(node, 1); | 439 Node* frame_state = NodeProperties::GetFrameStateInput(node, 1); |
| 465 r.ConvertInputsToNumber(frame_state); | 440 r.ConvertInputsToNumber(frame_state); |
| 466 r.ConvertInputsToUI32(left_signedness, kUnsigned); | 441 r.ConvertInputsToUI32(left_signedness, kUnsigned); |
| 467 return r.ChangeToPureOperator(shift_op); | 442 return r.ChangeToPureOperator(shift_op); |
| 468 } | 443 } |
| 469 | 444 |
| 470 | 445 |
| 471 Reduction JSTypedLowering::ReduceJSComparison(Node* node) { | 446 Reduction JSTypedLowering::ReduceJSComparison(Node* node) { |
| 472 if (flags() & kDisableBinaryOpReduction) return NoChange(); | 447 if (flags() & kDisableBinaryOpReduction) return NoChange(); |
| 473 | 448 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 500 const Operator* less_than; | 475 const Operator* less_than; |
| 501 const Operator* less_than_or_equal; | 476 const Operator* less_than_or_equal; |
| 502 if (r.BothInputsAre(Type::Unsigned32())) { | 477 if (r.BothInputsAre(Type::Unsigned32())) { |
| 503 less_than = machine()->Uint32LessThan(); | 478 less_than = machine()->Uint32LessThan(); |
| 504 less_than_or_equal = machine()->Uint32LessThanOrEqual(); | 479 less_than_or_equal = machine()->Uint32LessThanOrEqual(); |
| 505 } else if (r.BothInputsAre(Type::Signed32())) { | 480 } else if (r.BothInputsAre(Type::Signed32())) { |
| 506 less_than = machine()->Int32LessThan(); | 481 less_than = machine()->Int32LessThan(); |
| 507 less_than_or_equal = machine()->Int32LessThanOrEqual(); | 482 less_than_or_equal = machine()->Int32LessThanOrEqual(); |
| 508 } else { | 483 } else { |
| 509 // TODO(turbofan): mixed signed/unsigned int32 comparisons. | 484 // TODO(turbofan): mixed signed/unsigned int32 comparisons. |
| 510 if (r.IsStrong() && !r.BothInputsAre(Type::Number())) { | |
| 511 return NoChange(); | |
| 512 } | |
| 513 Node* frame_state = NodeProperties::GetFrameStateInput(node, 1); | 485 Node* frame_state = NodeProperties::GetFrameStateInput(node, 1); |
| 514 r.ConvertInputsToNumber(frame_state); | 486 r.ConvertInputsToNumber(frame_state); |
| 515 less_than = simplified()->NumberLessThan(); | 487 less_than = simplified()->NumberLessThan(); |
| 516 less_than_or_equal = simplified()->NumberLessThanOrEqual(); | 488 less_than_or_equal = simplified()->NumberLessThanOrEqual(); |
| 517 } | 489 } |
| 518 const Operator* comparison; | 490 const Operator* comparison; |
| 519 switch (node->opcode()) { | 491 switch (node->opcode()) { |
| 520 case IrOpcode::kJSLessThan: | 492 case IrOpcode::kJSLessThan: |
| 521 comparison = less_than; | 493 comparison = less_than; |
| 522 break; | 494 break; |
| (...skipping 1265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1788 } | 1760 } |
| 1789 | 1761 |
| 1790 | 1762 |
| 1791 CompilationDependencies* JSTypedLowering::dependencies() const { | 1763 CompilationDependencies* JSTypedLowering::dependencies() const { |
| 1792 return dependencies_; | 1764 return dependencies_; |
| 1793 } | 1765 } |
| 1794 | 1766 |
| 1795 } // namespace compiler | 1767 } // namespace compiler |
| 1796 } // namespace internal | 1768 } // namespace internal |
| 1797 } // namespace v8 | 1769 } // namespace v8 |
| OLD | NEW |