-
Notifications
You must be signed in to change notification settings - Fork 446
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Teach functions inliner to inline into if condition
Signed-off-by: Anton Korobeynikov <anton@korobeynikov.info>
- Loading branch information
Showing
8 changed files
with
207 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
bit foo(in bit a) { | ||
return a + 1; | ||
} | ||
|
||
control p(inout bit bt) { | ||
action a(inout bit y0, bit y1) { | ||
bit y2 = y1 > 0 ? 1w1 : 0; | ||
if (y2 == 1) { | ||
y0 = 0; | ||
} else if (y1 != 1) { | ||
y0 = y0 | 1w1; | ||
} | ||
} | ||
|
||
action b() { | ||
a(bt, foo(bt)); | ||
a(bt, 1); | ||
} | ||
|
||
table t { | ||
actions = { b; } | ||
default_action = b; | ||
} | ||
|
||
apply { | ||
t.apply(); | ||
} | ||
} | ||
|
||
control simple<T>(inout T arg); | ||
package m<T>(simple<T> pipe); | ||
|
||
m(p()) 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,30 @@ | ||
bit<1> foo(in bit<1> a) { | ||
return a + 1w1; | ||
} | ||
control p(inout bit<1> bt) { | ||
action a(inout bit<1> y0, bit<1> y1) { | ||
bit<1> y2 = (y1 > 1w0 ? 1w1 : 1w0); | ||
if (y2 == 1w1) { | ||
y0 = 1w0; | ||
} else if (y1 != 1w1) { | ||
y0 = y0 | 1w1; | ||
} | ||
} | ||
action b() { | ||
a(bt, foo(bt)); | ||
a(bt, 1w1); | ||
} | ||
table t { | ||
actions = { | ||
b(); | ||
} | ||
default_action = b(); | ||
} | ||
apply { | ||
t.apply(); | ||
} | ||
} | ||
|
||
control simple<T>(inout T arg); | ||
package m<T>(simple<T> pipe); | ||
m<bit<1>>(p()) main; |
53 changes: 53 additions & 0 deletions
53
testdata/p4_16_samples_outputs/inline-function2-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,53 @@ | ||
control p(inout bit<1> bt) { | ||
@name("p.y2") bit<1> y2_0; | ||
@name("p.tmp") bit<1> tmp; | ||
@name("p.y0") bit<1> y0; | ||
@name("p.y0") bit<1> y0_1; | ||
@name("p.a_0") bit<1> a; | ||
@name("p.retval") bit<1> retval; | ||
@name("p.a_1") bit<1> a_2; | ||
@name("p.retval") bit<1> retval_1; | ||
@name("p.b") action b() { | ||
y0 = bt; | ||
a = bt; | ||
retval = a + 1w1; | ||
if (retval > 1w0) { | ||
tmp = 1w1; | ||
} else { | ||
tmp = 1w0; | ||
} | ||
y2_0 = tmp; | ||
if (y2_0 == 1w1) { | ||
y0 = 1w0; | ||
} else { | ||
a_2 = bt; | ||
retval_1 = a_2 + 1w1; | ||
if (retval_1 != 1w1) { | ||
y0 = y0 | 1w1; | ||
} | ||
} | ||
bt = y0; | ||
y0_1 = bt; | ||
tmp = 1w1; | ||
y2_0 = tmp; | ||
if (y2_0 == 1w1) { | ||
y0_1 = 1w0; | ||
} else { | ||
; | ||
} | ||
bt = y0_1; | ||
} | ||
@name("p.t") table t_0 { | ||
actions = { | ||
b(); | ||
} | ||
default_action = b(); | ||
} | ||
apply { | ||
t_0.apply(); | ||
} | ||
} | ||
|
||
control simple<T>(inout T arg); | ||
package m<T>(simple<T> pipe); | ||
m<bit<1>>(p()) 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,33 @@ | ||
control p(inout bit<1> bt) { | ||
@name("p.tmp") bit<1> tmp; | ||
@name("p.y0") bit<1> y0; | ||
@name("p.b") action b() { | ||
y0 = bt; | ||
if (bt + 1w1 > 1w0) { | ||
tmp = 1w1; | ||
} else { | ||
tmp = 1w0; | ||
} | ||
if (tmp == 1w1) { | ||
y0 = 1w0; | ||
} else if (bt + 1w1 != 1w1) { | ||
y0 = bt | 1w1; | ||
} | ||
bt = y0; | ||
tmp = 1w1; | ||
bt = 1w0; | ||
} | ||
@name("p.t") table t_0 { | ||
actions = { | ||
b(); | ||
} | ||
default_action = b(); | ||
} | ||
apply { | ||
t_0.apply(); | ||
} | ||
} | ||
|
||
control simple<T>(inout T arg); | ||
package m<T>(simple<T> pipe); | ||
m<bit<1>>(p()) 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,30 @@ | ||
bit<1> foo(in bit<1> a) { | ||
return a + 1; | ||
} | ||
control p(inout bit<1> bt) { | ||
action a(inout bit<1> y0, bit<1> y1) { | ||
bit<1> y2 = (y1 > 0 ? 1w1 : 0); | ||
if (y2 == 1) { | ||
y0 = 0; | ||
} else if (y1 != 1) { | ||
y0 = y0 | 1w1; | ||
} | ||
} | ||
action b() { | ||
a(bt, foo(bt)); | ||
a(bt, 1); | ||
} | ||
table t { | ||
actions = { | ||
b; | ||
} | ||
default_action = b; | ||
} | ||
apply { | ||
t.apply(); | ||
} | ||
} | ||
|
||
control simple<T>(inout T arg); | ||
package m<T>(simple<T> pipe); | ||
m(p()) main; |
Empty file.