Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: src/compiler/js-typed-lowering.cc

Issue 1369313004: [turbofan] Make string comparisons effectful. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/compiler/simplified-lowering.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/compiler/access-builder.h" 6 #include "src/compiler/access-builder.h"
7 #include "src/compiler/js-graph.h" 7 #include "src/compiler/js-graph.h"
8 #include "src/compiler/js-typed-lowering.h" 8 #include "src/compiler/js-typed-lowering.h"
9 #include "src/compiler/linkage.h" 9 #include "src/compiler/linkage.h"
10 #include "src/compiler/node-matchers.h" 10 #include "src/compiler/node-matchers.h"
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 // Insert an boolean not to invert the value. 174 // Insert an boolean not to invert the value.
175 Node* value = graph()->NewNode(simplified()->BooleanNot(), node_); 175 Node* value = graph()->NewNode(simplified()->BooleanNot(), node_);
176 node_->ReplaceUses(value); 176 node_->ReplaceUses(value);
177 // Note: ReplaceUses() smashes all uses, so smash it back here. 177 // Note: ReplaceUses() smashes all uses, so smash it back here.
178 value->ReplaceInput(0, node_); 178 value->ReplaceInput(0, node_);
179 return lowering_->Replace(value); 179 return lowering_->Replace(value);
180 } 180 }
181 return lowering_->Changed(node_); 181 return lowering_->Changed(node_);
182 } 182 }
183 183
184 Reduction ChangeToStringComparisonOperator(const Operator* op,
185 bool invert = false) {
186 if (node_->op()->ControlInputCount() > 0) {
187 lowering_->RelaxControls(node_);
188 }
189 // String comparison operators need effect and control inputs, so copy them
190 // over.
191 Node* effect = NodeProperties::GetEffectInput(node_);
192 Node* control = NodeProperties::GetControlInput(node_);
193 node_->ReplaceInput(2, effect);
194 node_->ReplaceInput(3, control);
195
196 node_->TrimInputCount(4);
197 NodeProperties::ChangeOp(node_, op);
198
199 if (invert) {
200 // Insert a boolean-not to invert the value.
201 Node* value = graph()->NewNode(simplified()->BooleanNot(), node_);
202 node_->ReplaceUses(value);
203 // Note: ReplaceUses() smashes all uses, so smash it back here.
204 value->ReplaceInput(0, node_);
205 return lowering_->Replace(value);
206 }
207 return lowering_->Changed(node_);
208 }
209
184 Reduction ChangeToPureOperator(const Operator* op, Type* type) { 210 Reduction ChangeToPureOperator(const Operator* op, Type* type) {
185 return ChangeToPureOperator(op, false, type); 211 return ChangeToPureOperator(op, false, type);
186 } 212 }
187 213
188 bool IsStrong() { return is_strong(OpParameter<LanguageMode>(node_)); } 214 bool IsStrong() { return is_strong(OpParameter<LanguageMode>(node_)); }
189 215
190 bool OneInputIs(Type* t) { return left_type()->Is(t) || right_type()->Is(t); } 216 bool OneInputIs(Type* t) { return left_type()->Is(t) || right_type()->Is(t); }
191 217
192 bool BothInputsAre(Type* t) { 218 bool BothInputsAre(Type* t) {
193 return left_type()->Is(t) && right_type()->Is(t); 219 return left_type()->Is(t) && right_type()->Is(t);
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 case IrOpcode::kJSLessThanOrEqual: 522 case IrOpcode::kJSLessThanOrEqual:
497 stringOp = simplified()->StringLessThanOrEqual(); 523 stringOp = simplified()->StringLessThanOrEqual();
498 break; 524 break;
499 case IrOpcode::kJSGreaterThanOrEqual: 525 case IrOpcode::kJSGreaterThanOrEqual:
500 stringOp = simplified()->StringLessThanOrEqual(); 526 stringOp = simplified()->StringLessThanOrEqual();
501 r.SwapInputs(); // a >= b => b <= a 527 r.SwapInputs(); // a >= b => b <= a
502 break; 528 break;
503 default: 529 default:
504 return NoChange(); 530 return NoChange();
505 } 531 }
506 return r.ChangeToPureOperator(stringOp); 532 r.ChangeToStringComparisonOperator(stringOp);
533 return Changed(node);
507 } 534 }
508 if (r.OneInputCannotBe(Type::StringOrReceiver())) { 535 if (r.OneInputCannotBe(Type::StringOrReceiver())) {
509 const Operator* less_than; 536 const Operator* less_than;
510 const Operator* less_than_or_equal; 537 const Operator* less_than_or_equal;
511 if (r.BothInputsAre(Type::Unsigned32())) { 538 if (r.BothInputsAre(Type::Unsigned32())) {
512 less_than = machine()->Uint32LessThan(); 539 less_than = machine()->Uint32LessThan();
513 less_than_or_equal = machine()->Uint32LessThanOrEqual(); 540 less_than_or_equal = machine()->Uint32LessThanOrEqual();
514 } else if (r.BothInputsAre(Type::Signed32())) { 541 } else if (r.BothInputsAre(Type::Signed32())) {
515 less_than = machine()->Int32LessThan(); 542 less_than = machine()->Int32LessThan();
516 less_than_or_equal = machine()->Int32LessThanOrEqual(); 543 less_than_or_equal = machine()->Int32LessThanOrEqual();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 } 577 }
551 578
552 579
553 Reduction JSTypedLowering::ReduceJSEqual(Node* node, bool invert) { 580 Reduction JSTypedLowering::ReduceJSEqual(Node* node, bool invert) {
554 JSBinopReduction r(this, node); 581 JSBinopReduction r(this, node);
555 582
556 if (r.BothInputsAre(Type::Number())) { 583 if (r.BothInputsAre(Type::Number())) {
557 return r.ChangeToPureOperator(simplified()->NumberEqual(), invert); 584 return r.ChangeToPureOperator(simplified()->NumberEqual(), invert);
558 } 585 }
559 if (r.BothInputsAre(Type::String())) { 586 if (r.BothInputsAre(Type::String())) {
560 return r.ChangeToPureOperator(simplified()->StringEqual(), invert); 587 return r.ChangeToStringComparisonOperator(simplified()->StringEqual(),
588 invert);
561 } 589 }
562 if (r.BothInputsAre(Type::Receiver())) { 590 if (r.BothInputsAre(Type::Receiver())) {
563 return r.ChangeToPureOperator( 591 return r.ChangeToPureOperator(
564 simplified()->ReferenceEqual(Type::Receiver()), invert); 592 simplified()->ReferenceEqual(Type::Receiver()), invert);
565 } 593 }
566 // TODO(turbofan): js-typed-lowering of Equal(undefined) 594 // TODO(turbofan): js-typed-lowering of Equal(undefined)
567 // TODO(turbofan): js-typed-lowering of Equal(null) 595 // TODO(turbofan): js-typed-lowering of Equal(null)
568 // TODO(turbofan): js-typed-lowering of Equal(boolean) 596 // TODO(turbofan): js-typed-lowering of Equal(boolean)
569 return NoChange(); 597 return NoChange();
570 } 598 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 } 635 }
608 if (r.OneInputIs(Type::Receiver())) { 636 if (r.OneInputIs(Type::Receiver())) {
609 return r.ChangeToPureOperator( 637 return r.ChangeToPureOperator(
610 simplified()->ReferenceEqual(Type::Receiver()), invert); 638 simplified()->ReferenceEqual(Type::Receiver()), invert);
611 } 639 }
612 if (r.BothInputsAre(Type::Unique())) { 640 if (r.BothInputsAre(Type::Unique())) {
613 return r.ChangeToPureOperator(simplified()->ReferenceEqual(Type::Unique()), 641 return r.ChangeToPureOperator(simplified()->ReferenceEqual(Type::Unique()),
614 invert); 642 invert);
615 } 643 }
616 if (r.BothInputsAre(Type::String())) { 644 if (r.BothInputsAre(Type::String())) {
617 return r.ChangeToPureOperator(simplified()->StringEqual(), invert); 645 return r.ChangeToStringComparisonOperator(simplified()->StringEqual(),
646 invert);
618 } 647 }
619 if (r.BothInputsAre(Type::Number())) { 648 if (r.BothInputsAre(Type::Number())) {
620 return r.ChangeToPureOperator(simplified()->NumberEqual(), invert); 649 return r.ChangeToPureOperator(simplified()->NumberEqual(), invert);
621 } 650 }
622 // TODO(turbofan): js-typed-lowering of StrictEqual(mixed types) 651 // TODO(turbofan): js-typed-lowering of StrictEqual(mixed types)
623 return NoChange(); 652 return NoChange();
624 } 653 }
625 654
626 655
627 Reduction JSTypedLowering::ReduceJSUnaryNot(Node* node) { 656 Reduction JSTypedLowering::ReduceJSUnaryNot(Node* node) {
(...skipping 1126 matching lines...) Expand 10 before | Expand all | Expand 10 after
1754 } 1783 }
1755 1784
1756 1785
1757 MachineOperatorBuilder* JSTypedLowering::machine() const { 1786 MachineOperatorBuilder* JSTypedLowering::machine() const {
1758 return jsgraph()->machine(); 1787 return jsgraph()->machine();
1759 } 1788 }
1760 1789
1761 } // namespace compiler 1790 } // namespace compiler
1762 } // namespace internal 1791 } // namespace internal
1763 } // namespace v8 1792 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/compiler/simplified-lowering.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698