Skip to content

Commit 6192d54

Browse files
committed
Fix switch elimination test patterns - verified locally
Signed-off-by: devalgupta404 <devalgupta4@gmail.com>
1 parent 4a315d6 commit 6192d54

File tree

1 file changed

+32
-31
lines changed

1 file changed

+32
-31
lines changed

test/Transforms/Passes/switch-elimination.mlir

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,71 +12,72 @@
1212
module {
1313
p4hir.control @c(%arg0: !p4hir.ref<!b32i> {p4hir.dir = #p4hir<dir inout>, p4hir.param_name = "b"})() {
1414
// Verify action functions are created with hidden annotation.
15-
// CHECK-DAG: p4hir.func action @[[CASE_0:_switch_[0-9]+_case_0]]() annotations {hidden} {
15+
// CHECK-DAG: p4hir.func action @_switch_{{[0-9]+}}_case_0() annotations {hidden} {
1616
// CHECK-DAG: p4hir.return
1717
// CHECK-DAG: }
18-
// CHECK-DAG: p4hir.func action @[[CASE_1:_switch_[0-9]+_case_1]]() annotations {hidden} {
18+
// CHECK-DAG: p4hir.func action @_switch_{{[0-9]+}}_case_1() annotations {hidden} {
1919
// CHECK-DAG: p4hir.return
2020
// CHECK-DAG: }
21-
// CHECK-DAG: p4hir.func action @[[DEFAULT:_switch_[0-9]+_default]]() annotations {hidden} {
21+
// CHECK-DAG: p4hir.func action @_switch_{{[0-9]+}}_default() annotations {hidden} {
2222
// CHECK-DAG: p4hir.return
2323
// CHECK-DAG: }
2424

2525
// Verify table structure with key, actions, default, and entries.
26-
// CHECK: p4hir.table @[[TABLE:_switch_[0-9]+_table]] annotations {hidden} {
26+
// CHECK: p4hir.table @_switch_{{[0-9]+}}_table annotations {hidden} {
2727
// CHECK: p4hir.table_key
2828
// CHECK: p4hir.match_key #exact
2929
// CHECK: p4hir.table_actions {
30-
// CHECK: p4hir.table_action @[[CASE_0]]() {
31-
// CHECK: p4hir.call @c::@[[CASE_0]] () : () -> ()
30+
// CHECK: p4hir.table_action @_switch_{{[0-9]+}}_case_0() {
31+
// CHECK: p4hir.call @c::@_switch_{{[0-9]+}}_case_0 () : () -> ()
3232
// CHECK: }
33-
// CHECK: p4hir.table_action @[[CASE_1]]() {
34-
// CHECK: p4hir.call @c::@[[CASE_1]] () : () -> ()
33+
// CHECK: p4hir.table_action @_switch_{{[0-9]+}}_case_1() {
34+
// CHECK: p4hir.call @c::@_switch_{{[0-9]+}}_case_1 () : () -> ()
3535
// CHECK: }
36-
// CHECK: p4hir.table_action @[[DEFAULT]]() {
37-
// CHECK: p4hir.call @c::@[[DEFAULT]] () : () -> ()
36+
// CHECK: p4hir.table_action @_switch_{{[0-9]+}}_default() {
37+
// CHECK: p4hir.call @c::@_switch_{{[0-9]+}}_default () : () -> ()
3838
// CHECK: }
3939
// CHECK: }
4040
// CHECK: p4hir.table_default_action {
41-
// CHECK: p4hir.call @c::@[[DEFAULT]] () : () -> ()
41+
// CHECK: p4hir.call @c::@_switch_{{[0-9]+}}_default () : () -> ()
4242
// CHECK: }
4343
// CHECK: p4hir.table_entries const {
4444
// CHECK: p4hir.table_entry #p4hir.aggregate<[#int16_b32i]> : tuple<!b32i> {
45-
// CHECK: p4hir.call @c::@[[CASE_0]] () : () -> ()
45+
// CHECK: p4hir.call @c::@_switch_{{[0-9]+}}_case_0 () : () -> ()
4646
// CHECK: }
4747
// CHECK: p4hir.table_entry #p4hir.aggregate<[#int32_b32i]> : tuple<!b32i> {
48-
// CHECK: p4hir.call @c::@[[CASE_0]] () : () -> ()
48+
// CHECK: p4hir.call @c::@_switch_{{[0-9]+}}_case_0 () : () -> ()
4949
// CHECK: }
5050
// CHECK: p4hir.table_entry #p4hir.aggregate<[#int2_b32i]> : tuple<!b32i> {
51-
// CHECK: p4hir.call @c::@[[CASE_1]] () : () -> ()
51+
// CHECK: p4hir.call @c::@_switch_{{[0-9]+}}_case_1 () : () -> ()
5252
// CHECK: }
5353
// CHECK: }
5454
// CHECK: }
5555

5656
// Verify table is applied directly with the condition (no intermediate variable).
57-
// CHECK: p4hir.control_apply
58-
// CHECK: p4hir.read
59-
// CHECK: p4hir.table_apply
60-
// CHECK: p4hir.struct_extract
61-
// CHECK: p4hir.switch
62-
// CHECK: p4hir.case(equal
63-
// CHECK: p4hir.const #int1_b32i
64-
// CHECK: p4hir.assign
57+
// CHECK: p4hir.control_apply {
58+
// CHECK: %{{.*}} = p4hir.read %arg0 : <!b32i>
59+
// CHECK-NEXT: %{{.*}} = p4hir.table_apply @c::@_switch_{{[0-9]+}}_table with key{{.*}}%{{.*}}
60+
// CHECK: %{{.*}} = p4hir.struct_extract %{{.*}}["action_run"]
61+
// CHECK: p4hir.switch (%{{.*}}{{.*}}) {
62+
// CHECK: p4hir.case(equal, [#{{[_a-z0-9]+}}_switch_{{[0-9]+}}_case_0]) {
63+
// CHECK: %{{.*}} = p4hir.const #int1_b32i
64+
// CHECK: p4hir.assign %{{.*}}, %arg0 : <!b32i>
6565
// CHECK: p4hir.yield
6666
// CHECK: }
67-
// CHECK: p4hir.case(equal
68-
// CHECK: p4hir.const #int2_b32i
69-
// CHECK: p4hir.assign
67+
// CHECK: p4hir.case(equal, [#{{[_a-z0-9]+}}_switch_{{[0-9]+}}_case_1]) {
68+
// CHECK: %{{.*}} = p4hir.const #int2_b32i
69+
// CHECK: p4hir.assign %{{.*}}, %arg0 : <!b32i>
7070
// CHECK: p4hir.yield
7171
// CHECK: }
72-
// CHECK: p4hir.case(default
73-
// CHECK: p4hir.const #int3_b32i
74-
// CHECK: p4hir.assign
72+
// CHECK: p4hir.case(default, [#{{[_a-z0-9]+}}_switch_{{[0-9]+}}_default]) {
73+
// CHECK: %{{.*}} = p4hir.const #int3_b32i
74+
// CHECK: p4hir.assign %{{.*}}, %arg0 : <!b32i>
7575
// CHECK: p4hir.yield
7676
// CHECK: }
7777
// CHECK: p4hir.yield
7878
// CHECK: }
7979
// CHECK: }
80+
8081
p4hir.control_apply {
8182
%val = p4hir.read %arg0 : <!b32i>
8283
p4hir.switch (%val : !b32i) {
@@ -151,9 +152,9 @@ module {
151152

152153
// The switch on action_run should remain unchanged.
153154
// CHECK: p4hir.control_apply {
154-
// CHECK: %[[APPLY:.*]] = p4hir.table_apply @c_action_run::@t with key()
155-
// CHECK: %[[AR:.*]] = p4hir.struct_extract %[[APPLY]]["action_run"]
156-
// CHECK: p4hir.switch (%[[AR]] : !anon) {
155+
// CHECK: %{{.*}} = p4hir.table_apply @c_action_run::@t with key()
156+
// CHECK: %{{.*}} = p4hir.struct_extract %{{.*}}["action_run"]
157+
// CHECK: p4hir.switch (%{{.*}} : !anon) {
157158
// CHECK: p4hir.case(equal, [#anon_a1]) {
158159
// CHECK: p4hir.yield
159160
// CHECK: }

0 commit comments

Comments
 (0)