117 lines · plain
1// RUN: mlir-opt %s -topological-sort | FileCheck %s2// RUN: mlir-opt %s -test-topological-sort-analysis -verify-diagnostics | FileCheck %s -check-prefix=CHECK-ANALYSIS3 4// Test producer is after user.5// CHECK-LABEL: test.graph_region6// CHECK-ANALYSIS-LABEL: test.graph_region7test.graph_region attributes{"root"} {8 // CHECK-NEXT: test.foo9 // CHECK-NEXT: test.baz10 // CHECK-NEXT: test.bar11 12 // CHECK-ANALYSIS-NEXT: test.foo{{.*}} {pos = 013 // CHECK-ANALYSIS-NEXT: test.bar{{.*}} {pos = 214 // CHECK-ANALYSIS-NEXT: test.baz{{.*}} {pos = 115 %0 = "test.foo"() {selected} : () -> i3216 "test.bar"(%1, %0) {selected} : (i32, i32) -> ()17 %1 = "test.baz"() {selected} : () -> i3218}19 20// Test cycles.21// CHECK-LABEL: test.graph_region22// CHECK-ANALYSIS-LABEL: test.graph_region23test.graph_region attributes{"root"} {24 // CHECK-NEXT: test.d25 // CHECK-NEXT: test.a26 // CHECK-NEXT: test.c27 // CHECK-NEXT: test.b28 29 // CHECK-ANALYSIS-NEXT: test.c{{.*}} {pos = 030 // CHECK-ANALYSIS-NEXT: test.b{{.*}} : (31 // CHECK-ANALYSIS-NEXT: test.a{{.*}} {pos = 232 // CHECK-ANALYSIS-NEXT: test.d{{.*}} {pos = 133 %2 = "test.c"(%1) {selected} : (i32) -> i3234 %1 = "test.b"(%0, %2) : (i32, i32) -> i3235 %0 = "test.a"(%3) {selected} : (i32) -> i3236 %3 = "test.d"() {selected} : () -> i3237}38 39// Test not all scheduled.40// CHECK-LABEL: test.graph_region41// CHECK-ANALYSIS-LABEL: test.graph_region42// expected-error@+1 {{could not schedule all ops}}43test.graph_region attributes{"root"} {44 %0 = "test.a"(%1) {selected} : (i32) -> i3245 %1 = "test.b"(%0) {selected} : (i32) -> i3246}47 48// CHECK-LABEL: func @test_multiple_blocks49// CHECK-ANALYSIS-LABEL: func @test_multiple_blocks50func.func @test_multiple_blocks() -> (i32) attributes{"root", "ordered"} {51 // CHECK-ANALYSIS-NEXT: test.foo{{.*}} {pos = 052 %0 = "test.foo"() {selected = 2} : () -> (i32)53 // CHECK-ANALYSIS-NEXT: test.foo54 %1 = "test.foo"() : () -> (i32)55 cf.br ^bb056^bb0:57 // CHECK-ANALYSIS: test.foo{{.*}} {pos = 158 %2 = "test.foo"() {selected = 3} : () -> (i32)59 // CHECK-ANALYSIS-NEXT: test.bar{{.*}} {pos = 260 %3 = "test.bar"(%0, %1, %2) {selected = 0} : (i32, i32, i32) -> (i32)61 cf.br ^bb1 (%2 : i32)62^bb1(%arg0: i32):63 // CHECK-ANALYSIS: test.qux{{.*}} {pos = 364 %4 = "test.qux"(%arg0, %0) {selected = 1} : (i32, i32) -> (i32)65 return %4 : i3266}67 68// Test block arguments.69// CHECK-LABEL: test.graph_region70test.graph_region {71// CHECK-NEXT: (%{{.*}}:72^entry(%arg0: i32):73 // CHECK-NEXT: test.foo74 // CHECK-NEXT: test.baz75 // CHECK-NEXT: test.bar76 %0 = "test.foo"(%arg0) : (i32) -> i3277 "test.bar"(%1, %0) : (i32, i32) -> ()78 %1 = "test.baz"(%arg0) : (i32) -> i3279}80 81// Test implicit block capture (and sort nested region).82// CHECK-LABEL: test.graph_region83func.func @test_graph_cfg() -> () {84 %0 = "test.foo"() : () -> i3285 cf.br ^next(%0 : i32)86 87^next(%1: i32):88 test.graph_region {89 // CHECK-NEXT: test.foo90 // CHECK-NEXT: test.baz91 // CHECK-NEXT: test.bar92 %2 = "test.foo"(%1) : (i32) -> i3293 "test.bar"(%3, %2) : (i32, i32) -> ()94 %3 = "test.baz"(%0) : (i32) -> i3295 }96 return97}98 99// Test region ops (and recursive sort).100// CHECK-LABEL: test.graph_region101test.graph_region {102 // CHECK-NEXT: test.baz103 // CHECK-NEXT: test.graph_region attributes {a} {104 // CHECK-NEXT: test.b105 // CHECK-NEXT: test.a106 // CHECK-NEXT: }107 // CHECK-NEXT: test.bar108 // CHECK-NEXT: test.foo109 %0 = "test.foo"(%1) : (i32) -> i32110 test.graph_region attributes {a} {111 %a = "test.a"(%b) : (i32) -> i32112 %b = "test.b"(%2) : (i32) -> i32113 }114 %1 = "test.bar"(%2) : (i32) -> i32115 %2 = "test.baz"() : () -> i32116}117