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
This commit is contained in:
Tobias Grosser 2015-12-15 23:49:53 +00:00
parent 028685a5db
commit 0921477248
5 changed files with 168 additions and 1 deletions

View File

@ -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);

View File

@ -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());

View File

@ -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
}

View File

@ -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] }"
}
]
}

View File

@ -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] }"
}
]
}