[PATCH] D31719: [RegionInfo] Fix dangling references created by moving RegionInfo objects
Philip Pfaffe via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 5 11:08:13 PDT 2017
philip.pfaffe created this revision.
Region objects capture the address of the creating RegionInfo instance. Because the RegionInfo class is movable, moving a RegionInfo object creates dangling references. This patch fixes these references by walking the Regions post-move, and updating references to the new parent.
Repository:
rL LLVM
https://reviews.llvm.org/D31719
Files:
include/llvm/Analysis/RegionInfo.h
Index: include/llvm/Analysis/RegionInfo.h
===================================================================
--- include/llvm/Analysis/RegionInfo.h
+++ include/llvm/Analysis/RegionInfo.h
@@ -708,10 +708,24 @@
/// The top level region.
RegionT *TopLevelRegion;
-private:
/// Map every BB to the smallest region, that contains BB.
BBtoRegionMap BBtoRegion;
+protected:
+ /// \brief Update refences to a RegionInfoT held by the RegionT managed here
+ ///
+ /// This is a post-move helper. Regions hold references to the owning
+ /// RegionInfo object. After a move these need to be fixed.
+ template<typename TheRegionT>
+ void updateRegionTree(RegionInfoT &RI, TheRegionT *R) {
+ if (!R)
+ return;
+ R->RI = &RI;
+ for (auto &SubR : *R)
+ updateRegionTree(RI, SubR.get());
+ }
+
+private:
/// \brief Wipe this region tree's state without releasing any resources.
///
/// This is essentially a post-move helper only. It leaves the object in an
@@ -880,9 +894,12 @@
~RegionInfo() override;
RegionInfo(RegionInfo &&Arg)
- : Base(std::move(static_cast<Base &>(Arg))) {}
- RegionInfo &operator=(RegionInfo &&RHS) {
- Base::operator=(std::move(static_cast<Base &>(RHS)));
+ : RegionInfoBase<RegionTraits<Function>>(std::move(Arg)) {
+ updateRegionTree(*this, TopLevelRegion);
+ }
+ RegionInfo &operator=(RegionInfo &&Arg) {
+ RegionInfoBase<RegionTraits<Function>>::operator=(std::move(Arg));
+ updateRegionTree(*this, TopLevelRegion);
return *this;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31719.94262.patch
Type: text/x-patch
Size: 1537 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170405/3d370d8e/attachment.bin>
More information about the llvm-commits
mailing list