Skip to content
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

Run def-use analysis again after inlining #3591

Merged
merged 6 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion backends/p4tools/testgen/targets/bmv2/test/BMV2Xfail.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ p4tools_add_xfail_reason(
p4tools_add_xfail_reason(
"testgen-p4c-bmv2"
"bad json"
invalid-hdr-warnings4.p4
control-hs-index-test5.p4
)

Expand Down
2 changes: 2 additions & 0 deletions frontends/p4/frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ const IR::P4Program *FrontEnd::run(const CompilerOptions &options, const IR::P4P
new RemoveParserControlFlow(&refMap, &typeMap), // more ifs may have been added to parsers
new UniqueNames(&refMap), // needed again after inlining
new MoveDeclarations(), // needed again after inlining
new SimplifyDefUse(&refMap, &typeMap),
new RemoveUnusedDeclarations(&refMap),
new SimplifyControlFlow(&refMap, &typeMap),
new HierarchicalNames(),
new FrontEndLast(),
Expand Down
8 changes: 6 additions & 2 deletions frontends/p4/simplifyDefUse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ class FindUninitialized : public Inspector {
const IR::ParameterList* parameters,
Definitions* defs) {
LOG2("Checking output parameters of " << block <<
"; definitions are " << Log::endl << defs);
"; definitions are " << IndentCtl::endl << defs);
for (auto p : parameters->parameters) {
if (p->direction == IR::Direction::Out || p->direction == IR::Direction::InOut) {
auto storage = definitions->storageMap->getStorage(p);
Expand Down Expand Up @@ -1443,6 +1443,10 @@ class FindUninitialized : public Inspector {
return false;
}

void postorder(const IR::StructExpression* expression) override {
otherExpression(expression);
}

void postorder(const IR::Operation_Unary* expression) override {
otherExpression(expression);
}
Expand Down Expand Up @@ -1490,7 +1494,7 @@ class RemoveUnused : public Transform {
return mcs;
}
// removing
LOG3("Removing statement " << getOriginal());
LOG3("Removing statement " << getOriginal() << IndentCtl::indent);
return new IR::EmptyStatement(mcs->srcInfo);
}
return mcs;
Expand Down
1 change: 0 additions & 1 deletion testdata/p4_14_samples_outputs/action_inline1-frontend.p4
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_
@noWarn("unused") @name(".NoAction") action NoAction_1() {
}
@name(".setb1") action setb1(@name("val") bit<8> val, @name("port") bit<9> port) {
dest = hdr.data.b1;
dest = val;
hdr.data.b1 = dest;
standard_metadata.egress_spec = port;
Expand Down
3 changes: 0 additions & 3 deletions testdata/p4_14_samples_outputs/action_inline2-frontend.p4
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ control ingress(inout headers hdr, inout metadata meta, inout standard_metadata_
@noWarn("unused") @name(".NoAction") action NoAction_1() {
}
@name(".setb1") action setb1(@name("port") bit<9> port) {
dest = hdr.data.b1;
dest_3 = dest;
dest_4 = dest_3;
dest_4 = hdr.data.b2;
dest_3 = dest_4;
dest = dest_3;
Expand Down
1 change: 0 additions & 1 deletion testdata/p4_16_samples_outputs/action-bind-frontend.p4
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
control c(inout bit<32> x) {
@name("c.b") bit<32> b_0;
@name("c.a") action a(@name("d") bit<32> d) {
b_0 = x;
b_0 = d;
x = b_0;
}
Expand Down
3 changes: 0 additions & 3 deletions testdata/p4_16_samples_outputs/action_call_ubpf-frontend.p4
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,10 @@ parser prs(packet_in p, out Headers_t headers, inout metadata meta, inout standa
}

control pipe(inout Headers_t headers, inout metadata meta, inout standard_metadata std_meta) {
@name("pipe.hasReturned") bool hasReturned;
@name("pipe.RejectConditional") action RejectConditional(@name("condition") bit<1> condition) {
}
@name("pipe.act_return") action act_return() {
hasReturned = false;
mark_to_pass();
hasReturned = true;
}
@name("pipe.act_exit") action act_exit() {
mark_to_pass();
Expand Down
7 changes: 0 additions & 7 deletions testdata/p4_16_samples_outputs/after-return-frontend.p4
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
control ctrl() {
@name("ctrl.a") bit<32> a_0;
@name("ctrl.hasReturned") bool hasReturned;
apply {
hasReturned = false;
a_0 = 32w0;
if (a_0 == 32w0) {
hasReturned = true;
} else {
hasReturned = true;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
control E(out bit<1> b);
control Ingress(out bit<1> b) {
apply {
b = 1w1;
b = 1w0;
}
}
Expand Down
11 changes: 5 additions & 6 deletions testdata/p4_16_samples_outputs/control-as-param-midend.p4
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@

control E(out bit<1> b);
control Ingress(out bit<1> b) {
@hidden action controlasparam7() {
b = 1w1;
@hidden action controlasparam13() {
b = 1w0;
}
@hidden table tbl_controlasparam7 {
@hidden table tbl_controlasparam13 {
actions = {
controlasparam7();
controlasparam13();
}
const default_action = controlasparam7();
const default_action = controlasparam13();
}
apply {
tbl_controlasparam7.apply();
tbl_controlasparam13.apply();
}
}

Expand Down
12 changes: 0 additions & 12 deletions testdata/p4_16_samples_outputs/decl2-frontend.p4
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
control p() {
@name("p.z") bit<1> z_0;
@name("p.x_0") bit<1> x_0;
@name("p.x_1") bit<1> x_3;
@name("p.y_0") bit<1> y_0;
@name("p.x") bit<1> x_4;
@name("p.y") bit<1> y_2;
@name("p.b") action b() {
x_4 = x_3;
x_0 = x_4;
z_0 = x_4 & x_0;
y_2 = z_0;
y_0 = y_2;
}
apply {
x_3 = 1w0;
b();
}
}
Expand Down
3 changes: 0 additions & 3 deletions testdata/p4_16_samples_outputs/def-use-frontend.p4
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ control IngressI(inout H hdr, inout M meta, inout std_meta_t std_meta) {
}

control EgressI(inout H hdr, inout M meta, inout std_meta_t std_meta) {
@name("EgressI.hasReturned") bool hasReturned;
@name("EgressI.a") action a() {
}
@name("EgressI.t") table t_0 {
Expand All @@ -31,10 +30,8 @@ control EgressI(inout H hdr, inout M meta, inout std_meta_t std_meta) {
default_action = a();
}
apply {
hasReturned = false;
switch (t_0.apply().action_run) {
a: {
hasReturned = true;
}
default: {
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fabric.p4(84): [--Wwarn=invalid_header] warning: accessing a field of a potentially invalid header hdr.gtpu_ipv4
spgw_ingress.apply(hdr.gtpu_ipv4, hdr.gtpu_udp, hdr.gtpu,
^^^^^^^^^^^^^
1 change: 0 additions & 1 deletion testdata/p4_16_samples_outputs/function-frontend.p4
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ control c(out bit<16> b) {
if (hasReturned) {
;
} else {
hasReturned = true;
retval = right;
}
b = retval;
Expand Down
2 changes: 2 additions & 0 deletions testdata/p4_16_samples_outputs/function.p4-stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[--Wwarn=uninitialized_use] warning: retval may be uninitialized
[--Wwarn=uninitialized_use] warning: retval may be uninitialized
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ control ingress(inout Headers h, inout Meta m, inout standard_metadata_t sm) {
} else {
val_0 = 8w3;
}
if (hasReturned) {
;
} else {
hasReturned = true;
}
h.h.a = val_0;
}
@name("ingress.simple_table") table simple_table_0 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,10 @@ control ingress(inout Headers h, inout Meta m, inout standard_metadata_t sm) {
@name("ingress.tmp") bit<48> tmp;
@name("ingress.tmp_0") bit<8> tmp_0;
@name("ingress.tmp_1") bit<48> tmp_1;
@name("ingress.hasReturned") bool hasReturned;
@name("ingress.retval") bit<8> retval;
apply {
if (h.eth_hdr.src_addr < 48w10) {
tmp = h.eth_hdr.dst_addr;
hasReturned = false;
hasReturned = true;
retval = 8w2;
tmp_0 = retval;
tmp_1 = tmp << tmp_0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,11 @@ control ingress(inout Headers h, inout Meta m, inout standard_metadata_t sm) {
@name("ingress.inout_c") bit<8> inout_c_2;
@name("ingress.do_thing") action do_thing() {
inout_c_0 = c_0;
h.h.a = inout_c_0;
c_0 = inout_c_0;
}
@name("ingress.do_thing") action do_thing_1() {
inout_c_2 = c_0;
h.h.a = inout_c_2;
c_0 = inout_c_2;
}
apply {
c_0 = 8w12;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ struct Meta {

control ingress(inout Headers h, inout Meta m, inout standard_metadata_t sm) {
@name("ingress.do_thing") action do_thing() {
h.h.a = 8w12;
}
@name("ingress.do_thing") action do_thing_1() {
h.h.a = 8w12;
}
@hidden table tbl_do_thing {
actions = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ control ingress(inout Headers h, inout Meta m, inout standard_metadata_t sm) {
dummy_0 = h.eth_hdr.src_addr;
h.eth_hdr.src_addr = dummy_0;
exit;
h.eth_hdr.src_addr = dummy_0;
}
apply {
simple_action();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ parser p(packet_in pkt, out Headers hdr, inout Meta m, inout standard_metadata_t
}

control ingress(inout Headers h, inout Meta m, inout standard_metadata_t sm) {
@name("ingress.hasReturned") bool hasReturned;
@name("ingress.simple_action") action simple_action() {
hasReturned = false;
hasReturned = true;
}
apply {
simple_action();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,14 @@ control ingress(inout Headers h, inout Meta m, inout standard_metadata_t sm) {
@noWarn("unused") @name(".NoAction") action NoAction_1() {
}
@name("ingress.do_action") action do_action() {
val_0 = h.eth_hdr.src_addr;
val_0 = 48w2;
h.eth_hdr.src_addr = val_0;
exit;
h.eth_hdr.src_addr = val_0;
}
@name("ingress.do_action") action do_action_1() {
val_2 = h.eth_hdr.dst_addr;
val_2 = 48w2;
h.eth_hdr.dst_addr = val_2;
exit;
h.eth_hdr.dst_addr = val_2;
}
@name("ingress.simple_table") table simple_table_0 {
key = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ parser p(packet_in pkt, out Headers hdr, inout Meta m, inout standard_metadata_t
}

control ingress(inout Headers h, inout Meta m, inout standard_metadata_t sm) {
@name("ingress.hasReturned") bool hasReturned;
apply {
hasReturned = false;
hasReturned = true;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@ parser p(packet_in pkt, out Headers hdr, inout Meta m, inout standard_metadata_t
}

control ingress(inout Headers h, inout Meta m, inout standard_metadata_t sm) {
@name("ingress.hasReturned") bool hasReturned;
@name("ingress.retval") ethernet_t retval;
apply {
hasReturned = false;
hasReturned = true;
retval.setValid();
retval = (ethernet_t){dst_addr = 48w1,src_addr = 48w1,eth_type = 16w1};
h.eth_hdr = retval;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,9 @@ struct Meta {
control ingress(inout Headers h, inout Meta m, inout standard_metadata_t sm) {
@name("ingress.tmp") bit<8> tmp;
@name("ingress.c") bit<32> c_0;
@name("ingress.d_0") bit<32> d;
@name("ingress.hasReturned") bool hasReturned;
@name("ingress.retval") bit<8> retval;
@name("ingress.action_thing") action action_thing() {
c_0 = sm.enq_timestamp;
hasReturned = false;
hasReturned = true;
retval = 8w1;
c_0 = d;
tmp = retval;
c_0 = (bit<32>)tmp;
sm.enq_timestamp = c_0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ bit<8> do_thing(out bit<32> d) {
gauntlet_function_return-bmv2.p4(15)
bit<8> do_thing(out bit<32> d) {
^^^^^^^^
[--Wwarn=uninitialized_use] warning: d_0 may be uninitialized
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@ parser p(packet_in pkt, out Headers hdr, inout Meta m, inout standard_metadata_t

control ingress(inout Headers h, inout Meta m, inout standard_metadata_t sm) {
@name("ingress.tmp") bit<8> tmp;
@name("ingress.hasReturned") bool hasReturned;
@name("ingress.retval") bit<8> retval;
apply {
hasReturned = false;
hasReturned = true;
retval = 8w255;
tmp = retval;
h.eth_hdr.eth_type = (bit<16>)tmp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ control ingress(inout Headers h, inout Meta m, inout standard_metadata_t sm) {
@name("ingress.val_0") bit<16> val;
@name("ingress.hasReturned") bool hasReturned;
@name("ingress.retval") ethernet_t retval;
@name("ingress.hasReturned_0") bool hasReturned_0;
@name("ingress.retval_0") ethernet_t retval_0;
apply {
val = h.eth_hdr1.eth_type;
Expand All @@ -45,14 +44,10 @@ control ingress(inout Headers h, inout Meta m, inout standard_metadata_t sm) {
if (hasReturned) {
;
} else {
hasReturned = true;
retval.setValid();
retval = (ethernet_t){dst_addr = 48w3,src_addr = 48w3,eth_type = 16w3};
}
h.eth_hdr1.eth_type = val;
h.eth_hdr1 = retval;
hasReturned_0 = false;
hasReturned_0 = true;
retval_0.setValid();
retval_0 = (ethernet_t){dst_addr = 48w1,src_addr = 48w1,eth_type = 16w1};
h.eth_hdr2 = retval_0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ control ingress(inout Headers h, inout Meta m, inout standard_metadata_t sm) {
hasReturned = false;
}
@hidden action gauntlet_hdr_function_castbmv2l26() {
hasReturned = true;
retval.setValid();
retval.dst_addr = 48w3;
retval.src_addr = 48w3;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[--Wwarn=uninitialized_use] warning: retval may not be completely initialized
[--Wwarn=uninitialized_use] warning: retval may not be completely initialized
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@ parser p(packet_in pkt, out Headers hdr, inout Meta m, inout standard_metadata_t
}

control ingress(inout Headers h, inout Meta m, inout standard_metadata_t sm) {
@name("ingress.hasReturned") bool hasReturned;
@name("ingress.retval") bit<16> retval;
apply {
hasReturned = false;
hasReturned = true;
retval = ((Headers){eth_hdr = (ethernet_t){dst_addr = 48w1,src_addr = 48w1,eth_type = 16w1}}).eth_hdr.eth_type + 16w1;
h.eth_hdr.eth_type = retval;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
gauntlet_hdr_out_in_action-bmv2.p4(35): [--Wwarn=unused] warning: 'val' is unused
action do_action(out ethernet_t val) {
^^^
gauntlet_hdr_out_in_action-bmv2.p4(35): [--Wwarn=uninitialized_use] warning: val may not be completely initialized
action do_action(out ethernet_t val) {
^^^
Loading