| OLD | NEW |
| 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 24 matching lines...) Expand all Loading... |
| 35 const intptr_t kNumInputs = 1; | 35 const intptr_t kNumInputs = 1; |
| 36 const intptr_t kNumTemps = 1; | 36 const intptr_t kNumTemps = 1; |
| 37 LocationSummary* locs = | 37 LocationSummary* locs = |
| 38 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kCall); | 38 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kCall); |
| 39 locs->set_in(0, Location::RegisterLocation(RAX)); | 39 locs->set_in(0, Location::RegisterLocation(RAX)); |
| 40 locs->set_temp(0, Location::RegisterLocation(RDX)); | 40 locs->set_temp(0, Location::RegisterLocation(RDX)); |
| 41 return locs; | 41 return locs; |
| 42 } | 42 } |
| 43 | 43 |
| 44 | 44 |
| 45 // Attempt optimized compilation at return instruction instead of at the entry. |
| 46 // The entry needs to be patchable, no inlined objects are allowed in the area |
| 47 // that will be overwritten by the patch instruction: a jump). |
| 45 void ReturnInstr::EmitNativeCode(FlowGraphCompiler* compiler) { | 48 void ReturnInstr::EmitNativeCode(FlowGraphCompiler* compiler) { |
| 49 const Function& function = |
| 50 Function::ZoneHandle(compiler->parsed_function().function().raw()); |
| 46 Register result = locs()->in(0).reg(); | 51 Register result = locs()->in(0).reg(); |
| 47 Register func_reg = locs()->temp(0).reg(); | 52 Register func_reg = locs()->temp(0).reg(); |
| 48 ASSERT(result == RAX); | 53 ASSERT(result == RAX); |
| 49 if (!compiler->is_optimizing()) { | 54 if (compiler->is_optimizing()) { |
| 55 if (compiler->may_reoptimize()) { |
| 56 // Increment of counter occurs only in optimized IC calls, as they |
| 57 // can cause reoptimization. |
| 58 Label done; |
| 59 __ LoadObject(func_reg, function); |
| 60 __ cmpq(FieldAddress(func_reg, Function::usage_counter_offset()), |
| 61 Immediate(FLAG_optimization_counter_threshold)); |
| 62 __ j(LESS, &done, Assembler::kNearJump); |
| 63 // Equal (or greater), optimize. Note that counter can reach equality |
| 64 // only at return instruction. |
| 65 // The stub call preserves result register (EAX). |
| 66 ASSERT(func_reg == RDX); |
| 67 compiler->GenerateCall(0, // no token position. |
| 68 &StubCode::OptimizeFunctionLabel(), |
| 69 PcDescriptors::kOther, |
| 70 locs()); |
| 71 __ Bind(&done); |
| 72 } |
| 73 } else { |
| 50 __ Comment("Check function counter"); | 74 __ Comment("Check function counter"); |
| 51 // Count only in unoptimized code. | 75 // Count only in unoptimized code. |
| 52 // TODO(srdjan): Replace the counting code with a type feedback | 76 // TODO(srdjan): Replace the counting code with a type feedback |
| 53 // collection and counting stub. | 77 // collection and counting stub. |
| 54 const Function& function = | |
| 55 Function::ZoneHandle(compiler->parsed_function().function().raw()); | |
| 56 __ LoadObject(func_reg, function); | 78 __ LoadObject(func_reg, function); |
| 57 __ incq(FieldAddress(func_reg, Function::usage_counter_offset())); | 79 __ incq(FieldAddress(func_reg, Function::usage_counter_offset())); |
| 58 if (FlowGraphCompiler::CanOptimize() && | 80 if (FlowGraphCompiler::CanOptimize() && |
| 59 compiler->parsed_function().function().is_optimizable()) { | 81 compiler->parsed_function().function().is_optimizable()) { |
| 60 // Do not optimize if usage count must be reported. | 82 // Do not optimize if usage count must be reported. |
| 61 __ cmpq(FieldAddress(func_reg, Function::usage_counter_offset()), | 83 __ cmpq(FieldAddress(func_reg, Function::usage_counter_offset()), |
| 62 Immediate(FLAG_optimization_counter_threshold)); | 84 Immediate(FLAG_optimization_counter_threshold)); |
| 63 Label not_yet_hot; | 85 Label not_yet_hot; |
| 64 __ j(LESS, ¬_yet_hot, Assembler::kNearJump); | 86 __ j(LESS, ¬_yet_hot, Assembler::kNearJump); |
| 65 // Equal (or greater), optimize. | 87 // Equal (or greater), optimize. |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 Immediate(reinterpret_cast<intptr_t>(Object::null())); | 363 Immediate(reinterpret_cast<intptr_t>(Object::null())); |
| 342 Label check_identity; | 364 Label check_identity; |
| 343 __ cmpq(Address(RSP, 0 * kWordSize), raw_null); | 365 __ cmpq(Address(RSP, 0 * kWordSize), raw_null); |
| 344 __ j(EQUAL, &check_identity, Assembler::kNearJump); | 366 __ j(EQUAL, &check_identity, Assembler::kNearJump); |
| 345 __ cmpq(Address(RSP, 1 * kWordSize), raw_null); | 367 __ cmpq(Address(RSP, 1 * kWordSize), raw_null); |
| 346 __ j(EQUAL, &check_identity, Assembler::kNearJump); | 368 __ j(EQUAL, &check_identity, Assembler::kNearJump); |
| 347 | 369 |
| 348 ICData& equality_ic_data = ICData::ZoneHandle(original_ic_data.raw()); | 370 ICData& equality_ic_data = ICData::ZoneHandle(original_ic_data.raw()); |
| 349 if (compiler->is_optimizing() && FLAG_propagate_ic_data) { | 371 if (compiler->is_optimizing() && FLAG_propagate_ic_data) { |
| 350 ASSERT(!original_ic_data.IsNull()); | 372 ASSERT(!original_ic_data.IsNull()); |
| 351 equality_ic_data = original_ic_data.AsUnaryClassChecks(); | 373 if (original_ic_data.NumberOfChecks() == 0) { |
| 374 // IC call for reoptimization populates original ICData. |
| 375 equality_ic_data = original_ic_data.raw(); |
| 376 } else { |
| 377 // Megamorphic call. |
| 378 equality_ic_data = original_ic_data.AsUnaryClassChecks(); |
| 379 } |
| 352 } else { | 380 } else { |
| 353 equality_ic_data = ICData::New(compiler->parsed_function().function(), | 381 equality_ic_data = ICData::New(compiler->parsed_function().function(), |
| 354 operator_name, | 382 operator_name, |
| 355 deopt_id, | 383 deopt_id, |
| 356 kNumArgumentsChecked); | 384 kNumArgumentsChecked); |
| 357 } | 385 } |
| 358 compiler->GenerateInstanceCall(deopt_id, | 386 compiler->GenerateInstanceCall(deopt_id, |
| 359 token_pos, | 387 token_pos, |
| 360 kNumberOfArguments, | 388 kNumberOfArguments, |
| 361 kNoArgumentNames, | 389 kNoArgumentNames, |
| (...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 832 if (!compiler->is_optimizing()) { | 860 if (!compiler->is_optimizing()) { |
| 833 compiler->AddCurrentDescriptor(PcDescriptors::kDeoptBefore, | 861 compiler->AddCurrentDescriptor(PcDescriptors::kDeoptBefore, |
| 834 deopt_id(), | 862 deopt_id(), |
| 835 token_pos()); | 863 token_pos()); |
| 836 } | 864 } |
| 837 const intptr_t kNumArguments = 2; | 865 const intptr_t kNumArguments = 2; |
| 838 const intptr_t kNumArgsChecked = 2; // Type-feedback. | 866 const intptr_t kNumArgsChecked = 2; // Type-feedback. |
| 839 ICData& relational_ic_data = ICData::ZoneHandle(ic_data()->raw()); | 867 ICData& relational_ic_data = ICData::ZoneHandle(ic_data()->raw()); |
| 840 if (compiler->is_optimizing() && FLAG_propagate_ic_data) { | 868 if (compiler->is_optimizing() && FLAG_propagate_ic_data) { |
| 841 ASSERT(!ic_data()->IsNull()); | 869 ASSERT(!ic_data()->IsNull()); |
| 842 relational_ic_data = ic_data()->AsUnaryClassChecks(); | 870 if (ic_data()->NumberOfChecks() == 0) { |
| 871 // IC call for reoptimization populates original ICData. |
| 872 relational_ic_data = ic_data()->raw(); |
| 873 } else { |
| 874 // Megamorphic call. |
| 875 relational_ic_data = ic_data()->AsUnaryClassChecks(); |
| 876 } |
| 843 } else { | 877 } else { |
| 844 relational_ic_data = ICData::New(compiler->parsed_function().function(), | 878 relational_ic_data = ICData::New(compiler->parsed_function().function(), |
| 845 function_name, | 879 function_name, |
| 846 deopt_id(), | 880 deopt_id(), |
| 847 kNumArgsChecked); | 881 kNumArgsChecked); |
| 848 } | 882 } |
| 849 compiler->GenerateInstanceCall(deopt_id(), | 883 compiler->GenerateInstanceCall(deopt_id(), |
| 850 token_pos(), | 884 token_pos(), |
| 851 kNumArguments, | 885 kNumArguments, |
| 852 Array::ZoneHandle(), // No optional arguments. | 886 Array::ZoneHandle(), // No optional arguments. |
| (...skipping 1480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2333 | 2367 |
| 2334 void ShiftMintOpInstr::EmitNativeCode(FlowGraphCompiler* compiler) { | 2368 void ShiftMintOpInstr::EmitNativeCode(FlowGraphCompiler* compiler) { |
| 2335 UNIMPLEMENTED(); | 2369 UNIMPLEMENTED(); |
| 2336 } | 2370 } |
| 2337 | 2371 |
| 2338 } // namespace dart | 2372 } // namespace dart |
| 2339 | 2373 |
| 2340 #undef __ | 2374 #undef __ |
| 2341 | 2375 |
| 2342 #endif // defined TARGET_ARCH_X64 | 2376 #endif // defined TARGET_ARCH_X64 |
| OLD | NEW |