Add printing and testing to ScopArrayInfo

Being here, we extend the interface to return the element type and not a pointer
to the element type. We also provide a function to get the size (in bytes) of
the elements stored in this array.

We currently still store the element size as an innermost dimension in
ScopArrayInfo, which is somehow inconsistent and should be addressed in future
patches.

llvm-svn: 237779
This commit is contained in:
Tobias Grosser 2015-05-20 08:05:31 +00:00
parent 7619004211
commit 49ad36ca16
5 changed files with 50 additions and 19 deletions

View File

@ -69,10 +69,10 @@ public:
/// @brief Construct a ScopArrayInfo object.
///
/// @param BasePtr The array base pointer.
/// @param AccessType The type used to access this array.
/// @param ElementType The type of the elements stored in the array.
/// @param IslCtx The isl context used to create the base pointer id.
/// @param DimensionSizes A vector containing the size of each dimension.
ScopArrayInfo(Value *BasePtr, Type *AccessType, isl_ctx *IslCtx,
ScopArrayInfo(Value *BasePtr, Type *ElementType, isl_ctx *IslCtx,
const SmallVector<const SCEV *, 4> &DimensionSizes);
/// @brief Destructor to free the isl id of the base pointer.
@ -90,8 +90,14 @@ public:
return DimensionSizes[dim];
}
/// @brief Return the type used to access this array in the SCoP.
Type *getType() const { return AccessType; }
/// @brief Get the type of the elements stored in this array.
Type *getElementType() const { return ElementType; }
/// @brief Get element size in bytes.
int getElemSizeInBytes() const;
/// @brief Get the name of this memory reference.
std::string getName() const;
/// @brief Return the isl id for the base pointer.
__isl_give isl_id *getBasePtrId() const;
@ -113,8 +119,8 @@ private:
/// @brief The base pointer.
Value *BasePtr;
/// @brief The type used to access this array.
Type *AccessType;
/// @brief The type of the elements stored in this array.
Type *ElementType;
/// @brief The isl id for the base pointer.
isl_id *Id;
@ -838,6 +844,7 @@ private:
///
///{
void printContext(raw_ostream &OS) const;
void printArrayInfo(raw_ostream &OS) const;
void printStatements(raw_ostream &OS) const;
void printAliasAssumptions(raw_ostream &OS) const;
///}
@ -1006,8 +1013,10 @@ public:
//@}
/// @brief Return the (possibly new) ScopArrayInfo object for @p Access.
///
/// @param ElementType The type of the elements stored in this array.
const ScopArrayInfo *
getOrCreateScopArrayInfo(Value *BasePtr, Type *AccessType,
getOrCreateScopArrayInfo(Value *BasePtr, Type *ElementType,
const SmallVector<const SCEV *, 4> &Sizes);
/// @brief Return the cached ScopArrayInfo object for @p BasePtr.

View File

@ -327,27 +327,31 @@ static __isl_give isl_set *addRangeBoundsToSet(__isl_take isl_set *S,
return isl_set_intersect(SLB, SUB);
}
ScopArrayInfo::ScopArrayInfo(Value *BasePtr, Type *AccessType, isl_ctx *Ctx,
ScopArrayInfo::ScopArrayInfo(Value *BasePtr, Type *ElementType, isl_ctx *Ctx,
const SmallVector<const SCEV *, 4> &DimensionSizes)
: BasePtr(BasePtr), AccessType(AccessType), DimensionSizes(DimensionSizes) {
: BasePtr(BasePtr), ElementType(ElementType),
DimensionSizes(DimensionSizes) {
const std::string BasePtrName = getIslCompatibleName("MemRef_", BasePtr, "");
Id = isl_id_alloc(Ctx, BasePtrName.c_str(), this);
}
ScopArrayInfo::~ScopArrayInfo() { isl_id_free(Id); }
std::string ScopArrayInfo::getName() const { return isl_id_get_name(Id); }
int ScopArrayInfo::getElemSizeInBytes() const {
return ElementType->getPrimitiveSizeInBits() / 8;
}
isl_id *ScopArrayInfo::getBasePtrId() const { return isl_id_copy(Id); }
void ScopArrayInfo::dump() const { print(errs()); }
void ScopArrayInfo::print(raw_ostream &OS) const {
OS << "ScopArrayInfo:\n";
OS << " Base: " << *getBasePtr() << "\n";
OS << " Type: " << *getType() << "\n";
OS << " Dimension Sizes:\n";
OS.indent(8) << *getElementType() << " " << getName() << "[*]";
for (unsigned u = 0; u < getNumberOfDimensions(); u++)
OS << " " << u << ") " << *DimensionSizes[u] << "\n";
OS << "\n";
OS << "[" << *DimensionSizes[u] << "]";
OS << " // Element size " << getElemSizeInBytes() << "\n";
}
const ScopArrayInfo *
@ -879,9 +883,9 @@ void ScopStmt::buildAccesses(TempScop &tempScop, BasicBlock *Block,
IRAccess &Access = AccessPair.first;
Instruction *AccessInst = AccessPair.second;
Type *AccessType = getAccessInstType(AccessInst)->getPointerTo();
Type *ElementType = getAccessInstType(AccessInst);
const ScopArrayInfo *SAI = getParent()->getOrCreateScopArrayInfo(
Access.getBase(), AccessType, Access.Sizes);
Access.getBase(), ElementType, Access.Sizes);
if (isApproximated && Access.isWrite())
Access.setMayWrite();
@ -1843,12 +1847,22 @@ void Scop::printStatements(raw_ostream &OS) const {
OS.indent(4) << "}\n";
}
void Scop::printArrayInfo(raw_ostream &OS) const {
OS << "Arrays {\n";
for (auto Array : arrays())
Array.second->print(OS);
OS.indent(4) << "}\n";
}
void Scop::print(raw_ostream &OS) const {
OS.indent(4) << "Function: " << getRegion().getEntry()->getParent()->getName()
<< "\n";
OS.indent(4) << "Region: " << getNameStr() << "\n";
OS.indent(4) << "Max Loop Depth: " << getMaxLoopDepth() << "\n";
printContext(OS.indent(4));
printArrayInfo(OS.indent(4));
printAliasAssumptions(OS);
printStatements(OS.indent(4));
}

View File

@ -115,8 +115,8 @@ Value *IslExprBuilder::createAccessAddress(isl_ast_expr *Expr) {
assert(Base->getType()->isPointerTy() && "Access base should be a pointer");
StringRef BaseName = Base->getName();
if (Base->getType() != SAI->getType())
Base = Builder.CreateBitCast(Base, SAI->getType(),
if (Base->getType() != SAI->getElementType()->getPointerTo())
Base = Builder.CreateBitCast(Base, SAI->getElementType()->getPointerTo(),
"polly.access.cast." + BaseName);
IndexOp = nullptr;

View File

@ -9,6 +9,11 @@
; }
; }
; CHECK: Arrays {
; CHECK: double MemRef_A[*][%m][%o][8] // Element size 8
; CHECK: }
; CHECK: [n, m, o] -> { Stmt_for_body6[i0, i1, i2] -> MemRef_A[3 + i0, i1, 7 + i2] };
; CHECK: [n, m, o] -> { Stmt_for_body6[i0, i1, i2] -> MemRef_A[i0, 0, i2] };

View File

@ -26,6 +26,9 @@ return: ; preds = %bb, %entry
; CHECK: Assumed Context:
; CHECK: { : }
; CHECK: Arrays {
; CHECK: i64 MemRef_a[*][8] // Element size 8
; CHECK: }
; CHECK: Stmt_bb
; CHECK: Domain :=