|
| 1 | +// RUN: p4mlir-opt --canonicalize %s | FileCheck %s |
| 2 | + |
| 3 | +!b8i = !p4hir.bit<8> |
| 4 | +#everything = #p4hir.universal_set : !p4hir.set<!p4hir.dontcare> |
| 5 | +#false = #p4hir.bool<false> : !p4hir.bool |
| 6 | +#true = #p4hir.bool<true> : !p4hir.bool |
| 7 | +#int1_b8i = #p4hir.int<1> : !b8i |
| 8 | +#int2_b8i = #p4hir.int<2> : !b8i |
| 9 | +#int8_b8i = #p4hir.int<8> : !b8i |
| 10 | +#set_const_of_false = #p4hir.set<const : [#false]> : !p4hir.set<!p4hir.bool> |
| 11 | +#set_const_of_true = #p4hir.set<const : [#true]> : !p4hir.set<!p4hir.bool> |
| 12 | +#set_const_of_int1_b8i = #p4hir.set<const : [#int1_b8i]> : !p4hir.set<!b8i> |
| 13 | +#set_const_of_int2_b8i = #p4hir.set<const : [#int2_b8i]> : !p4hir.set<!b8i> |
| 14 | +#set_const_of_int8_b8i = #p4hir.set<const : [#int8_b8i]> : !p4hir.set<!b8i> |
| 15 | + |
| 16 | +// CHECK-LABEL: module |
| 17 | +module { |
| 18 | + p4hir.parser @p1(%arg0: !b8i, %arg1: !p4hir.bool)() { |
| 19 | + %set = p4hir.const #set_const_of_int8_b8i |
| 20 | + %set_0 = p4hir.const #set_const_of_true |
| 21 | + %set_1 = p4hir.const #set_const_of_int2_b8i |
| 22 | + %set_2 = p4hir.const #set_const_of_false |
| 23 | + %set_3 = p4hir.const #set_const_of_int1_b8i |
| 24 | + %everything = p4hir.const #everything |
| 25 | + |
| 26 | + // CHECK-LABEL: p4hir.state @start |
| 27 | + p4hir.state @start { |
| 28 | + // CHECK-COUNT-2: p4hir.select_case |
| 29 | + // CHECK-NOT: p4hir.yield %everything, %everything : !p4hir.set<!p4hir.dontcare>, !p4hir.set<!p4hir.dontcare> |
| 30 | + // CHECK: p4hir.yield %everything : !p4hir.set<!p4hir.dontcare> |
| 31 | + // Remove dead cases; canonicalize default cases. |
| 32 | + p4hir.transition_select %arg0, %arg1 : !b8i, !p4hir.bool { |
| 33 | + p4hir.select_case { |
| 34 | + p4hir.yield %set_3, %set_2 : !p4hir.set<!b8i>, !p4hir.set<!p4hir.bool> |
| 35 | + } to @p1::@reject |
| 36 | + p4hir.select_case { |
| 37 | + p4hir.yield %everything, %everything : !p4hir.set<!p4hir.dontcare>, !p4hir.set<!p4hir.dontcare> |
| 38 | + } to @p1::@next |
| 39 | + p4hir.select_case { |
| 40 | + p4hir.yield %set_1, %set_0 : !p4hir.set<!b8i>, !p4hir.set<!p4hir.bool> |
| 41 | + } to @p1::@reject |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + // CHECK-LABEL: p4hir.state @next |
| 46 | + p4hir.state @next { |
| 47 | + // CHECK-NOT: p4hir.select_case |
| 48 | + // CHECK: p4hir.transition to @p1::@final |
| 49 | + // Replace select with one default case with direct transition. |
| 50 | + p4hir.transition_select %arg0, %arg1 : !b8i, !p4hir.bool { |
| 51 | + p4hir.select_case { |
| 52 | + p4hir.yield %everything, %everything : !p4hir.set<!p4hir.dontcare>, !p4hir.set<!p4hir.dontcare> |
| 53 | + } to @p1::@final |
| 54 | + p4hir.select_case { |
| 55 | + p4hir.yield %everything : !p4hir.set<!p4hir.dontcare> |
| 56 | + } to @p1::@reject |
| 57 | + p4hir.select_case { |
| 58 | + p4hir.yield %set, %set_2 : !p4hir.set<!b8i>, !p4hir.set<!p4hir.bool> |
| 59 | + } to @p1::@reject |
| 60 | + p4hir.select_case { |
| 61 | + p4hir.yield %everything : !p4hir.set<!p4hir.dontcare> |
| 62 | + } to @p1::@reject |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + p4hir.state @final { |
| 67 | + p4hir.transition to @p1::@accept |
| 68 | + } |
| 69 | + |
| 70 | + p4hir.state @accept { |
| 71 | + p4hir.parser_accept |
| 72 | + } |
| 73 | + |
| 74 | + p4hir.state @reject { |
| 75 | + p4hir.parser_reject |
| 76 | + } |
| 77 | + |
| 78 | + p4hir.transition to @p1::@start |
| 79 | + } |
| 80 | +} |
0 commit comments