blob: bb5b96992582b06a1aff84ffc698dc330ee0eabe [file] [log] [blame]
buzbee311ca162013-02-28 15:56:43 -08001/*
2 * Copyright (C) 2013 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 "dataflow_iterator.h"
18
19namespace art {
20
buzbee0665fe02013-03-21 12:32:21 -070021 BasicBlock* DataflowIterator::NextBody(bool had_change) {
buzbee311ca162013-02-28 15:56:43 -080022 changed_ |= had_change;
23 BasicBlock* res = NULL;
buzbee0665fe02013-03-21 12:32:21 -070024 if (reverse_) {
buzbee311ca162013-02-28 15:56:43 -080025 if (is_iterative_ && changed_ && (idx_ < 0)) {
26 idx_ = start_idx_;
27 changed_ = false;
28 }
29 if (idx_ >= 0) {
buzbee862a7602013-04-05 10:58:54 -070030 int bb_id = block_id_list_->Get(idx_--);
buzbee311ca162013-02-28 15:56:43 -080031 res = mir_graph_->GetBasicBlock(bb_id);
32 }
33 } else {
34 if (is_iterative_ && changed_ && (idx_ >= end_idx_)) {
35 idx_ = start_idx_;
36 changed_ = false;
37 }
38 if (idx_ < end_idx_) {
buzbee862a7602013-04-05 10:58:54 -070039 int bb_id = block_id_list_->Get(idx_++);
buzbee311ca162013-02-28 15:56:43 -080040 res = mir_graph_->GetBasicBlock(bb_id);
41 }
42 }
43 return res;
44 }
45
buzbee862a7602013-04-05 10:58:54 -070046 // AllNodes uses the existing GrowableArray iterator, so use different NextBody().
buzbee0665fe02013-03-21 12:32:21 -070047 BasicBlock* AllNodesIterator::NextBody(bool had_change) {
48 changed_ |= had_change;
49 BasicBlock* res = NULL;
50 bool keep_looking = true;
51 while (keep_looking) {
buzbee862a7602013-04-05 10:58:54 -070052 res = all_nodes_iterator_->Next();
buzbee0665fe02013-03-21 12:32:21 -070053 if (is_iterative_ && changed_ && (res == NULL)) {
buzbee862a7602013-04-05 10:58:54 -070054 all_nodes_iterator_->Reset();
buzbee0665fe02013-03-21 12:32:21 -070055 changed_ = false;
56 } else if ((res == NULL) || (!res->hidden)) {
57 keep_looking = false;
58 }
59 }
60 return res;
buzbee311ca162013-02-28 15:56:43 -080061 }
62
63} // namespace art