Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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 | |
| 17 | #include "nodes.h" |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 18 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 19 | #include "ssa_builder.h" |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 20 | #include "utils/growable_array.h" |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 21 | #include "scoped_thread_state_change.h" |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 22 | |
| 23 | namespace art { |
| 24 | |
| 25 | void HGraph::AddBlock(HBasicBlock* block) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 26 | block->SetBlockId(blocks_.Size()); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 27 | blocks_.Add(block); |
| 28 | } |
| 29 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 30 | void HGraph::FindBackEdges(ArenaBitVector* visited) { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 31 | ArenaBitVector visiting(arena_, blocks_.Size(), false); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 32 | VisitBlockForBackEdges(entry_block_, visited, &visiting); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 33 | } |
| 34 | |
Roland Levillain | fc600dc | 2014-12-02 17:16:31 +0000 | [diff] [blame] | 35 | static void RemoveAsUser(HInstruction* instruction) { |
| 36 | for (size_t i = 0; i < instruction->InputCount(); i++) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 37 | instruction->RemoveAsUserOfInput(i); |
Roland Levillain | fc600dc | 2014-12-02 17:16:31 +0000 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | HEnvironment* environment = instruction->GetEnvironment(); |
| 41 | if (environment != nullptr) { |
| 42 | for (size_t i = 0, e = environment->Size(); i < e; ++i) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 43 | if (environment->GetInstructionAt(i) != nullptr) { |
| 44 | environment->RemoveAsUserOfInput(i); |
Roland Levillain | fc600dc | 2014-12-02 17:16:31 +0000 | [diff] [blame] | 45 | } |
| 46 | } |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | void HGraph::RemoveInstructionsAsUsersFromDeadBlocks(const ArenaBitVector& visited) const { |
| 51 | for (size_t i = 0; i < blocks_.Size(); ++i) { |
| 52 | if (!visited.IsBitSet(i)) { |
| 53 | HBasicBlock* block = blocks_.Get(i); |
Nicolas Geoffray | f776b92 | 2015-04-15 18:22:45 +0100 | [diff] [blame] | 54 | DCHECK(block->GetPhis().IsEmpty()) << "Phis are not inserted at this stage"; |
Roland Levillain | fc600dc | 2014-12-02 17:16:31 +0000 | [diff] [blame] | 55 | for (HInstructionIterator it(block->GetInstructions()); !it.Done(); it.Advance()) { |
| 56 | RemoveAsUser(it.Current()); |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | |
Nicolas Geoffray | f776b92 | 2015-04-15 18:22:45 +0100 | [diff] [blame] | 62 | void HGraph::RemoveDeadBlocks(const ArenaBitVector& visited) { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 63 | for (size_t i = 0; i < blocks_.Size(); ++i) { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 64 | if (!visited.IsBitSet(i)) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 65 | HBasicBlock* block = blocks_.Get(i); |
Nicolas Geoffray | f776b92 | 2015-04-15 18:22:45 +0100 | [diff] [blame] | 66 | // We only need to update the successor, which might be live. |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 67 | for (size_t j = 0; j < block->GetSuccessors().Size(); ++j) { |
| 68 | block->GetSuccessors().Get(j)->RemovePredecessor(block); |
| 69 | } |
Nicolas Geoffray | f776b92 | 2015-04-15 18:22:45 +0100 | [diff] [blame] | 70 | // Remove the block from the list of blocks, so that further analyses |
| 71 | // never see it. |
| 72 | blocks_.Put(i, nullptr); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 73 | } |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | void HGraph::VisitBlockForBackEdges(HBasicBlock* block, |
| 78 | ArenaBitVector* visited, |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 79 | ArenaBitVector* visiting) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 80 | int id = block->GetBlockId(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 81 | if (visited->IsBitSet(id)) return; |
| 82 | |
| 83 | visited->SetBit(id); |
| 84 | visiting->SetBit(id); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 85 | for (size_t i = 0; i < block->GetSuccessors().Size(); i++) { |
| 86 | HBasicBlock* successor = block->GetSuccessors().Get(i); |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 87 | if (visiting->IsBitSet(successor->GetBlockId())) { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 88 | successor->AddBackEdge(block); |
| 89 | } else { |
| 90 | VisitBlockForBackEdges(successor, visited, visiting); |
| 91 | } |
| 92 | } |
| 93 | visiting->ClearBit(id); |
| 94 | } |
| 95 | |
| 96 | void HGraph::BuildDominatorTree() { |
| 97 | ArenaBitVector visited(arena_, blocks_.Size(), false); |
| 98 | |
| 99 | // (1) Find the back edges in the graph doing a DFS traversal. |
| 100 | FindBackEdges(&visited); |
| 101 | |
Roland Levillain | fc600dc | 2014-12-02 17:16:31 +0000 | [diff] [blame] | 102 | // (2) Remove instructions and phis from blocks not visited during |
| 103 | // the initial DFS as users from other instructions, so that |
| 104 | // users can be safely removed before uses later. |
| 105 | RemoveInstructionsAsUsersFromDeadBlocks(visited); |
| 106 | |
| 107 | // (3) Remove blocks not visited during the initial DFS. |
| 108 | // Step (4) requires dead blocks to be removed from the |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 109 | // predecessors list of live blocks. |
| 110 | RemoveDeadBlocks(visited); |
| 111 | |
Roland Levillain | fc600dc | 2014-12-02 17:16:31 +0000 | [diff] [blame] | 112 | // (4) Simplify the CFG now, so that we don't need to recompute |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 113 | // dominators and the reverse post order. |
| 114 | SimplifyCFG(); |
| 115 | |
Roland Levillain | fc600dc | 2014-12-02 17:16:31 +0000 | [diff] [blame] | 116 | // (5) Compute the immediate dominator of each block. We visit |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 117 | // the successors of a block only when all its forward branches |
| 118 | // have been processed. |
| 119 | GrowableArray<size_t> visits(arena_, blocks_.Size()); |
| 120 | visits.SetSize(blocks_.Size()); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 121 | reverse_post_order_.Add(entry_block_); |
| 122 | for (size_t i = 0; i < entry_block_->GetSuccessors().Size(); i++) { |
| 123 | VisitBlockForDominatorTree(entry_block_->GetSuccessors().Get(i), entry_block_, &visits); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 124 | } |
| 125 | } |
| 126 | |
| 127 | HBasicBlock* HGraph::FindCommonDominator(HBasicBlock* first, HBasicBlock* second) const { |
| 128 | ArenaBitVector visited(arena_, blocks_.Size(), false); |
| 129 | // Walk the dominator tree of the first block and mark the visited blocks. |
| 130 | while (first != nullptr) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 131 | visited.SetBit(first->GetBlockId()); |
| 132 | first = first->GetDominator(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 133 | } |
| 134 | // Walk the dominator tree of the second block until a marked block is found. |
| 135 | while (second != nullptr) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 136 | if (visited.IsBitSet(second->GetBlockId())) { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 137 | return second; |
| 138 | } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 139 | second = second->GetDominator(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 140 | } |
| 141 | LOG(ERROR) << "Could not find common dominator"; |
| 142 | return nullptr; |
| 143 | } |
| 144 | |
| 145 | void HGraph::VisitBlockForDominatorTree(HBasicBlock* block, |
| 146 | HBasicBlock* predecessor, |
| 147 | GrowableArray<size_t>* visits) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 148 | if (block->GetDominator() == nullptr) { |
| 149 | block->SetDominator(predecessor); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 150 | } else { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 151 | block->SetDominator(FindCommonDominator(block->GetDominator(), predecessor)); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 152 | } |
| 153 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 154 | visits->Increment(block->GetBlockId()); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 155 | // Once all the forward edges have been visited, we know the immediate |
| 156 | // dominator of the block. We can then start visiting its successors. |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 157 | if (visits->Get(block->GetBlockId()) == |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 158 | block->GetPredecessors().Size() - block->NumberOfBackEdges()) { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 159 | block->GetDominator()->AddDominatedBlock(block); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 160 | reverse_post_order_.Add(block); |
| 161 | for (size_t i = 0; i < block->GetSuccessors().Size(); i++) { |
| 162 | VisitBlockForDominatorTree(block->GetSuccessors().Get(i), block, visits); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 163 | } |
| 164 | } |
| 165 | } |
| 166 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 167 | void HGraph::TransformToSsa() { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 168 | DCHECK(!reverse_post_order_.IsEmpty()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 169 | SsaBuilder ssa_builder(this); |
| 170 | ssa_builder.BuildSsa(); |
| 171 | } |
| 172 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 173 | void HGraph::SplitCriticalEdge(HBasicBlock* block, HBasicBlock* successor) { |
| 174 | // Insert a new node between `block` and `successor` to split the |
| 175 | // critical edge. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 176 | HBasicBlock* new_block = new (arena_) HBasicBlock(this, successor->GetDexPc()); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 177 | AddBlock(new_block); |
| 178 | new_block->AddInstruction(new (arena_) HGoto()); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 179 | block->ReplaceSuccessor(successor, new_block); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 180 | new_block->AddSuccessor(successor); |
| 181 | if (successor->IsLoopHeader()) { |
| 182 | // If we split at a back edge boundary, make the new block the back edge. |
| 183 | HLoopInformation* info = successor->GetLoopInformation(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 184 | if (info->IsBackEdge(*block)) { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 185 | info->RemoveBackEdge(block); |
| 186 | info->AddBackEdge(new_block); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 187 | } |
| 188 | } |
| 189 | } |
| 190 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 191 | void HGraph::SimplifyLoop(HBasicBlock* header) { |
| 192 | HLoopInformation* info = header->GetLoopInformation(); |
| 193 | |
| 194 | // If there are more than one back edge, make them branch to the same block that |
| 195 | // will become the only back edge. This simplifies finding natural loops in the |
| 196 | // graph. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 197 | // Also, if the loop is a do/while (that is the back edge is an if), change the |
| 198 | // back edge to be a goto. This simplifies code generation of suspend cheks. |
| 199 | if (info->NumberOfBackEdges() > 1 || info->GetBackEdges().Get(0)->GetLastInstruction()->IsIf()) { |
| 200 | HBasicBlock* new_back_edge = new (arena_) HBasicBlock(this, header->GetDexPc()); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 201 | AddBlock(new_back_edge); |
| 202 | new_back_edge->AddInstruction(new (arena_) HGoto()); |
| 203 | for (size_t pred = 0, e = info->GetBackEdges().Size(); pred < e; ++pred) { |
| 204 | HBasicBlock* back_edge = info->GetBackEdges().Get(pred); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 205 | back_edge->ReplaceSuccessor(header, new_back_edge); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 206 | } |
| 207 | info->ClearBackEdges(); |
| 208 | info->AddBackEdge(new_back_edge); |
| 209 | new_back_edge->AddSuccessor(header); |
| 210 | } |
| 211 | |
| 212 | // Make sure the loop has only one pre header. This simplifies SSA building by having |
| 213 | // to just look at the pre header to know which locals are initialized at entry of the |
| 214 | // loop. |
| 215 | size_t number_of_incomings = header->GetPredecessors().Size() - info->NumberOfBackEdges(); |
| 216 | if (number_of_incomings != 1) { |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 217 | HBasicBlock* pre_header = new (arena_) HBasicBlock(this, header->GetDexPc()); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 218 | AddBlock(pre_header); |
| 219 | pre_header->AddInstruction(new (arena_) HGoto()); |
| 220 | |
| 221 | ArenaBitVector back_edges(arena_, GetBlocks().Size(), false); |
| 222 | HBasicBlock* back_edge = info->GetBackEdges().Get(0); |
| 223 | for (size_t pred = 0; pred < header->GetPredecessors().Size(); ++pred) { |
| 224 | HBasicBlock* predecessor = header->GetPredecessors().Get(pred); |
| 225 | if (predecessor != back_edge) { |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 226 | predecessor->ReplaceSuccessor(header, pre_header); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 227 | pred--; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 228 | } |
| 229 | } |
| 230 | pre_header->AddSuccessor(header); |
| 231 | } |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 232 | |
| 233 | // Make sure the second predecessor of a loop header is the back edge. |
| 234 | if (header->GetPredecessors().Get(1) != info->GetBackEdges().Get(0)) { |
| 235 | header->SwapPredecessors(); |
| 236 | } |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 237 | |
| 238 | // Place the suspend check at the beginning of the header, so that live registers |
| 239 | // will be known when allocating registers. Note that code generation can still |
| 240 | // generate the suspend check at the back edge, but needs to be careful with |
| 241 | // loop phi spill slots (which are not written to at back edge). |
| 242 | HInstruction* first_instruction = header->GetFirstInstruction(); |
| 243 | if (!first_instruction->IsSuspendCheck()) { |
| 244 | HSuspendCheck* check = new (arena_) HSuspendCheck(header->GetDexPc()); |
| 245 | header->InsertInstructionBefore(check, first_instruction); |
| 246 | first_instruction = check; |
| 247 | } |
| 248 | info->SetSuspendCheck(first_instruction->AsSuspendCheck()); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | void HGraph::SimplifyCFG() { |
| 252 | // Simplify the CFG for future analysis, and code generation: |
| 253 | // (1): Split critical edges. |
| 254 | // (2): Simplify loops by having only one back edge, and one preheader. |
| 255 | for (size_t i = 0; i < blocks_.Size(); ++i) { |
| 256 | HBasicBlock* block = blocks_.Get(i); |
Nicolas Geoffray | f776b92 | 2015-04-15 18:22:45 +0100 | [diff] [blame] | 257 | if (block == nullptr) continue; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 258 | if (block->GetSuccessors().Size() > 1) { |
| 259 | for (size_t j = 0; j < block->GetSuccessors().Size(); ++j) { |
| 260 | HBasicBlock* successor = block->GetSuccessors().Get(j); |
| 261 | if (successor->GetPredecessors().Size() > 1) { |
| 262 | SplitCriticalEdge(block, successor); |
| 263 | --j; |
| 264 | } |
| 265 | } |
| 266 | } |
| 267 | if (block->IsLoopHeader()) { |
| 268 | SimplifyLoop(block); |
| 269 | } |
| 270 | } |
| 271 | } |
| 272 | |
Nicolas Geoffray | f537012 | 2014-12-02 11:51:19 +0000 | [diff] [blame] | 273 | bool HGraph::AnalyzeNaturalLoops() const { |
Nicolas Geoffray | f776b92 | 2015-04-15 18:22:45 +0100 | [diff] [blame] | 274 | // Order does not matter. |
| 275 | for (HReversePostOrderIterator it(*this); !it.Done(); it.Advance()) { |
| 276 | HBasicBlock* block = it.Current(); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 277 | if (block->IsLoopHeader()) { |
| 278 | HLoopInformation* info = block->GetLoopInformation(); |
| 279 | if (!info->Populate()) { |
| 280 | // Abort if the loop is non natural. We currently bailout in such cases. |
| 281 | return false; |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | return true; |
| 286 | } |
| 287 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 288 | void HGraph::InsertConstant(HConstant* constant) { |
| 289 | // New constants are inserted before the final control-flow instruction |
| 290 | // of the graph, or at its end if called from the graph builder. |
| 291 | if (entry_block_->EndsWithControlFlowInstruction()) { |
| 292 | entry_block_->InsertInstructionBefore(constant, entry_block_->GetLastInstruction()); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 293 | } else { |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 294 | entry_block_->AddInstruction(constant); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 295 | } |
| 296 | } |
| 297 | |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 298 | HNullConstant* HGraph::GetNullConstant() { |
| 299 | if (cached_null_constant_ == nullptr) { |
| 300 | cached_null_constant_ = new (arena_) HNullConstant(); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 301 | InsertConstant(cached_null_constant_); |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 302 | } |
| 303 | return cached_null_constant_; |
| 304 | } |
| 305 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 306 | template <class InstructionType, typename ValueType> |
| 307 | InstructionType* HGraph::CreateConstant(ValueType value, |
| 308 | ArenaSafeMap<ValueType, InstructionType*>* cache) { |
| 309 | // Try to find an existing constant of the given value. |
| 310 | InstructionType* constant = nullptr; |
| 311 | auto cached_constant = cache->find(value); |
| 312 | if (cached_constant != cache->end()) { |
| 313 | constant = cached_constant->second; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 314 | } |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 315 | |
| 316 | // If not found or previously deleted, create and cache a new instruction. |
| 317 | if (constant == nullptr || constant->GetBlock() == nullptr) { |
| 318 | constant = new (arena_) InstructionType(value); |
| 319 | cache->Overwrite(value, constant); |
| 320 | InsertConstant(constant); |
| 321 | } |
| 322 | return constant; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 323 | } |
| 324 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 325 | HConstant* HGraph::GetConstant(Primitive::Type type, int64_t value) { |
| 326 | switch (type) { |
| 327 | case Primitive::Type::kPrimBoolean: |
| 328 | DCHECK(IsUint<1>(value)); |
| 329 | FALLTHROUGH_INTENDED; |
| 330 | case Primitive::Type::kPrimByte: |
| 331 | case Primitive::Type::kPrimChar: |
| 332 | case Primitive::Type::kPrimShort: |
| 333 | case Primitive::Type::kPrimInt: |
| 334 | DCHECK(IsInt(Primitive::ComponentSize(type) * kBitsPerByte, value)); |
| 335 | return GetIntConstant(static_cast<int32_t>(value)); |
| 336 | |
| 337 | case Primitive::Type::kPrimLong: |
| 338 | return GetLongConstant(value); |
| 339 | |
| 340 | default: |
| 341 | LOG(FATAL) << "Unsupported constant type"; |
| 342 | UNREACHABLE(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 343 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 344 | } |
| 345 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 346 | void HLoopInformation::Add(HBasicBlock* block) { |
| 347 | blocks_.SetBit(block->GetBlockId()); |
| 348 | } |
| 349 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 350 | void HLoopInformation::Remove(HBasicBlock* block) { |
| 351 | blocks_.ClearBit(block->GetBlockId()); |
| 352 | } |
| 353 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 354 | void HLoopInformation::PopulateRecursive(HBasicBlock* block) { |
| 355 | if (blocks_.IsBitSet(block->GetBlockId())) { |
| 356 | return; |
| 357 | } |
| 358 | |
| 359 | blocks_.SetBit(block->GetBlockId()); |
| 360 | block->SetInLoop(this); |
| 361 | for (size_t i = 0, e = block->GetPredecessors().Size(); i < e; ++i) { |
| 362 | PopulateRecursive(block->GetPredecessors().Get(i)); |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | bool HLoopInformation::Populate() { |
| 367 | DCHECK_EQ(GetBackEdges().Size(), 1u); |
| 368 | HBasicBlock* back_edge = GetBackEdges().Get(0); |
| 369 | DCHECK(back_edge->GetDominator() != nullptr); |
| 370 | if (!header_->Dominates(back_edge)) { |
| 371 | // This loop is not natural. Do not bother going further. |
| 372 | return false; |
| 373 | } |
| 374 | |
| 375 | // Populate this loop: starting with the back edge, recursively add predecessors |
| 376 | // that are not already part of that loop. Set the header as part of the loop |
| 377 | // to end the recursion. |
| 378 | // This is a recursive implementation of the algorithm described in |
| 379 | // "Advanced Compiler Design & Implementation" (Muchnick) p192. |
| 380 | blocks_.SetBit(header_->GetBlockId()); |
| 381 | PopulateRecursive(back_edge); |
| 382 | return true; |
| 383 | } |
| 384 | |
| 385 | HBasicBlock* HLoopInformation::GetPreHeader() const { |
| 386 | DCHECK_EQ(header_->GetPredecessors().Size(), 2u); |
| 387 | return header_->GetDominator(); |
| 388 | } |
| 389 | |
| 390 | bool HLoopInformation::Contains(const HBasicBlock& block) const { |
| 391 | return blocks_.IsBitSet(block.GetBlockId()); |
| 392 | } |
| 393 | |
| 394 | bool HLoopInformation::IsIn(const HLoopInformation& other) const { |
| 395 | return other.blocks_.IsBitSet(header_->GetBlockId()); |
| 396 | } |
| 397 | |
| 398 | bool HBasicBlock::Dominates(HBasicBlock* other) const { |
| 399 | // Walk up the dominator tree from `other`, to find out if `this` |
| 400 | // is an ancestor. |
| 401 | HBasicBlock* current = other; |
| 402 | while (current != nullptr) { |
| 403 | if (current == this) { |
| 404 | return true; |
| 405 | } |
| 406 | current = current->GetDominator(); |
| 407 | } |
| 408 | return false; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 409 | } |
| 410 | |
Nicolas Geoffray | 191c4b1 | 2014-10-07 14:14:27 +0100 | [diff] [blame] | 411 | static void UpdateInputsUsers(HInstruction* instruction) { |
| 412 | for (size_t i = 0, e = instruction->InputCount(); i < e; ++i) { |
| 413 | instruction->InputAt(i)->AddUseAt(instruction, i); |
| 414 | } |
| 415 | // Environment should be created later. |
| 416 | DCHECK(!instruction->HasEnvironment()); |
| 417 | } |
| 418 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 419 | void HBasicBlock::ReplaceAndRemoveInstructionWith(HInstruction* initial, |
| 420 | HInstruction* replacement) { |
| 421 | DCHECK(initial->GetBlock() == this); |
| 422 | InsertInstructionBefore(replacement, initial); |
| 423 | initial->ReplaceWith(replacement); |
| 424 | RemoveInstruction(initial); |
| 425 | } |
| 426 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 427 | static void Add(HInstructionList* instruction_list, |
| 428 | HBasicBlock* block, |
| 429 | HInstruction* instruction) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 430 | DCHECK(instruction->GetBlock() == nullptr); |
Nicolas Geoffray | 43c8642 | 2014-03-18 11:58:24 +0000 | [diff] [blame] | 431 | DCHECK_EQ(instruction->GetId(), -1); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 432 | instruction->SetBlock(block); |
| 433 | instruction->SetId(block->GetGraph()->GetNextInstructionId()); |
Nicolas Geoffray | 191c4b1 | 2014-10-07 14:14:27 +0100 | [diff] [blame] | 434 | UpdateInputsUsers(instruction); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 435 | instruction_list->AddInstruction(instruction); |
| 436 | } |
| 437 | |
| 438 | void HBasicBlock::AddInstruction(HInstruction* instruction) { |
| 439 | Add(&instructions_, this, instruction); |
| 440 | } |
| 441 | |
| 442 | void HBasicBlock::AddPhi(HPhi* phi) { |
| 443 | Add(&phis_, this, phi); |
| 444 | } |
| 445 | |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 446 | void HBasicBlock::InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor) { |
| 447 | DCHECK(!cursor->IsPhi()); |
| 448 | DCHECK(!instruction->IsPhi()); |
| 449 | DCHECK_EQ(instruction->GetId(), -1); |
| 450 | DCHECK_NE(cursor->GetId(), -1); |
| 451 | DCHECK_EQ(cursor->GetBlock(), this); |
| 452 | DCHECK(!instruction->IsControlFlow()); |
| 453 | instruction->SetBlock(this); |
| 454 | instruction->SetId(GetGraph()->GetNextInstructionId()); |
| 455 | UpdateInputsUsers(instruction); |
| 456 | instructions_.InsertInstructionBefore(instruction, cursor); |
| 457 | } |
| 458 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 459 | void HBasicBlock::InsertPhiAfter(HPhi* phi, HPhi* cursor) { |
| 460 | DCHECK_EQ(phi->GetId(), -1); |
| 461 | DCHECK_NE(cursor->GetId(), -1); |
| 462 | DCHECK_EQ(cursor->GetBlock(), this); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 463 | phi->SetBlock(this); |
| 464 | phi->SetId(GetGraph()->GetNextInstructionId()); |
| 465 | UpdateInputsUsers(phi); |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 466 | phis_.InsertInstructionAfter(phi, cursor); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 467 | } |
| 468 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 469 | static void Remove(HInstructionList* instruction_list, |
| 470 | HBasicBlock* block, |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 471 | HInstruction* instruction, |
| 472 | bool ensure_safety) { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 473 | DCHECK_EQ(block, instruction->GetBlock()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 474 | instruction->SetBlock(nullptr); |
| 475 | instruction_list->RemoveInstruction(instruction); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 476 | if (ensure_safety) { |
| 477 | DCHECK(instruction->GetUses().IsEmpty()); |
| 478 | DCHECK(instruction->GetEnvUses().IsEmpty()); |
| 479 | RemoveAsUser(instruction); |
| 480 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 481 | } |
| 482 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 483 | void HBasicBlock::RemoveInstruction(HInstruction* instruction, bool ensure_safety) { |
David Brazdil | c7508e9 | 2015-04-27 13:28:57 +0100 | [diff] [blame^] | 484 | DCHECK(!instruction->IsPhi()); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 485 | Remove(&instructions_, this, instruction, ensure_safety); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 486 | } |
| 487 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 488 | void HBasicBlock::RemovePhi(HPhi* phi, bool ensure_safety) { |
| 489 | Remove(&phis_, this, phi, ensure_safety); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 490 | } |
| 491 | |
David Brazdil | c7508e9 | 2015-04-27 13:28:57 +0100 | [diff] [blame^] | 492 | void HBasicBlock::RemoveInstructionOrPhi(HInstruction* instruction, bool ensure_safety) { |
| 493 | if (instruction->IsPhi()) { |
| 494 | RemovePhi(instruction->AsPhi(), ensure_safety); |
| 495 | } else { |
| 496 | RemoveInstruction(instruction, ensure_safety); |
| 497 | } |
| 498 | } |
| 499 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 500 | void HEnvironment::CopyFrom(HEnvironment* env) { |
| 501 | for (size_t i = 0; i < env->Size(); i++) { |
| 502 | HInstruction* instruction = env->GetInstructionAt(i); |
| 503 | SetRawEnvAt(i, instruction); |
| 504 | if (instruction != nullptr) { |
| 505 | instruction->AddEnvUseAt(this, i); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 506 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 507 | } |
| 508 | } |
| 509 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 510 | void HEnvironment::CopyFromWithLoopPhiAdjustment(HEnvironment* env, |
| 511 | HBasicBlock* loop_header) { |
| 512 | DCHECK(loop_header->IsLoopHeader()); |
| 513 | for (size_t i = 0; i < env->Size(); i++) { |
| 514 | HInstruction* instruction = env->GetInstructionAt(i); |
| 515 | SetRawEnvAt(i, instruction); |
| 516 | if (instruction == nullptr) { |
| 517 | continue; |
| 518 | } |
| 519 | if (instruction->IsLoopHeaderPhi() && (instruction->GetBlock() == loop_header)) { |
| 520 | // At the end of the loop pre-header, the corresponding value for instruction |
| 521 | // is the first input of the phi. |
| 522 | HInstruction* initial = instruction->AsPhi()->InputAt(0); |
| 523 | DCHECK(initial->GetBlock()->Dominates(loop_header)); |
| 524 | SetRawEnvAt(i, initial); |
| 525 | initial->AddEnvUseAt(this, i); |
| 526 | } else { |
| 527 | instruction->AddEnvUseAt(this, i); |
| 528 | } |
| 529 | } |
| 530 | } |
| 531 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 532 | void HEnvironment::RemoveAsUserOfInput(size_t index) const { |
| 533 | const HUserRecord<HEnvironment*> user_record = vregs_.Get(index); |
| 534 | user_record.GetInstruction()->RemoveEnvironmentUser(user_record.GetUseNode()); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 535 | } |
| 536 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 537 | HInstruction* HInstruction::GetNextDisregardingMoves() const { |
| 538 | HInstruction* next = GetNext(); |
| 539 | while (next != nullptr && next->IsParallelMove()) { |
| 540 | next = next->GetNext(); |
| 541 | } |
| 542 | return next; |
| 543 | } |
| 544 | |
| 545 | HInstruction* HInstruction::GetPreviousDisregardingMoves() const { |
| 546 | HInstruction* previous = GetPrevious(); |
| 547 | while (previous != nullptr && previous->IsParallelMove()) { |
| 548 | previous = previous->GetPrevious(); |
| 549 | } |
| 550 | return previous; |
| 551 | } |
| 552 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 553 | void HInstructionList::AddInstruction(HInstruction* instruction) { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 554 | if (first_instruction_ == nullptr) { |
| 555 | DCHECK(last_instruction_ == nullptr); |
| 556 | first_instruction_ = last_instruction_ = instruction; |
| 557 | } else { |
| 558 | last_instruction_->next_ = instruction; |
| 559 | instruction->previous_ = last_instruction_; |
| 560 | last_instruction_ = instruction; |
| 561 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 562 | } |
| 563 | |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 564 | void HInstructionList::InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor) { |
| 565 | DCHECK(Contains(cursor)); |
| 566 | if (cursor == first_instruction_) { |
| 567 | cursor->previous_ = instruction; |
| 568 | instruction->next_ = cursor; |
| 569 | first_instruction_ = instruction; |
| 570 | } else { |
| 571 | instruction->previous_ = cursor->previous_; |
| 572 | instruction->next_ = cursor; |
| 573 | cursor->previous_ = instruction; |
| 574 | instruction->previous_->next_ = instruction; |
| 575 | } |
| 576 | } |
| 577 | |
| 578 | void HInstructionList::InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor) { |
| 579 | DCHECK(Contains(cursor)); |
| 580 | if (cursor == last_instruction_) { |
| 581 | cursor->next_ = instruction; |
| 582 | instruction->previous_ = cursor; |
| 583 | last_instruction_ = instruction; |
| 584 | } else { |
| 585 | instruction->next_ = cursor->next_; |
| 586 | instruction->previous_ = cursor; |
| 587 | cursor->next_ = instruction; |
| 588 | instruction->next_->previous_ = instruction; |
| 589 | } |
| 590 | } |
| 591 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 592 | void HInstructionList::RemoveInstruction(HInstruction* instruction) { |
| 593 | if (instruction->previous_ != nullptr) { |
| 594 | instruction->previous_->next_ = instruction->next_; |
| 595 | } |
| 596 | if (instruction->next_ != nullptr) { |
| 597 | instruction->next_->previous_ = instruction->previous_; |
| 598 | } |
| 599 | if (instruction == first_instruction_) { |
| 600 | first_instruction_ = instruction->next_; |
| 601 | } |
| 602 | if (instruction == last_instruction_) { |
| 603 | last_instruction_ = instruction->previous_; |
| 604 | } |
| 605 | } |
| 606 | |
Roland Levillain | 6b46923 | 2014-09-25 10:10:38 +0100 | [diff] [blame] | 607 | bool HInstructionList::Contains(HInstruction* instruction) const { |
| 608 | for (HInstructionIterator it(*this); !it.Done(); it.Advance()) { |
| 609 | if (it.Current() == instruction) { |
| 610 | return true; |
| 611 | } |
| 612 | } |
| 613 | return false; |
| 614 | } |
| 615 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 616 | bool HInstructionList::FoundBefore(const HInstruction* instruction1, |
| 617 | const HInstruction* instruction2) const { |
| 618 | DCHECK_EQ(instruction1->GetBlock(), instruction2->GetBlock()); |
| 619 | for (HInstructionIterator it(*this); !it.Done(); it.Advance()) { |
| 620 | if (it.Current() == instruction1) { |
| 621 | return true; |
| 622 | } |
| 623 | if (it.Current() == instruction2) { |
| 624 | return false; |
| 625 | } |
| 626 | } |
| 627 | LOG(FATAL) << "Did not find an order between two instructions of the same block."; |
| 628 | return true; |
| 629 | } |
| 630 | |
Roland Levillain | 6c82d40 | 2014-10-13 16:10:27 +0100 | [diff] [blame] | 631 | bool HInstruction::StrictlyDominates(HInstruction* other_instruction) const { |
| 632 | if (other_instruction == this) { |
| 633 | // An instruction does not strictly dominate itself. |
| 634 | return false; |
| 635 | } |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 636 | HBasicBlock* block = GetBlock(); |
| 637 | HBasicBlock* other_block = other_instruction->GetBlock(); |
| 638 | if (block != other_block) { |
| 639 | return GetBlock()->Dominates(other_instruction->GetBlock()); |
| 640 | } else { |
| 641 | // If both instructions are in the same block, ensure this |
| 642 | // instruction comes before `other_instruction`. |
| 643 | if (IsPhi()) { |
| 644 | if (!other_instruction->IsPhi()) { |
| 645 | // Phis appear before non phi-instructions so this instruction |
| 646 | // dominates `other_instruction`. |
| 647 | return true; |
| 648 | } else { |
| 649 | // There is no order among phis. |
| 650 | LOG(FATAL) << "There is no dominance between phis of a same block."; |
| 651 | return false; |
| 652 | } |
| 653 | } else { |
| 654 | // `this` is not a phi. |
| 655 | if (other_instruction->IsPhi()) { |
| 656 | // Phis appear before non phi-instructions so this instruction |
| 657 | // does not dominate `other_instruction`. |
| 658 | return false; |
| 659 | } else { |
| 660 | // Check whether this instruction comes before |
| 661 | // `other_instruction` in the instruction list. |
| 662 | return block->GetInstructions().FoundBefore(this, other_instruction); |
| 663 | } |
| 664 | } |
| 665 | } |
| 666 | } |
| 667 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 668 | void HInstruction::ReplaceWith(HInstruction* other) { |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 669 | DCHECK(other != nullptr); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 670 | for (HUseIterator<HInstruction*> it(GetUses()); !it.Done(); it.Advance()) { |
| 671 | HUseListNode<HInstruction*>* current = it.Current(); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 672 | HInstruction* user = current->GetUser(); |
| 673 | size_t input_index = current->GetIndex(); |
| 674 | user->SetRawInputAt(input_index, other); |
| 675 | other->AddUseAt(user, input_index); |
| 676 | } |
| 677 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 678 | for (HUseIterator<HEnvironment*> it(GetEnvUses()); !it.Done(); it.Advance()) { |
| 679 | HUseListNode<HEnvironment*>* current = it.Current(); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 680 | HEnvironment* user = current->GetUser(); |
| 681 | size_t input_index = current->GetIndex(); |
| 682 | user->SetRawEnvAt(input_index, other); |
| 683 | other->AddEnvUseAt(user, input_index); |
| 684 | } |
| 685 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 686 | uses_.Clear(); |
| 687 | env_uses_.Clear(); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 688 | } |
| 689 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 690 | void HInstruction::ReplaceInput(HInstruction* replacement, size_t index) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 691 | RemoveAsUserOfInput(index); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 692 | SetRawInputAt(index, replacement); |
| 693 | replacement->AddUseAt(this, index); |
| 694 | } |
| 695 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 696 | size_t HInstruction::EnvironmentSize() const { |
| 697 | return HasEnvironment() ? environment_->Size() : 0; |
| 698 | } |
| 699 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 700 | void HPhi::AddInput(HInstruction* input) { |
| 701 | DCHECK(input->GetBlock() != nullptr); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 702 | inputs_.Add(HUserRecord<HInstruction*>(input)); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 703 | input->AddUseAt(this, inputs_.Size() - 1); |
| 704 | } |
| 705 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 706 | void HPhi::RemoveInputAt(size_t index) { |
| 707 | RemoveAsUserOfInput(index); |
| 708 | inputs_.DeleteAt(index); |
| 709 | } |
| 710 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 711 | #define DEFINE_ACCEPT(name, super) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 712 | void H##name::Accept(HGraphVisitor* visitor) { \ |
| 713 | visitor->Visit##name(this); \ |
| 714 | } |
| 715 | |
| 716 | FOR_EACH_INSTRUCTION(DEFINE_ACCEPT) |
| 717 | |
| 718 | #undef DEFINE_ACCEPT |
| 719 | |
| 720 | void HGraphVisitor::VisitInsertionOrder() { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 721 | const GrowableArray<HBasicBlock*>& blocks = graph_->GetBlocks(); |
| 722 | for (size_t i = 0 ; i < blocks.Size(); i++) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 723 | HBasicBlock* block = blocks.Get(i); |
| 724 | if (block != nullptr) { |
| 725 | VisitBasicBlock(block); |
| 726 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 727 | } |
| 728 | } |
| 729 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 730 | void HGraphVisitor::VisitReversePostOrder() { |
| 731 | for (HReversePostOrderIterator it(*graph_); !it.Done(); it.Advance()) { |
| 732 | VisitBasicBlock(it.Current()); |
| 733 | } |
| 734 | } |
| 735 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 736 | void HGraphVisitor::VisitBasicBlock(HBasicBlock* block) { |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 737 | for (HInstructionIterator it(block->GetPhis()); !it.Done(); it.Advance()) { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 738 | it.Current()->Accept(this); |
| 739 | } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 740 | for (HInstructionIterator it(block->GetInstructions()); !it.Done(); it.Advance()) { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 741 | it.Current()->Accept(this); |
| 742 | } |
| 743 | } |
| 744 | |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 745 | HConstant* HUnaryOperation::TryStaticEvaluation() const { |
| 746 | if (GetInput()->IsIntConstant()) { |
| 747 | int32_t value = Evaluate(GetInput()->AsIntConstant()->GetValue()); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 748 | return GetBlock()->GetGraph()->GetIntConstant(value); |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 749 | } else if (GetInput()->IsLongConstant()) { |
Roland Levillain | b762d2e | 2014-10-22 10:11:06 +0100 | [diff] [blame] | 750 | // TODO: Implement static evaluation of long unary operations. |
| 751 | // |
| 752 | // Do not exit with a fatal condition here. Instead, simply |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 753 | // return `null' to notify the caller that this instruction |
Roland Levillain | b762d2e | 2014-10-22 10:11:06 +0100 | [diff] [blame] | 754 | // cannot (yet) be statically evaluated. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 755 | return nullptr; |
| 756 | } |
| 757 | return nullptr; |
| 758 | } |
| 759 | |
| 760 | HConstant* HBinaryOperation::TryStaticEvaluation() const { |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 761 | if (GetLeft()->IsIntConstant() && GetRight()->IsIntConstant()) { |
| 762 | int32_t value = Evaluate(GetLeft()->AsIntConstant()->GetValue(), |
| 763 | GetRight()->AsIntConstant()->GetValue()); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 764 | return GetBlock()->GetGraph()->GetIntConstant(value); |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 765 | } else if (GetLeft()->IsLongConstant() && GetRight()->IsLongConstant()) { |
| 766 | int64_t value = Evaluate(GetLeft()->AsLongConstant()->GetValue(), |
| 767 | GetRight()->AsLongConstant()->GetValue()); |
Nicolas Geoffray | 9ee6618 | 2015-01-16 12:35:40 +0000 | [diff] [blame] | 768 | if (GetResultType() == Primitive::kPrimLong) { |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 769 | return GetBlock()->GetGraph()->GetLongConstant(value); |
Nicolas Geoffray | 9ee6618 | 2015-01-16 12:35:40 +0000 | [diff] [blame] | 770 | } else { |
Nicolas Geoffray | 6c2dff8 | 2015-01-21 14:56:54 +0000 | [diff] [blame] | 771 | DCHECK_EQ(GetResultType(), Primitive::kPrimInt); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 772 | return GetBlock()->GetGraph()->GetIntConstant(static_cast<int32_t>(value)); |
Nicolas Geoffray | 9ee6618 | 2015-01-16 12:35:40 +0000 | [diff] [blame] | 773 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 774 | } |
| 775 | return nullptr; |
| 776 | } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 777 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 778 | HConstant* HBinaryOperation::GetConstantRight() const { |
| 779 | if (GetRight()->IsConstant()) { |
| 780 | return GetRight()->AsConstant(); |
| 781 | } else if (IsCommutative() && GetLeft()->IsConstant()) { |
| 782 | return GetLeft()->AsConstant(); |
| 783 | } else { |
| 784 | return nullptr; |
| 785 | } |
| 786 | } |
| 787 | |
| 788 | // If `GetConstantRight()` returns one of the input, this returns the other |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 789 | // one. Otherwise it returns null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 790 | HInstruction* HBinaryOperation::GetLeastConstantLeft() const { |
| 791 | HInstruction* most_constant_right = GetConstantRight(); |
| 792 | if (most_constant_right == nullptr) { |
| 793 | return nullptr; |
| 794 | } else if (most_constant_right == GetLeft()) { |
| 795 | return GetRight(); |
| 796 | } else { |
| 797 | return GetLeft(); |
| 798 | } |
| 799 | } |
| 800 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 801 | bool HCondition::IsBeforeWhenDisregardMoves(HInstruction* instruction) const { |
| 802 | return this == instruction->GetPreviousDisregardingMoves(); |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 803 | } |
| 804 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 805 | bool HInstruction::Equals(HInstruction* other) const { |
| 806 | if (!InstructionTypeEquals(other)) return false; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 807 | DCHECK_EQ(GetKind(), other->GetKind()); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 808 | if (!InstructionDataEquals(other)) return false; |
| 809 | if (GetType() != other->GetType()) return false; |
| 810 | if (InputCount() != other->InputCount()) return false; |
| 811 | |
| 812 | for (size_t i = 0, e = InputCount(); i < e; ++i) { |
| 813 | if (InputAt(i) != other->InputAt(i)) return false; |
| 814 | } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 815 | DCHECK_EQ(ComputeHashCode(), other->ComputeHashCode()); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 816 | return true; |
| 817 | } |
| 818 | |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 819 | std::ostream& operator<<(std::ostream& os, const HInstruction::InstructionKind& rhs) { |
| 820 | #define DECLARE_CASE(type, super) case HInstruction::k##type: os << #type; break; |
| 821 | switch (rhs) { |
| 822 | FOR_EACH_INSTRUCTION(DECLARE_CASE) |
| 823 | default: |
| 824 | os << "Unknown instruction kind " << static_cast<int>(rhs); |
| 825 | break; |
| 826 | } |
| 827 | #undef DECLARE_CASE |
| 828 | return os; |
| 829 | } |
| 830 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 831 | void HInstruction::MoveBefore(HInstruction* cursor) { |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 832 | next_->previous_ = previous_; |
| 833 | if (previous_ != nullptr) { |
| 834 | previous_->next_ = next_; |
| 835 | } |
| 836 | if (block_->instructions_.first_instruction_ == this) { |
| 837 | block_->instructions_.first_instruction_ = next_; |
| 838 | } |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 839 | DCHECK_NE(block_->instructions_.last_instruction_, this); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 840 | |
| 841 | previous_ = cursor->previous_; |
| 842 | if (previous_ != nullptr) { |
| 843 | previous_->next_ = this; |
| 844 | } |
| 845 | next_ = cursor; |
| 846 | cursor->previous_ = this; |
| 847 | block_ = cursor->block_; |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 848 | |
| 849 | if (block_->instructions_.first_instruction_ == cursor) { |
| 850 | block_->instructions_.first_instruction_ = this; |
| 851 | } |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 852 | } |
| 853 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 854 | HBasicBlock* HBasicBlock::SplitAfter(HInstruction* cursor) { |
| 855 | DCHECK(!cursor->IsControlFlow()); |
| 856 | DCHECK_NE(instructions_.last_instruction_, cursor); |
| 857 | DCHECK_EQ(cursor->GetBlock(), this); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 858 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 859 | HBasicBlock* new_block = new (GetGraph()->GetArena()) HBasicBlock(GetGraph(), GetDexPc()); |
| 860 | new_block->instructions_.first_instruction_ = cursor->GetNext(); |
| 861 | new_block->instructions_.last_instruction_ = instructions_.last_instruction_; |
| 862 | cursor->next_->previous_ = nullptr; |
| 863 | cursor->next_ = nullptr; |
| 864 | instructions_.last_instruction_ = cursor; |
| 865 | |
| 866 | new_block->instructions_.SetBlockOfInstructions(new_block); |
| 867 | for (size_t i = 0, e = GetSuccessors().Size(); i < e; ++i) { |
| 868 | HBasicBlock* successor = GetSuccessors().Get(i); |
| 869 | new_block->successors_.Add(successor); |
| 870 | successor->predecessors_.Put(successor->GetPredecessorIndexOf(this), new_block); |
| 871 | } |
| 872 | successors_.Reset(); |
| 873 | |
| 874 | for (size_t i = 0, e = GetDominatedBlocks().Size(); i < e; ++i) { |
| 875 | HBasicBlock* dominated = GetDominatedBlocks().Get(i); |
| 876 | dominated->dominator_ = new_block; |
| 877 | new_block->dominated_blocks_.Add(dominated); |
| 878 | } |
| 879 | dominated_blocks_.Reset(); |
| 880 | return new_block; |
| 881 | } |
| 882 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 883 | bool HBasicBlock::IsSingleGoto() const { |
| 884 | HLoopInformation* loop_info = GetLoopInformation(); |
| 885 | // TODO: Remove the null check b/19084197. |
| 886 | return GetFirstInstruction() != nullptr |
| 887 | && GetPhis().IsEmpty() |
| 888 | && GetFirstInstruction() == GetLastInstruction() |
| 889 | && GetLastInstruction()->IsGoto() |
| 890 | // Back edges generate the suspend check. |
| 891 | && (loop_info == nullptr || !loop_info->IsBackEdge(*this)); |
| 892 | } |
| 893 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 894 | bool HBasicBlock::EndsWithControlFlowInstruction() const { |
| 895 | return !GetInstructions().IsEmpty() && GetLastInstruction()->IsControlFlow(); |
| 896 | } |
| 897 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 898 | bool HBasicBlock::EndsWithIf() const { |
| 899 | return !GetInstructions().IsEmpty() && GetLastInstruction()->IsIf(); |
| 900 | } |
| 901 | |
| 902 | bool HBasicBlock::HasSinglePhi() const { |
| 903 | return !GetPhis().IsEmpty() && GetFirstPhi()->GetNext() == nullptr; |
| 904 | } |
| 905 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 906 | size_t HInstructionList::CountSize() const { |
| 907 | size_t size = 0; |
| 908 | HInstruction* current = first_instruction_; |
| 909 | for (; current != nullptr; current = current->GetNext()) { |
| 910 | size++; |
| 911 | } |
| 912 | return size; |
| 913 | } |
| 914 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 915 | void HInstructionList::SetBlockOfInstructions(HBasicBlock* block) const { |
| 916 | for (HInstruction* current = first_instruction_; |
| 917 | current != nullptr; |
| 918 | current = current->GetNext()) { |
| 919 | current->SetBlock(block); |
| 920 | } |
| 921 | } |
| 922 | |
| 923 | void HInstructionList::AddAfter(HInstruction* cursor, const HInstructionList& instruction_list) { |
| 924 | DCHECK(Contains(cursor)); |
| 925 | if (!instruction_list.IsEmpty()) { |
| 926 | if (cursor == last_instruction_) { |
| 927 | last_instruction_ = instruction_list.last_instruction_; |
| 928 | } else { |
| 929 | cursor->next_->previous_ = instruction_list.last_instruction_; |
| 930 | } |
| 931 | instruction_list.last_instruction_->next_ = cursor->next_; |
| 932 | cursor->next_ = instruction_list.first_instruction_; |
| 933 | instruction_list.first_instruction_->previous_ = cursor; |
| 934 | } |
| 935 | } |
| 936 | |
| 937 | void HInstructionList::Add(const HInstructionList& instruction_list) { |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 938 | if (IsEmpty()) { |
| 939 | first_instruction_ = instruction_list.first_instruction_; |
| 940 | last_instruction_ = instruction_list.last_instruction_; |
| 941 | } else { |
| 942 | AddAfter(last_instruction_, instruction_list); |
| 943 | } |
| 944 | } |
| 945 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 946 | void HBasicBlock::DisconnectAndDelete() { |
| 947 | // Dominators must be removed after all the blocks they dominate. This way |
| 948 | // a loop header is removed last, a requirement for correct loop information |
| 949 | // iteration. |
| 950 | DCHECK(dominated_blocks_.IsEmpty()); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 951 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 952 | // Remove the block from all loops it is included in. |
| 953 | for (HLoopInformationOutwardIterator it(*this); !it.Done(); it.Advance()) { |
| 954 | HLoopInformation* loop_info = it.Current(); |
| 955 | loop_info->Remove(this); |
| 956 | if (loop_info->IsBackEdge(*this)) { |
| 957 | // This deliberately leaves the loop in an inconsistent state and will |
| 958 | // fail SSAChecker unless the entire loop is removed during the pass. |
| 959 | loop_info->RemoveBackEdge(this); |
| 960 | } |
| 961 | } |
| 962 | |
| 963 | // Disconnect the block from its predecessors and update their control-flow |
| 964 | // instructions. |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 965 | for (size_t i = 0, e = predecessors_.Size(); i < e; ++i) { |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 966 | HBasicBlock* predecessor = predecessors_.Get(i); |
| 967 | HInstruction* last_instruction = predecessor->GetLastInstruction(); |
| 968 | predecessor->RemoveInstruction(last_instruction); |
| 969 | predecessor->RemoveSuccessor(this); |
| 970 | if (predecessor->GetSuccessors().Size() == 1u) { |
| 971 | DCHECK(last_instruction->IsIf()); |
| 972 | predecessor->AddInstruction(new (graph_->GetArena()) HGoto()); |
| 973 | } else { |
| 974 | // The predecessor has no remaining successors and therefore must be dead. |
| 975 | // We deliberately leave it without a control-flow instruction so that the |
| 976 | // SSAChecker fails unless it is not removed during the pass too. |
| 977 | DCHECK_EQ(predecessor->GetSuccessors().Size(), 0u); |
| 978 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 979 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 980 | predecessors_.Reset(); |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 981 | |
| 982 | // Disconnect the block from its successors and update their dominators |
| 983 | // and phis. |
| 984 | for (size_t i = 0, e = successors_.Size(); i < e; ++i) { |
| 985 | HBasicBlock* successor = successors_.Get(i); |
| 986 | // Delete this block from the list of predecessors. |
| 987 | size_t this_index = successor->GetPredecessorIndexOf(this); |
| 988 | successor->predecessors_.DeleteAt(this_index); |
| 989 | |
| 990 | // Check that `successor` has other predecessors, otherwise `this` is the |
| 991 | // dominator of `successor` which violates the order DCHECKed at the top. |
| 992 | DCHECK(!successor->predecessors_.IsEmpty()); |
| 993 | |
| 994 | // Recompute the successor's dominator. |
| 995 | HBasicBlock* old_dominator = successor->GetDominator(); |
| 996 | HBasicBlock* new_dominator = successor->predecessors_.Get(0); |
| 997 | for (size_t j = 1, f = successor->predecessors_.Size(); j < f; ++j) { |
| 998 | new_dominator = graph_->FindCommonDominator( |
| 999 | new_dominator, successor->predecessors_.Get(j)); |
| 1000 | } |
| 1001 | if (old_dominator != new_dominator) { |
| 1002 | successor->SetDominator(new_dominator); |
| 1003 | old_dominator->RemoveDominatedBlock(successor); |
| 1004 | new_dominator->AddDominatedBlock(successor); |
| 1005 | } |
| 1006 | |
| 1007 | // Remove this block's entries in the successor's phis. |
| 1008 | if (successor->predecessors_.Size() == 1u) { |
| 1009 | // The successor has just one predecessor left. Replace phis with the only |
| 1010 | // remaining input. |
| 1011 | for (HInstructionIterator phi_it(successor->GetPhis()); !phi_it.Done(); phi_it.Advance()) { |
| 1012 | HPhi* phi = phi_it.Current()->AsPhi(); |
| 1013 | phi->ReplaceWith(phi->InputAt(1 - this_index)); |
| 1014 | successor->RemovePhi(phi); |
| 1015 | } |
| 1016 | } else { |
| 1017 | for (HInstructionIterator phi_it(successor->GetPhis()); !phi_it.Done(); phi_it.Advance()) { |
| 1018 | phi_it.Current()->AsPhi()->RemoveInputAt(this_index); |
| 1019 | } |
| 1020 | } |
| 1021 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1022 | successors_.Reset(); |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1023 | |
| 1024 | // Disconnect from the dominator. |
| 1025 | dominator_->RemoveDominatedBlock(this); |
| 1026 | SetDominator(nullptr); |
| 1027 | |
| 1028 | // Delete from the graph. The function safely deletes remaining instructions |
| 1029 | // and updates the reverse post order. |
| 1030 | graph_->DeleteDeadBlock(this); |
| 1031 | SetGraph(nullptr); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1032 | } |
| 1033 | |
| 1034 | void HBasicBlock::MergeWith(HBasicBlock* other) { |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1035 | DCHECK_EQ(GetGraph(), other->GetGraph()); |
| 1036 | DCHECK(GetDominatedBlocks().Contains(other)); |
| 1037 | DCHECK_EQ(GetSuccessors().Size(), 1u); |
| 1038 | DCHECK_EQ(GetSuccessors().Get(0), other); |
| 1039 | DCHECK_EQ(other->GetPredecessors().Size(), 1u); |
| 1040 | DCHECK_EQ(other->GetPredecessors().Get(0), this); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1041 | DCHECK(other->GetPhis().IsEmpty()); |
| 1042 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1043 | // Move instructions from `other` to `this`. |
| 1044 | DCHECK(EndsWithControlFlowInstruction()); |
| 1045 | RemoveInstruction(GetLastInstruction()); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1046 | instructions_.Add(other->GetInstructions()); |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1047 | other->instructions_.SetBlockOfInstructions(this); |
| 1048 | other->instructions_.Clear(); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1049 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1050 | // Remove `other` from the loops it is included in. |
| 1051 | for (HLoopInformationOutwardIterator it(*other); !it.Done(); it.Advance()) { |
| 1052 | HLoopInformation* loop_info = it.Current(); |
| 1053 | loop_info->Remove(other); |
| 1054 | if (loop_info->IsBackEdge(*other)) { |
| 1055 | loop_info->ClearBackEdges(); |
| 1056 | loop_info->AddBackEdge(this); |
| 1057 | } |
| 1058 | } |
| 1059 | |
| 1060 | // Update links to the successors of `other`. |
| 1061 | successors_.Reset(); |
| 1062 | while (!other->successors_.IsEmpty()) { |
| 1063 | HBasicBlock* successor = other->successors_.Get(0); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1064 | successor->ReplacePredecessor(other, this); |
| 1065 | } |
| 1066 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1067 | // Update the dominator tree. |
| 1068 | dominated_blocks_.Delete(other); |
| 1069 | for (size_t i = 0, e = other->GetDominatedBlocks().Size(); i < e; ++i) { |
| 1070 | HBasicBlock* dominated = other->GetDominatedBlocks().Get(i); |
| 1071 | dominated_blocks_.Add(dominated); |
| 1072 | dominated->SetDominator(this); |
| 1073 | } |
| 1074 | other->dominated_blocks_.Reset(); |
| 1075 | other->dominator_ = nullptr; |
| 1076 | |
| 1077 | // Clear the list of predecessors of `other` in preparation of deleting it. |
| 1078 | other->predecessors_.Reset(); |
| 1079 | |
| 1080 | // Delete `other` from the graph. The function updates reverse post order. |
| 1081 | graph_->DeleteDeadBlock(other); |
| 1082 | other->SetGraph(nullptr); |
| 1083 | } |
| 1084 | |
| 1085 | void HBasicBlock::MergeWithInlined(HBasicBlock* other) { |
| 1086 | DCHECK_NE(GetGraph(), other->GetGraph()); |
| 1087 | DCHECK(GetDominatedBlocks().IsEmpty()); |
| 1088 | DCHECK(GetSuccessors().IsEmpty()); |
| 1089 | DCHECK(!EndsWithControlFlowInstruction()); |
| 1090 | DCHECK_EQ(other->GetPredecessors().Size(), 1u); |
| 1091 | DCHECK(other->GetPredecessors().Get(0)->IsEntryBlock()); |
| 1092 | DCHECK(other->GetPhis().IsEmpty()); |
| 1093 | DCHECK(!other->IsInLoop()); |
| 1094 | |
| 1095 | // Move instructions from `other` to `this`. |
| 1096 | instructions_.Add(other->GetInstructions()); |
| 1097 | other->instructions_.SetBlockOfInstructions(this); |
| 1098 | |
| 1099 | // Update links to the successors of `other`. |
| 1100 | successors_.Reset(); |
| 1101 | while (!other->successors_.IsEmpty()) { |
| 1102 | HBasicBlock* successor = other->successors_.Get(0); |
| 1103 | successor->ReplacePredecessor(other, this); |
| 1104 | } |
| 1105 | |
| 1106 | // Update the dominator tree. |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1107 | for (size_t i = 0, e = other->GetDominatedBlocks().Size(); i < e; ++i) { |
| 1108 | HBasicBlock* dominated = other->GetDominatedBlocks().Get(i); |
| 1109 | dominated_blocks_.Add(dominated); |
| 1110 | dominated->SetDominator(this); |
| 1111 | } |
| 1112 | other->dominated_blocks_.Reset(); |
| 1113 | other->dominator_ = nullptr; |
| 1114 | other->graph_ = nullptr; |
| 1115 | } |
| 1116 | |
| 1117 | void HBasicBlock::ReplaceWith(HBasicBlock* other) { |
| 1118 | while (!GetPredecessors().IsEmpty()) { |
| 1119 | HBasicBlock* predecessor = GetPredecessors().Get(0); |
| 1120 | predecessor->ReplaceSuccessor(this, other); |
| 1121 | } |
| 1122 | while (!GetSuccessors().IsEmpty()) { |
| 1123 | HBasicBlock* successor = GetSuccessors().Get(0); |
| 1124 | successor->ReplacePredecessor(this, other); |
| 1125 | } |
| 1126 | for (size_t i = 0; i < dominated_blocks_.Size(); ++i) { |
| 1127 | other->AddDominatedBlock(dominated_blocks_.Get(i)); |
| 1128 | } |
| 1129 | GetDominator()->ReplaceDominatedBlock(this, other); |
| 1130 | other->SetDominator(GetDominator()); |
| 1131 | dominator_ = nullptr; |
| 1132 | graph_ = nullptr; |
| 1133 | } |
| 1134 | |
| 1135 | // Create space in `blocks` for adding `number_of_new_blocks` entries |
| 1136 | // starting at location `at`. Blocks after `at` are moved accordingly. |
| 1137 | static void MakeRoomFor(GrowableArray<HBasicBlock*>* blocks, |
| 1138 | size_t number_of_new_blocks, |
| 1139 | size_t at) { |
| 1140 | size_t old_size = blocks->Size(); |
| 1141 | size_t new_size = old_size + number_of_new_blocks; |
| 1142 | blocks->SetSize(new_size); |
| 1143 | for (size_t i = old_size - 1, j = new_size - 1; i > at; --i, --j) { |
| 1144 | blocks->Put(j, blocks->Get(i)); |
| 1145 | } |
| 1146 | } |
| 1147 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1148 | void HGraph::DeleteDeadBlock(HBasicBlock* block) { |
| 1149 | DCHECK_EQ(block->GetGraph(), this); |
| 1150 | DCHECK(block->GetSuccessors().IsEmpty()); |
| 1151 | DCHECK(block->GetPredecessors().IsEmpty()); |
| 1152 | DCHECK(block->GetDominatedBlocks().IsEmpty()); |
| 1153 | DCHECK(block->GetDominator() == nullptr); |
| 1154 | |
| 1155 | for (HBackwardInstructionIterator it(block->GetInstructions()); !it.Done(); it.Advance()) { |
| 1156 | block->RemoveInstruction(it.Current()); |
| 1157 | } |
| 1158 | for (HBackwardInstructionIterator it(block->GetPhis()); !it.Done(); it.Advance()) { |
| 1159 | block->RemovePhi(it.Current()->AsPhi()); |
| 1160 | } |
| 1161 | |
| 1162 | reverse_post_order_.Delete(block); |
| 1163 | blocks_.Put(block->GetBlockId(), nullptr); |
| 1164 | } |
| 1165 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1166 | void HGraph::InlineInto(HGraph* outer_graph, HInvoke* invoke) { |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1167 | if (GetBlocks().Size() == 3) { |
Nicolas Geoffray | be31ff9 | 2015-02-04 14:52:20 +0000 | [diff] [blame] | 1168 | // Simple case of an entry block, a body block, and an exit block. |
| 1169 | // Put the body block's instruction into `invoke`'s block. |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1170 | HBasicBlock* body = GetBlocks().Get(1); |
Nicolas Geoffray | be31ff9 | 2015-02-04 14:52:20 +0000 | [diff] [blame] | 1171 | DCHECK(GetBlocks().Get(0)->IsEntryBlock()); |
| 1172 | DCHECK(GetBlocks().Get(2)->IsExitBlock()); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1173 | DCHECK(!body->IsExitBlock()); |
| 1174 | HInstruction* last = body->GetLastInstruction(); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1175 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1176 | invoke->GetBlock()->instructions_.AddAfter(invoke, body->GetInstructions()); |
| 1177 | body->GetInstructions().SetBlockOfInstructions(invoke->GetBlock()); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1178 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1179 | // Replace the invoke with the return value of the inlined graph. |
| 1180 | if (last->IsReturn()) { |
| 1181 | invoke->ReplaceWith(last->InputAt(0)); |
| 1182 | } else { |
| 1183 | DCHECK(last->IsReturnVoid()); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1184 | } |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1185 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1186 | invoke->GetBlock()->RemoveInstruction(last); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1187 | } else { |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1188 | // Need to inline multiple blocks. We split `invoke`'s block |
| 1189 | // into two blocks, merge the first block of the inlined graph into |
Nicolas Geoffray | be31ff9 | 2015-02-04 14:52:20 +0000 | [diff] [blame] | 1190 | // the first half, and replace the exit block of the inlined graph |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1191 | // with the second half. |
| 1192 | ArenaAllocator* allocator = outer_graph->GetArena(); |
| 1193 | HBasicBlock* at = invoke->GetBlock(); |
| 1194 | HBasicBlock* to = at->SplitAfter(invoke); |
| 1195 | |
| 1196 | HBasicBlock* first = entry_block_->GetSuccessors().Get(0); |
| 1197 | DCHECK(!first->IsInLoop()); |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 1198 | at->MergeWithInlined(first); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1199 | exit_block_->ReplaceWith(to); |
| 1200 | |
| 1201 | // Update all predecessors of the exit block (now the `to` block) |
Nicolas Geoffray | 817bce7 | 2015-02-24 13:35:38 +0000 | [diff] [blame] | 1202 | // to not `HReturn` but `HGoto` instead. |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1203 | HInstruction* return_value = nullptr; |
Nicolas Geoffray | 817bce7 | 2015-02-24 13:35:38 +0000 | [diff] [blame] | 1204 | bool returns_void = to->GetPredecessors().Get(0)->GetLastInstruction()->IsReturnVoid(); |
| 1205 | if (to->GetPredecessors().Size() == 1) { |
| 1206 | HBasicBlock* predecessor = to->GetPredecessors().Get(0); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1207 | HInstruction* last = predecessor->GetLastInstruction(); |
Nicolas Geoffray | 817bce7 | 2015-02-24 13:35:38 +0000 | [diff] [blame] | 1208 | if (!returns_void) { |
| 1209 | return_value = last->InputAt(0); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1210 | } |
| 1211 | predecessor->AddInstruction(new (allocator) HGoto()); |
| 1212 | predecessor->RemoveInstruction(last); |
Nicolas Geoffray | 817bce7 | 2015-02-24 13:35:38 +0000 | [diff] [blame] | 1213 | } else { |
| 1214 | if (!returns_void) { |
| 1215 | // There will be multiple returns. |
Nicolas Geoffray | 4f1a384 | 2015-03-12 10:34:11 +0000 | [diff] [blame] | 1216 | return_value = new (allocator) HPhi( |
| 1217 | allocator, kNoRegNumber, 0, HPhi::ToPhiType(invoke->GetType())); |
Nicolas Geoffray | 817bce7 | 2015-02-24 13:35:38 +0000 | [diff] [blame] | 1218 | to->AddPhi(return_value->AsPhi()); |
| 1219 | } |
| 1220 | for (size_t i = 0, e = to->GetPredecessors().Size(); i < e; ++i) { |
| 1221 | HBasicBlock* predecessor = to->GetPredecessors().Get(i); |
| 1222 | HInstruction* last = predecessor->GetLastInstruction(); |
| 1223 | if (!returns_void) { |
| 1224 | return_value->AsPhi()->AddInput(last->InputAt(0)); |
| 1225 | } |
| 1226 | predecessor->AddInstruction(new (allocator) HGoto()); |
| 1227 | predecessor->RemoveInstruction(last); |
| 1228 | } |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1229 | } |
| 1230 | |
| 1231 | if (return_value != nullptr) { |
| 1232 | invoke->ReplaceWith(return_value); |
| 1233 | } |
| 1234 | |
| 1235 | // Update the meta information surrounding blocks: |
| 1236 | // (1) the graph they are now in, |
| 1237 | // (2) the reverse post order of that graph, |
| 1238 | // (3) the potential loop information they are now in. |
| 1239 | |
| 1240 | // We don't add the entry block, the exit block, and the first block, which |
| 1241 | // has been merged with `at`. |
| 1242 | static constexpr int kNumberOfSkippedBlocksInCallee = 3; |
| 1243 | |
| 1244 | // We add the `to` block. |
| 1245 | static constexpr int kNumberOfNewBlocksInCaller = 1; |
| 1246 | size_t blocks_added = (reverse_post_order_.Size() - kNumberOfSkippedBlocksInCallee) |
| 1247 | + kNumberOfNewBlocksInCaller; |
| 1248 | |
| 1249 | // Find the location of `at` in the outer graph's reverse post order. The new |
| 1250 | // blocks will be added after it. |
| 1251 | size_t index_of_at = 0; |
| 1252 | while (outer_graph->reverse_post_order_.Get(index_of_at) != at) { |
| 1253 | index_of_at++; |
| 1254 | } |
| 1255 | MakeRoomFor(&outer_graph->reverse_post_order_, blocks_added, index_of_at); |
| 1256 | |
| 1257 | // Do a reverse post order of the blocks in the callee and do (1), (2), |
| 1258 | // and (3) to the blocks that apply. |
| 1259 | HLoopInformation* info = at->GetLoopInformation(); |
| 1260 | for (HReversePostOrderIterator it(*this); !it.Done(); it.Advance()) { |
| 1261 | HBasicBlock* current = it.Current(); |
| 1262 | if (current != exit_block_ && current != entry_block_ && current != first) { |
| 1263 | DCHECK(!current->IsInLoop()); |
| 1264 | DCHECK(current->GetGraph() == this); |
| 1265 | current->SetGraph(outer_graph); |
| 1266 | outer_graph->AddBlock(current); |
| 1267 | outer_graph->reverse_post_order_.Put(++index_of_at, current); |
| 1268 | if (info != nullptr) { |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1269 | current->SetLoopInformation(info); |
David Brazdil | 7d27537 | 2015-04-21 16:36:35 +0100 | [diff] [blame] | 1270 | for (HLoopInformationOutwardIterator loop_it(*at); !loop_it.Done(); loop_it.Advance()) { |
| 1271 | loop_it.Current()->Add(current); |
| 1272 | } |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1273 | } |
| 1274 | } |
| 1275 | } |
| 1276 | |
| 1277 | // Do (1), (2), and (3) to `to`. |
| 1278 | to->SetGraph(outer_graph); |
| 1279 | outer_graph->AddBlock(to); |
| 1280 | outer_graph->reverse_post_order_.Put(++index_of_at, to); |
| 1281 | if (info != nullptr) { |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1282 | to->SetLoopInformation(info); |
David Brazdil | 7d27537 | 2015-04-21 16:36:35 +0100 | [diff] [blame] | 1283 | for (HLoopInformationOutwardIterator loop_it(*at); !loop_it.Done(); loop_it.Advance()) { |
| 1284 | loop_it.Current()->Add(to); |
| 1285 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 1286 | if (info->IsBackEdge(*at)) { |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 1287 | // Only `at` can become a back edge, as the inlined blocks |
| 1288 | // are predecessors of `at`. |
| 1289 | DCHECK_EQ(1u, info->NumberOfBackEdges()); |
| 1290 | info->ClearBackEdges(); |
| 1291 | info->AddBackEdge(to); |
| 1292 | } |
| 1293 | } |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1294 | } |
Nicolas Geoffray | 7c5367b | 2014-12-17 10:13:46 +0000 | [diff] [blame] | 1295 | |
David Brazdil | 05144f4 | 2015-04-16 15:18:00 +0100 | [diff] [blame] | 1296 | // Update the next instruction id of the outer graph, so that instructions |
| 1297 | // added later get bigger ids than those in the inner graph. |
| 1298 | outer_graph->SetCurrentInstructionId(GetNextInstructionId()); |
| 1299 | |
| 1300 | // Walk over the entry block and: |
| 1301 | // - Move constants from the entry block to the outer_graph's entry block, |
| 1302 | // - Replace HParameterValue instructions with their real value. |
| 1303 | // - Remove suspend checks, that hold an environment. |
| 1304 | // We must do this after the other blocks have been inlined, otherwise ids of |
| 1305 | // constants could overlap with the inner graph. |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1306 | size_t parameter_index = 0; |
David Brazdil | 05144f4 | 2015-04-16 15:18:00 +0100 | [diff] [blame] | 1307 | for (HInstructionIterator it(entry_block_->GetInstructions()); !it.Done(); it.Advance()) { |
| 1308 | HInstruction* current = it.Current(); |
| 1309 | if (current->IsNullConstant()) { |
| 1310 | current->ReplaceWith(outer_graph->GetNullConstant()); |
| 1311 | } else if (current->IsIntConstant()) { |
| 1312 | current->ReplaceWith(outer_graph->GetIntConstant(current->AsIntConstant()->GetValue())); |
| 1313 | } else if (current->IsLongConstant()) { |
| 1314 | current->ReplaceWith(outer_graph->GetLongConstant(current->AsLongConstant()->GetValue())); |
| 1315 | } else if (current->IsFloatConstant() || current->IsDoubleConstant()) { |
| 1316 | // TODO: Don't duplicate floating-point constants. |
| 1317 | current->MoveBefore(outer_graph->GetEntryBlock()->GetLastInstruction()); |
| 1318 | } else if (current->IsParameterValue()) { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 1319 | if (kIsDebugBuild |
| 1320 | && invoke->IsInvokeStaticOrDirect() |
| 1321 | && invoke->AsInvokeStaticOrDirect()->IsStaticWithExplicitClinitCheck()) { |
| 1322 | // Ensure we do not use the last input of `invoke`, as it |
| 1323 | // contains a clinit check which is not an actual argument. |
| 1324 | size_t last_input_index = invoke->InputCount() - 1; |
| 1325 | DCHECK(parameter_index != last_input_index); |
| 1326 | } |
David Brazdil | 05144f4 | 2015-04-16 15:18:00 +0100 | [diff] [blame] | 1327 | current->ReplaceWith(invoke->InputAt(parameter_index++)); |
| 1328 | } else { |
| 1329 | DCHECK(current->IsGoto() || current->IsSuspendCheck()); |
| 1330 | entry_block_->RemoveInstruction(current); |
| 1331 | } |
| 1332 | } |
| 1333 | |
Nicolas Geoffray | 7c5367b | 2014-12-17 10:13:46 +0000 | [diff] [blame] | 1334 | // Finally remove the invoke from the caller. |
| 1335 | invoke->GetBlock()->RemoveInstruction(invoke); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1336 | } |
| 1337 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1338 | std::ostream& operator<<(std::ostream& os, const ReferenceTypeInfo& rhs) { |
| 1339 | ScopedObjectAccess soa(Thread::Current()); |
| 1340 | os << "[" |
| 1341 | << " is_top=" << rhs.IsTop() |
| 1342 | << " type=" << (rhs.IsTop() ? "?" : PrettyClass(rhs.GetTypeHandle().Get())) |
| 1343 | << " is_exact=" << rhs.IsExact() |
| 1344 | << " ]"; |
| 1345 | return os; |
| 1346 | } |
| 1347 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1348 | } // namespace art |