summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Grosser <tobias@grosser.es>2015-12-15 23:49:53 +0000
committerTobias Grosser <tobias@grosser.es>2015-12-15 23:49:53 +0000
commit092147724853b63036cf98fc9948903d4db383c4 (patch)
treef136dc76bd5f6197942cad26ea0897229435f545
parent028685a5db1163ab513342142488a7d32d160d5f (diff)
downloadbcm5719-llvm-092147724853b63036cf98fc9948903d4db383c4.tar.gz
bcm5719-llvm-092147724853b63036cf98fc9948903d4db383c4.zip
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. llvm-svn: 255713
-rw-r--r--polly/include/polly/ScopInfo.h27
-rw-r--r--polly/lib/CodeGen/BlockGenerators.cpp2
-rw-r--r--polly/test/Isl/CodeGen/MemAccess/update_access_functions.ll46
-rw-r--r--polly/test/Isl/CodeGen/MemAccess/update_access_functions___%loop1---%exit.jscop47
-rw-r--r--polly/test/Isl/CodeGen/MemAccess/update_access_functions___%loop1---%exit.jscop.transformed47
5 files changed, 168 insertions, 1 deletions
diff --git a/polly/include/polly/ScopInfo.h b/polly/include/polly/ScopInfo.h
index caf5247cf10..130e4360a15 100644
--- a/polly/include/polly/ScopInfo.h
+++ b/polly/include/polly/ScopInfo.h
@@ -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);
diff --git a/polly/lib/CodeGen/BlockGenerators.cpp b/polly/lib/CodeGen/BlockGenerators.cpp
index 17305da9b59..b4364df7fda 100644
--- a/polly/lib/CodeGen/BlockGenerators.cpp
+++ b/polly/lib/CodeGen/BlockGenerators.cpp
@@ -164,7 +164,7 @@ void BlockGenerator::copyInstScalar(ScopStmt &Stmt, Instruction *Inst,
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());
diff --git a/polly/test/Isl/CodeGen/MemAccess/update_access_functions.ll b/polly/test/Isl/CodeGen/MemAccess/update_access_functions.ll
new file mode 100644
index 00000000000..33eba60e825
--- /dev/null
+++ b/polly/test/Isl/CodeGen/MemAccess/update_access_functions.ll
@@ -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
+}
diff --git a/polly/test/Isl/CodeGen/MemAccess/update_access_functions___%loop1---%exit.jscop b/polly/test/Isl/CodeGen/MemAccess/update_access_functions___%loop1---%exit.jscop
new file mode 100644
index 00000000000..733280104a6
--- /dev/null
+++ b/polly/test/Isl/CodeGen/MemAccess/update_access_functions___%loop1---%exit.jscop
@@ -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] }"
+ }
+ ]
+}
diff --git a/polly/test/Isl/CodeGen/MemAccess/update_access_functions___%loop1---%exit.jscop.transformed b/polly/test/Isl/CodeGen/MemAccess/update_access_functions___%loop1---%exit.jscop.transformed
new file mode 100644
index 00000000000..845af31e7e2
--- /dev/null
+++ b/polly/test/Isl/CodeGen/MemAccess/update_access_functions___%loop1---%exit.jscop.transformed
@@ -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] }"
+ }
+ ]
+}
OpenPOWER on IntegriCloud