Skip to content

Commit 8aa4f37

Browse files
mbudiu-vmwantoninbas
mbudiu-vmw
authored andcommitted
Fix for issue #425
1 parent d30f436 commit 8aa4f37

File tree

94 files changed

+394
-438
lines changed

Some content is hidden

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

94 files changed

+394
-438
lines changed

ir/base.def

+5-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,11 @@ class Annotation {
174174
Annotation(ID n, intmax_t v) : name(n) {
175175
expr.push_back(new IR::Constant(v)); }
176176
/// Predefined annotations used by the compiler
177-
static const cstring nameAnnotation;
177+
static const cstring nameAnnotation; /// indicates the control-plane name
178+
static const cstring tableOnlyAnnotation; /// action cannot be a default_action
179+
static const cstring defaultOnlyAnnotation; /// action can only be a default_action
180+
static const cstring atomicAnnotation; /// code should be executed atomically
181+
static const cstring hiddenAnnotation; /// object should not be exposed to the control-plane
178182
toString{ return cstring("@") + name; }
179183
validate{ BUG_CHECK(!name.name.isNullOrEmpty(), "empty annotation name"); }
180184
}

ir/type.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ const IR::ID IR::Type_Table::hit = ID("hit");
3232
const IR::ID IR::Type_Table::action_run = ID("action_run");
3333

3434
const cstring IR::Annotation::nameAnnotation = "name";
35+
const cstring IR::Annotation::tableOnlyAnnotation = "tableonly";
36+
const cstring IR::Annotation::defaultOnlyAnnotation = "defaultonly";
37+
const cstring IR::Annotation::atomicAnnotation = "atomic";
38+
const cstring IR::Annotation::hiddenAnnotation = "hidden";
3539

3640
std::map<int, const IR::Type_Bits*> *Type_Bits::signedTypes = nullptr;
3741
std::map<int, const IR::Type_Bits*> *Type_Bits::unsignedTypes = nullptr;

