MemRegionManager: Migrate logic for getAllocaRegion() over to using trait-based MemRegion creation.

llvm-svn: 73927
This commit is contained in:
Ted Kremenek 2009-06-23 00:15:41 +00:00
parent 2266640a7a
commit 8bae300ade
2 changed files with 38 additions and 18 deletions

View File

@ -123,7 +123,7 @@ protected:
// memory allocated by alloca at the same call site. // memory allocated by alloca at the same call site.
const Expr* Ex; const Expr* Ex;
AllocaRegion(const Expr* ex, unsigned cnt, const MemRegion* superRegion) AllocaRegion(const Expr* ex, unsigned cnt, const MemRegion *superRegion)
: SubRegion(superRegion, AllocaRegionKind), Cnt(cnt), Ex(ex) {} : SubRegion(superRegion, AllocaRegionKind), Cnt(cnt), Ex(ex) {}
public: public:
@ -133,7 +133,7 @@ public:
void Profile(llvm::FoldingSetNodeID& ID) const; void Profile(llvm::FoldingSetNodeID& ID) const;
static void ProfileRegion(llvm::FoldingSetNodeID& ID, const Expr* Ex, static void ProfileRegion(llvm::FoldingSetNodeID& ID, const Expr* Ex,
unsigned Cnt); unsigned Cnt, const MemRegion *superRegion);
void print(llvm::raw_ostream& os) const; void print(llvm::raw_ostream& os) const;
@ -657,6 +657,9 @@ public:
template <typename RegionTy, typename A1> template <typename RegionTy, typename A1>
RegionTy* getRegion(const A1 a1, const MemRegion* superRegion); RegionTy* getRegion(const A1 a1, const MemRegion* superRegion);
template <typename RegionTy, typename A1, typename A2>
RegionTy* getRegion(const A1 a1, const A2 a2);
private: private:
MemSpaceRegion* LazyAllocate(MemSpaceRegion*& region); MemSpaceRegion* LazyAllocate(MemSpaceRegion*& region);
@ -707,10 +710,39 @@ RegionTy* MemRegionManager::getRegion(const A1 a1, const MemRegion *superRegion)
return R; return R;
} }
template <typename RegionTy, typename A1, typename A2>
RegionTy* MemRegionManager::getRegion(const A1 a1, const A2 a2) {
const typename MemRegionManagerTrait<RegionTy>::SuperRegionTy *superRegion =
MemRegionManagerTrait<RegionTy>::getSuperRegion(*this, a1, a2);
llvm::FoldingSetNodeID ID;
RegionTy::ProfileRegion(ID, a1, a2, superRegion);
void* InsertPos;
RegionTy* R = cast_or_null<RegionTy>(Regions.FindNodeOrInsertPos(ID,
InsertPos));
if (!R) {
R = (RegionTy*) A.Allocate<RegionTy>();
new (R) RegionTy(a1, a2, superRegion);
Regions.InsertNode(R, InsertPos);
}
return R;
}
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// Traits for constructing regions. // Traits for constructing regions.
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
template <> struct MemRegionManagerTrait<AllocaRegion> {
typedef MemRegion SuperRegionTy;
static const SuperRegionTy* getSuperRegion(MemRegionManager& MRMgr,
const Expr *, unsigned) {
return MRMgr.getStackRegion();
}
};
template <> struct MemRegionManagerTrait<CompoundLiteralRegion> { template <> struct MemRegionManagerTrait<CompoundLiteralRegion> {
typedef MemRegion SuperRegionTy; typedef MemRegion SuperRegionTy;
static const SuperRegionTy* getSuperRegion(MemRegionManager& MRMgr, static const SuperRegionTy* getSuperRegion(MemRegionManager& MRMgr,

View File

@ -50,14 +50,15 @@ void StringRegion::ProfileRegion(llvm::FoldingSetNodeID& ID,
} }
void AllocaRegion::ProfileRegion(llvm::FoldingSetNodeID& ID, void AllocaRegion::ProfileRegion(llvm::FoldingSetNodeID& ID,
const Expr* Ex, unsigned cnt) { const Expr* Ex, unsigned cnt,
const MemRegion *) {
ID.AddInteger((unsigned) AllocaRegionKind); ID.AddInteger((unsigned) AllocaRegionKind);
ID.AddPointer(Ex); ID.AddPointer(Ex);
ID.AddInteger(cnt); ID.AddInteger(cnt);
} }
void AllocaRegion::Profile(llvm::FoldingSetNodeID& ID) const { void AllocaRegion::Profile(llvm::FoldingSetNodeID& ID) const {
ProfileRegion(ID, Ex, Cnt); ProfileRegion(ID, Ex, Cnt, superRegion);
} }
void TypedViewRegion::ProfileRegion(llvm::FoldingSetNodeID& ID, QualType T, void TypedViewRegion::ProfileRegion(llvm::FoldingSetNodeID& ID, QualType T,
@ -335,20 +336,7 @@ MemRegionManager::getTypedViewRegion(QualType t, const MemRegion* superRegion) {
} }
AllocaRegion* MemRegionManager::getAllocaRegion(const Expr* E, unsigned cnt) { AllocaRegion* MemRegionManager::getAllocaRegion(const Expr* E, unsigned cnt) {
llvm::FoldingSetNodeID ID; return getRegion<AllocaRegion>(E, cnt);
AllocaRegion::ProfileRegion(ID, E, cnt);
void* InsertPos;
MemRegion* data = Regions.FindNodeOrInsertPos(ID, InsertPos);
AllocaRegion* R = cast_or_null<AllocaRegion>(data);
if (!R) {
R = (AllocaRegion*) A.Allocate<AllocaRegion>();
new (R) AllocaRegion(E, cnt, getStackRegion());
Regions.InsertNode(R, InsertPos);
}
return R;
} }
bool MemRegionManager::hasStackStorage(const MemRegion* R) { bool MemRegionManager::hasStackStorage(const MemRegion* R) {