fix format

This commit is contained in:
William S. Moses 2021-07-01 02:04:14 -04:00
parent 1d2feea90b
commit d4bfa0d6ce
37 changed files with 348 additions and 281 deletions

View File

@ -1,28 +1,44 @@
add_clang_tool(mlir - clang mlir - clang.cc) add_clang_tool(mlir-clang
mlir-clang.cc
)
target_include_directories(mlir - clang PRIVATE target_include_directories(mlir-clang PRIVATE
"${LLVM_SOURCE_DIR}/../clang/include" "${LLVM_SOURCE_DIR}/../clang/include"
"${CMAKE_BINARY_DIR}/tools/clang/include") "${CMAKE_BINARY_DIR}/tools/clang/include"
#MLIRTransformsPassIncGen )
# MLIRTransformsPassIncGen
target_compile_definitions(mlir - clang PUBLIC - target_compile_definitions(mlir-clang PUBLIC -DLLVM_OBJ_ROOT="${LLVM_BINARY_DIR}")
DLLVM_OBJ_ROOT = "${LLVM_BINARY_DIR}") target_link_libraries(mlir-clang PRIVATE
target_link_libraries( LLVMCore
mlir - LLVMOption
clang PRIVATE LLVMCore LLVMOption LLVMSupport LLVMSupport
MLIRSCFTransforms MLIRPolygeist MLIRSCFTransforms
MLIRPolygeist
MLIRSupport MLIRIR MLIRAnalysis MLIRLLVMIR MLIRNVVMIR MLIRSupport
MLIRGPU MLIRTransforms MLIRSCFToStandard MLIRIR
MLIRStandardToLLVM MLIRAffineTransforms MLIRAnalysis
MLIRAffineToStandard MLIRTargetLLVMIRImport MLIRLLVMIR
MLIRPolygeistTransforms MLIRNVVMIR
MLIRGPU
MLIRTransforms
MLIRSCFToStandard
MLIRStandardToLLVM
MLIRAffineTransforms
MLIRAffineToStandard
MLIRTargetLLVMIRImport
MLIRPolygeistTransforms
clangAST clangBasic clangCodeGen clangAST
clangDriver clangFrontend clangBasic
clangFrontendTool clangLex clangCodeGen
clangSerialization) clangDriver
add_dependencies( clangFrontend
mlir - clang MLIRPolygeistOpsIncGen MLIRPolygeistPassIncGen) clangFrontendTool
add_subdirectory(Test) clangLex
clangSerialization
)
add_dependencies(mlir-clang MLIRPolygeistOpsIncGen MLIRPolygeistPassIncGen)
add_subdirectory(Test)

View File

@ -1,13 +1,15 @@
// RUN: mlir-clang %s --function=okernel_2mm | FileCheck %s // RUN: mlir-clang %s --function=okernel_2mm | FileCheck %s
void okernel_2mm(unsigned int ni, double *tmp) { void okernel_2mm(unsigned int ni,
double *tmp) {
int i, j, k; int i, j, k;
#pragma scop #pragma scop
/* D := alpha*A*B*C + beta*D */ /* D := alpha*A*B*C + beta*D */
for (i = 0; i < ni; i++) { for (i = 0; i < ni; i++)
tmp[i] = 0.0; {
} tmp[i] = 0.0;
}
#pragma endscop #pragma endscop
} }

View File

@ -1,10 +1,12 @@
// RUN: mlir-clang %s --function=kernel_deriche | FileCheck %s // RUN: mlir-clang %s --function=kernel_deriche | FileCheck %s
void sub(int a[2]) { a[2]++; } void sub(int a[2]) {
a[2]++;
}
void kernel_deriche() { void kernel_deriche() {
int a[2]; int a[2];
sub(a); sub(a);
} }
// CHECK: func @kernel_deriche() { // CHECK: func @kernel_deriche() {

View File

@ -1,20 +1,22 @@
// RUN: mlir-clang %s %stdinclude --function=set | FileCheck %s // RUN: mlir-clang %s %stdinclude --function=set | FileCheck %s
#include <math.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <unistd.h> #include <unistd.h>
#include <string.h>
#include <math.h>
/* Array initialization. */ /* Array initialization. */
int set(int b) { int set (int b)
int res; {
if (b) int res;
res = 1; if (b)
else res = 1;
res = 2; else
return res; res = 2;
// path[0][1] = 2; return res;
//path[0][1] = 2;
} }
// CHECK: func @set(%arg0: i32) -> i32 { // CHECK: func @set(%arg0: i32) -> i32 {

View File

@ -1,18 +1,20 @@
// RUN: mlir-clang %s %stdinclude --function=set | FileCheck %s // RUN: mlir-clang %s %stdinclude --function=set | FileCheck %s
#include <math.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <unistd.h> #include <unistd.h>
#include <string.h>
#include <math.h>
/* Array initialization. */ /* Array initialization. */
int set(int b) { int set (int b)
int res = 1; {
if (b) int res = 1;
res = 2; if (b)
return res; res = 2;
// path[0][1] = 2; return res;
//path[0][1] = 2;
} }
// CHECK: func @set(%arg0: i32) -> i32 { // CHECK: func @set(%arg0: i32) -> i32 {

View File

@ -1,9 +1,9 @@
// RUN: mlir-clang %s --function=kernel_deriche | FileCheck %s // RUN: mlir-clang %s --function=kernel_deriche | FileCheck %s
float kernel_deriche() { float kernel_deriche() {
float a2, a6; float a2, a6;
a2 = a6 = 2.0; // EXP_FUN(-alpha); a2 = a6 = 2.0;//EXP_FUN(-alpha);
return a2; return a2;
} }
// CHECK: func @kernel_deriche() -> f32 { // CHECK: func @kernel_deriche() -> f32 {

View File

@ -1,8 +1,12 @@
// RUN: mlir-clang %s --function=kernel_deriche | FileCheck %s // RUN: mlir-clang %s --function=kernel_deriche | FileCheck %s
int deref(int a) { return a; } int deref(int a) {
return a;
}
void kernel_deriche(int *a) { deref(*a); } void kernel_deriche(int *a) {
deref(*a);
}
// CHECK: func @kernel_deriche(%arg0: memref<?xi32>) { // CHECK: func @kernel_deriche(%arg0: memref<?xi32>) {
// CHECK-NEXT: %0 = affine.load %arg0[0] : memref<?xi32> // CHECK-NEXT: %0 = affine.load %arg0[0] : memref<?xi32>

View File

@ -3,19 +3,20 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
int *alloc() { int* alloc() {
int no_of_nodes; int no_of_nodes;
scanf("%d", &no_of_nodes); scanf("%d",&no_of_nodes);
// allocate host memory
int* h_graph_nodes = (int*) malloc(sizeof(int)*no_of_nodes);
// allocate host memory // initalize the memory
int *h_graph_nodes = (int *)malloc(sizeof(int) * no_of_nodes); for( unsigned int i = 0; i < no_of_nodes; i++)
{
// initalize the memory scanf("%d\n", &h_graph_nodes[i]);
for (unsigned int i = 0; i < no_of_nodes; i++) { }
scanf("%d\n", &h_graph_nodes[i]); return h_graph_nodes;
}
return h_graph_nodes;
} }
// CHECK: llvm.mlir.global internal constant @str1("%d\0A\00") // CHECK: llvm.mlir.global internal constant @str1("%d\0A\00")
@ -29,9 +30,8 @@ int *alloc() {
// CHECK-DAG: %c1 = constant 1 : index // CHECK-DAG: %c1 = constant 1 : index
// CHECK-NEXT: %0 = llvm.alloca %c1_i64 x i32 : (i64) -> !llvm.ptr<i32> // CHECK-NEXT: %0 = llvm.alloca %c1_i64 x i32 : (i64) -> !llvm.ptr<i32>
// CHECK-NEXT: %1 = llvm.mlir.addressof @str0 : !llvm.ptr<array<3 x i8>> // CHECK-NEXT: %1 = llvm.mlir.addressof @str0 : !llvm.ptr<array<3 x i8>>
// CHECK-NEXT: %2 = llvm.getelementptr %1[%c0_i64, %c0_i64] : // CHECK-NEXT: %2 = llvm.getelementptr %1[%c0_i64, %c0_i64] : (!llvm.ptr<array<3 x i8>>, i64, i64) -> !llvm.ptr<i8>
// (!llvm.ptr<array<3 x i8>>, i64, i64) -> !llvm.ptr<i8> CHECK-NEXT: %3 = // CHECK-NEXT: %3 = llvm.call @__isoc99_scanf(%2, %0) : (!llvm.ptr<i8>, !llvm.ptr<i32>) -> i32
// llvm.call @__isoc99_scanf(%2, %0) : (!llvm.ptr<i8>, !llvm.ptr<i32>) -> i32
// CHECK-NEXT: %4 = llvm.load %0 : !llvm.ptr<i32> // CHECK-NEXT: %4 = llvm.load %0 : !llvm.ptr<i32>
// CHECK-NEXT: %5 = zexti %4 : i32 to i64 // CHECK-NEXT: %5 = zexti %4 : i32 to i64
// CHECK-NEXT: %6 = index_cast %5 : i64 to index // CHECK-NEXT: %6 = index_cast %5 : i64 to index
@ -41,9 +41,8 @@ int *alloc() {
// CHECK-NEXT: %10 = index_cast %4 : i32 to index // CHECK-NEXT: %10 = index_cast %4 : i32 to index
// CHECK-NEXT: scf.for %arg0 = %c0 to %10 step %c1 { // CHECK-NEXT: scf.for %arg0 = %c0 to %10 step %c1 {
// CHECK-NEXT: %11 = llvm.mlir.addressof @str1 : !llvm.ptr<array<4 x i8>> // CHECK-NEXT: %11 = llvm.mlir.addressof @str1 : !llvm.ptr<array<4 x i8>>
// CHECK-NEXT: %12 = llvm.getelementptr %11[%c0_i64, %c0_i64] : // CHECK-NEXT: %12 = llvm.getelementptr %11[%c0_i64, %c0_i64] : (!llvm.ptr<array<4 x i8>>, i64, i64) -> !llvm.ptr<i8>
// (!llvm.ptr<array<4 x i8>>, i64, i64) -> !llvm.ptr<i8> CHECK-NEXT: %13 = // CHECK-NEXT: %13 = llvm.call @__isoc99_scanf(%12, %0) : (!llvm.ptr<i8>, !llvm.ptr<i32>) -> i32
// llvm.call @__isoc99_scanf(%12, %0) : (!llvm.ptr<i8>, !llvm.ptr<i32>) -> i32
// CHECK-NEXT: %14 = llvm.load %0 : !llvm.ptr<i32> // CHECK-NEXT: %14 = llvm.load %0 : !llvm.ptr<i32>
// CHECK-NEXT: memref.store %14, %9[%arg0] : memref<?xi32> // CHECK-NEXT: memref.store %14, %9[%arg0] : memref<?xi32>
// CHECK-NEXT: } // CHECK-NEXT: }

View File

@ -1,31 +1,35 @@
// RUN: mlir-clang %s %stdinclude | FileCheck %s // RUN: mlir-clang %s %stdinclude | FileCheck %s
#include <math.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <unistd.h> #include <unistd.h>
#include <string.h>
#include <math.h>
/* Include polybench common header. */ /* Include polybench common header. */
#include <polybench.h> #include <polybench.h>
#define N 2800 # define N 2800
/* Array initialization. */ /* Array initialization. */
static void init_array(int path[N]) { static
// path[0][1] = 2; void init_array (int path[N])
{
//path[0][1] = 2;
} }
int main() { int main()
{
/* Retrieve problem size. */ /* Retrieve problem size. */
/* Variable declaration/allocation. */ /* Variable declaration/allocation. */
// POLYBENCH_1D_ARRAY_DECL(path, int, N, n); //POLYBENCH_1D_ARRAY_DECL(path, int, N, n);
int(*path)[N]; int (*path)[N];
// int path[POLYBENCH_C99_SELECT(N,n) + POLYBENCH_PADDING_FACTOR]; //int path[POLYBENCH_C99_SELECT(N,n) + POLYBENCH_PADDING_FACTOR];
path = (int(*)[N])polybench_alloc_data(N, sizeof(int)); path = (int(*)[N])polybench_alloc_data (N, sizeof(int)) ;
/* Initialize array(s). */ /* Initialize array(s). */
init_array(*path); init_array (*path);
return 0; return 0;
} }

View File

@ -1,31 +1,34 @@
// RUN: mlir-clang %s %stdinclude | FileCheck %s // RUN: mlir-clang %s %stdinclude | FileCheck %s
#include <math.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <unistd.h> #include <unistd.h>
#include <string.h>
#include <math.h>
/* Include polybench common header. */ /* Include polybench common header. */
#include <polybench.h> #include <polybench.h>
#define N 2800 # define N 2800
/* Array initialization. */ /* Array initialization. */
static void init_array(int path[N]) { static
// path[0][1] = 2; void init_array (int path[N])
{
//path[0][1] = 2;
} }
int main() { int main()
{
/* Retrieve problem size. */ /* Retrieve problem size. */
/* Variable declaration/allocation. */ /* Variable declaration/allocation. */
// POLYBENCH_1D_ARRAY_DECL(path, int, N, n); //POLYBENCH_1D_ARRAY_DECL(path, int, N, n);
int(*path)[N]; int (*path)[N];
// int path[POLYBENCH_C99_SELECT(N,n) + POLYBENCH_PADDING_FACTOR]; //int path[POLYBENCH_C99_SELECT(N,n) + POLYBENCH_PADDING_FACTOR];
path = (int(*)[N])polybench_alloc_data(N, sizeof(int)); path = (int(*)[N])polybench_alloc_data (N, sizeof(int)) ;
/* Initialize array(s). */ /* Initialize array(s). */
init_array(*path); init_array (*path);
POLYBENCH_FREE_ARRAY(path); POLYBENCH_FREE_ARRAY(path);
return 0; return 0;

View File

@ -1,8 +1,8 @@
// RUN: mlir-clang %s --function=kernel_deriche | FileCheck %s // RUN: mlir-clang %s --function=kernel_deriche | FileCheck %s
int kernel_deriche(int a[30][40]) { int kernel_deriche(int a[30][40]) {
a[3][5]++; a[3][5]++;
return a[1][2]; return a[1][2];
} }
// CHECK: func @kernel_deriche(%arg0: memref<?x40xi32>) -> i32 { // CHECK: func @kernel_deriche(%arg0: memref<?x40xi32>) -> i32 {

View File

@ -1,8 +1,8 @@
// RUN: mlir-clang %s --function=kernel_deriche | FileCheck %s // RUN: mlir-clang %s --function=kernel_deriche | FileCheck %s
int kernel_deriche(int *a) { int kernel_deriche(int *a) {
a[3]++; a[3]++;
return a[1]; return a[1];
} }
// CHECK: func @kernel_deriche(%arg0: memref<?xi32>) -> i32 { // CHECK: func @kernel_deriche(%arg0: memref<?xi32>) -> i32 {

View File

@ -1,6 +1,8 @@
// RUN: mlir-clang %s --function=test | FileCheck %s // RUN: mlir-clang %s --function=test | FileCheck %s
int test() { return -3; } int test() {
return -3;
}
// CHECK: func @test() -> i32 { // CHECK: func @test() -> i32 {
// CHECK-NEXT: %c-3_i32 = constant -3 : i32 // CHECK-NEXT: %c-3_i32 = constant -3 : i32

View File

@ -5,9 +5,9 @@
void sum(double *result); void sum(double *result);
void caller(int size) { void caller(int size) {
double *array = (double *)malloc(sizeof(double) * size); double* array = (double*)malloc(sizeof(double) * size);
sum(array); sum(array);
free(array); free(array);
} }
// CHECK: func @caller(%arg0: i32) { // CHECK: func @caller(%arg0: i32) {

View File

@ -1,8 +1,8 @@
// RUN: mlir-clang %s --function=kernel_deriche | FileCheck %s // RUN: mlir-clang %s --function=kernel_deriche | FileCheck %s
int kernel_deriche(int a[30]) { int kernel_deriche(int a[30]) {
a[0]++; a[0]++;
return a[1]; return a[1];
} }
// CHECK: func @kernel_deriche(%arg0: memref<?xi32>) -> i32 { // CHECK: func @kernel_deriche(%arg0: memref<?xi32>) -> i32 {

View File

@ -1,18 +1,21 @@
// RUN: mlir-clang %s %stdinclude --function=init_array | FileCheck %s // RUN: mlir-clang %s %stdinclude --function=init_array | FileCheck %s
#include <math.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <unistd.h> #include <unistd.h>
#include <string.h>
#include <math.h>
void init_array(int path[10][10]) {
void init_array (int path[10][10])
{
int i, j; int i, j;
for (i = 0; i < 10; i++) for (i = 0; i < 10; i++)
for (j = 0; j < 10; j++) { for (j = 0; j < 10; j++) {
path[i][j] = i * j % 7 + 1; path[i][j] = i*j%7+1;
if ((i + j) % 13 == 0 || (i + j) % 7 == 0 || (i + j) % 11 == 0) if ((i+j)%13 == 0 || (i+j)%7==0 || (i+j)%11 == 0)
path[i][j] = 999; path[i][j] = 999;
} }
} }
@ -53,8 +56,10 @@ void init_array(int path[10][10]) {
// CHECK-NEXT: scf.yield %11 : i1 // CHECK-NEXT: scf.yield %11 : i1
// CHECK-NEXT: } // CHECK-NEXT: }
// CHECK-NEXT: scf.if %9 { // CHECK-NEXT: scf.if %9 {
// CHECK-NEXT: memref.store %c999_i32, %arg0[%arg1, %arg2] : // CHECK-NEXT: memref.store %c999_i32, %arg0[%arg1, %arg2] : memref<?x10xi32>
// memref<?x10xi32> CHECK-NEXT: } CHECK-NEXT: } CHECK-NEXT: } // CHECK-NEXT: }
// CHECK-NEXT: }
// CHECK-NEXT: }
// CHECK-NEXT: return // CHECK-NEXT: return
// CHECK-NEXT: } // CHECK-NEXT: }
// CHECK-NEXT: } // CHECK-NEXT: }

View File

@ -15,14 +15,17 @@
// CHECK-NEXT: return // CHECK-NEXT: return
// CHECK-NEXT: } // CHECK-NEXT: }
void kernel_nussinov(int n, int table[N]) { void kernel_nussinov(int n, int table[N])
{
int j; int j;
#pragma scop #pragma scop
for (j = 1; j < N; j++) { for (j=1; j<N; j++) {
if (j - 1 >= 0) if (j-1>=0)
table[j] = max_score(table[j], table[j - 1]); table[j] = max_score(table[j], table[j-1]);
}
}
#pragma endscop #pragma endscop
} }

View File

@ -1,8 +1,8 @@
// RUN: mlir-clang %s %stdinclude --function=init_array | FileCheck %s // RUN: mlir-clang %s %stdinclude --function=init_array | FileCheck %s
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <unistd.h> #include <unistd.h>
#include <string.h>
/* Include polybench common header. */ /* Include polybench common header. */
#include <polybench.h> #include <polybench.h>
@ -10,12 +10,14 @@
void use(double A[20]); void use(double A[20]);
/* Array initialization. */ /* Array initialization. */
void init_array(int n) { void init_array (int n)
double(*B)[20] = (double(*)[20])polybench_alloc_data(20, sizeof(double)); {
double (*B)[20] = (double(*)[20])polybench_alloc_data (20, sizeof(double)) ;
(*B)[2] = 3.0; (*B)[2] = 3.0;
use(*B); use(*B);
} }
// CHECK: func @init_array(%arg0: i32) // CHECK: func @init_array(%arg0: i32)
// CHECK-NEXT: %cst = constant 3.000000e+00 : f64 // CHECK-NEXT: %cst = constant 3.000000e+00 : f64
// CHECK-NEXT: %0 = memref.alloc() : memref<20xf64> // CHECK-NEXT: %0 = memref.alloc() : memref<20xf64>

View File

@ -1,9 +1,7 @@
// RUN: split-file %s %t // RUN: split-file %s %t
// RUN: mlir-clang %t/matmul_signed_cmp.cpp --function=matmul // RUN: mlir-clang %t/matmul_signed_cmp.cpp --function=matmul --raise-scf-to-affine | FileCheck %s -check-prefix=GEMMSIGNED
// --raise-scf-to-affine | FileCheck %s -check-prefix=GEMMSIGNED RUN: mlir-clang // RUN: mlir-clang %t/matmul_unsigned_cmp.cpp --function=matmul_unsigned_cmp --raise-scf-to-affine | FileCheck %s -check-prefix=GEMMUNSIGNED
// %t/matmul_unsigned_cmp.cpp --function=matmul_unsigned_cmp
// --raise-scf-to-affine | FileCheck %s -check-prefix=GEMMUNSIGNED
//--- matmul_signed_cmp.cpp //--- matmul_signed_cmp.cpp
#define N 200 #define N 200
@ -19,36 +17,33 @@ void matmul(DATA_TYPE A[N][K], DATA_TYPE B[K][M], DATA_TYPE C[N][M]) {
for (j = 0; j < M; j++) for (j = 0; j < M; j++)
// GEMMSIGNED: affine.for // GEMMSIGNED: affine.for
for (k = 0; k < K; k++) for (k = 0; k < K; k++)
// GEMMSIGNED: {{.*}} = affine.load %{{.*}}[%{{.*}}, %{{.*}}] : // GEMMSIGNED: {{.*}} = affine.load %{{.*}}[%{{.*}}, %{{.*}}] : memref<?x400xf32>
// memref<?x400xf32> GEMMSIGNED: {{.*}} = affine.load %{{.*}}[%{{.*}}, // GEMMSIGNED: {{.*}} = affine.load %{{.*}}[%{{.*}}, %{{.*}}] : memref<?x300xf32>
// %{{.*}}] : memref<?x300xf32> GEMMSIGNED: {{.*}} = mulf GEMMSIGNED: // GEMMSIGNED: {{.*}} = mulf
// {{.*}} = affine.load %{{.*}}[%{{.*}}, %{{.*}}] : memref<?x300xf32> // GEMMSIGNED: {{.*}} = affine.load %{{.*}}[%{{.*}}, %{{.*}}] : memref<?x300xf32>
// GEMMSIGNED: {{.*}} = addf // GEMMSIGNED: {{.*}} = addf
// GEMMSIGNED: affine.store {{.*}}, %{{.*}}[%{{.*}}, %{{.*}}] : // GEMMSIGNED: affine.store {{.*}}, %{{.*}}[%{{.*}}, %{{.*}}] : memref<?x300xf32>
// memref<?x300xf32>
C[i][j] += A[i][k] * B[k][j]; C[i][j] += A[i][k] * B[k][j];
} }
//--- matmul_unsigned_cmp.cpp //--- matmul_unsigned_cmp.cpp
void matmul_unsigned_cmp(float A[100][200], float B[200][300], void matmul_unsigned_cmp(float A[100][200], float B[200][300], float C[100][300]) {
float C[100][300]) {
int i, j, k; int i, j, k;
// GEMMUNSIGNED: affine.for // GEMMUNSIGNED: affine.for
for (i = 0; i < 100; i++) { for (i = 0; i < 100; i++) {
// GEMMUNSIGNED: affine.for // GEMMUNSIGNED: affine.for
for (j = 0; j < 300; j++) { for (j = 0; j < 300; j++) {
// GEMMUNSIGNED: affine.store %{{.*}}, %{{.*}}[%{{.*}}, %{{.*}}] : // GEMMUNSIGNED: affine.store %{{.*}}, %{{.*}}[%{{.*}}, %{{.*}}] : memref<?x300xf32>
// memref<?x300xf32>
C[i][j] = 0; C[i][j] = 0;
// GEMMUNSIGNED: affine.for // GEMMUNSIGNED: affine.for
for (k = 0; k < 200; k++) { for (k = 0; k < 200; k++) {
// GEMMUNSIGNED: {{.*}} = affine.load %{{.*}}[%{{.*}}, %{{.*}}] : // GEMMUNSIGNED: {{.*}} = affine.load %{{.*}}[%{{.*}}, %{{.*}}] : memref<?x200xf32>
// memref<?x200xf32> GEMMUNSIGNED: {{.*}} = affine.load %{{.*}}[%{{.*}}, // GEMMUNSIGNED: {{.*}} = affine.load %{{.*}}[%{{.*}}, %{{.*}}] : memref<?x300xf32>
// %{{.*}}] : memref<?x300xf32> GEMMUNSIGNED: {{.*}} = mulf // GEMMUNSIGNED: {{.*}} = mulf
// GEMMUNSIGNED: {{.*}} = affine.load %{{.*}}[%{{.*}}, %{{.*}}] : // GEMMUNSIGNED: {{.*}} = affine.load %{{.*}}[%{{.*}}, %{{.*}}] : memref<?x300xf32>
// memref<?x300xf32> GEMMUNSIGNED: {{.*}} = addf GEMMUNSIGNED: // GEMMUNSIGNED: {{.*}} = addf
// affine.store {{.*}}, %{{.*}}[%{{.*}}, %{{.*}}] : memref<?x300xf32> // GEMMUNSIGNED: affine.store {{.*}}, %{{.*}}[%{{.*}}, %{{.*}}] : memref<?x300xf32>
C[i][j] += A[i][k] * B[k][j]; C[i][j] += A[i][k] * B[k][j];
} }
} }

View File

@ -7,18 +7,18 @@ void matmul(float A[100][200], float B[200][300], float C[100][300]) {
for (i = 0; i < 100; i++) { for (i = 0; i < 100; i++) {
// CHECK: affine.for // CHECK: affine.for
for (j = 0; j < 300; j++) { for (j = 0; j < 300; j++) {
// CHECK: affine.store %{{.*}}, %{{.*}}[%{{.*}}, %{{.*}}] : // CHECK: affine.store %{{.*}}, %{{.*}}[%{{.*}}, %{{.*}}] : memref<?x300xf32>
// memref<?x300xf32>
C[i][j] = 0; C[i][j] = 0;
// CHECK: affine.for // CHECK: affine.for
for (k = 0; k < 200; k++) { for (k = 0; k < 200; k++) {
// CHECK: {{.*}} = affine.load %{{.*}}[%{{.*}}, %{{.*}}] : // CHECK: {{.*}} = affine.load %{{.*}}[%{{.*}}, %{{.*}}] : memref<?x200xf32>
// memref<?x200xf32> CHECK: {{.*}} = affine.load %{{.*}}[%{{.*}}, // CHECK: {{.*}} = affine.load %{{.*}}[%{{.*}}, %{{.*}}] : memref<?x300xf32>
// %{{.*}}] : memref<?x300xf32> CHECK: {{.*}} = mulf CHECK: {{.*}} = // CHECK: {{.*}} = mulf
// affine.load %{{.*}}[%{{.*}}, %{{.*}}] : memref<?x300xf32> CHECK: // CHECK: {{.*}} = affine.load %{{.*}}[%{{.*}}, %{{.*}}] : memref<?x300xf32>
// {{.*}} = addf CHECK: affine.store {{.*}}, %{{.*}}[%{{.*}}, %{{.*}}] : // CHECK: {{.*}} = addf
// memref<?x300xf32> // CHECK: affine.store {{.*}}, %{{.*}}[%{{.*}}, %{{.*}}] : memref<?x300xf32>
C[i][j] += A[i][k] * B[k][j]; C[i][j] += A[i][k] * B[k][j];
} }
} }
} }

View File

@ -1,7 +1,7 @@
// RUN: mlir-opt --detect-reduction %s | FileCheck %s // RUN: mlir-opt --detect-reduction %s | FileCheck %s
// XFAIL: * // XFAIL: *
module { module {
func @reduce_with_iter_args(%arg0: memref<?xf32>) -> f32 { func @reduce_with_iter_args(%arg0: memref<?xf32>) -> f32 {
%c0 = constant 0 : index %c0 = constant 0 : index
%0 = memref.dim %arg0, %c0 : memref<?xf32> %0 = memref.dim %arg0, %c0 : memref<?xf32>

View File

@ -2,31 +2,33 @@
extern int print(double); extern int print(double);
void sum(double *result, double *array, int N) { void sum(double *result, double* array, int N) {
#pragma scop #pragma scop
for (int j = 0; j < N; j++) { for (int j=0; j<N; j++) {
result[0] = 0; result[0] = 0;
for (int i = 0; i < 10; i++) { for (int i=0; i<10; i++) {
result[0] += array[i]; result[0] += array[i];
}
print(result[0]);
} }
print(result[0]); #pragma endscop
}
#pragma endscop
} }
void caller(double *array) { void caller(double* array) {
double result; double result;
sum(&result, array, 1); sum(&result, array, 1);
print(result); print(result);
} }
// CHECK: func @caller(%arg0: memref<?xf64>) { // CHECK: func @caller(%arg0: memref<?xf64>) {
// CHECK-NEXT: %c1_i32 = constant 1 : i32 // CHECK-NEXT: %c1_i32 = constant 1 : i32
// CHECK-NEXT: %0 = memref.alloca() : memref<1xf64> // CHECK-NEXT: %0 = memref.alloca() : memref<1xf64>
// CHECK-NEXT: %1 = memref.cast %0 : memref<1xf64> to memref<?xf64> // CHECK-NEXT: %1 = memref.cast %0 : memref<1xf64> to memref<?xf64>
// CHECK-NEXT: call @sum(%1, %arg0, %c1_i32) : (memref<?xf64>, memref<?xf64>, // CHECK-NEXT: call @sum(%1, %arg0, %c1_i32) : (memref<?xf64>, memref<?xf64>, i32) -> ()
// i32) -> () CHECK-NEXT: %2 = affine.load %0[0] : memref<1xf64> CHECK-NEXT: // CHECK-NEXT: %2 = affine.load %0[0] : memref<1xf64>
// %3 = call @print(%2) : (f64) -> i32 CHECK-NEXT: return CHECK-NEXT: } // CHECK-NEXT: %3 = call @print(%2) : (f64) -> i32
// CHECK-NEXT: return
// CHECK-NEXT: }
// CHECK: func @sum(%arg0: memref<?xf64>, %arg1: memref<?xf64>, %arg2: i32) { // CHECK: func @sum(%arg0: memref<?xf64>, %arg1: memref<?xf64>, %arg2: i32) {
// CHECK-NEXT: %c0_i32 = constant 0 : i32 // CHECK-NEXT: %c0_i32 = constant 0 : i32
@ -35,8 +37,8 @@ void caller(double *array) {
// CHECK-NEXT: affine.for %arg3 = 0 to %0 { // CHECK-NEXT: affine.for %arg3 = 0 to %0 {
// CHECK-NEXT: affine.store %1, %arg0[0] : memref<?xf64> // CHECK-NEXT: affine.store %1, %arg0[0] : memref<?xf64>
// CHECK-NEXT: %2 = affine.load %arg0[0] : memref<?xf64> // CHECK-NEXT: %2 = affine.load %arg0[0] : memref<?xf64>
// CHECK-NEXT: %3 = affine.for %arg4 = 0 to 10 iter_args(%arg5 = %2) -> // CHECK-NEXT: %3 = affine.for %arg4 = 0 to 10 iter_args(%arg5 = %2) -> (f64) {
// (f64) { CHECK-NEXT: %6 = affine.load %arg1[%arg4] : memref<?xf64> // CHECK-NEXT: %6 = affine.load %arg1[%arg4] : memref<?xf64>
// CHECK-NEXT: %7 = addf %arg5, %6 : f64 // CHECK-NEXT: %7 = addf %arg5, %6 : f64
// CHECK-NEXT: affine.yield %7 : f64 // CHECK-NEXT: affine.yield %7 : f64
// CHECK-NEXT: } // CHECK-NEXT: }

View File

@ -2,19 +2,19 @@
extern int print(double); extern int print(double);
void sum(double *result, double *array) { void sum(double *result, double* array) {
result[0] = 0; result[0] = 0;
#pragma scop #pragma scop
for (int i = 0; i < 10; i++) { for (int i=0; i<10; i++) {
result[0] += array[i]; result[0] += array[i];
} }
#pragma endscop #pragma endscop
} }
void caller(double *array) { void caller(double* array) {
double result; double result;
sum(&result, array); sum(&result, array);
print(result); print(result);
} }
// CHECK: func @caller(%arg0: memref<?xf64>) { // CHECK: func @caller(%arg0: memref<?xf64>) {
@ -31,8 +31,11 @@ void caller(double *array) {
// CHECK-NEXT: %0 = sitofp %c0_i32 : i32 to f64 // CHECK-NEXT: %0 = sitofp %c0_i32 : i32 to f64
// CHECK-NEXT: affine.store %0, %arg0[0] : memref<?xf64> // CHECK-NEXT: affine.store %0, %arg0[0] : memref<?xf64>
// CHECK-NEXT: %1 = affine.load %arg0[0] : memref<?xf64> // CHECK-NEXT: %1 = affine.load %arg0[0] : memref<?xf64>
// CHECK-NEXT: %2 = affine.for %arg2 = 0 to 10 iter_args(%arg3 = %1) -> (f64) // CHECK-NEXT: %2 = affine.for %arg2 = 0 to 10 iter_args(%arg3 = %1) -> (f64) {
// { CHECK-NEXT: %3 = affine.load %arg1[%arg2] : memref<?xf64> CHECK-NEXT: // CHECK-NEXT: %3 = affine.load %arg1[%arg2] : memref<?xf64>
// %4 = addf %arg3, %3 : f64 CHECK-NEXT: affine.yield %4 : f64 CHECK-NEXT: // CHECK-NEXT: %4 = addf %arg3, %3 : f64
// } CHECK-NEXT: affine.store %2, %arg0[0] : memref<?xf64> CHECK-NEXT: return // CHECK-NEXT: affine.yield %4 : f64
// CHECK-NEXT: }
// CHECK-NEXT: affine.store %2, %arg0[0] : memref<?xf64>
// CHECK-NEXT: return
// CHECK-NEXT: } // CHECK-NEXT: }

View File

@ -43,3 +43,4 @@ void reduction_sum() {
sum += A[i]; sum += A[i];
#pragma endscop #pragma endscop
} }

View File

@ -1,5 +1,4 @@
// RUN: mlir-clang %s --function=kernel_correlation --raise-scf-to-affine | // RUN: mlir-clang %s --function=kernel_correlation --raise-scf-to-affine | FileCheck %s
// FileCheck %s
#define DATA_TYPE double #define DATA_TYPE double

View File

@ -6,26 +6,30 @@
/* Main computational kernel. The whole function will be timed, /* Main computational kernel. The whole function will be timed,
including the call and return. */ including the call and return. */
void kernel_correlation(double out[28], double stddev[28], _Bool cmp) { void kernel_correlation(double out[28], double stddev[28], _Bool cmp)
{
int j; int j;
#pragma scop #pragma scop
for (j = 0; j < 28; j++) { for (j = 0; j < 28; j++)
stddev[j] = 0.0; {
stddev[j] = 3.14; stddev[j] = 0.0;
/* The following in an inelegant but usual way to handle stddev[j] = 3.14;
near-zero std. dev. values, which below would cause a zero- /* The following in an inelegant but usual way to handle
divide. */ near-zero std. dev. values, which below would cause a zero-
divide. */
out[j] = cmp ? 1.0 : stddev[j];
} out[j] = cmp ? 1.0 : stddev[j];
}
#pragma endscop #pragma endscop
} }
// CHECK: func @kernel_correlation(%arg0: memref<?xf64>, %arg1: memref<?xf64>, // CHECK: func @kernel_correlation(%arg0: memref<?xf64>, %arg1: memref<?xf64>, %arg2: i1) {
// %arg2: i1) { CHECK-DAG: %[[cst:.+]] = constant 1.000000e+00 : f64 // CHECK-DAG: %[[cst:.+]] = constant 1.000000e+00 : f64
// CHECK-DAG: %[[cst_0:.+]] = constant 3.140000e+00 : f64 // CHECK-DAG: %[[cst_0:.+]] = constant 3.140000e+00 : f64
// CHECK: %0 = select %arg2, %[[cst]], %[[cst_0]] : f64 // CHECK: %0 = select %arg2, %[[cst]], %[[cst_0]] : f64
// CHECK-NEXT: affine.for %arg3 = 0 to 28 { // CHECK-NEXT: affine.for %arg3 = 0 to 28 {

View File

@ -1,5 +1,4 @@
// RUN: mlir-clang %s --function=kernel_correlation --raise-scf-to-affine | // RUN: mlir-clang %s --function=kernel_correlation --raise-scf-to-affine | FileCheck %s
// FileCheck %s
#define DATA_TYPE double #define DATA_TYPE double
@ -7,8 +6,9 @@
/* Main computational kernel. The whole function will be timed, /* Main computational kernel. The whole function will be timed,
including the call and return. */ including the call and return. */
void kernel_correlation(int m, double corr[28]) { void kernel_correlation(int m, double corr[28])
for (int i = 0; i < m - 1; i++) { {
for (int i = 0; i < m-1; i++) {
corr[i] = 0.; corr[i] = 0.;
} }
} }

View File

@ -1,5 +1,4 @@
// RUN: mlir-clang %s --function=kernel_correlation --raise-scf-to-affine | // RUN: mlir-clang %s --function=kernel_correlation --raise-scf-to-affine | FileCheck %s
// FileCheck %s
#define DATA_TYPE double #define DATA_TYPE double
@ -7,14 +6,17 @@
/* Main computational kernel. The whole function will be timed, /* Main computational kernel. The whole function will be timed,
including the call and return. */ including the call and return. */
void kernel_correlation(int m, double corr[28][28]) { void kernel_correlation(int m, double corr[28][28])
int i, j, k; {
// i = 0; int i, j, k;
for (i = 0; i < 28; i++) { //i = 0;
for (j = i + 1; j < m; j++) { for (i = 0; i < 28; i++)
corr[i][j] = SCALAR_VAL(0.0); {
for (j = i+1; j < m; j++)
{
corr[i][j] = SCALAR_VAL(0.0);
}
} }
}
} }
// CHECK: func @kernel_correlation(%arg0: i32, %arg1: memref<?x28xf64>) { // CHECK: func @kernel_correlation(%arg0: i32, %arg1: memref<?x28xf64>) {

View File

@ -1,5 +1,4 @@
// RUN: mlir-clang %s --function=kernel_correlation --raise-scf-to-affine | // RUN: mlir-clang %s --function=kernel_correlation --raise-scf-to-affine | FileCheck %s
// FileCheck %s
#define DATA_TYPE double #define DATA_TYPE double
@ -9,7 +8,8 @@ void use(int i);
/* Main computational kernel. The whole function will be timed, /* Main computational kernel. The whole function will be timed,
including the call and return. */ including the call and return. */
void kernel_correlation(double A[28], double B[28]) { void kernel_correlation(double A[28], double B[28])
{
int i; int i;
for (i = 1; i < 10; i++) { for (i = 1; i < 10; i++) {
A[i] = 0.; A[i] = 0.;
@ -19,11 +19,13 @@ void kernel_correlation(double A[28], double B[28]) {
} }
} }
// CHECK: func @kernel_correlation(%arg0: memref<?xf64>, %arg1: memref<?xf64>) // CHECK: func @kernel_correlation(%arg0: memref<?xf64>, %arg1: memref<?xf64>) {
// { CHECK-NEXT: %cst = constant 0.000000e+00 : f64 CHECK-NEXT: affine.for // CHECK-NEXT: %cst = constant 0.000000e+00 : f64
// %arg2 = 1 to 10 { CHECK-NEXT: affine.store %cst, %arg0[%arg2] : // CHECK-NEXT: affine.for %arg2 = 1 to 10 {
// memref<?xf64> CHECK-NEXT: } CHECK-NEXT: affine.for %arg2 = 1 to // CHECK-NEXT: affine.store %cst, %arg0[%arg2] : memref<?xf64>
// 10 { CHECK-NEXT: affine.store %cst, %arg1[%arg2] : memref<?xf64> // CHECK-NEXT: }
// CHECK-NEXT: affine.for %arg2 = 1 to 10 {
// CHECK-NEXT: affine.store %cst, %arg1[%arg2] : memref<?xf64>
// CHECK-NEXT: } // CHECK-NEXT: }
// CHECK-NEXT: return // CHECK-NEXT: return
// CHECK-NEXT: } // CHECK-NEXT: }

View File

@ -1,10 +1,12 @@
// RUN: mlir-clang %s --function=kernel_deriche | FileCheck %s // RUN: mlir-clang %s --function=kernel_deriche | FileCheck %s
void sub(int *a) { *a = 3; } void sub(int *a) {
*a = 3;
}
void kernel_deriche() { void kernel_deriche() {
int a; int a;
sub(&a); sub(&a);
} }
// CHECK: func @kernel_deriche() { // CHECK: func @kernel_deriche() {

View File

@ -1,5 +1,4 @@
// RUN: mlir-clang %s --function=kernel_correlation --raise-scf-to-affine | // RUN: mlir-clang %s --function=kernel_correlation --raise-scf-to-affine | FileCheck %s
// FileCheck %s
#define DATA_TYPE double #define DATA_TYPE double
@ -7,26 +6,32 @@
/* Main computational kernel. The whole function will be timed, /* Main computational kernel. The whole function will be timed,
including the call and return. */ including the call and return. */
void kernel_correlation(int n, double alpha, double beta, double A[28][28], void kernel_correlation(int n, double alpha, double beta,
double B[28][28], double tmp[28], double x[28], double A[28][28],
double y[28]) { double B[28][28],
double tmp[28],
double x[28],
double y[28])
{
int i, j; int i, j;
for (i = 0; i < n; i++) { for (i = 0; i < n; i++)
tmp[i] = SCALAR_VAL(0.0); {
y[i] = SCALAR_VAL(0.0); tmp[i] = SCALAR_VAL(0.0);
for (j = 0; j < n; j++) { y[i] = SCALAR_VAL(0.0);
tmp[i] = A[i][j] * x[j] + tmp[i]; for (j = 0; j < n; j++)
y[i] = B[i][j] * x[j] + y[i]; {
tmp[i] = A[i][j] * x[j] + tmp[i];
y[i] = B[i][j] * x[j] + y[i];
}
y[i] = alpha * tmp[i] + beta * y[i];
} }
y[i] = alpha * tmp[i] + beta * y[i];
}
} }
// CHECK: func @kernel_correlation(%arg0: i32, %arg1: f64, %arg2: f64, %arg3: // CHECK: func @kernel_correlation(%arg0: i32, %arg1: f64, %arg2: f64, %arg3: memref<?x28xf64>, %arg4: memref<?x28xf64>, %arg5: memref<?xf64>, %arg6: memref<?xf64>, %arg7: memref<?xf64>) {
// memref<?x28xf64>, %arg4: memref<?x28xf64>, %arg5: memref<?xf64>, %arg6: // CHECK-NEXT: %cst = constant 0.000000e+00 : f64
// memref<?xf64>, %arg7: memref<?xf64>) { CHECK-NEXT: %cst = constant // CHECK-NEXT: %0 = index_cast %arg0 : i32 to index
// 0.000000e+00 : f64 CHECK-NEXT: %0 = index_cast %arg0 : i32 to index
// CHECK-NEXT: affine.for %arg8 = 0 to %0 { // CHECK-NEXT: affine.for %arg8 = 0 to %0 {
// CHECK-NEXT: affine.store %cst, %arg5[%arg8] : memref<?xf64> // CHECK-NEXT: affine.store %cst, %arg5[%arg8] : memref<?xf64>
// CHECK-NEXT: affine.store %cst, %arg7[%arg8] : memref<?xf64> // CHECK-NEXT: affine.store %cst, %arg7[%arg8] : memref<?xf64>

View File

@ -1,17 +1,16 @@
// RUN: mlir-clang %s -detect-reduction --function=kernel_nussinov | FileCheck // RUN: mlir-clang %s -detect-reduction --function=kernel_nussinov | FileCheck %s
// %s
#define max_score(s1, s2) ((s1 >= s2) ? s1 : s2) #define max_score(s1, s2) ((s1 >= s2) ? s1 : s2)
void set(double table[20]); void set(double table[20]);
void kernel_nussinov(double *out, int n) { void kernel_nussinov(double* out, int n) {
double table[20]; double table[20];
set(table); set(table);
#pragma scop #pragma scop
for (int k = 0; k < 10; k++) { for (int k=0; k<10; k++) {
out[n] = max_score(out[n], table[k]); out[n] = max_score(out[n], table[k]);
} }
//} //}
#pragma endscop #pragma endscop
} }
@ -22,8 +21,8 @@ void kernel_nussinov(double *out, int n) {
// CHECK-NEXT: %2 = memref.cast %0 : memref<20xf64> to memref<?xf64> // CHECK-NEXT: %2 = memref.cast %0 : memref<20xf64> to memref<?xf64>
// CHECK-NEXT: call @set(%2) : (memref<?xf64>) -> () // CHECK-NEXT: call @set(%2) : (memref<?xf64>) -> ()
// CHECK-NEXT: %3 = affine.load %arg0[symbol(%1)] : memref<?xf64> // CHECK-NEXT: %3 = affine.load %arg0[symbol(%1)] : memref<?xf64>
// CHECK-NEXT: %4 = affine.for %arg2 = 0 to 10 iter_args(%arg3 = %3) -> // CHECK-NEXT: %4 = affine.for %arg2 = 0 to 10 iter_args(%arg3 = %3) -> (f64) {
// (f64) { CHECK-NEXT: %5 = affine.load %0[%arg2] : memref<20xf64> // CHECK-NEXT: %5 = affine.load %0[%arg2] : memref<20xf64>
// CHECK-NEXT: %6 = cmpf uge, %arg3, %5 : f64 // CHECK-NEXT: %6 = cmpf uge, %arg3, %5 : f64
// CHECK-NEXT: %7 = select %6, %arg3, %5 : f64 // CHECK-NEXT: %7 = select %6, %arg3, %5 : f64
// CHECK-NEXT: affine.yield %7 : f64 // CHECK-NEXT: affine.yield %7 : f64

View File

@ -4,7 +4,9 @@ typedef struct {
int a, b, c; int a, b, c;
} threeInt; } threeInt;
int struct_pass_all_same(threeInt *a) { return a->b; } int struct_pass_all_same(threeInt* a) {
return a->b;
}
// CHECK: func @struct_pass_all_same(%arg0: memref<?x3xi32>) -> i32 { // CHECK: func @struct_pass_all_same(%arg0: memref<?x3xi32>) -> i32 {
// CHECK-NEXT: %0 = affine.load %arg0[0, 1] : memref<?x3xi32> // CHECK-NEXT: %0 = affine.load %arg0[0, 1] : memref<?x3xi32>

View File

@ -1,19 +1,18 @@
// RUN: mlir-clang %s --function=kernel_correlation --raise-scf-to-affine | // RUN: mlir-clang %s --function=kernel_correlation --raise-scf-to-affine | FileCheck %s
// FileCheck %s
#define DATA_TYPE double #define DATA_TYPE double
#define N 10 #define N 10
#define match(b1, b2) (((b1) + (b2)) == 3 ? 1 : 0) #define match(b1, b2) (((b1)+(b2)) == 3 ? 1 : 0)
#define max_score(s1, s2) ((s1 >= s2) ? s1 : s2) #define max_score(s1, s2) ((s1 >= s2) ? s1 : s2)
/* Main computational kernel. The whole function will be timed, /* Main computational kernel. The whole function will be timed,
including the call and return. */ including the call and return. */
void kernel_correlation(int table[N][N]) { void kernel_correlation(int table[N][N]) {
for (int i = 9; i >= 0; i--) { for (int i = 9; i >= 0; i--) {
for (int j = 0; j < 10; j++) { for (int j=0; j<10; j++) {
table[i][j] = i + j; table[i][j] = i+j;
} }
} }
} }
@ -26,6 +25,8 @@ void kernel_correlation(int table[N][N]) {
// CHECK-NEXT: affine.for %arg2 = 0 to 10 { // CHECK-NEXT: affine.for %arg2 = 0 to 10 {
// CHECK-NEXT: %2 = index_cast %arg2 : index to i32 // CHECK-NEXT: %2 = index_cast %arg2 : index to i32
// CHECK-NEXT: %3 = addi %1, %2 : i32 // CHECK-NEXT: %3 = addi %1, %2 : i32
// CHECK-NEXT: affine.store %3, %arg0[-%arg1 + 9, %arg2] : // CHECK-NEXT: affine.store %3, %arg0[-%arg1 + 9, %arg2] : memref<?x10xi32>
// memref<?x10xi32> CHECK-NEXT: } CHECK-NEXT: } CHECK-NEXT: return // CHECK-NEXT: }
// CHECK-NEXT: }
// CHECK-NEXT: return
// CHECK-NEXT: } // CHECK-NEXT: }

View File

@ -1,21 +1,22 @@
// RUN: mlir-clang %s %stdinclude --function=set | FileCheck %s // RUN: mlir-clang %s %stdinclude --function=set | FileCheck %s
#include <math.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <unistd.h> #include <unistd.h>
#include <string.h>
#include <math.h>
/* Array initialization. */ /* Array initialization. */
void set(int path[20]) { void set (int path[20])
int i = 0; {
while (1) { int i = 0;
path[i] = 3; while (1) {
i++; path[i] = 3;
if (i == 20) i++;
break; if (i == 20) break;
} }
// path[0][1] = 2; //path[0][1] = 2;
} }
// TODO consider making into for // TODO consider making into for
@ -25,11 +26,13 @@ void set(int path[20]) {
// CHECK-DAG: %c3_i32 = constant 3 : i32 // CHECK-DAG: %c3_i32 = constant 3 : i32
// CHECK-DAG: %c20_i32 = constant 20 : i32 // CHECK-DAG: %c20_i32 = constant 20 : i32
// CHECK-DAG: %true = constant true // CHECK-DAG: %true = constant true
// CHECK-NEXT: %0 = scf.while (%arg1 = %true, %arg2 = %c0_i32) : (i1, i32) // CHECK-NEXT: %0 = scf.while (%arg1 = %true, %arg2 = %c0_i32) : (i1, i32) -> i32 {
// -> i32 { CHECK-NEXT: scf.condition(%arg1) %arg2 : i32 CHECK-NEXT: } // CHECK-NEXT: scf.condition(%arg1) %arg2 : i32
// do { CHECK-NEXT: ^bb0(%arg1: i32): // no predecessors CHECK-NEXT: %1 = // CHECK-NEXT: } do {
// index_cast %arg1 : i32 to index CHECK-NEXT: memref.store %c3_i32, // CHECK-NEXT: ^bb0(%arg1: i32): // no predecessors
// %arg0[%1] : memref<?xi32> CHECK-NEXT: %2 = addi %arg1, %c1_i32 : i32 // CHECK-NEXT: %1 = index_cast %arg1 : i32 to index
// CHECK-NEXT: memref.store %c3_i32, %arg0[%1] : memref<?xi32>
// CHECK-NEXT: %2 = addi %arg1, %c1_i32 : i32
// CHECK-NEXT: %3 = cmpi ne, %2, %c20_i32 : i32 // CHECK-NEXT: %3 = cmpi ne, %2, %c20_i32 : i32
// CHECK-NEXT: scf.yield %3, %2 : i1, i32 // CHECK-NEXT: scf.yield %3, %2 : i1, i32
// CHECK-NEXT: } // CHECK-NEXT: }

View File

@ -31,22 +31,23 @@ void whiletofor() {
// CHECK-NEXT: %c3_i32 = constant 3 : i32 // CHECK-NEXT: %c3_i32 = constant 3 : i32
// CHECK-NEXT: %c1_i32 = constant 1 : i32 // CHECK-NEXT: %c1_i32 = constant 1 : i32
// CHECK-NEXT: %0 = memref.alloca() : memref<100x100xi32> // CHECK-NEXT: %0 = memref.alloca() : memref<100x100xi32>
// CHECK-NEXT: %1 = scf.for %arg0 = %c0 to %c100 step %c1 iter_args(%arg1 = // CHECK-NEXT: %1 = scf.for %arg0 = %c0 to %c100 step %c1 iter_args(%arg1 = %c7_i32) -> (i32) {
// %c7_i32) -> (i32) { CHECK-NEXT: %3 = scf.for %arg2 = %c0 to %c100 step // CHECK-NEXT: %3 = scf.for %arg2 = %c0 to %c100 step %c1 iter_args(%arg3 = %arg1) -> (i32) {
// %c1 iter_args(%arg3 = %arg1) -> (i32) { CHECK-NEXT: %4 = index_cast // CHECK-NEXT: %4 = index_cast %arg2 : index to i32
// %arg2 : index to i32 CHECK-NEXT: %5 = addi %4, %arg1 : i32 // CHECK-NEXT: %5 = addi %4, %arg1 : i32
// CHECK-NEXT: %[[i4:.+]] = remi_signed %5, %c20_i32 : i32 // CHECK-NEXT: %[[i4:.+]] = remi_signed %5, %c20_i32 : i32
// CHECK-NEXT: %[[i5:.+]] = cmpi eq, %[[i4]], %c0_i32 : i32 // CHECK-NEXT: %[[i5:.+]] = cmpi eq, %[[i4]], %c0_i32 : i32
// CHECK-NEXT: scf.if %[[i5]] { // CHECK-NEXT: scf.if %[[i5]] {
// CHECK-NEXT: memref.store %c2_i32, %0[%arg0, %arg2] : // CHECK-NEXT: memref.store %c2_i32, %0[%arg0, %arg2] : memref<100x100xi32>
// memref<100x100xi32> CHECK-NEXT: } else { CHECK-NEXT: memref.store // CHECK-NEXT: } else {
// %c3_i32, %0[%arg0, %arg2] : memref<100x100xi32> CHECK-NEXT: } // CHECK-NEXT: memref.store %c3_i32, %0[%arg0, %arg2] : memref<100x100xi32>
// CHECK-NEXT: }
// CHECK-NEXT: %[[i6:.+]] = addi %5, %c1_i32 : i32 // CHECK-NEXT: %[[i6:.+]] = addi %5, %c1_i32 : i32
// CHECK-NEXT: scf.yield %[[i6]] : i32 // CHECK-NEXT: scf.yield %[[i6]] : i32
// CHECK-NEXT: } // CHECK-NEXT: }
// CHECK-NEXT: scf.yield %3 : i32 // CHECK-NEXT: scf.yield %3 : i32
// CHECK-NEXT: } // CHECK-NEXT: }
// CHECK-NEXT: %2 = memref.cast %0 : memref<100x100xi32> to // CHECK-NEXT: %2 = memref.cast %0 : memref<100x100xi32> to memref<?x100xi32>
// memref<?x100xi32> CHECK-NEXT: call @use(%2) : (memref<?x100xi32>) -> () // CHECK-NEXT: call @use(%2) : (memref<?x100xi32>) -> ()
// CHECK-NEXT: return // CHECK-NEXT: return
// CHECK-NEXT: } // CHECK-NEXT: }

View File

@ -1,10 +1,10 @@
// RUN: mlir-clang %s --function=kernel_deriche | FileCheck %s // RUN: mlir-clang %s --function=kernel_deriche | FileCheck %s
int kernel_deriche(int x) { int kernel_deriche(int x) {
x++; x++;
x += 3; x+=3;
x *= 2; x*=2;
return x; return x;
} }
// CHECK: func @kernel_deriche(%arg0: i32) -> i32 { // CHECK: func @kernel_deriche(%arg0: i32) -> i32 {