midend/actionSynthesis.cpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ const IR::Node* DoMoveActionsToTables::postorder(IR::MethodCallStatement* statem
7575
auto props = new IR::TableProperties(nm);
7676
// Synthesize a new table
7777
cstring tblName = IR::ID(refMap->newName(cstring("tbl_") + ac->action->name.name), nullptr);
78-
auto tbl = new IR::P4Table(tblName, props);
78+
79+
auto annos = new IR::Annotations();
80+
annos->add(new IR::Annotation(IR::Annotation::hiddenAnnotation,
81+
IR::Vector<IR::Expression>()));
82+
auto tbl = new IR::P4Table(tblName, annos, props);
7983
tables.push_back(tbl);
8084

8185
// Table invocation statement
@@ -197,7 +201,11 @@ const IR::Statement* DoSynthesizeActions::createAction(const IR::Statement* toAd
197201
b->push_back(toAdd);
198202
body = new IR::BlockStatement(toAdd->srcInfo, b);
199203
}
200-
auto action = new IR::P4Action(name, new IR::ParameterList(), body);
204+
205+
auto annos = new IR::Annotations();
206+
annos->add(new IR::Annotation(IR::Annotation::hiddenAnnotation,
207+
IR::Vector<IR::Expression>()));
208+
auto action = new IR::P4Action(name, annos, new IR::ParameterList(), body);
201209
actions.push_back(action);
202210
auto actpath = new IR::PathExpression(name);
203211
auto repl = new IR::MethodCallExpression(actpath);

midend/actionSynthesis.h

+46-30
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,41 @@ limitations under the License.
2222

2323
namespace P4 {
2424

25-
// Policy which selects the control blocks where action
26-
// synthesis is applied.
25+
/**
26+
Policy which selects the control blocks where action
27+
synthesis is applied.
28+
*/
2729
class ActionSynthesisPolicy {
2830
public:
2931
virtual ~ActionSynthesisPolicy() {}
30-
// If the policy returns true the control block is processed,
31-
// otherwise it is left unchanged.
32+
/**
33+
If the policy returns true the control block is processed,
34+
otherwise it is left unchanged.
35+
*/
3236
virtual bool convert(const IR::P4Control* control) const = 0;
3337
};
3438

35-
// Convert direct action calls to table invocations.
36-
// control c() {
37-
// action x(in bit b) { ... }
38-
// apply { x(e); }
39-
// }
40-
// turns into
41-
// control c() {
42-
// action x(in bit b) { ... }
43-
// table _tmp() {
44-
// actions = { x(e); }
45-
// const default_action = x();
46-
// }
47-
// apply { _tmp.apply(); }
48-
// }
49-
// For this to work all variable declarations must have been moved to the beginning.
39+
/**
40+
Convert direct action calls to table invocations.
41+
42+
control c() {
43+
action x(in bit b) { ... }
44+
apply { x(e); }
45+
}
46+
47+
turns into
48+
49+
control c() {
50+
action x(in bit b) { ... }
51+
table _tmp() {
52+
actions = { x(e); }
53+
const default_action = x();
54+
}
55+
apply { _tmp.apply(); }
56+
}
57+
58+
For this to work all variable declarations must have been moved to the beginning.
59+
*/
5060
class DoMoveActionsToTables : public Transform {
5161
ReferenceMap* refMap;
5262
TypeMap* typeMap;
@@ -66,17 +76,23 @@ class DoMoveActionsToTables : public Transform {
6676
const IR::Node* postorder(IR::MethodCallStatement* statement) override;
6777
};
6878

69-
// Convert some statements into action invocations by synthesizing new actions.
70-
// E.g.
71-
// control c(inout bit x) {
72-
// apply { x = 1; }
73-
// }
74-
// is converted to:
75-
// control c(inout bit x) {
76-
// action act() { x = 1; }
77-
// apply { act(); }
78-
// }
79-
// For this to work all variable declarations must have been moved to the beginning.
79+
/**
80+
Convert some statements into action invocations by synthesizing new actions.
81+
E.g.
82+
83+
control c(inout bit x) {
84+
apply { x = 1; }
85+
}
86+
87+
is converted to:
88+
89+
control c(inout bit x) {
90+
action act() { x = 1; }
91+
apply { act(); }
92+
}
93+
94+
For this to work all variable declarations must have been moved to the beginning.
95+
*/
8096
class DoSynthesizeActions : public Transform {
8197
ReferenceMap* refMap;
8298
TypeMap* typeMap;

testdata/p4_14_samples_outputs/exact_match_mask1-midend.p4

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_
4545
}
4646
default_action = NoAction_0();
4747
}
48-
action act() {
48+
@hidden action act() {
4949
key_0 = hdr.data.f1 & 32w0xff00ff;
5050
}
51-
table tbl_act {
51+
@hidden table tbl_act {
5252
actions = {
5353
act();
5454
}

testdata/p4_14_samples_outputs/hit-midend.p4

+4-4
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,19 @@ control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_
7777
}
7878
default_action = NoAction_5();
7979
}
80-
action act() {
80+
@hidden action act() {
8181
tmp_0 = true;
8282
}
83-
action act_0() {
83+
@hidden action act_0() {
8484
tmp_0 = false;
8585
}
86-
table tbl_act {
86+
@hidden table tbl_act {
8787
actions = {
8888
act();
8989
}
9090
const default_action = act();
9191
}
92-
table tbl_act_0 {
92+
@hidden table tbl_act_0 {
9393
actions = {
9494
act_0();
9595
}

testdata/p4_14_samples_outputs/hitmiss-midend.p4

+4-4
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,19 @@ control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_
8585
}
8686
default_action = NoAction_5();
8787
}
88-
action act() {
88+
@hidden action act() {
8989
tmp_0 = true;
9090
}
91-
action act_0() {
91+
@hidden action act_0() {
9292
tmp_0 = false;
9393
}
94-
table tbl_act {
94+
@hidden table tbl_act {
9595
actions = {
9696
act();
9797
}
9898
const default_action = act();
9999
}
100-
table tbl_act_0 {
100+
@hidden table tbl_act_0 {
101101
actions = {
102102
act_0();
103103
}

testdata/p4_14_samples_outputs/miss-midend.p4

+4-4
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,19 @@ control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_
7777
}
7878
default_action = NoAction_5();
7979
}
80-
action act() {
80+
@hidden action act() {
8181
tmp_0 = true;
8282
}
83-
action act_0() {
83+
@hidden action act_0() {
8484
tmp_0 = false;
8585
}
86-
table tbl_act {
86+
@hidden table tbl_act {
8787
actions = {
8888
act();
8989
}
9090
const default_action = act();
9191
}
92-
table tbl_act_0 {
92+
@hidden table tbl_act_0 {
9393
actions = {
9494
act_0();
9595
}

testdata/p4_16_samples_outputs/action-synth-midend.p4

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ parser ParserI(packet_in pk, out H hdr, inout M meta, inout standard_metadata_t
1616
control IngressI(inout H hdr, inout M meta, inout standard_metadata_t smeta) {
1717
@name("aux.a") action aux_a() {
1818
}
19-
table tbl_aux_a {
19+
@hidden table tbl_aux_a {
2020
actions = {
2121
aux_a();
2222
}

testdata/p4_16_samples_outputs/action_call_ebpf-midend.p4

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ control pipe(inout Headers_t headers, out bool pass) {
1515
@name("Reject") action Reject_0() {
1616
pass = x;
1717
}
18-
action act() {
18+
@hidden action act() {
1919
x = true;
2020
}
21-
table tbl_act {
21+
@hidden table tbl_act {
2222
actions = {
2323
act();
2424
}
2525
const default_action = act();
2626
}
27-
table tbl_Reject {
27+
@hidden table tbl_Reject {
2828
actions = {
2929
Reject_0();
3030
}

testdata/p4_16_samples_outputs/action_param1-midend.p4

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ control c(inout bit<32> x) {
22
@name("a") action a_0() {
33
x = 32w15;
44
}
5-
table tbl_a {
5+
@hidden table tbl_a {
66
actions = {
77
a_0();
88
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ control ingress(inout Headers h, inout Meta m, inout standard_metadata_t sm) {
5252
}
5353
const default_action = c_add();
5454
}
55-
action act() {
55+
@hidden action act() {
5656
sm.egress_spec = 9w0;
5757
}
58-
table tbl_act {
58+
@hidden table tbl_act {
5959
actions = {
6060
act();
6161
}

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

+8-8
Original file line numberDiff line numberDiff line change
@@ -43,37 +43,37 @@ 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-
action act() {
46+
@hidden action act() {
4747
h.h.c = 8w0;
4848
}
49-
action act_0() {
49+
@hidden action act_0() {
5050
h.h.c = 8w1;
5151
}
52-
action act_1() {
52+
@hidden action act_1() {
5353
sm.egress_spec = 9w0;
5454
}
55-
table tbl_act {
55+
@hidden table tbl_act {
5656
actions = {
5757
act();
5858
}
5959
const default_action = act();
6060
}
61-
table tbl_act_0 {
61+
@hidden table tbl_act_0 {
6262
actions = {
6363
act_0();
6464
}
6565
const default_action = act_0();
6666
}
67-
table tbl_act_1 {
67+
@hidden table tbl_act_1 {
6868
actions = {
6969
act_1();
7070
}
7171
const default_action = act_1();
7272
}
7373
apply {
74-
if (h.h.a < h.h.b)
74+
if (h.h.a < h.h.b)
7575
tbl_act.apply();
76-
else
76+
else
7777
tbl_act_0.apply();
7878
tbl_act_1.apply();
7979
}

testdata/p4_16_samples_outputs/array_field-midend.p4

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ control c(out H[2] h);
77
package top(c _c);
88
control my(out H[2] s) {
99
bit<1> tmp_1;
10-
action act() {
10+
@hidden action act() {
1111
s[32w0].z = 1w1;
1212
s[32w1].z = 1w0;
1313
tmp_1 = f(s[32w0].z, 1w0);
1414
}
15-
table tbl_act {
15+
@hidden table tbl_act {
1616
actions = {
1717
act();
1818
}

testdata/p4_16_samples_outputs/clone-bmv2-midend.p4

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ parser ParserI(packet_in pk, out H hdr, inout M meta, inout standard_metadata_t
1414
}
1515

1616
control IngressI(inout H hdr, inout M meta, inout standard_metadata_t smeta) {
17-
action act() {
17+
@hidden action act() {
1818
clone(CloneType.I2E, smeta.clone_spec);
1919
}
20-
table tbl_act {
20+
@hidden table tbl_act {
2121
actions = {
2222
act();
2323
}

testdata/p4_16_samples_outputs/complex-midend.p4

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ extern bit<32> f(in bit<32> x);
22
control c(inout bit<32> r) {
33
bit<32> tmp_2;
44
bit<32> tmp_4;
5-
action act() {
5+
@hidden action act() {
66
tmp_2 = f(32w5);
77
tmp_4 = f(tmp_2);
88
r = tmp_4;
99
}
10-
table tbl_act {
10+
@hidden table tbl_act {
1111
actions = {
1212
act();
1313
}

testdata/p4_16_samples_outputs/complex1-midend.p4

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ control c(inout bit<32> r) {
44
bit<32> tmp_8;
55
bit<32> tmp_10;
66
bit<32> tmp_12;
7-
action act() {
7+
@hidden action act() {
88
tmp_6 = f(32w5, 32w2);
99
tmp_8 = f(32w2, 32w3);
1010
tmp_10 = f(32w6, tmp_8);
1111
tmp_12 = f(tmp_6, tmp_10);
1212
r = tmp_12;
1313
}
14-
table tbl_act {
14+
@hidden table tbl_act {
1515
actions = {
1616
act();
1717
}

0 commit comments

Comments
 (0)