| 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_IA32. | 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_IA32. |
| 6 #if defined(TARGET_ARCH_IA32) | 6 #if defined(TARGET_ARCH_IA32) |
| 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/code_patcher.h" | 11 #include "vm/code_patcher.h" |
| 12 #include "vm/compiler.h" | 12 #include "vm/compiler.h" |
| 13 #include "vm/cpu.h" | 13 #include "vm/cpu.h" |
| 14 #include "vm/dart_entry.h" | 14 #include "vm/dart_entry.h" |
| 15 #include "vm/deopt_instructions.h" | 15 #include "vm/deopt_instructions.h" |
| 16 #include "vm/flow_graph_builder.h" | 16 #include "vm/flow_graph_builder.h" |
| 17 #include "vm/il_printer.h" | 17 #include "vm/il_printer.h" |
| 18 #include "vm/locations.h" | 18 #include "vm/locations.h" |
| 19 #include "vm/object_store.h" | 19 #include "vm/object_store.h" |
| 20 #include "vm/parser.h" | 20 #include "vm/parser.h" |
| 21 #include "vm/stack_frame.h" | 21 #include "vm/stack_frame.h" |
| 22 #include "vm/stub_code.h" | 22 #include "vm/stub_code.h" |
| 23 #include "vm/symbols.h" | 23 #include "vm/symbols.h" |
| 24 #include "vm/verified_memory.h" | 24 #include "vm/verified_memory.h" |
| 25 | 25 |
| 26 namespace dart { | 26 namespace dart { |
| 27 | 27 |
| 28 DEFINE_FLAG(bool, trap_on_deoptimization, false, "Trap on deoptimization."); | 28 DEFINE_FLAG(bool, trap_on_deoptimization, false, "Trap on deoptimization."); |
| 29 DEFINE_FLAG(bool, unbox_mints, true, "Optimize 64-bit integer arithmetic."); | 29 DEFINE_FLAG(bool, unbox_mints, true, "Optimize 64-bit integer arithmetic."); |
| 30 |
| 30 DECLARE_FLAG(bool, enable_type_checks); | 31 DECLARE_FLAG(bool, enable_type_checks); |
| 31 DECLARE_FLAG(bool, enable_simd_inline); | 32 DECLARE_FLAG(bool, enable_simd_inline); |
| 33 DECLARE_FLAG(bool, use_megamorphic_stub); |
| 32 | 34 |
| 33 | 35 |
| 34 FlowGraphCompiler::~FlowGraphCompiler() { | 36 FlowGraphCompiler::~FlowGraphCompiler() { |
| 35 // BlockInfos are zone-allocated, so their destructors are not called. | 37 // BlockInfos are zone-allocated, so their destructors are not called. |
| 36 // Verify the labels explicitly here. | 38 // Verify the labels explicitly here. |
| 37 for (int i = 0; i < block_info_.length(); ++i) { | 39 for (int i = 0; i < block_info_.length(); ++i) { |
| 38 ASSERT(!block_info_[i]->jump_label()->IsLinked()); | 40 ASSERT(!block_info_[i]->jump_label()->IsLinked()); |
| 39 ASSERT(!block_info_[i]->jump_label()->HasNear()); | 41 ASSERT(!block_info_[i]->jump_label()->HasNear()); |
| 40 } | 42 } |
| 41 } | 43 } |
| (...skipping 1254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1296 __ Drop(argument_count); | 1298 __ Drop(argument_count); |
| 1297 } | 1299 } |
| 1298 | 1300 |
| 1299 | 1301 |
| 1300 void FlowGraphCompiler::EmitMegamorphicInstanceCall( | 1302 void FlowGraphCompiler::EmitMegamorphicInstanceCall( |
| 1301 const ICData& ic_data, | 1303 const ICData& ic_data, |
| 1302 intptr_t argument_count, | 1304 intptr_t argument_count, |
| 1303 intptr_t deopt_id, | 1305 intptr_t deopt_id, |
| 1304 intptr_t token_pos, | 1306 intptr_t token_pos, |
| 1305 LocationSummary* locs) { | 1307 LocationSummary* locs) { |
| 1306 MegamorphicCacheTable* table = Isolate::Current()->megamorphic_cache_table(); | 1308 MegamorphicCacheTable* table = isolate()->megamorphic_cache_table(); |
| 1307 const String& name = String::Handle(ic_data.target_name()); | 1309 const String& name = String::Handle(ic_data.target_name()); |
| 1308 const Array& arguments_descriptor = | 1310 const Array& arguments_descriptor = |
| 1309 Array::ZoneHandle(ic_data.arguments_descriptor()); | 1311 Array::ZoneHandle(ic_data.arguments_descriptor()); |
| 1310 ASSERT(!arguments_descriptor.IsNull() && (arguments_descriptor.Length() > 0)); | 1312 ASSERT(!arguments_descriptor.IsNull() && (arguments_descriptor.Length() > 0)); |
| 1311 const MegamorphicCache& cache = | 1313 const MegamorphicCache& cache = |
| 1312 MegamorphicCache::ZoneHandle(table->Lookup(name, arguments_descriptor)); | 1314 MegamorphicCache::ZoneHandle(table->Lookup(name, arguments_descriptor)); |
| 1313 Label load_cache; | 1315 __ movl(EDI, Address(ESP, (argument_count - 1) * kWordSize)); |
| 1314 __ movl(EBX, Address(ESP, (argument_count - 1) * kWordSize)); | 1316 __ LoadObject(EBX, cache); |
| 1315 __ LoadTaggedClassIdMayBeSmi(EAX, EBX); | |
| 1316 | 1317 |
| 1317 // EAX: class ID of the receiver (smi). | 1318 if (FLAG_use_megamorphic_stub) { |
| 1318 __ Bind(&load_cache); | 1319 StubCode* stub_code = isolate()->stub_code(); |
| 1319 __ LoadObject(EBX, cache); | 1320 __ call(&stub_code->MegamorphicLookupLabel()); |
| 1320 __ movl(EDI, FieldAddress(EBX, MegamorphicCache::buckets_offset())); | 1321 } else { |
| 1321 __ movl(EBX, FieldAddress(EBX, MegamorphicCache::mask_offset())); | 1322 __ LoadTaggedClassIdMayBeSmi(EAX, EDI); |
| 1322 // EDI: cache buckets array. | |
| 1323 // EBX: mask. | |
| 1324 __ movl(ECX, EAX); | |
| 1325 | 1323 |
| 1326 Label loop, update, call_target_function; | 1324 // EAX: class ID of the receiver (smi). |
| 1327 __ jmp(&loop); | 1325 __ movl(EDI, FieldAddress(EBX, MegamorphicCache::buckets_offset())); |
| 1326 __ movl(EBX, FieldAddress(EBX, MegamorphicCache::mask_offset())); |
| 1327 // EDI: cache buckets array. |
| 1328 // EBX: mask. |
| 1329 __ movl(ECX, EAX); |
| 1328 | 1330 |
| 1329 __ Bind(&update); | 1331 Label loop, update, call_target_function; |
| 1330 __ addl(ECX, Immediate(Smi::RawValue(1))); | 1332 __ jmp(&loop); |
| 1331 __ Bind(&loop); | |
| 1332 __ andl(ECX, EBX); | |
| 1333 const intptr_t base = Array::data_offset(); | |
| 1334 // ECX is smi tagged, but table entries are two words, so TIMES_4. | |
| 1335 __ movl(EDX, FieldAddress(EDI, ECX, TIMES_4, base)); | |
| 1336 | 1333 |
| 1337 ASSERT(kIllegalCid == 0); | 1334 __ Bind(&update); |
| 1338 __ testl(EDX, EDX); | 1335 __ addl(ECX, Immediate(Smi::RawValue(1))); |
| 1339 __ j(ZERO, &call_target_function, Assembler::kNearJump); | 1336 __ Bind(&loop); |
| 1340 __ cmpl(EDX, EAX); | 1337 __ andl(ECX, EBX); |
| 1341 __ j(NOT_EQUAL, &update, Assembler::kNearJump); | 1338 const intptr_t base = Array::data_offset(); |
| 1339 // ECX is smi tagged, but table entries are two words, so TIMES_4. |
| 1340 __ movl(EDX, FieldAddress(EDI, ECX, TIMES_4, base)); |
| 1342 | 1341 |
| 1343 __ Bind(&call_target_function); | 1342 ASSERT(kIllegalCid == 0); |
| 1344 // Call the target found in the cache. For a class id match, this is a | 1343 __ testl(EDX, EDX); |
| 1345 // proper target for the given name and arguments descriptor. If the | 1344 __ j(ZERO, &call_target_function, Assembler::kNearJump); |
| 1346 // illegal class id was found, the target is a cache miss handler that can | 1345 __ cmpl(EDX, EAX); |
| 1347 // be invoked as a normal Dart function. | 1346 __ j(NOT_EQUAL, &update, Assembler::kNearJump); |
| 1348 __ movl(EAX, FieldAddress(EDI, ECX, TIMES_4, base + kWordSize)); | 1347 |
| 1349 __ movl(EBX, FieldAddress(EAX, Function::instructions_offset())); | 1348 __ Bind(&call_target_function); |
| 1349 // Call the target found in the cache. For a class id match, this is a |
| 1350 // proper target for the given name and arguments descriptor. If the |
| 1351 // illegal class id was found, the target is a cache miss handler that can |
| 1352 // be invoked as a normal Dart function. |
| 1353 __ movl(EAX, FieldAddress(EDI, ECX, TIMES_4, base + kWordSize)); |
| 1354 __ movl(EBX, FieldAddress(EAX, Function::instructions_offset())); |
| 1355 __ addl(EBX, Immediate(Instructions::HeaderSize() - kHeapObjectTag)); |
| 1356 } |
| 1357 |
| 1350 __ LoadObject(ECX, ic_data); | 1358 __ LoadObject(ECX, ic_data); |
| 1351 __ LoadObject(EDX, arguments_descriptor); | 1359 __ LoadObject(EDX, arguments_descriptor); |
| 1352 __ addl(EBX, Immediate(Instructions::HeaderSize() - kHeapObjectTag)); | |
| 1353 __ call(EBX); | 1360 __ call(EBX); |
| 1354 AddCurrentDescriptor(RawPcDescriptors::kOther, | 1361 AddCurrentDescriptor(RawPcDescriptors::kOther, |
| 1355 Isolate::kNoDeoptId, token_pos); | 1362 Isolate::kNoDeoptId, token_pos); |
| 1356 RecordSafepoint(locs); | 1363 RecordSafepoint(locs); |
| 1357 const intptr_t deopt_id_after = Isolate::ToDeoptAfter(deopt_id); | 1364 const intptr_t deopt_id_after = Isolate::ToDeoptAfter(deopt_id); |
| 1358 if (is_optimizing()) { | 1365 if (is_optimizing()) { |
| 1359 AddDeoptIndexAtCall(deopt_id_after, token_pos); | 1366 AddDeoptIndexAtCall(deopt_id_after, token_pos); |
| 1360 } else { | 1367 } else { |
| 1361 // Add deoptimization continuation point after the call and before the | 1368 // Add deoptimization continuation point after the call and before the |
| 1362 // arguments are removed. | 1369 // arguments are removed. |
| (...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1842 __ movups(reg, Address(ESP, 0)); | 1849 __ movups(reg, Address(ESP, 0)); |
| 1843 __ addl(ESP, Immediate(kFpuRegisterSize)); | 1850 __ addl(ESP, Immediate(kFpuRegisterSize)); |
| 1844 } | 1851 } |
| 1845 | 1852 |
| 1846 | 1853 |
| 1847 #undef __ | 1854 #undef __ |
| 1848 | 1855 |
| 1849 } // namespace dart | 1856 } // namespace dart |
| 1850 | 1857 |
| 1851 #endif // defined TARGET_ARCH_IA32 | 1858 #endif // defined TARGET_ARCH_IA32 |
| OLD | NEW |