dataflow_iterator-inl.h revision 0d82948094d9a198e01aa95f64012bdedd5b6fc9
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#ifndef ART_COMPILER_DEX_DATAFLOW_ITERATOR_INL_H_ 18#define ART_COMPILER_DEX_DATAFLOW_ITERATOR_INL_H_ 19 20#include "dataflow_iterator.h" 21 22namespace art { 23 24// Single forward pass over the nodes. 25inline BasicBlock* DataflowIterator::ForwardSingleNext() { 26 BasicBlock* res = NULL; 27 if (idx_ < end_idx_) { 28 BasicBlockId bb_id = block_id_list_->Get(idx_++); 29 res = mir_graph_->GetBasicBlock(bb_id); 30 } 31 return res; 32} 33 34// Repeat full forward passes over all nodes until no change occurs during a complete pass. 35inline BasicBlock* DataflowIterator::ForwardRepeatNext(bool had_change) { 36 changed_ |= had_change; 37 BasicBlock* res = NULL; 38 if ((idx_ >= end_idx_) && changed_) { 39 idx_ = start_idx_; 40 changed_ = false; 41 } 42 if (idx_ < end_idx_) { 43 BasicBlockId 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 BasicBlockId 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 BasicBlockId 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; 77 bool keep_looking = true; 78 while (keep_looking) { 79 res = all_nodes_iterator_->Next(); 80 if ((res == NULL) || (!res->hidden)) { 81 keep_looking = false; 82 } 83 } 84 return res; 85} 86 87} // namespace art 88 89#endif // ART_COMPILER_DEX_DATAFLOW_ITERATOR_INL_H_ 90