[polly] r237779 - Add printing and testing to ScopArrayInfo

Tobias Grosser tobias at grosser.es
Wed May 20 01:05:32 PDT 2015


Author: grosser
Date: Wed May 20 03:05:31 2015
New Revision: 237779

URL: http://llvm.org/viewvc/llvm-project?rev=237779&view=rev
Log:
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.

Modified:
    polly/trunk/include/polly/ScopInfo.h
    polly/trunk/lib/Analysis/ScopInfo.cpp
    polly/trunk/lib/CodeGen/IslExprBuilder.cpp
    polly/trunk/test/ScopInfo/delinearize-together-all-data-refs.ll
    polly/trunk/test/ScopInfo/simple_loop_1.ll

Modified: polly/trunk/include/polly/ScopInfo.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/ScopInfo.h?rev=237779&r1=237778&r2=237779&view=diff
==============================================================================
--- polly/trunk/include/polly/ScopInfo.h (original)
+++ polly/trunk/include/polly/ScopInfo.h Wed May 20 03:05:31 2015
@@ -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.

Modified: polly/trunk/lib/Analysis/ScopInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/ScopInfo.cpp?rev=237779&r1=237778&r2=237779&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/ScopInfo.cpp (original)
+++ polly/trunk/lib/Analysis/ScopInfo.cpp Wed May 20 03:05:31 2015
@@ -327,27 +327,31 @@ static __isl_give isl_set *addRangeBound
     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 &t
     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.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));
 }

Modified: polly/trunk/lib/CodeGen/IslExprBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGen/IslExprBuilder.cpp?rev=237779&r1=237778&r2=237779&view=diff
==============================================================================
--- polly/trunk/lib/CodeGen/IslExprBuilder.cpp (original)
+++ polly/trunk/lib/CodeGen/IslExprBuilder.cpp Wed May 20 03:05:31 2015
@@ -115,8 +115,8 @@ Value *IslExprBuilder::createAccessAddre
   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;

Modified: polly/trunk/test/ScopInfo/delinearize-together-all-data-refs.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/ScopInfo/delinearize-together-all-data-refs.ll?rev=237779&r1=237778&r2=237779&view=diff
==============================================================================
--- polly/trunk/test/ScopInfo/delinearize-together-all-data-refs.ll (original)
+++ polly/trunk/test/ScopInfo/delinearize-together-all-data-refs.ll Wed May 20 03:05:31 2015
@@ -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] };
 

Modified: polly/trunk/test/ScopInfo/simple_loop_1.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/ScopInfo/simple_loop_1.ll?rev=237779&r1=237778&r2=237779&view=diff
==============================================================================
--- polly/trunk/test/ScopInfo/simple_loop_1.ll (original)
+++ polly/trunk/test/ScopInfo/simple_loop_1.ll Wed May 20 03:05:31 2015
@@ -26,6 +26,9 @@ return:
 
 ; CHECK: Assumed Context:
 ; CHECK:   {  :  }
+; CHECK: Arrays {
+; CHECK:     i64 MemRef_a[*][8] // Element size 8
+; CHECK: }
 
 ; CHECK:  Stmt_bb
 ; CHECK:        Domain :=





More information about the llvm-commits mailing list