Skip to content

Commit d471427

Browse files
author
Chris Dodd
authored
Use sourceInfo to generate action names in ActionSynthesis (#2024)
- make it easier in the backend to figure out where actions and tables came from when debugging by using a name that vaguely corresponds to the source file and line of the original statement.
1 parent 69e132d commit d471427

File tree

227 files changed

+2489
-2459
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

227 files changed

+2489
-2459
lines changed

midend/actionSynthesis.cpp

+19-1
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ const IR::Node* DoSynthesizeActions::preorder(IR::BlockStatement* statement) {
157157
actbody = new IR::BlockStatement;
158158
}
159159
left->push_back(c);
160+
left->srcInfo += c->srcInfo;
160161
}
161162
if (!actbody->components.empty()) {
162163
auto action = createAction(actbody);
@@ -172,9 +173,26 @@ const IR::Node* DoSynthesizeActions::preorder(IR::BlockStatement* statement) {
172173
return statement;
173174
}
174175

176+
static cstring createName(const Util::SourceInfo &si) {
177+
if (!si.isValid()) return "act";
178+
auto pos = si.toPosition();
179+
if (pos.fileName.isNullOrEmpty() || pos.sourceLine == 0) return "act";
180+
std::string name;
181+
const char *p = pos.fileName.findlast('/');
182+
p = p ? p + 1 : pos.fileName.c_str();
183+
while (*p && !isalpha(*p)) ++p;
184+
while (*p && *p != '.') {
185+
if (isalnum(*p) || *p == '_')
186+
name += *p;
187+
++p; }
188+
if (name.empty()) return "act";
189+
if (isdigit(name.back())) name += 'l';
190+
return name + std::to_string(pos.sourceLine);
191+
}
192+
175193
const IR::Statement* DoSynthesizeActions::createAction(const IR::Statement* toAdd) {
176194
changes = true;
177-
auto name = refMap->newName("act");
195+
auto name = refMap->newName(createName(toAdd->srcInfo));
178196
const IR::BlockStatement* body;
179197
if (toAdd->is<IR::BlockStatement>()) {
180198
body = toAdd->to<IR::BlockStatement>();

testdata/p4_14_samples_outputs/exact_match_mask1-midend.p4

+5-5
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,17 @@ control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_
4545
}
4646
default_action = NoAction_0();
4747
}
48-
@hidden action act() {
48+
@hidden action exact_match_mask1l41() {
4949
key_0 = hdr.data.f1 & 32w0xff00ff;
5050
}
51-
@hidden table tbl_act {
51+
@hidden table tbl_exact_match_mask1l41 {
5252
actions = {
53-
act();
53+
exact_match_mask1l41();
5454
}
55-
const default_action = act();
55+
const default_action = exact_match_mask1l41();
5656
}
5757
apply {
58-
tbl_act.apply();
58+
tbl_exact_match_mask1l41.apply();
5959
test1_0.apply();
6060
}
6161
}

testdata/p4_14_samples_outputs/issue1237-midend.p4

+5-5
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,17 @@ control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_
5353
}
5454
default_action = NoAction_0();
5555
}
56-
@hidden action act() {
56+
@hidden action issue1237l37() {
5757
key_0 = 48w0;
5858
}
59-
@hidden table tbl_act {
59+
@hidden table tbl_issue1237l37 {
6060
actions = {
61-
act();
61+
issue1237l37();
6262
}
63-
const default_action = act();
63+
const default_action = issue1237l37();
6464
}
6565
apply {
66-
tbl_act.apply();
66+
tbl_issue1237l37.apply();
6767
conceptualization_0.apply();
6868
}
6969
}

testdata/p4_16_samples_outputs/action_call_ebpf-midend.p4

+5-5
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ control pipe(inout Headers_t headers, out bool pass) {
1515
@name("pipe.Reject") action Reject() {
1616
pass = x_0;
1717
}
18-
@hidden action act() {
18+
@hidden action action_call_ebpf34() {
1919
x_0 = true;
2020
}
21-
@hidden table tbl_act {
21+
@hidden table tbl_action_call_ebpf34 {
2222
actions = {
23-
act();
23+
action_call_ebpf34();
2424
}
25-
const default_action = act();
25+
const default_action = action_call_ebpf34();
2626
}
2727
@hidden table tbl_Reject {
2828
actions = {
@@ -31,7 +31,7 @@ control pipe(inout Headers_t headers, out bool pass) {
3131
const default_action = Reject();
3232
}
3333
apply {
34-
tbl_act.apply();
34+
tbl_action_call_ebpf34.apply();
3535
tbl_Reject.apply();
3636
}
3737
}

testdata/p4_16_samples_outputs/annotation-bug-midend.p4

+5-5
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ struct tuple_0 {
2020
extern bit<16> get<T>(in T data);
2121
control cc() {
2222
ipv4_option_timestamp_t hdr_0_ipv4_option_timestamp;
23-
@hidden action act() {
23+
@hidden action annotationbug24() {
2424
get<headers>({ hdr_0_ipv4_option_timestamp });
2525
}
26-
@hidden table tbl_act {
26+
@hidden table tbl_annotationbug24 {
2727
actions = {
28-
act();
28+
annotationbug24();
2929
}
30-
const default_action = act();
30+
const default_action = annotationbug24();
3131
}
3232
apply {
33-
tbl_act.apply();
33+
tbl_annotationbug24.apply();
3434
}
3535
}
3636

testdata/p4_16_samples_outputs/arith-inline-bmv2-midend.p4

+5-5
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,18 @@ control ingress(inout Headers h, inout Meta m, inout standard_metadata_t sm) {
5252
}
5353
const default_action = c_add_0();
5454
}
55-
@hidden action act() {
55+
@hidden action arithinlineskeleton51() {
5656
sm.egress_spec = 9w0;
5757
}
58-
@hidden table tbl_act {
58+
@hidden table tbl_arithinlineskeleton51 {
5959
actions = {
60-
act();
60+
arithinlineskeleton51();
6161
}
62-
const default_action = act();
62+
const default_action = arithinlineskeleton51();
6363
}
6464
apply {
6565
c_t.apply();
66-
tbl_act.apply();
66+
tbl_arithinlineskeleton51.apply();
6767
}
6868
}
6969

testdata/p4_16_samples_outputs/arith2-inline-bmv2-midend.p4

+15-15
Original file line numberDiff line numberDiff line change
@@ -43,40 +43,40 @@ control deparser(packet_out b, in Headers h) {
4343
}
4444

4545
control ingress(inout Headers h, inout Meta m, inout standard_metadata_t sm) {
46-
@hidden action act() {
46+
@hidden action arith2inlinebmv2l29() {
4747
h.h.c = 8w0;
4848
}
49-
@hidden action act_0() {
49+
@hidden action arith2inlinebmv2l31() {
5050
h.h.c = 8w1;
5151
}
52-
@hidden action act_1() {
52+
@hidden action arithinlineskeleton51() {
5353
sm.egress_spec = 9w0;
5454
}
55-
@hidden table tbl_act {
55+
@hidden table tbl_arith2inlinebmv2l29 {
5656
actions = {
57-
act();
57+
arith2inlinebmv2l29();
5858
}
59-
const default_action = act();
59+
const default_action = arith2inlinebmv2l29();
6060
}
61-
@hidden table tbl_act_0 {
61+
@hidden table tbl_arith2inlinebmv2l31 {
6262
actions = {
63-
act_0();
63+
arith2inlinebmv2l31();
6464
}
65-
const default_action = act_0();
65+
const default_action = arith2inlinebmv2l31();
6666
}
67-
@hidden table tbl_act_1 {
67+
@hidden table tbl_arithinlineskeleton51 {
6868
actions = {
69-
act_1();
69+
arithinlineskeleton51();
7070
}
71-
const default_action = act_1();
71+
const default_action = arithinlineskeleton51();
7272
}
7373
apply {
7474
if (h.h.a < h.h.b) {
75-
tbl_act.apply();
75+
tbl_arith2inlinebmv2l29.apply();
7676
} else {
77-
tbl_act_0.apply();
77+
tbl_arith2inlinebmv2l31.apply();
7878
}
79-
tbl_act_1.apply();
79+
tbl_arithinlineskeleton51.apply();
8080
}
8181
}
8282

testdata/p4_16_samples_outputs/array-copy-bmv2-midend.p4

+5-5
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,17 @@ control deparser(packet_out b, in Headers h) {
4747
}
4848

4949
control ingress(inout Headers h, inout Meta m, inout standard_metadata_t sm) {
50-
@hidden action act() {
50+
@hidden action arraycopybmv2l34() {
5151
sm.egress_spec = 9w0;
5252
}
53-
@hidden table tbl_act {
53+
@hidden table tbl_arraycopybmv2l34 {
5454
actions = {
55-
act();
55+
arraycopybmv2l34();
5656
}
57-
const default_action = act();
57+
const default_action = arraycopybmv2l34();
5858
}
5959
apply {
60-
tbl_act.apply();
60+
tbl_arraycopybmv2l34.apply();
6161
}
6262
}
6363

testdata/p4_16_samples_outputs/array_field-midend.p4

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@ control c(out H[2] h);
77
package top(c _c);
88
control my(out H[2] s) {
99
bit<32> tmp;
10-
@hidden action act() {
10+
@hidden action array_field27() {
1111
s[32w0].z = 1w1;
1212
s[32w1].z = 1w0;
1313
tmp = f(s[32w0].z, 1w0);
1414
f(s[tmp].z, 1w1);
1515
}
16-
@hidden table tbl_act {
16+
@hidden table tbl_array_field27 {
1717
actions = {
18-
act();
18+
array_field27();
1919
}
20-
const default_action = act();
20+
const default_action = array_field27();
2121
}
2222
apply {
23-
tbl_act.apply();
23+
tbl_array_field27.apply();
2424
}
2525
}
2626

testdata/p4_16_samples_outputs/bool_ebpf-midend.p4

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ parser prs(packet_in p, out Headers_t headers) {
1111
}
1212

1313
control pipe(inout Headers_t headers, out bool pass) {
14-
@hidden action act() {
14+
@hidden action bool_ebpf31() {
1515
pass = true;
1616
}
17-
@hidden table tbl_act {
17+
@hidden table tbl_bool_ebpf31 {
1818
actions = {
19-
act();
19+
bool_ebpf31();
2020
}
21-
const default_action = act();
21+
const default_action = bool_ebpf31();
2222
}
2323
apply {
24-
tbl_act.apply();
24+
tbl_bool_ebpf31.apply();
2525
}
2626
}
2727

testdata/p4_16_samples_outputs/bvec_union-bmv2-midend.p4

+5-5
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,18 @@ control deparser(packet_out b, in Headers h) {
8686
}
8787

8888
control ingress(inout Headers h, inout Meta m, inout standard_metadata_t sm) {
89-
@hidden action act() {
89+
@hidden action bvec_unionbmv2l88() {
9090
h.u.h2.setInvalid();
9191
}
92-
@hidden table tbl_act {
92+
@hidden table tbl_bvec_unionbmv2l88 {
9393
actions = {
94-
act();
94+
bvec_unionbmv2l88();
9595
}
96-
const default_action = act();
96+
const default_action = bvec_unionbmv2l88();
9797
}
9898
apply {
9999
if (h.u.h2.isValid()) {
100-
tbl_act.apply();
100+
tbl_bvec_unionbmv2l88.apply();
101101
}
102102
}
103103
}

testdata/p4_16_samples_outputs/calc-ebpf-midend.p4

+5-5
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,14 @@ control Ingress(inout headers hdr, out bool xout) {
141141

142142
implementation = hash_table(32w8);
143143
}
144-
@hidden action act() {
144+
@hidden action calcebpf152() {
145145
xout = true;
146146
}
147-
@hidden table tbl_act {
147+
@hidden table tbl_calcebpf152 {
148148
actions = {
149-
act();
149+
calcebpf152();
150150
}
151-
const default_action = act();
151+
const default_action = calcebpf152();
152152
}
153153
@hidden table tbl_operation_drop {
154154
actions = {
@@ -157,7 +157,7 @@ control Ingress(inout headers hdr, out bool xout) {
157157
const default_action = operation_drop_2();
158158
}
159159
apply {
160-
tbl_act.apply();
160+
tbl_calcebpf152.apply();
161161
if (hdr.p4calc.isValid()) {
162162
calculate_0.apply();
163163
} else {

0 commit comments

Comments
 (0)