blob: 502df1e9e9222a1f1dfd74da2987d0a73503f9d2 [file] [log] [blame]
buzbee67bf8852011-08-17 17:51:35 -07001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
buzbeeeaf09bc2012-11-15 14:51:41 -080017#include "compiler_internals.h"
Ian Rogers8d3a1172013-06-04 01:13:28 -070018#include "dataflow_iterator-inl.h"
buzbee67bf8852011-08-17 17:51:35 -070019
buzbee1fd33462013-03-25 13:40:45 -070020#define NOTVISITED (-1)
21
Elliott Hughes11d1b0c2012-01-23 16:57:47 -080022namespace art {
23
buzbeea5abf702013-04-12 14:39:29 -070024void MIRGraph::ClearAllVisitedFlags() {
buzbee56c71782013-09-05 17:13:19 -070025 AllNodesIterator iter(this);
buzbeea5abf702013-04-12 14:39:29 -070026 for (BasicBlock* bb = iter.Next(); bb != NULL; bb = iter.Next()) {
27 bb->visited = false;
28 }
29}
30
buzbee311ca162013-02-28 15:56:43 -080031BasicBlock* MIRGraph::NeedsVisit(BasicBlock* bb) {
buzbeee5f01222012-06-14 15:19:35 -070032 if (bb != NULL) {
33 if (bb->visited || bb->hidden) {
34 bb = NULL;
35 }
36 }
37 return bb;
38}
39
Brian Carlstrom2ce745c2013-07-17 17:44:30 -070040BasicBlock* MIRGraph::NextUnvisitedSuccessor(BasicBlock* bb) {
buzbee0d829482013-10-11 15:24:55 -070041 BasicBlock* res = NeedsVisit(GetBasicBlock(bb->fall_through));
buzbeee5f01222012-06-14 15:19:35 -070042 if (res == NULL) {
buzbee0d829482013-10-11 15:24:55 -070043 res = NeedsVisit(GetBasicBlock(bb->taken));
buzbeee5f01222012-06-14 15:19:35 -070044 if (res == NULL) {
buzbee0d829482013-10-11 15:24:55 -070045 if (bb->successor_block_list_type != kNotUsed) {
46 GrowableArray<SuccessorBlockInfo*>::Iterator iterator(bb->successor_blocks);
buzbeee5f01222012-06-14 15:19:35 -070047 while (true) {
buzbee862a7602013-04-05 10:58:54 -070048 SuccessorBlockInfo *sbi = iterator.Next();
Brian Carlstrom0cd7ec22013-07-17 23:40:20 -070049 if (sbi == NULL) {
50 break;
51 }
buzbee0d829482013-10-11 15:24:55 -070052 res = NeedsVisit(GetBasicBlock(sbi->block));
Brian Carlstrom0cd7ec22013-07-17 23:40:20 -070053 if (res != NULL) {
54 break;
55 }
buzbeee5f01222012-06-14 15:19:35 -070056 }
57 }
58 }
59 }
60 return res;
61}
62
Brian Carlstrom2ce745c2013-07-17 17:44:30 -070063void MIRGraph::MarkPreOrder(BasicBlock* block) {
buzbeee5f01222012-06-14 15:19:35 -070064 block->visited = true;
buzbeefa57c472012-11-21 12:06:18 -080065 /* Enqueue the pre_order block id */
buzbee0d829482013-10-11 15:24:55 -070066 if (block->id != NullBasicBlockId) {
67 dfs_order_->Insert(block->id);
68 }
buzbeee5f01222012-06-14 15:19:35 -070069}
70
Brian Carlstrom2ce745c2013-07-17 17:44:30 -070071void MIRGraph::RecordDFSOrders(BasicBlock* block) {
buzbeee5f01222012-06-14 15:19:35 -070072 std::vector<BasicBlock*> succ;
buzbee311ca162013-02-28 15:56:43 -080073 MarkPreOrder(block);
buzbeee5f01222012-06-14 15:19:35 -070074 succ.push_back(block);
75 while (!succ.empty()) {
76 BasicBlock* curr = succ.back();
buzbeefa57c472012-11-21 12:06:18 -080077 BasicBlock* next_successor = NextUnvisitedSuccessor(curr);
78 if (next_successor != NULL) {
buzbee311ca162013-02-28 15:56:43 -080079 MarkPreOrder(next_successor);
buzbeefa57c472012-11-21 12:06:18 -080080 succ.push_back(next_successor);
buzbeee5f01222012-06-14 15:19:35 -070081 continue;
82 }
buzbee862a7602013-04-05 10:58:54 -070083 curr->dfs_id = dfs_post_order_->Size();
buzbee0d829482013-10-11 15:24:55 -070084 if (curr->id != NullBasicBlockId) {
85 dfs_post_order_->Insert(curr->id);
86 }
buzbeee5f01222012-06-14 15:19:35 -070087 succ.pop_back();
88 }
89}
90
buzbee5b537102012-01-17 17:33:47 -080091/* Sort the blocks by the Depth-First-Search */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -070092void MIRGraph::ComputeDFSOrders() {
buzbeefa57c472012-11-21 12:06:18 -080093 /* Initialize or reset the DFS pre_order list */
buzbee862a7602013-04-05 10:58:54 -070094 if (dfs_order_ == NULL) {
buzbee0d829482013-10-11 15:24:55 -070095 dfs_order_ = new (arena_) GrowableArray<BasicBlockId>(arena_, GetNumBlocks(),
96 kGrowableArrayDfsOrder);
Bill Buzbeea114add2012-05-03 15:00:40 -070097 } else {
98 /* Just reset the used length on the counter */
buzbee862a7602013-04-05 10:58:54 -070099 dfs_order_->Reset();
Bill Buzbeea114add2012-05-03 15:00:40 -0700100 }
buzbee67bf8852011-08-17 17:51:35 -0700101
buzbeefa57c472012-11-21 12:06:18 -0800102 /* Initialize or reset the DFS post_order list */
buzbee862a7602013-04-05 10:58:54 -0700103 if (dfs_post_order_ == NULL) {
buzbee0d829482013-10-11 15:24:55 -0700104 dfs_post_order_ = new (arena_) GrowableArray<BasicBlockId>(arena_, GetNumBlocks(),
105 kGrowableArrayDfsPostOrder);
Bill Buzbeea114add2012-05-03 15:00:40 -0700106 } else {
107 /* Just reset the used length on the counter */
buzbee862a7602013-04-05 10:58:54 -0700108 dfs_post_order_->Reset();
Bill Buzbeea114add2012-05-03 15:00:40 -0700109 }
buzbee5b537102012-01-17 17:33:47 -0800110
buzbeee5f01222012-06-14 15:19:35 -0700111 // Reset visited flags from all nodes
buzbeea5abf702013-04-12 14:39:29 -0700112 ClearAllVisitedFlags();
113
buzbeee5f01222012-06-14 15:19:35 -0700114 // Record dfs orders
buzbee311ca162013-02-28 15:56:43 -0800115 RecordDFSOrders(GetEntryBlock());
buzbeee5f01222012-06-14 15:19:35 -0700116
buzbee862a7602013-04-05 10:58:54 -0700117 num_reachable_blocks_ = dfs_order_->Size();
buzbee67bf8852011-08-17 17:51:35 -0700118}
119
120/*
121 * Mark block bit on the per-Dalvik register vector to denote that Dalvik
122 * register idx is defined in BasicBlock bb.
123 */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700124bool MIRGraph::FillDefBlockMatrix(BasicBlock* bb) {
Brian Carlstrom0cd7ec22013-07-17 23:40:20 -0700125 if (bb->data_flow_info == NULL) {
126 return false;
127 }
buzbee67bf8852011-08-17 17:51:35 -0700128
buzbee862a7602013-04-05 10:58:54 -0700129 ArenaBitVector::Iterator iterator(bb->data_flow_info->def_v);
Bill Buzbeea114add2012-05-03 15:00:40 -0700130 while (true) {
buzbee862a7602013-04-05 10:58:54 -0700131 int idx = iterator.Next();
Brian Carlstrom0cd7ec22013-07-17 23:40:20 -0700132 if (idx == -1) {
133 break;
134 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700135 /* Block bb defines register idx */
buzbee862a7602013-04-05 10:58:54 -0700136 def_block_matrix_[idx]->SetBit(bb->id);
Bill Buzbeea114add2012-05-03 15:00:40 -0700137 }
138 return true;
buzbee67bf8852011-08-17 17:51:35 -0700139}
140
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700141void MIRGraph::ComputeDefBlockMatrix() {
buzbee311ca162013-02-28 15:56:43 -0800142 int num_registers = cu_->num_dalvik_registers;
buzbeefa57c472012-11-21 12:06:18 -0800143 /* Allocate num_dalvik_registers bit vector pointers */
buzbee311ca162013-02-28 15:56:43 -0800144 def_block_matrix_ = static_cast<ArenaBitVector**>
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700145 (arena_->Alloc(sizeof(ArenaBitVector *) * num_registers,
146 ArenaAllocator::kAllocDFInfo));
Bill Buzbeea114add2012-05-03 15:00:40 -0700147 int i;
buzbee67bf8852011-08-17 17:51:35 -0700148
buzbeefa57c472012-11-21 12:06:18 -0800149 /* Initialize num_register vectors with num_blocks bits each */
150 for (i = 0; i < num_registers; i++) {
buzbee862a7602013-04-05 10:58:54 -0700151 def_block_matrix_[i] =
152 new (arena_) ArenaBitVector(arena_, GetNumBlocks(), false, kBitMapBMatrix);
Bill Buzbeea114add2012-05-03 15:00:40 -0700153 }
buzbee56c71782013-09-05 17:13:19 -0700154 AllNodesIterator iter(this);
buzbee311ca162013-02-28 15:56:43 -0800155 for (BasicBlock* bb = iter.Next(); bb != NULL; bb = iter.Next()) {
156 FindLocalLiveIn(bb);
157 }
buzbee56c71782013-09-05 17:13:19 -0700158 AllNodesIterator iter2(this);
buzbee311ca162013-02-28 15:56:43 -0800159 for (BasicBlock* bb = iter2.Next(); bb != NULL; bb = iter2.Next()) {
160 FillDefBlockMatrix(bb);
161 }
buzbee67bf8852011-08-17 17:51:35 -0700162
Bill Buzbeea114add2012-05-03 15:00:40 -0700163 /*
164 * Also set the incoming parameters as defs in the entry block.
165 * Only need to handle the parameters for the outer method.
166 */
buzbee311ca162013-02-28 15:56:43 -0800167 int num_regs = cu_->num_dalvik_registers;
168 int in_reg = num_regs - cu_->num_ins;
buzbeefa57c472012-11-21 12:06:18 -0800169 for (; in_reg < num_regs; in_reg++) {
buzbee862a7602013-04-05 10:58:54 -0700170 def_block_matrix_[in_reg]->SetBit(GetEntryBlock()->id);
Bill Buzbeea114add2012-05-03 15:00:40 -0700171 }
buzbee67bf8852011-08-17 17:51:35 -0700172}
173
buzbeea5abf702013-04-12 14:39:29 -0700174void MIRGraph::ComputeDomPostOrderTraversal(BasicBlock* bb) {
175 if (dom_post_order_traversal_ == NULL) {
176 // First time - create the array.
177 dom_post_order_traversal_ =
buzbee0d829482013-10-11 15:24:55 -0700178 new (arena_) GrowableArray<BasicBlockId>(arena_, num_reachable_blocks_,
buzbeea5abf702013-04-12 14:39:29 -0700179 kGrowableArrayDomPostOrderTraversal);
180 } else {
181 dom_post_order_traversal_->Reset();
Bill Buzbeea114add2012-05-03 15:00:40 -0700182 }
buzbeea5abf702013-04-12 14:39:29 -0700183 ClearAllVisitedFlags();
184 std::vector<std::pair<BasicBlock*, ArenaBitVector::Iterator*> > work_stack;
185 bb->visited = true;
Brian Carlstrom413e89f2013-10-21 23:53:49 -0700186 work_stack.push_back(std::make_pair(bb, bb->i_dominated->GetIterator()));
buzbeea5abf702013-04-12 14:39:29 -0700187 while (!work_stack.empty()) {
Sebastien Hertz74e256b2013-10-04 10:40:37 +0200188 const std::pair<BasicBlock*, ArenaBitVector::Iterator*>& curr = work_stack.back();
buzbeea5abf702013-04-12 14:39:29 -0700189 BasicBlock* curr_bb = curr.first;
190 ArenaBitVector::Iterator* curr_idom_iter = curr.second;
191 int bb_idx = curr_idom_iter->Next();
192 while ((bb_idx != -1) && (NeedsVisit(GetBasicBlock(bb_idx)) == NULL)) {
193 bb_idx = curr_idom_iter->Next();
194 }
195 if (bb_idx != -1) {
196 BasicBlock* new_bb = GetBasicBlock(bb_idx);
197 new_bb->visited = true;
198 work_stack.push_back(
Brian Carlstrom413e89f2013-10-21 23:53:49 -0700199 std::make_pair(new_bb, new_bb->i_dominated->GetIterator()));
buzbeea5abf702013-04-12 14:39:29 -0700200 } else {
201 // no successor/next
buzbee0d829482013-10-11 15:24:55 -0700202 if (curr_bb->id != NullBasicBlockId) {
203 dom_post_order_traversal_->Insert(curr_bb->id);
204 }
buzbeea5abf702013-04-12 14:39:29 -0700205 work_stack.pop_back();
buzbee67bf8852011-08-17 17:51:35 -0700206
buzbeea5abf702013-04-12 14:39:29 -0700207 /* hacky loop detection */
buzbee0d829482013-10-11 15:24:55 -0700208 if ((curr_bb->taken != NullBasicBlockId) && curr_bb->dominators->IsBitSet(curr_bb->taken)) {
Bill Buzbee0b1191c2013-10-28 22:11:59 +0000209 curr_bb->nesting_depth++;
buzbeea5abf702013-04-12 14:39:29 -0700210 attributes_ |= METHOD_HAS_LOOP;
211 }
212 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700213 }
buzbee67bf8852011-08-17 17:51:35 -0700214}
215
buzbee311ca162013-02-28 15:56:43 -0800216void MIRGraph::CheckForDominanceFrontier(BasicBlock* dom_bb,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700217 const BasicBlock* succ_bb) {
Bill Buzbeea114add2012-05-03 15:00:40 -0700218 /*
219 * TODO - evaluate whether phi will ever need to be inserted into exit
220 * blocks.
221 */
buzbee0d829482013-10-11 15:24:55 -0700222 if (succ_bb->i_dom != dom_bb->id &&
buzbeefa57c472012-11-21 12:06:18 -0800223 succ_bb->block_type == kDalvikByteCode &&
224 succ_bb->hidden == false) {
buzbee862a7602013-04-05 10:58:54 -0700225 dom_bb->dom_frontier->SetBit(succ_bb->id);
Bill Buzbeea114add2012-05-03 15:00:40 -0700226 }
buzbee67bf8852011-08-17 17:51:35 -0700227}
228
229/* Worker function to compute the dominance frontier */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700230bool MIRGraph::ComputeDominanceFrontier(BasicBlock* bb) {
Bill Buzbeea114add2012-05-03 15:00:40 -0700231 /* Calculate DF_local */
buzbee0d829482013-10-11 15:24:55 -0700232 if (bb->taken != NullBasicBlockId) {
233 CheckForDominanceFrontier(bb, GetBasicBlock(bb->taken));
Bill Buzbeea114add2012-05-03 15:00:40 -0700234 }
buzbee0d829482013-10-11 15:24:55 -0700235 if (bb->fall_through != NullBasicBlockId) {
236 CheckForDominanceFrontier(bb, GetBasicBlock(bb->fall_through));
Bill Buzbeea114add2012-05-03 15:00:40 -0700237 }
buzbee0d829482013-10-11 15:24:55 -0700238 if (bb->successor_block_list_type != kNotUsed) {
239 GrowableArray<SuccessorBlockInfo*>::Iterator iterator(bb->successor_blocks);
Bill Buzbeea114add2012-05-03 15:00:40 -0700240 while (true) {
buzbee862a7602013-04-05 10:58:54 -0700241 SuccessorBlockInfo *successor_block_info = iterator.Next();
Brian Carlstrom0cd7ec22013-07-17 23:40:20 -0700242 if (successor_block_info == NULL) {
243 break;
244 }
buzbee0d829482013-10-11 15:24:55 -0700245 BasicBlock* succ_bb = GetBasicBlock(successor_block_info->block);
buzbee311ca162013-02-28 15:56:43 -0800246 CheckForDominanceFrontier(bb, succ_bb);
Bill Buzbeea114add2012-05-03 15:00:40 -0700247 }
248 }
buzbee67bf8852011-08-17 17:51:35 -0700249
Bill Buzbeea114add2012-05-03 15:00:40 -0700250 /* Calculate DF_up */
buzbee862a7602013-04-05 10:58:54 -0700251 ArenaBitVector::Iterator bv_iterator(bb->i_dominated);
Bill Buzbeea114add2012-05-03 15:00:40 -0700252 while (true) {
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700253 // TUNING: hot call to BitVectorIteratorNext
buzbee862a7602013-04-05 10:58:54 -0700254 int dominated_idx = bv_iterator.Next();
Brian Carlstrom0cd7ec22013-07-17 23:40:20 -0700255 if (dominated_idx == -1) {
256 break;
257 }
buzbee311ca162013-02-28 15:56:43 -0800258 BasicBlock* dominated_bb = GetBasicBlock(dominated_idx);
buzbee862a7602013-04-05 10:58:54 -0700259 ArenaBitVector::Iterator df_iterator(dominated_bb->dom_frontier);
buzbee67bf8852011-08-17 17:51:35 -0700260 while (true) {
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700261 // TUNING: hot call to BitVectorIteratorNext
buzbee862a7602013-04-05 10:58:54 -0700262 int df_up_idx = df_iterator.Next();
Brian Carlstrom0cd7ec22013-07-17 23:40:20 -0700263 if (df_up_idx == -1) {
264 break;
265 }
buzbee311ca162013-02-28 15:56:43 -0800266 BasicBlock* df_up_block = GetBasicBlock(df_up_idx);
267 CheckForDominanceFrontier(bb, df_up_block);
buzbee67bf8852011-08-17 17:51:35 -0700268 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700269 }
buzbee67bf8852011-08-17 17:51:35 -0700270
Bill Buzbeea114add2012-05-03 15:00:40 -0700271 return true;
buzbee67bf8852011-08-17 17:51:35 -0700272}
273
274/* Worker function for initializing domination-related data structures */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700275void MIRGraph::InitializeDominationInfo(BasicBlock* bb) {
buzbee311ca162013-02-28 15:56:43 -0800276 int num_total_blocks = GetBasicBlockListCount();
buzbee67bf8852011-08-17 17:51:35 -0700277
Brian Carlstromdf629502013-07-17 22:39:56 -0700278 if (bb->dominators == NULL) {
buzbee862a7602013-04-05 10:58:54 -0700279 bb->dominators = new (arena_) ArenaBitVector(arena_, num_total_blocks,
280 false /* expandable */, kBitMapDominators);
281 bb->i_dominated = new (arena_) ArenaBitVector(arena_, num_total_blocks,
282 false /* expandable */, kBitMapIDominated);
283 bb->dom_frontier = new (arena_) ArenaBitVector(arena_, num_total_blocks,
284 false /* expandable */, kBitMapDomFrontier);
Bill Buzbeea114add2012-05-03 15:00:40 -0700285 } else {
buzbee862a7602013-04-05 10:58:54 -0700286 bb->dominators->ClearAllBits();
287 bb->i_dominated->ClearAllBits();
288 bb->dom_frontier->ClearAllBits();
Bill Buzbeea114add2012-05-03 15:00:40 -0700289 }
290 /* Set all bits in the dominator vector */
buzbee862a7602013-04-05 10:58:54 -0700291 bb->dominators->SetInitialBits(num_total_blocks);
buzbee67bf8852011-08-17 17:51:35 -0700292
buzbee862a7602013-04-05 10:58:54 -0700293 return;
buzbee67bf8852011-08-17 17:51:35 -0700294}
295
buzbee5b537102012-01-17 17:33:47 -0800296/*
buzbeefa57c472012-11-21 12:06:18 -0800297 * Walk through the ordered i_dom list until we reach common parent.
298 * Given the ordering of i_dom_list, this common parent represents the
buzbee5b537102012-01-17 17:33:47 -0800299 * last element of the intersection of block1 and block2 dominators.
300 */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700301int MIRGraph::FindCommonParent(int block1, int block2) {
Bill Buzbeea114add2012-05-03 15:00:40 -0700302 while (block1 != block2) {
303 while (block1 < block2) {
buzbee311ca162013-02-28 15:56:43 -0800304 block1 = i_dom_list_[block1];
Bill Buzbeea114add2012-05-03 15:00:40 -0700305 DCHECK_NE(block1, NOTVISITED);
buzbee5b537102012-01-17 17:33:47 -0800306 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700307 while (block2 < block1) {
buzbee311ca162013-02-28 15:56:43 -0800308 block2 = i_dom_list_[block2];
Bill Buzbeea114add2012-05-03 15:00:40 -0700309 DCHECK_NE(block2, NOTVISITED);
310 }
311 }
312 return block1;
buzbee5b537102012-01-17 17:33:47 -0800313}
314
315/* Worker function to compute each block's immediate dominator */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700316bool MIRGraph::ComputeblockIDom(BasicBlock* bb) {
Bill Buzbeea114add2012-05-03 15:00:40 -0700317 /* Special-case entry block */
buzbee0d829482013-10-11 15:24:55 -0700318 if ((bb->id == NullBasicBlockId) || (bb == GetEntryBlock())) {
buzbee5b537102012-01-17 17:33:47 -0800319 return false;
Bill Buzbeea114add2012-05-03 15:00:40 -0700320 }
321
322 /* Iterate through the predecessors */
buzbee0d829482013-10-11 15:24:55 -0700323 GrowableArray<BasicBlockId>::Iterator iter(bb->predecessors);
Bill Buzbeea114add2012-05-03 15:00:40 -0700324
325 /* Find the first processed predecessor */
buzbee862a7602013-04-05 10:58:54 -0700326 int idom = -1;
Bill Buzbeea114add2012-05-03 15:00:40 -0700327 while (true) {
buzbee0d829482013-10-11 15:24:55 -0700328 BasicBlock* pred_bb = GetBasicBlock(iter.Next());
buzbeefa57c472012-11-21 12:06:18 -0800329 CHECK(pred_bb != NULL);
buzbee311ca162013-02-28 15:56:43 -0800330 if (i_dom_list_[pred_bb->dfs_id] != NOTVISITED) {
buzbeefa57c472012-11-21 12:06:18 -0800331 idom = pred_bb->dfs_id;
Bill Buzbeea114add2012-05-03 15:00:40 -0700332 break;
333 }
334 }
335
336 /* Scan the rest of the predecessors */
337 while (true) {
buzbee0d829482013-10-11 15:24:55 -0700338 BasicBlock* pred_bb = GetBasicBlock(iter.Next());
Brian Carlstrom0cd7ec22013-07-17 23:40:20 -0700339 if (!pred_bb) {
340 break;
341 }
buzbee311ca162013-02-28 15:56:43 -0800342 if (i_dom_list_[pred_bb->dfs_id] == NOTVISITED) {
Bill Buzbeea114add2012-05-03 15:00:40 -0700343 continue;
344 } else {
buzbee311ca162013-02-28 15:56:43 -0800345 idom = FindCommonParent(pred_bb->dfs_id, idom);
Bill Buzbeea114add2012-05-03 15:00:40 -0700346 }
347 }
348
349 DCHECK_NE(idom, NOTVISITED);
350
351 /* Did something change? */
buzbee311ca162013-02-28 15:56:43 -0800352 if (i_dom_list_[bb->dfs_id] != idom) {
353 i_dom_list_[bb->dfs_id] = idom;
Bill Buzbeea114add2012-05-03 15:00:40 -0700354 return true;
355 }
356 return false;
buzbee5b537102012-01-17 17:33:47 -0800357}
358
359/* Worker function to compute each block's domintors */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700360bool MIRGraph::ComputeBlockDominators(BasicBlock* bb) {
buzbee311ca162013-02-28 15:56:43 -0800361 if (bb == GetEntryBlock()) {
buzbee862a7602013-04-05 10:58:54 -0700362 bb->dominators->ClearAllBits();
Bill Buzbeea114add2012-05-03 15:00:40 -0700363 } else {
buzbee0d829482013-10-11 15:24:55 -0700364 bb->dominators->Copy(GetBasicBlock(bb->i_dom)->dominators);
Bill Buzbeea114add2012-05-03 15:00:40 -0700365 }
buzbee862a7602013-04-05 10:58:54 -0700366 bb->dominators->SetBit(bb->id);
Bill Buzbeea114add2012-05-03 15:00:40 -0700367 return false;
buzbee5b537102012-01-17 17:33:47 -0800368}
369
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700370bool MIRGraph::SetDominators(BasicBlock* bb) {
buzbee311ca162013-02-28 15:56:43 -0800371 if (bb != GetEntryBlock()) {
372 int idom_dfs_idx = i_dom_list_[bb->dfs_id];
buzbeefa57c472012-11-21 12:06:18 -0800373 DCHECK_NE(idom_dfs_idx, NOTVISITED);
buzbee862a7602013-04-05 10:58:54 -0700374 int i_dom_idx = dfs_post_order_->Get(idom_dfs_idx);
buzbee311ca162013-02-28 15:56:43 -0800375 BasicBlock* i_dom = GetBasicBlock(i_dom_idx);
buzbee0d829482013-10-11 15:24:55 -0700376 bb->i_dom = i_dom->id;
buzbeefa57c472012-11-21 12:06:18 -0800377 /* Add bb to the i_dominated set of the immediate dominator block */
buzbee862a7602013-04-05 10:58:54 -0700378 i_dom->i_dominated->SetBit(bb->id);
Bill Buzbeea114add2012-05-03 15:00:40 -0700379 }
380 return false;
buzbee5b537102012-01-17 17:33:47 -0800381}
382
buzbee67bf8852011-08-17 17:51:35 -0700383/* Compute dominators, immediate dominator, and dominance fronter */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700384void MIRGraph::ComputeDominators() {
buzbee311ca162013-02-28 15:56:43 -0800385 int num_reachable_blocks = num_reachable_blocks_;
386 int num_total_blocks = GetBasicBlockListCount();
buzbee67bf8852011-08-17 17:51:35 -0700387
Bill Buzbeea114add2012-05-03 15:00:40 -0700388 /* Initialize domination-related data structures */
buzbee56c71782013-09-05 17:13:19 -0700389 PreOrderDfsIterator iter(this);
buzbee311ca162013-02-28 15:56:43 -0800390 for (BasicBlock* bb = iter.Next(); bb != NULL; bb = iter.Next()) {
391 InitializeDominationInfo(bb);
392 }
buzbee67bf8852011-08-17 17:51:35 -0700393
buzbeefa57c472012-11-21 12:06:18 -0800394 /* Initalize & Clear i_dom_list */
buzbee311ca162013-02-28 15:56:43 -0800395 if (i_dom_list_ == NULL) {
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700396 i_dom_list_ = static_cast<int*>(arena_->Alloc(sizeof(int) * num_reachable_blocks,
397 ArenaAllocator::kAllocDFInfo));
Bill Buzbeea114add2012-05-03 15:00:40 -0700398 }
buzbeefa57c472012-11-21 12:06:18 -0800399 for (int i = 0; i < num_reachable_blocks; i++) {
buzbee311ca162013-02-28 15:56:43 -0800400 i_dom_list_[i] = NOTVISITED;
Bill Buzbeea114add2012-05-03 15:00:40 -0700401 }
buzbee5b537102012-01-17 17:33:47 -0800402
buzbeefa57c472012-11-21 12:06:18 -0800403 /* For post-order, last block is entry block. Set its i_dom to istelf */
buzbee311ca162013-02-28 15:56:43 -0800404 DCHECK_EQ(GetEntryBlock()->dfs_id, num_reachable_blocks-1);
405 i_dom_list_[GetEntryBlock()->dfs_id] = GetEntryBlock()->dfs_id;
buzbee5b537102012-01-17 17:33:47 -0800406
Bill Buzbeea114add2012-05-03 15:00:40 -0700407 /* Compute the immediate dominators */
buzbee56c71782013-09-05 17:13:19 -0700408 RepeatingReversePostOrderDfsIterator iter2(this);
buzbee311ca162013-02-28 15:56:43 -0800409 bool change = false;
410 for (BasicBlock* bb = iter2.Next(false); bb != NULL; bb = iter2.Next(change)) {
411 change = ComputeblockIDom(bb);
412 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700413
414 /* Set the dominator for the root node */
buzbee862a7602013-04-05 10:58:54 -0700415 GetEntryBlock()->dominators->ClearAllBits();
416 GetEntryBlock()->dominators->SetBit(GetEntryBlock()->id);
Bill Buzbeea114add2012-05-03 15:00:40 -0700417
buzbee311ca162013-02-28 15:56:43 -0800418 if (temp_block_v_ == NULL) {
buzbee862a7602013-04-05 10:58:54 -0700419 temp_block_v_ = new (arena_) ArenaBitVector(arena_, num_total_blocks,
420 false /* expandable */, kBitMapTmpBlockV);
Bill Buzbeea114add2012-05-03 15:00:40 -0700421 } else {
buzbee862a7602013-04-05 10:58:54 -0700422 temp_block_v_->ClearAllBits();
Bill Buzbeea114add2012-05-03 15:00:40 -0700423 }
buzbee0d829482013-10-11 15:24:55 -0700424 GetEntryBlock()->i_dom = 0;
Bill Buzbeea114add2012-05-03 15:00:40 -0700425
buzbee56c71782013-09-05 17:13:19 -0700426 PreOrderDfsIterator iter3(this);
buzbee311ca162013-02-28 15:56:43 -0800427 for (BasicBlock* bb = iter3.Next(); bb != NULL; bb = iter3.Next()) {
428 SetDominators(bb);
Bill Buzbeea114add2012-05-03 15:00:40 -0700429 }
buzbee67bf8852011-08-17 17:51:35 -0700430
buzbee56c71782013-09-05 17:13:19 -0700431 ReversePostOrderDfsIterator iter4(this);
buzbee311ca162013-02-28 15:56:43 -0800432 for (BasicBlock* bb = iter4.Next(); bb != NULL; bb = iter4.Next()) {
433 ComputeBlockDominators(bb);
434 }
buzbee5b537102012-01-17 17:33:47 -0800435
buzbeea5abf702013-04-12 14:39:29 -0700436 // Compute the dominance frontier for each block.
buzbee311ca162013-02-28 15:56:43 -0800437 ComputeDomPostOrderTraversal(GetEntryBlock());
buzbee56c71782013-09-05 17:13:19 -0700438 PostOrderDOMIterator iter5(this);
buzbee311ca162013-02-28 15:56:43 -0800439 for (BasicBlock* bb = iter5.Next(); bb != NULL; bb = iter5.Next()) {
440 ComputeDominanceFrontier(bb);
441 }
buzbee67bf8852011-08-17 17:51:35 -0700442}
443
444/*
445 * Perform dest U= src1 ^ ~src2
446 * This is probably not general enough to be placed in BitVector.[ch].
447 */
buzbee311ca162013-02-28 15:56:43 -0800448void MIRGraph::ComputeSuccLineIn(ArenaBitVector* dest, const ArenaBitVector* src1,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700449 const ArenaBitVector* src2) {
buzbee862a7602013-04-05 10:58:54 -0700450 if (dest->GetStorageSize() != src1->GetStorageSize() ||
451 dest->GetStorageSize() != src2->GetStorageSize() ||
452 dest->IsExpandable() != src1->IsExpandable() ||
453 dest->IsExpandable() != src2->IsExpandable()) {
Bill Buzbeea114add2012-05-03 15:00:40 -0700454 LOG(FATAL) << "Incompatible set properties";
455 }
buzbee67bf8852011-08-17 17:51:35 -0700456
Bill Buzbeea114add2012-05-03 15:00:40 -0700457 unsigned int idx;
buzbee862a7602013-04-05 10:58:54 -0700458 for (idx = 0; idx < dest->GetStorageSize(); idx++) {
459 dest->GetRawStorage()[idx] |= src1->GetRawStorageWord(idx) & ~(src2->GetRawStorageWord(idx));
Bill Buzbeea114add2012-05-03 15:00:40 -0700460 }
buzbee67bf8852011-08-17 17:51:35 -0700461}
462
463/*
464 * Iterate through all successor blocks and propagate up the live-in sets.
465 * The calculated result is used for phi-node pruning - where we only need to
466 * insert a phi node if the variable is live-in to the block.
467 */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700468bool MIRGraph::ComputeBlockLiveIns(BasicBlock* bb) {
buzbee311ca162013-02-28 15:56:43 -0800469 ArenaBitVector* temp_dalvik_register_v = temp_dalvik_register_v_;
buzbee67bf8852011-08-17 17:51:35 -0700470
Brian Carlstrom0cd7ec22013-07-17 23:40:20 -0700471 if (bb->data_flow_info == NULL) {
472 return false;
473 }
buzbee862a7602013-04-05 10:58:54 -0700474 temp_dalvik_register_v->Copy(bb->data_flow_info->live_in_v);
buzbee0d829482013-10-11 15:24:55 -0700475 BasicBlock* bb_taken = GetBasicBlock(bb->taken);
476 BasicBlock* bb_fall_through = GetBasicBlock(bb->fall_through);
477 if (bb_taken && bb_taken->data_flow_info)
478 ComputeSuccLineIn(temp_dalvik_register_v, bb_taken->data_flow_info->live_in_v,
buzbeefa57c472012-11-21 12:06:18 -0800479 bb->data_flow_info->def_v);
buzbee0d829482013-10-11 15:24:55 -0700480 if (bb_fall_through && bb_fall_through->data_flow_info)
481 ComputeSuccLineIn(temp_dalvik_register_v, bb_fall_through->data_flow_info->live_in_v,
buzbeefa57c472012-11-21 12:06:18 -0800482 bb->data_flow_info->def_v);
buzbee0d829482013-10-11 15:24:55 -0700483 if (bb->successor_block_list_type != kNotUsed) {
484 GrowableArray<SuccessorBlockInfo*>::Iterator iterator(bb->successor_blocks);
Bill Buzbeea114add2012-05-03 15:00:40 -0700485 while (true) {
buzbee862a7602013-04-05 10:58:54 -0700486 SuccessorBlockInfo *successor_block_info = iterator.Next();
Brian Carlstrom0cd7ec22013-07-17 23:40:20 -0700487 if (successor_block_info == NULL) {
488 break;
489 }
buzbee0d829482013-10-11 15:24:55 -0700490 BasicBlock* succ_bb = GetBasicBlock(successor_block_info->block);
buzbeefa57c472012-11-21 12:06:18 -0800491 if (succ_bb->data_flow_info) {
buzbee311ca162013-02-28 15:56:43 -0800492 ComputeSuccLineIn(temp_dalvik_register_v, succ_bb->data_flow_info->live_in_v,
buzbeefa57c472012-11-21 12:06:18 -0800493 bb->data_flow_info->def_v);
Bill Buzbeea114add2012-05-03 15:00:40 -0700494 }
buzbee67bf8852011-08-17 17:51:35 -0700495 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700496 }
buzbee862a7602013-04-05 10:58:54 -0700497 if (!temp_dalvik_register_v->Equal(bb->data_flow_info->live_in_v)) {
498 bb->data_flow_info->live_in_v->Copy(temp_dalvik_register_v);
Bill Buzbeea114add2012-05-03 15:00:40 -0700499 return true;
500 }
501 return false;
buzbee67bf8852011-08-17 17:51:35 -0700502}
503
504/* Insert phi nodes to for each variable to the dominance frontiers */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700505void MIRGraph::InsertPhiNodes() {
buzbeefa57c472012-11-21 12:06:18 -0800506 int dalvik_reg;
buzbee862a7602013-04-05 10:58:54 -0700507 ArenaBitVector* phi_blocks =
508 new (arena_) ArenaBitVector(arena_, GetNumBlocks(), false, kBitMapPhi);
509 ArenaBitVector* tmp_blocks =
510 new (arena_) ArenaBitVector(arena_, GetNumBlocks(), false, kBitMapTmpBlocks);
511 ArenaBitVector* input_blocks =
512 new (arena_) ArenaBitVector(arena_, GetNumBlocks(), false, kBitMapInputBlocks);
buzbee67bf8852011-08-17 17:51:35 -0700513
buzbee311ca162013-02-28 15:56:43 -0800514 temp_dalvik_register_v_ =
buzbee862a7602013-04-05 10:58:54 -0700515 new (arena_) ArenaBitVector(arena_, cu_->num_dalvik_registers, false, kBitMapRegisterV);
buzbee67bf8852011-08-17 17:51:35 -0700516
buzbee56c71782013-09-05 17:13:19 -0700517 RepeatingPostOrderDfsIterator iter(this);
buzbee311ca162013-02-28 15:56:43 -0800518 bool change = false;
519 for (BasicBlock* bb = iter.Next(false); bb != NULL; bb = iter.Next(change)) {
520 change = ComputeBlockLiveIns(bb);
521 }
buzbee67bf8852011-08-17 17:51:35 -0700522
Bill Buzbeea114add2012-05-03 15:00:40 -0700523 /* Iterate through each Dalvik register */
buzbee311ca162013-02-28 15:56:43 -0800524 for (dalvik_reg = cu_->num_dalvik_registers - 1; dalvik_reg >= 0; dalvik_reg--) {
Bill Buzbeea114add2012-05-03 15:00:40 -0700525 bool change;
buzbee67bf8852011-08-17 17:51:35 -0700526
buzbee862a7602013-04-05 10:58:54 -0700527 input_blocks->Copy(def_block_matrix_[dalvik_reg]);
528 phi_blocks->ClearAllBits();
buzbee67bf8852011-08-17 17:51:35 -0700529
Bill Buzbeea114add2012-05-03 15:00:40 -0700530 /* Calculate the phi blocks for each Dalvik register */
531 do {
532 change = false;
buzbee862a7602013-04-05 10:58:54 -0700533 tmp_blocks->ClearAllBits();
534 ArenaBitVector::Iterator iterator(input_blocks);
buzbee67bf8852011-08-17 17:51:35 -0700535
Bill Buzbeea114add2012-05-03 15:00:40 -0700536 while (true) {
buzbee862a7602013-04-05 10:58:54 -0700537 int idx = iterator.Next();
Brian Carlstrom0cd7ec22013-07-17 23:40:20 -0700538 if (idx == -1) {
539 break;
buzbee67bf8852011-08-17 17:51:35 -0700540 }
Brian Carlstrom0cd7ec22013-07-17 23:40:20 -0700541 BasicBlock* def_bb = GetBasicBlock(idx);
Bill Buzbeea114add2012-05-03 15:00:40 -0700542
Brian Carlstrom0cd7ec22013-07-17 23:40:20 -0700543 /* Merge the dominance frontier to tmp_blocks */
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700544 // TUNING: hot call to Union().
Brian Carlstrom0cd7ec22013-07-17 23:40:20 -0700545 if (def_bb->dom_frontier != NULL) {
546 tmp_blocks->Union(def_bb->dom_frontier);
547 }
548 }
549 if (!phi_blocks->Equal(tmp_blocks)) {
550 change = true;
551 phi_blocks->Copy(tmp_blocks);
552
553 /*
554 * Iterate through the original blocks plus the new ones in
555 * the dominance frontier.
556 */
557 input_blocks->Copy(phi_blocks);
558 input_blocks->Union(def_block_matrix_[dalvik_reg]);
Bill Buzbeea114add2012-05-03 15:00:40 -0700559 }
560 } while (change);
561
562 /*
buzbeefa57c472012-11-21 12:06:18 -0800563 * Insert a phi node for dalvik_reg in the phi_blocks if the Dalvik
Bill Buzbeea114add2012-05-03 15:00:40 -0700564 * register is in the live-in set.
565 */
buzbee862a7602013-04-05 10:58:54 -0700566 ArenaBitVector::Iterator iterator(phi_blocks);
Bill Buzbeea114add2012-05-03 15:00:40 -0700567 while (true) {
buzbee862a7602013-04-05 10:58:54 -0700568 int idx = iterator.Next();
Brian Carlstrom0cd7ec22013-07-17 23:40:20 -0700569 if (idx == -1) {
570 break;
571 }
buzbee311ca162013-02-28 15:56:43 -0800572 BasicBlock* phi_bb = GetBasicBlock(idx);
Bill Buzbeea114add2012-05-03 15:00:40 -0700573 /* Variable will be clobbered before being used - no need for phi */
Brian Carlstrom0cd7ec22013-07-17 23:40:20 -0700574 if (!phi_bb->data_flow_info->live_in_v->IsBitSet(dalvik_reg)) {
575 continue;
576 }
buzbee862a7602013-04-05 10:58:54 -0700577 MIR *phi =
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700578 static_cast<MIR*>(arena_->Alloc(sizeof(MIR), ArenaAllocator::kAllocDFInfo));
buzbeecbd6d442012-11-17 14:11:25 -0800579 phi->dalvikInsn.opcode = static_cast<Instruction::Code>(kMirOpPhi);
buzbeefa57c472012-11-21 12:06:18 -0800580 phi->dalvikInsn.vA = dalvik_reg;
581 phi->offset = phi_bb->start_offset;
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700582 phi->m_unit_index = 0; // Arbitrarily assign all Phi nodes to outermost method.
buzbeefa57c472012-11-21 12:06:18 -0800583 PrependMIR(phi_bb, phi);
buzbee67bf8852011-08-17 17:51:35 -0700584 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700585 }
buzbee67bf8852011-08-17 17:51:35 -0700586}
587
588/*
589 * Worker function to insert phi-operands with latest SSA names from
590 * predecessor blocks
591 */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700592bool MIRGraph::InsertPhiNodeOperands(BasicBlock* bb) {
Bill Buzbeea114add2012-05-03 15:00:40 -0700593 /* Phi nodes are at the beginning of each block */
buzbee0d829482013-10-11 15:24:55 -0700594 for (MIR* mir = bb->first_mir_insn; mir != NULL; mir = mir->next) {
buzbeecbd6d442012-11-17 14:11:25 -0800595 if (mir->dalvikInsn.opcode != static_cast<Instruction::Code>(kMirOpPhi))
Bill Buzbeea114add2012-05-03 15:00:40 -0700596 return true;
buzbeefa57c472012-11-21 12:06:18 -0800597 int ssa_reg = mir->ssa_rep->defs[0];
598 DCHECK_GE(ssa_reg, 0); // Shouldn't see compiler temps here
buzbee311ca162013-02-28 15:56:43 -0800599 int v_reg = SRegToVReg(ssa_reg);
buzbee67bf8852011-08-17 17:51:35 -0700600
Bill Buzbeea114add2012-05-03 15:00:40 -0700601 /* Iterate through the predecessors */
buzbee0d829482013-10-11 15:24:55 -0700602 GrowableArray<BasicBlockId>::Iterator iter(bb->predecessors);
603 size_t num_uses = bb->predecessors->Size();
604 mir->ssa_rep->num_uses = num_uses;
605 int* uses = static_cast<int*>(arena_->Alloc(sizeof(int) * num_uses,
606 ArenaAllocator::kAllocDFInfo));
607 mir->ssa_rep->uses = uses;
608 mir->ssa_rep->fp_use =
609 static_cast<bool*>(arena_->Alloc(sizeof(bool) * num_uses, ArenaAllocator::kAllocDFInfo));
610 BasicBlockId* incoming =
611 static_cast<BasicBlockId*>(arena_->Alloc(sizeof(BasicBlockId) * num_uses,
612 ArenaAllocator::kAllocDFInfo));
613 mir->meta.phi_incoming = incoming;
614 int idx = 0;
Bill Buzbeea114add2012-05-03 15:00:40 -0700615 while (true) {
buzbee0d829482013-10-11 15:24:55 -0700616 BasicBlock* pred_bb = GetBasicBlock(iter.Next());
Brian Carlstrom0cd7ec22013-07-17 23:40:20 -0700617 if (!pred_bb) {
618 break;
619 }
buzbeefa57c472012-11-21 12:06:18 -0800620 int ssa_reg = pred_bb->data_flow_info->vreg_to_ssa_map[v_reg];
buzbee0d829482013-10-11 15:24:55 -0700621 uses[idx] = ssa_reg;
622 incoming[idx] = pred_bb->id;
623 idx++;
Bill Buzbeea114add2012-05-03 15:00:40 -0700624 }
625 }
626
627 return true;
buzbee67bf8852011-08-17 17:51:35 -0700628}
629
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700630void MIRGraph::DoDFSPreOrderSSARename(BasicBlock* block) {
Brian Carlstrom0cd7ec22013-07-17 23:40:20 -0700631 if (block->visited || block->hidden) {
632 return;
633 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700634 block->visited = true;
buzbeef0cde542011-09-13 14:55:02 -0700635
Bill Buzbeea114add2012-05-03 15:00:40 -0700636 /* Process this block */
buzbee311ca162013-02-28 15:56:43 -0800637 DoSSAConversion(block);
638 int map_size = sizeof(int) * cu_->num_dalvik_registers;
buzbeef0cde542011-09-13 14:55:02 -0700639
Bill Buzbeea114add2012-05-03 15:00:40 -0700640 /* Save SSA map snapshot */
buzbee862a7602013-04-05 10:58:54 -0700641 int* saved_ssa_map =
Mathieu Chartierf6c4b3b2013-08-24 16:11:37 -0700642 static_cast<int*>(arena_->Alloc(map_size, ArenaAllocator::kAllocDalvikToSSAMap));
buzbee311ca162013-02-28 15:56:43 -0800643 memcpy(saved_ssa_map, vreg_to_ssa_map_, map_size);
buzbeef0cde542011-09-13 14:55:02 -0700644
buzbee0d829482013-10-11 15:24:55 -0700645 if (block->fall_through != NullBasicBlockId) {
646 DoDFSPreOrderSSARename(GetBasicBlock(block->fall_through));
Bill Buzbeea114add2012-05-03 15:00:40 -0700647 /* Restore SSA map snapshot */
buzbee311ca162013-02-28 15:56:43 -0800648 memcpy(vreg_to_ssa_map_, saved_ssa_map, map_size);
Bill Buzbeea114add2012-05-03 15:00:40 -0700649 }
buzbee0d829482013-10-11 15:24:55 -0700650 if (block->taken != NullBasicBlockId) {
651 DoDFSPreOrderSSARename(GetBasicBlock(block->taken));
Bill Buzbeea114add2012-05-03 15:00:40 -0700652 /* Restore SSA map snapshot */
buzbee311ca162013-02-28 15:56:43 -0800653 memcpy(vreg_to_ssa_map_, saved_ssa_map, map_size);
Bill Buzbeea114add2012-05-03 15:00:40 -0700654 }
buzbee0d829482013-10-11 15:24:55 -0700655 if (block->successor_block_list_type != kNotUsed) {
656 GrowableArray<SuccessorBlockInfo*>::Iterator iterator(block->successor_blocks);
Bill Buzbeea114add2012-05-03 15:00:40 -0700657 while (true) {
buzbee862a7602013-04-05 10:58:54 -0700658 SuccessorBlockInfo *successor_block_info = iterator.Next();
Brian Carlstrom0cd7ec22013-07-17 23:40:20 -0700659 if (successor_block_info == NULL) {
660 break;
661 }
buzbee0d829482013-10-11 15:24:55 -0700662 BasicBlock* succ_bb = GetBasicBlock(successor_block_info->block);
buzbee311ca162013-02-28 15:56:43 -0800663 DoDFSPreOrderSSARename(succ_bb);
Bill Buzbeea114add2012-05-03 15:00:40 -0700664 /* Restore SSA map snapshot */
buzbee311ca162013-02-28 15:56:43 -0800665 memcpy(vreg_to_ssa_map_, saved_ssa_map, map_size);
buzbeef0cde542011-09-13 14:55:02 -0700666 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700667 }
buzbee311ca162013-02-28 15:56:43 -0800668 vreg_to_ssa_map_ = saved_ssa_map;
Bill Buzbeea114add2012-05-03 15:00:40 -0700669 return;
buzbeef0cde542011-09-13 14:55:02 -0700670}
671
Elliott Hughes11d1b0c2012-01-23 16:57:47 -0800672} // namespace art