Skip to content

Commit

Permalink
DPDK Backend: Move learn instructions constant argument to metadata (#…
Browse files Browse the repository at this point in the history
…3163)

* Move learn instructions constant argument to metadata
  • Loading branch information
usha1830 authored Apr 1, 2022
1 parent 8136060 commit 58defb7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
10 changes: 8 additions & 2 deletions backends/dpdk/dpdkHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,13 @@ bool ConvertStatementToDpdk::preorder(const IR::MethodCallStatement *s) {
auto argument = param->to<IR::StructExpression>()->components.at(0)->expression;
add_instr(new IR::DpdkLearnStatement(action_name, argument));
} else if (param->is<IR::Constant>()) {
add_instr(new IR::DpdkLearnStatement(action_name, param));
// Move constant param to metadata as DPDK expects it to be in metadata
BUG_CHECK(metadataStruct, "Metadata structure missing unexpectedly!");
IR::ID learnArg(refmap->newName("learnArg"));
metadataStruct->fields.push_back(new IR::StructField(learnArg, param->type));
auto learnMember = new IR::Member(new IR::PathExpression("m"), learnArg);
add_instr(new IR::DpdkMovStatement(learnMember, param));
add_instr(new IR::DpdkLearnStatement(action_name, learnMember));
} else {
::error("%1%: unhandled function", s);
}
Expand All @@ -785,7 +791,7 @@ bool ConvertStatementToDpdk::preorder(const IR::MethodCallStatement *s) {
return false;
}

// Mov slot id and session id to metadata fields as DPDK expects these parameters
// Move slot id and session id to metadata fields as DPDK expects these parameters
// to be in metadata
BUG_CHECK(metadataStruct, "Metadata structure missing unexpectedly!");
IR::ID slotName(refmap->newName("mirrorSlot"));
Expand Down
4 changes: 3 additions & 1 deletion testdata/p4_16_samples_outputs/pna-add-on-miss.p4.spec
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ struct main_metadata_t {
bit<32> pna_main_output_metadata_output_port
bit<32> MainControlT_tmp
bit<32> MainControlT_tmp_0
bit<32> learnArg
}
metadata instanceof main_metadata_t

Expand All @@ -44,7 +45,8 @@ action next_hop args instanceof next_hop_arg_t {
}

action add_on_miss_action args none {
learn next_hop 0x0
mov m.learnArg 0x0
learn next_hop m.learnArg
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ struct main_metadata_t {
bit<32> MainControlT_tmp_1
bit<32> MainControlT_tmp_2
bit<32> MainControlT_tmp_3
bit<32> learnArg
}
metadata instanceof main_metadata_t

Expand All @@ -85,7 +86,8 @@ action next_hop args instanceof next_hop_arg_t {
}

action add_on_miss_action args none {
learn next_hop 0x0
mov m.learnArg 0x0
learn next_hop m.learnArg
return
}

Expand Down
4 changes: 3 additions & 1 deletion testdata/p4_16_samples_outputs/pna-mux-dismantle.p4.spec
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ struct main_metadata_t {
bit<32> MainControlT_tmp_2
bit<32> MainControlT_tmp_3
bit<32> MainControlT_tmp_4
bit<32> learnArg
}
metadata instanceof main_metadata_t

Expand All @@ -85,7 +86,8 @@ action next_hop args instanceof next_hop_arg_t {
}

action add_on_miss_action args none {
learn next_hop 0x0
mov m.learnArg 0x0
learn next_hop m.learnArg
return
}

Expand Down

0 comments on commit 58defb7

Please sign in to comment.