kumasento / polymer

Bridging polyhedral analysis tools to the MLIR framework
MIT License
99 stars 20 forks source link

Handle duplication of for-loop structures #58

Open kumasento opened 3 years ago

kumasento commented 3 years ago

Sometimes Pluto may generate a Scop like this:

<OpenScop>

# =============================================== Global
# Language
C

# Context
CONTEXT
2 4 0 0 0 2
# e/i| P0   P1 |  1  
   1    1    0   -1    ## P0-1 >= 0
   1    0    1   -1    ## P1-1 >= 0

# Parameters are provided
1
<strings>
P0 P1
</strings>

# Number of statements
2

# =============================================== Statement 1
# Number of relations describing the statement:
4

# ----------------------------------------------  1.1 Domain
DOMAIN
6 7 3 0 0 2
# e/i| fk0  fk1  i0 | P0   P1 |  1  
   1    0    0    1    0    0    0    ## i0 >= 0
   1    0    0   -1    1    0   -1    ## -i0+P0-1 >= 0
   1  -32    0    1    0    0    0    ## -32*fk0+i0 >= 0
   1   32    0   -1    0    0   31    ## 32*fk0-i0+31 >= 0
   1    0  -32    0    0    0    0    ## -32*fk1 >= 0
   1    0   32    0    0    0   31    ## 32*fk1+31 >= 0

# ----------------------------------------------  1.2 Scattering
SCATTERING
8 15 8 3 0 2
# e/i| c1   c2   c3   c4   c5   c6   c7   c8 | fk0  fk1  i0 | P0   P1 |  1  
   0   -1    0    0    0    0    0    0    0    0    0    0    0    0    0    ## c1 == 0
   0    0   -1    0    0    0    0    0    0    1    0    0    0    0    0    ## c2 == fk0
   0    0    0   -1    0    0    0    0    0    0    1    0    0    0    0    ## c3 == fk1
   0    0    0    0   -1    0    0    0    0    0    0    0    0    0    0    ## c4 == 0
   0    0    0    0    0   -1    0    0    0    0    0    1    0    0    0    ## c5 == i0
   0    0    0    0    0    0   -1    0    0    0    0    0    0    0    0    ## c6 == 0
   0    0    0    0    0    0    0   -1    0    0    0    0    0    0    0    ## c7 == 0
   0    0    0    0    0    0    0    0   -1    0    0    0    0    0    0    ## c8 == 0

# ----------------------------------------------  1.3 Access
WRITE
2 9 2 3 0 2
# e/i| Arr  [1]| fk0  fk1  i0 | P0   P1 |  1  
   0   -1    0    0    0    0    0    0    1    ## Arr == A1
   0    0   -1    0    0    1    0    0    0    ## [1] == i0

READ
2 9 2 3 0 2
# e/i| Arr  [1]| fk0  fk1  i0 | P0   P1 |  1  
   0   -1    0    0    0    0    0    0    2    ## Arr == A2
   0    0   -1    0    0    1    0    0    0    ## [1] == i0

# ----------------------------------------------  1.4 Statement Extensions
# Number of Statement Extensions
1
<body>
# Number of original iterators
3
# List of original iterators
fk0 fk1 i0
# Statement body expression
S0(A1, 1, A2, 1, i0)
</body>

# =============================================== Statement 2
# Number of relations describing the statement:
4

# ----------------------------------------------  2.1 Domain
DOMAIN
10 9 5 0 0 2
# e/i| fk0  fk1  fk2  i0   i1 | P0   P1 |  1  
   1    0    0    0    1    0    0    0    0    ## i0 >= 0
   1    0    0    0   -1    0    1    0   -1    ## -i0+P0-1 >= 0
   1    0    0    0    0    1    0    0    0    ## i1 >= 0
   1    0    0    0    0   -1    0    1   -1    ## -i1+P1-1 >= 0
   1  -32    0    0    1    0    0    0    0    ## -32*fk0+i0 >= 0
   1   32    0    0   -1    0    0    0   31    ## 32*fk0-i0+31 >= 0
   1    0  -32    0    0    0    0    0    1    ## -32*fk1+1 >= 0
   1    0   32    0    0    0    0    0   30    ## 32*fk1+30 >= 0
   1    0    0  -32    0    1    0    0    0    ## -32*fk2+i1 >= 0
   1    0    0   32    0   -1    0    0   31    ## 32*fk2-i1+31 >= 0

