Store ArrayShape in shared_ptr and MemAccs as actual objects

This fixes two more memory leaks.

llvm-svn: 239050
This commit is contained in:
Tobias Grosser 2015-06-04 16:03:16 +00:00
parent 81c7ae2bf5
commit a5c092d844
3 changed files with 13 additions and 9 deletions

View File

@ -52,6 +52,7 @@
#include "llvm/Analysis/AliasSetTracker.h"
#include "llvm/Pass.h"
#include <map>
#include <memory>
#include <set>
using namespace llvm;
@ -89,16 +90,16 @@ struct MemAcc {
const Instruction *Insn;
// A pointer to the shape description of the array.
ArrayShape *Shape;
std::shared_ptr<ArrayShape> Shape;
// Subscripts computed by delinearization.
SmallVector<const SCEV *, 4> DelinearizedSubscripts;
MemAcc(const Instruction *I, ArrayShape *S)
MemAcc(const Instruction *I, std::shared_ptr<ArrayShape> S)
: Insn(I), Shape(S), DelinearizedSubscripts() {}
};
typedef std::map<const Instruction *, MemAcc *> MapInsnToMemAcc;
typedef std::map<const Instruction *, MemAcc> MapInsnToMemAcc;
typedef std::pair<const Instruction *, const SCEV *> PairInstSCEV;
typedef std::vector<PairInstSCEV> AFs;
typedef std::map<const SCEVUnknown *, AFs> BaseToAFs;

View File

@ -471,7 +471,7 @@ bool ScopDetection::hasAffineMemoryAccesses(DetectionContext &Context) const {
for (const SCEVUnknown *BasePointer : Context.NonAffineAccesses) {
Value *BaseValue = BasePointer->getValue();
ArrayShape *Shape = new ArrayShape(BasePointer);
auto Shape = std::shared_ptr<ArrayShape>(new ArrayShape(BasePointer));
bool BasePtrHasNonAffine = false;
// First step: collect parametric terms in all array references.
@ -527,8 +527,10 @@ bool ScopDetection::hasAffineMemoryAccesses(DetectionContext &Context) const {
const Instruction *Insn = Pair.first;
const SCEVAddRecExpr *AF = dyn_cast<SCEVAddRecExpr>(Pair.second);
bool IsNonAffine = false;
MemAcc *Acc = new MemAcc(Insn, Shape);
TempMemoryAccesses.insert({Insn, Acc});
TempMemoryAccesses.emplace(std::piecewise_construct,
std::forward_as_tuple(Insn),
std::forward_as_tuple(Insn, Shape));
MemAcc *Acc = &TempMemoryAccesses.find(Insn)->second;
if (!AF) {
if (isAffineExpr(&CurRegion, Pair.second, *SE, BaseValue))

View File

@ -237,10 +237,11 @@ TempScopInfo::buildIRAccess(Instruction *Inst, Loop *L, Region *R,
assert(BasePointer && "Could not find base pointer");
AccessFunction = SE->getMinusSCEV(AccessFunction, BasePointer);
MemAcc *Acc = InsnToMemAcc[Inst];
if (PollyDelinearize && Acc)
auto AccItr = InsnToMemAcc.find(Inst);
if (PollyDelinearize && AccItr != InsnToMemAcc.end())
return IRAccess(Type, BasePointer->getValue(), AccessFunction, Size, true,
Acc->DelinearizedSubscripts, Acc->Shape->DelinearizedSizes);
AccItr->second.DelinearizedSubscripts,
AccItr->second.Shape->DelinearizedSizes);
// Check if the access depends on a loop contained in a non-affine subregion.
bool isVariantInNonAffineLoop = false;