| 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/compiler/graph-inl.h" | 5 #include "src/compiler/graph-inl.h" |
| 6 #include "src/compiler/js-graph.h" | 6 #include "src/compiler/js-graph.h" |
| 7 #include "src/compiler/js-typed-lowering.h" | 7 #include "src/compiler/js-typed-lowering.h" |
| 8 #include "src/compiler/machine-operator.h" | 8 #include "src/compiler/machine-operator.h" |
| 9 #include "src/compiler/node-properties-inl.h" | 9 #include "src/compiler/node-properties-inl.h" |
| 10 #include "src/compiler/opcodes.h" | 10 #include "src/compiler/opcodes.h" |
| (...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 { // ToBoolean(null) | 500 { // ToBoolean(null) |
| 501 Node* r = R.ReduceUnop(op, Type::Null()); | 501 Node* r = R.ReduceUnop(op, Type::Null()); |
| 502 R.CheckFalse(r); | 502 R.CheckFalse(r); |
| 503 } | 503 } |
| 504 | 504 |
| 505 { // ToBoolean(boolean) | 505 { // ToBoolean(boolean) |
| 506 Node* r = R.ReduceUnop(op, Type::Boolean()); | 506 Node* r = R.ReduceUnop(op, Type::Boolean()); |
| 507 CHECK_EQ(IrOpcode::kParameter, r->opcode()); | 507 CHECK_EQ(IrOpcode::kParameter, r->opcode()); |
| 508 } | 508 } |
| 509 | 509 |
| 510 { // ToBoolean(ordered-number) | |
| 511 Node* r = R.ReduceUnop(op, Type::OrderedNumber()); | |
| 512 CHECK_EQ(IrOpcode::kBooleanNot, r->opcode()); | |
| 513 Node* i = r->InputAt(0); | |
| 514 CHECK_EQ(IrOpcode::kNumberEqual, i->opcode()); | |
| 515 // ToBoolean(x:ordered-number) => BooleanNot(NumberEqual(x, #0)) | |
| 516 } | |
| 517 | |
| 518 { // ToBoolean(string) | |
| 519 Node* r = R.ReduceUnop(op, Type::String()); | |
| 520 CHECK_EQ(IrOpcode::kBooleanNot, r->opcode()); | |
| 521 Node* i = r->InputAt(0); | |
| 522 CHECK_EQ(IrOpcode::kNumberEqual, i->opcode()); | |
| 523 Node* j = i->InputAt(0); | |
| 524 CHECK_EQ(IrOpcode::kLoadField, j->opcode()); | |
| 525 // ToBoolean(x:string) => BooleanNot(NumberEqual(x.length, #0)) | |
| 526 } | |
| 527 | |
| 528 { // ToBoolean(object) | 510 { // ToBoolean(object) |
| 529 Node* r = R.ReduceUnop(op, Type::DetectableObject()); | 511 Node* r = R.ReduceUnop(op, Type::DetectableObject()); |
| 530 R.CheckTrue(r); | 512 R.CheckTrue(r); |
| 531 } | 513 } |
| 532 | 514 |
| 533 { // ToBoolean(undetectable) | 515 { // ToBoolean(undetectable) |
| 534 Node* r = R.ReduceUnop(op, Type::Undetectable()); | 516 Node* r = R.ReduceUnop(op, Type::Undetectable()); |
| 535 R.CheckFalse(r); | 517 R.CheckFalse(r); |
| 536 } | 518 } |
| 537 | 519 |
| 538 { // ToBoolean(object) | 520 { // ToBoolean(object) |
| 539 Node* r = R.ReduceUnop(op, Type::Object()); | 521 Node* r = R.ReduceUnop(op, Type::Object()); |
| 540 CHECK_EQ(IrOpcode::kJSToBoolean, r->opcode()); | 522 CHECK_EQ(IrOpcode::kAnyToBoolean, r->opcode()); |
| 541 } | 523 } |
| 542 } | 524 } |
| 543 | 525 |
| 544 | |
| 545 TEST(JSToBoolean_replacement) { | |
| 546 JSTypedLoweringTester R; | |
| 547 | |
| 548 Type* types[] = {Type::Null(), Type::Undefined(), | |
| 549 Type::Boolean(), Type::OrderedNumber(), | |
| 550 Type::DetectableObject(), Type::Undetectable()}; | |
| 551 | |
| 552 for (size_t i = 0; i < arraysize(types); i++) { | |
| 553 Node* n = R.Parameter(types[i]); | |
| 554 Node* c = R.graph.NewNode(R.javascript.ToBoolean(), n, R.context()); | |
| 555 Node* r = R.reduce(c); | |
| 556 | |
| 557 if (types[i]->Is(Type::Boolean())) { | |
| 558 CHECK_EQ(n, r); | |
| 559 } else if (types[i]->Is(Type::OrderedNumber())) { | |
| 560 CHECK_EQ(IrOpcode::kBooleanNot, r->opcode()); | |
| 561 } else { | |
| 562 CHECK_EQ(IrOpcode::kHeapConstant, r->opcode()); | |
| 563 } | |
| 564 } | |
| 565 } | |
| 566 | |
| 567 | 526 |
| 568 TEST(JSToString1) { | 527 TEST(JSToString1) { |
| 569 JSTypedLoweringTester R; | 528 JSTypedLoweringTester R; |
| 570 | 529 |
| 571 for (size_t i = 0; i < arraysize(kStringTypes); i++) { | 530 for (size_t i = 0; i < arraysize(kStringTypes); i++) { |
| 572 Node* r = R.ReduceUnop(R.javascript.ToString(), kStringTypes[i]); | 531 Node* r = R.ReduceUnop(R.javascript.ToString(), kStringTypes[i]); |
| 573 CHECK_EQ(IrOpcode::kParameter, r->opcode()); | 532 CHECK_EQ(IrOpcode::kParameter, r->opcode()); |
| 574 } | 533 } |
| 575 | 534 |
| 576 const Operator* op = R.javascript.ToString(); | 535 const Operator* op = R.javascript.ToString(); |
| (...skipping 721 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1298 CHECK_EQ(p1, r->InputAt(0)); | 1257 CHECK_EQ(p1, r->InputAt(0)); |
| 1299 CHECK_EQ(p0, r->InputAt(1)); | 1258 CHECK_EQ(p0, r->InputAt(1)); |
| 1300 } else { | 1259 } else { |
| 1301 CHECK_EQ(p0, r->InputAt(0)); | 1260 CHECK_EQ(p0, r->InputAt(0)); |
| 1302 CHECK_EQ(p1, r->InputAt(1)); | 1261 CHECK_EQ(p1, r->InputAt(1)); |
| 1303 } | 1262 } |
| 1304 } | 1263 } |
| 1305 } | 1264 } |
| 1306 } | 1265 } |
| 1307 } | 1266 } |
| OLD | NEW |