forked from OSchip/llvm-project
MemRegionManager: Migrate logic for getAllocaRegion() over to using trait-based MemRegion creation.
llvm-svn: 73927
This commit is contained in:
parent
2266640a7a
commit
8bae300ade
|
@ -123,7 +123,7 @@ protected:
|
|||
// memory allocated by alloca at the same call site.
|
||||
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) {}
|
||||
|
||||
public:
|
||||
|
@ -133,7 +133,7 @@ public:
|
|||
void Profile(llvm::FoldingSetNodeID& ID) const;
|
||||
|
||||
static void ProfileRegion(llvm::FoldingSetNodeID& ID, const Expr* Ex,
|
||||
unsigned Cnt);
|
||||
unsigned Cnt, const MemRegion *superRegion);
|
||||
|
||||
void print(llvm::raw_ostream& os) const;
|
||||
|
||||
|
@ -657,6 +657,9 @@ public:
|
|||
|
||||
template <typename RegionTy, typename A1>
|
||||
RegionTy* getRegion(const A1 a1, const MemRegion* superRegion);
|
||||
|
||||
template <typename RegionTy, typename A1, typename A2>
|
||||
RegionTy* getRegion(const A1 a1, const A2 a2);
|
||||
|
||||
private:
|
||||
MemSpaceRegion* LazyAllocate(MemSpaceRegion*& region);
|
||||
|
@ -707,10 +710,39 @@ RegionTy* MemRegionManager::getRegion(const A1 a1, const MemRegion *superRegion)
|
|||
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.
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
template <> struct MemRegionManagerTrait<AllocaRegion> {
|
||||
typedef MemRegion SuperRegionTy;
|
||||
static const SuperRegionTy* getSuperRegion(MemRegionManager& MRMgr,
|
||||
const Expr *, unsigned) {
|
||||
return MRMgr.getStackRegion();
|
||||
}
|
||||
};
|
||||
|
||||
template <> struct MemRegionManagerTrait<CompoundLiteralRegion> {
|
||||
typedef MemRegion SuperRegionTy;
|
||||
static const SuperRegionTy* getSuperRegion(MemRegionManager& MRMgr,
|
||||
|
|
|
@ -50,14 +50,15 @@ void StringRegion::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.AddPointer(Ex);
|
||||
ID.AddInteger(cnt);
|
||||
}
|
||||
|
||||
void AllocaRegion::Profile(llvm::FoldingSetNodeID& ID) const {
|
||||
ProfileRegion(ID, Ex, Cnt);
|
||||
ProfileRegion(ID, Ex, Cnt, superRegion);
|
||||
}
|
||||
|
||||
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) {
|
||||
llvm::FoldingSetNodeID ID;
|
||||
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;
|
||||
return getRegion<AllocaRegion>(E, cnt);
|
||||
}
|
||||
|
||||
bool MemRegionManager::hasStackStorage(const MemRegion* R) {
|
||||
|
|
Loading…
Reference in New Issue