# ----------------------------------------------  2.2 Scattering
SCATTERING
8 17 8 5 0 2
# e/i| c1   c2   c3   c4   c5   c6   c7   c8 | fk0  fk1  fk2  i0   i1 | P0   P1 |  1  
   0   -1    0    0    0    0    0    0    0    0    0    0    0    0    0    0    0    ## c1 == 0
   0    0   -1    0    0    0    0    0    0    1    0    0    0    0    0    0    0    ## c2 == fk0
   0    0    0   -1    0    0    0    0    0    0    1    0    0    0    0    0    0    ## c3 == fk1
   0    0    0    0   -1    0    0    0    0    0    0    1    0    0    0    0    0    ## c4 == fk2
   0    0    0    0    0   -1    0    0    0    0    0    0    1    0    0    0    0    ## c5 == i0
   0    0    0    0    0    0   -1    0    0    0    0    0    0    0    0    0    1    ## c6 == 1
   0    0    0    0    0    0    0   -1    0    0    0    0    0    1    0    0    0    ## c7 == i1
   0    0    0    0    0    0    0    0   -1    0    0    0    0    0    0    0    0    ## c8 == 0

# ----------------------------------------------  2.3 Access
WRITE
3 12 3 5 0 2
# e/i| Arr  [1]  [2]| fk0  fk1  fk2  i0   i1 | P0   P1 |  1  
   0   -1    0    0    0    0    0    0    0    0    0    3    ## Arr == A3
   0    0   -1    0    0    0    0    1    0    0    0    0    ## [1] == i0
   0    0    0   -1    0    0    0    0    1    0    0    0    ## [2] == i1

READ
2 11 2 5 0 2
# e/i| Arr  [1]| fk0  fk1  fk2  i0   i1 | P0   P1 |  1  
   0   -1    0    0    0    0    0    0    0    0    1    ## Arr == A1
   0    0   -1    0    0    0    1    0    0    0    0    ## [1] == i0

# ----------------------------------------------  2.4 Statement Extensions
# Number of Statement Extensions
1
<body>
# Number of original iterators
5
# List of original iterators
fk0 fk1 fk2 i0 i1
# Statement body expression
S1(A3, 2, A1, 1, i0, i1)
</body>

# =============================================== Extensions
<arrays>
# Number of arrays
3
# Mapping array-identifiers/array-names
3 A3
2 A2
1 A1
</arrays>

<scatnames>
t1 t2 t3 t4 t5 t6 t7 t8
</scatnames>

<loop>
# Number of loops
2
# ===========================================
# Loop number 1 
# Iterator name
t2
# Number of stmts
2
# Statement identifiers
1
2
# Private variables
lbv, ubvt3,t4,t5,t6,t7,t8
# Directive
1
# ===========================================
# Loop number 2 
# Iterator name
t7
# Number of stmts
1
# Statement identifiers
2
# Private variables
(null)
# Directive
4
</loop>

</OpenScop>

When it is handled by CLooG, there might be duplicated loop structures that iterate the polyhedra. In that case, the same statement can exist at different places in the code. For different placement, they could have exactly the same naming for their loop IVs, however, if so, our code that generates MLIR from Scop cannot handle well since it relies the fact that IV names to be unique.

We might need to fundamentally change the design of the symbol table. Or maybe we need to add a new pass to make things easier to handle.

Also note that there are conflicts in the naming of the statements as well. For instance, one S1 can be different places of the code due to Pluto and CLooG.

kumasento commented 3 years ago

One possible solution: