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 1 commit
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
Prev Previous commit
Next Next commit
Run def-use analysis after inlining
Signed-off-by: Mihai Budiu <mbudiu@vmware.com>
  • Loading branch information
Mihai Budiu committed Oct 21, 2022
commit c9ed0aa2c18496e3ca953e6073202f56a72b299e
4 changes: 4 additions & 0 deletions frontends/p4/simplifyDefUse.cpp
Original file line number Diff line number Diff line change
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
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
Expand Up @@ -23,8 +23,6 @@ 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(".do_action") action do_action_0() {
}
apply {
}
}
Expand All @@ -51,3 +49,4 @@ control deparser(packet_out pkt, in Headers h) {
}

V1Switch<Headers, Meta>(p(), vrfy(), ingress(), egress(), update(), deparser()) main;

15 changes: 8 additions & 7 deletions testdata/p4_16_samples_outputs/issue1765-1-bmv2-midend.p4
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ struct headers {
}

struct metadata {
@field_list(0)
port_t ingress_port;
@field_list(0)
task_t task;
@field_list(0)
@field_list(0)
bit<9> ingress_port;
@field_list(0)
bit<16> task;
@field_list(0)
bit<16> tcp_length;
@field_list(0)
@field_list(0)
bit<32> cast_length;
@field_list(0)
@field_list(0)
bit<1> do_cksum;
}

Expand Down Expand Up @@ -299,3 +299,4 @@ control MyEgress(inout headers hdr, inout metadata meta, inout standard_metadata
}

V1Switch<headers, metadata>(MyParser(), MyVerifyChecksum(), MyIngress(), MyEgress(), MyComputeChecksum(), MyDeparser()) main;

3 changes: 0 additions & 3 deletions testdata/p4_16_samples_outputs/issue2648-frontend.p4
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@ parser p(packet_in pkt, out Headers hdr) {
control ingress(inout Headers h) {
@name("ingress.tmp") bit<8> tmp;
@name("ingress.tmp_0") bit<8> tmp_0;
@name("ingress.hasReturned") bool hasReturned;
@name("ingress.retval") bit<8> retval;
apply {
hasReturned = false;
hasReturned = true;
retval = ((H){a = 8w1}).a;
tmp = retval;
tmp_0 = tmp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ control ingress(inout headers hdr, inout metadata meta, in pna_main_input_metada
if (hasReturned) {
;
} else {
hasReturned = true;
retval = false;
}
tmp = retval;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ control ingress(inout headers hdr, inout metadata meta, in pna_main_input_metada
hasReturned = false;
}
@hidden action pnaexampleheaderunion1l52() {
hasReturned = true;
retval = false;
}
@hidden action pnaexampleheaderunion1l73() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
[--Wwarn=uninitialized_use] warning: retval may be uninitialized
[--Wwarn=uninitialized_use] warning: retval may be uninitialized
[--Wwarn=mismatch] warning: Mismatched header/metadata struct for key elements in table debug_hdr. Copying all match fields to metadata
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 @@ -77,8 +77,7 @@ apply {
mov m.MainControlT_retval 1
LABEL_END_3 : jmpneq LABEL_FALSE_2 m.MainControlT_hasReturned 0x1
jmp LABEL_END_4
LABEL_FALSE_2 : mov m.MainControlT_hasReturned 1
mov m.MainControlT_retval 0
LABEL_FALSE_2 : mov m.MainControlT_retval 0
LABEL_END_4 : jmpneq LABEL_END_5 m.MainControlT_retval 0x1
mov h.base.t 0x3
LABEL_END_5 : jmpnv LABEL_FALSE_4 h.u_short
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ control MyIngressControl(inout headers_t hdr, inout user_meta_data_t m, in psa_i
tmp1_0 = m.flag;
if (tmp1_0 == 32w0x1 && tmp2 == 32w0x2) {
m.addr = hdr.ethernet.dst_addr;
hdr.ethernet.dst_addr = hdr.ethernet.src_addr;
hdr.ethernet.src_addr = m.addr;
}
m.flag = tmp1_0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ control MyIngressControl(inout headers_t hdr, inout user_meta_data_t m, in psa_i
hdr.ethernet.src_addr = m.addr;
}
@name("MyIngressControl.macswp") action macswp(@name("tmp2") bit<32> tmp2) {
m.addr = (hdr.ethernet.dst_addr == 48w0x1 && tmp2 == 32w0x2 ? hdr.ethernet.dst_addr : m.addr);
hdr.ethernet.src_addr = (hdr.ethernet.dst_addr == 48w0x1 && tmp2 == 32w0x2 ? m.addr : hdr.ethernet.src_addr);
m.addr = (m.flag == 32w0x1 && tmp2 == 32w0x2 ? hdr.ethernet.dst_addr : m.addr);
hdr.ethernet.dst_addr = (m.flag == 32w0x1 && tmp2 == 32w0x2 ? hdr.ethernet.src_addr : hdr.ethernet.dst_addr);
hdr.ethernet.src_addr = (m.flag == 32w0x1 && tmp2 == 32w0x2 ? m.addr : hdr.ethernet.src_addr);
}
@name("MyIngressControl.stub") table stub_0 {
actions = {
Expand Down Expand Up @@ -96,3 +97,4 @@ IngressPipeline<headers_t, user_meta_data_t, EMPTY, EMPTY, EMPTY, EMPTY>(MyIngre
EgressPipeline<EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY>(MyEgressParser(), MyEgressControl(), MyEgressDeparser()) ep;

PSA_Switch<headers_t, user_meta_data_t, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY>(ip, PacketReplicationEngine(), ep, BufferingQueueingEngine()) main;

Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ struct user_meta_data_t {
bit<8> psa_ingress_output_metadata_drop
bit<32> psa_ingress_output_metadata_egress_port
bit<48> local_metadata_addr
bit<32> local_metadata_flag
}
metadata instanceof user_meta_data_t

Expand All @@ -47,10 +48,11 @@ action nonDefAct args none {
}

action macswp args instanceof macswp_arg_t {
jmpneq LABEL_END h.ethernet.dst_addr 0x1
jmpneq LABEL_END m.local_metadata_flag 0x1
jmpneq LABEL_END t.tmp2 0x2
mov m.local_metadata_addr h.ethernet.dst_addr
mov h.ethernet.src_addr h.ethernet.dst_addr
mov h.ethernet.dst_addr h.ethernet.src_addr
mov h.ethernet.src_addr m.local_metadata_addr
LABEL_END : return
}

Expand All @@ -59,7 +61,7 @@ table stub {
macswp
nonDefAct
}
default_action macswp args tmp2 0x3
default_action macswp args tmp2 0x3
size 0xf4240
}

Expand All @@ -77,3 +79,5 @@ apply {
tx m.psa_ingress_output_metadata_egress_port
LABEL_DROP : drop
}