| 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/intermediate_language.h" | 5 #include "vm/intermediate_language.h" |
| 6 | 6 |
| 7 #include "vm/object.h" | 7 #include "vm/object.h" |
| 8 #include "vm/os.h" | 8 #include "vm/os.h" |
| 9 #include "vm/scopes.h" | 9 #include "vm/scopes.h" |
| 10 | 10 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 intptr_t BindInstr::InputCount() const { | 116 intptr_t BindInstr::InputCount() const { |
| 117 return computation()->InputCount(); | 117 return computation()->InputCount(); |
| 118 } | 118 } |
| 119 | 119 |
| 120 | 120 |
| 121 intptr_t DoInstr::InputCount() const { | 121 intptr_t DoInstr::InputCount() const { |
| 122 return computation()->InputCount(); | 122 return computation()->InputCount(); |
| 123 } | 123 } |
| 124 | 124 |
| 125 | 125 |
| 126 intptr_t GraphEntryInstr::InputCount() const { |
| 127 return 0; |
| 128 } |
| 129 |
| 130 |
| 126 intptr_t TargetEntryInstr::InputCount() const { | 131 intptr_t TargetEntryInstr::InputCount() const { |
| 127 return 0; | 132 return 0; |
| 128 } | 133 } |
| 129 | 134 |
| 130 | 135 |
| 131 intptr_t JoinEntryInstr::InputCount() const { | 136 intptr_t JoinEntryInstr::InputCount() const { |
| 132 return 0; | 137 return 0; |
| 133 } | 138 } |
| 134 | 139 |
| 135 | 140 |
| 136 // ==== Postorder graph traversal. | 141 // ==== Postorder graph traversal. |
| 142 void GraphEntryInstr::DiscoverBlocks( |
| 143 BlockEntryInstr* current_block, |
| 144 GrowableArray<BlockEntryInstr*>* preorder, |
| 145 GrowableArray<BlockEntryInstr*>* postorder, |
| 146 GrowableArray<intptr_t>* parent) { |
| 147 // We only visit this block once, first of all blocks. |
| 148 ASSERT(preorder_number() == -1); |
| 149 ASSERT(current_block == NULL); |
| 150 ASSERT(preorder->is_empty()); |
| 151 ASSERT(postorder->is_empty()); |
| 152 ASSERT(parent->is_empty()); |
| 153 |
| 154 // This node has no parent, indicated by -1. The preorder number is 0. |
| 155 parent->Add(-1); |
| 156 set_preorder_number(0); |
| 157 preorder->Add(this); |
| 158 |
| 159 // Iteratively traverse all successors. In the unoptimized code, we will |
| 160 // enter the function at the first successor in reverse postorder, so we |
| 161 // must visit the normal entry last. |
| 162 for (intptr_t i = catch_entries_.length() - 1; i >= 0; --i) { |
| 163 catch_entries_[i]->DiscoverBlocks(this, preorder, postorder, parent); |
| 164 } |
| 165 normal_entry_->DiscoverBlocks(this, preorder, postorder, parent); |
| 166 |
| 167 // Assign postorder number. |
| 168 set_postorder_number(postorder->length()); |
| 169 postorder->Add(this); |
| 170 } |
| 171 |
| 172 |
| 137 void JoinEntryInstr::DiscoverBlocks( | 173 void JoinEntryInstr::DiscoverBlocks( |
| 138 BlockEntryInstr* current_block, | 174 BlockEntryInstr* current_block, |
| 139 GrowableArray<BlockEntryInstr*>* preorder, | 175 GrowableArray<BlockEntryInstr*>* preorder, |
| 140 GrowableArray<BlockEntryInstr*>* postorder, | 176 GrowableArray<BlockEntryInstr*>* postorder, |
| 141 GrowableArray<intptr_t>* parent) { | 177 GrowableArray<intptr_t>* parent) { |
| 142 // The global graph entry is a TargetEntryInstr, so we can assume | 178 // We have already visited the graph entry, so we can assume current_block |
| 143 // current_block is non-null and preorder array is non-empty. | 179 // is non-null and preorder array is non-empty. |
| 144 ASSERT(current_block != NULL); | 180 ASSERT(current_block != NULL); |
| 145 ASSERT(!preorder->is_empty()); | 181 ASSERT(!preorder->is_empty()); |
| 146 | 182 |
| 147 // 1. Record control-flow-graph basic-block predecessors. | 183 // 1. Record control-flow-graph basic-block predecessors. |
| 148 predecessors_.Add(current_block); | 184 predecessors_.Add(current_block); |
| 149 | 185 |
| 150 // 2. If the block has already been reached by the traversal, we are done. | 186 // 2. If the block has already been reached by the traversal, we are done. |
| 151 if (preorder_number() >= 0) return; | 187 if (preorder_number() >= 0) return; |
| 152 | 188 |
| 153 // 3. The last entry in the preorder array is the spanning-tree parent. | 189 // 3. The last entry in the preorder array is the spanning-tree parent. |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 // true/false order in reverse postorder used as the block ordering in the | 267 // true/false order in reverse postorder used as the block ordering in the |
| 232 // nonoptimizing compiler. | 268 // nonoptimizing compiler. |
| 233 ASSERT(true_successor_ != NULL); | 269 ASSERT(true_successor_ != NULL); |
| 234 ASSERT(false_successor_ != NULL); | 270 ASSERT(false_successor_ != NULL); |
| 235 false_successor_->DiscoverBlocks(current_block, preorder, postorder, parent); | 271 false_successor_->DiscoverBlocks(current_block, preorder, postorder, parent); |
| 236 true_successor_->DiscoverBlocks(current_block, preorder, postorder, parent); | 272 true_successor_->DiscoverBlocks(current_block, preorder, postorder, parent); |
| 237 } | 273 } |
| 238 | 274 |
| 239 | 275 |
| 240 } // namespace dart | 276 } // namespace dart |
| OLD | NEW |