[polly] r255713 - ScopInfo: Look up first (and only) array access

Tobias Grosser via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 15 15:49:54 PST 2015


Author: grosser
Date: Tue Dec 15 17:49:53 2015
New Revision: 255713

URL: http://llvm.org/viewvc/llvm-project?rev=255713&view=rev
Log:
ScopInfo: Look up first (and only) array access

When rewriting the access functions of load/store statements, we are only
interested in the actual array memory location. The current code just took
the very first memory access, which could be a scalar or an array access. As
a result, we failed to update access functions even though this was requested
via .jscop.

Added:
    polly/trunk/test/Isl/CodeGen/MemAccess/update_access_functions.ll
    polly/trunk/test/Isl/CodeGen/MemAccess/update_access_functions___%loop1---%exit.jscop
    polly/trunk/test/Isl/CodeGen/MemAccess/update_access_functions___%loop1---%exit.jscop.transformed
Modified:
    polly/trunk/include/polly/ScopInfo.h
    polly/trunk/lib/CodeGen/BlockGenerators.cpp

Modified: polly/trunk/include/polly/ScopInfo.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/ScopInfo.h?rev=255713&r1=255712&r2=255713&view=diff
==============================================================================
--- polly/trunk/include/polly/ScopInfo.h (original)
+++ polly/trunk/include/polly/ScopInfo.h Tue Dec 15 17:49:53 2015
@@ -979,6 +979,33 @@ public:
     return *MA;
   }
 
