|
| 1 | +// RUN: mlir-neura-opt %s \ |
| 2 | +// RUN: --assign-accelerator \ |
| 3 | +// RUN: --lower-llvm-to-neura \ |
| 4 | +// RUN: --leverage-predicated-value \ |
| 5 | +// RUN: | FileCheck %s |
| 6 | + |
| 7 | +// RUN: mlir-neura-opt %s \ |
| 8 | +// RUN: --assign-accelerator \ |
| 9 | +// RUN: --lower-llvm-to-neura \ |
| 10 | +// RUN: --leverage-predicated-value \ |
| 11 | +// RUN: --transform-ctrl-to-data-flow \ |
| 12 | +// RUN: | FileCheck %s -check-prefix=CTRL2DATA |
| 13 | + |
| 14 | +func.func @loop_test() -> f32 { |
| 15 | + %n = llvm.mlir.constant(10 : i64) : i64 |
| 16 | + %c0 = llvm.mlir.constant(0 : i64) : i64 |
| 17 | + %c1 = llvm.mlir.constant(1 : i64) : i64 |
| 18 | + %c1f = llvm.mlir.constant(3.0 : f32) : f32 |
| 19 | + %acc_init = llvm.mlir.constant(0.0 : f32) : f32 |
| 20 | + |
| 21 | + llvm.br ^bb1(%c0, %acc_init : i64, f32) |
| 22 | + |
| 23 | +^bb1(%i: i64, %acc: f32): // loop body + check + increment |
| 24 | + %next_acc = llvm.fadd %acc, %c1f : f32 |
| 25 | + %i_next = llvm.add %i, %c1 : i64 |
| 26 | + %cmp = llvm.icmp "slt" %i_next, %n : i64 |
| 27 | + llvm.cond_br %cmp, ^bb1(%i_next, %next_acc : i64, f32), ^exit(%next_acc : f32) |
| 28 | + |
| 29 | +^exit(%result: f32): |
| 30 | + return %result : f32 |
| 31 | +} |
| 32 | + |
| 33 | +// CHECK: func.func @loop_test() -> f32 attributes {accelerator = "neura"} { |
| 34 | +// CHECK-NEXT: %0 = "neura.constant"() <{predicate = true, value = 10 : i64}> : () -> !neura.data<i64, i1> |
| 35 | +// CHECK-NEXT: %1 = "neura.constant"() <{predicate = true, value = 0 : i64}> : () -> !neura.data<i64, i1> |
| 36 | +// CHECK-NEXT: %2 = "neura.constant"() <{predicate = true, value = 1 : i64}> : () -> !neura.data<i64, i1> |
| 37 | +// CHECK-NEXT: %3 = "neura.constant"() <{predicate = true, value = 3.000000e+00 : f32}> : () -> !neura.data<f32, i1> |
| 38 | +// CHECK-NEXT: %4 = "neura.constant"() <{predicate = true, value = 0.000000e+00 : f32}> : () -> !neura.data<f32, i1> |
| 39 | +// CHECK-NEXT: neura.br %1, %4 : !neura.data<i64, i1>, !neura.data<f32, i1> to ^bb1 |
| 40 | +// CHECK-NEXT: ^bb1(%5: !neura.data<i64, i1>, %6: !neura.data<f32, i1>): // 2 preds: ^bb0, ^bb1 |
| 41 | +// CHECK-NEXT: %7 = "neura.fadd"(%6, %3) : (!neura.data<f32, i1>, !neura.data<f32, i1>) -> !neura.data<f32, i1> |
| 42 | +// CHECK-NEXT: %8 = "neura.add"(%5, %2) : (!neura.data<i64, i1>, !neura.data<i64, i1>) -> !neura.data<i64, i1> |
| 43 | +// CHECK-NEXT: %9 = "neura.icmp"(%8, %0) <{cmpType = "slt"}> : (!neura.data<i64, i1>, !neura.data<i64, i1>) -> !neura.data<i1, i1> |
| 44 | +// CHECK-NEXT: neura.cond_br %9 : !neura.data<i1, i1> then %8, %7 : !neura.data<i64, i1>, !neura.data<f32, i1> to ^bb1 else %7 : !neura.data<f32, i1> to ^bb2 |
| 45 | +// CHECK-NEXT: ^bb2(%10: !neura.data<f32, i1>): // pred: ^bb1 |
| 46 | +// CHECK-NEXT: "neura.return"(%10) : (!neura.data<f32, i1>) -> () |
| 47 | +// CHECK-NEXT: } |
| 48 | + |
| 49 | +// CTRL2DATA: func.func @loop_test() -> f32 attributes {accelerator = "neura"} { |
| 50 | +// CTRL2DATA-NEXT: %0 = "neura.constant"() <{predicate = true, value = 10 : i64}> : () -> !neura.data<i64, i1> |
| 51 | +// CTRL2DATA-NEXT: %1 = "neura.constant"() <{predicate = true, value = 0 : i64}> : () -> !neura.data<i64, i1> |
| 52 | +// CTRL2DATA-NEXT: %2 = "neura.constant"() <{predicate = true, value = 1 : i64}> : () -> !neura.data<i64, i1> |
| 53 | +// CTRL2DATA-NEXT: %3 = "neura.constant"() <{predicate = true, value = 3.000000e+00 : f32}> : () -> !neura.data<f32, i1> |
| 54 | +// CTRL2DATA-NEXT: %4 = "neura.constant"() <{predicate = true, value = 0.000000e+00 : f32}> : () -> !neura.data<f32, i1> |
| 55 | +// CTRL2DATA-NEXT: %5 = neura.reserve : !neura.data<i64, i1> |
| 56 | +// CTRL2DATA-NEXT: %6 = "neura.phi"(%1, %5) : (!neura.data<i64, i1>, !neura.data<i64, i1>) -> !neura.data<i64, i1> |
| 57 | +// CTRL2DATA-NEXT: %7 = neura.reserve : !neura.data<f32, i1> |
| 58 | +// CTRL2DATA-NEXT: %8 = "neura.phi"(%4, %7) : (!neura.data<f32, i1>, !neura.data<f32, i1>) -> !neura.data<f32, i1> |
| 59 | +// CTRL2DATA-NEXT: %9 = "neura.fadd"(%8, %3) : (!neura.data<f32, i1>, !neura.data<f32, i1>) -> !neura.data<f32, i1> |
| 60 | +// CTRL2DATA-NEXT: neura.ctrl_mov %9 -> %7 : !neura.data<f32, i1> !neura.data<f32, i1> |
| 61 | +// CTRL2DATA-NEXT: %10 = "neura.add"(%6, %2) : (!neura.data<i64, i1>, !neura.data<i64, i1>) -> !neura.data<i64, i1> |
| 62 | +// CTRL2DATA-NEXT: neura.ctrl_mov %10 -> %5 : !neura.data<i64, i1> !neura.data<i64, i1> |
| 63 | +// CTRL2DATA-NEXT: %11 = "neura.icmp"(%10, %0) <{cmpType = "slt"}> : (!neura.data<i64, i1>, !neura.data<i64, i1>) -> !neura.data<i1, i1> |
| 64 | +// CTRL2DATA-NEXT: "neura.return"(%9) : (!neura.data<f32, i1>) -> () |
| 65 | +// CTRL2DATA-NEXT: } |
0 commit comments