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_XXX. | 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_XXX. |
| 6 | 6 |
| 7 #include "vm/flow_graph_compiler.h" | 7 #include "vm/flow_graph_compiler.h" |
| 8 | 8 |
| 9 #include "vm/dart_entry.h" | 9 #include "vm/dart_entry.h" |
| 10 #include "vm/debugger.h" | 10 #include "vm/debugger.h" |
| 11 #include "vm/deopt_instructions.h" | |
| 11 #include "vm/il_printer.h" | 12 #include "vm/il_printer.h" |
| 12 #include "vm/intrinsifier.h" | 13 #include "vm/intrinsifier.h" |
| 13 #include "vm/locations.h" | 14 #include "vm/locations.h" |
| 14 #include "vm/longjump.h" | 15 #include "vm/longjump.h" |
| 15 #include "vm/object_store.h" | 16 #include "vm/object_store.h" |
| 16 #include "vm/parser.h" | 17 #include "vm/parser.h" |
| 17 #include "vm/stub_code.h" | 18 #include "vm/stub_code.h" |
| 18 #include "vm/symbols.h" | 19 #include "vm/symbols.h" |
| 19 | 20 |
| 20 namespace dart { | 21 namespace dart { |
| 21 | 22 |
| 22 DEFINE_FLAG(bool, print_scopes, false, "Print scopes of local variables."); | 23 DEFINE_FLAG(bool, print_scopes, false, "Print scopes of local variables."); |
| 23 DEFINE_FLAG(bool, trace_functions, false, "Trace entry of each function."); | 24 DEFINE_FLAG(bool, trace_functions, false, "Trace entry of each function."); |
| 24 DECLARE_FLAG(bool, code_comments); | 25 DECLARE_FLAG(bool, code_comments); |
| 25 DECLARE_FLAG(bool, enable_type_checks); | 26 DECLARE_FLAG(bool, enable_type_checks); |
| 26 DECLARE_FLAG(bool, intrinsify); | 27 DECLARE_FLAG(bool, intrinsify); |
| 27 DECLARE_FLAG(bool, report_usage_count); | 28 DECLARE_FLAG(bool, report_usage_count); |
| 28 DECLARE_FLAG(bool, trace_functions); | 29 DECLARE_FLAG(bool, trace_functions); |
| 29 DECLARE_FLAG(int, optimization_counter_threshold); | 30 DECLARE_FLAG(int, optimization_counter_threshold); |
| 30 | 31 |
| 32 RawDeoptInfo* DeoptimizationStub::CreateDeoptInfo(FlowGraphCompiler* compiler) { | |
| 33 if (deoptimization_env_ == NULL) return DeoptInfo::null(); | |
| 34 // We do not support copied parameters yet. | |
| 35 ASSERT(compiler->parsed_function().function().num_optional_parameters() == 0); | |
| 36 const intptr_t fixed_parameter_count = | |
| 37 deoptimization_env_->fixed_parameter_count(); | |
| 38 DeoptInfoBuilder builder(compiler->object_table(), fixed_parameter_count); | |
| 39 | |
| 40 const Function& function = compiler->parsed_function().function(); | |
| 41 intptr_t slot_ix = 0; | |
| 42 builder.AddReturnAddress(function, deopt_id_, slot_ix++); | |
| 43 | |
| 44 // All locals between TOS and PC-marker. | |
| 45 const GrowableArray<Value*>& values = deoptimization_env_->values(); | |
| 46 // const intptr_t local_slot_count = values.length() - fixed_parameter_count; | |
| 47 for (intptr_t i = values.length() - 1; i >= fixed_parameter_count; i--) { | |
| 48 builder.AddCopy(deoptimization_env_->LocationAt(i), *values[i], slot_ix++); | |
| 49 } | |
| 50 | |
| 51 // PC marker, caller-fp, caller-pc. | |
| 52 builder.AddPcMarker(function, slot_ix++); | |
| 53 builder.AddCallerFp(slot_ix++); | |
| 54 builder.AddCallerPc(slot_ix++); | |
| 55 // Incoming arguments. | |
| 56 for (intptr_t i = fixed_parameter_count - 1; i >= 0; i--) { | |
| 57 builder.AddCopy(deoptimization_env_->LocationAt(i), *values[i], slot_ix++); | |
| 58 } | |
| 59 | |
| 60 const DeoptInfo& deopt_info = DeoptInfo::Handle(builder.CreateDeoptInfo()); | |
| 61 return deopt_info.raw(); | |
| 62 } | |
| 63 | |
| 31 | 64 |
| 32 FlowGraphCompiler::FlowGraphCompiler( | 65 FlowGraphCompiler::FlowGraphCompiler( |
| 33 Assembler* assembler, | 66 Assembler* assembler, |
| 34 const ParsedFunction& parsed_function, | 67 const ParsedFunction& parsed_function, |
| 35 const GrowableArray<BlockEntryInstr*>& block_order, | 68 const GrowableArray<BlockEntryInstr*>& block_order, |
| 36 bool is_optimizing, | 69 bool is_optimizing, |
| 37 bool is_ssa, | 70 bool is_ssa, |
| 38 bool is_leaf) | 71 bool is_leaf) |
| 39 : assembler_(assembler), | 72 : assembler_(assembler), |
| 40 parsed_function_(parsed_function), | 73 parsed_function_(parsed_function), |
| 41 block_order_(block_order), | 74 block_order_(block_order), |
| 42 current_block_(NULL), | 75 current_block_(NULL), |
| 43 exception_handlers_list_(NULL), | 76 exception_handlers_list_(NULL), |
| 44 pc_descriptors_list_(NULL), | 77 pc_descriptors_list_(NULL), |
| 45 stackmap_table_builder_(NULL), | 78 stackmap_table_builder_(NULL), |
| 46 block_info_(block_order.length()), | 79 block_info_(block_order.length()), |
| 47 deopt_stubs_(), | 80 deopt_stubs_(), |
| 81 object_table_(GrowableObjectArray::Handle(GrowableObjectArray::New())), | |
| 48 is_optimizing_(is_optimizing), | 82 is_optimizing_(is_optimizing), |
| 49 is_ssa_(is_ssa), | 83 is_ssa_(is_ssa), |
| 50 is_dart_leaf_(is_leaf), | 84 is_dart_leaf_(is_leaf), |
| 51 bool_true_(Bool::ZoneHandle(Bool::True())), | 85 bool_true_(Bool::ZoneHandle(Bool::True())), |
| 52 bool_false_(Bool::ZoneHandle(Bool::False())), | 86 bool_false_(Bool::ZoneHandle(Bool::False())), |
| 53 double_class_(Class::ZoneHandle( | 87 double_class_(Class::ZoneHandle( |
| 54 Isolate::Current()->object_store()->double_class())), | 88 Isolate::Current()->object_store()->double_class())), |
| 55 frame_register_allocator_(this, is_optimizing, is_ssa), | 89 frame_register_allocator_(this, is_optimizing, is_ssa), |
| 56 parallel_move_resolver_(this) { | 90 parallel_move_resolver_(this) { |
| 57 ASSERT(assembler != NULL); | 91 ASSERT(assembler != NULL); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 158 | 192 |
| 159 bool FlowGraphCompiler::IsNextBlock(BlockEntryInstr* block_entry) const { | 193 bool FlowGraphCompiler::IsNextBlock(BlockEntryInstr* block_entry) const { |
| 160 intptr_t current_index = reverse_index(current_block()->postorder_number()); | 194 intptr_t current_index = reverse_index(current_block()->postorder_number()); |
| 161 return (current_index < (block_order().length() - 1)) && | 195 return (current_index < (block_order().length() - 1)) && |
| 162 (block_order()[current_index + 1] == block_entry); | 196 (block_order()[current_index + 1] == block_entry); |
| 163 } | 197 } |
| 164 | 198 |
| 165 | 199 |
| 166 void FlowGraphCompiler::GenerateDeferredCode() { | 200 void FlowGraphCompiler::GenerateDeferredCode() { |
| 167 for (intptr_t i = 0; i < deopt_stubs_.length(); i++) { | 201 for (intptr_t i = 0; i < deopt_stubs_.length(); i++) { |
| 168 deopt_stubs_[i]->GenerateCode(this); | 202 deopt_stubs_[i]->GenerateCode(this, i); |
| 169 } | 203 } |
| 170 } | 204 } |
| 171 | 205 |
| 172 | 206 |
| 173 void FlowGraphCompiler::AddExceptionHandler(intptr_t try_index, | 207 void FlowGraphCompiler::AddExceptionHandler(intptr_t try_index, |
| 174 intptr_t pc_offset) { | 208 intptr_t pc_offset) { |
| 175 exception_handlers_list_->AddHandler(try_index, pc_offset); | 209 exception_handlers_list_->AddHandler(try_index, pc_offset); |
| 176 } | 210 } |
| 177 | 211 |
| 178 | 212 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 225 | 259 |
| 226 void FlowGraphCompiler::FinalizePcDescriptors(const Code& code) { | 260 void FlowGraphCompiler::FinalizePcDescriptors(const Code& code) { |
| 227 ASSERT(pc_descriptors_list_ != NULL); | 261 ASSERT(pc_descriptors_list_ != NULL); |
| 228 const PcDescriptors& descriptors = PcDescriptors::Handle( | 262 const PcDescriptors& descriptors = PcDescriptors::Handle( |
| 229 pc_descriptors_list_->FinalizePcDescriptors(code.EntryPoint())); | 263 pc_descriptors_list_->FinalizePcDescriptors(code.EntryPoint())); |
| 230 descriptors.Verify(parsed_function_.function().is_optimizable()); | 264 descriptors.Verify(parsed_function_.function().is_optimizable()); |
| 231 code.set_pc_descriptors(descriptors); | 265 code.set_pc_descriptors(descriptors); |
| 232 } | 266 } |
| 233 | 267 |
| 234 | 268 |
| 269 void FlowGraphCompiler::FinalizeDeoptInfo(const Code& code) { | |
| 270 const Array& array = | |
| 271 Array::Handle(Array::New(deopt_stubs_.length(), Heap::kOld)); | |
| 272 for (intptr_t i = 0; i < deopt_stubs_.length(); i++) { | |
| 273 const DeoptInfo& info = | |
| 274 DeoptInfo::Handle(deopt_stubs_[i]->CreateDeoptInfo(this)); | |
|
siva
2012/08/06 20:32:24
The handle could be created outside the loop?
srdjan
2012/08/06 20:39:48
Done.
| |
| 275 array.SetAt(i, info); | |
| 276 } | |
| 277 code.set_deopt_info_array(array); | |
| 278 const Array& object_array = Array::Handle(Array::MakeArray(object_table_)); | |
| 279 code.set_object_table(object_array); | |
| 280 } | |
| 281 | |
| 282 | |
| 235 void FlowGraphCompiler::FinalizeStackmaps(const Code& code) { | 283 void FlowGraphCompiler::FinalizeStackmaps(const Code& code) { |
| 236 if (stackmap_table_builder_ == NULL) { | 284 if (stackmap_table_builder_ == NULL) { |
| 237 // The unoptimizing compiler has no stack maps. | 285 // The unoptimizing compiler has no stack maps. |
| 238 code.set_stackmaps(Array::Handle()); | 286 code.set_stackmaps(Array::Handle()); |
| 239 } else { | 287 } else { |
| 240 // Finalize the stack map array and add it to the code object. | 288 // Finalize the stack map array and add it to the code object. |
| 241 code.set_stackmaps( | 289 code.set_stackmaps( |
| 242 Array::Handle(stackmap_table_builder_->FinalizeStackmaps(code))); | 290 Array::Handle(stackmap_table_builder_->FinalizeStackmaps(code))); |
| 243 } | 291 } |
| 244 } | 292 } |
| (...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 801 return; | 849 return; |
| 802 } | 850 } |
| 803 } | 851 } |
| 804 | 852 |
| 805 // This move is not blocked. | 853 // This move is not blocked. |
| 806 EmitMove(index); | 854 EmitMove(index); |
| 807 } | 855 } |
| 808 | 856 |
| 809 | 857 |
| 810 } // namespace dart | 858 } // namespace dart |
| OLD | NEW |