Ian Rogers | 8d3a117 | 2013-06-04 01:13:28 -0700 | [diff] [blame] | 1 | /* |
| 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 Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 17 | #ifndef ART_COMPILER_DEX_DATAFLOW_ITERATOR_INL_H_ |
| 18 | #define ART_COMPILER_DEX_DATAFLOW_ITERATOR_INL_H_ |
Ian Rogers | 8d3a117 | 2013-06-04 01:13:28 -0700 | [diff] [blame] | 19 | |
| 20 | #include "dataflow_iterator.h" |
| 21 | |
| 22 | namespace art { |
| 23 | |
buzbee | 56c7178 | 2013-09-05 17:13:19 -0700 | [diff] [blame] | 24 | // Single forward pass over the nodes. |
| 25 | inline BasicBlock* DataflowIterator::ForwardSingleNext() { |
Ian Rogers | 8d3a117 | 2013-06-04 01:13:28 -0700 | [diff] [blame] | 26 | BasicBlock* res = NULL; |
buzbee | 56c7178 | 2013-09-05 17:13:19 -0700 | [diff] [blame] | 27 | if (idx_ < end_idx_) { |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 28 | BasicBlockId bb_id = block_id_list_->Get(idx_++); |
buzbee | 56c7178 | 2013-09-05 17:13:19 -0700 | [diff] [blame] | 29 | res = mir_graph_->GetBasicBlock(bb_id); |
Ian Rogers | 8d3a117 | 2013-06-04 01:13:28 -0700 | [diff] [blame] | 30 | } |
| 31 | return res; |
| 32 | } |
| 33 | |
buzbee | 56c7178 | 2013-09-05 17:13:19 -0700 | [diff] [blame] | 34 | // Repeat full forward passes over all nodes until no change occurs during a complete pass. |
| 35 | inline BasicBlock* DataflowIterator::ForwardRepeatNext(bool had_change) { |
Ian Rogers | 8d3a117 | 2013-06-04 01:13:28 -0700 | [diff] [blame] | 36 | changed_ |= had_change; |
| 37 | BasicBlock* res = NULL; |
buzbee | 56c7178 | 2013-09-05 17:13:19 -0700 | [diff] [blame] | 38 | if ((idx_ >= end_idx_) && changed_) { |
| 39 | idx_ = start_idx_; |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 40 | repeats_++; |
buzbee | 56c7178 | 2013-09-05 17:13:19 -0700 | [diff] [blame] | 41 | changed_ = false; |
| 42 | } |
| 43 | if (idx_ < end_idx_) { |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 44 | BasicBlockId bb_id = block_id_list_->Get(idx_++); |
buzbee | 56c7178 | 2013-09-05 17:13:19 -0700 | [diff] [blame] | 45 | res = mir_graph_->GetBasicBlock(bb_id); |
| 46 | } |
| 47 | return res; |
| 48 | } |
| 49 | |
| 50 | // Single reverse pass over the nodes. |
| 51 | inline BasicBlock* DataflowIterator::ReverseSingleNext() { |
| 52 | BasicBlock* res = NULL; |
| 53 | if (idx_ >= 0) { |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 54 | BasicBlockId bb_id = block_id_list_->Get(idx_--); |
buzbee | 56c7178 | 2013-09-05 17:13:19 -0700 | [diff] [blame] | 55 | res = mir_graph_->GetBasicBlock(bb_id); |
| 56 | } |
| 57 | return res; |
| 58 | } |
| 59 | |
| 60 | // Repeat full backwards passes over all nodes until no change occurs during a complete pass. |
| 61 | inline BasicBlock* DataflowIterator::ReverseRepeatNext(bool had_change) { |
| 62 | changed_ |= had_change; |
| 63 | BasicBlock* res = NULL; |
| 64 | if ((idx_ < 0) && changed_) { |
| 65 | idx_ = start_idx_; |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 66 | repeats_++; |
buzbee | 56c7178 | 2013-09-05 17:13:19 -0700 | [diff] [blame] | 67 | changed_ = false; |
| 68 | } |
| 69 | if (idx_ >= 0) { |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 70 | BasicBlockId bb_id = block_id_list_->Get(idx_--); |
buzbee | 56c7178 | 2013-09-05 17:13:19 -0700 | [diff] [blame] | 71 | res = mir_graph_->GetBasicBlock(bb_id); |
| 72 | } |
| 73 | return res; |
| 74 | } |
| 75 | |
| 76 | // AllNodes uses the existing GrowableArray iterator, and should be considered unordered. |
| 77 | inline BasicBlock* AllNodesIterator::Next() { |
| 78 | BasicBlock* res = NULL; |
Ian Rogers | 8d3a117 | 2013-06-04 01:13:28 -0700 | [diff] [blame] | 79 | bool keep_looking = true; |
| 80 | while (keep_looking) { |
| 81 | res = all_nodes_iterator_->Next(); |
buzbee | 56c7178 | 2013-09-05 17:13:19 -0700 | [diff] [blame] | 82 | if ((res == NULL) || (!res->hidden)) { |
Ian Rogers | 8d3a117 | 2013-06-04 01:13:28 -0700 | [diff] [blame] | 83 | keep_looking = false; |
| 84 | } |
| 85 | } |
| 86 | return res; |
| 87 | } |
| 88 | |
| 89 | } // namespace art |
| 90 | |
Brian Carlstrom | fc0e321 | 2013-07-17 14:40:12 -0700 | [diff] [blame] | 91 | #endif // ART_COMPILER_DEX_DATAFLOW_ITERATOR_INL_H_ |