From 49ad36ca1689fdbf88275765c4e5b47e166e9e0f Mon Sep 17 00:00:00 2001 From: Tobias Grosser Date: Wed, 20 May 2015 08:05:31 +0000 Subject: [PATCH] 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 --- polly/include/polly/ScopInfo.h | 23 +++++++++---- polly/lib/Analysis/ScopInfo.cpp | 34 +++++++++++++------ polly/lib/CodeGen/IslExprBuilder.cpp | 4 +-- .../delinearize-together-all-data-refs.ll | 5 +++ polly/test/ScopInfo/simple_loop_1.ll | 3 ++ 5 files changed, 50 insertions(+), 19 deletions(-) diff --git a/polly/include/polly/ScopInfo.h b/polly/include/polly/ScopInfo.h index c31f31f7ba47..4aa7d06c3230 100644 --- a/polly/include/polly/ScopInfo.h +++ b/polly/include/polly/ScopInfo.h @@ -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 &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 &Sizes); /// @brief Return the cached ScopArrayInfo object for @p BasePtr. diff --git a/polly/lib/Analysis/ScopInfo.cpp b/polly/lib/Analysis/ScopInfo.cpp index 558da0a55cd2..951dfc79a4d2 100644 --- a/polly/lib/Analysis/ScopInfo.cpp +++ b/polly/lib/Analysis/ScopInfo.cpp @@ -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 &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)); } diff --git a/polly/lib/CodeGen/IslExprBuilder.cpp b/polly/lib/CodeGen/IslExprBuilder.cpp index 8cd145ca7c18..ed2641fbd2df 100644 --- a/polly/lib/CodeGen/IslExprBuilder.cpp +++ b/polly/lib/CodeGen/IslExprBuilder.cpp @@ -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; diff --git a/polly/test/ScopInfo/delinearize-together-all-data-refs.ll b/polly/test/ScopInfo/delinearize-together-all-data-refs.ll index 08450d64db2d..446c95104e21 100644 --- a/polly/test/ScopInfo/delinearize-together-all-data-refs.ll +++ b/polly/test/ScopInfo/delinearize-together-all-data-refs.ll @@ -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] }; diff --git a/polly/test/ScopInfo/simple_loop_1.ll b/polly/test/ScopInfo/simple_loop_1.ll index f1da4e53c3a6..6146fd63a805 100644 --- a/polly/test/ScopInfo/simple_loop_1.ll +++ b/polly/test/ScopInfo/simple_loop_1.ll @@ -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 :=