+  /// @brief Return the only array access for @p Inst.
+  ///
+  /// @param Inst The instruction for which to look up the access.
+  /// @returns The unique array memory access related to Inst.
+  MemoryAccess &getArrayAccessFor(const Instruction *Inst) const {
+    auto It = InstructionToAccess.find(Inst);
+    assert(It != InstructionToAccess.end() &&
+           "No memory accesses found for instruction");
+    auto *Accesses = It->getSecond();
+
+    assert(Accesses && "No memory accesses found for instruction");
+
+    MemoryAccess *ArrayAccess = nullptr;
+
+    for (auto Access : *Accesses) {
+      if (!Access->isArrayKind())
+        continue;
+
+      assert(!ArrayAccess && "More then one array access for instruction");
+
+      ArrayAccess = Access;
+    }
+
+    assert(ArrayAccess && "No array access found for instruction!");
+    return *ArrayAccess;
+  }
+
   /// @brief Return the __first__ (scalar) memory access for @p Inst if any.
   MemoryAccess *lookupAccessFor(const Instruction *Inst) const {
     auto It = InstructionToAccess.find(Inst);

Modified: polly/trunk/lib/CodeGen/BlockGenerators.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGen/BlockGenerators.cpp?rev=255713&r1=255712&r2=255713&view=diff
==============================================================================
--- polly/trunk/lib/CodeGen/BlockGenerators.cpp (original)
+++ polly/trunk/lib/CodeGen/BlockGenerators.cpp Tue Dec 15 17:49:53 2015
@@ -164,7 +164,7 @@ void BlockGenerator::copyInstScalar(Scop
 Value *BlockGenerator::generateLocationAccessed(
     ScopStmt &Stmt, const Instruction *Inst, Value *Pointer, ValueMapT &BBMap,
     LoopToScevMapT &LTS, isl_id_to_ast_expr *NewAccesses) {
-  const MemoryAccess &MA = Stmt.getAccessFor(Inst);
+  const MemoryAccess &MA = Stmt.getArrayAccessFor(Inst);
 
   isl_ast_expr *AccessExpr = isl_id_to_ast_expr_get(NewAccesses, MA.getId());
 

Added: polly/trunk/test/Isl/CodeGen/MemAccess/update_access_functions.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/CodeGen/MemAccess/update_access_functions.ll?rev=255713&view=auto
==============================================================================
--- polly/trunk/test/Isl/CodeGen/MemAccess/update_access_functions.ll (added)
+++ polly/trunk/test/Isl/CodeGen/MemAccess/update_access_functions.ll Tue Dec 15 17:49:53 2015
@@ -0,0 +1,46 @@
+; RUN: opt %loadPolly -polly-import-jscop -polly-import-jscop-dir=%S \
+; RUN:                -polly-import-jscop-postfix=transformed -polly-codegen \
+; RUN:                 < %s -S | FileCheck %s
+
+; CHECK: polly.stmt.loop2:
+; CHECK-NEXT:   %polly.access.A = getelementptr double, double* %A, i64 42
+; CHECK-NEXT:   %val_p_scalar_ = load double, double* %polly.access.A
+
+; CHECK: polly.stmt.loop3:
+; CHECK-NEXT:   %val.s2a.reload = load double, double* %val.s2a
+; CHECK-NEXT:   %polly.access.A20 = getelementptr double, double* %A, i64 42
+; CHECK-NEXT:   store double %val.s2a.reload, double* %polly.access.A20
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+
+define void @update_access_functions(i64 %arg, double* %A) {
+bb3:
+  br label %loop1
+
+loop1:
+  %indvar = phi i64 [ %indvar.next, %loop1 ], [ 1, %bb3 ]
+  %ptr1 = getelementptr inbounds double, double* %A, i64 %indvar
+  store double 42.0, double* %ptr1, align 8
+  %indvar.next = add nuw nsw i64 %indvar, 1
+  %cmp = icmp ne i64 %indvar.next, %arg
+  br i1 %cmp, label %loop1, label %loop2
+
+loop2:
+  %indvar.2 = phi i64 [ %indvar.2.next, %loop2 ], [ 1, %loop1 ]
+  %ptr2 = getelementptr inbounds double, double* %A, i64 %indvar.2
+  %val = load double, double* %ptr2, align 8
+  %indvar.2.next = add nuw nsw i64 %indvar.2, 1
+  %cmp.2 = icmp ne i64 %indvar.2.next, %arg
+  br i1 %cmp.2, label %loop2, label %loop3
+
+loop3:
+  %indvar.3 = phi i64 [ %indvar.3.next, %loop3 ], [ 1, %loop2 ]
+  %ptr3 = getelementptr inbounds double, double* %A, i64 %indvar.3
+  store double %val, double* %ptr3, align 8
+  %indvar.3.next = add nuw nsw i64 %indvar.3, 1
+  %cmp.3 = icmp ne i64 %indvar.3.next, %arg
+  br i1 %cmp.3, label %loop3, label %exit
+
+exit:
+  ret void
+}

Added: polly/trunk/test/Isl/CodeGen/MemAccess/update_access_functions___%loop1---%exit.jscop
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/CodeGen/MemAccess/update_access_functions___%25loop1---%25exit.jscop?rev=255713&view=auto
==============================================================================
--- polly/trunk/test/Isl/CodeGen/MemAccess/update_access_functions___%loop1---%exit.jscop (added)
+++ polly/trunk/test/Isl/CodeGen/MemAccess/update_access_functions___%loop1---%exit.jscop Tue Dec 15 17:49:53 2015
@@ -0,0 +1,47 @@
+{
+   "context" : "[arg] -> {  : arg >= -9223372036854775808 and arg <= 9223372036854775807 }",
+   "name" : "loop1 => exit",
+   "statements" : [
+      {
+         "accesses" : [
+            {
+               "kind" : "write",
+               "relation" : "[arg] -> { Stmt_loop1[i0] -> MemRef_A[1 + i0] }"
+            }
+         ],
+         "domain" : "[arg] -> { Stmt_loop1[i0] : i0 >= 0 and i0 <= -2 + arg }",
+         "name" : "Stmt_loop1",
+         "schedule" : "[arg] -> { Stmt_loop1[i0] -> [0, i0] }"
+      },
+      {
+         "accesses" : [
+            {
+               "kind" : "read",
+               "relation" : "[arg] -> { Stmt_loop2[i0] -> MemRef_A[1 + i0] }"
+            },
+            {
+               "kind" : "write",
+               "relation" : "[arg] -> { Stmt_loop2[i0] -> MemRef_val[] }"
+            }
+         ],
+         "domain" : "[arg] -> { Stmt_loop2[i0] : i0 >= 0 and i0 <= -2 + arg }",
+         "name" : "Stmt_loop2",
+         "schedule" : "[arg] -> { Stmt_loop2[i0] -> [1, i0] }"
+      },
+      {
+         "accesses" : [
+            {
+               "kind" : "read",
+               "relation" : "[arg] -> { Stmt_loop3[i0] -> MemRef_val[] }"
+            },
+            {
+               "kind" : "write",
+               "relation" : "[arg] -> { Stmt_loop3[i0] -> MemRef_A[1 + i0] }"
+            }
+         ],
+         "domain" : "[arg] -> { Stmt_loop3[i0] : i0 >= 0 and i0 <= -2 + arg }",
+         "name" : "Stmt_loop3",
+         "schedule" : "[arg] -> { Stmt_loop3[i0] -> [2, i0] }"
+      }
+   ]
+}

Added: polly/trunk/test/Isl/CodeGen/MemAccess/update_access_functions___%loop1---%exit.jscop.transformed
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/CodeGen/MemAccess/update_access_functions___%25loop1---%25exit.jscop.transformed?rev=255713&view=auto
==============================================================================
--- polly/trunk/test/Isl/CodeGen/MemAccess/update_access_functions___%loop1---%exit.jscop.transformed (added)
+++ polly/trunk/test/Isl/CodeGen/MemAccess/update_access_functions___%loop1---%exit.jscop.transformed Tue Dec 15 17:49:53 2015
@@ -0,0 +1,47 @@
+{
+   "context" : "[arg] -> {  : arg >= -9223372036854775808 and arg <= 9223372036854775807 }",
+   "name" : "loop1 => exit",
+   "statements" : [
+      {
+         "accesses" : [
+            {
+               "kind" : "write",
+               "relation" : "[arg] -> { Stmt_loop1[i0] -> MemRef_A[1 + i0] }"
+            }
+         ],
+         "domain" : "[arg] -> { Stmt_loop1[i0] : i0 >= 0 and i0 <= -2 + arg }",
+         "name" : "Stmt_loop1",
+         "schedule" : "[arg] -> { Stmt_loop1[i0] -> [0, i0] }"
+      },
+      {
+         "accesses" : [
+            {
+               "kind" : "read",
+               "relation" : "[arg] -> { Stmt_loop2[i0] -> MemRef_A[42] }"
+            },
+            {
+               "kind" : "write",
+               "relation" : "[arg] -> { Stmt_loop2[i0] -> MemRef_val[] }"
+            }
+         ],
+         "domain" : "[arg] -> { Stmt_loop2[i0] : i0 >= 0 and i0 <= -2 + arg }",
+         "name" : "Stmt_loop2",
+         "schedule" : "[arg] -> { Stmt_loop2[i0] -> [1, i0] }"
+      },
+      {
+         "accesses" : [
+            {
+               "kind" : "read",
+               "relation" : "[arg] -> { Stmt_loop3[i0] -> MemRef_val[] }"
+            },
+            {
+               "kind" : "write",
+               "relation" : "[arg] -> { Stmt_loop3[i0] -> MemRef_A[42] }"
+            }
+         ],
+         "domain" : "[arg] -> { Stmt_loop3[i0] : i0 >= 0 and i0 <= -2 + arg }",
+         "name" : "Stmt_loop3",
+         "schedule" : "[arg] -> { Stmt_loop3[i0] -> [2, i0] }"
+      }
+   ]
+}




More information about the llvm-commits mailing list