| 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/flow_graph_compiler.h" | 8 #include "vm/flow_graph_compiler.h" |
| 9 | 9 |
| 10 #include "lib/error.h" | 10 #include "lib/error.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 DECLARE_FLAG(bool, enable_type_checks); | 26 DECLARE_FLAG(bool, enable_type_checks); |
| 27 DECLARE_FLAG(bool, intrinsify); | 27 DECLARE_FLAG(bool, intrinsify); |
| 28 DECLARE_FLAG(bool, optimization_counter_threshold); | 28 DECLARE_FLAG(bool, optimization_counter_threshold); |
| 29 DECLARE_FLAG(bool, print_ast); | 29 DECLARE_FLAG(bool, print_ast); |
| 30 DECLARE_FLAG(bool, report_usage_count); | 30 DECLARE_FLAG(bool, report_usage_count); |
| 31 | 31 |
| 32 | 32 |
| 33 FlowGraphCompiler::FlowGraphCompiler( | 33 FlowGraphCompiler::FlowGraphCompiler( |
| 34 Assembler* assembler, | 34 Assembler* assembler, |
| 35 const ParsedFunction& parsed_function, | 35 const ParsedFunction& parsed_function, |
| 36 const GrowableArray<BlockEntryInstr*>& block_order) | 36 const GrowableArray<BlockEntryInstr*>& block_order, |
| 37 bool is_optimizing) |
| 37 : FlowGraphVisitor(block_order), | 38 : FlowGraphVisitor(block_order), |
| 38 assembler_(assembler), | 39 assembler_(assembler), |
| 39 parsed_function_(parsed_function), | 40 parsed_function_(parsed_function), |
| 40 block_info_(block_order.length()), | 41 block_info_(block_order.length()), |
| 41 current_block_(NULL), | 42 current_block_(NULL), |
| 42 pc_descriptors_list_(new DescriptorList()), | 43 pc_descriptors_list_(new DescriptorList()), |
| 43 exception_handlers_list_(new ExceptionHandlerList()) { | 44 exception_handlers_list_(new ExceptionHandlerList()), |
| 45 is_optimizing_(is_optimizing) { |
| 44 for (int i = 0; i < block_order.length(); ++i) { | 46 for (int i = 0; i < block_order.length(); ++i) { |
| 45 block_info_.Add(new BlockInfo()); | 47 block_info_.Add(new BlockInfo()); |
| 46 } | 48 } |
| 47 } | 49 } |
| 48 | 50 |
| 49 | 51 |
| 50 FlowGraphCompiler::~FlowGraphCompiler() { | 52 FlowGraphCompiler::~FlowGraphCompiler() { |
| 51 // BlockInfos are zone-allocated, so their destructors are not called. | 53 // BlockInfos are zone-allocated, so their destructors are not called. |
| 52 // Verify the labels explicitly here. | 54 // Verify the labels explicitly here. |
| 53 for (int i = 0; i < block_info_.length(); ++i) { | 55 for (int i = 0; i < block_info_.length(); ++i) { |
| (...skipping 1161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1215 | 1217 |
| 1216 | 1218 |
| 1217 void FlowGraphCompiler::VisitBind(BindInstr* instr) { | 1219 void FlowGraphCompiler::VisitBind(BindInstr* instr) { |
| 1218 instr->computation()->Accept(this); | 1220 instr->computation()->Accept(this); |
| 1219 __ pushq(RAX); | 1221 __ pushq(RAX); |
| 1220 } | 1222 } |
| 1221 | 1223 |
| 1222 | 1224 |
| 1223 void FlowGraphCompiler::VisitReturn(ReturnInstr* instr) { | 1225 void FlowGraphCompiler::VisitReturn(ReturnInstr* instr) { |
| 1224 LoadValue(RAX, instr->value()); | 1226 LoadValue(RAX, instr->value()); |
| 1227 if (!is_optimizing()) { |
| 1228 // Count only in unoptimized code. |
| 1229 // TODO(srdjan): Replace the counting code with a type feedback |
| 1230 // collection and counting stub. |
| 1231 const Function& function = |
| 1232 Function::ZoneHandle(parsed_function_.function().raw()); |
| 1233 __ LoadObject(RCX, function); |
| 1234 __ incq(FieldAddress(RCX, Function::usage_counter_offset())); |
| 1235 if (CodeGenerator::CanOptimize()) { |
| 1236 // Do not optimize if usage count must be reported. |
| 1237 __ cmpl(FieldAddress(RCX, Function::usage_counter_offset()), |
| 1238 Immediate(FLAG_optimization_counter_threshold)); |
| 1239 Label not_yet_hot; |
| 1240 __ j(LESS_EQUAL, ¬_yet_hot, Assembler::kNearJump); |
| 1241 __ pushq(RAX); // Preserve result. |
| 1242 __ pushq(RCX); // Argument for runtime: function to optimize. |
| 1243 __ CallRuntime(kOptimizeInvokedFunctionRuntimeEntry); |
| 1244 __ popq(RCX); // Remove argument. |
| 1245 __ popq(RAX); // Restore result. |
| 1246 __ Bind(¬_yet_hot); |
| 1247 } |
| 1248 } |
| 1225 | 1249 |
| 1226 if (FLAG_trace_functions) { | 1250 if (FLAG_trace_functions) { |
| 1227 __ pushq(RAX); // Preserve result. | 1251 __ pushq(RAX); // Preserve result. |
| 1228 const Function& function = | 1252 const Function& function = |
| 1229 Function::ZoneHandle(parsed_function_.function().raw()); | 1253 Function::ZoneHandle(parsed_function_.function().raw()); |
| 1230 __ LoadObject(RBX, function); | 1254 __ LoadObject(RBX, function); |
| 1231 __ pushq(RBX); | 1255 __ pushq(RBX); |
| 1232 GenerateCallRuntime(AstNode::kNoId, | 1256 GenerateCallRuntime(AstNode::kNoId, |
| 1233 0, | 1257 0, |
| 1234 CatchClauseNode::kInvalidTryIndex, | 1258 CatchClauseNode::kInvalidTryIndex, |
| (...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1708 ASSERT(exception_handlers_list_ != NULL); | 1732 ASSERT(exception_handlers_list_ != NULL); |
| 1709 const ExceptionHandlers& handlers = ExceptionHandlers::Handle( | 1733 const ExceptionHandlers& handlers = ExceptionHandlers::Handle( |
| 1710 exception_handlers_list_->FinalizeExceptionHandlers(code.EntryPoint())); | 1734 exception_handlers_list_->FinalizeExceptionHandlers(code.EntryPoint())); |
| 1711 code.set_exception_handlers(handlers); | 1735 code.set_exception_handlers(handlers); |
| 1712 } | 1736 } |
| 1713 | 1737 |
| 1714 | 1738 |
| 1715 } // namespace dart | 1739 } // namespace dart |
| 1716 | 1740 |
| 1717 #endif // defined TARGET_ARCH_X64 | 1741 #endif // defined TARGET_ARCH_X64 |
| OLD | NEW |