[llvm-commits] [polly] r137603 - in /polly/trunk: lib/Analysis/ScopInfo.cpp lib/CodeGeneration.cpp lib/Exchange/JSONExporter.cpp test/CodeGen/MemAccess/memaccess_codegen_constant_offset.c test/CodeGen/MemAccess/memaccess_codegen_constant_offset.ll test/CodeGen/MemAccess/memaccess_codegen_constant_offset___%for.cond---%for.end.jscop test/CodeGen/MemAccess/memaccess_codegen_constant_offset___%for.cond---%for.end.jscop.transformed
Raghesh Aloor
raghesh.a at gmail.com
Sun Aug 14 19:33:39 PDT 2011
Author: raghesh
Date: Sun Aug 14 21:33:39 2011
New Revision: 137603
URL: http://llvm.org/viewvc/llvm-project?rev=137603&view=rev
Log:
Memaccess: Code generation for constant access function change
Support for generating code for an access function change which is
a constant is added.
Added:
polly/trunk/test/CodeGen/MemAccess/memaccess_codegen_constant_offset.c
polly/trunk/test/CodeGen/MemAccess/memaccess_codegen_constant_offset.ll
polly/trunk/test/CodeGen/MemAccess/memaccess_codegen_constant_offset___%for.cond---%for.end.jscop
polly/trunk/test/CodeGen/MemAccess/memaccess_codegen_constant_offset___%for.cond---%for.end.jscop.transformed
Modified:
polly/trunk/lib/Analysis/ScopInfo.cpp
polly/trunk/lib/CodeGeneration.cpp
polly/trunk/lib/Exchange/JSONExporter.cpp
Modified: polly/trunk/lib/Analysis/ScopInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/ScopInfo.cpp?rev=137603&r1=137602&r2=137603&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/ScopInfo.cpp (original)
+++ polly/trunk/lib/Analysis/ScopInfo.cpp Sun Aug 14 21:33:39 2011
@@ -112,6 +112,7 @@
MemoryAccess::~MemoryAccess() {
isl_map_free(getAccessFunction());
+ isl_map_free(newAccessRelation);
}
static void replace(std::string& str, const std::string& find,
Modified: polly/trunk/lib/CodeGeneration.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGeneration.cpp?rev=137603&r1=137602&r2=137603&view=diff
==============================================================================
--- polly/trunk/lib/CodeGeneration.cpp (original)
+++ polly/trunk/lib/CodeGeneration.cpp Sun Aug 14 21:33:39 2011
@@ -314,13 +314,44 @@
return vector;
}
+ /// @brief Get the memory access offset to be added to the base address
+ std::vector <Value*> getMemoryAccessIndex(isl_map *accessRelation,
+ Value *baseAddr) {
+ isl_int offsetMPZ;
+ isl_int_init(offsetMPZ);
+
+ assert((isl_map_dim(accessRelation, isl_dim_out) == 1)
+ && "Only single dimensional access functions supported");
+
+ if (isl_map_plain_is_fixed(accessRelation, isl_dim_out,
+ 0, &offsetMPZ) == -1)
+ errs() << "Only fixed value access functions supported\n";
+
+ // Convert the offset from MPZ to Value*.
+ APInt offset = APInt_from_MPZ(offsetMPZ);
+ Value *offsetValue = ConstantInt::get(Builder.getContext(), offset);
+ PointerType *baseAddrType = dyn_cast<PointerType>(baseAddr->getType());
+ Type *arrayType = baseAddrType->getElementType();
+ Type *arrayElementType = dyn_cast<ArrayType>(arrayType)->getElementType();
+ offsetValue = Builder.CreateSExtOrBitCast(offsetValue, arrayElementType);
+
+ std::vector<Value*> indexArray;
+ Value *nullValue = Constant::getNullValue(arrayElementType);
+ indexArray.push_back(nullValue);
+ indexArray.push_back(offsetValue);
+
+ isl_int_clear(offsetMPZ);
+ return indexArray;
+ }
+
/// @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_");
+ std::vector<Value*> indexArray = getMemoryAccessIndex(newAccessRelation,
+ baseAddr);
+ Value *newOperand = Builder.CreateGEP(baseAddr, indexArray,
+ "p_newarrayidx_");
return newOperand;
}
@@ -328,7 +359,12 @@
Value *generateLocationAccessed(const Instruction *Inst,
const Value *pointer, ValueMapT &BBMap ) {
MemoryAccess &access = statement.getAccessFor(Inst);
+ isl_map *currentAccessRelation = access.getAccessFunction();
isl_map *newAccessRelation = access.getNewAccessFunction();
+
+ assert(isl_map_has_equal_dim(currentAccessRelation, newAccessRelation)
+ && "Current and new access function dimensions differ");
+
if (!newAccessRelation) {
Value *newPointer = getOperand(pointer, BBMap);
return newPointer;
Modified: polly/trunk/lib/Exchange/JSONExporter.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Exchange/JSONExporter.cpp?rev=137603&r1=137602&r2=137603&view=diff
==============================================================================
--- polly/trunk/lib/Exchange/JSONExporter.cpp (original)
+++ polly/trunk/lib/Exchange/JSONExporter.cpp Sun Aug 14 21:33:39 2011
@@ -269,6 +269,15 @@
isl_map *newAccessMap = isl_map_read_from_str(S->getCtx(),
accesses.asCString(), -1);
isl_map *currentAccessMap = (*MI)->getAccessFunction();
+ if (!isl_map_has_equal_dim(currentAccessMap, newAccessMap)) {
+ errs() << "JScop file contains access function with incompatible "
+ << "dimensions\n";
+ return false;
+ }
+ if (isl_map_dim(newAccessMap, isl_dim_out) != 1) {
+ errs() << "New access map in JScop file should be single dimensional\n";
+ return false;
+ }
if (!isl_map_is_equal(newAccessMap, currentAccessMap)) {
// Statistics.
++NewAccessMapFound;
Added: polly/trunk/test/CodeGen/MemAccess/memaccess_codegen_constant_offset.c
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/CodeGen/MemAccess/memaccess_codegen_constant_offset.c?rev=137603&view=auto
==============================================================================
--- polly/trunk/test/CodeGen/MemAccess/memaccess_codegen_constant_offset.c (added)
+++ polly/trunk/test/CodeGen/MemAccess/memaccess_codegen_constant_offset.c Sun Aug 14 21:33:39 2011
@@ -0,0 +1,8 @@
+int A[100];
+
+int memaccess_codegen_constant_offset() {
+ for (int i = 0; i < 12; i++)
+ A[13] = A[i] + A[i-1];
+
+ return 0;
+}
Added: polly/trunk/test/CodeGen/MemAccess/memaccess_codegen_constant_offset.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/CodeGen/MemAccess/memaccess_codegen_constant_offset.ll?rev=137603&view=auto
==============================================================================
--- polly/trunk/test/CodeGen/MemAccess/memaccess_codegen_constant_offset.ll (added)
+++ polly/trunk/test/CodeGen/MemAccess/memaccess_codegen_constant_offset.ll Sun Aug 14 21:33:39 2011
@@ -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_constant_offset.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"
+
+ at A = common global [100 x i32] zeroinitializer, align 4
+
+define i32 @memaccess_codegen_constant_offset() 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 10)
Added: polly/trunk/test/CodeGen/MemAccess/memaccess_codegen_constant_offset___%for.cond---%for.end.jscop
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/CodeGen/MemAccess/memaccess_codegen_constant_offset___%25for.cond---%25for.end.jscop?rev=137603&view=auto
==============================================================================
--- polly/trunk/test/CodeGen/MemAccess/memaccess_codegen_constant_offset___%for.cond---%for.end.jscop (added)
+++ polly/trunk/test/CodeGen/MemAccess/memaccess_codegen_constant_offset___%for.cond---%for.end.jscop Sun Aug 14 21:33:39 2011
@@ -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] }"
+ }
+ ]
+}
Added: polly/trunk/test/CodeGen/MemAccess/memaccess_codegen_constant_offset___%for.cond---%for.end.jscop.transformed
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/CodeGen/MemAccess/memaccess_codegen_constant_offset___%25for.cond---%25for.end.jscop.transformed?rev=137603&view=auto
==============================================================================
--- polly/trunk/test/CodeGen/MemAccess/memaccess_codegen_constant_offset___%for.cond---%for.end.jscop.transformed (added)
+++ polly/trunk/test/CodeGen/MemAccess/memaccess_codegen_constant_offset___%for.cond---%for.end.jscop.transformed Sun Aug 14 21:33:39 2011
@@ -0,0 +1,25 @@
+{
+ "context" : "{ [] }",
+ "name" : "for.cond => for.end",
+ "statements" : [
+ {
+ "accesses" : [
+ {
+ "kind" : "read",
+ "relation" : "{ Stmt_for_body[i0] -> MemRef_A[10] }"
+ },
+ {
+ "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] }"
+ }
+ ]
+}
More information about the llvm-commits
mailing list