| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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/flow_graph_compiler.h" | 8 #include "vm/flow_graph_compiler.h" |
| 9 | 9 |
| 10 #include "vm/ast_printer.h" | 10 #include "vm/ast_printer.h" |
| 11 #include "vm/compiler.h" | 11 #include "vm/compiler.h" |
| 12 #include "vm/dart_entry.h" | 12 #include "vm/dart_entry.h" |
| 13 #include "vm/deopt_instructions.h" | 13 #include "vm/deopt_instructions.h" |
| 14 #include "vm/il_printer.h" | 14 #include "vm/il_printer.h" |
| 15 #include "vm/locations.h" | 15 #include "vm/locations.h" |
| 16 #include "vm/object_store.h" | 16 #include "vm/object_store.h" |
| 17 #include "vm/parser.h" | 17 #include "vm/parser.h" |
| 18 #include "vm/stack_frame.h" | 18 #include "vm/stack_frame.h" |
| 19 #include "vm/stub_code.h" | 19 #include "vm/stub_code.h" |
| 20 #include "vm/symbols.h" | 20 #include "vm/symbols.h" |
| 21 #include "vm/verified_memory.h" | 21 #include "vm/verified_memory.h" |
| 22 | 22 |
| 23 namespace dart { | 23 namespace dart { |
| 24 | 24 |
| 25 DEFINE_FLAG(bool, trap_on_deoptimization, false, "Trap on deoptimization."); | 25 DEFINE_FLAG(bool, trap_on_deoptimization, false, "Trap on deoptimization."); |
| 26 DEFINE_FLAG(bool, unbox_mints, true, "Optimize 64-bit integer arithmetic."); | 26 DEFINE_FLAG(bool, unbox_mints, true, "Optimize 64-bit integer arithmetic."); |
| 27 DECLARE_FLAG(bool, enable_type_checks); | 27 DECLARE_FLAG(bool, enable_type_checks); |
| 28 DECLARE_FLAG(bool, enable_simd_inline); | 28 DECLARE_FLAG(bool, enable_simd_inline); |
| 29 DECLARE_FLAG(bool, use_megamorphic_stub); |
| 29 | 30 |
| 30 | 31 |
| 31 FlowGraphCompiler::~FlowGraphCompiler() { | 32 FlowGraphCompiler::~FlowGraphCompiler() { |
| 32 // BlockInfos are zone-allocated, so their destructors are not called. | 33 // BlockInfos are zone-allocated, so their destructors are not called. |
| 33 // Verify the labels explicitly here. | 34 // Verify the labels explicitly here. |
| 34 for (int i = 0; i < block_info_.length(); ++i) { | 35 for (int i = 0; i < block_info_.length(); ++i) { |
| 35 ASSERT(!block_info_[i]->jump_label()->IsLinked()); | 36 ASSERT(!block_info_[i]->jump_label()->IsLinked()); |
| 36 ASSERT(!block_info_[i]->jump_label()->HasNear()); | 37 ASSERT(!block_info_[i]->jump_label()->HasNear()); |
| 37 } | 38 } |
| 38 } | 39 } |
| (...skipping 1265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1304 __ Drop(argument_count, RCX); | 1305 __ Drop(argument_count, RCX); |
| 1305 } | 1306 } |
| 1306 | 1307 |
| 1307 | 1308 |
| 1308 void FlowGraphCompiler::EmitMegamorphicInstanceCall( | 1309 void FlowGraphCompiler::EmitMegamorphicInstanceCall( |
| 1309 const ICData& ic_data, | 1310 const ICData& ic_data, |
| 1310 intptr_t argument_count, | 1311 intptr_t argument_count, |
| 1311 intptr_t deopt_id, | 1312 intptr_t deopt_id, |
| 1312 intptr_t token_pos, | 1313 intptr_t token_pos, |
| 1313 LocationSummary* locs) { | 1314 LocationSummary* locs) { |
| 1314 MegamorphicCacheTable* table = Isolate::Current()->megamorphic_cache_table(); | 1315 MegamorphicCacheTable* table = isolate()->megamorphic_cache_table(); |
| 1315 const String& name = String::Handle(ic_data.target_name()); | 1316 const String& name = String::Handle(ic_data.target_name()); |
| 1316 const Array& arguments_descriptor = | 1317 const Array& arguments_descriptor = |
| 1317 Array::ZoneHandle(ic_data.arguments_descriptor()); | 1318 Array::ZoneHandle(ic_data.arguments_descriptor()); |
| 1318 ASSERT(!arguments_descriptor.IsNull() && (arguments_descriptor.Length() > 0)); | 1319 ASSERT(!arguments_descriptor.IsNull() && (arguments_descriptor.Length() > 0)); |
| 1319 const MegamorphicCache& cache = | 1320 const MegamorphicCache& cache = |
| 1320 MegamorphicCache::ZoneHandle(table->Lookup(name, arguments_descriptor)); | 1321 MegamorphicCache::ZoneHandle(table->Lookup(name, arguments_descriptor)); |
| 1321 __ movq(RBX, Address(RSP, (argument_count - 1) * kWordSize)); | 1322 __ movq(RDI, Address(RSP, (argument_count - 1) * kWordSize)); |
| 1322 __ LoadTaggedClassIdMayBeSmi(RAX, RBX); | 1323 __ LoadObject(RBX, cache, PP); |
| 1323 | 1324 |
| 1324 // RAX: class ID of the receiver (smi). | 1325 if (FLAG_use_megamorphic_stub) { |
| 1325 __ LoadObject(RBX, cache, PP); | 1326 StubCode* stub_code = isolate()->stub_code(); |
| 1326 __ movq(RDI, FieldAddress(RBX, MegamorphicCache::buckets_offset())); | 1327 __ call(&stub_code->MegamorphicLookupLabel()); |
| 1327 __ movq(RBX, FieldAddress(RBX, MegamorphicCache::mask_offset())); | 1328 } else { |
| 1328 // RDI: cache buckets array. | 1329 __ LoadTaggedClassIdMayBeSmi(RAX, RDI); |
| 1329 // RBX: mask. | |
| 1330 __ movq(RCX, RAX); | |
| 1331 | 1330 |
| 1332 Label loop, update, call_target_function; | 1331 // RAX: class ID of the receiver (smi). |
| 1333 __ jmp(&loop); | 1332 __ movq(RDI, FieldAddress(RBX, MegamorphicCache::buckets_offset())); |
| 1333 __ movq(RBX, FieldAddress(RBX, MegamorphicCache::mask_offset())); |
| 1334 // RDI: cache buckets array. |
| 1335 // RBX: mask. |
| 1336 __ movq(RCX, RAX); |
| 1334 | 1337 |
| 1335 __ Bind(&update); | 1338 Label loop, update, call_target_function; |
| 1336 __ AddImmediate(RCX, Immediate(Smi::RawValue(1)), PP); | 1339 __ jmp(&loop); |
| 1337 __ Bind(&loop); | |
| 1338 __ andq(RCX, RBX); | |
| 1339 const intptr_t base = Array::data_offset(); | |
| 1340 // RCX is smi tagged, but table entries are two words, so TIMES_8. | |
| 1341 __ movq(RDX, FieldAddress(RDI, RCX, TIMES_8, base)); | |
| 1342 | 1340 |
| 1343 ASSERT(kIllegalCid == 0); | 1341 __ Bind(&update); |
| 1344 __ testq(RDX, RDX); | 1342 __ AddImmediate(RCX, Immediate(Smi::RawValue(1)), PP); |
| 1345 __ j(ZERO, &call_target_function, Assembler::kNearJump); | 1343 __ Bind(&loop); |
| 1346 __ cmpq(RDX, RAX); | 1344 __ andq(RCX, RBX); |
| 1347 __ j(NOT_EQUAL, &update, Assembler::kNearJump); | 1345 const intptr_t base = Array::data_offset(); |
| 1346 // RCX is smi tagged, but table entries are two words, so TIMES_8. |
| 1347 __ movq(RDX, FieldAddress(RDI, RCX, TIMES_8, base)); |
| 1348 | 1348 |
| 1349 __ Bind(&call_target_function); | 1349 ASSERT(kIllegalCid == 0); |
| 1350 // Call the target found in the cache. For a class id match, this is a | 1350 __ testq(RDX, RDX); |
| 1351 // proper target for the given name and arguments descriptor. If the | 1351 __ j(ZERO, &call_target_function, Assembler::kNearJump); |
| 1352 // illegal class id was found, the target is a cache miss handler that can | 1352 __ cmpq(RDX, RAX); |
| 1353 // be invoked as a normal Dart function. | 1353 __ j(NOT_EQUAL, &update, Assembler::kNearJump); |
| 1354 __ movq(RAX, FieldAddress(RDI, RCX, TIMES_8, base + kWordSize)); | 1354 |
| 1355 __ movq(RCX, FieldAddress(RAX, Function::instructions_offset())); | 1355 __ Bind(&call_target_function); |
| 1356 // Call the target found in the cache. For a class id match, this is a |
| 1357 // proper target for the given name and arguments descriptor. If the |
| 1358 // illegal class id was found, the target is a cache miss handler that can |
| 1359 // be invoked as a normal Dart function. |
| 1360 __ movq(RAX, FieldAddress(RDI, RCX, TIMES_8, base + kWordSize)); |
| 1361 __ movq(RCX, FieldAddress(RAX, Function::instructions_offset())); |
| 1362 __ AddImmediate( |
| 1363 RCX, Immediate(Instructions::HeaderSize() - kHeapObjectTag), PP); |
| 1364 } |
| 1356 __ LoadObject(RBX, ic_data, PP); | 1365 __ LoadObject(RBX, ic_data, PP); |
| 1357 __ LoadObject(R10, arguments_descriptor, PP); | 1366 __ LoadObject(R10, arguments_descriptor, PP); |
| 1358 __ AddImmediate( | |
| 1359 RCX, Immediate(Instructions::HeaderSize() - kHeapObjectTag), PP); | |
| 1360 __ call(RCX); | 1367 __ call(RCX); |
| 1361 AddCurrentDescriptor(RawPcDescriptors::kOther, | 1368 AddCurrentDescriptor(RawPcDescriptors::kOther, |
| 1362 Isolate::kNoDeoptId, token_pos); | 1369 Isolate::kNoDeoptId, token_pos); |
| 1363 RecordSafepoint(locs); | 1370 RecordSafepoint(locs); |
| 1364 const intptr_t deopt_id_after = Isolate::ToDeoptAfter(deopt_id); | 1371 const intptr_t deopt_id_after = Isolate::ToDeoptAfter(deopt_id); |
| 1365 if (is_optimizing()) { | 1372 if (is_optimizing()) { |
| 1366 AddDeoptIndexAtCall(deopt_id_after, token_pos); | 1373 AddDeoptIndexAtCall(deopt_id_after, token_pos); |
| 1367 } else { | 1374 } else { |
| 1368 // Add deoptimization continuation point after the call and before the | 1375 // Add deoptimization continuation point after the call and before the |
| 1369 // arguments are removed. | 1376 // arguments are removed. |
| (...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1776 __ movups(reg, Address(RSP, 0)); | 1783 __ movups(reg, Address(RSP, 0)); |
| 1777 __ AddImmediate(RSP, Immediate(kFpuRegisterSize), PP); | 1784 __ AddImmediate(RSP, Immediate(kFpuRegisterSize), PP); |
| 1778 } | 1785 } |
| 1779 | 1786 |
| 1780 | 1787 |
| 1781 #undef __ | 1788 #undef __ |
| 1782 | 1789 |
| 1783 } // namespace dart | 1790 } // namespace dart |
| 1784 | 1791 |
| 1785 #endif // defined TARGET_ARCH_X64 | 1792 #endif // defined TARGET_ARCH_X64 |
| OLD | NEW |