OLD | NEW |
---|---|
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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_DBC. | 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_DBC. |
6 #if defined(TARGET_ARCH_DBC) | 6 #if defined(TARGET_ARCH_DBC) |
7 | 7 |
8 #include "vm/intermediate_language.h" | 8 #include "vm/intermediate_language.h" |
9 | 9 |
10 #include "vm/cpu.h" | 10 #include "vm/cpu.h" |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
94 M(Float64x2OneArg) \ | 94 M(Float64x2OneArg) \ |
95 M(ExtractNthOutput) \ | 95 M(ExtractNthOutput) \ |
96 M(BinaryUint32Op) \ | 96 M(BinaryUint32Op) \ |
97 M(ShiftUint32Op) \ | 97 M(ShiftUint32Op) \ |
98 M(UnaryUint32Op) \ | 98 M(UnaryUint32Op) \ |
99 M(UnboxedIntConverter) \ | 99 M(UnboxedIntConverter) \ |
100 M(GrowRegExpStack) \ | 100 M(GrowRegExpStack) \ |
101 M(BoxInteger32) \ | 101 M(BoxInteger32) \ |
102 M(UnboxInteger32) \ | 102 M(UnboxInteger32) \ |
103 M(CheckedSmiOp) \ | 103 M(CheckedSmiOp) \ |
104 M(CheckArrayBound) \ | |
105 M(RelationalOp) \ | |
106 M(EqualityCompare) \ | |
107 M(LoadIndexed) | |
108 | 104 |
109 // Location summaries actually are not used by the unoptimizing DBC compiler | 105 // Location summaries actually are not used by the unoptimizing DBC compiler |
110 // because we don't allocate any registers. | 106 // because we don't allocate any registers. |
111 static LocationSummary* CreateLocationSummary( | 107 static LocationSummary* CreateLocationSummary( |
112 Zone* zone, | 108 Zone* zone, |
113 intptr_t num_inputs, | 109 intptr_t num_inputs, |
114 Location output = Location::NoLocation(), | 110 Location output = Location::NoLocation(), |
115 LocationSummary::ContainsCall contains_call = LocationSummary::kNoCall) { | 111 LocationSummary::ContainsCall contains_call = LocationSummary::kNoCall) { |
116 const intptr_t kNumTemps = 0; | 112 const intptr_t kNumTemps = 0; |
117 LocationSummary* locs = new(zone) LocationSummary( | 113 LocationSummary* locs = new(zone) LocationSummary( |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
162 | 158 |
163 #define DEFINE_UNIMPLEMENTED(Name) \ | 159 #define DEFINE_UNIMPLEMENTED(Name) \ |
164 DEFINE_UNIMPLEMENTED_MAKE_LOCATION_SUMMARY(Name) \ | 160 DEFINE_UNIMPLEMENTED_MAKE_LOCATION_SUMMARY(Name) \ |
165 DEFINE_UNIMPLEMENTED_EMIT_NATIVE_CODE(Name) \ | 161 DEFINE_UNIMPLEMENTED_EMIT_NATIVE_CODE(Name) \ |
166 | 162 |
167 FOR_EACH_UNIMPLEMENTED_INSTRUCTION(DEFINE_UNIMPLEMENTED) | 163 FOR_EACH_UNIMPLEMENTED_INSTRUCTION(DEFINE_UNIMPLEMENTED) |
168 | 164 |
169 #undef DEFINE_UNIMPLEMENTED | 165 #undef DEFINE_UNIMPLEMENTED |
170 | 166 |
171 DEFINE_UNIMPLEMENTED_EMIT_BRANCH_CODE(TestCids) | 167 DEFINE_UNIMPLEMENTED_EMIT_BRANCH_CODE(TestCids) |
172 DEFINE_UNIMPLEMENTED_EMIT_BRANCH_CODE(RelationalOp) | |
173 DEFINE_UNIMPLEMENTED_EMIT_BRANCH_CODE(EqualityCompare) | |
174 | 168 |
175 | 169 |
176 EMIT_NATIVE_CODE(InstanceOf, 2, Location::SameAsFirstInput(), | 170 EMIT_NATIVE_CODE(InstanceOf, 2, Location::SameAsFirstInput(), |
177 LocationSummary::kCall) { | 171 LocationSummary::kCall) { |
178 SubtypeTestCache& test_cache = SubtypeTestCache::Handle(); | 172 SubtypeTestCache& test_cache = SubtypeTestCache::Handle(); |
179 if (!type().IsVoidType() && type().IsInstantiated()) { | 173 if (!type().IsVoidType() && type().IsInstantiated()) { |
180 test_cache = SubtypeTestCache::New(); | 174 test_cache = SubtypeTestCache::New(); |
181 } | 175 } |
182 | 176 |
183 if (compiler->is_optimizing()) { | 177 if (compiler->is_optimizing()) { |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
371 if (compiler->is_optimizing()) { | 365 if (compiler->is_optimizing()) { |
372 __ PopLocal(locs()->out(0).reg()); | 366 __ PopLocal(locs()->out(0).reg()); |
373 } | 367 } |
374 } | 368 } |
375 | 369 |
376 | 370 |
377 static void EmitBranchOnCondition(FlowGraphCompiler* compiler, | 371 static void EmitBranchOnCondition(FlowGraphCompiler* compiler, |
378 Condition true_condition, | 372 Condition true_condition, |
379 BranchLabels labels) { | 373 BranchLabels labels) { |
380 if (true_condition == NEXT_IS_TRUE) { | 374 if (true_condition == NEXT_IS_TRUE) { |
375 // NEXT_IS_TRUE indicates that the preceeding test expects the true case | |
376 // to be in the subsequent instruction, which it skips if the test fails. | |
381 __ Jump(labels.true_label); | 377 __ Jump(labels.true_label); |
382 if (labels.fall_through != labels.false_label) { | 378 if (labels.fall_through != labels.false_label) { |
379 // The preceeding Jump instruction will be skipped if the test fails. | |
380 // If we aren't falling through to the false case, then we have to do | |
381 // a Jump to it here. | |
383 __ Jump(labels.false_label); | 382 __ Jump(labels.false_label); |
384 } | 383 } |
385 } else { | 384 } else { |
386 ASSERT(true_condition == NEXT_IS_FALSE); | 385 ASSERT(true_condition == NEXT_IS_FALSE); |
386 // NEXT_IS_FALSE indicates that the preceeing test has been flipped and | |
387 // expects the false case to be in the subsequent instruction, which it | |
388 // skips if the test succeeds. | |
387 __ Jump(labels.false_label); | 389 __ Jump(labels.false_label); |
388 if (labels.fall_through != labels.true_label) { | 390 if (labels.fall_through != labels.true_label) { |
391 // The preceeding Jump instruction will be skipped if the test succeeds. | |
392 // If we aren't falling through to the true case, then we have to do | |
393 // a Jump to it here. | |
389 __ Jump(labels.true_label); | 394 __ Jump(labels.true_label); |
390 } | 395 } |
391 } | 396 } |
392 } | 397 } |
393 | 398 |
394 | 399 |
395 Condition StrictCompareInstr::EmitComparisonCode(FlowGraphCompiler* compiler, | 400 Condition StrictCompareInstr::EmitComparisonCode(FlowGraphCompiler* compiler, |
396 BranchLabels labels) { | 401 BranchLabels labels) { |
397 ASSERT((kind() == Token::kNE_STRICT) || | 402 ASSERT((kind() == Token::kNE_STRICT) || |
398 (kind() == Token::kEQ_STRICT)); | 403 (kind() == Token::kEQ_STRICT)); |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
568 __ StoreIndexed(locs()->in(kArrayPos).reg(), | 573 __ StoreIndexed(locs()->in(kArrayPos).reg(), |
569 locs()->in(kIndexPos).reg(), | 574 locs()->in(kIndexPos).reg(), |
570 locs()->in(kValuePos).reg()); | 575 locs()->in(kValuePos).reg()); |
571 } else { | 576 } else { |
572 ASSERT(class_id() == kArrayCid); | 577 ASSERT(class_id() == kArrayCid); |
573 __ StoreIndexedTOS(); | 578 __ StoreIndexedTOS(); |
574 } | 579 } |
575 } | 580 } |
576 | 581 |
577 | 582 |
583 EMIT_NATIVE_CODE(LoadIndexed, 2, Location::RequiresRegister()) { | |
584 ASSERT(compiler->is_optimizing()); | |
585 if (class_id() != kArrayCid) { | |
586 Unsupported(compiler); | |
587 UNREACHABLE(); | |
588 } | |
589 const Register array = locs()->in(0).reg(); | |
590 const Register index = locs()->in(1).reg(); | |
591 const Register result = locs()->out(0).reg(); | |
592 | |
593 __ LoadIndexed(result, array, index); | |
594 } | |
595 | |
596 | |
578 EMIT_NATIVE_CODE(StringInterpolate, | 597 EMIT_NATIVE_CODE(StringInterpolate, |
579 1, Location::RegisterLocation(0), | 598 1, Location::RegisterLocation(0), |
580 LocationSummary::kCall) { | 599 LocationSummary::kCall) { |
581 if (compiler->is_optimizing()) { | 600 if (compiler->is_optimizing()) { |
582 __ Push(locs()->in(0).reg()); | 601 __ Push(locs()->in(0).reg()); |
583 } | 602 } |
584 const intptr_t kArgumentCount = 1; | 603 const intptr_t kArgumentCount = 1; |
585 const Array& arguments_descriptor = Array::Handle( | 604 const Array& arguments_descriptor = Array::Handle( |
586 ArgumentsDescriptor::New(kArgumentCount, Object::null_array())); | 605 ArgumentsDescriptor::New(kArgumentCount, Object::null_array())); |
587 __ PushConstant(CallFunction()); | 606 __ PushConstant(CallFunction()); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
635 EMIT_NATIVE_CODE(StringToCharCode, | 654 EMIT_NATIVE_CODE(StringToCharCode, |
636 1, Location::RequiresRegister(), | 655 1, Location::RequiresRegister(), |
637 LocationSummary::kNoCall) { | 656 LocationSummary::kNoCall) { |
638 ASSERT(cid_ == kOneByteStringCid); | 657 ASSERT(cid_ == kOneByteStringCid); |
639 const Register str = locs()->in(0).reg(); | 658 const Register str = locs()->in(0).reg(); |
640 const Register result = locs()->out(0).reg(); // Result char code is a smi. | 659 const Register result = locs()->out(0).reg(); // Result char code is a smi. |
641 __ StringToCharCode(result, str); | 660 __ StringToCharCode(result, str); |
642 } | 661 } |
643 | 662 |
644 | 663 |
645 | |
646 EMIT_NATIVE_CODE(AllocateObject, | 664 EMIT_NATIVE_CODE(AllocateObject, |
647 0, Location::RequiresRegister(), | 665 0, Location::RequiresRegister(), |
648 LocationSummary::kCall) { | 666 LocationSummary::kCall) { |
649 if (ArgumentCount() == 1) { | 667 if (ArgumentCount() == 1) { |
650 __ PushConstant(cls()); | 668 __ PushConstant(cls()); |
651 __ AllocateT(); | 669 __ AllocateT(); |
652 compiler->AddCurrentDescriptor(RawPcDescriptors::kOther, | 670 compiler->AddCurrentDescriptor(RawPcDescriptors::kOther, |
653 Thread::kNoDeoptId, | 671 Thread::kNoDeoptId, |
654 token_pos()); | 672 token_pos()); |
655 } else { | 673 } else { |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
734 __ MoveSpecial(-exception_var().index()-1, | 752 __ MoveSpecial(-exception_var().index()-1, |
735 Simulator::kExceptionSpecialIndex); | 753 Simulator::kExceptionSpecialIndex); |
736 __ MoveSpecial(-stacktrace_var().index()-1, | 754 __ MoveSpecial(-stacktrace_var().index()-1, |
737 Simulator::kStacktraceSpecialIndex); | 755 Simulator::kStacktraceSpecialIndex); |
738 __ SetFrame(compiler->StackSize()); | 756 __ SetFrame(compiler->StackSize()); |
739 } | 757 } |
740 | 758 |
741 | 759 |
742 EMIT_NATIVE_CODE(Throw, 0, Location::NoLocation(), LocationSummary::kCall) { | 760 EMIT_NATIVE_CODE(Throw, 0, Location::NoLocation(), LocationSummary::kCall) { |
743 __ Throw(0); | 761 __ Throw(0); |
744 compiler->RecordSafepoint(locs()); | |
745 compiler->AddCurrentDescriptor(RawPcDescriptors::kOther, | 762 compiler->AddCurrentDescriptor(RawPcDescriptors::kOther, |
746 deopt_id(), | 763 deopt_id(), |
747 token_pos()); | 764 token_pos()); |
765 compiler->RecordAfterCall(this); | |
748 __ Trap(); | 766 __ Trap(); |
749 } | 767 } |
750 | 768 |
751 | 769 |
752 EMIT_NATIVE_CODE(ReThrow, 0, Location::NoLocation(), LocationSummary::kCall) { | 770 EMIT_NATIVE_CODE(ReThrow, 0, Location::NoLocation(), LocationSummary::kCall) { |
753 compiler->SetNeedsStacktrace(catch_try_index()); | 771 compiler->SetNeedsStacktrace(catch_try_index()); |
754 __ Throw(1); | 772 __ Throw(1); |
755 compiler->RecordSafepoint(locs()); | |
756 compiler->AddCurrentDescriptor(RawPcDescriptors::kOther, | 773 compiler->AddCurrentDescriptor(RawPcDescriptors::kOther, |
757 deopt_id(), | 774 deopt_id(), |
758 token_pos()); | 775 token_pos()); |
776 compiler->RecordAfterCall(this); | |
759 __ Trap(); | 777 __ Trap(); |
760 } | 778 } |
761 | 779 |
762 EMIT_NATIVE_CODE(InstantiateType, | 780 EMIT_NATIVE_CODE(InstantiateType, |
763 1, Location::RequiresRegister(), | 781 1, Location::RequiresRegister(), |
764 LocationSummary::kCall) { | 782 LocationSummary::kCall) { |
765 if (compiler->is_optimizing()) { | 783 if (compiler->is_optimizing()) { |
766 __ Push(locs()->in(0).reg()); | 784 __ Push(locs()->in(0).reg()); |
767 } | 785 } |
768 __ InstantiateType(__ AddConstant(type())); | 786 __ InstantiateType(__ AddConstant(type())); |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1123 break; | 1141 break; |
1124 } | 1142 } |
1125 case Token::kBIT_NOT: | 1143 case Token::kBIT_NOT: |
1126 __ BitNot(locs()->out(0).reg(), locs()->in(0).reg()); | 1144 __ BitNot(locs()->out(0).reg(), locs()->in(0).reg()); |
1127 break; | 1145 break; |
1128 default: | 1146 default: |
1129 UNREACHABLE(); | 1147 UNREACHABLE(); |
1130 } | 1148 } |
1131 } | 1149 } |
1132 | 1150 |
1151 | |
1152 static Token::Kind FlipCondition(Token::Kind kind) { | |
1153 switch (kind) { | |
1154 case Token::kEQ: return Token::kNE; | |
1155 case Token::kNE: return Token::kEQ; | |
1156 case Token::kLT: return Token::kGTE; | |
1157 case Token::kGT: return Token::kLTE; | |
1158 case Token::kLTE: return Token::kGT; | |
1159 case Token::kGTE: return Token::kLT; | |
1160 default: | |
1161 UNREACHABLE(); | |
1162 return Token::kNE; | |
1163 } | |
1164 } | |
1165 | |
1166 | |
1167 static Bytecode::Opcode OpcodeForCondition(Token::Kind kind) { | |
1168 switch (kind) { | |
1169 case Token::kEQ: return Bytecode::kIfEqStrict; | |
1170 case Token::kNE: return Bytecode::kIfNeStrict; | |
1171 case Token::kLT: return Bytecode::kIfLt; | |
1172 case Token::kGT: return Bytecode::kIfGt; | |
1173 case Token::kLTE: return Bytecode::kIfLe; | |
1174 case Token::kGTE: return Bytecode::kIfGe; | |
1175 default: | |
1176 UNREACHABLE(); | |
1177 return Bytecode::kTrap; | |
1178 } | |
1179 } | |
1180 | |
1181 | |
1182 static Condition EmitSmiComparisonOp(FlowGraphCompiler* compiler, | |
1183 LocationSummary* locs, | |
1184 Token::Kind kind, | |
1185 BranchLabels labels) { | |
1186 const Register left = locs->in(0).reg(); | |
1187 const Register right = locs->in(1).reg(); | |
1188 Token::Kind comparison = kind; | |
1189 Condition condition = NEXT_IS_TRUE; | |
1190 if (labels.fall_through != labels.false_label) { | |
1191 // If we aren't falling through to the false label, we can save a Jump | |
1192 // instruction in the case that the true case is the fall through by | |
1193 // flipping the sense of the test such that the instruction following the | |
1194 // test is the Jump to the false label. | |
1195 condition = NEXT_IS_FALSE; | |
1196 comparison = FlipCondition(kind); | |
1197 } | |
1198 __ Emit(Bytecode::Encode(OpcodeForCondition(comparison), left, right)); | |
1199 return condition; | |
1200 } | |
1201 | |
1202 | |
1203 Condition EqualityCompareInstr::EmitComparisonCode(FlowGraphCompiler* compiler, | |
1204 BranchLabels labels) { | |
1205 if (operation_cid() == kSmiCid) { | |
1206 return EmitSmiComparisonOp(compiler, locs(), kind(), labels); | |
1207 } else { | |
1208 ASSERT(operation_cid() == kDoubleCid); | |
1209 Unsupported(compiler); | |
1210 UNREACHABLE(); | |
1211 return NEXT_IS_FALSE; | |
1212 } | |
1213 } | |
1214 | |
1215 | |
1216 EMIT_NATIVE_CODE(EqualityCompare, 2, Location::RequiresRegister()) { | |
1217 ASSERT(compiler->is_optimizing()); | |
1218 ASSERT((kind() == Token::kEQ) || (kind() == Token::kNE)); | |
1219 Label is_true, is_false; | |
1220 // These labels are not used. They are arranged so that EmitComparisonCode | |
1221 // emits a test that executes the following instruction when the test | |
1222 // succeeds. | |
1223 BranchLabels labels = { &is_true, &is_false, &is_false }; | |
1224 const Register result = locs()->out(0).reg(); | |
1225 __ LoadConstant(result, Bool::False()); | |
1226 Condition true_condition = EmitComparisonCode(compiler, labels); | |
1227 ASSERT(true_condition == NEXT_IS_TRUE); | |
1228 __ LoadConstant(result, Bool::True()); | |
1229 } | |
1230 | |
1231 | |
1232 void EqualityCompareInstr::EmitBranchCode(FlowGraphCompiler* compiler, | |
1233 BranchInstr* branch) { | |
1234 ASSERT((kind() == Token::kNE) || (kind() == Token::kEQ)); | |
1235 BranchLabels labels = compiler->CreateBranchLabels(branch); | |
1236 Condition true_condition = EmitComparisonCode(compiler, labels); | |
1237 EmitBranchOnCondition(compiler, true_condition, labels); | |
1238 } | |
1239 | |
1240 | |
1241 Condition RelationalOpInstr::EmitComparisonCode(FlowGraphCompiler* compiler, | |
1242 BranchLabels labels) { | |
1243 if (operation_cid() == kSmiCid) { | |
1244 return EmitSmiComparisonOp(compiler, locs(), kind(), labels); | |
1245 } else { | |
1246 ASSERT(operation_cid() == kDoubleCid); | |
1247 Unsupported(compiler); | |
1248 UNREACHABLE(); | |
1249 return NEXT_IS_FALSE; | |
1250 } | |
1251 } | |
1252 | |
1253 | |
1254 EMIT_NATIVE_CODE(RelationalOp, 2, Location::RequiresRegister()) { | |
1255 ASSERT(compiler->is_optimizing()); | |
1256 Label is_true, is_false; | |
1257 BranchLabels labels = { &is_true, &is_false, &is_false }; | |
Vyacheslav Egorov (Google)
2016/07/07 16:42:06
I see. NEXT_IS_FALSE actually refers to instructio
| |
1258 const Register result = locs()->out(0).reg(); | |
1259 __ LoadConstant(result, Bool::False()); | |
1260 Condition true_condition = EmitComparisonCode(compiler, labels); | |
1261 ASSERT(true_condition == NEXT_IS_TRUE); | |
1262 __ LoadConstant(result, Bool::True()); | |
1263 } | |
1264 | |
1265 | |
1266 void RelationalOpInstr::EmitBranchCode(FlowGraphCompiler* compiler, | |
1267 BranchInstr* branch) { | |
1268 BranchLabels labels = compiler->CreateBranchLabels(branch); | |
1269 Condition true_condition = EmitComparisonCode(compiler, labels); | |
1270 EmitBranchOnCondition(compiler, true_condition, labels); | |
1271 } | |
1272 | |
1273 | |
1274 EMIT_NATIVE_CODE(CheckArrayBound, 2) { | |
1275 const Register length = locs()->in(kLengthPos).reg(); | |
1276 const Register index = locs()->in(kIndexPos).reg(); | |
1277 __ IfULe(length, index); | |
1278 compiler->EmitDeopt(deopt_id(), | |
1279 ICData::kDeoptCheckArrayBound, | |
1280 (generalized_ ? ICData::kGeneralized : 0) | | |
1281 (licm_hoisted_ ? ICData::kHoisted : 0)); | |
1282 } | |
1283 | |
1133 } // namespace dart | 1284 } // namespace dart |
1134 | 1285 |
1135 #endif // defined TARGET_ARCH_DBC | 1286 #endif // defined TARGET_ARCH_DBC |
OLD | NEW |