-
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.
Remove @likely/@unlikely when constfolding if statements
- warn if @unlikely is always taken.
- Loading branch information
Showing
7 changed files
with
129 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include <core.p4> | ||
|
||
struct Headers { | ||
bit<8> a; | ||
bit<8> b; | ||
} | ||
|
||
control ingress(inout Headers h) { | ||
apply { | ||
if (true) @likely { | ||
h.a = 0; | ||
} | ||
if (true) @unlikely { | ||
h.b = 0; | ||
} | ||
} | ||
} | ||
|
||
control c<T>(inout T d); | ||
package top<T>(c<T> _c); | ||
|
||
top(ingress()) 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,17 @@ | ||
#include <core.p4> | ||
|
||
struct Headers { | ||
bit<8> a; | ||
bit<8> b; | ||
} | ||
|
||
control ingress(inout Headers h) { | ||
apply { | ||
h.a = 8w0; | ||
h.b = 8w0; | ||
} | ||
} | ||
|
||
control c<T>(inout T d); | ||
package top<T>(c<T> _c); | ||
top<Headers>(ingress()) main; |
17 changes: 17 additions & 0 deletions
17
testdata/p4_16_samples_outputs/annotation-likely-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,17 @@ | ||
#include <core.p4> | ||
|
||
struct Headers { | ||
bit<8> a; | ||
bit<8> b; | ||
} | ||
|
||
control ingress(inout Headers h) { | ||
apply { | ||
h.a = 8w0; | ||
h.b = 8w0; | ||
} | ||
} | ||
|
||
control c<T>(inout T d); | ||
package top<T>(c<T> _c); | ||
top<Headers>(ingress()) main; |
26 changes: 26 additions & 0 deletions
26
testdata/p4_16_samples_outputs/annotation-likely-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,26 @@ | ||
#include <core.p4> | ||
|
||
struct Headers { | ||
bit<8> a; | ||
bit<8> b; | ||
} | ||
|
||
control ingress(inout Headers h) { | ||
@hidden action annotationlikely11() { | ||
h.a = 8w0; | ||
h.b = 8w0; | ||
} | ||
@hidden table tbl_annotationlikely11 { | ||
actions = { | ||
annotationlikely11(); | ||
} | ||
const default_action = annotationlikely11(); | ||
} | ||
apply { | ||
tbl_annotationlikely11.apply(); | ||
} | ||
} | ||
|
||
control c<T>(inout T d); | ||
package top<T>(c<T> _c); | ||
top<Headers>(ingress()) 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,21 @@ | ||
#include <core.p4> | ||
|
||
struct Headers { | ||
bit<8> a; | ||
bit<8> b; | ||
} | ||
|
||
control ingress(inout Headers h) { | ||
apply { | ||
if (true) @likely { | ||
h.a = 0; | ||
} | ||
if (true) @unlikely { | ||
h.b = 0; | ||
} | ||
} | ||
} | ||
|
||
control c<T>(inout T d); | ||
package top<T>(c<T> _c); | ||
top(ingress()) 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,3 @@ | ||
annotation-likely.p4(13): [--Wwarn=ignore] warning: ignoring @unlikely on always taken statement | ||
if (true) @unlikely { | ||
^ |