[polly] r252200 - ScopInfo: Allocate globally unique memory access identifiers

Tobias Grosser via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 5 12:15:37 PST 2015


Author: grosser
Date: Thu Nov  5 14:15:37 2015
New Revision: 252200

URL: http://llvm.org/viewvc/llvm-project?rev=252200&view=rev
Log:
ScopInfo: Allocate globally unique memory access identifiers

Before this commit memory reference identifiers have only been unique per
basic block, but not per (non-affine) ScopStmt. This commit now uses the
MemoryAccess base pointer to uniquely identify each Memory access.

Added:
    polly/trunk/test/Isl/CodeGen/non-affine-update.ll
    polly/trunk/test/Isl/CodeGen/non-affine-update___%bb1---%bb15.jscop
Modified:
    polly/trunk/include/polly/ScopInfo.h
    polly/trunk/lib/Analysis/ScopInfo.cpp

Modified: polly/trunk/include/polly/ScopInfo.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/ScopInfo.h?rev=252200&r1=252199&r2=252200&view=diff
==============================================================================
--- polly/trunk/include/polly/ScopInfo.h (original)
+++ polly/trunk/include/polly/ScopInfo.h Thu Nov  5 14:15:37 2015
@@ -514,8 +514,6 @@ public:
   ///
   /// @param Stmt       The parent statement.
   /// @param AccessInst The instruction doing the access.
-  /// @param Id         Identifier that is guranteed to be unique within the
-  ///                   same ScopStmt.
   /// @param BaseAddr   The accessed array's address.
   /// @param ElemBytes  Number of accessed bytes.
   /// @param AccType    Whether read or write access.
@@ -524,11 +522,10 @@ public:
   /// @param Subscripts Subscipt expressions
   /// @param Sizes      Dimension lengths of the accessed array.
   /// @param BaseName   Name of the acessed array.
-  MemoryAccess(ScopStmt *Stmt, Instruction *AccessInst, __isl_take isl_id *Id,
-               AccessType Type, Value *BaseAddress, unsigned ElemBytes,
-               bool Affine, ArrayRef<const SCEV *> Subscripts,
-               ArrayRef<const SCEV *> Sizes, Value *AccessValue,
-               AccessOrigin Origin, StringRef BaseName);
+  MemoryAccess(ScopStmt *Stmt, Instruction *AccessInst, AccessType Type,
+               Value *BaseAddress, unsigned ElemBytes, bool Affine,
+               ArrayRef<const SCEV *> Subscripts, ArrayRef<const SCEV *> Sizes,
+               Value *AccessValue, AccessOrigin Origin, StringRef BaseName);
   ~MemoryAccess();
 
   /// @brief Get the type of a memory access.

Modified: polly/trunk/lib/Analysis/ScopInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/ScopInfo.cpp?rev=252200&r1=252199&r2=252200&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/ScopInfo.cpp (original)
+++ polly/trunk/lib/Analysis/ScopInfo.cpp Thu Nov  5 14:15:37 2015
@@ -641,17 +641,21 @@ void MemoryAccess::buildAccessRelation(c
 }
 
 MemoryAccess::MemoryAccess(ScopStmt *Stmt, Instruction *AccessInst,
-                           __isl_take isl_id *Id, AccessType Type,
-                           Value *BaseAddress, unsigned ElemBytes, bool Affine,
+                           AccessType Type, Value *BaseAddress,
+                           unsigned ElemBytes, bool Affine,
                            ArrayRef<const SCEV *> Subscripts,
                            ArrayRef<const SCEV *> Sizes, Value *AccessValue,
                            AccessOrigin Origin, StringRef BaseName)
-    : Id(Id), Origin(Origin), AccType(Type), RedType(RT_NONE), Statement(Stmt),
+    : Origin(Origin), AccType(Type), RedType(RT_NONE), Statement(Stmt),
       BaseAddr(BaseAddress), BaseName(BaseName), ElemBytes(ElemBytes),
       Sizes(Sizes.begin(), Sizes.end()), AccessInstruction(AccessInst),
       AccessValue(AccessValue), IsAffine(Affine),
       Subscripts(Subscripts.begin(), Subscripts.end()), AccessRelation(nullptr),
