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

Side by Side Diff: runtime/vm/intermediate_language_x64.cc

Issue 10918097: Allow smi comparisons to have constant operands. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_X64. 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_X64.
6 #if defined(TARGET_ARCH_X64) 6 #if defined(TARGET_ARCH_X64)
7 7
8 #include "vm/intermediate_language.h" 8 #include "vm/intermediate_language.h"
9 9
10 #include "lib/error.h" 10 #include "lib/error.h"
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 HasICData() && ic_data()->AllTargetsHaveSameOwner(kInstanceCid); 272 HasICData() && ic_data()->AllTargetsHaveSameOwner(kInstanceCid);
273 if (receiver_class_id() == kDoubleCid) { 273 if (receiver_class_id() == kDoubleCid) {
274 const intptr_t kNumTemps = 0; 274 const intptr_t kNumTemps = 0;
275 LocationSummary* locs = 275 LocationSummary* locs =
276 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall); 276 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall);
277 locs->set_in(0, Location::RequiresXmmRegister()); 277 locs->set_in(0, Location::RequiresXmmRegister());
278 locs->set_in(1, Location::RequiresXmmRegister()); 278 locs->set_in(1, Location::RequiresXmmRegister());
279 locs->set_out(Location::RequiresRegister()); 279 locs->set_out(Location::RequiresRegister());
280 return locs; 280 return locs;
281 } 281 }
282 if ((receiver_class_id() == kSmiCid) || is_checked_strict_equal) { 282 if (receiver_class_id() == kSmiCid) {
283 const intptr_t kNumTemps = 1; 283 const intptr_t kNumTemps = 0;
284 LocationSummary* locs =
285 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall);
286 locs->set_in(0, Location::RegisterOrConstant(left()));
287 locs->set_in(1, Location::RegisterOrConstant(right()));
288 locs->set_out(Location::RequiresRegister());
289 return locs;
290 }
291 if (is_checked_strict_equal) {
292 const intptr_t kNumTemps = 1;
284 LocationSummary* locs = 293 LocationSummary* locs =
285 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall); 294 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall);
286 locs->set_in(0, Location::RequiresRegister()); 295 locs->set_in(0, Location::RequiresRegister());
287 locs->set_in(1, Location::RequiresRegister()); 296 locs->set_in(1, Location::RequiresRegister());
288 locs->set_temp(0, Location::RequiresRegister()); 297 locs->set_temp(0, Location::RequiresRegister());
289 locs->set_out(Location::RequiresRegister()); 298 locs->set_out(Location::RequiresRegister());
290 return locs; 299 return locs;
291 } 300 }
292 if (HasICData() && (ic_data()->NumberOfChecks() > 0)) { 301 if (HasICData() && (ic_data()->NumberOfChecks() > 0)) {
293 const intptr_t kNumTemps = 1; 302 const intptr_t kNumTemps = 1;
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 __ jmp(&done); 563 __ jmp(&done);
555 __ Bind(&non_null_compare); // Receiver is not null. 564 __ Bind(&non_null_compare); // Receiver is not null.
556 __ pushq(left); 565 __ pushq(left);
557 __ pushq(right); 566 __ pushq(right);
558 EmitEqualityAsPolymorphicCall(compiler, ic_data, locs, branch, kind, 567 EmitEqualityAsPolymorphicCall(compiler, ic_data, locs, branch, kind,
559 deopt_id, token_pos); 568 deopt_id, token_pos);
560 __ Bind(&done); 569 __ Bind(&done);
561 } 570 }
562 571
563 572
573 Immediate SmiConstantToImmediate(const Object& constant) {
574 ASSERT(constant.IsSmi());
575 return Immediate(reinterpret_cast<int64_t>(constant.raw()));
576 }
577
578
564 static void EmitSmiComparisonOp(FlowGraphCompiler* compiler, 579 static void EmitSmiComparisonOp(FlowGraphCompiler* compiler,
565 const LocationSummary& locs, 580 const LocationSummary& locs,
566 Token::Kind kind, 581 Token::Kind kind,
567 BranchInstr* branch) { 582 BranchInstr* branch) {
568 Register left = locs.in(0).reg(); 583 Location left = locs.in(0);
569 Register right = locs.in(1).reg(); 584 Location right = locs.in(1);
570 585
571 Condition true_condition = TokenKindToSmiCondition(kind); 586 Condition true_condition = TokenKindToSmiCondition(kind);
572 __ cmpq(left, right); 587
588 if (left.IsConstant() && right.IsConstant()) {
589 // TODO(vegorov): should be eliminated earlier by constant propagation.
590 const bool result = FlowGraphCompiler::EvaluateCondition(
591 true_condition,
592 Smi::Cast(left.constant()).Value(),
593 Smi::Cast(right.constant()).Value());
594
595 if (branch != NULL) {
596 branch->EmitBranchOnValue(compiler, result);
597 } else {
598 __ LoadObject(locs.out().reg(), result ? compiler->bool_true()
599 : compiler->bool_false());
600 }
601
602 return;
603 }
604
605 if (left.IsConstant()) {
606 __ cmpq(right.reg(), SmiConstantToImmediate(left.constant()));
607 true_condition = FlowGraphCompiler::FlipCondition(true_condition);
608 } else if (right.IsConstant()) {
609 __ cmpq(left.reg(), SmiConstantToImmediate(right.constant()));
610 } else {
611 __ cmpq(left.reg(), right.reg());
612 }
573 613
574 if (branch != NULL) { 614 if (branch != NULL) {
575 branch->EmitBranchOnCondition(compiler, true_condition); 615 branch->EmitBranchOnCondition(compiler, true_condition);
576 } else { 616 } else {
577 Register result = locs.out().reg(); 617 Register result = locs.out().reg();
578 Label done, is_true; 618 Label done, is_true;
579 __ j(true_condition, &is_true); 619 __ j(true_condition, &is_true);
580 __ LoadObject(result, compiler->bool_false()); 620 __ LoadObject(result, compiler->bool_false());
581 __ jmp(&done); 621 __ jmp(&done);
582 __ Bind(&is_true); 622 __ Bind(&is_true);
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 Token::kEQ, // kNE reverse occurs at branch. 732 Token::kEQ, // kNE reverse occurs at branch.
693 locs()); 733 locs());
694 Condition branch_condition = (kind() == Token::kNE) ? NOT_EQUAL : EQUAL; 734 Condition branch_condition = (kind() == Token::kNE) ? NOT_EQUAL : EQUAL;
695 __ CompareObject(RAX, compiler->bool_true()); 735 __ CompareObject(RAX, compiler->bool_true());
696 branch->EmitBranchOnCondition(compiler, branch_condition); 736 branch->EmitBranchOnCondition(compiler, branch_condition);
697 } 737 }
698 738
699 739
700 LocationSummary* RelationalOpInstr::MakeLocationSummary() const { 740 LocationSummary* RelationalOpInstr::MakeLocationSummary() const {
701 const intptr_t kNumInputs = 2; 741 const intptr_t kNumInputs = 2;
742 const intptr_t kNumTemps = 0;
702 if (operands_class_id() == kDoubleCid) { 743 if (operands_class_id() == kDoubleCid) {
703 const intptr_t kNumTemps = 0;
704 LocationSummary* summary = 744 LocationSummary* summary =
705 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall); 745 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall);
706 summary->set_in(0, Location::RequiresXmmRegister()); 746 summary->set_in(0, Location::RequiresXmmRegister());
707 summary->set_in(1, Location::RequiresXmmRegister()); 747 summary->set_in(1, Location::RequiresXmmRegister());
708 summary->set_out(Location::RequiresRegister()); 748 summary->set_out(Location::RequiresRegister());
709 return summary; 749 return summary;
710 } else if (operands_class_id() == kSmiCid) { 750 } else if (operands_class_id() == kSmiCid) {
711 const intptr_t kNumTemps = 1;
712 LocationSummary* summary = 751 LocationSummary* summary =
713 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall); 752 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall);
714 summary->set_in(0, Location::RequiresRegister()); 753 summary->set_in(0, Location::RegisterOrConstant(left()));
715 summary->set_in(1, Location::RequiresRegister()); 754 summary->set_in(1, Location::RegisterOrConstant(right()));
716 summary->set_out(Location::RequiresRegister()); 755 summary->set_out(Location::RequiresRegister());
717 summary->set_temp(0, Location::RequiresRegister());
718 return summary; 756 return summary;
719 } 757 }
720 const intptr_t kNumTemps = 0;
721 LocationSummary* locs = 758 LocationSummary* locs =
722 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kCall); 759 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kCall);
723 // Pick arbitrary fixed input registers because this is a call. 760 // Pick arbitrary fixed input registers because this is a call.
724 locs->set_in(0, Location::RegisterLocation(RAX)); 761 locs->set_in(0, Location::RegisterLocation(RAX));
725 locs->set_in(1, Location::RegisterLocation(RCX)); 762 locs->set_in(1, Location::RegisterLocation(RCX));
726 locs->set_out(Location::RegisterLocation(RAX)); 763 locs->set_out(Location::RegisterLocation(RAX));
727 return locs; 764 return locs;
728 } 765 }
729 766
730 767
(...skipping 1544 matching lines...) Expand 10 before | Expand all | Expand 10 after
2275 __ j(ABOVE_EQUAL, deopt); 2312 __ j(ABOVE_EQUAL, deopt);
2276 } 2313 }
2277 } 2314 }
2278 2315
2279 2316
2280 } // namespace dart 2317 } // namespace dart
2281 2318
2282 #undef __ 2319 #undef __
2283 2320
2284 #endif // defined TARGET_ARCH_X64 2321 #endif // defined TARGET_ARCH_X64
OLDNEW
« runtime/vm/intermediate_language_ia32.cc ('K') | « runtime/vm/intermediate_language_ia32.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698