-
Notifications
You must be signed in to change notification settings - Fork 446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Teach functions inliner to inline into if condition #5073
Open
asl
wants to merge
1
commit into
p4lang:main
Choose a base branch
from
asl:func-inline-cond
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Teach functions inliner to inline into if condition
Signed-off-by: Anton Korobeynikov <anton@korobeynikov.info>
- Loading branch information
commit 7ba5781b2cea8785cc1e5ad62f21e4aff8f704e0
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
bool(
cast should not be necessary.