diff options
6 files changed, 125 insertions, 1 deletions
diff --git a/polly/include/polly/ScopInfo.h b/polly/include/polly/ScopInfo.h index 10a3b078b42..1e4d79eefc7 100755 --- a/polly/include/polly/ScopInfo.h +++ b/polly/include/polly/ScopInfo.h @@ -130,6 +130,11 @@ public: return BaseName; } + /// @brief Get the new access function imported from JSCOP file + isl_map *getNewAccessFunction() { + return newAccessRelation; + } + /// @brief Get the stride of this memory access in the specified domain /// subset. isl_set *getStride(const isl_set *domainSubset) const; diff --git a/polly/lib/CodeGeneration.cpp b/polly/lib/CodeGeneration.cpp index 9f68aedda6f..48428b1e443 100644 --- a/polly/lib/CodeGeneration.cpp +++ b/polly/lib/CodeGeneration.cpp @@ -314,9 +314,36 @@ public: return vector; } + /// @brief Get the new operand address according to the changed access in + /// JSCOP file. + Value *getNewAccessOperand(isl_map *newAccessRelation, Value *baseAddr, + const Value *OldOperand, ValueMapT &BBMap) { + unsigned accessIdx = 0; + Value *newOperand = Builder.CreateStructGEP(baseAddr, + accessIdx, "p_newarrayidx_"); + return newOperand; + } + + /// @brief Generate the operand address + Value *generateLocationAccessed(const Instruction *Inst, + const Value *pointer, ValueMapT &BBMap ) { + MemoryAccess &Access = statement.getAccessFor(Inst); + isl_map *newAccessRelation = Access.getNewAccessFunction(); + if (!newAccessRelation) { + Value *newPointer = getOperand(pointer, BBMap); + return newPointer; + } + + Value *baseAddr = const_cast<Value*>(Access.getBaseAddr()); + Value *newPointer = getNewAccessOperand(newAccessRelation, baseAddr, + pointer, BBMap); + return newPointer; + } + Value *generateScalarLoad(const LoadInst *load, ValueMapT &BBMap) { const Value *pointer = load->getPointerOperand(); - Value *newPointer = getOperand(pointer, BBMap); + const Instruction *Inst = dyn_cast<Instruction>(load); + Value *newPointer = generateLocationAccessed(Inst, pointer, BBMap); Value *scalarLoad = Builder.CreateLoad(newPointer, load->getNameStr() + "_p_scalar_"); return scalarLoad; diff --git a/polly/test/CodeGen/MemAccess/memaccess_codegen_simple.c b/polly/test/CodeGen/MemAccess/memaccess_codegen_simple.c new file mode 100644 index 00000000000..b6ddf9d2128 --- /dev/null +++ b/polly/test/CodeGen/MemAccess/memaccess_codegen_simple.c @@ -0,0 +1,8 @@ +int A[100]; + +int memaccess_codegen_simple () { + for (int i = 0; i < 12; i++) + A[13] = A[i] + A[i-1]; + + return 0; +} diff --git a/polly/test/CodeGen/MemAccess/memaccess_codegen_simple.ll b/polly/test/CodeGen/MemAccess/memaccess_codegen_simple.ll new file mode 100644 index 00000000000..8e980c51206 --- /dev/null +++ b/polly/test/CodeGen/MemAccess/memaccess_codegen_simple.ll @@ -0,0 +1,34 @@ +;RUN: opt %loadPolly -polly-import-jscop -polly-import-jscop-dir=`dirname %s` -polly-import-jscop-postfix=transformed -polly-codegen -instnamer %s -S | FileCheck %s +; ModuleID = 'memaccess_codegen_simple.ll' +target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32" +target triple = "i386-pc-linux-gnu" + +@A = common global [100 x i32] zeroinitializer, align 4 + +define i32 @memaccess_codegen_simple() nounwind { +entry: + br label %for.cond + +for.cond: ; preds = %for.inc, %entry + %tmp1 = phi i32 [ 0, %entry ], [ %inc, %for.inc ] + %tmp = add i32 %tmp1, -1 + %arrayidx4 = getelementptr [100 x i32]* @A, i32 0, i32 %tmp + %arrayidx = getelementptr [100 x i32]* @A, i32 0, i32 %tmp1 + %exitcond = icmp ne i32 %tmp1, 12 + br i1 %exitcond, label %for.body, label %for.end + +for.body: ; preds = %for.cond + %tmp2 = load i32* %arrayidx, align 4 + %tmp5 = load i32* %arrayidx4, align 4 + %add = add nsw i32 %tmp2, %tmp5 + store i32 %add, i32* getelementptr inbounds ([100 x i32]* @A, i32 0, i32 13), align 4 + br label %for.inc + +for.inc: ; preds = %for.body + %inc = add nsw i32 %tmp1, 1 + br label %for.cond + +for.end: ; preds = %for.cond + ret i32 0 +} +; CHECK: load i32* getelementptr inbounds ([100 x i32]* @A, i32 0, i32 0) diff --git a/polly/test/CodeGen/MemAccess/memaccess_codegen_simple___%for.cond---%for.end.jscop b/polly/test/CodeGen/MemAccess/memaccess_codegen_simple___%for.cond---%for.end.jscop new file mode 100644 index 00000000000..bf39e59d17c --- /dev/null +++ b/polly/test/CodeGen/MemAccess/memaccess_codegen_simple___%for.cond---%for.end.jscop @@ -0,0 +1,25 @@ +{ + "context" : "{ [] }", + "name" : "for.cond => for.end", + "statements" : [ + { + "accesses" : [ + { + "kind" : "read", + "relation" : "{ Stmt_for_body[i0] -> MemRef_A[i0] }" + }, + { + "kind" : "read", + "relation" : "{ Stmt_for_body[i0] -> MemRef_A[-1 + i0] }" + }, + { + "kind" : "write", + "relation" : "{ Stmt_for_body[i0] -> MemRef_A[13] }" + } + ], + "domain" : "{ Stmt_for_body[i0] : i0 >= 0 and i0 <= 11 }", + "name" : "Stmt_for_body", + "schedule" : "{ Stmt_for_body[i0] -> scattering[0, i0, 0] }" + } + ] +} diff --git a/polly/test/CodeGen/MemAccess/memaccess_codegen_simple___%for.cond---%for.end.jscop.transformed b/polly/test/CodeGen/MemAccess/memaccess_codegen_simple___%for.cond---%for.end.jscop.transformed new file mode 100644 index 00000000000..a2bed3085d6 --- /dev/null +++ b/polly/test/CodeGen/MemAccess/memaccess_codegen_simple___%for.cond---%for.end.jscop.transformed @@ -0,0 +1,25 @@ +{ + "context" : "{ [] }", + "name" : "for.cond => for.end", + "statements" : [ + { + "accesses" : [ + { + "kind" : "read", + "relation" : "{ Stmt_for_body[i0] -> MemRef_A[0] }" + }, + { + "kind" : "read", + "relation" : "{ Stmt_for_body[i0] -> MemRef_A[-1 + i0] }" + }, + { + "kind" : "write", + "relation" : "{ Stmt_for_body[i0] -> MemRef_A[13] }" + } + ], + "domain" : "{ Stmt_for_body[i0] : i0 >= 0 and i0 <= 11 }", + "name" : "Stmt_for_body", + "schedule" : "{ Stmt_for_body[i0] -> scattering[0, i0, 0] }" + } + ] +} |

