Memaccess: Codegeneration for a simple access function change

Code is generated for a simple access function change imported
from JSCOP file. An access of A[i] is changed to A[0]. The code
for A[0] is generated directly without refering to isl function calls.

llvm-svn: 136789
This commit is contained in:
Raghesh Aloor 2011-08-03 17:02:50 +00:00
parent 73b8551188
commit 62b13120ee
6 changed files with 125 additions and 1 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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