diff options
9 files changed, 171 insertions, 0 deletions
diff --git a/polly/include/polly/ScopInfo.h b/polly/include/polly/ScopInfo.h index d8398c40fc1..10a3b078b42 100755 --- a/polly/include/polly/ScopInfo.h +++ b/polly/include/polly/ScopInfo.h @@ -95,6 +95,8 @@ private: void setBaseName(); ScopStmt *statement; + /// Updated access relation read from JSCOP file. + isl_map *newAccessRelation; public: // @brief Create an affine memory access. // @@ -143,6 +145,8 @@ public: /// @brief Get the statement that contains this memory access. ScopStmt *getStatement() const { return statement; } + /// @brief Set the updated access relation read from JSCOP file. + void setNewAccessFunction(isl_map *newAccessRelation); /// @brief Print the MemoryAccess. /// /// @param OS The output stream the MemoryAccess is printed to. diff --git a/polly/lib/Analysis/ScopInfo.cpp b/polly/lib/Analysis/ScopInfo.cpp index 41dc3eeaae7..cd3df56764a 100644 --- a/polly/lib/Analysis/ScopInfo.cpp +++ b/polly/lib/Analysis/ScopInfo.cpp @@ -156,6 +156,7 @@ isl_basic_map *MemoryAccess::createBasicAccessMap(ScopStmt *Statement) { } MemoryAccess::MemoryAccess(const SCEVAffFunc &AffFunc, ScopStmt *Statement) { + newAccessRelation = NULL; BaseAddr = AffFunc.getBaseAddr(); Type = AffFunc.isRead() ? Read : Write; statement = Statement; @@ -191,6 +192,7 @@ MemoryAccess::MemoryAccess(const SCEVAffFunc &AffFunc, ScopStmt *Statement) { } MemoryAccess::MemoryAccess(const Value *BaseAddress, ScopStmt *Statement) { + newAccessRelation = NULL; BaseAddr = BaseAddress; Type = Read; statement = Statement; @@ -334,6 +336,9 @@ bool MemoryAccess::isStrideOne(const isl_set *domainSubset) const { return isl_set_is_equal(stride, strideZero); } +void MemoryAccess::setNewAccessFunction(isl_map *newAccessRelation) { + newAccessRelation = newAccessRelation; +} //===----------------------------------------------------------------------===// void ScopStmt::buildScattering(SmallVectorImpl<unsigned> &Scatter) { diff --git a/polly/lib/Exchange/JSONExporter.cpp b/polly/lib/Exchange/JSONExporter.cpp index fb51bbf6233..56d172a74f7 100755 --- a/polly/lib/Exchange/JSONExporter.cpp +++ b/polly/lib/Exchange/JSONExporter.cpp @@ -22,6 +22,9 @@ #include "llvm/Support/system_error.h" #include "llvm/ADT/OwningPtr.h" #include "llvm/Assembly/Writer.h" +#include "llvm/ADT/Statistic.h" + +#define DEBUG_TYPE "polly-import-jscop" #include "json/reader.h" #include "json/writer.h" @@ -36,6 +39,8 @@ using namespace llvm; using namespace polly; +STATISTIC(NewAccessMapFound, "Number of updated access functions"); + namespace { static cl::opt<std::string> ImportDir("polly-import-jscop-dir", @@ -245,6 +250,31 @@ bool JSONImporter::runOnScop(Scop &scop) { Stmt->setScattering(NewScattering[Stmt]); } + int statementIdx = 0; + int memoryAccessIdx = 0; + for (Scop::iterator SI = S->begin(), SE = S->end(); SI != SE; ++SI) { + ScopStmt *Stmt = *SI; + + if (Stmt->isFinalRead()) + continue; + + for (ScopStmt::memacc_iterator MI = Stmt->memacc_begin(), + ME = Stmt->memacc_end(); MI != ME; ++MI) { + Json::Value accesses = jscop["statements"][statementIdx] + ["accesses"][memoryAccessIdx]["relation"]; + isl_map *newAccessMap = isl_map_read_from_str(S->getCtx(), + accesses.asCString(), -1); + isl_map *currentAccessMap = (*MI)->getAccessFunction(); + if (!isl_map_is_equal(newAccessMap, currentAccessMap)) { + // Statistics. + ++NewAccessMapFound; + (*MI)->setNewAccessFunction(newAccessMap); + } + memoryAccessIdx++; + } + statementIdx++; + } + return false; } diff --git a/polly/test/CodeGen/MemAccess/memaccess_simple.c b/polly/test/CodeGen/MemAccess/memaccess_simple.c new file mode 100644 index 00000000000..b9dd8f00202 --- /dev/null +++ b/polly/test/CodeGen/MemAccess/memaccess_simple.c @@ -0,0 +1,17 @@ +int A[100]; +int B[100]; + +int memaccess_simple() +{ + int i, j; + for (i = 0; i < 12; i++) { + A[i] = i; + } + + for (i = 0; i < 12; i++) { + B[i] = i; + } + + return 0; +} + diff --git a/polly/test/CodeGen/MemAccess/memaccess_simple.ll b/polly/test/CodeGen/MemAccess/memaccess_simple.ll new file mode 100644 index 00000000000..538d86150af --- /dev/null +++ b/polly/test/CodeGen/MemAccess/memaccess_simple.ll @@ -0,0 +1,47 @@ +;RUN: opt %loadPolly -polly-import-jscop -polly-import-jscop-dir=`dirname %s` -polly-import-jscop-postfix=transformed -stats %s 2>&1 | FileCheck %s +; ModuleID = 'memaccess_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 +@B = common global [100 x i32] zeroinitializer, align 4 + +define i32 @memaccess_simple() nounwind { +entry: + br label %for.cond + +for.cond: ; preds = %for.inc, %entry + %0 = phi i32 [ 0, %entry ], [ %inc, %for.inc ] + %arrayidx = getelementptr [100 x i32]* @A, i32 0, i32 %0 + %exitcond1 = icmp ne i32 %0, 12 + br i1 %exitcond1, label %for.body, label %for.end + +for.body: ; preds = %for.cond + store i32 %0, i32* %arrayidx + br label %for.inc + +for.inc: ; preds = %for.body + %inc = add nsw i32 %0, 1 + br label %for.cond + +for.end: ; preds = %for.cond + br label %for.cond4 + +for.cond4: ; preds = %for.inc11, %for.end + %1 = phi i32 [ 0, %for.end ], [ %inc13, %for.inc11 ] + %arrayidx10 = getelementptr [100 x i32]* @B, i32 0, i32 %1 + %exitcond = icmp ne i32 %1, 12 + br i1 %exitcond, label %for.body7, label %for.end14 + +for.body7: ; preds = %for.cond4 + store i32 %1, i32* %arrayidx10 + br label %for.inc11 + +for.inc11: ; preds = %for.body7 + %inc13 = add nsw i32 %1, 1 + br label %for.cond4 + +for.end14: ; preds = %for.cond4 + ret i32 0 +} +; CHECK: 2 polly-import-jscop diff --git a/polly/test/CodeGen/MemAccess/memaccess_simple___%for.cond---%for.end.jscop b/polly/test/CodeGen/MemAccess/memaccess_simple___%for.cond---%for.end.jscop new file mode 100644 index 00000000000..ccee1cbde12 --- /dev/null +++ b/polly/test/CodeGen/MemAccess/memaccess_simple___%for.cond---%for.end.jscop @@ -0,0 +1,17 @@ +{ + "context" : "{ [] }", + "name" : "for.cond => for.end", + "statements" : [ + { + "accesses" : [ + { + "kind" : "write", + "relation" : "{ Stmt_for_body[i0] -> MemRef_A[i0] }" + } + ], + "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_simple___%for.cond---%for.end.jscop.transformed b/polly/test/CodeGen/MemAccess/memaccess_simple___%for.cond---%for.end.jscop.transformed new file mode 100644 index 00000000000..a9853bd2bd8 --- /dev/null +++ b/polly/test/CodeGen/MemAccess/memaccess_simple___%for.cond---%for.end.jscop.transformed @@ -0,0 +1,17 @@ +{ + "context" : "{ [] }", + "name" : "for.cond => for.end", + "statements" : [ + { + "accesses" : [ + { + "kind" : "write", + "relation" : "{ Stmt_for_body[i0] -> MemRef_A[0] }" + } + ], + "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_simple___%for.cond4---%for.end14.jscop b/polly/test/CodeGen/MemAccess/memaccess_simple___%for.cond4---%for.end14.jscop new file mode 100644 index 00000000000..0794c01dce7 --- /dev/null +++ b/polly/test/CodeGen/MemAccess/memaccess_simple___%for.cond4---%for.end14.jscop @@ -0,0 +1,17 @@ +{ + "context" : "{ [] }", + "name" : "for.cond4 => for.end14", + "statements" : [ + { + "accesses" : [ + { + "kind" : "write", + "relation" : "{ Stmt_for_body7[i0] -> MemRef_B[i0] }" + } + ], + "domain" : "{ Stmt_for_body7[i0] : i0 >= 0 and i0 <= 11 }", + "name" : "Stmt_for_body7", + "schedule" : "{ Stmt_for_body7[i0] -> scattering[0, i0, 0] }" + } + ] +} diff --git a/polly/test/CodeGen/MemAccess/memaccess_simple___%for.cond4---%for.end14.jscop.transformed b/polly/test/CodeGen/MemAccess/memaccess_simple___%for.cond4---%for.end14.jscop.transformed new file mode 100644 index 00000000000..5df6c367512 --- /dev/null +++ b/polly/test/CodeGen/MemAccess/memaccess_simple___%for.cond4---%for.end14.jscop.transformed @@ -0,0 +1,17 @@ +{ + "context" : "{ [] }", + "name" : "for.cond4 => for.end14", + "statements" : [ + { + "accesses" : [ + { + "kind" : "write", + "relation" : "{ Stmt_for_body7[i0] -> MemRef_B[0] }" + } + ], + "domain" : "{ Stmt_for_body7[i0] : i0 >= 0 and i0 <= 11 }", + "name" : "Stmt_for_body7", + "schedule" : "{ Stmt_for_body7[i0] -> scattering[0, i0, 0] }" + } + ] +} |