Chromium Code Reviews| 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_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/intermediate_language.h" | 8 #include "vm/intermediate_language.h" |
| 9 | 9 |
| 10 #include "lib/error.h" | 10 #include "lib/error.h" |
| 11 #include "vm/flow_graph_compiler.h" | 11 #include "vm/flow_graph_compiler.h" |
| 12 #include "vm/locations.h" | 12 #include "vm/locations.h" |
| 13 #include "vm/object_store.h" | 13 #include "vm/object_store.h" |
| 14 #include "vm/parser.h" | 14 #include "vm/parser.h" |
| 15 #include "vm/stub_code.h" | 15 #include "vm/stub_code.h" |
| 16 #include "vm/symbols.h" | 16 #include "vm/symbols.h" |
| 17 | 17 |
| 18 #define __ compiler->assembler()-> | 18 #define __ compiler->assembler()-> |
| 19 | 19 |
| 20 namespace dart { | 20 namespace dart { |
| 21 | 21 |
| 22 DECLARE_FLAG(int, optimization_counter_threshold); | 22 DECLARE_FLAG(int, optimization_counter_threshold); |
| 23 DECLARE_FLAG(bool, trace_functions); | |
| 24 DECLARE_FLAG(bool, propagate_ic_data); | 23 DECLARE_FLAG(bool, propagate_ic_data); |
| 25 | 24 |
| 26 // Generic summary for call instructions that have all arguments pushed | 25 // Generic summary for call instructions that have all arguments pushed |
| 27 // on the stack and return the result in a fixed register EAX. | 26 // on the stack and return the result in a fixed register EAX. |
| 28 LocationSummary* Instruction::MakeCallSummary() { | 27 LocationSummary* Instruction::MakeCallSummary() { |
| 29 LocationSummary* result = new LocationSummary(0, 0, LocationSummary::kCall); | 28 LocationSummary* result = new LocationSummary(0, 0, LocationSummary::kCall); |
| 30 result->set_out(Location::RegisterLocation(EAX)); | 29 result->set_out(Location::RegisterLocation(EAX)); |
| 31 return result; | 30 return result; |
| 32 } | 31 } |
| 33 | 32 |
| 34 | 33 |
| 35 LocationSummary* ReturnInstr::MakeLocationSummary() const { | 34 LocationSummary* ReturnInstr::MakeLocationSummary() const { |
| 36 const intptr_t kNumInputs = 1; | 35 const intptr_t kNumInputs = 1; |
| 37 const intptr_t kNumTemps = 1; | 36 const intptr_t kNumTemps = 1; |
| 38 LocationSummary* locs = | 37 LocationSummary* locs = |
| 39 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kNoCall); | 38 new LocationSummary(kNumInputs, kNumTemps, LocationSummary::kCall); |
|
Florian Schneider
2012/11/09 20:41:35
Make sure that marking this as kCall does not caus
srdjan
2012/11/09 20:54:31
Discussed off-line: nothing should survice a retur
| |
| 40 locs->set_in(0, Location::RegisterLocation(EAX)); | 39 locs->set_in(0, Location::RegisterLocation(EAX)); |
| 41 locs->set_temp(0, Location::RequiresRegister()); | 40 locs->set_temp(0, Location::RegisterLocation(EDX)); |
| 42 return locs; | 41 return locs; |
| 43 } | 42 } |
| 44 | 43 |
| 45 | 44 |
| 46 void ReturnInstr::EmitNativeCode(FlowGraphCompiler* compiler) { | 45 void ReturnInstr::EmitNativeCode(FlowGraphCompiler* compiler) { |
| 47 Register result = locs()->in(0).reg(); | 46 Register result = locs()->in(0).reg(); |
| 48 Register temp = locs()->temp(0).reg(); | 47 Register func_reg = locs()->temp(0).reg(); |
| 49 ASSERT(result == EAX); | 48 ASSERT(result == EAX); |
| 50 if (!compiler->is_optimizing()) { | 49 if (!compiler->is_optimizing()) { |
| 51 // Count only in unoptimized code. | 50 // Count only in unoptimized code. |
| 52 // TODO(srdjan): Replace the counting code with a type feedback | 51 // TODO(srdjan): Replace the counting code with a type feedback |
| 53 // collection and counting stub. | 52 // collection and counting stub. |
| 54 const Function& function = | 53 const Function& function = |
| 55 Function::ZoneHandle(compiler->parsed_function().function().raw()); | 54 Function::ZoneHandle(compiler->parsed_function().function().raw()); |
| 56 __ LoadObject(temp, function); | 55 __ LoadObject(func_reg, function); |
| 57 __ incl(FieldAddress(temp, Function::usage_counter_offset())); | 56 __ incl(FieldAddress(func_reg, Function::usage_counter_offset())); |
| 58 if (FlowGraphCompiler::CanOptimize() && | 57 if (FlowGraphCompiler::CanOptimize() && |
| 59 compiler->parsed_function().function().is_optimizable()) { | 58 compiler->parsed_function().function().is_optimizable()) { |
| 60 // Do not optimize if usage count must be reported. | 59 // Do not optimize if usage count must be reported. |
| 61 __ cmpl(FieldAddress(temp, Function::usage_counter_offset()), | 60 __ cmpl(FieldAddress(func_reg, Function::usage_counter_offset()), |
| 62 Immediate(FLAG_optimization_counter_threshold)); | 61 Immediate(FLAG_optimization_counter_threshold)); |
| 63 Label not_yet_hot; | 62 Label not_yet_hot; |
| 64 __ j(LESS, ¬_yet_hot, Assembler::kNearJump); | 63 __ j(LESS, ¬_yet_hot, Assembler::kNearJump); |
| 65 __ pushl(result); // Preserve result. | 64 // Equal (or greater), optimize. |
| 66 __ pushl(temp); // Argument for runtime: function to optimize. | 65 // The stub call preserves result register (EAX). |
| 67 __ CallRuntime(kOptimizeInvokedFunctionRuntimeEntry); | 66 ASSERT(func_reg == EDX); |
| 68 __ popl(temp); // Remove argument. | 67 compiler->GenerateCall(0, // no token position. |
| 69 __ popl(result); // Restore result. | 68 &StubCode::OptimizeFunctionLabel(), |
| 69 PcDescriptors::kOther, | |
| 70 locs()); | |
| 70 __ Bind(¬_yet_hot); | 71 __ Bind(¬_yet_hot); |
| 71 } | 72 } |
| 72 } | 73 } |
| 73 if (FLAG_trace_functions) { | |
| 74 const Function& function = | |
| 75 Function::ZoneHandle(compiler->parsed_function().function().raw()); | |
| 76 __ LoadObject(temp, function); | |
| 77 __ pushl(result); // Preserve result. | |
| 78 __ pushl(temp); | |
| 79 compiler->GenerateCallRuntime(0, | |
| 80 kTraceFunctionExitRuntimeEntry, | |
| 81 locs()); | |
| 82 __ popl(temp); // Remove argument. | |
| 83 __ popl(result); // Restore result. | |
| 84 } | |
| 85 #if defined(DEBUG) | 74 #if defined(DEBUG) |
| 86 // TODO(srdjan): Fix for functions with finally clause. | 75 // TODO(srdjan): Fix for functions with finally clause. |
| 87 // A finally clause may leave a previously pushed return value if it | 76 // A finally clause may leave a previously pushed return value if it |
| 88 // has its own return instruction. Method that have finally are currently | 77 // has its own return instruction. Method that have finally are currently |
| 89 // not optimized. | 78 // not optimized. |
| 90 if (!compiler->HasFinally()) { | 79 if (!compiler->HasFinally()) { |
| 91 __ Comment("Stack Check"); | 80 __ Comment("Stack Check"); |
| 92 Label done; | 81 Label done; |
| 93 __ movl(EDI, EBP); | 82 __ movl(EDI, EBP); |
| 94 __ subl(EDI, ESP); | 83 __ subl(EDI, ESP); |
| (...skipping 2628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2723 __ pcmpeqq(XMM0, XMM0); // Generate all 1's. | 2712 __ pcmpeqq(XMM0, XMM0); // Generate all 1's. |
| 2724 __ pxor(value, XMM0); | 2713 __ pxor(value, XMM0); |
| 2725 } | 2714 } |
| 2726 | 2715 |
| 2727 | 2716 |
| 2728 } // namespace dart | 2717 } // namespace dart |
| 2729 | 2718 |
| 2730 #undef __ | 2719 #undef __ |
| 2731 | 2720 |
| 2732 #endif // defined TARGET_ARCH_X64 | 2721 #endif // defined TARGET_ARCH_X64 |
| OLD | NEW |