blob: 236c6f49401729e9f6fa2993394f8425b61d766f [file] [log] [blame]
Ian Rogers8d3a1172013-06-04 01:13:28 -07001/*
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
Brian Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_COMPILER_DEX_DATAFLOW_ITERATOR_INL_H_
18#define ART_COMPILER_DEX_DATAFLOW_ITERATOR_INL_H_
Ian Rogers8d3a1172013-06-04 01:13:28 -070019
20#include "dataflow_iterator.h"
21
22namespace art {
23
buzbee56c71782013-09-05 17:13:19 -070024// Single forward pass over the nodes.
25inline BasicBlock* DataflowIterator::ForwardSingleNext() {
Ian Rogers8d3a1172013-06-04 01:13:28 -070026 BasicBlock* res = NULL;
buzbee56c71782013-09-05 17:13:19 -070027 if (idx_ < end_idx_) {
28 int bb_id = block_id_list_->Get(idx_++);
29 res = mir_graph_->GetBasicBlock(bb_id);
Ian Rogers8d3a1172013-06-04 01:13:28 -070030 }
31 return res;
32}
33
buzbee56c71782013-09-05 17:13:19 -070034// Repeat full forward passes over all nodes until no change occurs during a complete pass.
35inline BasicBlock* DataflowIterator::ForwardRepeatNext(bool had_change) {
Ian Rogers8d3a1172013-06-04 01:13:28 -070036 changed_ |= had_change;
37 BasicBlock* res = NULL;
buzbee56c71782013-09-05 17:13:19 -070038 if ((idx_ >= end_idx_) && changed_) {
39 idx_ = start_idx_;
40 changed_ = false;
41 }
42 if (idx_ < end_idx_) {
43 int bb_id = block_id_list_->Get(idx_++);
44 res = mir_graph_->GetBasicBlock(bb_id);
45 }
46 return res;
47}
48
49// Single reverse pass over the nodes.
50inline BasicBlock* DataflowIterator::ReverseSingleNext() {
51 BasicBlock* res = NULL;
52 if (idx_ >= 0) {
53 int bb_id = block_id_list_->Get(idx_--);
54 res = mir_graph_->GetBasicBlock(bb_id);
55 }
56 return res;
57}
58
59// Repeat full backwards passes over all nodes until no change occurs during a complete pass.
60inline BasicBlock* DataflowIterator::ReverseRepeatNext(bool had_change) {
61 changed_ |= had_change;
62 BasicBlock* res = NULL;
63 if ((idx_ < 0) && changed_) {
64 idx_ = start_idx_;
65 changed_ = false;
66 }
67 if (idx_ >= 0) {
68 int bb_id = block_id_list_->Get(idx_--);
69 res = mir_graph_->GetBasicBlock(bb_id);
70 }
71 return res;
72}
73
74// AllNodes uses the existing GrowableArray iterator, and should be considered unordered.
75inline BasicBlock* AllNodesIterator::Next() {
76 BasicBlock* res = NULL;
Ian Rogers8d3a1172013-06-04 01:13:28 -070077 bool keep_looking = true;
78 while (keep_looking) {
79 res = all_nodes_iterator_->Next();
buzbee56c71782013-09-05 17:13:19 -070080 if ((res == NULL) || (!res->hidden)) {
Ian Rogers8d3a1172013-06-04 01:13:28 -070081 keep_looking = false;
82 }
83 }
84 return res;
85}
86
87} // namespace art
88
Brian Carlstromfc0e3212013-07-17 14:40:12 -070089#endif // ART_COMPILER_DEX_DATAFLOW_ITERATOR_INL_H_