Index: lib/Exchange/JSONExporter.cpp =================================================================== --- lib/Exchange/JSONExporter.cpp +++ lib/Exchange/JSONExporter.cpp @@ -274,10 +274,45 @@ bool JSONImporter::importContext(Scop &S, Json::Value &JScop) { isl_set *OldContext = S.getContext(); + // Check if key 'context' is present. + if (!JScop.isMember("context")) { + errs() << "JScop file has no key named 'context'.\n"; + isl_set_free(OldContext); + return false; + } + isl_set *NewContext = isl_set_read_from_str(S.getIslCtx(), JScop["context"].asCString()); - for (unsigned i = 0; i < isl_set_dim(OldContext, isl_dim_param); i++) { + // Check whether the context was parsed successfully. + if (!NewContext) { + errs() << "The context was not parsed successfully by ISL.\n"; + isl_set_free(NewContext); + isl_set_free(OldContext); + return false; + } + + // Check if the isl_set is a parameter set. + if (!isl_set_is_params(NewContext)) { + errs() << "The isl_set is not a parameter set.\n"; + isl_set_free(NewContext); + isl_set_free(OldContext); + return false; + } + + unsigned OldContextDim = isl_set_dim(OldContext, isl_dim_param); + unsigned NewContextDim = isl_set_dim(NewContext, isl_dim_param); + // Check if the imported context has the right number of parameters. + if (OldContextDim != NewContextDim) { + errs() << "Imported context has the wrong number of parameters : " + << "Found " << NewContextDim << " Expected " << OldContextDim + << "\n"; + isl_set_free(NewContext); + isl_set_free(OldContext); + return false; + } + + for (unsigned i = 0; i < OldContextDim; i++) { isl_id *Id = isl_set_get_dim_id(OldContext, isl_dim_param, i); NewContext = isl_set_set_dim_id(NewContext, isl_dim_param, i, Id); } @@ -290,13 +325,44 @@ bool JSONImporter::importSchedule(Scop &S, Json::Value &JScop, const Dependences &D) { StatementToIslMapTy NewSchedule; + // Check if key 'statements' is present. + if (!JScop.isMember("statements")) { + errs() << "JScop file has no key name 'statements'.\n"; + return false; + } + + Json::Value statements = JScop["statements"]; + // Check whether the number of indices equals the number of statements + if (statements.size() != S.getSize()) { + errs() << "The number of indices and the number of statements differ.\n"; + return false; + } int Index = 0; for (ScopStmt &Stmt : S) { - Json::Value Schedule = JScop["statements"][Index]["schedule"]; + // Check if key 'schedule' is present. + if (!statements[Index].isMember("schedule")) { + errs() << "Statement " << Index << " has no 'schedule' key.\n"; + for (auto Element : NewSchedule) { + isl_map_free(Element.second); + } + return false; + } + Json::Value Schedule = statements[Index]["schedule"]; assert(!Schedule.asString().empty() && "Schedules that contain extension nodes require special handling."); + isl_map *Map = isl_map_read_from_str(S.getIslCtx(), Schedule.asCString()); + // Check whether the schedule was parsed successfully + if (!Map) { + errs() << "The schedule was not parsed successfully (index = " << Index + << ").\n"; + for (auto Element : NewSchedule) { + isl_map_free(Element.second); + } + return false; + } + isl_space *Space = Stmt.getDomainSpace(); // Copy the old tuple id. This is necessary to retain the user pointer, @@ -312,6 +378,7 @@ Index++; } + // Check whether the new schedule is valid or not. if (!D.isValidSchedule(S, &NewSchedule)) { errs() << "JScop file contains a schedule that changes the " << "dependences. Use -disable-polly-legality to continue anyways\n"; @@ -534,10 +601,12 @@ } bool JSONImporter::importArrays(Scop &S, Json::Value &JScop) { + // Check if key 'arrays' is present. Json::Value Arrays = JScop["arrays"]; - - if (Arrays.size() == 0) + if (Arrays.size() == 0) { + errs() << "JScop file has no key named 'arrays'.\n"; return true; + } unsigned ArrayIdx = 0; for (auto &SAI : S.arrays()) { @@ -551,13 +620,35 @@ } for (; ArrayIdx < Arrays.size(); ArrayIdx++) { + // Check if key 'type' is present. + if (!Arrays[ArrayIdx].isMember("type")) { + errs() << "Array at index " << ArrayIdx << " has no key 'type'.\n"; + return false; + } auto *ElementType = parseTextType(Arrays[ArrayIdx]["type"].asCString(), S.getSE()->getContext()); - if (!ElementType) + // Check whether the array was parsed successfully + if (!ElementType) { + errs() << "Array was not parsed successfully for index " << ArrayIdx + << ".\n"; return false; + } + std::vector DimSizes; - for (unsigned i = 0; i < Arrays[ArrayIdx]["sizes"].size(); i++) + // Check if key 'sizes' is present. + if (!Arrays[ArrayIdx].isMember("sizes")) { + errs() << "Array at index " << ArrayIdx << " has no key 'sizes'.\n"; + return false; + } + for (unsigned i = 0; i < Arrays[ArrayIdx]["sizes"].size(); i++) { DimSizes.push_back(std::stoi(Arrays[ArrayIdx]["sizes"][i].asCString())); + } + + // Check if key 'name' is present. + if (!Arrays[ArrayIdx].isMember("name")) { + errs() << "Array at index " << ArrayIdx << " has no key 'name'.\n"; + return false; + } S.createScopArrayInfo(ElementType, Arrays[ArrayIdx]["name"].asCString(), DimSizes); } Index: test/CMakeLists.txt =================================================================== --- test/CMakeLists.txt +++ test/CMakeLists.txt @@ -5,7 +5,8 @@ "CodeGen" "OpenMP" "polybench" - "vect") + "vect" + "JSONExporter") set(POLLY_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/..") Index: test/JSONExporter/rlr.ll =================================================================== --- /dev/null +++ test/JSONExporter/rlr.ll @@ -0,0 +1,65 @@ +; RUN: opt %loadPolly -polly-import-jscop-dir=%S -polly-import-jscop -polly-ast -polly-ast-detect-parallel < %s 2>&1 >/dev/null | FileCheck %s +; +; CHECK: JScop file has no key named 'arrays'. +; +; PINFO: for.cond2: Loop is parallel. +; PINFO-NEXT: for.cond: Loop is not parallel. +; +; void rlr(int *A, long n) { +; for (long i = 0; i < 2 * n; i++) +; S0: A[0] += i; +; for (long i = 0; i < 2 * n; i++) +; S1: A[i + 1] = 1; +; } +; +target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-n32-S64" + +define void @rlr(i32* %A, i32 %n) { +entry: + br label %for.cond + +for.cond: ; preds = %for.inc, %entry + %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.inc ] + %mul = shl nsw i32 %n, 1 + %cmp = icmp slt i32 %i.0, %mul + br i1 %cmp, label %for.body, label %for.end + +for.body: ; preds = %for.cond + br label %S0 + +S0: ; preds = %for.body + %tmp = load i32, i32* %A, align 4 + %add = add nsw i32 %tmp, %i.0 + store i32 %add, i32* %A, align 4 + br label %for.inc + +for.inc: ; preds = %S0 + %inc = add nsw i32 %i.0, 1 + br label %for.cond + +for.end: ; preds = %for.cond + br label %for.cond2 + +for.cond2: ; preds = %for.inc8, %for.end + %i1.0 = phi i32 [ 0, %for.end ], [ %inc9, %for.inc8 ] + %mul3 = shl nsw i32 %n, 1 + %cmp4 = icmp slt i32 %i1.0, %mul3 + br i1 %cmp4, label %for.body5, label %for.end10 + +for.body5: ; preds = %for.cond2 + br label %S1 + +S1: ; preds = %for.body5 + %add6 = add nsw i32 %i1.0, 1 + %arrayidx7 = getelementptr inbounds i32, i32* %A, i32 %add6 + store i32 1, i32* %arrayidx7, align 4 + br label %for.inc8 + +for.inc8: ; preds = %S1 + %inc9 = add nsw i32 %i1.0, 1 + br label %for.cond2 + +for.end10: ; preds = %for.cond2 + ret void +} + Index: test/JSONExporter/rlr2.ll =================================================================== --- /dev/null +++ test/JSONExporter/rlr2.ll @@ -0,0 +1,65 @@ +; RUN: opt %loadPolly -polly-import-jscop-dir=%S -polly-import-jscop -polly-ast -polly-ast-detect-parallel < %s 2>&1 >/dev/null | FileCheck %s +; +; CHECK: JScop file has no key named 'context'. +; +; PINFO: for.cond2: Loop is parallel. +; PINFO-NEXT: for.cond: Loop is not parallel. +; +; void rlr2(int *A, long n) { +; for (long i = 0; i < 2 * n; i++) +; S0: A[0] += i; +; for (long i = 0; i < 2 * n; i++) +; S1: A[i + 1] = 1; +; } +; +target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-n32-S64" + +define void @rlr2(i32* %A, i32 %n) { +entry: + br label %for.cond + +for.cond: ; preds = %for.inc, %entry + %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.inc ] + %mul = shl nsw i32 %n, 1 + %cmp = icmp slt i32 %i.0, %mul + br i1 %cmp, label %for.body, label %for.end + +for.body: ; preds = %for.cond + br label %S0 + +S0: ; preds = %for.body + %tmp = load i32, i32* %A, align 4 + %add = add nsw i32 %tmp, %i.0 + store i32 %add, i32* %A, align 4 + br label %for.inc + +for.inc: ; preds = %S0 + %inc = add nsw i32 %i.0, 1 + br label %for.cond + +for.end: ; preds = %for.cond + br label %for.cond2 + +for.cond2: ; preds = %for.inc8, %for.end + %i1.0 = phi i32 [ 0, %for.end ], [ %inc9, %for.inc8 ] + %mul3 = shl nsw i32 %n, 1 + %cmp4 = icmp slt i32 %i1.0, %mul3 + br i1 %cmp4, label %for.body5, label %for.end10 + +for.body5: ; preds = %for.cond2 + br label %S1 + +S1: ; preds = %for.body5 + %add6 = add nsw i32 %i1.0, 1 + %arrayidx7 = getelementptr inbounds i32, i32* %A, i32 %add6 + store i32 1, i32* %arrayidx7, align 4 + br label %for.inc8 + +for.inc8: ; preds = %S1 + %inc9 = add nsw i32 %i1.0, 1 + br label %for.cond2 + +for.end10: ; preds = %for.cond2 + ret void +} + Index: test/JSONExporter/rlr2___%for.cond---%for.end10.jscop =================================================================== --- /dev/null +++ test/JSONExporter/rlr2___%for.cond---%for.end10.jscop @@ -0,0 +1,32 @@ +{ + "cntext" : "[n] -> { : n >= -2147483648 and n <= 2147483647 }", + "name" : "for.cond => for.end10", + "statements" : [ + { + "accesses" : [ + { + "kind" : "read", + "relation" : "[n] -> { Stmt_S0[i0] -> MemRef_A[0] }" + }, + { + "kind" : "write", + "relation" : "[n] -> { Stmt_S0[i0] -> MemRef_A[0] }" + } + ], + "domain" : "[n] -> { Stmt_S0[i0] : i0 >= 0 and i0 <= -1 + 2n and n >= 1 }", + "name" : "Stmt_S0", + "schedule" : "[n] -> { Stmt_S0[i0] -> [0, n - i0, 0] }" + }, + { + "accesses" : [ + { + "kind" : "write", + "relation" : "[n] -> { Stmt_S1[i0] -> MemRef_A[1 + i0] }" + } + ], + "domain" : "[n] -> { Stmt_S1[i0] : i0 >= 0 and i0 <= -1 + 2n and n >= 1 }", + "name" : "Stmt_S1", + "schedule" : "[n] -> { Stmt_S1[i0] -> [1, n - i0, 0] }" + } + ] +} Index: test/JSONExporter/rlr3.ll =================================================================== --- /dev/null +++ test/JSONExporter/rlr3.ll @@ -0,0 +1,65 @@ +; RUN: opt %loadPolly -polly-import-jscop-dir=%S -polly-import-jscop -polly-ast -polly-ast-detect-parallel < %s 2>&1 >/dev/null | FileCheck %s +; +; CHECK: The context was not parsed successfully by ISL. +; +; PINFO: for.cond2: Loop is parallel. +; PINFO-NEXT: for.cond: Loop is not parallel. +; +; void rlr3(int *A, long n) { +; for (long i = 0; i < 2 * n; i++) +; S0: A[0] += i; +; for (long i = 0; i < 2 * n; i++) +; S1: A[i + 1] = 1; +; } +; +target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-n32-S64" + +define void @rlr3(i32* %A, i32 %n) { +entry: + br label %for.cond + +for.cond: ; preds = %for.inc, %entry + %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.inc ] + %mul = shl nsw i32 %n, 1 + %cmp = icmp slt i32 %i.0, %mul + br i1 %cmp, label %for.body, label %for.end + +for.body: ; preds = %for.cond + br label %S0 + +S0: ; preds = %for.body + %tmp = load i32, i32* %A, align 4 + %add = add nsw i32 %tmp, %i.0 + store i32 %add, i32* %A, align 4 + br label %for.inc + +for.inc: ; preds = %S0 + %inc = add nsw i32 %i.0, 1 + br label %for.cond + +for.end: ; preds = %for.cond + br label %for.cond2 + +for.cond2: ; preds = %for.inc8, %for.end + %i1.0 = phi i32 [ 0, %for.end ], [ %inc9, %for.inc8 ] + %mul3 = shl nsw i32 %n, 1 + %cmp4 = icmp slt i32 %i1.0, %mul3 + br i1 %cmp4, label %for.body5, label %for.end10 + +for.body5: ; preds = %for.cond2 + br label %S1 + +S1: ; preds = %for.body5 + %add6 = add nsw i32 %i1.0, 1 + %arrayidx7 = getelementptr inbounds i32, i32* %A, i32 %add6 + store i32 1, i32* %arrayidx7, align 4 + br label %for.inc8 + +for.inc8: ; preds = %S1 + %inc9 = add nsw i32 %i1.0, 1 + br label %for.cond2 + +for.end10: ; preds = %for.cond2 + ret void +} + Index: test/JSONExporter/rlr3___%for.cond---%for.end10.jscop =================================================================== --- /dev/null +++ test/JSONExporter/rlr3___%for.cond---%for.end10.jscop @@ -0,0 +1,32 @@ +{ + "context" : "[n] -> { : >= -2147483648 and n <= 2147483647 }", + "name" : "for.cond => for.end10", + "statements" : [ + { + "accesses" : [ + { + "kind" : "read", + "relation" : "[n] -> { Stmt_S0[i0] -> MemRef_A[0] }" + }, + { + "kind" : "write", + "relation" : "[n] -> { Stmt_S0[i0] -> MemRef_A[0] }" + } + ], + "domain" : "[n] -> { Stmt_S0[i0] : i0 >= 0 and i0 <= -1 + 2n and n >= 1 }", + "name" : "Stmt_S0", + "schedule" : "[n] -> { Stmt_S0[i0] -> [0, n - i0, 0] }" + }, + { + "accesses" : [ + { + "kind" : "write", + "relation" : "[n] -> { Stmt_S1[i0] -> MemRef_A[1 + i0] }" + } + ], + "domain" : "[n] -> { Stmt_S1[i0] : i0 >= 0 and i0 <= -1 + 2n and n >= 1 }", + "name" : "Stmt_S1", + "schedule" : "[n] -> { Stmt_S1[i0] -> [1, n - i0, 0] }" + } + ] +} Index: test/JSONExporter/rlr4.ll =================================================================== --- /dev/null +++ test/JSONExporter/rlr4.ll @@ -0,0 +1,65 @@ +; RUN: opt %loadPolly -polly-import-jscop-dir=%S -polly-import-jscop -polly-ast -polly-ast-detect-parallel -analyze < %s 2>&1 >/dev/null | FileCheck %s +; +; CHECK: The isl_set is not a parameter set. +; +; PINFO: for.cond2: Loop is parallel. +; PINFO-NEXT: for.cond: Loop is not parallel. +; +; void rlr4(int *A, long n) { +; for (long i = 0; i < 2 * n; i++) +; S0: A[0] += i; +; for (long i = 0; i < 2 * n; i++) +; S1: A[i + 1] = 1; +; } +; +target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-n32-S64" + +define void @rlr4(i32* %A, i32 %n) { +entry: + br label %for.cond + +for.cond: ; preds = %for.inc, %entry + %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.inc ] + %mul = shl nsw i32 %n, 1 + %cmp = icmp slt i32 %i.0, %mul + br i1 %cmp, label %for.body, label %for.end + +for.body: ; preds = %for.cond + br label %S0 + +S0: ; preds = %for.body + %tmp = load i32, i32* %A, align 4 + %add = add nsw i32 %tmp, %i.0 + store i32 %add, i32* %A, align 4 + br label %for.inc + +for.inc: ; preds = %S0 + %inc = add nsw i32 %i.0, 1 + br label %for.cond + +for.end: ; preds = %for.cond + br label %for.cond2 + +for.cond2: ; preds = %for.inc8, %for.end + %i1.0 = phi i32 [ 0, %for.end ], [ %inc9, %for.inc8 ] + %mul3 = shl nsw i32 %n, 1 + %cmp4 = icmp slt i32 %i1.0, %mul3 + br i1 %cmp4, label %for.body5, label %for.end10 + +for.body5: ; preds = %for.cond2 + br label %S1 + +S1: ; preds = %for.body5 + %add6 = add nsw i32 %i1.0, 1 + %arrayidx7 = getelementptr inbounds i32, i32* %A, i32 %add6 + store i32 1, i32* %arrayidx7, align 4 + br label %for.inc8 + +for.inc8: ; preds = %S1 + %inc9 = add nsw i32 %i1.0, 1 + br label %for.cond2 + +for.end10: ; preds = %for.cond2 + ret void +} + Index: test/JSONExporter/rlr4___%for.cond---%for.end10.jscop =================================================================== --- /dev/null +++ test/JSONExporter/rlr4___%for.cond---%for.end10.jscop @@ -0,0 +1,32 @@ +{ + "context" : "{ S[n] : n >= -2147483648 and n <= 2147483647 }", + "name" : "for.cond => for.end10", + "statements" : [ + { + "accesses" : [ + { + "kind" : "read", + "relation" : "[n] -> { Stmt_S0[i0] -> MemRef_A[0] }" + }, + { + "kind" : "write", + "relation" : "[n] -> { Stmt_S0[i0] -> MemRef_A[0] }" + } + ], + "domain" : "[n] -> { Stmt_S0[i0] : i0 >= 0 and i0 <= -1 + 2n and n >= 1 }", + "name" : "Stmt_S0", + "schedule" : "[n] -> { Stmt_S0[i0] -> [0, n - i0, 0] }" + }, + { + "accesses" : [ + { + "kind" : "write", + "relation" : "[n] -> { Stmt_S1[i0] -> MemRef_A[1 + i0] }" + } + ], + "domain" : "[n] -> { Stmt_S1[i0] : i0 >= 0 and i0 <= -1 + 2n and n >= 1 }", + "name" : "Stmt_S1", + "schedule" : "[n] -> { Stmt_S1[i0] -> [1, n - i0, 0] }" + } + ] +} Index: test/JSONExporter/rlr5.ll =================================================================== --- /dev/null +++ test/JSONExporter/rlr5.ll @@ -0,0 +1,65 @@ +; RUN: opt %loadPolly -polly-import-jscop-dir=%S -polly-import-jscop -polly-ast -polly-ast-detect-parallel < %s 2>&1 >/dev/null | FileCheck %s +; +; CHECK: Imported context has the wrong number of parameters : Found 2 Expected 1 +; +; PINFO: for.cond2: Loop is parallel. +; PINFO-NEXT: for.cond: Loop is not parallel. +; +; void rlr5(int *A, long n) { +; for (long i = 0; i < 2 * n; i++) +; S0: A[0] += i; +; for (long i = 0; i < 2 * n; i++) +; S1: A[i + 1] = 1; +; } +; +target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-n32-S64" + +define void @rlr5(i32* %A, i32 %n) { +entry: + br label %for.cond + +for.cond: ; preds = %for.inc, %entry + %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.inc ] + %mul = shl nsw i32 %n, 1 + %cmp = icmp slt i32 %i.0, %mul + br i1 %cmp, label %for.body, label %for.end + +for.body: ; preds = %for.cond + br label %S0 + +S0: ; preds = %for.body + %tmp = load i32, i32* %A, align 4 + %add = add nsw i32 %tmp, %i.0 + store i32 %add, i32* %A, align 4 + br label %for.inc + +for.inc: ; preds = %S0 + %inc = add nsw i32 %i.0, 1 + br label %for.cond + +for.end: ; preds = %for.cond + br label %for.cond2 + +for.cond2: ; preds = %for.inc8, %for.end + %i1.0 = phi i32 [ 0, %for.end ], [ %inc9, %for.inc8 ] + %mul3 = shl nsw i32 %n, 1 + %cmp4 = icmp slt i32 %i1.0, %mul3 + br i1 %cmp4, label %for.body5, label %for.end10 + +for.body5: ; preds = %for.cond2 + br label %S1 + +S1: ; preds = %for.body5 + %add6 = add nsw i32 %i1.0, 1 + %arrayidx7 = getelementptr inbounds i32, i32* %A, i32 %add6 + store i32 1, i32* %arrayidx7, align 4 + br label %for.inc8 + +for.inc8: ; preds = %S1 + %inc9 = add nsw i32 %i1.0, 1 + br label %for.cond2 + +for.end10: ; preds = %for.cond2 + ret void +} + Index: test/JSONExporter/rlr5___%for.cond---%for.end10.jscop =================================================================== --- /dev/null +++ test/JSONExporter/rlr5___%for.cond---%for.end10.jscop @@ -0,0 +1,32 @@ +{ + "context" : "[n, m] -> { : n >= -2147483648 and n <= 2147483647 }", + "name" : "for.cond => for.end10", + "statements" : [ + { + "accesses" : [ + { + "kind" : "read", + "relation" : "[n] -> { Stmt_S0[i0] -> MemRef_A[0] }" + }, + { + "kind" : "write", + "relation" : "[n] -> { Stmt_S0[i0] -> MemRef_A[0] }" + } + ], + "domain" : "[n] -> { Stmt_S0[i0] : i0 >= 0 and i0 <= -1 + 2n and n >= 1 }", + "name" : "Stmt_S0", + "schedule" : "[n] -> { Stmt_S0[i0] -> [0, n - i0, 0] }" + }, + { + "accesses" : [ + { + "kind" : "write", + "relation" : "[n] -> { Stmt_S1[i0] -> MemRef_A[1 + i0] }" + } + ], + "domain" : "[n] -> { Stmt_S1[i0] : i0 >= 0 and i0 <= -1 + 2n and n >= 1 }", + "name" : "Stmt_S1", + "schedule" : "[n] -> { Stmt_S1[i0] -> [1, n - i0, 0] }" + } + ] +} Index: test/JSONExporter/rlr6.ll =================================================================== --- /dev/null +++ test/JSONExporter/rlr6.ll @@ -0,0 +1,65 @@ +; RUN: opt %loadPolly -polly-import-jscop-dir=%S -polly-import-jscop -polly-ast -polly-ast-detect-parallel < %s 2>&1 >/dev/null | FileCheck %s +; +; CHECK: JScop file has no key name 'statements'. +; +; PINFO: for.cond2: Loop is parallel. +; PINFO-NEXT: for.cond: Loop is not parallel. +; +; void rlr6(int *A, long n) { +; for (long i = 0; i < 2 * n; i++) +; S0: A[0] += i; +; for (long i = 0; i < 2 * n; i++) +; S1: A[i + 1] = 1; +; } +; +target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-n32-S64" + +define void @rlr6(i32* %A, i32 %n) { +entry: + br label %for.cond + +for.cond: ; preds = %for.inc, %entry + %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.inc ] + %mul = shl nsw i32 %n, 1 + %cmp = icmp slt i32 %i.0, %mul + br i1 %cmp, label %for.body, label %for.end + +for.body: ; preds = %for.cond + br label %S0 + +S0: ; preds = %for.body + %tmp = load i32, i32* %A, align 4 + %add = add nsw i32 %tmp, %i.0 + store i32 %add, i32* %A, align 4 + br label %for.inc + +for.inc: ; preds = %S0 + %inc = add nsw i32 %i.0, 1 + br label %for.cond + +for.end: ; preds = %for.cond + br label %for.cond2 + +for.cond2: ; preds = %for.inc8, %for.end + %i1.0 = phi i32 [ 0, %for.end ], [ %inc9, %for.inc8 ] + %mul3 = shl nsw i32 %n, 1 + %cmp4 = icmp slt i32 %i1.0, %mul3 + br i1 %cmp4, label %for.body5, label %for.end10 + +for.body5: ; preds = %for.cond2 + br label %S1 + +S1: ; preds = %for.body5 + %add6 = add nsw i32 %i1.0, 1 + %arrayidx7 = getelementptr inbounds i32, i32* %A, i32 %add6 + store i32 1, i32* %arrayidx7, align 4 + br label %for.inc8 + +for.inc8: ; preds = %S1 + %inc9 = add nsw i32 %i1.0, 1 + br label %for.cond2 + +for.end10: ; preds = %for.cond2 + ret void +} + Index: test/JSONExporter/rlr6___%for.cond---%for.end10.jscop =================================================================== --- /dev/null +++ test/JSONExporter/rlr6___%for.cond---%for.end10.jscop @@ -0,0 +1,32 @@ +{ + "context" : "[n] -> { : n >= -2147483648 and n <= 2147483647 }", + "name" : "for.cond => for.end10", + "staements" : [ + { + "accesses" : [ + { + "kind" : "read", + "relation" : "[n] -> { Stmt_S0[i0] -> MemRef_A[0] }" + }, + { + "kind" : "write", + "relation" : "[n] -> { Stmt_S0[i0] -> MemRef_A[0] }" + } + ], + "domain" : "[n] -> { Stmt_S0[i0] : i0 >= 0 and i0 <= -1 + 2n and n >= 1 }", + "name" : "Stmt_S0", + "schedule" : "[n] -> { Stmt_S0[i0] -> [0, n - i0, 0] }" + }, + { + "accesses" : [ + { + "kind" : "write", + "relation" : "[n] -> { Stmt_S1[i0] -> MemRef_A[1 + i0] }" + } + ], + "domain" : "[n] -> { Stmt_S1[i0] : i0 >= 0 and i0 <= -1 + 2n and n >= 1 }", + "name" : "Stmt_S1", + "schedule" : "[n] -> { Stmt_S1[i0] -> [1, n - i0, 0] }" + } + ] +} Index: test/JSONExporter/rlr7.ll =================================================================== --- /dev/null +++ test/JSONExporter/rlr7.ll @@ -0,0 +1,65 @@ +; RUN: opt %loadPolly -polly-import-jscop-dir=%S -polly-import-jscop -polly-ast -polly-ast-detect-parallel < %s 2>&1 >/dev/null | FileCheck %s +; +; CHECK: The number of indices and the number of statements differ. +; +; PINFO: for.cond2: Loop is parallel. +; PINFO-NEXT: for.cond: Loop is not parallel. +; +; void rlr7(int *A, long n) { +; for (long i = 0; i < 2 * n; i++) +; S0: A[0] += i; +; for (long i = 0; i < 2 * n; i++) +; S1: A[i + 1] = 1; +; } +; +target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-n32-S64" + +define void @rlr7(i32* %A, i32 %n) { +entry: + br label %for.cond + +for.cond: ; preds = %for.inc, %entry + %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.inc ] + %mul = shl nsw i32 %n, 1 + %cmp = icmp slt i32 %i.0, %mul + br i1 %cmp, label %for.body, label %for.end + +for.body: ; preds = %for.cond + br label %S0 + +S0: ; preds = %for.body + %tmp = load i32, i32* %A, align 4 + %add = add nsw i32 %tmp, %i.0 + store i32 %add, i32* %A, align 4 + br label %for.inc + +for.inc: ; preds = %S0 + %inc = add nsw i32 %i.0, 1 + br label %for.cond + +for.end: ; preds = %for.cond + br label %for.cond2 + +for.cond2: ; preds = %for.inc8, %for.end + %i1.0 = phi i32 [ 0, %for.end ], [ %inc9, %for.inc8 ] + %mul3 = shl nsw i32 %n, 1 + %cmp4 = icmp slt i32 %i1.0, %mul3 + br i1 %cmp4, label %for.body5, label %for.end10 + +for.body5: ; preds = %for.cond2 + br label %S1 + +S1: ; preds = %for.body5 + %add6 = add nsw i32 %i1.0, 1 + %arrayidx7 = getelementptr inbounds i32, i32* %A, i32 %add6 + store i32 1, i32* %arrayidx7, align 4 + br label %for.inc8 + +for.inc8: ; preds = %S1 + %inc9 = add nsw i32 %i1.0, 1 + br label %for.cond2 + +for.end10: ; preds = %for.cond2 + ret void +} + Index: test/JSONExporter/rlr7___%for.cond---%for.end10.jscop =================================================================== --- /dev/null +++ test/JSONExporter/rlr7___%for.cond---%for.end10.jscop @@ -0,0 +1,21 @@ +{ + "context" : "[n] -> { : n >= -2147483648 and n <= 2147483647 }", + "name" : "for.cond => for.end10", + "statements" : [ + { + "accesses" : [ + { + "kind" : "read", + "relation" : "[n] -> { Stmt_S0[i0] -> MemRef_A[0] }" + }, + { + "kind" : "write", + "relation" : "[n] -> { Stmt_S0[i0] -> MemRef_A[0] }" + } + ], + "domain" : "[n] -> { Stmt_S0[i0] : i0 >= 0 and i0 <= -1 + 2n and n >= 1 }", + "name" : "Stmt_S0", + "schedule" : "[n] -> { Stmt_S0[i0] -> [0, n - i0, 0] }" + } + ] +} Index: test/JSONExporter/rlr8.ll =================================================================== --- /dev/null +++ test/JSONExporter/rlr8.ll @@ -0,0 +1,65 @@ +; RUN: opt %loadPolly -polly-import-jscop-dir=%S -polly-import-jscop -polly-ast -polly-ast-detect-parallel < %s 2>&1 >/dev/null | FileCheck %s +; +; CHECK: Statement 0 has no 'schedule' key. +; +; PINFO: for.cond2: Loop is parallel. +; PINFO-NEXT: for.cond: Loop is not parallel. +; +; void rlr8(int *A, long n) { +; for (long i = 0; i < 2 * n; i++) +; S0: A[0] += i; +; for (long i = 0; i < 2 * n; i++) +; S1: A[i + 1] = 1; +; } +; +target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-n32-S64" + +define void @rlr8(i32* %A, i32 %n) { +entry: + br label %for.cond + +for.cond: ; preds = %for.inc, %entry + %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.inc ] + %mul = shl nsw i32 %n, 1 + %cmp = icmp slt i32 %i.0, %mul + br i1 %cmp, label %for.body, label %for.end + +for.body: ; preds = %for.cond + br label %S0 + +S0: ; preds = %for.body + %tmp = load i32, i32* %A, align 4 + %add = add nsw i32 %tmp, %i.0 + store i32 %add, i32* %A, align 4 + br label %for.inc + +for.inc: ; preds = %S0 + %inc = add nsw i32 %i.0, 1 + br label %for.cond + +for.end: ; preds = %for.cond + br label %for.cond2 + +for.cond2: ; preds = %for.inc8, %for.end + %i1.0 = phi i32 [ 0, %for.end ], [ %inc9, %for.inc8 ] + %mul3 = shl nsw i32 %n, 1 + %cmp4 = icmp slt i32 %i1.0, %mul3 + br i1 %cmp4, label %for.body5, label %for.end10 + +for.body5: ; preds = %for.cond2 + br label %S1 + +S1: ; preds = %for.body5 + %add6 = add nsw i32 %i1.0, 1 + %arrayidx7 = getelementptr inbounds i32, i32* %A, i32 %add6 + store i32 1, i32* %arrayidx7, align 4 + br label %for.inc8 + +for.inc8: ; preds = %S1 + %inc9 = add nsw i32 %i1.0, 1 + br label %for.cond2 + +for.end10: ; preds = %for.cond2 + ret void +} + Index: test/JSONExporter/rlr8___%for.cond---%for.end10.jscop =================================================================== --- /dev/null +++ test/JSONExporter/rlr8___%for.cond---%for.end10.jscop @@ -0,0 +1,31 @@ +{ + "context" : "[n] -> { : n >= -2147483648 and n <= 2147483647 }", + "name" : "for.cond => for.end10", + "statements" : [ + { + "accesses" : [ + { + "kind" : "read", + "relation" : "[n] -> { Stmt_S0[i0] -> MemRef_A[0] }" + }, + { + "kind" : "write", + "relation" : "[n] -> { Stmt_S0[i0] -> MemRef_A[0] }" + } + ], + "domain" : "[n] -> { Stmt_S0[i0] : i0 >= 0 and i0 <= -1 + 2n and n >= 1 }", + "name" : "Stmt_S0" + }, + { + "accesses" : [ + { + "kind" : "write", + "relation" : "[n] -> { Stmt_S1[i0] -> MemRef_A[1 + i0] }" + } + ], + "domain" : "[n] -> { Stmt_S1[i0] : i0 >= 0 and i0 <= -1 + 2n and n >= 1 }", + "name" : "Stmt_S1", + "schedule" : "[n] -> { Stmt_S1[i0] -> [1, n - i0, 0] }" + } + ] +} Index: test/JSONExporter/rlr9.ll =================================================================== --- /dev/null +++ test/JSONExporter/rlr9.ll @@ -0,0 +1,65 @@ +; RUN: opt %loadPolly -polly-import-jscop-dir=%S -polly-import-jscop -polly-ast -polly-ast-detect-parallel < %s 2>&1 >/dev/null | FileCheck %s +; +; CHECK: The schedule was not parsed successfully (index = 1). +; +; PINFO: for.cond2: Loop is parallel. +; PINFO-NEXT: for.cond: Loop is not parallel. +; +; void rlr9(int *A, long n) { +; for (long i = 0; i < 2 * n; i++) +; S0: A[0] += i; +; for (long i = 0; i < 2 * n; i++) +; S1: A[i + 1] = 1; +; } +; +target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-n32-S64" + +define void @rlr9(i32* %A, i32 %n) { +entry: + br label %for.cond + +for.cond: ; preds = %for.inc, %entry + %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.inc ] + %mul = shl nsw i32 %n, 1 + %cmp = icmp slt i32 %i.0, %mul + br i1 %cmp, label %for.body, label %for.end + +for.body: ; preds = %for.cond + br label %S0 + +S0: ; preds = %for.body + %tmp = load i32, i32* %A, align 4 + %add = add nsw i32 %tmp, %i.0 + store i32 %add, i32* %A, align 4 + br label %for.inc + +for.inc: ; preds = %S0 + %inc = add nsw i32 %i.0, 1 + br label %for.cond + +for.end: ; preds = %for.cond + br label %for.cond2 + +for.cond2: ; preds = %for.inc8, %for.end + %i1.0 = phi i32 [ 0, %for.end ], [ %inc9, %for.inc8 ] + %mul3 = shl nsw i32 %n, 1 + %cmp4 = icmp slt i32 %i1.0, %mul3 + br i1 %cmp4, label %for.body5, label %for.end10 + +for.body5: ; preds = %for.cond2 + br label %S1 + +S1: ; preds = %for.body5 + %add6 = add nsw i32 %i1.0, 1 + %arrayidx7 = getelementptr inbounds i32, i32* %A, i32 %add6 + store i32 1, i32* %arrayidx7, align 4 + br label %for.inc8 + +for.inc8: ; preds = %S1 + %inc9 = add nsw i32 %i1.0, 1 + br label %for.cond2 + +for.end10: ; preds = %for.cond2 + ret void +} + Index: test/JSONExporter/rlr9___%for.cond---%for.end10.jscop =================================================================== --- /dev/null +++ test/JSONExporter/rlr9___%for.cond---%for.end10.jscop @@ -0,0 +1,32 @@ +{ + "context" : "[n] -> { : n >= -2147483648 and n <= 2147483647 }", + "name" : "for.cond => for.end10", + "statements" : [ + { + "accesses" : [ + { + "kind" : "read", + "relation" : "[n] -> { Stmt_S0[i0] -> MemRef_A[0] }" + }, + { + "kind" : "write", + "relation" : "[n] -> { Stmt_S0[i0] -> MemRef_A[0] }" + } + ], + "domain" : "[n] -> { Stmt_S0[i0] : i0 >= 0 and i0 <= -1 + 2n and n >= 1 }", + "name" : "Stmt_S0", + "schedule" : "[n] -> { Stmt_S0[i0] -> [0, n - i0, 0] }" + }, + { + "accesses" : [ + { + "kind" : "write", + "relation" : "[n] -> { Stmt_S1[i0] -> MemRef_A[1 + i0] }" + } + ], + "domain" : "[n] -> { Stmt_S1[i0] : i0 >= 0 and i0 <= -1 + 2n and n >= 1 }", + "name" : "Stmt_S1", + "schedule" : "[] -> { Stmt_S1[i0] -> [1, n - i0, 0] }" + } + ] +} Index: test/JSONExporter/rlr___%for.cond---%for.end10.jscop =================================================================== --- /dev/null +++ test/JSONExporter/rlr___%for.cond---%for.end10.jscop @@ -0,0 +1,32 @@ +{ + "context" : "[n] -> { : n >= -2147483648 and n <= 2147483647 }", + "name" : "for.cond => for.end10", + "statements" : [ + { + "accesses" : [ + { + "kind" : "read", + "relation" : "[n] -> { Stmt_S0[i0] -> MemRef_A[0] }" + }, + { + "kind" : "write", + "relation" : "[n] -> { Stmt_S0[i0] -> MemRef_A[0] }" + } + ], + "domain" : "[n] -> { Stmt_S0[i0] : i0 >= 0 and i0 <= -1 + 2n and n >= 1 }", + "name" : "Stmt_S0", + "schedule" : "[n] -> { Stmt_S0[i0] -> [0, n - i0, 0] }" + }, + { + "accesses" : [ + { + "kind" : "write", + "relation" : "[n] -> { Stmt_S1[i0] -> MemRef_A[1 + i0] }" + } + ], + "domain" : "[n] -> { Stmt_S1[i0] : i0 >= 0 and i0 <= -1 + 2n and n >= 1 }", + "name" : "Stmt_S1", + "schedule" : "[n] -> { Stmt_S1[i0] -> [1, n - i0, 0] }" + } + ] +}