-
Notifications
You must be signed in to change notification settings - Fork 442
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#4656] Explicitly delay constant folding of only action enum `IR::Sw…
…itchCase` `label` expressions, instead of delaying constant folding of all `IR::Mux` expressions (#4657) * Delay constant folding IR::Mux expressions only if we are inside of a label of an action enum SwitchStatement * Apply IR::Mux constant folding logic to all switch case labels. We don't know if it is an action enum switch statement until after type inference has run. * Move issue3699 test to p4_16_samples/ as we now have the proper fix for #3699 * Add IR::SwitchCase preorder function instead of visiting all IR::Mux expressions. * appease cpplint * try to appease cpplint * Add test with compile-time constant expressions in labels of regular switch statement labels * Explicitly check whether SwitchCase belongs to a SwitchStatement with action_run expression * appease p4c-lint * Invert logic to skip visiting action_run SwitchCase labels * Move isActionRun() to anonymous namespace * Add comment about static_cast
- Loading branch information
Showing
21 changed files
with
406 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
File renamed without changes.
24 changes: 24 additions & 0 deletions
24
testdata/p4_16_samples/issue4656_const_fold_generic_switch_label_expr.p4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include <core.p4> | ||
|
||
extern void foo(); | ||
extern void bar(); | ||
extern bit<8> baz(); | ||
action a(){} | ||
action b(){} | ||
control c() { | ||
table t { | ||
actions = { a ; b; } | ||
} | ||
apply { | ||
switch(baz()) { | ||
1 + 2 == 3 ? 1 : 2 : { foo(); } | ||
3 + 4 == 0 ? 3 : 4 : { bar(); } | ||
} | ||
t.apply(); | ||
} | ||
} | ||
|
||
control C(); | ||
package top(C c); | ||
|
||
top(c()) main; |
22 changes: 22 additions & 0 deletions
22
testdata/p4_16_samples/issue4656_fold_bit_width_const_mux_expr.p4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
header h_t { | ||
bit<((10 == 1 ? 1 : 10 + 1) * (8+1))> f; | ||
} | ||
|
||
control C() { | ||
action bar() { | ||
} | ||
|
||
table t { | ||
actions = { bar; } | ||
default_action = bar; | ||
} | ||
|
||
apply { | ||
t.apply(); | ||
} | ||
} | ||
|
||
control proto(); | ||
package top(proto p); | ||
|
||
top(C()) main; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const bit<4> one = 4w1; | ||
const bit<4> max = 4w0xf; | ||
const bit<4> value = 4w0xf; | ||
const bit<4> value1 = 4w0xf; | ||
header h { | ||
} | ||
|
||
void f(in h[1] a) { | ||
} | ||
void f1(in h[1] a) { | ||
} | ||
void f1(in h[1] a) { | ||
} | ||
void f1(in h[1] a) { | ||
} | ||
const int<5> ones = 5s1; | ||
const int<5> maxs = 5s0xf; | ||
const int<5> values = 5s0xf; | ||
const int<5> values1 = 5s0xf; | ||
void f(in h[1] a) { | ||
} | ||
void f1(in h[1] a) { | ||
} | ||
void f1(in h[1] a) { | ||
} | ||
void f1(in h[1] a) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
header h { | ||
} | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[--Wwarn=missing] warning: Program does not contain a `main' module |
34 changes: 34 additions & 0 deletions
34
testdata/p4_16_samples_outputs/issue4656_const_fold_generic_switch_label_expr-first.p4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include <core.p4> | ||
|
||
extern void foo(); | ||
extern void bar(); | ||
extern bit<8> baz(); | ||
action a() { | ||
} | ||
action b() { | ||
} | ||
control c() { | ||
table t { | ||
actions = { | ||
a(); | ||
b(); | ||
@defaultonly NoAction(); | ||
} | ||
default_action = NoAction(); | ||
} | ||
apply { | ||
switch (baz()) { | ||
8w1: { | ||
foo(); | ||
} | ||
8w4: { | ||
bar(); | ||
} | ||
} | ||
t.apply(); | ||
} | ||
} | ||
|
||
control C(); | ||
package top(C c); | ||
top(c()) main; |
38 changes: 38 additions & 0 deletions
38
testdata/p4_16_samples_outputs/issue4656_const_fold_generic_switch_label_expr-frontend.p4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include <core.p4> | ||
|
||
extern void foo(); | ||
extern void bar(); | ||
extern bit<8> baz(); | ||
control c() { | ||
@name("c.tmp") bit<8> tmp; | ||
@name(".a") action a_0() { | ||
} | ||
@name(".b") action b_0() { | ||
} | ||
@noWarn("unused") @name(".NoAction") action NoAction_1() { | ||
} | ||
@name("c.t") table t_0 { | ||
actions = { | ||
a_0(); | ||
b_0(); | ||
@defaultonly NoAction_1(); | ||
} | ||
default_action = NoAction_1(); | ||
} | ||
apply { | ||
tmp = baz(); | ||
switch (tmp) { | ||
8w1: { | ||
foo(); | ||
} | ||
8w4: { | ||
bar(); | ||
} | ||
} | ||
t_0.apply(); | ||
} | ||
} | ||
|
||
control C(); | ||
package top(C c); | ||
top(c()) main; |
99 changes: 99 additions & 0 deletions
99
testdata/p4_16_samples_outputs/issue4656_const_fold_generic_switch_label_expr-midend.p4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
#include <core.p4> | ||
|
||
extern void foo(); | ||
extern void bar(); | ||
extern bit<8> baz(); | ||
control c() { | ||
@name("c.tmp") bit<8> tmp; | ||
@name(".a") action a_0() { | ||
} | ||
@name(".b") action b_0() { | ||
} | ||
@noWarn("unused") @name(".NoAction") action NoAction_1() { | ||
} | ||
@name("c.t") table t_0 { | ||
actions = { | ||
a_0(); | ||
b_0(); | ||
@defaultonly NoAction_1(); | ||
} | ||
default_action = NoAction_1(); | ||
} | ||
bit<8> switch_0_key; | ||
@hidden action switch_0_case() { | ||
} | ||
@hidden action switch_0_case_0() { | ||
} | ||
@hidden action switch_0_case_1() { | ||
} | ||
@hidden table switch_0_table { | ||
key = { | ||
switch_0_key: exact; | ||
} | ||
actions = { | ||
switch_0_case(); | ||
switch_0_case_0(); | ||
switch_0_case_1(); | ||
} | ||
const default_action = switch_0_case_1(); | ||
const entries = { | ||
const 8w1 : switch_0_case(); | ||
const 8w4 : switch_0_case_0(); | ||
} | ||
} | ||
@hidden action issue4656_const_fold_generic_switch_label_expr14() { | ||
foo(); | ||
} | ||
@hidden action issue4656_const_fold_generic_switch_label_expr15() { | ||
bar(); | ||
} | ||
@hidden action issue4656_const_fold_generic_switch_label_expr13() { | ||
switch_0_key = tmp; | ||
} | ||
@hidden action act() { | ||
tmp = baz(); | ||
} | ||
@hidden table tbl_act { | ||
actions = { | ||
act(); | ||
} | ||
const default_action = act(); | ||
} | ||
@hidden table tbl_issue4656_const_fold_generic_switch_label_expr13 { | ||
actions = { | ||
issue4656_const_fold_generic_switch_label_expr13(); | ||
} | ||
const default_action = issue4656_const_fold_generic_switch_label_expr13(); | ||
} | ||
@hidden table tbl_issue4656_const_fold_generic_switch_label_expr14 { | ||
actions = { | ||
issue4656_const_fold_generic_switch_label_expr14(); | ||
} | ||
const default_action = issue4656_const_fold_generic_switch_label_expr14(); | ||
} | ||
@hidden table tbl_issue4656_const_fold_generic_switch_label_expr15 { | ||
actions = { | ||
issue4656_const_fold_generic_switch_label_expr15(); | ||
} | ||
const default_action = issue4656_const_fold_generic_switch_label_expr15(); | ||
} | ||
apply { | ||
tbl_act.apply(); | ||
tbl_issue4656_const_fold_generic_switch_label_expr13.apply(); | ||
switch (switch_0_table.apply().action_run) { | ||
switch_0_case: { | ||
tbl_issue4656_const_fold_generic_switch_label_expr14.apply(); | ||
} | ||
switch_0_case_0: { | ||
tbl_issue4656_const_fold_generic_switch_label_expr15.apply(); | ||
} | ||
switch_0_case_1: { | ||
} | ||
} | ||
t_0.apply(); | ||
} | ||
} | ||
|
||
control C(); | ||
package top(C c); | ||
top(c()) main; |
Oops, something went wrong.