diff options
author | David Blaikie <dblaikie@gmail.com> | 2014-04-15 18:32:43 +0000 |
---|---|---|
committer | David Blaikie <dblaikie@gmail.com> | 2014-04-15 18:32:43 +0000 |
commit | 2bbc5a7e2cf6292ca246915510b22263e5f6901a (patch) | |
tree | ee188485d4a9131e2c64d9610e9d08087c539a79 | |
parent | 894b7f642c0b52f378cdd754c3aee38a7e3b49ec (diff) | |
download | llvm-2bbc5a7e2cf6292ca246915510b22263e5f6901a.tar.gz llvm-2bbc5a7e2cf6292ca246915510b22263e5f6901a.tar.bz2 llvm-2bbc5a7e2cf6292ca246915510b22263e5f6901a.tar.xz |
Use unique_ptr to manage ownership of child Regions within llvm::Region
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206310 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/llvm/Analysis/RegionInfo.h | 3 | ||||
-rw-r--r-- | lib/Analysis/RegionInfo.cpp | 34 | ||||
-rw-r--r-- | lib/Analysis/RegionPass.cpp | 10 | ||||
-rw-r--r-- | lib/Analysis/RegionPrinter.cpp | 22 |
4 files changed, 37 insertions, 32 deletions
diff --git a/include/llvm/Analysis/RegionInfo.h b/include/llvm/Analysis/RegionInfo.h index 6b43ae3124..82a788d1bb 100644 --- a/include/llvm/Analysis/RegionInfo.h +++ b/include/llvm/Analysis/RegionInfo.h @@ -33,6 +33,7 @@ #include "llvm/Analysis/PostDominators.h" #include "llvm/Support/Allocator.h" #include <map> +#include <memory> namespace llvm { @@ -213,7 +214,7 @@ class Region : public RegionNode { // (The entry BasicBlock is part of RegionNode) BasicBlock *exit; - typedef std::vector<Region*> RegionSet; + typedef std::vector<std::unique_ptr<Region>> RegionSet; // The subregions of this region. RegionSet children; diff --git a/lib/Analysis/RegionInfo.cpp b/lib/Analysis/RegionInfo.cpp index c9a07ab60d..6f3b4c2951 100644 --- a/lib/Analysis/RegionInfo.cpp +++ b/lib/Analysis/RegionInfo.cpp @@ -19,6 +19,7 @@ #include "llvm/Support/Debug.h" #include "llvm/Support/ErrorHandling.h" #include <algorithm> +#include <iterator> #include <set> using namespace llvm; @@ -62,9 +63,6 @@ Region::~Region() { // Only clean the cache for this Region. Caches of child Regions will be // cleaned when the child Regions are deleted. BBNodeMap.clear(); - - for (iterator I = begin(), E = end(); I != E; ++I) - delete *I; } void Region::replaceEntry(BasicBlock *BB) { @@ -88,7 +86,7 @@ void Region::replaceEntryRecursive(BasicBlock *NewEntry) { R->replaceEntry(NewEntry); for (Region::const_iterator RI = R->begin(), RE = R->end(); RI != RE; ++RI) if ((*RI)->getEntry() == OldEntry) - RegionQueue.push_back(*RI); + RegionQueue.push_back(RI->get()); } } @@ -104,7 +102,7 @@ void Region::replaceExitRecursive(BasicBlock *NewExit) { R->replaceExit(NewExit); for (Region::const_iterator RI = R->begin(), RE = R->end(); RI != RE; ++RI) if ((*RI)->getExit() == OldExit) - RegionQueue.push_back(*RI); + RegionQueue.push_back(RI->get()); } } @@ -333,18 +331,20 @@ RegionNode* Region::getNode(BasicBlock *BB) const { void Region::transferChildrenTo(Region *To) { for (iterator I = begin(), E = end(); I != E; ++I) { (*I)->parent = To; - To->children.push_back(*I); + To->children.push_back(std::move(*I)); } children.clear(); } void Region::addSubRegion(Region *SubRegion, bool moveChildren) { assert(!SubRegion->parent && "SubRegion already has a parent!"); - assert(std::find(begin(), end(), SubRegion) == children.end() - && "Subregion already exists!"); + assert(std::find_if(begin(), end(), [&](const std::unique_ptr<Region> &R) { + return R.get() == SubRegion; + }) == children.end() && + "Subregion already exists!"); SubRegion->parent = this; - children.push_back(SubRegion); + children.push_back(std::unique_ptr<Region>(SubRegion)); if (!moveChildren) return; @@ -360,23 +360,27 @@ void Region::addSubRegion(Region *SubRegion, bool moveChildren) { RI->setRegionFor(BB, SubRegion); } - std::vector<Region*> Keep; + std::vector<std::unique_ptr<Region>> Keep; for (iterator I = begin(), E = end(); I != E; ++I) - if (SubRegion->contains(*I) && *I != SubRegion) { - SubRegion->children.push_back(*I); + if (SubRegion->contains(I->get()) && I->get() != SubRegion) { + SubRegion->children.push_back(std::move(*I)); (*I)->parent = SubRegion; } else - Keep.push_back(*I); + Keep.push_back(std::move(*I)); children.clear(); - children.insert(children.begin(), Keep.begin(), Keep.end()); + children.insert(children.begin(), + std::move_iterator<RegionSet::iterator>(Keep.begin()), + std::move_iterator<RegionSet::iterator>(Keep.end())); } Region *Region::removeSubRegion(Region *Child) { assert(Child->parent == this && "Child is not a child of this region!"); Child->parent = nullptr; - RegionSet::iterator I = std::find(children.begin(), children.end(), Child); + RegionSet::iterator I = std::find_if( + children.begin(), children.end(), + [&](const std::unique_ptr<Region> &R) { return R.get() == Child; }); assert(I != children.end() && "Region does not exit. Unable to remove."); children.erase(children.begin()+(I-begin())); return Child; diff --git a/lib/Analysis/RegionPass.cpp b/lib/Analysis/RegionPass.cpp index b29070a4fb..1798c36fc1 100644 --- a/lib/Analysis/RegionPass.cpp +++ b/lib/Analysis/RegionPass.cpp @@ -36,10 +36,10 @@ RGPassManager::RGPassManager() } // Recurse through all subregions and all regions into RQ. -static void addRegionIntoQueue(Region *R, std::deque<Region *> &RQ) { - RQ.push_back(R); - for (Region::iterator I = R->begin(), E = R->end(); I != E; ++I) - addRegionIntoQueue(*I, RQ); +static void addRegionIntoQueue(Region &R, std::deque<Region *> &RQ) { + RQ.push_back(&R); + for (const auto &E : R) + addRegionIntoQueue(*E, RQ); } /// Pass Manager itself does not invalidate any analysis info. @@ -57,7 +57,7 @@ bool RGPassManager::runOnFunction(Function &F) { // Collect inherited analysis from Module level pass manager. populateInheritedAnalysis(TPM->activeStack); - addRegionIntoQueue(RI->getTopLevelRegion(), RQ); + addRegionIntoQueue(*RI->getTopLevelRegion(), RQ); if (RQ.empty()) // No regions, skip calling finalizers return false; diff --git a/lib/Analysis/RegionPrinter.cpp b/lib/Analysis/RegionPrinter.cpp index 6467f47cfb..893210a5d7 100644 --- a/lib/Analysis/RegionPrinter.cpp +++ b/lib/Analysis/RegionPrinter.cpp @@ -98,31 +98,31 @@ struct DOTGraphTraits<RegionInfo*> : public DOTGraphTraits<RegionNode*> { // Print the cluster of the subregions. This groups the single basic blocks // and adds a different background color for each group. - static void printRegionCluster(const Region *R, GraphWriter<RegionInfo*> &GW, + static void printRegionCluster(const Region &R, GraphWriter<RegionInfo*> &GW, unsigned depth = 0) { raw_ostream &O = GW.getOStream(); - O.indent(2 * depth) << "subgraph cluster_" << static_cast<const void*>(R) + O.indent(2 * depth) << "subgraph cluster_" << static_cast<const void*>(&R) << " {\n"; O.indent(2 * (depth + 1)) << "label = \"\";\n"; - if (!onlySimpleRegions || R->isSimple()) { + if (!onlySimpleRegions || R.isSimple()) { O.indent(2 * (depth + 1)) << "style = filled;\n"; O.indent(2 * (depth + 1)) << "color = " - << ((R->getDepth() * 2 % 12) + 1) << "\n"; + << ((R.getDepth() * 2 % 12) + 1) << "\n"; } else { O.indent(2 * (depth + 1)) << "style = solid;\n"; O.indent(2 * (depth + 1)) << "color = " - << ((R->getDepth() * 2 % 12) + 2) << "\n"; + << ((R.getDepth() * 2 % 12) + 2) << "\n"; } - for (Region::const_iterator RI = R->begin(), RE = R->end(); RI != RE; ++RI) - printRegionCluster(*RI, GW, depth + 1); + for (Region::const_iterator RI = R.begin(), RE = R.end(); RI != RE; ++RI) + printRegionCluster(**RI, GW, depth + 1); - RegionInfo *RI = R->getRegionInfo(); + RegionInfo *RI = R.getRegionInfo(); - for (const auto &BB : R->blocks()) - if (RI->getRegionFor(BB) == R) + for (const auto &BB : R.blocks()) + if (RI->getRegionFor(BB) == &R) O.indent(2 * (depth + 1)) << "Node" << static_cast<const void*>(RI->getTopLevelRegion()->getBBNode(BB)) << ";\n"; @@ -134,7 +134,7 @@ struct DOTGraphTraits<RegionInfo*> : public DOTGraphTraits<RegionNode*> { GraphWriter<RegionInfo*> &GW) { raw_ostream &O = GW.getOStream(); O << "\tcolorscheme = \"paired12\"\n"; - printRegionCluster(RI->getTopLevelRegion(), GW, 4); + printRegionCluster(*RI->getTopLevelRegion(), GW, 4); } }; } //end namespace llvm |