From eff9984dca033af2727ff90e22fbfb3af4ce7d4c Mon Sep 17 00:00:00 2001 From: Mehdi Amini Date: Tue, 29 Sep 2020 20:19:23 +0000 Subject: [PATCH] Fix TODO in the mlir-cpu-runner/bare_ptr_call_conv.mlir test: call ops in bare-ptr calling convention is supported now (NFC) This was fixed in a89fc12653c. --- .../mlir-cpu-runner/bare_ptr_call_conv.mlir | 177 +++--------------- 1 file changed, 31 insertions(+), 146 deletions(-) diff --git a/mlir/test/mlir-cpu-runner/bare_ptr_call_conv.mlir b/mlir/test/mlir-cpu-runner/bare_ptr_call_conv.mlir index caa945d11b6c..6dc8b5576251 100644 --- a/mlir/test/mlir-cpu-runner/bare_ptr_call_conv.mlir +++ b/mlir/test/mlir-cpu-runner/bare_ptr_call_conv.mlir @@ -32,152 +32,37 @@ func @printF32(%arg0: f32) func @printComma() func @printNewline() -// TODO: 'main' function currently has to be provided in LLVM dialect since -// 'call' op is not yet supported by the bare pointer calling convention. The -// LLVM dialect version was generated using the following loop/std dialect -// version and minor changes around the 'simple_add1_add2_test' call. +func @main() +{ + %c2 = constant 2 : index + %c0 = constant 0 : index + %c1 = constant 1 : index + %cst = constant 1.000000e+00 : f32 + %cst_0 = constant 2.000000e+00 : f32 + %a = alloc() : memref<2xf32> + %b = alloc() : memref<2xf32> + scf.for %i = %c0 to %c2 step %c1 { + store %cst, %a[%i] : memref<2xf32> + store %cst, %b[%i] : memref<2xf32> + } -//func @main() -//{ -// %c2 = constant 2 : index -// %c0 = constant 0 : index -// %c1 = constant 1 : index -// %cst = constant 1.000000e+00 : f32 -// %cst_0 = constant 2.000000e+00 : f32 -// %a = alloc() : memref<2xf32> -// %b = alloc() : memref<2xf32> -// scf.for %i = %c0 to %c2 step %c1 { -// store %cst, %a[%i] : memref<2xf32> -// store %cst, %b[%i] : memref<2xf32> -// } -// -// call @simple_add1_add2_test(%a, %b) : (memref<2xf32>, memref<2xf32>) -> () -// -// %l0 = load %a[%c0] : memref<2xf32> -// call @printF32(%l0) : (f32) -> () -// call @printComma() : () -> () -// %l1 = load %a[%c1] : memref<2xf32> -// call @printF32(%l1) : (f32) -> () -// call @printNewline() : () -> () -// -// %l2 = load %b[%c0] : memref<2xf32> -// call @printF32(%l2) : (f32) -> () -// call @printComma() : () -> () -// %l3 = load %b[%c1] : memref<2xf32> -// call @printF32(%l3) : (f32) -> () -// call @printNewline() : () -> () -// -// dealloc %a : memref<2xf32> -// dealloc %b : memref<2xf32> -// return -//} + call @simple_add1_add2_test(%a, %b) : (memref<2xf32>, memref<2xf32>) -> () -llvm.func @main() { - %0 = llvm.mlir.constant(2 : index) : !llvm.i64 - %1 = llvm.mlir.constant(0 : index) : !llvm.i64 - %2 = llvm.mlir.constant(1 : index) : !llvm.i64 - %3 = llvm.mlir.constant(1.000000e+00 : f32) : !llvm.float - %4 = llvm.mlir.constant(2.000000e+00 : f32) : !llvm.float - %5 = llvm.mlir.constant(2 : index) : !llvm.i64 - %6 = llvm.mlir.null : !llvm.ptr - %7 = llvm.mlir.constant(1 : index) : !llvm.i64 - %8 = llvm.getelementptr %6[%7] : (!llvm.ptr, !llvm.i64) -> !llvm.ptr - %9 = llvm.ptrtoint %8 : !llvm.ptr to !llvm.i64 - %10 = llvm.mul %5, %9 : !llvm.i64 - %11 = llvm.call @malloc(%10) : (!llvm.i64) -> !llvm.ptr - %12 = llvm.bitcast %11 : !llvm.ptr to !llvm.ptr - %13 = llvm.mlir.undef : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)> - %14 = llvm.insertvalue %12, %13[0] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)> - %15 = llvm.insertvalue %12, %14[1] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)> - %16 = llvm.mlir.constant(0 : index) : !llvm.i64 - %17 = llvm.insertvalue %16, %15[2] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)> - %18 = llvm.mlir.constant(1 : index) : !llvm.i64 - %19 = llvm.insertvalue %5, %17[3, 0] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)> - %20 = llvm.insertvalue %18, %19[4, 0] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)> - %21 = llvm.mlir.constant(2 : index) : !llvm.i64 - %22 = llvm.mlir.null : !llvm.ptr - %23 = llvm.mlir.constant(1 : index) : !llvm.i64 - %24 = llvm.getelementptr %22[%23] : (!llvm.ptr, !llvm.i64) -> !llvm.ptr - %25 = llvm.ptrtoint %24 : !llvm.ptr to !llvm.i64 - %26 = llvm.mul %21, %25 : !llvm.i64 - %27 = llvm.call @malloc(%26) : (!llvm.i64) -> !llvm.ptr - %28 = llvm.bitcast %27 : !llvm.ptr to !llvm.ptr - %29 = llvm.mlir.undef : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)> - %30 = llvm.insertvalue %28, %29[0] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)> - %31 = llvm.insertvalue %28, %30[1] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)> - %32 = llvm.mlir.constant(0 : index) : !llvm.i64 - %33 = llvm.insertvalue %32, %31[2] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)> - %34 = llvm.mlir.constant(1 : index) : !llvm.i64 - %35 = llvm.insertvalue %21, %33[3, 0] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)> - %36 = llvm.insertvalue %34, %35[4, 0] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)> - llvm.br ^bb1(%1 : !llvm.i64) -^bb1(%37: !llvm.i64): // 2 preds: ^bb0, ^bb2 - %38 = llvm.icmp "slt" %37, %0 : !llvm.i64 - llvm.cond_br %38, ^bb2, ^bb3 -^bb2: // pred: ^bb1 - %39 = llvm.extractvalue %20[1] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)> - %40 = llvm.mlir.constant(0 : index) : !llvm.i64 - %41 = llvm.mlir.constant(1 : index) : !llvm.i64 - %42 = llvm.mul %37, %41 : !llvm.i64 - %43 = llvm.add %40, %42 : !llvm.i64 - %44 = llvm.getelementptr %39[%43] : (!llvm.ptr, !llvm.i64) -> !llvm.ptr - llvm.store %3, %44 : !llvm.ptr - %45 = llvm.extractvalue %36[1] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)> - %46 = llvm.mlir.constant(0 : index) : !llvm.i64 - %47 = llvm.mlir.constant(1 : index) : !llvm.i64 - %48 = llvm.mul %37, %47 : !llvm.i64 - %49 = llvm.add %46, %48 : !llvm.i64 - %50 = llvm.getelementptr %45[%49] : (!llvm.ptr, !llvm.i64) -> !llvm.ptr - llvm.store %3, %50 : !llvm.ptr - %51 = llvm.add %37, %2 : !llvm.i64 - llvm.br ^bb1(%51 : !llvm.i64) -^bb3: // pred: ^bb1 - %52 = llvm.mlir.constant(1 : index) : !llvm.i64 - %53 = llvm.mlir.constant(1 : index) : !llvm.i64 - %54 = llvm.extractvalue %20[1] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)> - %55 = llvm.extractvalue %36[1] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)> - llvm.call @simple_add1_add2_test(%54, %55) : (!llvm.ptr, !llvm.ptr) -> () - %56 = llvm.extractvalue %20[1] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)> - %57 = llvm.mlir.constant(0 : index) : !llvm.i64 - %58 = llvm.mlir.constant(1 : index) : !llvm.i64 - %59 = llvm.mul %1, %58 : !llvm.i64 - %60 = llvm.add %57, %59 : !llvm.i64 - %61 = llvm.getelementptr %56[%60] : (!llvm.ptr, !llvm.i64) -> !llvm.ptr - %62 = llvm.load %61 : !llvm.ptr - llvm.call @printF32(%62) : (!llvm.float) -> () - llvm.call @printComma() : () -> () - %63 = llvm.extractvalue %20[1] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)> - %64 = llvm.mlir.constant(0 : index) : !llvm.i64 - %65 = llvm.mlir.constant(1 : index) : !llvm.i64 - %66 = llvm.mul %2, %65 : !llvm.i64 - %67 = llvm.add %64, %66 : !llvm.i64 - %68 = llvm.getelementptr %63[%67] : (!llvm.ptr, !llvm.i64) -> !llvm.ptr - %69 = llvm.load %68 : !llvm.ptr - llvm.call @printF32(%69) : (!llvm.float) -> () - llvm.call @printNewline() : () -> () - %70 = llvm.extractvalue %36[1] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)> - %71 = llvm.mlir.constant(0 : index) : !llvm.i64 - %72 = llvm.mlir.constant(1 : index) : !llvm.i64 - %73 = llvm.mul %1, %72 : !llvm.i64 - %74 = llvm.add %71, %73 : !llvm.i64 - %75 = llvm.getelementptr %70[%74] : (!llvm.ptr, !llvm.i64) -> !llvm.ptr - %76 = llvm.load %75 : !llvm.ptr - llvm.call @printF32(%76) : (!llvm.float) -> () - llvm.call @printComma() : () -> () - %77 = llvm.extractvalue %36[1] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)> - %78 = llvm.mlir.constant(0 : index) : !llvm.i64 - %79 = llvm.mlir.constant(1 : index) : !llvm.i64 - %80 = llvm.mul %2, %79 : !llvm.i64 - %81 = llvm.add %78, %80 : !llvm.i64 - %82 = llvm.getelementptr %77[%81] : (!llvm.ptr, !llvm.i64) -> !llvm.ptr - %83 = llvm.load %82 : !llvm.ptr - llvm.call @printF32(%83) : (!llvm.float) -> () - llvm.call @printNewline() : () -> () - %84 = llvm.extractvalue %20[0] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)> - %85 = llvm.bitcast %84 : !llvm.ptr to !llvm.ptr - llvm.call @free(%85) : (!llvm.ptr) -> () - %86 = llvm.extractvalue %36[0] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)> - %87 = llvm.bitcast %86 : !llvm.ptr to !llvm.ptr - llvm.call @free(%87) : (!llvm.ptr) -> () - llvm.return + %l0 = load %a[%c0] : memref<2xf32> + call @printF32(%l0) : (f32) -> () + call @printComma() : () -> () + %l1 = load %a[%c1] : memref<2xf32> + call @printF32(%l1) : (f32) -> () + call @printNewline() : () -> () + + %l2 = load %b[%c0] : memref<2xf32> + call @printF32(%l2) : (f32) -> () + call @printComma() : () -> () + %l3 = load %b[%c1] : memref<2xf32> + call @printF32(%l3) : (f32) -> () + call @printNewline() : () -> () + + dealloc %a : memref<2xf32> + dealloc %b : memref<2xf32> + return }