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 | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 36 | BasicBlock* res = NeedsVisit(bb->fallThrough); |
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) { |
| 40 | if (bb->successorBlockList.blockListType != kNotUsed) { |
| 41 | GrowableListIterator iterator; |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 42 | GrowableListIteratorInit(&bb->successorBlockList.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 | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 57 | static void MarkPreOrder(CompilationUnit* cUnit, BasicBlock* block) |
buzbee | e5f0122 | 2012-06-14 15:19:35 -0700 | [diff] [blame] | 58 | { |
| 59 | block->visited = true; |
buzbee | e5f0122 | 2012-06-14 15:19:35 -0700 | [diff] [blame] | 60 | /* Enqueue the preOrder block id */ |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 61 | InsertGrowableList(cUnit, &cUnit->dfsOrder, block->id); |
buzbee | e5f0122 | 2012-06-14 15:19:35 -0700 | [diff] [blame] | 62 | } |
| 63 | |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 64 | static void RecordDFSOrders(CompilationUnit* cUnit, 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 | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 67 | MarkPreOrder(cUnit, 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 | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 71 | BasicBlock* nextSuccessor = NextUnvisitedSuccessor(curr); |
buzbee | e5f0122 | 2012-06-14 15:19:35 -0700 | [diff] [blame] | 72 | if (nextSuccessor != NULL) { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 73 | MarkPreOrder(cUnit, nextSuccessor); |
buzbee | e5f0122 | 2012-06-14 15:19:35 -0700 | [diff] [blame] | 74 | succ.push_back(nextSuccessor); |
| 75 | continue; |
| 76 | } |
| 77 | curr->dfsId = cUnit->dfsPostOrder.numUsed; |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 78 | InsertGrowableList(cUnit, &cUnit->dfsPostOrder, 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) |
| 84 | /* Enter the node to the dfsOrder list then visit its successors */ |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 85 | static void RecursiveRecordDFSOrders(CompilationUnit* cUnit, 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? |
| 92 | if ((block->blockType == kDalvikByteCode) && |
| 93 | (block->predecessors->numUsed == 1)) { |
| 94 | DCHECK_GE(cUnit->dfsOrder.numUsed, 1U); |
| 95 | int prevIdx = cUnit->dfsOrder.numUsed - 1; |
| 96 | int prevId = cUnit->dfsOrder.elemList[prevIdx]; |
| 97 | BasicBlock* predBB = (BasicBlock*)block->predecessors->elemList[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 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 100 | /* Enqueue the preOrder block id */ |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 101 | InsertGrowableList(cUnit, &cUnit->dfsOrder, block->id); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 102 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 103 | if (block->fallThrough) { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 104 | RecursiveRecordDFSOrders(cUnit, block->fallThrough); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 105 | } |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 106 | if (block->taken) RecursiveRecordDFSOrders(cUnit, block->taken); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 107 | if (block->successorBlockList.blockListType != kNotUsed) { |
| 108 | GrowableListIterator iterator; |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 109 | GrowableListIteratorInit(&block->successorBlockList.blocks, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 110 | &iterator); |
| 111 | while (true) { |
| 112 | SuccessorBlockInfo *successorBlockInfo = |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 113 | (SuccessorBlockInfo *) GrowableListIteratorNext(&iterator); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 114 | if (successorBlockInfo == NULL) break; |
| 115 | BasicBlock* succBB = successorBlockInfo->block; |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 116 | RecursiveRecordDFSOrders(cUnit, succBB); |
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 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 120 | /* Record postorder in basic block and enqueue normal id in dfsPostOrder */ |
| 121 | block->dfsId = cUnit->dfsPostOrder.numUsed; |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 122 | InsertGrowableList(cUnit, &cUnit->dfsPostOrder, 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 | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 128 | static void ComputeDFSOrders(CompilationUnit* cUnit) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 129 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 130 | /* Initialize or reset the DFS preOrder list */ |
| 131 | if (cUnit->dfsOrder.elemList == NULL) { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 132 | CompilerInitGrowableList(cUnit, &cUnit->dfsOrder, cUnit->numBlocks, |
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 */ |
| 136 | cUnit->dfsOrder.numUsed = 0; |
| 137 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 138 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 139 | /* Initialize or reset the DFS postOrder list */ |
| 140 | if (cUnit->dfsPostOrder.elemList == NULL) { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 141 | CompilerInitGrowableList(cUnit, &cUnit->dfsPostOrder, cUnit->numBlocks, |
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 */ |
| 145 | cUnit->dfsPostOrder.numUsed = 0; |
| 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 | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 150 | DataFlowAnalysisDispatcher(cUnit, ClearVisitedFlag, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 151 | kAllNodes, false /* isIterative */); |
buzbee | e5f0122 | 2012-06-14 15:19:35 -0700 | [diff] [blame] | 152 | // Record pre and post order dfs |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 153 | RecursiveRecordDFSOrders(cUnit, cUnit->entryBlock); |
buzbee | e5f0122 | 2012-06-14 15:19:35 -0700 | [diff] [blame] | 154 | // Copy the results for later comparison and reset the lists |
| 155 | GrowableList recursiveDfsOrder; |
| 156 | GrowableList recursiveDfsPostOrder; |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 157 | CompilerInitGrowableList(cUnit, &recursiveDfsOrder, cUnit->dfsOrder.numUsed, |
buzbee | e5f0122 | 2012-06-14 15:19:35 -0700 | [diff] [blame] | 158 | kListDfsOrder); |
| 159 | for (unsigned int i = 0; i < cUnit->dfsOrder.numUsed; i++) { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 160 | InsertGrowableList(cUnit, &recursiveDfsOrder, |
buzbee | e5f0122 | 2012-06-14 15:19:35 -0700 | [diff] [blame] | 161 | cUnit->dfsOrder.elemList[i]); |
| 162 | } |
| 163 | cUnit->dfsOrder.numUsed = 0; |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 164 | CompilerInitGrowableList(cUnit, &recursiveDfsPostOrder, |
buzbee | e5f0122 | 2012-06-14 15:19:35 -0700 | [diff] [blame] | 165 | cUnit->dfsPostOrder.numUsed, kListDfsOrder); |
| 166 | for (unsigned int i = 0; i < cUnit->dfsPostOrder.numUsed; i++) { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 167 | InsertGrowableList(cUnit, &recursiveDfsPostOrder, |
buzbee | e5f0122 | 2012-06-14 15:19:35 -0700 | [diff] [blame] | 168 | cUnit->dfsPostOrder.elemList[i]); |
| 169 | } |
| 170 | cUnit->dfsPostOrder.numUsed = 0; |
| 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 | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 174 | DataFlowAnalysisDispatcher(cUnit, ClearVisitedFlag, |
buzbee | e5f0122 | 2012-06-14 15:19:35 -0700 | [diff] [blame] | 175 | kAllNodes, false /* isIterative */); |
| 176 | // Record dfs orders |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 177 | RecordDFSOrders(cUnit, cUnit->entryBlock); |
buzbee | e5f0122 | 2012-06-14 15:19:35 -0700 | [diff] [blame] | 178 | |
| 179 | #if defined(TEST_DFS) |
| 180 | bool mismatch = false; |
| 181 | mismatch |= (cUnit->dfsOrder.numUsed != recursiveDfsOrder.numUsed); |
| 182 | for (unsigned int i = 0; i < cUnit->dfsOrder.numUsed; i++) { |
| 183 | mismatch |= (cUnit->dfsOrder.elemList[i] != |
| 184 | recursiveDfsOrder.elemList[i]); |
| 185 | } |
| 186 | mismatch |= (cUnit->dfsPostOrder.numUsed != recursiveDfsPostOrder.numUsed); |
| 187 | for (unsigned int i = 0; i < cUnit->dfsPostOrder.numUsed; i++) { |
| 188 | mismatch |= (cUnit->dfsPostOrder.elemList[i] != |
| 189 | recursiveDfsPostOrder.elemList[i]); |
| 190 | } |
| 191 | if (mismatch) { |
| 192 | LOG(INFO) << "Mismatch for " |
| 193 | << PrettyMethod(cUnit->method_idx, *cUnit->dex_file); |
buzbee | e5f0122 | 2012-06-14 15:19:35 -0700 | [diff] [blame] | 194 | LOG(INFO) << "New dfs"; |
| 195 | for (unsigned int i = 0; i < cUnit->dfsOrder.numUsed; i++) { |
| 196 | LOG(INFO) << i << " - " << cUnit->dfsOrder.elemList[i]; |
| 197 | } |
| 198 | LOG(INFO) << "Recursive dfs"; |
| 199 | for (unsigned int i = 0; i < recursiveDfsOrder.numUsed; i++) { |
| 200 | LOG(INFO) << i << " - " << recursiveDfsOrder.elemList[i]; |
| 201 | } |
| 202 | LOG(INFO) << "New post dfs"; |
| 203 | for (unsigned int i = 0; i < cUnit->dfsPostOrder.numUsed; i++) { |
| 204 | LOG(INFO) << i << " - " << cUnit->dfsPostOrder.elemList[i]; |
| 205 | } |
| 206 | LOG(INFO) << "Recursive post dfs"; |
| 207 | for (unsigned int i = 0; i < recursiveDfsPostOrder.numUsed; i++) { |
| 208 | LOG(INFO) << i << " - " << recursiveDfsPostOrder.elemList[i]; |
| 209 | } |
| 210 | } |
| 211 | CHECK_EQ(cUnit->dfsOrder.numUsed, recursiveDfsOrder.numUsed); |
| 212 | for (unsigned int i = 0; i < cUnit->dfsOrder.numUsed; i++) { |
| 213 | CHECK_EQ(cUnit->dfsOrder.elemList[i], recursiveDfsOrder.elemList[i]); |
| 214 | } |
| 215 | CHECK_EQ(cUnit->dfsPostOrder.numUsed, recursiveDfsPostOrder.numUsed); |
| 216 | for (unsigned int i = 0; i < cUnit->dfsPostOrder.numUsed; i++) { |
| 217 | CHECK_EQ(cUnit->dfsPostOrder.elemList[i], |
| 218 | recursiveDfsPostOrder.elemList[i]); |
| 219 | } |
| 220 | #endif |
| 221 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 222 | cUnit->numReachableBlocks = cUnit->dfsOrder.numUsed; |
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 | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 229 | static bool FillDefBlockMatrix(CompilationUnit* cUnit, BasicBlock* bb) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 230 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 231 | if (bb->dataFlowInfo == 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 | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 235 | BitVectorIteratorInit(bb->dataFlowInfo->defV, &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 | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 240 | SetBit(cUnit, cUnit->defBlockMatrix[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 | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 245 | static void ComputeDefBlockMatrix(CompilationUnit* cUnit) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 246 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 247 | int numRegisters = cUnit->numDalvikRegisters; |
| 248 | /* Allocate numDalvikRegisters bit vector pointers */ |
buzbee | cbd6d44 | 2012-11-17 14:11:25 -0800 | [diff] [blame] | 249 | cUnit->defBlockMatrix = static_cast<ArenaBitVector**> |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 250 | (NewMem(cUnit, sizeof(ArenaBitVector *) * numRegisters, 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 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 253 | /* Initialize numRegister vectors with numBlocks bits each */ |
| 254 | for (i = 0; i < numRegisters; i++) { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 255 | cUnit->defBlockMatrix[i] = AllocBitVector(cUnit, cUnit->numBlocks, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 256 | false, kBitMapBMatrix); |
| 257 | } |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 258 | DataFlowAnalysisDispatcher(cUnit, FindLocalLiveIn, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 259 | kAllNodes, false /* isIterative */); |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 260 | DataFlowAnalysisDispatcher(cUnit, FillDefBlockMatrix, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 261 | kAllNodes, false /* isIterative */); |
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 | */ |
| 267 | int numRegs = cUnit->numDalvikRegisters; |
| 268 | int inReg = numRegs - cUnit->numIns; |
| 269 | for (; inReg < numRegs; inReg++) { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 270 | SetBit(cUnit, cUnit->defBlockMatrix[inReg], cUnit->entryBlock->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 | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 275 | static void ComputeDomPostOrderTraversal(CompilationUnit* cUnit, BasicBlock* bb) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 276 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 277 | ArenaBitVectorIterator bvIterator; |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 278 | BitVectorIteratorInit(bb->iDominated, &bvIterator); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 279 | GrowableList* blockList = &cUnit->blockList; |
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 |
| 284 | int bbIdx = BitVectorIteratorNext(&bvIterator); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 285 | if (bbIdx == -1) break; |
| 286 | BasicBlock* dominatedBB = |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 287 | reinterpret_cast<BasicBlock*>(GrowableListGetElement(blockList, bbIdx)); |
| 288 | ComputeDomPostOrderTraversal(cUnit, dominatedBB); |
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 | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 292 | InsertGrowableList(cUnit, &cUnit->domPostOrderTraversal, 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)) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 296 | cUnit->hasLoop = true; |
| 297 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 298 | } |
| 299 | |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 300 | static void CheckForDominanceFrontier(CompilationUnit* cUnit, BasicBlock* domBB, |
| 301 | const BasicBlock* succBB) |
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 | */ |
| 307 | if (succBB->iDom != domBB && |
| 308 | succBB->blockType == kDalvikByteCode && |
| 309 | succBB->hidden == false) { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 310 | SetBit(cUnit, domBB->domFrontier, succBB->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 | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 315 | static bool ComputeDominanceFrontier(CompilationUnit* cUnit, BasicBlock* bb) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 316 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 317 | GrowableList* blockList = &cUnit->blockList; |
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 | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 321 | CheckForDominanceFrontier(cUnit, bb, bb->taken); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 322 | } |
| 323 | if (bb->fallThrough) { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 324 | CheckForDominanceFrontier(cUnit, bb, bb->fallThrough); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 325 | } |
| 326 | if (bb->successorBlockList.blockListType != kNotUsed) { |
| 327 | GrowableListIterator iterator; |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 328 | GrowableListIteratorInit(&bb->successorBlockList.blocks, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 329 | &iterator); |
| 330 | while (true) { |
| 331 | SuccessorBlockInfo *successorBlockInfo = |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 332 | reinterpret_cast<SuccessorBlockInfo*>(GrowableListIteratorNext(&iterator)); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 333 | if (successorBlockInfo == NULL) break; |
| 334 | BasicBlock* succBB = successorBlockInfo->block; |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 335 | CheckForDominanceFrontier(cUnit, bb, succBB); |
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 */ |
| 340 | ArenaBitVectorIterator bvIterator; |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 341 | BitVectorIteratorInit(bb->iDominated, &bvIterator); |
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 |
| 344 | int dominatedIdx = BitVectorIteratorNext(&bvIterator); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 345 | if (dominatedIdx == -1) break; |
buzbee | cbd6d44 | 2012-11-17 14:11:25 -0800 | [diff] [blame] | 346 | BasicBlock* dominatedBB = |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 347 | reinterpret_cast<BasicBlock*>(GrowableListGetElement(blockList, dominatedIdx)); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 348 | ArenaBitVectorIterator dfIterator; |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 349 | BitVectorIteratorInit(dominatedBB->domFrontier, &dfIterator); |
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 |
| 352 | int dfUpIdx = BitVectorIteratorNext(&dfIterator); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 353 | if (dfUpIdx == -1) break; |
buzbee | cbd6d44 | 2012-11-17 14:11:25 -0800 | [diff] [blame] | 354 | BasicBlock* dfUpBlock = |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 355 | reinterpret_cast<BasicBlock*>( GrowableListGetElement(blockList, dfUpIdx)); |
| 356 | CheckForDominanceFrontier(cUnit, bb, dfUpBlock); |
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 | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 364 | static bool InitializeDominationInfo(CompilationUnit* cUnit, BasicBlock* bb) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 365 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 366 | int numTotalBlocks = cUnit->blockList.numUsed; |
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 | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 369 | bb->dominators = AllocBitVector(cUnit, numTotalBlocks, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 370 | false /* expandable */, |
| 371 | kBitMapDominators); |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 372 | bb->iDominated = AllocBitVector(cUnit, numTotalBlocks, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 373 | false /* expandable */, |
| 374 | kBitMapIDominated); |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 375 | bb->domFrontier = AllocBitVector(cUnit, numTotalBlocks, |
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); |
| 380 | ClearAllBits(bb->iDominated); |
| 381 | ClearAllBits(bb->domFrontier); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 382 | } |
| 383 | /* Set all bits in the dominator vector */ |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 384 | SetInitialBits(bb->dominators, numTotalBlocks); |
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 | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 394 | static bool SlowComputeBlockDominators(CompilationUnit* cUnit, BasicBlock* bb) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 395 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 396 | GrowableList* blockList = &cUnit->blockList; |
| 397 | int numTotalBlocks = blockList->numUsed; |
| 398 | ArenaBitVector* tempBlockV = cUnit->tempBlockV; |
| 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 | */ |
| 405 | if (bb == cUnit->entryBlock) return false; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 406 | |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 407 | SetInitialBits(tempBlockV, numTotalBlocks); |
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 | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 412 | BasicBlock* predBB = reinterpret_cast<BasicBlock*>(GrowableListIteratorNext(&iter)); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 413 | if (!predBB) break; |
| 414 | /* tempBlockV = tempBlockV ^ dominators */ |
| 415 | if (predBB->dominators != NULL) { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 416 | IntersectBitVectors(tempBlockV, tempBlockV, predBB->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 | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 419 | SetBit(cUnit, tempBlockV, bb->id); |
| 420 | if (CompareBitVectors(tempBlockV, bb->dominators)) { |
| 421 | CopyBitVector(bb->dominators, tempBlockV); |
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 | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 430 | * same iDom as ComputeblockIDom. |
buzbee | 5b53710 | 2012-01-17 17:33:47 -0800 | [diff] [blame] | 431 | */ |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 432 | static bool SlowComputeBlockIDom(CompilationUnit* cUnit, BasicBlock* bb) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 433 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 434 | GrowableList* blockList = &cUnit->blockList; |
| 435 | ArenaBitVector* tempBlockV = cUnit->tempBlockV; |
| 436 | ArenaBitVectorIterator bvIterator; |
| 437 | BasicBlock* iDom; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 438 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 439 | if (bb == cUnit->entryBlock) return false; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 440 | |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 441 | CopyBitVector(tempBlockV, bb->dominators); |
| 442 | ClearBit(tempBlockV, bb->id); |
| 443 | BitVectorIteratorInit(tempBlockV, &bvIterator); |
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 | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 446 | DCHECK_NE(CountSetBits(tempBlockV), 0); |
| 447 | if (CountSetBits(tempBlockV) == 1) { |
buzbee | cbd6d44 | 2012-11-17 14:11:25 -0800 | [diff] [blame] | 448 | iDom = reinterpret_cast<BasicBlock*> |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 449 | (GrowableListGetElement(blockList, BitVectorIteratorNext(&bvIterator))); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 450 | bb->iDom = iDom; |
| 451 | } else { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 452 | int iDomIdx = BitVectorIteratorNext(&bvIterator); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 453 | DCHECK_NE(iDomIdx, -1); |
| 454 | while (true) { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 455 | int nextDom = BitVectorIteratorNext(&bvIterator); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 456 | if (nextDom == -1) break; |
buzbee | cbd6d44 | 2012-11-17 14:11:25 -0800 | [diff] [blame] | 457 | BasicBlock* nextDomBB = |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 458 | reinterpret_cast<BasicBlock*>(GrowableListGetElement(blockList, nextDom)); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 459 | /* iDom dominates nextDom - set new iDom */ |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 460 | if (IsBitSet(nextDomBB->dominators, iDomIdx)) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 461 | iDomIdx = nextDom; |
| 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 | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 465 | iDom = reinterpret_cast<BasicBlock*>(GrowableListGetElement(blockList, iDomIdx)); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 466 | /* Set the immediate dominator block for bb */ |
| 467 | bb->iDom = iDom; |
| 468 | } |
| 469 | /* Add bb to the iDominated set of the immediate dominator block */ |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 470 | SetBit(cUnit, iDom->iDominated, 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 | /* |
| 475 | * Walk through the ordered iDom list until we reach common parent. |
| 476 | * Given the ordering of iDomList, this common parent represents the |
| 477 | * last element of the intersection of block1 and block2 dominators. |
| 478 | */ |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 479 | static int FindCommonParent(CompilationUnit *cUnit, 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) { |
| 483 | block1 = cUnit->iDomList[block1]; |
| 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) { |
| 487 | block2 = cUnit->iDomList[block2]; |
| 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 | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 495 | static bool ComputeblockIDom(CompilationUnit* cUnit, 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 */ |
| 501 | if (bb == cUnit->entryBlock) { |
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 | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 510 | BasicBlock* predBB = reinterpret_cast<BasicBlock*>(GrowableListIteratorNext(&iter)); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 511 | CHECK(predBB != NULL); |
| 512 | if (cUnit->iDomList[predBB->dfsId] != NOTVISITED) { |
| 513 | idom = predBB->dfsId; |
| 514 | break; |
| 515 | } |
| 516 | } |
| 517 | |
| 518 | /* Scan the rest of the predecessors */ |
| 519 | while (true) { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 520 | BasicBlock* predBB = reinterpret_cast<BasicBlock*>(GrowableListIteratorNext(&iter)); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 521 | if (!predBB) break; |
| 522 | if (cUnit->iDomList[predBB->dfsId] == NOTVISITED) { |
| 523 | continue; |
| 524 | } else { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 525 | idom = FindCommonParent(cUnit, predBB->dfsId, 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? */ |
| 532 | if (cUnit->iDomList[bb->dfsId] != idom) { |
| 533 | cUnit->iDomList[bb->dfsId] = idom; |
| 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 | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 540 | static bool ComputeBlockDominiators(CompilationUnit* cUnit, BasicBlock* bb) |
buzbee | 5b53710 | 2012-01-17 17:33:47 -0800 | [diff] [blame] | 541 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 542 | if (bb == cUnit->entryBlock) { |
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 | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 545 | CopyBitVector(bb->dominators, bb->iDom->dominators); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 546 | } |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 547 | SetBit(cUnit, 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 | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 551 | static bool SetDominators(CompilationUnit* cUnit, BasicBlock* bb) |
buzbee | 5b53710 | 2012-01-17 17:33:47 -0800 | [diff] [blame] | 552 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 553 | if (bb != cUnit->entryBlock) { |
| 554 | int iDomDFSIdx = cUnit->iDomList[bb->dfsId]; |
| 555 | DCHECK_NE(iDomDFSIdx, NOTVISITED); |
| 556 | int iDomIdx = cUnit->dfsPostOrder.elemList[iDomDFSIdx]; |
buzbee | cbd6d44 | 2012-11-17 14:11:25 -0800 | [diff] [blame] | 557 | BasicBlock* iDom = |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 558 | reinterpret_cast<BasicBlock*>(GrowableListGetElement(&cUnit->blockList, iDomIdx)); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 559 | if (cUnit->enableDebug & (1 << kDebugVerifyDataflow)) { |
| 560 | DCHECK_EQ(bb->iDom->id, iDom->id); |
buzbee | 5b53710 | 2012-01-17 17:33:47 -0800 | [diff] [blame] | 561 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 562 | bb->iDom = iDom; |
| 563 | /* Add bb to the iDominated set of the immediate dominator block */ |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 564 | SetBit(cUnit, iDom->iDominated, 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 | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 570 | static void ComputeDominators(CompilationUnit* cUnit) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 571 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 572 | int numReachableBlocks = cUnit->numReachableBlocks; |
| 573 | int numTotalBlocks = cUnit->blockList.numUsed; |
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 | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 576 | DataFlowAnalysisDispatcher(cUnit, InitializeDominationInfo, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 577 | kReachableNodes, false /* isIterative */); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 578 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 579 | /* Initalize & Clear iDomList */ |
| 580 | if (cUnit->iDomList == NULL) { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 581 | cUnit->iDomList = static_cast<int*>(NewMem(cUnit, sizeof(int) * numReachableBlocks, |
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 | } |
| 584 | for (int i = 0; i < numReachableBlocks; i++) { |
| 585 | cUnit->iDomList[i] = NOTVISITED; |
| 586 | } |
buzbee | 5b53710 | 2012-01-17 17:33:47 -0800 | [diff] [blame] | 587 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 588 | /* For post-order, last block is entry block. Set its iDom to istelf */ |
| 589 | DCHECK_EQ(cUnit->entryBlock->dfsId, numReachableBlocks-1); |
| 590 | cUnit->iDomList[cUnit->entryBlock->dfsId] = cUnit->entryBlock->dfsId; |
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 | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 593 | DataFlowAnalysisDispatcher(cUnit, ComputeblockIDom, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 594 | kReversePostOrderTraversal, |
| 595 | true /* isIterative */); |
| 596 | |
| 597 | /* Set the dominator for the root node */ |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 598 | ClearAllBits(cUnit->entryBlock->dominators); |
| 599 | SetBit(cUnit, cUnit->entryBlock->dominators, cUnit->entryBlock->id); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 600 | |
| 601 | if (cUnit->tempBlockV == NULL) { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 602 | cUnit->tempBlockV = AllocBitVector(cUnit, numTotalBlocks, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 603 | false /* expandable */, |
| 604 | kBitMapTmpBlockV); |
| 605 | } else { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 606 | ClearAllBits(cUnit->tempBlockV); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 607 | } |
| 608 | cUnit->entryBlock->iDom = NULL; |
| 609 | |
| 610 | /* For testing, compute sets using alternate mechanism */ |
| 611 | if (cUnit->enableDebug & (1 << kDebugVerifyDataflow)) { |
| 612 | // Use alternate mechanism to compute dominators for comparison |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 613 | DataFlowAnalysisDispatcher(cUnit, SlowComputeBlockDominators, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 614 | kPreOrderDFSTraversal, |
buzbee | 5b53710 | 2012-01-17 17:33:47 -0800 | [diff] [blame] | 615 | true /* isIterative */); |
| 616 | |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 617 | DataFlowAnalysisDispatcher(cUnit, SlowComputeBlockIDom, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 618 | kReachableNodes, |
| 619 | false /* isIterative */); |
| 620 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 621 | |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 622 | DataFlowAnalysisDispatcher(cUnit, SetDominators, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 623 | kReachableNodes, |
| 624 | false /* isIterative */); |
buzbee | 5b53710 | 2012-01-17 17:33:47 -0800 | [diff] [blame] | 625 | |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 626 | DataFlowAnalysisDispatcher(cUnit, ComputeBlockDominiators, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 627 | kReversePostOrderTraversal, |
| 628 | false /* isIterative */); |
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 |
| 632 | * iDominated sets. |
| 633 | */ |
| 634 | if (cUnit->domPostOrderTraversal.elemList == NULL) { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 635 | CompilerInitGrowableList(cUnit, &cUnit->domPostOrderTraversal, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 636 | numReachableBlocks, kListDomPostOrderTraversal); |
| 637 | } else { |
| 638 | cUnit->domPostOrderTraversal.numUsed = 0; |
| 639 | } |
buzbee | 5b53710 | 2012-01-17 17:33:47 -0800 | [diff] [blame] | 640 | |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 641 | ComputeDomPostOrderTraversal(cUnit, cUnit->entryBlock); |
buzbee | cbd6d44 | 2012-11-17 14:11:25 -0800 | [diff] [blame] | 642 | DCHECK_EQ(cUnit->domPostOrderTraversal.numUsed, static_cast<unsigned>(cUnit->numReachableBlocks)); |
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 | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 645 | DataFlowAnalysisDispatcher(cUnit, ComputeDominanceFrontier, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 646 | kPostOrderDOMTraversal, |
| 647 | false /* isIterative */); |
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 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 657 | if (dest->storageSize != src1->storageSize || |
| 658 | dest->storageSize != src2->storageSize || |
| 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; |
| 665 | for (idx = 0; idx < dest->storageSize; idx++) { |
| 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 | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 675 | static bool ComputeBlockLiveIns(CompilationUnit* cUnit, BasicBlock* bb) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 676 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 677 | ArenaBitVector* tempDalvikRegisterV = cUnit->tempDalvikRegisterV; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 678 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 679 | if (bb->dataFlowInfo == NULL) return false; |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 680 | CopyBitVector(tempDalvikRegisterV, bb->dataFlowInfo->liveInV); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 681 | if (bb->taken && bb->taken->dataFlowInfo) |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 682 | ComputeSuccLineIn(tempDalvikRegisterV, bb->taken->dataFlowInfo->liveInV, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 683 | bb->dataFlowInfo->defV); |
| 684 | if (bb->fallThrough && bb->fallThrough->dataFlowInfo) |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 685 | ComputeSuccLineIn(tempDalvikRegisterV, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 686 | bb->fallThrough->dataFlowInfo->liveInV, |
| 687 | bb->dataFlowInfo->defV); |
| 688 | if (bb->successorBlockList.blockListType != kNotUsed) { |
| 689 | GrowableListIterator iterator; |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 690 | GrowableListIteratorInit(&bb->successorBlockList.blocks, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 691 | &iterator); |
| 692 | while (true) { |
| 693 | SuccessorBlockInfo *successorBlockInfo = |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 694 | reinterpret_cast<SuccessorBlockInfo*>(GrowableListIteratorNext(&iterator)); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 695 | if (successorBlockInfo == NULL) break; |
| 696 | BasicBlock* succBB = successorBlockInfo->block; |
| 697 | if (succBB->dataFlowInfo) { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 698 | ComputeSuccLineIn(tempDalvikRegisterV, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 699 | succBB->dataFlowInfo->liveInV, |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 700 | bb->dataFlowInfo->defV); |
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 | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 704 | if (CompareBitVectors(tempDalvikRegisterV, bb->dataFlowInfo->liveInV)) { |
| 705 | CopyBitVector(bb->dataFlowInfo->liveInV, tempDalvikRegisterV); |
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 | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 712 | static void InsertPhiNodes(CompilationUnit* cUnit) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 713 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 714 | int dalvikReg; |
| 715 | const GrowableList* blockList = &cUnit->blockList; |
| 716 | ArenaBitVector* phiBlocks = |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 717 | AllocBitVector(cUnit, cUnit->numBlocks, false, kBitMapPhi); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 718 | ArenaBitVector* tmpBlocks = |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 719 | AllocBitVector(cUnit, cUnit->numBlocks, false, kBitMapTmpBlocks); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 720 | ArenaBitVector* inputBlocks = |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 721 | AllocBitVector(cUnit, cUnit->numBlocks, false, kBitMapInputBlocks); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 722 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 723 | cUnit->tempDalvikRegisterV = |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 724 | AllocBitVector(cUnit, cUnit->numDalvikRegisters, 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 | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 727 | DataFlowAnalysisDispatcher(cUnit, ComputeBlockLiveIns, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 728 | kPostOrderDFSTraversal, true /* isIterative */); |
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 | 2a83e8f | 2012-07-13 16:42:30 -0700 | [diff] [blame] | 731 | for (dalvikReg = cUnit->numDalvikRegisters - 1; dalvikReg >= 0; dalvikReg--) { |
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 | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 735 | CopyBitVector(inputBlocks, cUnit->defBlockMatrix[dalvikReg]); |
| 736 | ClearAllBits(phiBlocks); |
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 | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 741 | ClearAllBits(tmpBlocks); |
| 742 | BitVectorIteratorInit(inputBlocks, &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; |
| 747 | BasicBlock* defBB = |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 748 | reinterpret_cast<BasicBlock*>(GrowableListGetElement(blockList, idx)); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 749 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 750 | /* Merge the dominance frontier to tmpBlocks */ |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 751 | //TUNING: hot call to UnifyBitVetors |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 752 | if (defBB->domFrontier != NULL) { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 753 | UnifyBitVetors(tmpBlocks, tmpBlocks, defBB->domFrontier); |
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 | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 756 | if (CompareBitVectors(phiBlocks, tmpBlocks)) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 757 | change = true; |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 758 | CopyBitVector(phiBlocks, tmpBlocks); |
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 | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 764 | CopyBitVector(inputBlocks, phiBlocks); |
| 765 | UnifyBitVetors(inputBlocks, inputBlocks, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 766 | cUnit->defBlockMatrix[dalvikReg]); |
| 767 | } |
| 768 | } while (change); |
| 769 | |
| 770 | /* |
| 771 | * Insert a phi node for dalvikReg in the phiBlocks if the Dalvik |
| 772 | * register is in the live-in set. |
| 773 | */ |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 774 | BitVectorIteratorInit(phiBlocks, &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; |
| 778 | BasicBlock* phiBB = |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 779 | reinterpret_cast<BasicBlock*>(GrowableListGetElement(blockList, 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 | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 781 | if (!IsBitSet(phiBB->dataFlowInfo->liveInV, dalvikReg)) continue; |
| 782 | MIR *phi = static_cast<MIR*>(NewMem(cUnit, sizeof(MIR), true, kAllocDFInfo)); |
buzbee | cbd6d44 | 2012-11-17 14:11:25 -0800 | [diff] [blame] | 783 | phi->dalvikInsn.opcode = static_cast<Instruction::Code>(kMirOpPhi); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 784 | phi->dalvikInsn.vA = dalvikReg; |
| 785 | phi->offset = phiBB->startOffset; |
| 786 | phi->meta.phiNext = cUnit->phiList; |
| 787 | cUnit->phiList = phi; |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 788 | PrependMIR(phiBB, phi); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 789 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 790 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 791 | } |
| 792 | |
| 793 | /* |
| 794 | * Worker function to insert phi-operands with latest SSA names from |
| 795 | * predecessor blocks |
| 796 | */ |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 797 | static bool InsertPhiNodeOperands(CompilationUnit* cUnit, BasicBlock* bb) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 798 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 799 | GrowableListIterator iter; |
| 800 | MIR *mir; |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 801 | std::vector<int> uses; |
| 802 | std::vector<int> incomingArc; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 803 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 804 | /* Phi nodes are at the beginning of each block */ |
| 805 | for (mir = bb->firstMIRInsn; mir; mir = mir->next) { |
buzbee | cbd6d44 | 2012-11-17 14:11:25 -0800 | [diff] [blame] | 806 | if (mir->dalvikInsn.opcode != static_cast<Instruction::Code>(kMirOpPhi)) |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 807 | return true; |
| 808 | int ssaReg = mir->ssaRep->defs[0]; |
| 809 | DCHECK_GE(ssaReg, 0); // Shouldn't see compiler temps here |
| 810 | int vReg = SRegToVReg(cUnit, ssaReg); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 811 | |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 812 | uses.clear(); |
| 813 | incomingArc.clear(); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 814 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 815 | /* Iterate through the predecessors */ |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 816 | GrowableListIteratorInit(bb->predecessors, &iter); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 817 | while (true) { |
| 818 | BasicBlock* predBB = |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 819 | reinterpret_cast<BasicBlock*>(GrowableListIteratorNext(&iter)); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 820 | if (!predBB) break; |
| 821 | int ssaReg = predBB->dataFlowInfo->vRegToSSAMap[vReg]; |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 822 | uses.push_back(ssaReg); |
| 823 | incomingArc.push_back(predBB->id); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 824 | } |
| 825 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 826 | /* Count the number of SSA registers for a Dalvik register */ |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 827 | int numUses = uses.size(); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 828 | mir->ssaRep->numUses = numUses; |
| 829 | mir->ssaRep->uses = |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 830 | static_cast<int*>(NewMem(cUnit, sizeof(int) * numUses, false, kAllocDFInfo)); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 831 | mir->ssaRep->fpUse = |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 832 | static_cast<bool*>(NewMem(cUnit, sizeof(bool) * numUses, true, kAllocDFInfo)); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 833 | int* incoming = |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 834 | static_cast<int*>(NewMem(cUnit, sizeof(int) * numUses, false, kAllocDFInfo)); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 835 | // 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] | 836 | mir->dalvikInsn.vB = reinterpret_cast<uintptr_t>(incoming); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 837 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 838 | /* Set the uses array for the phi node */ |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 839 | int *usePtr = mir->ssaRep->uses; |
| 840 | for (int i = 0; i < numUses; i++) { |
| 841 | *usePtr++ = uses[i]; |
| 842 | *incoming++ = incomingArc[i]; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 843 | } |
| 844 | } |
| 845 | |
| 846 | return true; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 847 | } |
| 848 | |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 849 | static void DoDFSPreOrderSSARename(CompilationUnit* cUnit, BasicBlock* block) |
buzbee | f0cde54 | 2011-09-13 14:55:02 -0700 | [diff] [blame] | 850 | { |
| 851 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 852 | if (block->visited || block->hidden) return; |
| 853 | block->visited = true; |
buzbee | f0cde54 | 2011-09-13 14:55:02 -0700 | [diff] [blame] | 854 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 855 | /* Process this block */ |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 856 | DoSSAConversion(cUnit, block); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 857 | int mapSize = sizeof(int) * cUnit->numDalvikRegisters; |
buzbee | f0cde54 | 2011-09-13 14:55:02 -0700 | [diff] [blame] | 858 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 859 | /* Save SSA map snapshot */ |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 860 | int* savedSSAMap = static_cast<int*>(NewMem(cUnit, mapSize, false, kAllocDalvikToSSAMap)); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 861 | memcpy(savedSSAMap, cUnit->vRegToSSAMap, mapSize); |
buzbee | f0cde54 | 2011-09-13 14:55:02 -0700 | [diff] [blame] | 862 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 863 | if (block->fallThrough) { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 864 | DoDFSPreOrderSSARename(cUnit, block->fallThrough); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 865 | /* Restore SSA map snapshot */ |
| 866 | memcpy(cUnit->vRegToSSAMap, savedSSAMap, mapSize); |
| 867 | } |
| 868 | if (block->taken) { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 869 | DoDFSPreOrderSSARename(cUnit, block->taken); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 870 | /* Restore SSA map snapshot */ |
| 871 | memcpy(cUnit->vRegToSSAMap, savedSSAMap, mapSize); |
| 872 | } |
| 873 | if (block->successorBlockList.blockListType != kNotUsed) { |
| 874 | GrowableListIterator iterator; |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 875 | GrowableListIteratorInit(&block->successorBlockList.blocks, &iterator); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 876 | while (true) { |
| 877 | SuccessorBlockInfo *successorBlockInfo = |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 878 | reinterpret_cast<SuccessorBlockInfo*>(GrowableListIteratorNext(&iterator)); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 879 | if (successorBlockInfo == NULL) break; |
| 880 | BasicBlock* succBB = successorBlockInfo->block; |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 881 | DoDFSPreOrderSSARename(cUnit, succBB); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 882 | /* Restore SSA map snapshot */ |
| 883 | memcpy(cUnit->vRegToSSAMap, savedSSAMap, mapSize); |
buzbee | f0cde54 | 2011-09-13 14:55:02 -0700 | [diff] [blame] | 884 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 885 | } |
| 886 | cUnit->vRegToSSAMap = savedSSAMap; |
| 887 | return; |
buzbee | f0cde54 | 2011-09-13 14:55:02 -0700 | [diff] [blame] | 888 | } |
| 889 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 890 | /* Perform SSA transformation for the whole method */ |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 891 | void SSATransformation(CompilationUnit* cUnit) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 892 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 893 | /* Compute the DFS order */ |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 894 | ComputeDFSOrders(cUnit); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 895 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 896 | if (!cUnit->disableDataflow) { |
| 897 | /* Compute the dominator info */ |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 898 | ComputeDominators(cUnit); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 899 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 900 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 901 | /* Allocate data structures in preparation for SSA conversion */ |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 902 | CompilerInitializeSSAConversion(cUnit); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 903 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 904 | if (!cUnit->disableDataflow) { |
| 905 | /* Find out the "Dalvik reg def x block" relation */ |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 906 | ComputeDefBlockMatrix(cUnit); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 907 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 908 | /* Insert phi nodes to dominance frontiers for all variables */ |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 909 | InsertPhiNodes(cUnit); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 910 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 911 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 912 | /* Rename register names by local defs and phi nodes */ |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 913 | DataFlowAnalysisDispatcher(cUnit, ClearVisitedFlag, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 914 | kAllNodes, false /* isIterative */); |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 915 | DoDFSPreOrderSSARename(cUnit, cUnit->entryBlock); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 916 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 917 | if (!cUnit->disableDataflow) { |
| 918 | /* |
| 919 | * Shared temp bit vector used by each block to count the number of defs |
| 920 | * from all the predecessor blocks. |
| 921 | */ |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 922 | cUnit->tempSSARegisterV = AllocBitVector(cUnit, cUnit->numSSARegs, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 923 | false, kBitMapTempSSARegisterV); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 924 | |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 925 | cUnit->tempSSABlockIdV = |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 926 | static_cast<int*>(NewMem(cUnit, sizeof(int) * cUnit->numSSARegs, false, kAllocDFInfo)); |
buzbee | 2cfc639 | 2012-05-07 14:51:40 -0700 | [diff] [blame] | 927 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 928 | /* Insert phi-operands with latest SSA names from predecessor blocks */ |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 929 | DataFlowAnalysisDispatcher(cUnit, InsertPhiNodeOperands, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 930 | kReachableNodes, false /* isIterative */); |
| 931 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 932 | } |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 933 | |
| 934 | } // namespace art |