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 builder.AddReturnAddress(compiler->parsed_function().function(), deopt_id_); | |
| 41 | |
| 42 // All locals between TOS and PC-marker. | |
| 43 const GrowableArray<Value*>& values = deoptimization_env_->values(); | |
| 44 // const intptr_t local_slot_count = values.length() - fixed_parameter_count; | |
| 45 for (intptr_t i = values.length() - 1; i >= fixed_parameter_count; i--) { | |
| 46 builder.AddCopy(deoptimization_env_->LocationAt(i), *values[i]); | |
| 47 } | |
| 48 | |
| 49 // PC marker, caller-fp, caller-pc. | |
| 50 builder.AddPcMarker(compiler->parsed_function().function()); | |
| 51 builder.AddCallerFp(); | |
| 52 builder.AddCallerPc(); | |
| 53 // Incoming arguments. | |
| 54 for (intptr_t i = fixed_parameter_count - 1; i >= 0; i--) { | |
| 55 builder.AddCopy(deoptimization_env_->LocationAt(i), *values[i]); | |
| 56 } | |
| 57 | |
| 58 const DeoptInfo& deopt_info = DeoptInfo::Handle(builder.CreateDeoptInfo()); | |
| 59 return deopt_info.raw(); | |
| 60 } | |
| 61 | |
| 31 | 62 |
| 32 FlowGraphCompiler::FlowGraphCompiler( | 63 FlowGraphCompiler::FlowGraphCompiler( |
| 33 Assembler* assembler, | 64 Assembler* assembler, |
| 34 const ParsedFunction& parsed_function, | 65 const ParsedFunction& parsed_function, |
| 35 const GrowableArray<BlockEntryInstr*>& block_order, | 66 const GrowableArray<BlockEntryInstr*>& block_order, |
| 36 bool is_optimizing, | 67 bool is_optimizing, |
| 37 bool is_ssa, | 68 bool is_ssa, |
| 38 bool is_leaf) | 69 bool is_leaf) |
| 39 : assembler_(assembler), | 70 : assembler_(assembler), |
| 40 parsed_function_(parsed_function), | 71 parsed_function_(parsed_function), |
| 41 block_order_(block_order), | 72 block_order_(block_order), |
| 42 current_block_(NULL), | 73 current_block_(NULL), |
| 43 exception_handlers_list_(NULL), | 74 exception_handlers_list_(NULL), |
| 44 pc_descriptors_list_(NULL), | 75 pc_descriptors_list_(NULL), |
| 45 stackmap_table_builder_(NULL), | 76 stackmap_table_builder_(NULL), |
| 46 block_info_(block_order.length()), | 77 block_info_(block_order.length()), |
| 47 deopt_stubs_(), | 78 deopt_stubs_(), |
| 79 object_table_(), | |
| 48 is_optimizing_(is_optimizing), | 80 is_optimizing_(is_optimizing), |
| 49 is_ssa_(is_ssa), | 81 is_ssa_(is_ssa), |
| 50 is_dart_leaf_(is_leaf), | 82 is_dart_leaf_(is_leaf), |
| 51 bool_true_(Bool::ZoneHandle(Bool::True())), | 83 bool_true_(Bool::ZoneHandle(Bool::True())), |
| 52 bool_false_(Bool::ZoneHandle(Bool::False())), | 84 bool_false_(Bool::ZoneHandle(Bool::False())), |
| 53 double_class_(Class::ZoneHandle( | 85 double_class_(Class::ZoneHandle( |
| 54 Isolate::Current()->object_store()->double_class())), | 86 Isolate::Current()->object_store()->double_class())), |
| 55 frame_register_allocator_(this, is_optimizing, is_ssa), | 87 frame_register_allocator_(this, is_optimizing, is_ssa), |
| 56 parallel_move_resolver_(this) { | 88 parallel_move_resolver_(this) { |
| 57 ASSERT(assembler != NULL); | 89 ASSERT(assembler != NULL); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 159 | 191 |
| 160 bool FlowGraphCompiler::IsNextBlock(BlockEntryInstr* block_entry) const { | 192 bool FlowGraphCompiler::IsNextBlock(BlockEntryInstr* block_entry) const { |
| 161 intptr_t current_index = reverse_index(current_block()->postorder_number()); | 193 intptr_t current_index = reverse_index(current_block()->postorder_number()); |
| 162 return (current_index < (block_order().length() - 1)) && | 194 return (current_index < (block_order().length() - 1)) && |
| 163 (block_order()[current_index + 1] == block_entry); | 195 (block_order()[current_index + 1] == block_entry); |
| 164 } | 196 } |
| 165 | 197 |
| 166 | 198 |
| 167 void FlowGraphCompiler::GenerateDeferredCode() { | 199 void FlowGraphCompiler::GenerateDeferredCode() { |
| 168 for (intptr_t i = 0; i < deopt_stubs_.length(); i++) { | 200 for (intptr_t i = 0; i < deopt_stubs_.length(); i++) { |
| 169 deopt_stubs_[i]->GenerateCode(this); | 201 deopt_stubs_[i]->GenerateCode(this, i); |
| 170 } | 202 } |
| 171 } | 203 } |
| 172 | 204 |
| 173 | 205 |
| 174 void FlowGraphCompiler::AddExceptionHandler(intptr_t try_index, | 206 void FlowGraphCompiler::AddExceptionHandler(intptr_t try_index, |
| 175 intptr_t pc_offset) { | 207 intptr_t pc_offset) { |
| 176 exception_handlers_list_->AddHandler(try_index, pc_offset); | 208 exception_handlers_list_->AddHandler(try_index, pc_offset); |
| 177 } | 209 } |
| 178 | 210 |
| 179 | 211 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 226 | 258 |
| 227 void FlowGraphCompiler::FinalizePcDescriptors(const Code& code) { | 259 void FlowGraphCompiler::FinalizePcDescriptors(const Code& code) { |
| 228 ASSERT(pc_descriptors_list_ != NULL); | 260 ASSERT(pc_descriptors_list_ != NULL); |
| 229 const PcDescriptors& descriptors = PcDescriptors::Handle( | 261 const PcDescriptors& descriptors = PcDescriptors::Handle( |
| 230 pc_descriptors_list_->FinalizePcDescriptors(code.EntryPoint())); | 262 pc_descriptors_list_->FinalizePcDescriptors(code.EntryPoint())); |
| 231 descriptors.Verify(parsed_function_.function().is_optimizable()); | 263 descriptors.Verify(parsed_function_.function().is_optimizable()); |
| 232 code.set_pc_descriptors(descriptors); | 264 code.set_pc_descriptors(descriptors); |
| 233 } | 265 } |
| 234 | 266 |
| 235 | 267 |
| 268 void FlowGraphCompiler::FinalizeDeoptInfo(const Code& code) { | |
| 269 const Array& array = | |
| 270 Array::Handle(Array::New(deopt_stubs_.length(), Heap::kOld)); | |
| 271 for (intptr_t i = 0; i < deopt_stubs_.length(); i++) { | |
| 272 const DeoptInfo& info = | |
| 273 DeoptInfo::Handle(deopt_stubs_[i]->CreateDeoptInfo(this)); | |
| 274 array.SetAt(i, info); | |
| 275 } | |
| 276 code.set_deopt_info_array(array); | |
| 277 intptr_t len = object_table_.length(); | |
| 278 const Array& object_array = Array::Handle(Array::New(len)); | |
| 279 for (intptr_t i = 0; i < len; i++) { | |
| 280 object_array.SetAt(i, *object_table_[i]); | |
| 281 } | |
|
siva
2012/08/04 01:21:50
If you had been carrying the object_table_ as a gr
srdjan
2012/08/06 20:09:05
Done.
| |
| 282 code.set_object_table(object_array); | |
| 283 } | |
| 284 | |
| 285 | |
| 236 void FlowGraphCompiler::FinalizeStackmaps(const Code& code) { | 286 void FlowGraphCompiler::FinalizeStackmaps(const Code& code) { |
| 237 if (stackmap_table_builder_ == NULL) { | 287 if (stackmap_table_builder_ == NULL) { |
| 238 // The unoptimizing compiler has no stack maps. | 288 // The unoptimizing compiler has no stack maps. |
| 239 code.set_stackmaps(Array::Handle()); | 289 code.set_stackmaps(Array::Handle()); |
| 240 } else { | 290 } else { |
| 241 // Finalize the stack map array and add it to the code object. | 291 // Finalize the stack map array and add it to the code object. |
| 242 code.set_stackmaps( | 292 code.set_stackmaps( |
| 243 Array::Handle(stackmap_table_builder_->FinalizeStackmaps(code))); | 293 Array::Handle(stackmap_table_builder_->FinalizeStackmaps(code))); |
| 244 } | 294 } |
| 245 } | 295 } |
| (...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 802 return; | 852 return; |
| 803 } | 853 } |
| 804 } | 854 } |
| 805 | 855 |
| 806 // This move is not blocked. | 856 // This move is not blocked. |
| 807 EmitMove(index); | 857 EmitMove(index); |
| 808 } | 858 } |
| 809 | 859 |
| 810 | 860 |
| 811 } // namespace dart | 861 } // namespace dart |
| OLD | NEW |