blob: f8b9c1a952f04765bb9b2c9c3f6c4abeabcacc6f [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;
Jean Christophe Beyler6e3cb662013-12-20 15:47:52 -080027
28 // Are we not yet at the end?
buzbee56c71782013-09-05 17:13:19 -070029 if (idx_ < end_idx_) {
Jean Christophe Beyler6e3cb662013-12-20 15:47:52 -080030 // Get the next index.
31 BasicBlockId bb_id = block_id_list_->Get(idx_);
buzbee56c71782013-09-05 17:13:19 -070032 res = mir_graph_->GetBasicBlock(bb_id);
Jean Christophe Beyler6e3cb662013-12-20 15:47:52 -080033 idx_++;
Ian Rogers8d3a1172013-06-04 01:13:28 -070034 }
Jean Christophe Beyler6e3cb662013-12-20 15:47:52 -080035
Ian Rogers8d3a1172013-06-04 01:13:28 -070036 return res;
37}
38
buzbee56c71782013-09-05 17:13:19 -070039// Repeat full forward passes over all nodes until no change occurs during a complete pass.
Jean Christophe Beyler6e3cb662013-12-20 15:47:52 -080040inline BasicBlock* DataflowIterator::ForwardRepeatNext() {
Ian Rogers8d3a1172013-06-04 01:13:28 -070041 BasicBlock* res = NULL;
Jean Christophe Beyler6e3cb662013-12-20 15:47:52 -080042
43 // Are we at the end and have we changed something?
44 if ((idx_ >= end_idx_) && changed_ == true) {
45 // Reset the index.
buzbee56c71782013-09-05 17:13:19 -070046 idx_ = start_idx_;
buzbee1da1e2f2013-11-15 13:37:01 -080047 repeats_++;
buzbee56c71782013-09-05 17:13:19 -070048 changed_ = false;
49 }
Jean Christophe Beyler6e3cb662013-12-20 15:47:52 -080050
51 // Are we not yet at the end?
buzbee56c71782013-09-05 17:13:19 -070052 if (idx_ < end_idx_) {
Jean Christophe Beyler6e3cb662013-12-20 15:47:52 -080053 // Get the BasicBlockId.
54 BasicBlockId bb_id = block_id_list_->Get(idx_);
buzbee56c71782013-09-05 17:13:19 -070055 res = mir_graph_->GetBasicBlock(bb_id);
Jean Christophe Beyler6e3cb662013-12-20 15:47:52 -080056 idx_++;
buzbee56c71782013-09-05 17:13:19 -070057 }
Jean Christophe Beyler6e3cb662013-12-20 15:47:52 -080058
buzbee56c71782013-09-05 17:13:19 -070059 return res;
60}
61
62// Single reverse pass over the nodes.
63inline BasicBlock* DataflowIterator::ReverseSingleNext() {
64 BasicBlock* res = NULL;
Jean Christophe Beyler6e3cb662013-12-20 15:47:52 -080065
66 // Are we not yet at the end?
buzbee56c71782013-09-05 17:13:19 -070067 if (idx_ >= 0) {
Jean Christophe Beyler6e3cb662013-12-20 15:47:52 -080068 // Get the BasicBlockId.
69 BasicBlockId bb_id = block_id_list_->Get(idx_);
buzbee56c71782013-09-05 17:13:19 -070070 res = mir_graph_->GetBasicBlock(bb_id);
Jean Christophe Beyler6e3cb662013-12-20 15:47:52 -080071 idx_--;
buzbee56c71782013-09-05 17:13:19 -070072 }
Jean Christophe Beyler6e3cb662013-12-20 15:47:52 -080073
buzbee56c71782013-09-05 17:13:19 -070074 return res;
75}
76
77// Repeat full backwards passes over all nodes until no change occurs during a complete pass.
Jean Christophe Beyler6e3cb662013-12-20 15:47:52 -080078inline BasicBlock* DataflowIterator::ReverseRepeatNext() {
buzbee56c71782013-09-05 17:13:19 -070079 BasicBlock* res = NULL;
Jean Christophe Beyler6e3cb662013-12-20 15:47:52 -080080
81 // Are we done and we changed something during the last iteration?
buzbee56c71782013-09-05 17:13:19 -070082 if ((idx_ < 0) && changed_) {
Jean Christophe Beyler6e3cb662013-12-20 15:47:52 -080083 // Reset the index.
buzbee56c71782013-09-05 17:13:19 -070084 idx_ = start_idx_;
buzbee1da1e2f2013-11-15 13:37:01 -080085 repeats_++;
buzbee56c71782013-09-05 17:13:19 -070086 changed_ = false;
87 }
Jean Christophe Beyler6e3cb662013-12-20 15:47:52 -080088
89 // Are we not yet done?
buzbee56c71782013-09-05 17:13:19 -070090 if (idx_ >= 0) {
Jean Christophe Beyler6e3cb662013-12-20 15:47:52 -080091 // Get the BasicBlockId.
92 BasicBlockId bb_id = block_id_list_->Get(idx_);
buzbee56c71782013-09-05 17:13:19 -070093 res = mir_graph_->GetBasicBlock(bb_id);
Jean Christophe Beyler6e3cb662013-12-20 15:47:52 -080094 idx_--;
buzbee56c71782013-09-05 17:13:19 -070095 }
Jean Christophe Beyler6e3cb662013-12-20 15:47:52 -080096
buzbee56c71782013-09-05 17:13:19 -070097 return res;
98}
99
100// AllNodes uses the existing GrowableArray iterator, and should be considered unordered.
Jean Christophe Beyler6e3cb662013-12-20 15:47:52 -0800101inline BasicBlock* AllNodesIterator::Next(bool had_change) {
buzbee56c71782013-09-05 17:13:19 -0700102 BasicBlock* res = NULL;
Jean Christophe Beyler6e3cb662013-12-20 15:47:52 -0800103
104 // Suppose we want to keep looking.
Ian Rogers8d3a1172013-06-04 01:13:28 -0700105 bool keep_looking = true;
Jean Christophe Beyler6e3cb662013-12-20 15:47:52 -0800106
107 // Find the next BasicBlock.
108 while (keep_looking == true) {
109 // Get next BasicBlock.
Vladimir Marko75ba13f2014-01-28 12:15:24 +0000110 res = all_nodes_iterator_.Next();
Jean Christophe Beyler6e3cb662013-12-20 15:47:52 -0800111
112 // Are we done or is the BasicBlock not hidden?
113 if ((res == NULL) || (res->hidden == false)) {
Ian Rogers8d3a1172013-06-04 01:13:28 -0700114 keep_looking = false;
115 }
116 }
Jean Christophe Beyler6e3cb662013-12-20 15:47:52 -0800117
118 // Update changed: if had_changed is true, we remember it for the whole iteration.
119 changed_ |= had_change;
120
Ian Rogers8d3a1172013-06-04 01:13:28 -0700121 return res;
122}
123
124} // namespace art
125
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700126#endif // ART_COMPILER_DEX_DATAFLOW_ITERATOR_INL_H_