buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [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 | |
| 17 | #include "dataflow_iterator.h" |
| 18 | |
| 19 | namespace art { |
| 20 | |
buzbee | 0665fe0 | 2013-03-21 12:32:21 -0700 | [diff] [blame] | 21 | BasicBlock* DataflowIterator::NextBody(bool had_change) { |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 22 | changed_ |= had_change; |
| 23 | BasicBlock* res = NULL; |
buzbee | 0665fe0 | 2013-03-21 12:32:21 -0700 | [diff] [blame] | 24 | if (reverse_) { |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 25 | if (is_iterative_ && changed_ && (idx_ < 0)) { |
| 26 | idx_ = start_idx_; |
| 27 | changed_ = false; |
| 28 | } |
| 29 | if (idx_ >= 0) { |
buzbee | 862a760 | 2013-04-05 10:58:54 -0700 | [diff] [blame] | 30 | int bb_id = block_id_list_->Get(idx_--); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 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_) { |
buzbee | 862a760 | 2013-04-05 10:58:54 -0700 | [diff] [blame] | 39 | int bb_id = block_id_list_->Get(idx_++); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 40 | res = mir_graph_->GetBasicBlock(bb_id); |
| 41 | } |
| 42 | } |
| 43 | return res; |
| 44 | } |
| 45 | |
buzbee | 862a760 | 2013-04-05 10:58:54 -0700 | [diff] [blame] | 46 | // AllNodes uses the existing GrowableArray iterator, so use different NextBody(). |
buzbee | 0665fe0 | 2013-03-21 12:32:21 -0700 | [diff] [blame] | 47 | BasicBlock* AllNodesIterator::NextBody(bool had_change) { |
| 48 | changed_ |= had_change; |
| 49 | BasicBlock* res = NULL; |
| 50 | bool keep_looking = true; |
| 51 | while (keep_looking) { |
buzbee | 862a760 | 2013-04-05 10:58:54 -0700 | [diff] [blame] | 52 | res = all_nodes_iterator_->Next(); |
buzbee | 0665fe0 | 2013-03-21 12:32:21 -0700 | [diff] [blame] | 53 | if (is_iterative_ && changed_ && (res == NULL)) { |
buzbee | 862a760 | 2013-04-05 10:58:54 -0700 | [diff] [blame] | 54 | all_nodes_iterator_->Reset(); |
buzbee | 0665fe0 | 2013-03-21 12:32:21 -0700 | [diff] [blame] | 55 | changed_ = false; |
| 56 | } else if ((res == NULL) || (!res->hidden)) { |
| 57 | keep_looking = false; |
| 58 | } |
| 59 | } |
| 60 | return res; |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | } // namespace art |