| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 #include "vm/flow_graph_compiler_shared.h" |
| 6 |
| 7 #include "vm/intermediate_language.h" |
| 8 #include "vm/parser.h" |
| 9 |
| 10 namespace dart { |
| 11 |
| 12 FlowGraphCompilerShared::FlowGraphCompilerShared( |
| 13 Assembler* assembler, |
| 14 const ParsedFunction& parsed_function, |
| 15 const GrowableArray<BlockEntryInstr*>& block_order, |
| 16 bool is_optimizing) |
| 17 : assembler_(assembler), |
| 18 parsed_function_(parsed_function), |
| 19 block_order_(block_order), |
| 20 current_block_(NULL), |
| 21 exception_handlers_list_(NULL), |
| 22 pc_descriptors_list_(NULL), |
| 23 stackmap_builder_(NULL), |
| 24 block_info_(block_order.length()), |
| 25 deopt_stubs_(), |
| 26 is_optimizing_(is_optimizing) { |
| 27 ASSERT(assembler != NULL); |
| 28 } |
| 29 |
| 30 |
| 31 FlowGraphCompilerShared::~FlowGraphCompilerShared() { |
| 32 // BlockInfos are zone-allocated, so their destructors are not called. |
| 33 // Verify the labels explicitly here. |
| 34 for (int i = 0; i < block_info_.length(); ++i) { |
| 35 ASSERT(!block_info_[i]->label.IsLinked()); |
| 36 ASSERT(!block_info_[i]->label.HasNear()); |
| 37 } |
| 38 } |
| 39 |
| 40 void FlowGraphCompilerShared::InitCompiler() { |
| 41 pc_descriptors_list_ = new DescriptorList(); |
| 42 exception_handlers_list_ = new ExceptionHandlerList(); |
| 43 block_info_.Clear(); |
| 44 for (int i = 0; i < block_order_.length(); ++i) { |
| 45 block_info_.Add(new BlockInfo()); |
| 46 } |
| 47 } |
| 48 |
| 49 |
| 50 intptr_t FlowGraphCompilerShared::StackSize() const { |
| 51 return parsed_function_.stack_local_count() + |
| 52 parsed_function_.copied_parameter_count(); |
| 53 } |
| 54 |
| 55 |
| 56 Label* FlowGraphCompilerShared::GetBlockLabel( |
| 57 BlockEntryInstr* block_entry) const { |
| 58 intptr_t block_index = block_entry->postorder_number(); |
| 59 return &block_info_[block_index]->label; |
| 60 } |
| 61 |
| 62 |
| 63 bool FlowGraphCompilerShared::IsNextBlock(TargetEntryInstr* block_entry) const { |
| 64 intptr_t current_index = reverse_index(current_block()->postorder_number()); |
| 65 return block_order_[current_index + 1] == block_entry; |
| 66 } |
| 67 |
| 68 |
| 69 void FlowGraphCompilerShared::AddExceptionHandler(intptr_t try_index, |
| 70 intptr_t pc_offset) { |
| 71 exception_handlers_list_->AddHandler(try_index, pc_offset); |
| 72 } |
| 73 |
| 74 |
| 75 // Uses current pc position and try-index. |
| 76 void FlowGraphCompilerShared::AddCurrentDescriptor(PcDescriptors::Kind kind, |
| 77 intptr_t cid, |
| 78 intptr_t token_index, |
| 79 intptr_t try_index) { |
| 80 pc_descriptors_list()->AddDescriptor(kind, |
| 81 assembler()->CodeSize(), |
| 82 cid, |
| 83 token_index, |
| 84 try_index); |
| 85 } |
| 86 |
| 87 |
| 88 Label* FlowGraphCompilerShared::AddDeoptStub(intptr_t deopt_id, |
| 89 intptr_t deopt_token_index, |
| 90 intptr_t try_index, |
| 91 DeoptReasonId reason, |
| 92 Register reg1, |
| 93 Register reg2) { |
| 94 DeoptimizationStub* stub = |
| 95 new DeoptimizationStub(deopt_id, deopt_token_index, try_index, reason); |
| 96 stub->Push(reg1); |
| 97 stub->Push(reg2); |
| 98 deopt_stubs_.Add(stub); |
| 99 return stub->entry_label(); |
| 100 } |
| 101 |
| 102 |
| 103 void FlowGraphCompilerShared::FinalizeExceptionHandlers(const Code& code) { |
| 104 ASSERT(exception_handlers_list_ != NULL); |
| 105 const ExceptionHandlers& handlers = ExceptionHandlers::Handle( |
| 106 exception_handlers_list_->FinalizeExceptionHandlers(code.EntryPoint())); |
| 107 code.set_exception_handlers(handlers); |
| 108 } |
| 109 |
| 110 |
| 111 void FlowGraphCompilerShared::FinalizePcDescriptors(const Code& code) { |
| 112 ASSERT(pc_descriptors_list_ != NULL); |
| 113 const PcDescriptors& descriptors = PcDescriptors::Handle( |
| 114 pc_descriptors_list_->FinalizePcDescriptors(code.EntryPoint())); |
| 115 descriptors.Verify(parsed_function_.function().is_optimizable()); |
| 116 code.set_pc_descriptors(descriptors); |
| 117 } |
| 118 |
| 119 |
| 120 void FlowGraphCompilerShared::FinalizeStackmaps(const Code& code) { |
| 121 if (stackmap_builder_ == NULL) { |
| 122 // The unoptimizing compiler has no stack maps. |
| 123 code.set_stackmaps(Array::Handle()); |
| 124 } else { |
| 125 // Finalize the stack map array and add it to the code object. |
| 126 code.set_stackmaps( |
| 127 Array::Handle(stackmap_builder_->FinalizeStackmaps(code))); |
| 128 } |
| 129 } |
| 130 |
| 131 |
| 132 void FlowGraphCompilerShared::FinalizeVarDescriptors(const Code& code) { |
| 133 const LocalVarDescriptors& var_descs = LocalVarDescriptors::Handle( |
| 134 parsed_function_.node_sequence()->scope()->GetVarDescriptors()); |
| 135 code.set_var_descriptors(var_descs); |
| 136 } |
| 137 |
| 138 |
| 139 void FlowGraphCompilerShared::GenerateDeferredCode() { |
| 140 for (intptr_t i = 0; i < deopt_stubs_.length(); i++) { |
| 141 deopt_stubs_[i]->GenerateCode(this); |
| 142 } |
| 143 } |
| 144 |
| 145 |
| 146 } // namespace dart |
| 147 |
| 148 |
| OLD | NEW |