-
Notifications
You must be signed in to change notification settings - Fork 170
I want to construct a toolchain using polygeist and polymer so that I can produce OpenScop from C/C++ code. However, the output from cgeist cannot be processed directly by polymer. Is there a built-in method to generate cleaner MLIR Affine Dialect IR?
For example, the following code:
int sum_mtx(int x[10][20]){
int sum = 0;
for(int i = 0; i < 10; i++){
for(int j = 0; j < 20; j++){
sum += x[i][j];
}
}
return sum;
}
will produce the following IR after using -function=sum_mtx -S -raise-scf-to-affine :
module attributes {dlti.dl_spec = #dlti.dl_spec<#dlti.dl_entry<"dlti.endianness", "little">, #dlti.dl_entry<i64, dense<64> : vector<2xi32>>, #dlti.dl_entry<f80, dense<128> : vector<2xi32>>, #dlti.dl_entry<i1, dense<8> : vector<2xi32>>, #dlti.dl_entry<i8, dense<8> : vector<2xi32>>, #dlti.dl_entry<i16, dense<16> : vector<2xi32>>, #dlti.dl_entry<i32, dense<32> : vector<2xi32>>, #dlti.dl_entry<f16, dense<16> : vector<2xi32>>, #dlti.dl_entry<f64, dense<64> : vector<2xi32>>, #dlti.dl_entry<f128, dense<128> : vector<2xi32>>>, llvm.data_layout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128", llvm.target_triple = "x86_64-unknown-linux-gnu"} {
func @sum_mtx(%arg0: memref<?x20xi32>) -> i32 attributes {llvm.linkage = #llvm.linkage<external>} {
%c0_i32 = arith.constant 0 : i32
%0:2 = affine.for %arg1 = 0 to 10 iter_args(%arg2 = %c0_i32, %arg3 = %c0_i32) -> (i32, i32) {
%1:2 = affine.for %arg4 = 0 to 20 iter_args(%arg5 = %arg2, %arg6 = %arg2) -> (i32, i32) {
%2 = affine.load %arg0[%arg1, %arg4] : memref<?x20xi32>
%3 = arith.addi %arg5, %2 : i32
affine.yield %3, %3 : i32, i32
}
affine.yield %1#1, %1#1 : i32, i32
}
return %0#1 : i32
}
}
The output contains excessive amount of useless information for polymer. Additionally, the affine for-loop is in a slightly different format. Is there a way to generate clean MLIR similar to the ones in the polygeist presentation?
P.S.: I am building Polymer and Polygeist in Ubuntu 22.04 using LLVM 15 libraries.