Relax the condition on the jsop accesses regarding the alignment.

We restricted the new access functions to be a subset of the old one
  because we want to keep the alignment, however if the alignment is
  "not special", thus the default for the type, we can allow any access.


Differential Revision: http://reviews.llvm.org/D5680

llvm-svn: 219503
This commit is contained in:
Johannes Doerfert 2014-10-10 15:14:29 +00:00
parent 59eb767e11
commit 9b5786960d
3 changed files with 91 additions and 11 deletions

View File

@ -185,6 +185,7 @@ bool JSONImporter::runOnScop(Scop &scop) {
S = &scop;
Region &R = S->getRegion();
Dependences *D = &getAnalysis<Dependences>();
const DataLayout &DL = getAnalysis<DataLayoutPass>().getDataLayout();
std::string FileName = ImportDir + "/" + getFileName(S);
@ -281,18 +282,33 @@ bool JSONImporter::runOnScop(Scop &scop) {
newAccessMap = isl_map_set_tuple_id(newAccessMap, isl_dim_out, OutId);
// We keep the old alignment, thus we cannot allow accesses to memory
// locations that were not accessed before.
isl_set *newAccessSet = isl_map_range(isl_map_copy(newAccessMap));
isl_set *currentAccessSet = isl_map_range(isl_map_copy(currentAccessMap));
bool isSubset = isl_set_is_subset(newAccessSet, currentAccessSet);
isl_set_free(newAccessSet);
isl_set_free(currentAccessSet);
// locations that were not accessed before if the alignment of the access
// is not the default alignment.
bool SpecialAlignment = true;
if (LoadInst *LoadI = dyn_cast<LoadInst>(MA->getAccessInstruction())) {
SpecialAlignment =
DL.getABITypeAlignment(LoadI->getType()) != LoadI->getAlignment();
} else if (StoreInst *StoreI =
dyn_cast<StoreInst>(MA->getAccessInstruction())) {
SpecialAlignment =
DL.getABITypeAlignment(StoreI->getValueOperand()->getType()) !=
StoreI->getAlignment();
}
if (!isSubset) {
errs() << "JScop file changes the accessed memory\n";
isl_map_free(currentAccessMap);
isl_map_free(newAccessMap);
return false;
if (SpecialAlignment) {
isl_set *newAccessSet = isl_map_range(isl_map_copy(newAccessMap));
isl_set *currentAccessSet =
isl_map_range(isl_map_copy(currentAccessMap));
bool isSubset = isl_set_is_subset(newAccessSet, currentAccessSet);
isl_set_free(newAccessSet);
isl_set_free(currentAccessSet);
if (!isSubset) {
errs() << "JScop file changes the accessed memory\n";
isl_map_free(currentAccessMap);
isl_map_free(newAccessMap);
return false;
}
}
// We need to copy the isl_ids for the parameter dimensions to the new
@ -342,6 +358,7 @@ bool JSONImporter::runOnScop(Scop &scop) {
void JSONImporter::getAnalysisUsage(AnalysisUsage &AU) const {
ScopPass::getAnalysisUsage(AU);
AU.addRequired<Dependences>();
AU.addRequired<DataLayoutPass>();
}
Pass *polly::createJSONImporterPass() { return new JSONImporter(); }
@ -360,6 +377,7 @@ INITIALIZE_PASS_BEGIN(JSONImporter, "polly-import-jscop",
" (Reads a .jscop file for each Scop)",
false, false);
INITIALIZE_PASS_DEPENDENCY(Dependences)
INITIALIZE_PASS_DEPENDENCY(DataLayoutPass)
INITIALIZE_PASS_END(JSONImporter, "polly-import-jscop",
"Polly - Import Scops from JSON"
" (Reads a .jscop file for each Scop)",

View File

@ -0,0 +1,41 @@
; RUN: opt %loadPolly -basicaa -polly-import-jscop -polly-import-jscop-dir=%S -analyze < %s | FileCheck %s
;
; Check that we allow the new access functions even though they access
; different locations than the original ones (but the alignment is the
; default, thus there is no problem).
;
; CHECK-DAG: New access function '{ Stmt_for_body[i0] -> MemRef_B[0] }'detected in JSCOP file
; CHECK-DAG: New access function '{ Stmt_for_body[i0] -> MemRef_A[i0] }'detected in JSCOP file
;
; void simple_stride(int *restrict A, int *restrict B) {
; for (int i = 0; i < 16; i++)
; A[i * 2] = B[i * 2];
; }
;
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
define void @simple_stride(i32* noalias %A, i32* noalias %B) {
entry:
br label %for.cond
for.cond: ; preds = %for.inc, %entry
%indvars.iv = phi i64 [ %indvars.iv.next, %for.inc ], [ 0, %entry ]
%exitcond = icmp ne i64 %indvars.iv, 16
br i1 %exitcond, label %for.body, label %for.end
for.body: ; preds = %for.cond
%tmp = shl nsw i64 %indvars.iv, 1
%arrayidx = getelementptr inbounds i32* %B, i64 %tmp
%tmp4 = load i32* %arrayidx, align 4
%tmp5 = shl nsw i64 %indvars.iv, 1
%arrayidx3 = getelementptr inbounds i32* %A, i64 %tmp5
store i32 %tmp4, i32* %arrayidx3, align 4
br label %for.inc
for.inc: ; preds = %for.body
%indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
br label %for.cond
for.end: ; preds = %for.cond
ret void
}

View File

@ -0,0 +1,21 @@
{
"context" : "{ : }",
"name" : "for.cond => for.end",
"statements" : [
{
"accesses" : [
{
"kind" : "read",
"relation" : "{ Stmt_for_body[i0] -> MemRef_B[0] }"
},
{
"kind" : "write",
"relation" : "{ Stmt_for_body[i0] -> MemRef_A[i0] }"
}
],
"domain" : "{ Stmt_for_body[i0] : i0 >= 0 and i0 <= 15 }",
"name" : "Stmt_for_body",
"schedule" : "{ Stmt_for_body[i0] -> scattering[0, i0, 0] }"
}
]
}