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" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "vm/verified_memory.h" | 22 #include "vm/verified_memory.h" |
23 | 23 |
24 namespace dart { | 24 namespace dart { |
25 | 25 |
26 DEFINE_FLAG(bool, trap_on_deoptimization, false, "Trap on deoptimization."); | 26 DEFINE_FLAG(bool, trap_on_deoptimization, false, "Trap on deoptimization."); |
27 DEFINE_FLAG(bool, unbox_mints, true, "Optimize 64-bit integer arithmetic."); | 27 DEFINE_FLAG(bool, unbox_mints, true, "Optimize 64-bit integer arithmetic."); |
28 DECLARE_FLAG(bool, enable_simd_inline); | 28 DECLARE_FLAG(bool, enable_simd_inline); |
29 DECLARE_FLAG(bool, use_megamorphic_stub); | 29 DECLARE_FLAG(bool, use_megamorphic_stub); |
30 | 30 |
31 | 31 |
| 32 void MegamorphicSlowPath::EmitNativeCode(FlowGraphCompiler* compiler) { |
| 33 Assembler* assembler = compiler->assembler(); |
| 34 #define __ assembler-> |
| 35 __ Bind(entry_label()); |
| 36 __ Comment("MegamorphicSlowPath"); |
| 37 compiler->EmitMegamorphicInstanceCall(ic_data_, argument_count_, deopt_id_, |
| 38 token_pos_, locs_, try_index_); |
| 39 __ jmp(exit_label()); |
| 40 #undef __ |
| 41 } |
| 42 |
| 43 |
32 FlowGraphCompiler::~FlowGraphCompiler() { | 44 FlowGraphCompiler::~FlowGraphCompiler() { |
33 // BlockInfos are zone-allocated, so their destructors are not called. | 45 // BlockInfos are zone-allocated, so their destructors are not called. |
34 // Verify the labels explicitly here. | 46 // Verify the labels explicitly here. |
35 for (int i = 0; i < block_info_.length(); ++i) { | 47 for (int i = 0; i < block_info_.length(); ++i) { |
36 ASSERT(!block_info_[i]->jump_label()->IsLinked()); | 48 ASSERT(!block_info_[i]->jump_label()->IsLinked()); |
37 ASSERT(!block_info_[i]->jump_label()->HasNear()); | 49 ASSERT(!block_info_[i]->jump_label()->HasNear()); |
38 } | 50 } |
39 } | 51 } |
40 | 52 |
41 | 53 |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 } | 180 } |
169 | 181 |
170 return builder->CreateDeoptInfo(deopt_table); | 182 return builder->CreateDeoptInfo(deopt_table); |
171 } | 183 } |
172 | 184 |
173 | 185 |
174 void CompilerDeoptInfoWithStub::GenerateCode(FlowGraphCompiler* compiler, | 186 void CompilerDeoptInfoWithStub::GenerateCode(FlowGraphCompiler* compiler, |
175 intptr_t stub_ix) { | 187 intptr_t stub_ix) { |
176 // Calls do not need stubs, they share a deoptimization trampoline. | 188 // Calls do not need stubs, they share a deoptimization trampoline. |
177 ASSERT(reason() != ICData::kDeoptAtCall); | 189 ASSERT(reason() != ICData::kDeoptAtCall); |
178 Assembler* assem = compiler->assembler(); | 190 Assembler* assembler = compiler->assembler(); |
179 #define __ assem-> | 191 #define __ assembler-> |
180 __ Comment("%s", Name()); | 192 __ Comment("%s", Name()); |
181 __ Bind(entry_label()); | 193 __ Bind(entry_label()); |
182 if (FLAG_trap_on_deoptimization) { | 194 if (FLAG_trap_on_deoptimization) { |
183 __ int3(); | 195 __ int3(); |
184 } | 196 } |
185 | 197 |
186 ASSERT(deopt_env() != NULL); | 198 ASSERT(deopt_env() != NULL); |
187 | 199 |
188 __ pushq(CODE_REG); | 200 __ pushq(CODE_REG); |
189 __ Call(*StubCode::Deoptimize_entry()); | 201 __ Call(*StubCode::Deoptimize_entry()); |
190 set_pc_offset(assem->CodeSize()); | 202 set_pc_offset(assembler->CodeSize()); |
191 __ int3(); | 203 __ int3(); |
192 #undef __ | 204 #undef __ |
193 } | 205 } |
194 | 206 |
195 | 207 |
196 #define __ assembler()-> | 208 #define __ assembler()-> |
197 | 209 |
198 | 210 |
199 // Fall through if bool_register contains null. | 211 // Fall through if bool_register contains null. |
200 void FlowGraphCompiler::GenerateBoolToJump(Register bool_register, | 212 void FlowGraphCompiler::GenerateBoolToJump(Register bool_register, |
(...skipping 1071 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1272 locs); | 1284 locs); |
1273 __ Drop(argument_count, RCX); | 1285 __ Drop(argument_count, RCX); |
1274 } | 1286 } |
1275 | 1287 |
1276 | 1288 |
1277 void FlowGraphCompiler::EmitMegamorphicInstanceCall( | 1289 void FlowGraphCompiler::EmitMegamorphicInstanceCall( |
1278 const ICData& ic_data, | 1290 const ICData& ic_data, |
1279 intptr_t argument_count, | 1291 intptr_t argument_count, |
1280 intptr_t deopt_id, | 1292 intptr_t deopt_id, |
1281 intptr_t token_pos, | 1293 intptr_t token_pos, |
1282 LocationSummary* locs) { | 1294 LocationSummary* locs, |
| 1295 intptr_t try_index) { |
1283 const String& name = String::Handle(zone(), ic_data.target_name()); | 1296 const String& name = String::Handle(zone(), ic_data.target_name()); |
1284 const Array& arguments_descriptor = | 1297 const Array& arguments_descriptor = |
1285 Array::ZoneHandle(zone(), ic_data.arguments_descriptor()); | 1298 Array::ZoneHandle(zone(), ic_data.arguments_descriptor()); |
1286 ASSERT(!arguments_descriptor.IsNull() && (arguments_descriptor.Length() > 0)); | 1299 ASSERT(!arguments_descriptor.IsNull() && (arguments_descriptor.Length() > 0)); |
1287 const MegamorphicCache& cache = MegamorphicCache::ZoneHandle(zone(), | 1300 const MegamorphicCache& cache = MegamorphicCache::ZoneHandle(zone(), |
1288 MegamorphicCacheTable::Lookup(isolate(), name, arguments_descriptor)); | 1301 MegamorphicCacheTable::Lookup(isolate(), name, arguments_descriptor)); |
1289 | 1302 |
1290 __ Comment("MegamorphicCall"); | 1303 __ Comment("MegamorphicCall"); |
1291 __ movq(RDI, Address(RSP, (argument_count - 1) * kWordSize)); | 1304 __ movq(RDI, Address(RSP, (argument_count - 1) * kWordSize)); |
1292 __ LoadObject(RBX, cache); | 1305 __ LoadObject(RBX, cache); |
1293 if (FLAG_use_megamorphic_stub) { | 1306 if (FLAG_use_megamorphic_stub) { |
1294 __ Call(*StubCode::MegamorphicLookup_entry()); | 1307 __ Call(*StubCode::MegamorphicLookup_entry()); |
1295 } else { | 1308 } else { |
1296 StubCode::EmitMegamorphicLookup(assembler()); | 1309 StubCode::EmitMegamorphicLookup(assembler()); |
1297 } | 1310 } |
1298 __ call(RCX); | 1311 __ call(RCX); |
1299 | 1312 |
1300 AddCurrentDescriptor(RawPcDescriptors::kOther, | |
1301 Thread::kNoDeoptId, token_pos); | |
1302 RecordSafepoint(locs); | 1313 RecordSafepoint(locs); |
1303 const intptr_t deopt_id_after = Thread::ToDeoptAfter(deopt_id); | 1314 const intptr_t deopt_id_after = Thread::ToDeoptAfter(deopt_id); |
1304 if (is_optimizing()) { | 1315 if (Compiler::always_optimize()) { |
| 1316 // Megamorphic calls may occur in slow path stubs. |
| 1317 // If valid use try_index argument. |
| 1318 if (try_index == CatchClauseNode::kInvalidTryIndex) { |
| 1319 try_index = CurrentTryIndex(); |
| 1320 } |
| 1321 pc_descriptors_list()->AddDescriptor(RawPcDescriptors::kOther, |
| 1322 assembler()->CodeSize(), |
| 1323 Thread::kNoDeoptId, |
| 1324 token_pos, |
| 1325 try_index); |
| 1326 } else if (is_optimizing()) { |
| 1327 AddCurrentDescriptor(RawPcDescriptors::kOther, |
| 1328 Thread::kNoDeoptId, token_pos); |
1305 AddDeoptIndexAtCall(deopt_id_after, token_pos); | 1329 AddDeoptIndexAtCall(deopt_id_after, token_pos); |
1306 } else { | 1330 } else { |
| 1331 AddCurrentDescriptor(RawPcDescriptors::kOther, |
| 1332 Thread::kNoDeoptId, token_pos); |
1307 // Add deoptimization continuation point after the call and before the | 1333 // Add deoptimization continuation point after the call and before the |
1308 // arguments are removed. | 1334 // arguments are removed. |
1309 AddCurrentDescriptor(RawPcDescriptors::kDeopt, deopt_id_after, token_pos); | 1335 AddCurrentDescriptor(RawPcDescriptors::kDeopt, deopt_id_after, token_pos); |
1310 } | 1336 } |
1311 __ Drop(argument_count, RCX); | 1337 __ Drop(argument_count, RCX); |
1312 } | 1338 } |
1313 | 1339 |
1314 | 1340 |
1315 void FlowGraphCompiler::EmitSwitchableInstanceCall( | 1341 void FlowGraphCompiler::EmitSwitchableInstanceCall( |
1316 const ICData& ic_data, | 1342 const ICData& ic_data, |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1795 __ movups(reg, Address(RSP, 0)); | 1821 __ movups(reg, Address(RSP, 0)); |
1796 __ AddImmediate(RSP, Immediate(kFpuRegisterSize)); | 1822 __ AddImmediate(RSP, Immediate(kFpuRegisterSize)); |
1797 } | 1823 } |
1798 | 1824 |
1799 | 1825 |
1800 #undef __ | 1826 #undef __ |
1801 | 1827 |
1802 } // namespace dart | 1828 } // namespace dart |
1803 | 1829 |
1804 #endif // defined TARGET_ARCH_X64 | 1830 #endif // defined TARGET_ARCH_X64 |
OLD | NEW |