blob: 514eeba2f10528bc4da7688f19472ce5b3d57c3f [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) {
30 int bb_id = block_id_list_->elem_list[idx_--];
31 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_) {
39 int bb_id = block_id_list_->elem_list[idx_++];
40 res = mir_graph_->GetBasicBlock(bb_id);
41 }
42 }
43 return res;
44 }
45
buzbee0665fe02013-03-21 12:32:21 -070046 // AllNodes uses the existing GrowableList iterator, so use different NextBody().
47 BasicBlock* AllNodesIterator::NextBody(bool had_change) {
48 changed_ |= had_change;
49 BasicBlock* res = NULL;
50 bool keep_looking = true;
51 while (keep_looking) {
52 res = reinterpret_cast<BasicBlock*>(GrowableListIteratorNext(&all_nodes_iterator_));
53 if (is_iterative_ && changed_ && (res == NULL)) {
54 GrowableListIteratorInit(mir_graph_->GetBlockList(), &all_nodes_iterator_);
55 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