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
"${LLVM_SOURCE_DIR}/../clang/include"
"${CMAKE_BINARY_DIR}/tools/clang/include")
#MLIRTransformsPassIncGen
target_include_directories(mlir-clang PRIVATE
"${LLVM_SOURCE_DIR}/../clang/include"
"${CMAKE_BINARY_DIR}/tools/clang/include"
)
# MLIRTransformsPassIncGen
target_compile_definitions(mlir - clang PUBLIC -
DLLVM_OBJ_ROOT = "${LLVM_BINARY_DIR}")
target_link_libraries(
mlir -
clang PRIVATE LLVMCore LLVMOption LLVMSupport
target_compile_definitions(mlir-clang PUBLIC -DLLVM_OBJ_ROOT="${LLVM_BINARY_DIR}")
target_link_libraries(mlir-clang PRIVATE
LLVMCore
LLVMOption
LLVMSupport
MLIRSCFTransforms MLIRPolygeist
MLIRSCFTransforms
MLIRPolygeist
MLIRSupport MLIRIR MLIRAnalysis MLIRLLVMIR MLIRNVVMIR
MLIRGPU MLIRTransforms MLIRSCFToStandard
MLIRStandardToLLVM MLIRAffineTransforms
MLIRAffineToStandard MLIRTargetLLVMIRImport
MLIRPolygeistTransforms
MLIRSupport
MLIRIR
MLIRAnalysis
MLIRLLVMIR
MLIRNVVMIR
MLIRGPU
MLIRTransforms
MLIRSCFToStandard
MLIRStandardToLLVM
MLIRAffineTransforms
MLIRAffineToStandard
MLIRTargetLLVMIRImport
MLIRPolygeistTransforms
clangAST clangBasic clangCodeGen
clangDriver clangFrontend
clangFrontendTool clangLex
clangSerialization)
add_dependencies(
mlir - clang MLIRPolygeistOpsIncGen MLIRPolygeistPassIncGen)
add_subdirectory(Test)
clangAST
clangBasic
clangCodeGen
clangDriver
clangFrontend
clangFrontendTool
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
void okernel_2mm(unsigned int ni, double *tmp) {
void okernel_2mm(unsigned int ni,
double *tmp) {
int i, j, k;
#pragma scop
/* D := alpha*A*B*C + beta*D */
for (i = 0; i < ni; i++) {
tmp[i] = 0.0;
}
for (i = 0; i < ni; i++)
{
tmp[i] = 0.0;
}
#pragma endscop
}

View File

@ -1,10 +1,12 @@
// 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() {
int a[2];
sub(a);
int a[2];
sub(a);
}
// CHECK: func @kernel_deriche() {

View File

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

View File

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

View File

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

View File

@ -1,8 +1,12 @@
// 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-NEXT: %0 = affine.load %arg0[0] : memref<?xi32>

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -2,19 +2,19 @@
extern int print(double);
void sum(double *result, double *array) {
result[0] = 0;
#pragma scop
for (int i = 0; i < 10; i++) {
result[0] += array[i];
}
#pragma endscop
void sum(double *result, double* array) {
result[0] = 0;
#pragma scop
for (int i=0; i<10; i++) {
result[0] += array[i];
}
#pragma endscop
}
void caller(double *array) {
double result;
sum(&result, array);
print(result);
void caller(double* array) {
double result;
sum(&result, array);
print(result);
}
// 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: affine.store %0, %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: %3 = affine.load %arg1[%arg2] : memref<?xf64> CHECK-NEXT:
// %4 = addf %arg3, %3 : f64 CHECK-NEXT: affine.yield %4 : f64 CHECK-NEXT:
// } CHECK-NEXT: affine.store %2, %arg0[0] : memref<?xf64> CHECK-NEXT: return
// 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: %4 = addf %arg3, %3 : f64
// CHECK-NEXT: affine.yield %4 : f64
// CHECK-NEXT: }
// CHECK-NEXT: affine.store %2, %arg0[0] : memref<?xf64>
// CHECK-NEXT: return
// CHECK-NEXT: }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,5 +1,4 @@
// RUN: mlir-clang %s --function=kernel_correlation --raise-scf-to-affine |
// FileCheck %s
// RUN: mlir-clang %s --function=kernel_correlation --raise-scf-to-affine | FileCheck %s
#define DATA_TYPE double
@ -7,26 +6,32 @@
/* Main computational kernel. The whole function will be timed,
including the call and return. */
void kernel_correlation(int n, double alpha, double beta, double A[28][28],
double B[28][28], double tmp[28], double x[28],
double y[28]) {
void kernel_correlation(int n, double alpha, double beta,
double A[28][28],
double B[28][28],
double tmp[28],
double x[28],
double y[28])
{
int i, j;
for (i = 0; i < n; i++) {
tmp[i] = SCALAR_VAL(0.0);
y[i] = SCALAR_VAL(0.0);
for (j = 0; j < n; j++) {
tmp[i] = A[i][j] * x[j] + tmp[i];
y[i] = B[i][j] * x[j] + y[i];
for (i = 0; i < n; i++)
{
tmp[i] = SCALAR_VAL(0.0);
y[i] = SCALAR_VAL(0.0);
for (j = 0; j < n; j++)
{
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:
// memref<?x28xf64>, %arg4: memref<?x28xf64>, %arg5: memref<?xf64>, %arg6:
// memref<?xf64>, %arg7: memref<?xf64>) { CHECK-NEXT: %cst = constant
// 0.000000e+00 : f64 CHECK-NEXT: %0 = index_cast %arg0 : i32 to index
// 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>) {
// CHECK-NEXT: %cst = constant 0.000000e+00 : f64
// CHECK-NEXT: %0 = index_cast %arg0 : i32 to index
// CHECK-NEXT: affine.for %arg8 = 0 to %0 {
// CHECK-NEXT: affine.store %cst, %arg5[%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
// %s
// RUN: mlir-clang %s -detect-reduction --function=kernel_nussinov | FileCheck %s
#define max_score(s1, s2) ((s1 >= s2) ? s1 : s2)
void set(double table[20]);
void kernel_nussinov(double *out, int n) {
void kernel_nussinov(double* out, int n) {
double table[20];
set(table);
#pragma scop
for (int k = 0; k < 10; k++) {
out[n] = max_score(out[n], table[k]);
}
for (int k=0; k<10; k++) {
out[n] = max_score(out[n], table[k]);
}
//}
#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: call @set(%2) : (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) ->
// (f64) { CHECK-NEXT: %5 = affine.load %0[%arg2] : memref<20xf64>
// CHECK-NEXT: %4 = affine.for %arg2 = 0 to 10 iter_args(%arg3 = %3) -> (f64) {
// CHECK-NEXT: %5 = affine.load %0[%arg2] : memref<20xf64>
// CHECK-NEXT: %6 = cmpf uge, %arg3, %5 : f64
// CHECK-NEXT: %7 = select %6, %arg3, %5 : f64
// CHECK-NEXT: affine.yield %7 : f64

View File

@ -4,7 +4,9 @@ typedef struct {
int a, b, c;
} 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-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 |
// FileCheck %s
// RUN: mlir-clang %s --function=kernel_correlation --raise-scf-to-affine | FileCheck %s
#define DATA_TYPE double
#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)
/* Main computational kernel. The whole function will be timed,
including the call and return. */
void kernel_correlation(int table[N][N]) {
for (int i = 9; i >= 0; i--) {
for (int j = 0; j < 10; j++) {
table[i][j] = i + j;
for (int i = 9; i >= 0; i--) {
for (int j=0; j<10; 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: %2 = index_cast %arg2 : index to i32
// CHECK-NEXT: %3 = addi %1, %2 : i32
// CHECK-NEXT: affine.store %3, %arg0[-%arg1 + 9, %arg2] :
// memref<?x10xi32> CHECK-NEXT: } CHECK-NEXT: } CHECK-NEXT: return
// CHECK-NEXT: affine.store %3, %arg0[-%arg1 + 9, %arg2] : memref<?x10xi32>
// CHECK-NEXT: }
// CHECK-NEXT: }
// CHECK-NEXT: return
// CHECK-NEXT: }

View File

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

View File

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

View File

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