diff options
author | Ted Kremenek <kremenek@apple.com> | 2009-06-23 18:17:08 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2009-06-23 18:17:08 +0000 |
commit | bb7c96f290453104ec35ca17111a5165f68a4697 (patch) | |
tree | ccfc2ca389e182bf11d1bc04f99a8f3f3a1e5df6 /lib/Analysis/MemRegion.cpp | |
parent | 3c092bce5fb4523854c3429e0af44f99c6fe2b92 (diff) |
- Add MemRegion::getMemorySpace()
- Change implementation of MemRegion::hasStackStorage()/hasHeapStorage() to use
'getMemorySpace()'. This avoids a double traversal up the region hierarchy
and is simpler.
- Add MemRegion::hasHeapOrStackStorage() as a slightly more efficient
alternative to 'hasStackStorage() || hasHeapStorage()'.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@73977 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/MemRegion.cpp')
-rw-r--r-- | lib/Analysis/MemRegion.cpp | 49 |
1 files changed, 22 insertions, 27 deletions
diff --git a/lib/Analysis/MemRegion.cpp b/lib/Analysis/MemRegion.cpp index f018c83b91..c8e027579a 100644 --- a/lib/Analysis/MemRegion.cpp +++ b/lib/Analysis/MemRegion.cpp @@ -313,45 +313,40 @@ AllocaRegion* MemRegionManager::getAllocaRegion(const Expr* E, unsigned cnt) { return getRegion<AllocaRegion>(E, cnt); } -bool MemRegion::hasStackStorage() const { - // Only subregions can have stack storage. - const SubRegion* SR = dyn_cast<SubRegion>(this); - - if (!SR) - return false; - MemSpaceRegion* S = getMemRegionManager()->getStackRegion(); +const MemSpaceRegion *MemRegion::getMemorySpace() const { + const MemRegion *R = this; + const SubRegion* SR = dyn_cast<SubRegion>(this); while (SR) { - const MemRegion *R = SR->getSuperRegion(); - if (R == S) - return true; - - SR = dyn_cast<SubRegion>(R); + R = SR->getSuperRegion(); + SR = dyn_cast<SubRegion>(R); } - - return false; + + return dyn_cast<MemSpaceRegion>(R); } -bool MemRegion::hasHeapStorage() const { - // Only subregions can have stack storage. - const SubRegion* SR = dyn_cast<SubRegion>(this); +bool MemRegion::hasStackStorage() const { + if (const MemSpaceRegion *MS = getMemorySpace()) + return MS == getMemRegionManager()->getStackRegion(); - if (!SR) - return false; + return false; +} - MemSpaceRegion* H = getMemRegionManager()->getHeapRegion(); +bool MemRegion::hasHeapStorage() const { + if (const MemSpaceRegion *MS = getMemorySpace()) + return MS == getMemRegionManager()->getHeapRegion(); - while (SR) { - const MemRegion *R = SR->getSuperRegion(); - if (R == H) - return true; + return false; +} - SR = dyn_cast<SubRegion>(R); +bool MemRegion::hasHeapOrStackStorage() const { + if (const MemSpaceRegion *MS = getMemorySpace()) { + MemRegionManager *Mgr = getMemRegionManager(); + return MS == Mgr->getHeapRegion() || MS == Mgr->getStackRegion(); } - return false; -} +} //===----------------------------------------------------------------------===// // View handling. |