mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-26 04:32:44 +01:00
Use unique_ptr to manage ownership of child Regions within llvm::Region
llvm-svn: 206310
This commit is contained in:
parent
dd5842a2e5
commit
f5cc2195dc
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user