template <class Tr>
RegionBase<Tr>::~RegionBase() {
- // Free the cached nodes.
- for (typename BBNodeMapT::iterator it = BBNodeMap.begin(),
- ie = BBNodeMap.end();
- it != ie; ++it)
- delete it->second;
-
// Only clean the cache for this Region. Caches of child Regions will be
// cleaned when the child Regions are deleted.
BBNodeMap.clear();
RegionQueue.pop_back();
R->replaceEntry(NewEntry);
- for (typename RegionT::const_iterator RI = R->begin(), RE = R->end();
- RI != RE; ++RI) {
- if ((*RI)->getEntry() == OldEntry)
- RegionQueue.push_back(RI->get());
+ for (std::unique_ptr<RegionT> &Child : *R) {
+ if (Child->getEntry() == OldEntry)
+ RegionQueue.push_back(Child.get());
}
}
}
RegionQueue.pop_back();
R->replaceExit(NewExit);
- for (typename RegionT::const_iterator RI = R->begin(), RE = R->end();
- RI != RE; ++RI) {
- if ((*RI)->getExit() == OldExit)
- RegionQueue.push_back(RI->get());
+ for (std::unique_ptr<RegionT> &Child : *R) {
+ if (Child->getExit() == OldExit)
+ RegionQueue.push_back(Child.get());
}
}
}
template <class Tr>
typename RegionBase<Tr>::BlockT *RegionBase<Tr>::getEnteringBlock() const {
BlockT *entry = getEntry();
- BlockT *Pred;
BlockT *enteringBlock = nullptr;
- for (PredIterTy PI = InvBlockTraits::child_begin(entry),
- PE = InvBlockTraits::child_end(entry);
- PI != PE; ++PI) {
- Pred = *PI;
+ for (BlockT *Pred : make_range(InvBlockTraits::child_begin(entry),
+ InvBlockTraits::child_end(entry))) {
if (DT->getNode(Pred) && !contains(Pred)) {
if (enteringBlock)
return nullptr;
template <class Tr>
typename RegionBase<Tr>::BlockT *RegionBase<Tr>::getExitingBlock() const {
BlockT *exit = getExit();
- BlockT *Pred;
BlockT *exitingBlock = nullptr;
if (!exit)
return nullptr;
- for (PredIterTy PI = InvBlockTraits::child_begin(exit),
- PE = InvBlockTraits::child_end(exit);
- PI != PE; ++PI) {
- Pred = *PI;
+ for (BlockT *Pred : make_range(InvBlockTraits::child_begin(exit),
+ InvBlockTraits::child_end(exit))) {
if (contains(Pred)) {
if (exitingBlock)
return nullptr;
BlockT *entry = getEntry(), *exit = getExit();
- for (SuccIterTy SI = BlockTraits::child_begin(BB),
- SE = BlockTraits::child_end(BB);
- SI != SE; ++SI) {
- if (!contains(*SI) && exit != *SI)
+ for (BlockT *Succ :
+ make_range(BlockTraits::child_begin(BB), BlockTraits::child_end(BB))) {
+ if (!contains(Succ) && exit != Succ)
llvm_unreachable("Broken region found: edges leaving the region must go "
"to the exit node!");
}
if (entry != BB) {
- for (PredIterTy SI = InvBlockTraits::child_begin(BB),
- SE = InvBlockTraits::child_end(BB);
- SI != SE; ++SI) {
- if (!contains(*SI))
+ for (BlockT *Pred : make_range(InvBlockTraits::child_begin(BB),
+ InvBlockTraits::child_end(BB))) {
+ if (!contains(Pred))
llvm_unreachable("Broken region found: edges entering the region must "
"go to the entry node!");
}
verifyBBInRegion(BB);
- for (SuccIterTy SI = BlockTraits::child_begin(BB),
- SE = BlockTraits::child_end(BB);
- SI != SE; ++SI) {
- if (*SI != exit && visited->find(*SI) == visited->end())
- verifyWalk(*SI, visited);
+ for (BlockT *Succ :
+ make_range(BlockTraits::child_begin(BB), BlockTraits::child_end(BB))) {
+ if (Succ != exit && visited->find(Succ) == visited->end())
+ verifyWalk(Succ, visited);
}
}
template <class Tr>
void RegionBase<Tr>::verifyRegionNest() const {
- for (typename RegionT::const_iterator RI = begin(), RE = end(); RI != RE;
- ++RI)
- (*RI)->verifyRegionNest();
+ for (const std::unique_ptr<RegionT> &R : *this)
+ R->verifyRegionNest();
verifyRegion();
}
typename BBNodeMapT::const_iterator at = BBNodeMap.find(BB);
- if (at != BBNodeMap.end())
- return at->second;
-
- auto Deconst = const_cast<RegionBase<Tr> *>(this);
- RegionNodeT *NewNode = new RegionNodeT(static_cast<RegionT *>(Deconst), BB);
- BBNodeMap.insert(std::make_pair(BB, NewNode));
- return NewNode;
+ if (at == BBNodeMap.end()) {
+ auto Deconst = const_cast<RegionBase<Tr> *>(this);
+ at = BBNodeMap
+ .emplace(BB, make_unique<RegionNodeT>(
+ static_cast<RegionT *>(Deconst), BB))
+ .first;
+ }
+ return at->second.get();
}
template <class Tr>
template <class Tr>
void RegionBase<Tr>::transferChildrenTo(RegionT *To) {
- for (iterator I = begin(), E = end(); I != E; ++I) {
- (*I)->parent = To;
- To->children.push_back(std::move(*I));
+ for (std::unique_ptr<RegionT> &R : *this) {
+ R->parent = To;
+ To->children.push_back(std::move(R));
}
children.clear();
}
template <class Tr>
void RegionBase<Tr>::addSubRegion(RegionT *SubRegion, bool moveChildren) {
assert(!SubRegion->parent && "SubRegion already has a parent!");
- assert(std::find_if(begin(), end(), [&](const std::unique_ptr<RegionT> &R) {
- return R.get() == SubRegion;
- }) == children.end() &&
+ assert(find_if(*this,
+ [&](const std::unique_ptr<RegionT> &R) {
+ return R.get() == SubRegion;
+ }) == children.end() &&
"Subregion already exists!");
SubRegion->parent = static_cast<RegionT *>(this);
assert(SubRegion->children.empty() &&
"SubRegions that contain children are not supported");
- for (element_iterator I = element_begin(), E = element_end(); I != E; ++I) {
- if (!(*I)->isSubRegion()) {
- BlockT *BB = (*I)->template getNodeAs<BlockT>();
+ for (RegionNodeT *Element : elements()) {
+ if (!Element->isSubRegion()) {
+ BlockT *BB = Element->template getNodeAs<BlockT>();
if (SubRegion->contains(BB))
RI->setRegionFor(BB, SubRegion);
}
std::vector<std::unique_ptr<RegionT>> Keep;
- for (iterator I = begin(), E = end(); I != E; ++I) {
- if (SubRegion->contains(I->get()) && I->get() != SubRegion) {
- (*I)->parent = SubRegion;
- SubRegion->children.push_back(std::move(*I));
+ for (std::unique_ptr<RegionT> &R : *this) {
+ if (SubRegion->contains(R.get()) && R.get() != SubRegion) {
+ R->parent = SubRegion;
+ SubRegion->children.push_back(std::move(R));
} else
- Keep.push_back(std::move(*I));
+ Keep.push_back(std::move(R));
}
children.clear();
typename Tr::RegionT *RegionBase<Tr>::removeSubRegion(RegionT *Child) {
assert(Child->parent == this && "Child is not a child of this region!");
Child->parent = nullptr;
- typename RegionSet::iterator I = std::find_if(
- children.begin(), children.end(),
- [&](const std::unique_ptr<RegionT> &R) { return R.get() == Child; });
+ typename RegionSet::iterator I =
+ find_if(children, [&](const std::unique_ptr<RegionT> &R) {
+ return R.get() == Child;
+ });
assert(I != children.end() && "Region does not exit. Unable to remove.");
children.erase(children.begin() + (I - begin()));
return Child;
RegionT *R = RI->getRegionFor(exit);
if (R->getEntry() != exit) {
- for (PredIterTy PI = InvBlockTraits::child_begin(getExit()),
- PE = InvBlockTraits::child_end(getExit());
- PI != PE; ++PI)
- if (!contains(*PI))
+ for (BlockT *Pred : make_range(InvBlockTraits::child_begin(getExit()),
+ InvBlockTraits::child_end(getExit())))
+ if (!contains(Pred))
return nullptr;
if (Tr::getNumSuccessors(exit) == 1)
return new RegionT(getEntry(), *BlockTraits::child_begin(exit), RI, DT);
while (R->getParent() && R->getParent()->getEntry() == exit)
R = R->getParent();
- for (PredIterTy PI = InvBlockTraits::child_begin(getExit()),
- PE = InvBlockTraits::child_end(getExit());
- PI != PE; ++PI) {
- if (!(contains(*PI) || R->contains(*PI)))
+ for (BlockT *Pred : make_range(InvBlockTraits::child_begin(getExit()),
+ InvBlockTraits::child_end(getExit()))) {
+ if (!(contains(Pred) || R->contains(Pred)))
return nullptr;
}
for (const auto *BB : blocks())
OS << BB->getName() << ", "; // TODO: remove the last ","
} else if (Style == PrintRN) {
- for (const_element_iterator I = element_begin(), E = element_end();
- I != E; ++I) {
- OS << **I << ", "; // TODO: remove the last ",
+ for (const RegionNodeT *Element : elements()) {
+ OS << *Element << ", "; // TODO: remove the last ",
}
}
}
if (print_tree) {
- for (const_iterator RI = begin(), RE = end(); RI != RE; ++RI)
- (*RI)->print(OS, print_tree, level + 1, Style);
+ for (const std::unique_ptr<RegionT> &R : *this)
+ R->print(OS, print_tree, level + 1, Style);
}
if (Style != PrintNone)
template <class Tr>
void RegionBase<Tr>::clearNodeCache() {
- // Free the cached nodes.
- for (typename BBNodeMapT::iterator I = BBNodeMap.begin(),
- IE = BBNodeMap.end();
- I != IE; ++I)
- delete I->second;
-
BBNodeMap.clear();
- for (typename RegionT::iterator RI = begin(), RE = end(); RI != RE; ++RI)
- (*RI)->clearNodeCache();
+ for (std::unique_ptr<RegionT> &R : *this)
+ R->clearNodeCache();
}
//===----------------------------------------------------------------------===//
template <class Tr>
void RegionInfoBase<Tr>::verifyBBMap(const RegionT *R) const {
assert(R && "Re must be non-null");
- for (auto I = R->element_begin(), E = R->element_end(); I != E; ++I) {
- if (I->isSubRegion()) {
- const RegionT *SR = I->template getNodeAs<RegionT>();
+ for (const typename Tr::RegionNodeT *Element : R->elements()) {
+ if (Element->isSubRegion()) {
+ const RegionT *SR = Element->template getNodeAs<RegionT>();
verifyBBMap(SR);
} else {
- BlockT *BB = I->template getNodeAs<BlockT>();
+ BlockT *BB = Element->template getNodeAs<BlockT>();
if (getRegionFor(BB) != R)
llvm_unreachable("BB map does not match region nesting");
}
template <class Tr>
bool RegionInfoBase<Tr>::isCommonDomFrontier(BlockT *BB, BlockT *entry,
BlockT *exit) const {
- for (PredIterTy PI = InvBlockTraits::child_begin(BB),
- PE = InvBlockTraits::child_end(BB);
- PI != PE; ++PI) {
- BlockT *P = *PI;
+ for (BlockT *P : make_range(InvBlockTraits::child_begin(BB),
+ InvBlockTraits::child_end(BB))) {
if (DT->dominates(entry, P) && !DT->dominates(exit, P))
return false;
}
DST *exitSuccs = &DF->find(exit)->second;
// Do not allow edges leaving the region.
- for (typename DST::iterator SI = entrySuccs->begin(), SE = entrySuccs->end();
- SI != SE; ++SI) {
- if (*SI == exit || *SI == entry)
+ for (BlockT *Succ : *entrySuccs) {
+ if (Succ == exit || Succ == entry)
continue;
- if (exitSuccs->find(*SI) == exitSuccs->end())
+ if (exitSuccs->find(Succ) == exitSuccs->end())
return false;
- if (!isCommonDomFrontier(*SI, entry, exit))
+ if (!isCommonDomFrontier(Succ, entry, exit))
return false;
}
// Do not allow edges pointing into the region.
- for (typename DST::iterator SI = exitSuccs->begin(), SE = exitSuccs->end();
- SI != SE; ++SI) {
- if (DT->properlyDominates(entry, *SI) && *SI != exit)
+ for (BlockT *Succ : *exitSuccs) {
+ if (DT->properlyDominates(entry, Succ) && Succ != exit)
return false;
}
RegionT *region =
new RegionT(entry, exit, static_cast<RegionInfoT *>(this), DT);
- BBtoRegion.insert(std::make_pair(entry, region));
+ BBtoRegion.insert({entry, region});
#ifdef EXPENSIVE_CHECKS
region->verifyRegion();
BBtoRegion[BB] = region;
}
- for (typename DomTreeNodeT::iterator CI = N->begin(), CE = N->end(); CI != CE;
- ++CI) {
- buildRegionsTree(*CI, region);
+ for (DomTreeNodeBase<BlockT> *C : *N) {
+ buildRegionsTree(C, region);
}
}
ExitR->getParent()->getEntry() == Exit)
ExitR = ExitR->getParent();
- for (PredIterTy PI = InvBlockTraits::child_begin(Exit),
- PE = InvBlockTraits::child_end(Exit);
- PI != PE; ++PI) {
- if (!R->contains(*PI) && !ExitR->contains(*PI))
+ for (BlockT *Pred : make_range(InvBlockTraits::child_begin(Exit),
+ InvBlockTraits::child_end(Exit))) {
+ if (!R->contains(Pred) && !ExitR->contains(Pred))
break;
}