-      NewAccessRelation(nullptr) {}
+      NewAccessRelation(nullptr) {
+
+  std::string IdName = "__polly_array_ref";
+  Id = isl_id_alloc(Stmt->getParent()->getIslCtx(), IdName.c_str(), this);
+}
 
 void MemoryAccess::realignParams() {
   isl_space *ParamSpace = Statement->getParent()->getParamSpace();
@@ -3636,20 +3640,15 @@ void ScopInfo::addMemoryAccess(BasicBloc
     return;
 
   AccFuncSetType &AccList = AccFuncMap[BB];
-  size_t Identifier = AccList.size();
-
   Value *BaseAddr = BaseAddress;
   std::string BaseName = getIslCompatibleName("MemRef_", BaseAddr, "");
 
-  std::string IdName = "__polly_array_ref_" + std::to_string(Identifier);
-  isl_id *Id = isl_id_alloc(ctx, IdName.c_str(), nullptr);
-
   bool isApproximated =
       Stmt->isRegionStmt() && (Stmt->getRegion()->getEntry() != BB);
   if (isApproximated && Type == MemoryAccess::MUST_WRITE)
     Type = MemoryAccess::MAY_WRITE;
 
-  AccList.emplace_back(Stmt, Inst, Id, Type, BaseAddress, ElemBytes, Affine,
+  AccList.emplace_back(Stmt, Inst, Type, BaseAddress, ElemBytes, Affine,
                        Subscripts, Sizes, AccessValue, Origin, BaseName);
   Stmt->addAccess(&AccList.back());
 }

Added: polly/trunk/test/Isl/CodeGen/non-affine-update.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/CodeGen/non-affine-update.ll?rev=252200&view=auto
==============================================================================
--- polly/trunk/test/Isl/CodeGen/non-affine-update.ll (added)
+++ polly/trunk/test/Isl/CodeGen/non-affine-update.ll Thu Nov  5 14:15:37 2015
@@ -0,0 +1,69 @@
+; RUN: opt %loadPolly -polly-import-jscop -polly-import-jscop-dir=%S \
+; RUN:     -polly-codegen -S < %s | FileCheck %s
+;
+;    void non-affine-update(double A[], double C[], double B[]) {
+;      for (int i = 0; i < 10; i++) {
+;        if (A[i] >= 6)
+;          B[i] += 42;
+;        else
+;          C[i] += 3;
+;      }
+;    }
+
+; Verify that all changed memory access functions are corectly code generated.
+; At some point this did not work due to memory access identifiers not being
+; unique within non-affine scop statements.
+
+; CHECK: polly.stmt.bb2:
+; CHECK:   %scevgep = getelementptr double, double* %A, i64 %polly.indvar
+
+; CHECK: polly.stmt.bb9:
+; CHECK:   %polly.access.C{{.*}} = getelementptr double, double* %C, i64 42
+; CHECK:   %polly.access.C{{.*}} = getelementptr double, double* %C, i64 42
+
+; CHECK: polly.stmt.bb5:
+; CHECK:   %polly.access.B{{.*}} = getelementptr double, double* %B, i64 113
+; CHECK:   %polly.access.B{{.*}} = getelementptr double, double* %B, i64 113
+
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+
+define void @non-affine-update(double* %A, double* %C, double* %B) {
+bb:
+  br label %bb1
+
+bb1:                                              ; preds = %bb14, %bb
+  %indvars.iv = phi i64 [ %indvars.iv.next, %bb14 ], [ 0, %bb ]
+  %exitcond = icmp ne i64 %indvars.iv, 10
+  br i1 %exitcond, label %bb2, label %bb15
+
+bb2:                                              ; preds = %bb1
+  %tmp = getelementptr inbounds double, double* %A, i64 %indvars.iv
+  %tmp3 = load double, double* %tmp, align 8
+  %tmp4 = fcmp ult double %tmp3, 6.000000e+00
+  br i1 %tmp4, label %bb9, label %bb5
+
+bb5:                                              ; preds = %bb2
+  %tmp6 = getelementptr inbounds double, double* %B, i64 %indvars.iv
+  %tmp7 = load double, double* %tmp6, align 8
+  %tmp8 = fadd double %tmp7, 4.200000e+01
+  store double %tmp8, double* %tmp6, align 8
+  br label %bb13
+
+bb9:                                              ; preds = %bb2
+  %tmp10 = getelementptr inbounds double, double* %C, i64 %indvars.iv
+  %tmp11 = load double, double* %tmp10, align 8
+  %tmp12 = fadd double %tmp11, 3.000000e+00
+  store double %tmp12, double* %tmp10, align 8
+  br label %bb13
+
+bb13:                                             ; preds = %bb9, %bb5
+  br label %bb14
+
+bb14:                                             ; preds = %bb13
+  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
+  br label %bb1
+
+bb15:                                             ; preds = %bb1
+  ret void
+}

Added: polly/trunk/test/Isl/CodeGen/non-affine-update___%bb1---%bb15.jscop
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/CodeGen/non-affine-update___%25bb1---%25bb15.jscop?rev=252200&view=auto
==============================================================================
--- polly/trunk/test/Isl/CodeGen/non-affine-update___%bb1---%bb15.jscop (added)
+++ polly/trunk/test/Isl/CodeGen/non-affine-update___%bb1---%bb15.jscop Thu Nov  5 14:15:37 2015
@@ -0,0 +1,33 @@
+{
+   "context" : "{  :  }",
+   "name" : "bb1 => bb15",
+   "statements" : [
+      {
+         "accesses" : [
+            {
+               "kind" : "read",
+               "relation" : "{ Stmt_bb2__TO__bb13[i0] -> MemRef_A[i0] }"
+            },
+            {
+               "kind" : "read",
+               "relation" : "{ Stmt_bb2__TO__bb13[i0] -> MemRef_C[42] }"
+            },
+            {
+               "kind" : "write",
+               "relation" : "{ Stmt_bb2__TO__bb13[i0] -> MemRef_C[42] }"
+            },
+            {
+               "kind" : "read",
+               "relation" : "{ Stmt_bb2__TO__bb13[i0] -> MemRef_B[113] }"
+            },
+            {
+               "kind" : "write",
+               "relation" : "{ Stmt_bb2__TO__bb13[i0] -> MemRef_B[113] }"
+            }
+         ],
+         "domain" : "{ Stmt_bb2__TO__bb13[i0] : i0 <= 9 and i0 >= 0 }",
+         "name" : "Stmt_bb2__TO__bb13",
+         "schedule" : "{ Stmt_bb2__TO__bb13[i0] -> [i0] }"
+      }
+   ]
+}




More information about the llvm-commits mailing list