buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
buzbee | eaf09bc | 2012-11-15 14:51:41 -0800 | [diff] [blame] | 17 | #include "compiler_internals.h" |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 18 | #include "dataflow.h" |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 19 | |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 20 | namespace art { |
| 21 | |
buzbee | e5f0122 | 2012-06-14 15:19:35 -0700 | [diff] [blame] | 22 | // Make sure iterative dfs recording matches old recursive version |
| 23 | //#define TEST_DFS |
| 24 | |
buzbee | aad9438 | 2012-11-21 07:40:50 -0800 | [diff] [blame] | 25 | static BasicBlock* NeedsVisit(BasicBlock* bb) { |
buzbee | e5f0122 | 2012-06-14 15:19:35 -0700 | [diff] [blame] | 26 | if (bb != NULL) { |
| 27 | if (bb->visited || bb->hidden) { |
| 28 | bb = NULL; |
| 29 | } |
| 30 | } |
| 31 | return bb; |
| 32 | } |
| 33 | |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 34 | static BasicBlock* NextUnvisitedSuccessor(BasicBlock* bb) |
buzbee | e5f0122 | 2012-06-14 15:19:35 -0700 | [diff] [blame] | 35 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 36 | BasicBlock* res = NeedsVisit(bb->fall_through); |
buzbee | e5f0122 | 2012-06-14 15:19:35 -0700 | [diff] [blame] | 37 | if (res == NULL) { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 38 | res = NeedsVisit(bb->taken); |
buzbee | e5f0122 | 2012-06-14 15:19:35 -0700 | [diff] [blame] | 39 | if (res == NULL) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 40 | if (bb->successor_block_list.block_list_type != kNotUsed) { |
buzbee | e5f0122 | 2012-06-14 15:19:35 -0700 | [diff] [blame] | 41 | GrowableListIterator iterator; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 42 | GrowableListIteratorInit(&bb->successor_block_list.blocks, |
buzbee | e5f0122 | 2012-06-14 15:19:35 -0700 | [diff] [blame] | 43 | &iterator); |
| 44 | while (true) { |
buzbee | cbd6d44 | 2012-11-17 14:11:25 -0800 | [diff] [blame] | 45 | SuccessorBlockInfo *sbi = reinterpret_cast<SuccessorBlockInfo*> |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 46 | (GrowableListIteratorNext(&iterator)); |
buzbee | e5f0122 | 2012-06-14 15:19:35 -0700 | [diff] [blame] | 47 | if (sbi == NULL) break; |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 48 | res = NeedsVisit(sbi->block); |
buzbee | e5f0122 | 2012-06-14 15:19:35 -0700 | [diff] [blame] | 49 | if (res != NULL) break; |
| 50 | } |
| 51 | } |
| 52 | } |
| 53 | } |
| 54 | return res; |
| 55 | } |
| 56 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 57 | static void MarkPreOrder(CompilationUnit* cu, BasicBlock* block) |
buzbee | e5f0122 | 2012-06-14 15:19:35 -0700 | [diff] [blame] | 58 | { |
| 59 | block->visited = true; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 60 | /* Enqueue the pre_order block id */ |
| 61 | InsertGrowableList(cu, &cu->dfs_order, block->id); |
buzbee | e5f0122 | 2012-06-14 15:19:35 -0700 | [diff] [blame] | 62 | } |
| 63 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 64 | static void RecordDFSOrders(CompilationUnit* cu, BasicBlock* block) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 65 | { |
buzbee | e5f0122 | 2012-06-14 15:19:35 -0700 | [diff] [blame] | 66 | std::vector<BasicBlock*> succ; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 67 | MarkPreOrder(cu, block); |
buzbee | e5f0122 | 2012-06-14 15:19:35 -0700 | [diff] [blame] | 68 | succ.push_back(block); |
| 69 | while (!succ.empty()) { |
| 70 | BasicBlock* curr = succ.back(); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 71 | BasicBlock* next_successor = NextUnvisitedSuccessor(curr); |
| 72 | if (next_successor != NULL) { |
| 73 | MarkPreOrder(cu, next_successor); |
| 74 | succ.push_back(next_successor); |
buzbee | e5f0122 | 2012-06-14 15:19:35 -0700 | [diff] [blame] | 75 | continue; |
| 76 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 77 | curr->dfs_id = cu->dfs_post_order.num_used; |
| 78 | InsertGrowableList(cu, &cu->dfs_post_order, curr->id); |
buzbee | e5f0122 | 2012-06-14 15:19:35 -0700 | [diff] [blame] | 79 | succ.pop_back(); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | #if defined(TEST_DFS) |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 84 | /* Enter the node to the dfs_order list then visit its successors */ |
| 85 | static void RecursiveRecordDFSOrders(CompilationUnit* cu, BasicBlock* block) |
buzbee | e5f0122 | 2012-06-14 15:19:35 -0700 | [diff] [blame] | 86 | { |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 87 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 88 | if (block->visited || block->hidden) return; |
| 89 | block->visited = true; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 90 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 91 | // Can this block be reached only via previous block fallthrough? |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 92 | if ((block->block_type == kDalvikByteCode) && |
| 93 | (block->predecessors->num_used == 1)) { |
| 94 | DCHECK_GE(cu->dfs_order.num_used, 1U); |
| 95 | int prev_idx = cu->dfs_order.num_used - 1; |
| 96 | int prev_id = cu->dfs_order.elem_list[prev_idx]; |
| 97 | BasicBlock* pred_bb = (BasicBlock*)block->predecessors->elem_list[0]; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 98 | } |
buzbee | 3d66194 | 2012-03-14 17:37:27 -0700 | [diff] [blame] | 99 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 100 | /* Enqueue the pre_order block id */ |
| 101 | InsertGrowableList(cu, &cu->dfs_order, block->id); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 102 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 103 | if (block->fall_through) { |
| 104 | RecursiveRecordDFSOrders(cu, block->fall_through); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 105 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 106 | if (block->taken) RecursiveRecordDFSOrders(cu, block->taken); |
| 107 | if (block->successor_block_list.block_list_type != kNotUsed) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 108 | GrowableListIterator iterator; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 109 | GrowableListIteratorInit(&block->successor_block_list.blocks, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 110 | &iterator); |
| 111 | while (true) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 112 | SuccessorBlockInfo *successor_block_info = |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 113 | (SuccessorBlockInfo *) GrowableListIteratorNext(&iterator); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 114 | if (successor_block_info == NULL) break; |
| 115 | BasicBlock* succ_bb = successor_block_info->block; |
| 116 | RecursiveRecordDFSOrders(cu, succ_bb); |
buzbee | e196567 | 2012-03-11 18:39:19 -0700 | [diff] [blame] | 117 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 118 | } |
buzbee | 5b53710 | 2012-01-17 17:33:47 -0800 | [diff] [blame] | 119 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 120 | /* Record postorder in basic block and enqueue normal id in dfs_post_order */ |
| 121 | block->dfs_id = cu->dfs_post_order.num_used; |
| 122 | InsertGrowableList(cu, &cu->dfs_post_order, block->id); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 123 | return; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 124 | } |
buzbee | e5f0122 | 2012-06-14 15:19:35 -0700 | [diff] [blame] | 125 | #endif |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 126 | |
buzbee | 5b53710 | 2012-01-17 17:33:47 -0800 | [diff] [blame] | 127 | /* Sort the blocks by the Depth-First-Search */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 128 | static void ComputeDFSOrders(CompilationUnit* cu) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 129 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 130 | /* Initialize or reset the DFS pre_order list */ |
| 131 | if (cu->dfs_order.elem_list == NULL) { |
| 132 | CompilerInitGrowableList(cu, &cu->dfs_order, cu->num_blocks, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 133 | kListDfsOrder); |
| 134 | } else { |
| 135 | /* Just reset the used length on the counter */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 136 | cu->dfs_order.num_used = 0; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 137 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 138 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 139 | /* Initialize or reset the DFS post_order list */ |
| 140 | if (cu->dfs_post_order.elem_list == NULL) { |
| 141 | CompilerInitGrowableList(cu, &cu->dfs_post_order, cu->num_blocks, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 142 | kListDfsPostOrder); |
| 143 | } else { |
| 144 | /* Just reset the used length on the counter */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 145 | cu->dfs_post_order.num_used = 0; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 146 | } |
buzbee | 5b53710 | 2012-01-17 17:33:47 -0800 | [diff] [blame] | 147 | |
buzbee | e5f0122 | 2012-06-14 15:19:35 -0700 | [diff] [blame] | 148 | #if defined(TEST_DFS) |
| 149 | // Reset visited flags |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 150 | DataFlowAnalysisDispatcher(cu, ClearVisitedFlag, |
| 151 | kAllNodes, false /* is_iterative */); |
buzbee | e5f0122 | 2012-06-14 15:19:35 -0700 | [diff] [blame] | 152 | // Record pre and post order dfs |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 153 | RecursiveRecordDFSOrders(cu, cu->entry_block); |
buzbee | e5f0122 | 2012-06-14 15:19:35 -0700 | [diff] [blame] | 154 | // Copy the results for later comparison and reset the lists |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 155 | GrowableList recursive_dfs_order; |
| 156 | GrowableList recursive_dfs_post_order; |
| 157 | CompilerInitGrowableList(cu, &recursive_dfs_order, cu->dfs_order.num_used, |
buzbee | e5f0122 | 2012-06-14 15:19:35 -0700 | [diff] [blame] | 158 | kListDfsOrder); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 159 | for (unsigned int i = 0; i < cu->dfs_order.num_used; i++) { |
| 160 | InsertGrowableList(cu, &recursive_dfs_order, |
| 161 | cu->dfs_order.elem_list[i]); |
buzbee | e5f0122 | 2012-06-14 15:19:35 -0700 | [diff] [blame] | 162 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 163 | cu->dfs_order.num_used = 0; |
| 164 | CompilerInitGrowableList(cu, &recursive_dfs_post_order, |
| 165 | cu->dfs_post_order.num_used, kListDfsOrder); |
| 166 | for (unsigned int i = 0; i < cu->dfs_post_order.num_used; i++) { |
| 167 | InsertGrowableList(cu, &recursive_dfs_post_order, |
| 168 | cu->dfs_post_order.elem_list[i]); |
buzbee | e5f0122 | 2012-06-14 15:19:35 -0700 | [diff] [blame] | 169 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 170 | cu->dfs_post_order.num_used = 0; |
buzbee | e5f0122 | 2012-06-14 15:19:35 -0700 | [diff] [blame] | 171 | #endif |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 172 | |
buzbee | e5f0122 | 2012-06-14 15:19:35 -0700 | [diff] [blame] | 173 | // Reset visited flags from all nodes |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 174 | DataFlowAnalysisDispatcher(cu, ClearVisitedFlag, |
| 175 | kAllNodes, false /* is_iterative */); |
buzbee | e5f0122 | 2012-06-14 15:19:35 -0700 | [diff] [blame] | 176 | // Record dfs orders |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 177 | RecordDFSOrders(cu, cu->entry_block); |
buzbee | e5f0122 | 2012-06-14 15:19:35 -0700 | [diff] [blame] | 178 | |
| 179 | #if defined(TEST_DFS) |
| 180 | bool mismatch = false; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 181 | mismatch |= (cu->dfs_order.num_used != recursive_dfs_order.num_used); |
| 182 | for (unsigned int i = 0; i < cu->dfs_order.num_used; i++) { |
| 183 | mismatch |= (cu->dfs_order.elem_list[i] != |
| 184 | recursive_dfs_order.elem_list[i]); |
buzbee | e5f0122 | 2012-06-14 15:19:35 -0700 | [diff] [blame] | 185 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 186 | mismatch |= (cu->dfs_post_order.num_used != recursive_dfs_post_order.num_used); |
| 187 | for (unsigned int i = 0; i < cu->dfs_post_order.num_used; i++) { |
| 188 | mismatch |= (cu->dfs_post_order.elem_list[i] != |
| 189 | recursive_dfs_post_order.elem_list[i]); |
buzbee | e5f0122 | 2012-06-14 15:19:35 -0700 | [diff] [blame] | 190 | } |
| 191 | if (mismatch) { |
| 192 | LOG(INFO) << "Mismatch for " |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 193 | << PrettyMethod(cu->method_idx, *cu->dex_file); |
buzbee | e5f0122 | 2012-06-14 15:19:35 -0700 | [diff] [blame] | 194 | LOG(INFO) << "New dfs"; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 195 | for (unsigned int i = 0; i < cu->dfs_order.num_used; i++) { |
| 196 | LOG(INFO) << i << " - " << cu->dfs_order.elem_list[i]; |
buzbee | e5f0122 | 2012-06-14 15:19:35 -0700 | [diff] [blame] | 197 | } |
| 198 | LOG(INFO) << "Recursive dfs"; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 199 | for (unsigned int i = 0; i < recursive_dfs_order.num_used; i++) { |
| 200 | LOG(INFO) << i << " - " << recursive_dfs_order.elem_list[i]; |
buzbee | e5f0122 | 2012-06-14 15:19:35 -0700 | [diff] [blame] | 201 | } |
| 202 | LOG(INFO) << "New post dfs"; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 203 | for (unsigned int i = 0; i < cu->dfs_post_order.num_used; i++) { |
| 204 | LOG(INFO) << i << " - " << cu->dfs_post_order.elem_list[i]; |
buzbee | e5f0122 | 2012-06-14 15:19:35 -0700 | [diff] [blame] | 205 | } |
| 206 | LOG(INFO) << "Recursive post dfs"; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 207 | for (unsigned int i = 0; i < recursive_dfs_post_order.num_used; i++) { |
| 208 | LOG(INFO) << i << " - " << recursive_dfs_post_order.elem_list[i]; |
buzbee | e5f0122 | 2012-06-14 15:19:35 -0700 | [diff] [blame] | 209 | } |
| 210 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 211 | CHECK_EQ(cu->dfs_order.num_used, recursive_dfs_order.num_used); |
| 212 | for (unsigned int i = 0; i < cu->dfs_order.num_used; i++) { |
| 213 | CHECK_EQ(cu->dfs_order.elem_list[i], recursive_dfs_order.elem_list[i]); |
buzbee | e5f0122 | 2012-06-14 15:19:35 -0700 | [diff] [blame] | 214 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 215 | CHECK_EQ(cu->dfs_post_order.num_used, recursive_dfs_post_order.num_used); |
| 216 | for (unsigned int i = 0; i < cu->dfs_post_order.num_used; i++) { |
| 217 | CHECK_EQ(cu->dfs_post_order.elem_list[i], |
| 218 | recursive_dfs_post_order.elem_list[i]); |
buzbee | e5f0122 | 2012-06-14 15:19:35 -0700 | [diff] [blame] | 219 | } |
| 220 | #endif |
| 221 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 222 | cu->num_reachable_blocks = cu->dfs_order.num_used; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | /* |
| 226 | * Mark block bit on the per-Dalvik register vector to denote that Dalvik |
| 227 | * register idx is defined in BasicBlock bb. |
| 228 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 229 | static bool FillDefBlockMatrix(CompilationUnit* cu, BasicBlock* bb) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 230 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 231 | if (bb->data_flow_info == NULL) return false; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 232 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 233 | ArenaBitVectorIterator iterator; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 234 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 235 | BitVectorIteratorInit(bb->data_flow_info->def_v, &iterator); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 236 | while (true) { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 237 | int idx = BitVectorIteratorNext(&iterator); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 238 | if (idx == -1) break; |
| 239 | /* Block bb defines register idx */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 240 | SetBit(cu, cu->def_block_matrix[idx], bb->id); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 241 | } |
| 242 | return true; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 243 | } |
| 244 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 245 | static void ComputeDefBlockMatrix(CompilationUnit* cu) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 246 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 247 | int num_registers = cu->num_dalvik_registers; |
| 248 | /* Allocate num_dalvik_registers bit vector pointers */ |
| 249 | cu->def_block_matrix = static_cast<ArenaBitVector**> |
| 250 | (NewMem(cu, sizeof(ArenaBitVector *) * num_registers, true, kAllocDFInfo)); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 251 | int i; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 252 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 253 | /* Initialize num_register vectors with num_blocks bits each */ |
| 254 | for (i = 0; i < num_registers; i++) { |
| 255 | cu->def_block_matrix[i] = AllocBitVector(cu, cu->num_blocks, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 256 | false, kBitMapBMatrix); |
| 257 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 258 | DataFlowAnalysisDispatcher(cu, FindLocalLiveIn, |
| 259 | kAllNodes, false /* is_iterative */); |
| 260 | DataFlowAnalysisDispatcher(cu, FillDefBlockMatrix, |
| 261 | kAllNodes, false /* is_iterative */); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 262 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 263 | /* |
| 264 | * Also set the incoming parameters as defs in the entry block. |
| 265 | * Only need to handle the parameters for the outer method. |
| 266 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 267 | int num_regs = cu->num_dalvik_registers; |
| 268 | int in_reg = num_regs - cu->num_ins; |
| 269 | for (; in_reg < num_regs; in_reg++) { |
| 270 | SetBit(cu, cu->def_block_matrix[in_reg], cu->entry_block->id); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 271 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | /* Compute the post-order traversal of the CFG */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 275 | static void ComputeDomPostOrderTraversal(CompilationUnit* cu, BasicBlock* bb) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 276 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 277 | ArenaBitVectorIterator bv_iterator; |
| 278 | BitVectorIteratorInit(bb->i_dominated, &bv_iterator); |
| 279 | GrowableList* block_list = &cu->block_list; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 280 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 281 | /* Iterate through the dominated blocks first */ |
| 282 | while (true) { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 283 | //TUNING: hot call to BitVectorIteratorNext |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 284 | int bb_idx = BitVectorIteratorNext(&bv_iterator); |
| 285 | if (bb_idx == -1) break; |
| 286 | BasicBlock* dominated_bb = |
| 287 | reinterpret_cast<BasicBlock*>(GrowableListGetElement(block_list, bb_idx)); |
| 288 | ComputeDomPostOrderTraversal(cu, dominated_bb); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 289 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 290 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 291 | /* Enter the current block id */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 292 | InsertGrowableList(cu, &cu->dom_post_order_traversal, bb->id); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 293 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 294 | /* hacky loop detection */ |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 295 | if (bb->taken && IsBitSet(bb->dominators, bb->taken->id)) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 296 | cu->has_loop = true; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 297 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 298 | } |
| 299 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 300 | static void CheckForDominanceFrontier(CompilationUnit* cu, BasicBlock* dom_bb, |
| 301 | const BasicBlock* succ_bb) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 302 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 303 | /* |
| 304 | * TODO - evaluate whether phi will ever need to be inserted into exit |
| 305 | * blocks. |
| 306 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 307 | if (succ_bb->i_dom != dom_bb && |
| 308 | succ_bb->block_type == kDalvikByteCode && |
| 309 | succ_bb->hidden == false) { |
| 310 | SetBit(cu, dom_bb->dom_frontier, succ_bb->id); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 311 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | /* Worker function to compute the dominance frontier */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 315 | static bool ComputeDominanceFrontier(CompilationUnit* cu, BasicBlock* bb) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 316 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 317 | GrowableList* block_list = &cu->block_list; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 318 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 319 | /* Calculate DF_local */ |
| 320 | if (bb->taken) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 321 | CheckForDominanceFrontier(cu, bb, bb->taken); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 322 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 323 | if (bb->fall_through) { |
| 324 | CheckForDominanceFrontier(cu, bb, bb->fall_through); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 325 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 326 | if (bb->successor_block_list.block_list_type != kNotUsed) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 327 | GrowableListIterator iterator; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 328 | GrowableListIteratorInit(&bb->successor_block_list.blocks, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 329 | &iterator); |
| 330 | while (true) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 331 | SuccessorBlockInfo *successor_block_info = |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 332 | reinterpret_cast<SuccessorBlockInfo*>(GrowableListIteratorNext(&iterator)); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 333 | if (successor_block_info == NULL) break; |
| 334 | BasicBlock* succ_bb = successor_block_info->block; |
| 335 | CheckForDominanceFrontier(cu, bb, succ_bb); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 336 | } |
| 337 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 338 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 339 | /* Calculate DF_up */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 340 | ArenaBitVectorIterator bv_iterator; |
| 341 | BitVectorIteratorInit(bb->i_dominated, &bv_iterator); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 342 | while (true) { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 343 | //TUNING: hot call to BitVectorIteratorNext |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 344 | int dominated_idx = BitVectorIteratorNext(&bv_iterator); |
| 345 | if (dominated_idx == -1) break; |
| 346 | BasicBlock* dominated_bb = |
| 347 | reinterpret_cast<BasicBlock*>(GrowableListGetElement(block_list, dominated_idx)); |
| 348 | ArenaBitVectorIterator df_iterator; |
| 349 | BitVectorIteratorInit(dominated_bb->dom_frontier, &df_iterator); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 350 | while (true) { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 351 | //TUNING: hot call to BitVectorIteratorNext |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 352 | int df_up_idx = BitVectorIteratorNext(&df_iterator); |
| 353 | if (df_up_idx == -1) break; |
| 354 | BasicBlock* df_up_block = |
| 355 | reinterpret_cast<BasicBlock*>( GrowableListGetElement(block_list, df_up_idx)); |
| 356 | CheckForDominanceFrontier(cu, bb, df_up_block); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 357 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 358 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 359 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 360 | return true; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | /* Worker function for initializing domination-related data structures */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 364 | static bool InitializeDominationInfo(CompilationUnit* cu, BasicBlock* bb) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 365 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 366 | int num_total_blocks = cu->block_list.num_used; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 367 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 368 | if (bb->dominators == NULL ) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 369 | bb->dominators = AllocBitVector(cu, num_total_blocks, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 370 | false /* expandable */, |
| 371 | kBitMapDominators); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 372 | bb->i_dominated = AllocBitVector(cu, num_total_blocks, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 373 | false /* expandable */, |
| 374 | kBitMapIDominated); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 375 | bb->dom_frontier = AllocBitVector(cu, num_total_blocks, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 376 | false /* expandable */, |
| 377 | kBitMapDomFrontier); |
| 378 | } else { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 379 | ClearAllBits(bb->dominators); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 380 | ClearAllBits(bb->i_dominated); |
| 381 | ClearAllBits(bb->dom_frontier); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 382 | } |
| 383 | /* Set all bits in the dominator vector */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 384 | SetInitialBits(bb->dominators, num_total_blocks); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 385 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 386 | return true; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 387 | } |
| 388 | |
buzbee | 5b53710 | 2012-01-17 17:33:47 -0800 | [diff] [blame] | 389 | /* |
| 390 | * Worker function to compute each block's dominators. This implementation |
| 391 | * is only used when kDebugVerifyDataflow is active and should compute |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 392 | * the same dominator sets as ComputeBlockDominiators. |
buzbee | 5b53710 | 2012-01-17 17:33:47 -0800 | [diff] [blame] | 393 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 394 | static bool SlowComputeBlockDominators(CompilationUnit* cu, BasicBlock* bb) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 395 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 396 | GrowableList* block_list = &cu->block_list; |
| 397 | int num_total_blocks = block_list->num_used; |
| 398 | ArenaBitVector* temp_block_v = cu->temp_block_v; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 399 | GrowableListIterator iter; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 400 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 401 | /* |
| 402 | * The dominator of the entry block has been preset to itself and we need |
| 403 | * to skip the calculation here. |
| 404 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 405 | if (bb == cu->entry_block) return false; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 406 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 407 | SetInitialBits(temp_block_v, num_total_blocks); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 408 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 409 | /* Iterate through the predecessors */ |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 410 | GrowableListIteratorInit(bb->predecessors, &iter); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 411 | while (true) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 412 | BasicBlock* pred_bb = reinterpret_cast<BasicBlock*>(GrowableListIteratorNext(&iter)); |
| 413 | if (!pred_bb) break; |
| 414 | /* temp_block_v = temp_block_v ^ dominators */ |
| 415 | if (pred_bb->dominators != NULL) { |
| 416 | IntersectBitVectors(temp_block_v, temp_block_v, pred_bb->dominators); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 417 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 418 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 419 | SetBit(cu, temp_block_v, bb->id); |
| 420 | if (CompareBitVectors(temp_block_v, bb->dominators)) { |
| 421 | CopyBitVector(bb->dominators, temp_block_v); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 422 | return true; |
| 423 | } |
| 424 | return false; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 425 | } |
| 426 | |
buzbee | 5b53710 | 2012-01-17 17:33:47 -0800 | [diff] [blame] | 427 | /* |
| 428 | * Worker function to compute the idom. This implementation is only |
| 429 | * used when kDebugVerifyDataflow is active and should compute the |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 430 | * same i_dom as ComputeblockIDom. |
buzbee | 5b53710 | 2012-01-17 17:33:47 -0800 | [diff] [blame] | 431 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 432 | static bool SlowComputeBlockIDom(CompilationUnit* cu, BasicBlock* bb) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 433 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 434 | GrowableList* block_list = &cu->block_list; |
| 435 | ArenaBitVector* temp_block_v = cu->temp_block_v; |
| 436 | ArenaBitVectorIterator bv_iterator; |
| 437 | BasicBlock* i_dom; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 438 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 439 | if (bb == cu->entry_block) return false; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 440 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 441 | CopyBitVector(temp_block_v, bb->dominators); |
| 442 | ClearBit(temp_block_v, bb->id); |
| 443 | BitVectorIteratorInit(temp_block_v, &bv_iterator); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 444 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 445 | /* Should not see any dead block */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 446 | DCHECK_NE(CountSetBits(temp_block_v), 0); |
| 447 | if (CountSetBits(temp_block_v) == 1) { |
| 448 | i_dom = reinterpret_cast<BasicBlock*> |
| 449 | (GrowableListGetElement(block_list, BitVectorIteratorNext(&bv_iterator))); |
| 450 | bb->i_dom = i_dom; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 451 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 452 | int i_dom_idx = BitVectorIteratorNext(&bv_iterator); |
| 453 | DCHECK_NE(i_dom_idx, -1); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 454 | while (true) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 455 | int next_dom = BitVectorIteratorNext(&bv_iterator); |
| 456 | if (next_dom == -1) break; |
| 457 | BasicBlock* next_dom_bb = |
| 458 | reinterpret_cast<BasicBlock*>(GrowableListGetElement(block_list, next_dom)); |
| 459 | /* i_dom dominates next_dom - set new i_dom */ |
| 460 | if (IsBitSet(next_dom_bb->dominators, i_dom_idx)) { |
| 461 | i_dom_idx = next_dom; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 462 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 463 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 464 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 465 | i_dom = reinterpret_cast<BasicBlock*>(GrowableListGetElement(block_list, i_dom_idx)); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 466 | /* Set the immediate dominator block for bb */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 467 | bb->i_dom = i_dom; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 468 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 469 | /* Add bb to the i_dominated set of the immediate dominator block */ |
| 470 | SetBit(cu, i_dom->i_dominated, bb->id); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 471 | return true; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 472 | } |
| 473 | |
buzbee | 5b53710 | 2012-01-17 17:33:47 -0800 | [diff] [blame] | 474 | /* |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 475 | * Walk through the ordered i_dom list until we reach common parent. |
| 476 | * Given the ordering of i_dom_list, this common parent represents the |
buzbee | 5b53710 | 2012-01-17 17:33:47 -0800 | [diff] [blame] | 477 | * last element of the intersection of block1 and block2 dominators. |
| 478 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 479 | static int FindCommonParent(CompilationUnit *cu, int block1, int block2) |
buzbee | 5b53710 | 2012-01-17 17:33:47 -0800 | [diff] [blame] | 480 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 481 | while (block1 != block2) { |
| 482 | while (block1 < block2) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 483 | block1 = cu->i_dom_list[block1]; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 484 | DCHECK_NE(block1, NOTVISITED); |
buzbee | 5b53710 | 2012-01-17 17:33:47 -0800 | [diff] [blame] | 485 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 486 | while (block2 < block1) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 487 | block2 = cu->i_dom_list[block2]; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 488 | DCHECK_NE(block2, NOTVISITED); |
| 489 | } |
| 490 | } |
| 491 | return block1; |
buzbee | 5b53710 | 2012-01-17 17:33:47 -0800 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | /* Worker function to compute each block's immediate dominator */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 495 | static bool ComputeblockIDom(CompilationUnit* cu, BasicBlock* bb) |
buzbee | 5b53710 | 2012-01-17 17:33:47 -0800 | [diff] [blame] | 496 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 497 | GrowableListIterator iter; |
| 498 | int idom = -1; |
buzbee | 5b53710 | 2012-01-17 17:33:47 -0800 | [diff] [blame] | 499 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 500 | /* Special-case entry block */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 501 | if (bb == cu->entry_block) { |
buzbee | 5b53710 | 2012-01-17 17:33:47 -0800 | [diff] [blame] | 502 | return false; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | /* Iterate through the predecessors */ |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 506 | GrowableListIteratorInit(bb->predecessors, &iter); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 507 | |
| 508 | /* Find the first processed predecessor */ |
| 509 | while (true) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 510 | BasicBlock* pred_bb = reinterpret_cast<BasicBlock*>(GrowableListIteratorNext(&iter)); |
| 511 | CHECK(pred_bb != NULL); |
| 512 | if (cu->i_dom_list[pred_bb->dfs_id] != NOTVISITED) { |
| 513 | idom = pred_bb->dfs_id; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 514 | break; |
| 515 | } |
| 516 | } |
| 517 | |
| 518 | /* Scan the rest of the predecessors */ |
| 519 | while (true) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 520 | BasicBlock* pred_bb = reinterpret_cast<BasicBlock*>(GrowableListIteratorNext(&iter)); |
| 521 | if (!pred_bb) break; |
| 522 | if (cu->i_dom_list[pred_bb->dfs_id] == NOTVISITED) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 523 | continue; |
| 524 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 525 | idom = FindCommonParent(cu, pred_bb->dfs_id, idom); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 526 | } |
| 527 | } |
| 528 | |
| 529 | DCHECK_NE(idom, NOTVISITED); |
| 530 | |
| 531 | /* Did something change? */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 532 | if (cu->i_dom_list[bb->dfs_id] != idom) { |
| 533 | cu->i_dom_list[bb->dfs_id] = idom; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 534 | return true; |
| 535 | } |
| 536 | return false; |
buzbee | 5b53710 | 2012-01-17 17:33:47 -0800 | [diff] [blame] | 537 | } |
| 538 | |
| 539 | /* Worker function to compute each block's domintors */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 540 | static bool ComputeBlockDominiators(CompilationUnit* cu, BasicBlock* bb) |
buzbee | 5b53710 | 2012-01-17 17:33:47 -0800 | [diff] [blame] | 541 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 542 | if (bb == cu->entry_block) { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 543 | ClearAllBits(bb->dominators); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 544 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 545 | CopyBitVector(bb->dominators, bb->i_dom->dominators); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 546 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 547 | SetBit(cu, bb->dominators, bb->id); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 548 | return false; |
buzbee | 5b53710 | 2012-01-17 17:33:47 -0800 | [diff] [blame] | 549 | } |
| 550 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 551 | static bool SetDominators(CompilationUnit* cu, BasicBlock* bb) |
buzbee | 5b53710 | 2012-01-17 17:33:47 -0800 | [diff] [blame] | 552 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 553 | if (bb != cu->entry_block) { |
| 554 | int idom_dfs_idx = cu->i_dom_list[bb->dfs_id]; |
| 555 | DCHECK_NE(idom_dfs_idx, NOTVISITED); |
| 556 | int i_dom_idx = cu->dfs_post_order.elem_list[idom_dfs_idx]; |
| 557 | BasicBlock* i_dom = |
| 558 | reinterpret_cast<BasicBlock*>(GrowableListGetElement(&cu->block_list, i_dom_idx)); |
| 559 | if (cu->enable_debug & (1 << kDebugVerifyDataflow)) { |
| 560 | DCHECK_EQ(bb->i_dom->id, i_dom->id); |
buzbee | 5b53710 | 2012-01-17 17:33:47 -0800 | [diff] [blame] | 561 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 562 | bb->i_dom = i_dom; |
| 563 | /* Add bb to the i_dominated set of the immediate dominator block */ |
| 564 | SetBit(cu, i_dom->i_dominated, bb->id); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 565 | } |
| 566 | return false; |
buzbee | 5b53710 | 2012-01-17 17:33:47 -0800 | [diff] [blame] | 567 | } |
| 568 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 569 | /* Compute dominators, immediate dominator, and dominance fronter */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 570 | static void ComputeDominators(CompilationUnit* cu) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 571 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 572 | int num_reachable_blocks = cu->num_reachable_blocks; |
| 573 | int num_total_blocks = cu->block_list.num_used; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 574 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 575 | /* Initialize domination-related data structures */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 576 | DataFlowAnalysisDispatcher(cu, InitializeDominationInfo, |
| 577 | kReachableNodes, false /* is_iterative */); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 578 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 579 | /* Initalize & Clear i_dom_list */ |
| 580 | if (cu->i_dom_list == NULL) { |
| 581 | cu->i_dom_list = static_cast<int*>(NewMem(cu, sizeof(int) * num_reachable_blocks, |
buzbee | cbd6d44 | 2012-11-17 14:11:25 -0800 | [diff] [blame] | 582 | false, kAllocDFInfo)); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 583 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 584 | for (int i = 0; i < num_reachable_blocks; i++) { |
| 585 | cu->i_dom_list[i] = NOTVISITED; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 586 | } |
buzbee | 5b53710 | 2012-01-17 17:33:47 -0800 | [diff] [blame] | 587 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 588 | /* For post-order, last block is entry block. Set its i_dom to istelf */ |
| 589 | DCHECK_EQ(cu->entry_block->dfs_id, num_reachable_blocks-1); |
| 590 | cu->i_dom_list[cu->entry_block->dfs_id] = cu->entry_block->dfs_id; |
buzbee | 5b53710 | 2012-01-17 17:33:47 -0800 | [diff] [blame] | 591 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 592 | /* Compute the immediate dominators */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 593 | DataFlowAnalysisDispatcher(cu, ComputeblockIDom, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 594 | kReversePostOrderTraversal, |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 595 | true /* is_iterative */); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 596 | |
| 597 | /* Set the dominator for the root node */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 598 | ClearAllBits(cu->entry_block->dominators); |
| 599 | SetBit(cu, cu->entry_block->dominators, cu->entry_block->id); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 600 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 601 | if (cu->temp_block_v == NULL) { |
| 602 | cu->temp_block_v = AllocBitVector(cu, num_total_blocks, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 603 | false /* expandable */, |
| 604 | kBitMapTmpBlockV); |
| 605 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 606 | ClearAllBits(cu->temp_block_v); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 607 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 608 | cu->entry_block->i_dom = NULL; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 609 | |
| 610 | /* For testing, compute sets using alternate mechanism */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 611 | if (cu->enable_debug & (1 << kDebugVerifyDataflow)) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 612 | // Use alternate mechanism to compute dominators for comparison |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 613 | DataFlowAnalysisDispatcher(cu, SlowComputeBlockDominators, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 614 | kPreOrderDFSTraversal, |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 615 | true /* is_iterative */); |
buzbee | 5b53710 | 2012-01-17 17:33:47 -0800 | [diff] [blame] | 616 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 617 | DataFlowAnalysisDispatcher(cu, SlowComputeBlockIDom, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 618 | kReachableNodes, |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 619 | false /* is_iterative */); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 620 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 621 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 622 | DataFlowAnalysisDispatcher(cu, SetDominators, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 623 | kReachableNodes, |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 624 | false /* is_iterative */); |
buzbee | 5b53710 | 2012-01-17 17:33:47 -0800 | [diff] [blame] | 625 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 626 | DataFlowAnalysisDispatcher(cu, ComputeBlockDominiators, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 627 | kReversePostOrderTraversal, |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 628 | false /* is_iterative */); |
buzbee | 5b53710 | 2012-01-17 17:33:47 -0800 | [diff] [blame] | 629 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 630 | /* |
| 631 | * Now go ahead and compute the post order traversal based on the |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 632 | * i_dominated sets. |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 633 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 634 | if (cu->dom_post_order_traversal.elem_list == NULL) { |
| 635 | CompilerInitGrowableList(cu, &cu->dom_post_order_traversal, |
| 636 | num_reachable_blocks, kListDomPostOrderTraversal); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 637 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 638 | cu->dom_post_order_traversal.num_used = 0; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 639 | } |
buzbee | 5b53710 | 2012-01-17 17:33:47 -0800 | [diff] [blame] | 640 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 641 | ComputeDomPostOrderTraversal(cu, cu->entry_block); |
| 642 | DCHECK_EQ(cu->dom_post_order_traversal.num_used, static_cast<unsigned>(cu->num_reachable_blocks)); |
buzbee | 5b53710 | 2012-01-17 17:33:47 -0800 | [diff] [blame] | 643 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 644 | /* Now compute the dominance frontier for each block */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 645 | DataFlowAnalysisDispatcher(cu, ComputeDominanceFrontier, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 646 | kPostOrderDOMTraversal, |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 647 | false /* is_iterative */); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 648 | } |
| 649 | |
| 650 | /* |
| 651 | * Perform dest U= src1 ^ ~src2 |
| 652 | * This is probably not general enough to be placed in BitVector.[ch]. |
| 653 | */ |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 654 | static void ComputeSuccLineIn(ArenaBitVector* dest, const ArenaBitVector* src1, |
| 655 | const ArenaBitVector* src2) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 656 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 657 | if (dest->storage_size != src1->storage_size || |
| 658 | dest->storage_size != src2->storage_size || |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 659 | dest->expandable != src1->expandable || |
| 660 | dest->expandable != src2->expandable) { |
| 661 | LOG(FATAL) << "Incompatible set properties"; |
| 662 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 663 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 664 | unsigned int idx; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 665 | for (idx = 0; idx < dest->storage_size; idx++) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 666 | dest->storage[idx] |= src1->storage[idx] & ~src2->storage[idx]; |
| 667 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | /* |
| 671 | * Iterate through all successor blocks and propagate up the live-in sets. |
| 672 | * The calculated result is used for phi-node pruning - where we only need to |
| 673 | * insert a phi node if the variable is live-in to the block. |
| 674 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 675 | static bool ComputeBlockLiveIns(CompilationUnit* cu, BasicBlock* bb) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 676 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 677 | ArenaBitVector* temp_dalvik_register_v = cu->temp_dalvik_register_v; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 678 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 679 | if (bb->data_flow_info == NULL) return false; |
| 680 | CopyBitVector(temp_dalvik_register_v, bb->data_flow_info->live_in_v); |
| 681 | if (bb->taken && bb->taken->data_flow_info) |
| 682 | ComputeSuccLineIn(temp_dalvik_register_v, bb->taken->data_flow_info->live_in_v, |
| 683 | bb->data_flow_info->def_v); |
| 684 | if (bb->fall_through && bb->fall_through->data_flow_info) |
| 685 | ComputeSuccLineIn(temp_dalvik_register_v, |
| 686 | bb->fall_through->data_flow_info->live_in_v, |
| 687 | bb->data_flow_info->def_v); |
| 688 | if (bb->successor_block_list.block_list_type != kNotUsed) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 689 | GrowableListIterator iterator; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 690 | GrowableListIteratorInit(&bb->successor_block_list.blocks, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 691 | &iterator); |
| 692 | while (true) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 693 | SuccessorBlockInfo *successor_block_info = |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 694 | reinterpret_cast<SuccessorBlockInfo*>(GrowableListIteratorNext(&iterator)); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 695 | if (successor_block_info == NULL) break; |
| 696 | BasicBlock* succ_bb = successor_block_info->block; |
| 697 | if (succ_bb->data_flow_info) { |
| 698 | ComputeSuccLineIn(temp_dalvik_register_v, |
| 699 | succ_bb->data_flow_info->live_in_v, |
| 700 | bb->data_flow_info->def_v); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 701 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 702 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 703 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 704 | if (CompareBitVectors(temp_dalvik_register_v, bb->data_flow_info->live_in_v)) { |
| 705 | CopyBitVector(bb->data_flow_info->live_in_v, temp_dalvik_register_v); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 706 | return true; |
| 707 | } |
| 708 | return false; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 709 | } |
| 710 | |
| 711 | /* Insert phi nodes to for each variable to the dominance frontiers */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 712 | static void InsertPhiNodes(CompilationUnit* cu) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 713 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 714 | int dalvik_reg; |
| 715 | const GrowableList* block_list = &cu->block_list; |
| 716 | ArenaBitVector* phi_blocks = |
| 717 | AllocBitVector(cu, cu->num_blocks, false, kBitMapPhi); |
| 718 | ArenaBitVector* tmp_blocks = |
| 719 | AllocBitVector(cu, cu->num_blocks, false, kBitMapTmpBlocks); |
| 720 | ArenaBitVector* input_blocks = |
| 721 | AllocBitVector(cu, cu->num_blocks, false, kBitMapInputBlocks); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 722 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 723 | cu->temp_dalvik_register_v = |
| 724 | AllocBitVector(cu, cu->num_dalvik_registers, false, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 725 | kBitMapRegisterV); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 726 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 727 | DataFlowAnalysisDispatcher(cu, ComputeBlockLiveIns, |
| 728 | kPostOrderDFSTraversal, true /* is_iterative */); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 729 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 730 | /* Iterate through each Dalvik register */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 731 | for (dalvik_reg = cu->num_dalvik_registers - 1; dalvik_reg >= 0; dalvik_reg--) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 732 | bool change; |
| 733 | ArenaBitVectorIterator iterator; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 734 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 735 | CopyBitVector(input_blocks, cu->def_block_matrix[dalvik_reg]); |
| 736 | ClearAllBits(phi_blocks); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 737 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 738 | /* Calculate the phi blocks for each Dalvik register */ |
| 739 | do { |
| 740 | change = false; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 741 | ClearAllBits(tmp_blocks); |
| 742 | BitVectorIteratorInit(input_blocks, &iterator); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 743 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 744 | while (true) { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 745 | int idx = BitVectorIteratorNext(&iterator); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 746 | if (idx == -1) break; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 747 | BasicBlock* def_bb = |
| 748 | reinterpret_cast<BasicBlock*>(GrowableListGetElement(block_list, idx)); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 749 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 750 | /* Merge the dominance frontier to tmp_blocks */ |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 751 | //TUNING: hot call to UnifyBitVetors |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 752 | if (def_bb->dom_frontier != NULL) { |
| 753 | UnifyBitVetors(tmp_blocks, tmp_blocks, def_bb->dom_frontier); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 754 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 755 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 756 | if (CompareBitVectors(phi_blocks, tmp_blocks)) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 757 | change = true; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 758 | CopyBitVector(phi_blocks, tmp_blocks); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 759 | |
| 760 | /* |
| 761 | * Iterate through the original blocks plus the new ones in |
| 762 | * the dominance frontier. |
| 763 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 764 | CopyBitVector(input_blocks, phi_blocks); |
| 765 | UnifyBitVetors(input_blocks, input_blocks, |
| 766 | cu->def_block_matrix[dalvik_reg]); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 767 | } |
| 768 | } while (change); |
| 769 | |
| 770 | /* |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 771 | * Insert a phi node for dalvik_reg in the phi_blocks if the Dalvik |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 772 | * register is in the live-in set. |
| 773 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 774 | BitVectorIteratorInit(phi_blocks, &iterator); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 775 | while (true) { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 776 | int idx = BitVectorIteratorNext(&iterator); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 777 | if (idx == -1) break; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 778 | BasicBlock* phi_bb = |
| 779 | reinterpret_cast<BasicBlock*>(GrowableListGetElement(block_list, idx)); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 780 | /* Variable will be clobbered before being used - no need for phi */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 781 | if (!IsBitSet(phi_bb->data_flow_info->live_in_v, dalvik_reg)) continue; |
| 782 | MIR *phi = static_cast<MIR*>(NewMem(cu, sizeof(MIR), true, kAllocDFInfo)); |
buzbee | cbd6d44 | 2012-11-17 14:11:25 -0800 | [diff] [blame] | 783 | phi->dalvikInsn.opcode = static_cast<Instruction::Code>(kMirOpPhi); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 784 | phi->dalvikInsn.vA = dalvik_reg; |
| 785 | phi->offset = phi_bb->start_offset; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 786 | PrependMIR(phi_bb, phi); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 787 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 788 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 789 | } |
| 790 | |
| 791 | /* |
| 792 | * Worker function to insert phi-operands with latest SSA names from |
| 793 | * predecessor blocks |
| 794 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 795 | static bool InsertPhiNodeOperands(CompilationUnit* cu, BasicBlock* bb) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 796 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 797 | GrowableListIterator iter; |
| 798 | MIR *mir; |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 799 | std::vector<int> uses; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 800 | std::vector<int> incoming_arc; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 801 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 802 | /* Phi nodes are at the beginning of each block */ |
buzbee | 28c9a83 | 2012-11-21 15:39:13 -0800 | [diff] [blame] | 803 | for (mir = bb->first_mir_insn; mir != NULL; mir = mir->next) { |
buzbee | cbd6d44 | 2012-11-17 14:11:25 -0800 | [diff] [blame] | 804 | if (mir->dalvikInsn.opcode != static_cast<Instruction::Code>(kMirOpPhi)) |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 805 | return true; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 806 | int ssa_reg = mir->ssa_rep->defs[0]; |
| 807 | DCHECK_GE(ssa_reg, 0); // Shouldn't see compiler temps here |
| 808 | int v_reg = SRegToVReg(cu, ssa_reg); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 809 | |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 810 | uses.clear(); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 811 | incoming_arc.clear(); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 812 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 813 | /* Iterate through the predecessors */ |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 814 | GrowableListIteratorInit(bb->predecessors, &iter); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 815 | while (true) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 816 | BasicBlock* pred_bb = |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 817 | reinterpret_cast<BasicBlock*>(GrowableListIteratorNext(&iter)); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 818 | if (!pred_bb) break; |
| 819 | int ssa_reg = pred_bb->data_flow_info->vreg_to_ssa_map[v_reg]; |
| 820 | uses.push_back(ssa_reg); |
| 821 | incoming_arc.push_back(pred_bb->id); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 822 | } |
| 823 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 824 | /* Count the number of SSA registers for a Dalvik register */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 825 | int num_uses = uses.size(); |
| 826 | mir->ssa_rep->num_uses = num_uses; |
| 827 | mir->ssa_rep->uses = |
| 828 | static_cast<int*>(NewMem(cu, sizeof(int) * num_uses, false, kAllocDFInfo)); |
| 829 | mir->ssa_rep->fp_use = |
| 830 | static_cast<bool*>(NewMem(cu, sizeof(bool) * num_uses, true, kAllocDFInfo)); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 831 | int* incoming = |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 832 | static_cast<int*>(NewMem(cu, sizeof(int) * num_uses, false, kAllocDFInfo)); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 833 | // TODO: Ugly, rework (but don't burden each MIR/LIR for Phi-only needs) |
buzbee | cbd6d44 | 2012-11-17 14:11:25 -0800 | [diff] [blame] | 834 | mir->dalvikInsn.vB = reinterpret_cast<uintptr_t>(incoming); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 835 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 836 | /* Set the uses array for the phi node */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 837 | int *use_ptr = mir->ssa_rep->uses; |
| 838 | for (int i = 0; i < num_uses; i++) { |
| 839 | *use_ptr++ = uses[i]; |
| 840 | *incoming++ = incoming_arc[i]; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 841 | } |
| 842 | } |
| 843 | |
| 844 | return true; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 845 | } |
| 846 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 847 | static void DoDFSPreOrderSSARename(CompilationUnit* cu, BasicBlock* block) |
buzbee | f0cde54 | 2011-09-13 14:55:02 -0700 | [diff] [blame] | 848 | { |
| 849 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 850 | if (block->visited || block->hidden) return; |
| 851 | block->visited = true; |
buzbee | f0cde54 | 2011-09-13 14:55:02 -0700 | [diff] [blame] | 852 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 853 | /* Process this block */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 854 | DoSSAConversion(cu, block); |
| 855 | int map_size = sizeof(int) * cu->num_dalvik_registers; |
buzbee | f0cde54 | 2011-09-13 14:55:02 -0700 | [diff] [blame] | 856 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 857 | /* Save SSA map snapshot */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 858 | int* saved_ssa_map = static_cast<int*>(NewMem(cu, map_size, false, kAllocDalvikToSSAMap)); |
| 859 | memcpy(saved_ssa_map, cu->vreg_to_ssa_map, map_size); |
buzbee | f0cde54 | 2011-09-13 14:55:02 -0700 | [diff] [blame] | 860 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 861 | if (block->fall_through) { |
| 862 | DoDFSPreOrderSSARename(cu, block->fall_through); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 863 | /* Restore SSA map snapshot */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 864 | memcpy(cu->vreg_to_ssa_map, saved_ssa_map, map_size); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 865 | } |
| 866 | if (block->taken) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 867 | DoDFSPreOrderSSARename(cu, block->taken); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 868 | /* Restore SSA map snapshot */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 869 | memcpy(cu->vreg_to_ssa_map, saved_ssa_map, map_size); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 870 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 871 | if (block->successor_block_list.block_list_type != kNotUsed) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 872 | GrowableListIterator iterator; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 873 | GrowableListIteratorInit(&block->successor_block_list.blocks, &iterator); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 874 | while (true) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 875 | SuccessorBlockInfo *successor_block_info = |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 876 | reinterpret_cast<SuccessorBlockInfo*>(GrowableListIteratorNext(&iterator)); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 877 | if (successor_block_info == NULL) break; |
| 878 | BasicBlock* succ_bb = successor_block_info->block; |
| 879 | DoDFSPreOrderSSARename(cu, succ_bb); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 880 | /* Restore SSA map snapshot */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 881 | memcpy(cu->vreg_to_ssa_map, saved_ssa_map, map_size); |
buzbee | f0cde54 | 2011-09-13 14:55:02 -0700 | [diff] [blame] | 882 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 883 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 884 | cu->vreg_to_ssa_map = saved_ssa_map; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 885 | return; |
buzbee | f0cde54 | 2011-09-13 14:55:02 -0700 | [diff] [blame] | 886 | } |
| 887 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 888 | /* Perform SSA transformation for the whole method */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 889 | void SSATransformation(CompilationUnit* cu) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 890 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 891 | /* Compute the DFS order */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 892 | ComputeDFSOrders(cu); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 893 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 894 | if (!cu->disable_dataflow) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 895 | /* Compute the dominator info */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 896 | ComputeDominators(cu); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 897 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 898 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 899 | /* Allocate data structures in preparation for SSA conversion */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 900 | CompilerInitializeSSAConversion(cu); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 901 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 902 | if (!cu->disable_dataflow) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 903 | /* Find out the "Dalvik reg def x block" relation */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 904 | ComputeDefBlockMatrix(cu); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 905 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 906 | /* Insert phi nodes to dominance frontiers for all variables */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 907 | InsertPhiNodes(cu); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 908 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 909 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 910 | /* Rename register names by local defs and phi nodes */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 911 | DataFlowAnalysisDispatcher(cu, ClearVisitedFlag, |
| 912 | kAllNodes, false /* is_iterative */); |
| 913 | DoDFSPreOrderSSARename(cu, cu->entry_block); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 914 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 915 | if (!cu->disable_dataflow) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 916 | /* |
| 917 | * Shared temp bit vector used by each block to count the number of defs |
| 918 | * from all the predecessor blocks. |
| 919 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 920 | cu->temp_ssa_register_v = AllocBitVector(cu, cu->num_ssa_regs, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 921 | false, kBitMapTempSSARegisterV); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 922 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 923 | cu->temp_ssa_block_id_v = |
| 924 | static_cast<int*>(NewMem(cu, sizeof(int) * cu->num_ssa_regs, false, kAllocDFInfo)); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 925 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 926 | /* Insert phi-operands with latest SSA names from predecessor blocks */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 927 | DataFlowAnalysisDispatcher(cu, InsertPhiNodeOperands, |
| 928 | kReachableNodes, false /* is_iterative */); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 929 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 930 | } |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 931 | |
| 932 | } // namespace art |