Changing schedule in jscop file: An example

Consider the following code.

int A[100][100];

int main()
{
  int i, j;
  for (i = 0; i < 100; i++)
    for (j = 0; j < 100; j++)
      A[i][j] = i + j;

  return 0;
}

Issue the commands below to make it ready to import changes in jscop file.

$ clang -S -emit-llvm example1.c -o example1.s
$ opt -S -mem2reg -loop-simplify -indvars example1.s > example1.preopt.ll

Perfrom the command to export current scop description to a jscop file.

$ opt example1.preopt.ll -basicaa -polly-export-jscop

This will creata file named main___%for.cond---%for.end14.jscop which has
the following content

{
   "context" : "{ [] }",
   "name" : "for.cond => for.end14",
   "statements" : [
      {
         "accesses" : [
            {
               "kind" : "write",
               "relation" : "{ Stmt_for_body4[i0, i1] -> MemRef_A[100i0 + i1] }"
            }
         ],
         "domain" : "{ Stmt_for_body4[i0, i1] : i0 >= 0 and i0 <= 99 and i1 >= 0 and i1 <= 99 }",
         "name" : "Stmt_for_body4",
         "schedule" : "{ Stmt_for_body4[i0, i1] -> scattering[0, i0, 0, i1, 0] }"
      }
   ]
}

Suppose we want to perform a transformation from A[i][j] to A[j][i] just change the
scattering to scattering[0, i1, 0, i0, 0] and issue the command below.

$ opt example1.preopt.ll -basicaa -polly-import-jscop -polly-cloog -analyze

Observe below that the indices are interchanged from (c2,c4) to (c4,c2)

main():
for (c2=0;c2<=99;c2++) {
  for (c4=0;c4<=99;c4++) {
    Stmt_for_body4(c4,c2);
  }
}