Give each memory access a reference ID

This reference ID is handy for use cases where we need to identify individual
memory accesses (e.g. to modify their access functions).

This is a reworked version of a patch originally developed by Yabin Hu as part
of his summer of code project.

llvm-svn: 237431
This commit is contained in:
Tobias Grosser 2015-05-15 09:58:32 +00:00
parent 3ca283ada3
commit 6f48e0fd2b
2 changed files with 35 additions and 7 deletions

View File

@ -206,6 +206,12 @@ private:
/// Updated access relation read from JSCOP file.
isl_map *newAccessRelation;
/// @brief A unique identifier for this memory access.
///
/// The identifier is unique between all memory accesses belonging to the same
/// scop statement.
isl_id *Id;
void assumeNoOutOfBound(const IRAccess &Access);
/// @brief Compute bounds on an over approximated access relation.
@ -261,8 +267,10 @@ public:
/// @param AccInst The access instruction.
/// @param Statement The statement that contains the access.
/// @param SAI The ScopArrayInfo object for this base pointer.
/// @param Identifier An identifier that is unique for all memory accesses
/// belonging to the same scop statement.
MemoryAccess(const IRAccess &Access, Instruction *AccInst,
ScopStmt *Statement, const ScopArrayInfo *SAI);
ScopStmt *Statement, const ScopArrayInfo *SAI, int Identifier);
~MemoryAccess();
@ -369,6 +377,12 @@ public:
/// @brief Align the parameters in the access relation to the scop context
void realignParams();
/// @brief Get identifier for the memory access.
///
/// This identifier is unique for all accesses that belong to the same scop
/// statement.
__isl_give isl_id *getId() const;
/// @brief Print the MemoryAccess.
///
/// @param OS The output stream the MemoryAccess is printed to.

View File

@ -418,6 +418,7 @@ static MemoryAccess::ReductionType getReductionType(const BinaryOperator *BinOp,
//===----------------------------------------------------------------------===//
MemoryAccess::~MemoryAccess() {
isl_id_free(Id);
isl_map_free(AccessRelation);
isl_map_free(newAccessRelation);
}
@ -624,7 +625,8 @@ __isl_give isl_map *MemoryAccess::foldAccess(const IRAccess &Access,
}
MemoryAccess::MemoryAccess(const IRAccess &Access, Instruction *AccInst,
ScopStmt *Statement, const ScopArrayInfo *SAI)
ScopStmt *Statement, const ScopArrayInfo *SAI,
int Identifier)
: AccType(getMemoryAccessType(Access)), Statement(Statement), Inst(AccInst),
newAccessRelation(nullptr) {
@ -634,6 +636,12 @@ MemoryAccess::MemoryAccess(const IRAccess &Access, Instruction *AccInst,
isl_id *BaseAddrId = SAI->getBasePtrId();
std::string IdName;
raw_string_ostream IdNameStream(IdName);
IdNameStream << "__polly_array_ref_ " << Identifier;
IdNameStream.flush();
this->Id = isl_id_alloc(Ctx, IdName.c_str(), nullptr);
if (!Access.isAffine()) {
// We overapproximate non-affine accesses with a possible access to the
// whole array. For read accesses it does not make a difference, if an
@ -694,6 +702,8 @@ const std::string MemoryAccess::getReductionOperatorStr() const {
return MemoryAccess::getReductionOperatorStr(getReductionType());
}
__isl_give isl_id *MemoryAccess::getId() const { return isl_id_copy(Id); }
raw_ostream &polly::operator<<(raw_ostream &OS,
MemoryAccess::ReductionType RT) {
if (RT == MemoryAccess::RT_NONE)
@ -868,6 +878,8 @@ void ScopStmt::buildAccesses(TempScop &tempScop, BasicBlock *Block,
if (!AFS)
return;
int Identifier = 0;
for (auto &AccessPair : *AFS) {
IRAccess &Access = AccessPair.first;
Instruction *AccessInst = AccessPair.second;
@ -879,7 +891,9 @@ void ScopStmt::buildAccesses(TempScop &tempScop, BasicBlock *Block,
if (isApproximated && Access.isWrite())
Access.setMayWrite();
MemAccs.push_back(new MemoryAccess(Access, AccessInst, this, SAI));
MemAccs.push_back(
new MemoryAccess(Access, AccessInst, this, SAI, Identifier));
Identifier++;
// We do not track locations for scalar memory accesses at the moment.
//