RegionInfo: Enhance addSubregion.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@116395 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Tobias Grosser 2010-10-13 05:54:09 +00:00
parent 9ee5c50776
commit 9649390e1f
2 changed files with 33 additions and 6 deletions

View File

@ -58,6 +58,7 @@ class RegionNode {
// DO NOT IMPLEMENT
const RegionNode &operator=(const RegionNode &);
protected:
/// This is the entry basic block that starts this region node. If this is a
/// BasicBlock RegionNode, then entry is just the basic block, that this
/// RegionNode represents. Otherwise it is the entry of this (Sub)RegionNode.
@ -70,7 +71,6 @@ class RegionNode {
/// RegionNode.
PointerIntPair<BasicBlock*, 1, bool> entry;
protected:
/// @brief The parent Region of this RegionNode.
/// @see getParent()
Region* parent;
@ -386,7 +386,9 @@ public:
/// @brief Add a new subregion to this Region.
///
/// @param SubRegion The new subregion that will be added.
void addSubRegion(Region *SubRegion);
/// @param moveChildren Move the children of this region, that are also
/// contained in SubRegion into SubRegion.
void addSubRegion(Region *SubRegion, bool moveChildren = false);
/// @brief Remove a subregion from this Region.
///

View File

@ -311,13 +311,38 @@ void Region::transferChildrenTo(Region *To) {
children.clear();
}
void Region::addSubRegion(Region *SubRegion) {
void Region::addSubRegion(Region *SubRegion, bool moveChildren) {
assert(SubRegion->parent == 0 && "SubRegion already has a parent!");
assert(std::find(begin(), end(), SubRegion) == children.end()
&& "Subregion already exists!");
SubRegion->parent = this;
// Set up the region node.
assert(std::find(children.begin(), children.end(), SubRegion) == children.end()
&& "Node already exist!");
children.push_back(SubRegion);
if (!moveChildren)
return;
assert(SubRegion->children.size() == 0
&& "SubRegions that contain children are not supported");
for (element_iterator I = element_begin(), E = element_end(); I != E; ++I)
if (!(*I)->isSubRegion()) {
BasicBlock *BB = (*I)->getNodeAs<BasicBlock>();
if (SubRegion->contains(BB))
RI->setRegionFor(BB, SubRegion);
}
std::vector<Region*> Keep;
for (iterator I = begin(), E = end(); I != E; ++I)
if (SubRegion->contains(*I) && *I != SubRegion) {
SubRegion->children.push_back(*I);
(*I)->parent = SubRegion;
} else
Keep.push_back(*I);
children.clear();
children.insert(children.begin(), Keep.begin(), Keep.end());
}