blob: bffda93d8f3d788e90b2ed633ba554fef8146212 [file] [log] [blame]
Aart Bik281c6812016-08-26 11:31:48 -07001/*
2 * Copyright (C) 2016 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 "loop_optimization.h"
18
Aart Bik96202302016-10-04 17:33:56 -070019#include "linear_order.h"
Aart Bik281c6812016-08-26 11:31:48 -070020
21namespace art {
22
Aart Bik9abf8942016-10-14 09:49:42 -070023// Remove the instruction from the graph. A bit more elaborate than the usual
24// instruction removal, since there may be a cycle in the use structure.
Aart Bik281c6812016-08-26 11:31:48 -070025static void RemoveFromCycle(HInstruction* instruction) {
Aart Bik281c6812016-08-26 11:31:48 -070026 instruction->RemoveAsUserOfAllInputs();
27 instruction->RemoveEnvironmentUsers();
28 instruction->GetBlock()->RemoveInstructionOrPhi(instruction, /*ensure_safety=*/ false);
29}
30
Aart Bik807868e2016-11-03 17:51:43 -070031// Detect a goto block and sets succ to the single successor.
Aart Bike3dedc52016-11-02 17:50:27 -070032static bool IsGotoBlock(HBasicBlock* block, /*out*/ HBasicBlock** succ) {
33 if (block->GetPredecessors().size() == 1 &&
34 block->GetSuccessors().size() == 1 &&
35 block->IsSingleGoto()) {
36 *succ = block->GetSingleSuccessor();
37 return true;
38 }
39 return false;
40}
41
Aart Bik807868e2016-11-03 17:51:43 -070042// Detect an early exit loop.
43static bool IsEarlyExit(HLoopInformation* loop_info) {
44 HBlocksInLoopReversePostOrderIterator it_loop(*loop_info);
45 for (it_loop.Advance(); !it_loop.Done(); it_loop.Advance()) {
46 for (HBasicBlock* successor : it_loop.Current()->GetSuccessors()) {
47 if (!loop_info->Contains(*successor)) {
48 return true;
49 }
50 }
51 }
52 return false;
53}
54
Aart Bik281c6812016-08-26 11:31:48 -070055//
56// Class methods.
57//
58
59HLoopOptimization::HLoopOptimization(HGraph* graph,
60 HInductionVarAnalysis* induction_analysis)
61 : HOptimization(graph, kLoopOptimizationPassName),
62 induction_range_(induction_analysis),
Aart Bik96202302016-10-04 17:33:56 -070063 loop_allocator_(nullptr),
Aart Bik281c6812016-08-26 11:31:48 -070064 top_loop_(nullptr),
Aart Bik8c4a8542016-10-06 11:36:57 -070065 last_loop_(nullptr),
Aart Bik482095d2016-10-10 15:39:10 -070066 iset_(nullptr),
Aart Bikdf7822e2016-12-06 10:05:30 -080067 induction_simplication_count_(0),
68 simplified_(false) {
Aart Bik281c6812016-08-26 11:31:48 -070069}
70
71void HLoopOptimization::Run() {
Mingyao Yang01b47b02017-02-03 12:09:57 -080072 // Skip if there is no loop or the graph has try-catch/irreducible loops.
Aart Bik281c6812016-08-26 11:31:48 -070073 // TODO: make this less of a sledgehammer.
Mingyao Yang69d75ff2017-02-07 13:06:06 -080074 if (!graph_->HasLoops() || graph_->HasTryCatch() || graph_->HasIrreducibleLoops()) {
Aart Bik281c6812016-08-26 11:31:48 -070075 return;
76 }
77
Aart Bik96202302016-10-04 17:33:56 -070078 // Phase-local allocator that draws from the global pool. Since the allocator
79 // itself resides on the stack, it is destructed on exiting Run(), which
80 // implies its underlying memory is released immediately.
Nicolas Geoffrayebe16742016-10-05 09:55:42 +010081 ArenaAllocator allocator(graph_->GetArena()->GetArenaPool());
Aart Bik96202302016-10-04 17:33:56 -070082 loop_allocator_ = &allocator;
Nicolas Geoffrayebe16742016-10-05 09:55:42 +010083
Aart Bik96202302016-10-04 17:33:56 -070084 // Perform loop optimizations.
85 LocalRun();
86
Mingyao Yang69d75ff2017-02-07 13:06:06 -080087 if (top_loop_ == nullptr) {
Mingyao Yang01b47b02017-02-03 12:09:57 -080088 // All loops have been eliminated.
Mingyao Yang69d75ff2017-02-07 13:06:06 -080089 graph_->SetHasLoops(false);
90 }
91
Aart Bik96202302016-10-04 17:33:56 -070092 // Detach.
93 loop_allocator_ = nullptr;
94 last_loop_ = top_loop_ = nullptr;
95}
96
97void HLoopOptimization::LocalRun() {
98 // Build the linear order using the phase-local allocator. This step enables building
99 // a loop hierarchy that properly reflects the outer-inner and previous-next relation.
100 ArenaVector<HBasicBlock*> linear_order(loop_allocator_->Adapter(kArenaAllocLinearOrder));
101 LinearizeGraph(graph_, loop_allocator_, &linear_order);
102
Aart Bik281c6812016-08-26 11:31:48 -0700103 // Build the loop hierarchy.
Aart Bik96202302016-10-04 17:33:56 -0700104 for (HBasicBlock* block : linear_order) {
Aart Bik281c6812016-08-26 11:31:48 -0700105 if (block->IsLoopHeader()) {
106 AddLoop(block->GetLoopInformation());
107 }
108 }
Aart Bik96202302016-10-04 17:33:56 -0700109
Aart Bik8c4a8542016-10-06 11:36:57 -0700110 // Traverse the loop hierarchy inner-to-outer and optimize. Traversal can use
111 // a temporary set that stores instructions using the phase-local allocator.
112 if (top_loop_ != nullptr) {
113 ArenaSet<HInstruction*> iset(loop_allocator_->Adapter(kArenaAllocLoopOptimization));
114 iset_ = &iset;
115 TraverseLoopsInnerToOuter(top_loop_);
116 iset_ = nullptr; // detach
117 }
Aart Bik281c6812016-08-26 11:31:48 -0700118}
119
120void HLoopOptimization::AddLoop(HLoopInformation* loop_info) {
121 DCHECK(loop_info != nullptr);
Nicolas Geoffrayebe16742016-10-05 09:55:42 +0100122 LoopNode* node = new (loop_allocator_) LoopNode(loop_info); // phase-local allocator
Aart Bik281c6812016-08-26 11:31:48 -0700123 if (last_loop_ == nullptr) {
124 // First loop.
125 DCHECK(top_loop_ == nullptr);
126 last_loop_ = top_loop_ = node;
127 } else if (loop_info->IsIn(*last_loop_->loop_info)) {
128 // Inner loop.
129 node->outer = last_loop_;
130 DCHECK(last_loop_->inner == nullptr);
131 last_loop_ = last_loop_->inner = node;
132 } else {
133 // Subsequent loop.
134 while (last_loop_->outer != nullptr && !loop_info->IsIn(*last_loop_->outer->loop_info)) {
135 last_loop_ = last_loop_->outer;
136 }
137 node->outer = last_loop_->outer;
138 node->previous = last_loop_;
139 DCHECK(last_loop_->next == nullptr);
140 last_loop_ = last_loop_->next = node;
141 }
142}
143
144void HLoopOptimization::RemoveLoop(LoopNode* node) {
145 DCHECK(node != nullptr);
Aart Bik8c4a8542016-10-06 11:36:57 -0700146 DCHECK(node->inner == nullptr);
147 if (node->previous != nullptr) {
148 // Within sequence.
149 node->previous->next = node->next;
150 if (node->next != nullptr) {
151 node->next->previous = node->previous;
152 }
153 } else {
154 // First of sequence.
155 if (node->outer != nullptr) {
156 node->outer->inner = node->next;
157 } else {
158 top_loop_ = node->next;
159 }
160 if (node->next != nullptr) {
161 node->next->outer = node->outer;
162 node->next->previous = nullptr;
163 }
164 }
Aart Bik281c6812016-08-26 11:31:48 -0700165}
166
167void HLoopOptimization::TraverseLoopsInnerToOuter(LoopNode* node) {
168 for ( ; node != nullptr; node = node->next) {
Aart Bik6b69e0a2017-01-11 10:20:43 -0800169 // Visit inner loops first.
Aart Bik482095d2016-10-10 15:39:10 -0700170 int current_induction_simplification_count = induction_simplication_count_;
Aart Bik281c6812016-08-26 11:31:48 -0700171 if (node->inner != nullptr) {
172 TraverseLoopsInnerToOuter(node->inner);
173 }
Aart Bik6b69e0a2017-01-11 10:20:43 -0800174 // Recompute induction information of this loop if the induction
175 // of any inner loop has been simplified.
Aart Bik482095d2016-10-10 15:39:10 -0700176 if (current_induction_simplification_count != induction_simplication_count_) {
177 induction_range_.ReVisit(node->loop_info);
178 }
Aart Bik6b69e0a2017-01-11 10:20:43 -0800179 // Repeat simplifications in the body of this loop until no more changes occur.
180 // Note that since each simplification consists of eliminating code (without
181 // introducing new code), this process is always finite.
Aart Bikdf7822e2016-12-06 10:05:30 -0800182 do {
183 simplified_ = false;
Aart Bikdf7822e2016-12-06 10:05:30 -0800184 SimplifyInduction(node);
Aart Bik6b69e0a2017-01-11 10:20:43 -0800185 SimplifyBlocks(node);
Aart Bikdf7822e2016-12-06 10:05:30 -0800186 } while (simplified_);
Aart Bik6b69e0a2017-01-11 10:20:43 -0800187 // Simplify inner loop.
Aart Bik9abf8942016-10-14 09:49:42 -0700188 if (node->inner == nullptr) {
Aart Bik6b69e0a2017-01-11 10:20:43 -0800189 SimplifyInnerLoop(node);
Aart Bik9abf8942016-10-14 09:49:42 -0700190 }
Aart Bik281c6812016-08-26 11:31:48 -0700191 }
192}
193
194void HLoopOptimization::SimplifyInduction(LoopNode* node) {
195 HBasicBlock* header = node->loop_info->GetHeader();
196 HBasicBlock* preheader = node->loop_info->GetPreHeader();
Aart Bik8c4a8542016-10-06 11:36:57 -0700197 // Scan the phis in the header to find opportunities to simplify an induction
198 // cycle that is only used outside the loop. Replace these uses, if any, with
199 // the last value and remove the induction cycle.
200 // Examples: for (int i = 0; x != null; i++) { .... no i .... }
201 // for (int i = 0; i < 10; i++, k++) { .... no k .... } return k;
Aart Bik281c6812016-08-26 11:31:48 -0700202 for (HInstructionIterator it(header->GetPhis()); !it.Done(); it.Advance()) {
203 HPhi* phi = it.Current()->AsPhi();
Aart Bik8c4a8542016-10-06 11:36:57 -0700204 iset_->clear();
205 int32_t use_count = 0;
Aart Bikcc42be02016-10-20 16:14:16 -0700206 if (IsPhiInduction(phi) &&
Aart Bik6b69e0a2017-01-11 10:20:43 -0800207 IsOnlyUsedAfterLoop(node->loop_info, phi, /*collect_loop_uses*/ false, &use_count) &&
Aart Bik807868e2016-11-03 17:51:43 -0700208 // No uses, or no early-exit with proper replacement.
209 (use_count == 0 ||
210 (!IsEarlyExit(node->loop_info) && TryReplaceWithLastValue(phi, preheader)))) {
Aart Bik8c4a8542016-10-06 11:36:57 -0700211 for (HInstruction* i : *iset_) {
212 RemoveFromCycle(i);
Aart Bik281c6812016-08-26 11:31:48 -0700213 }
Aart Bikdf7822e2016-12-06 10:05:30 -0800214 simplified_ = true;
Aart Bik482095d2016-10-10 15:39:10 -0700215 }
216 }
217}
218
219void HLoopOptimization::SimplifyBlocks(LoopNode* node) {
Aart Bikdf7822e2016-12-06 10:05:30 -0800220 // Iterate over all basic blocks in the loop-body.
221 for (HBlocksInLoopIterator it(*node->loop_info); !it.Done(); it.Advance()) {
222 HBasicBlock* block = it.Current();
223 // Remove dead instructions from the loop-body.
Aart Bik6b69e0a2017-01-11 10:20:43 -0800224 RemoveDeadInstructions(block->GetPhis());
225 RemoveDeadInstructions(block->GetInstructions());
Aart Bikdf7822e2016-12-06 10:05:30 -0800226 // Remove trivial control flow blocks from the loop-body.
Aart Bik6b69e0a2017-01-11 10:20:43 -0800227 if (block->GetPredecessors().size() == 1 &&
228 block->GetSuccessors().size() == 1 &&
229 block->GetSingleSuccessor()->GetPredecessors().size() == 1) {
Aart Bikdf7822e2016-12-06 10:05:30 -0800230 simplified_ = true;
Aart Bik6b69e0a2017-01-11 10:20:43 -0800231 block->MergeWith(block->GetSingleSuccessor());
Aart Bikdf7822e2016-12-06 10:05:30 -0800232 } else if (block->GetSuccessors().size() == 2) {
233 // Trivial if block can be bypassed to either branch.
234 HBasicBlock* succ0 = block->GetSuccessors()[0];
235 HBasicBlock* succ1 = block->GetSuccessors()[1];
236 HBasicBlock* meet0 = nullptr;
237 HBasicBlock* meet1 = nullptr;
238 if (succ0 != succ1 &&
239 IsGotoBlock(succ0, &meet0) &&
240 IsGotoBlock(succ1, &meet1) &&
241 meet0 == meet1 && // meets again
242 meet0 != block && // no self-loop
243 meet0->GetPhis().IsEmpty()) { // not used for merging
244 simplified_ = true;
245 succ0->DisconnectAndDelete();
246 if (block->Dominates(meet0)) {
247 block->RemoveDominatedBlock(meet0);
248 succ1->AddDominatedBlock(meet0);
249 meet0->SetDominator(succ1);
Aart Bike3dedc52016-11-02 17:50:27 -0700250 }
Aart Bik482095d2016-10-10 15:39:10 -0700251 }
Aart Bik281c6812016-08-26 11:31:48 -0700252 }
Aart Bikdf7822e2016-12-06 10:05:30 -0800253 }
Aart Bik281c6812016-08-26 11:31:48 -0700254}
255
Aart Bik6b69e0a2017-01-11 10:20:43 -0800256bool HLoopOptimization::SimplifyInnerLoop(LoopNode* node) {
Aart Bik281c6812016-08-26 11:31:48 -0700257 HBasicBlock* header = node->loop_info->GetHeader();
258 HBasicBlock* preheader = node->loop_info->GetPreHeader();
Aart Bik9abf8942016-10-14 09:49:42 -0700259 // Ensure loop header logic is finite.
Aart Bik6b69e0a2017-01-11 10:20:43 -0800260 int64_t tc = 0;
261 if (!induction_range_.IsFinite(node->loop_info, &tc)) {
262 return false;
Aart Bik9abf8942016-10-14 09:49:42 -0700263 }
Aart Bik281c6812016-08-26 11:31:48 -0700264 // Ensure there is only a single loop-body (besides the header).
265 HBasicBlock* body = nullptr;
266 for (HBlocksInLoopIterator it(*node->loop_info); !it.Done(); it.Advance()) {
267 if (it.Current() != header) {
268 if (body != nullptr) {
Aart Bik6b69e0a2017-01-11 10:20:43 -0800269 return false;
Aart Bik281c6812016-08-26 11:31:48 -0700270 }
271 body = it.Current();
272 }
273 }
274 // Ensure there is only a single exit point.
275 if (header->GetSuccessors().size() != 2) {
Aart Bik6b69e0a2017-01-11 10:20:43 -0800276 return false;
Aart Bik281c6812016-08-26 11:31:48 -0700277 }
278 HBasicBlock* exit = (header->GetSuccessors()[0] == body)
279 ? header->GetSuccessors()[1]
280 : header->GetSuccessors()[0];
Aart Bik8c4a8542016-10-06 11:36:57 -0700281 // Ensure exit can only be reached by exiting loop.
Aart Bik281c6812016-08-26 11:31:48 -0700282 if (exit->GetPredecessors().size() != 1) {
Aart Bik6b69e0a2017-01-11 10:20:43 -0800283 return false;
Aart Bik281c6812016-08-26 11:31:48 -0700284 }
Aart Bik6b69e0a2017-01-11 10:20:43 -0800285 // Detect either an empty loop (no side effects other than plain iteration) or
286 // a trivial loop (just iterating once). Replace subsequent index uses, if any,
287 // with the last value and remove the loop, possibly after unrolling its body.
288 HInstruction* phi = header->GetFirstPhi();
Aart Bik8c4a8542016-10-06 11:36:57 -0700289 iset_->clear();
290 int32_t use_count = 0;
Aart Bik6b69e0a2017-01-11 10:20:43 -0800291 if (IsEmptyHeader(header)) {
292 bool is_empty = IsEmptyBody(body);
293 if ((is_empty || tc == 1) &&
294 IsOnlyUsedAfterLoop(node->loop_info, phi, /*collect_loop_uses*/ true, &use_count) &&
295 // No uses, or proper replacement.
296 (use_count == 0 || TryReplaceWithLastValue(phi, preheader))) {
297 if (!is_empty) {
298 // Unroll the loop body, which sees initial value of the index.
299 phi->ReplaceWith(phi->InputAt(0));
300 preheader->MergeInstructionsWith(body);
301 }
302 body->DisconnectAndDelete();
303 exit->RemovePredecessor(header);
304 header->RemoveSuccessor(exit);
305 header->RemoveDominatedBlock(exit);
306 header->DisconnectAndDelete();
307 preheader->AddSuccessor(exit);
308 preheader->AddInstruction(new (graph_->GetArena()) HGoto()); // global allocator
309 preheader->AddDominatedBlock(exit);
310 exit->SetDominator(preheader);
311 RemoveLoop(node); // update hierarchy
312 return true;
313 }
Aart Bik281c6812016-08-26 11:31:48 -0700314 }
Aart Bik6b69e0a2017-01-11 10:20:43 -0800315 return false;
Aart Bik281c6812016-08-26 11:31:48 -0700316}
317
Aart Bikcc42be02016-10-20 16:14:16 -0700318bool HLoopOptimization::IsPhiInduction(HPhi* phi) {
319 ArenaSet<HInstruction*>* set = induction_range_.LookupCycle(phi);
320 if (set != nullptr) {
Aart Bike3dedc52016-11-02 17:50:27 -0700321 DCHECK(iset_->empty());
Aart Bikcc42be02016-10-20 16:14:16 -0700322 for (HInstruction* i : *set) {
Aart Bike3dedc52016-11-02 17:50:27 -0700323 // Check that, other than instructions that are no longer in the graph (removed earlier)
324 // each instruction is removable and, other than the phi, uses are contained in the cycle.
325 if (!i->IsInBlock()) {
326 continue;
327 } else if (!i->IsRemovable()) {
328 return false;
329 } else if (i != phi) {
Aart Bikcc42be02016-10-20 16:14:16 -0700330 for (const HUseListNode<HInstruction*>& use : i->GetUses()) {
331 if (set->find(use.GetUser()) == set->end()) {
332 return false;
333 }
334 }
335 }
Aart Bike3dedc52016-11-02 17:50:27 -0700336 iset_->insert(i); // copy
Aart Bikcc42be02016-10-20 16:14:16 -0700337 }
Aart Bikcc42be02016-10-20 16:14:16 -0700338 return true;
339 }
340 return false;
341}
342
343// Find: phi: Phi(init, addsub)
344// s: SuspendCheck
345// c: Condition(phi, bound)
346// i: If(c)
347// TODO: Find a less pattern matching approach?
348bool HLoopOptimization::IsEmptyHeader(HBasicBlock* block) {
349 DCHECK(iset_->empty());
350 HInstruction* phi = block->GetFirstPhi();
351 if (phi != nullptr && phi->GetNext() == nullptr && IsPhiInduction(phi->AsPhi())) {
352 HInstruction* s = block->GetFirstInstruction();
353 if (s != nullptr && s->IsSuspendCheck()) {
354 HInstruction* c = s->GetNext();
355 if (c != nullptr && c->IsCondition() && c->GetUses().HasExactlyOneElement()) {
356 HInstruction* i = c->GetNext();
357 if (i != nullptr && i->IsIf() && i->InputAt(0) == c) {
358 iset_->insert(c);
359 iset_->insert(s);
360 return true;
361 }
362 }
363 }
364 }
365 return false;
366}
367
368bool HLoopOptimization::IsEmptyBody(HBasicBlock* block) {
369 if (block->GetFirstPhi() == nullptr) {
370 for (HInstructionIterator it(block->GetInstructions()); !it.Done(); it.Advance()) {
371 HInstruction* instruction = it.Current();
372 if (!instruction->IsGoto() && iset_->find(instruction) == iset_->end()) {
373 return false;
374 }
375 }
376 return true;
377 }
378 return false;
379}
380
Aart Bik482095d2016-10-10 15:39:10 -0700381bool HLoopOptimization::IsOnlyUsedAfterLoop(HLoopInformation* loop_info,
Aart Bik8c4a8542016-10-06 11:36:57 -0700382 HInstruction* instruction,
Aart Bik6b69e0a2017-01-11 10:20:43 -0800383 bool collect_loop_uses,
Aart Bik8c4a8542016-10-06 11:36:57 -0700384 /*out*/ int32_t* use_count) {
385 for (const HUseListNode<HInstruction*>& use : instruction->GetUses()) {
386 HInstruction* user = use.GetUser();
387 if (iset_->find(user) == iset_->end()) { // not excluded?
388 HLoopInformation* other_loop_info = user->GetBlock()->GetLoopInformation();
Aart Bik482095d2016-10-10 15:39:10 -0700389 if (other_loop_info != nullptr && other_loop_info->IsIn(*loop_info)) {
Aart Bik6b69e0a2017-01-11 10:20:43 -0800390 // If collect_loop_uses is set, simply keep adding those uses to the set.
391 // Otherwise, reject uses inside the loop that were not already in the set.
392 if (collect_loop_uses) {
393 iset_->insert(user);
394 continue;
395 }
Aart Bik8c4a8542016-10-06 11:36:57 -0700396 return false;
397 }
398 ++*use_count;
399 }
400 }
401 return true;
402}
403
Aart Bik807868e2016-11-03 17:51:43 -0700404bool HLoopOptimization::TryReplaceWithLastValue(HInstruction* instruction, HBasicBlock* block) {
405 // Try to replace outside uses with the last value. Environment uses can consume this
406 // value too, since any first true use is outside the loop (although this may imply
407 // that de-opting may look "ahead" a bit on the phi value). If there are only environment
408 // uses, the value is dropped altogether, since the computations have no effect.
409 if (induction_range_.CanGenerateLastValue(instruction)) {
Aart Bik6b69e0a2017-01-11 10:20:43 -0800410 HInstruction* replacement = induction_range_.GenerateLastValue(instruction, graph_, block);
411 const HUseList<HInstruction*>& uses = instruction->GetUses();
412 for (auto it = uses.begin(), end = uses.end(); it != end;) {
413 HInstruction* user = it->GetUser();
414 size_t index = it->GetIndex();
415 ++it; // increment before replacing
416 if (iset_->find(user) == iset_->end()) { // not excluded?
417 user->ReplaceInput(replacement, index);
418 induction_range_.Replace(user, instruction, replacement); // update induction
419 }
420 }
421 const HUseList<HEnvironment*>& env_uses = instruction->GetEnvUses();
422 for (auto it = env_uses.begin(), end = env_uses.end(); it != end;) {
423 HEnvironment* user = it->GetUser();
424 size_t index = it->GetIndex();
425 ++it; // increment before replacing
426 if (iset_->find(user->GetHolder()) == iset_->end()) { // not excluded?
427 user->RemoveAsUserOfInput(index);
428 user->SetRawEnvAt(index, replacement);
429 replacement->AddEnvUseAt(user, index);
430 }
431 }
432 induction_simplication_count_++;
Aart Bik807868e2016-11-03 17:51:43 -0700433 return true;
Aart Bik8c4a8542016-10-06 11:36:57 -0700434 }
Aart Bik807868e2016-11-03 17:51:43 -0700435 return false;
Aart Bik8c4a8542016-10-06 11:36:57 -0700436}
437
Aart Bik6b69e0a2017-01-11 10:20:43 -0800438void HLoopOptimization::RemoveDeadInstructions(const HInstructionList& list) {
439 for (HBackwardInstructionIterator i(list); !i.Done(); i.Advance()) {
440 HInstruction* instruction = i.Current();
441 if (instruction->IsDeadAndRemovable()) {
442 simplified_ = true;
443 instruction->GetBlock()->RemoveInstructionOrPhi(instruction);
444 }
445 }
446}
447
Aart Bik281c6812016-08-26 11:31:48 -0700448} // namespace art