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

Replace pna direction with register read #3224

Merged
merged 6 commits into from
Apr 20, 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
27 changes: 12 additions & 15 deletions backends/dpdk/dpdkMetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,25 @@ void DirectionToRegRead::uniqueNames(IR::DpdkAsmProgram *p) {
}
reg_read_tmp = mng.newName("reg_read_tmp");
left_shift_tmp = mng.newName("left_shift_tmp");
registerInstanceName = "network_port_mask";

P4::MinimalNameGenerator mng1;
for (auto decl : p->externDeclarations) {
mng1.usedName(decl->name);
}
// "network_port_mask" name is used in dpdk for initialzing direction port mask
// make sure no such decls exist with that name
if (mng1.newName(registerInstanceName) != registerInstanceName)
registerInstanceName = "network_port_mask";
for (auto decl : p->externDeclarations) {
usedNames.insert(decl->name);
}

if (usedNames.count(registerInstanceName))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works if usedNames contains everything you need to check for. I was hoping that you'd add a new method MinimalNameGenerator::nameIsUsed(cstring name)

::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET,"decl name %s is reserved for dpdk pna",
registerInstanceName);
}

const IR::Node* DirectionToRegRead::preorder(IR::DpdkAsmProgram *p) {
uniqueNames(p);
p->externDeclarations.push_back(addRegDeclInstance(registerInstanceName));
return p;
uniqueNames(p);
addMetadataField(reg_read_tmp);
addMetadataField(left_shift_tmp);
p->externDeclarations.push_back(addRegDeclInstance(registerInstanceName));
return p;
}

// create and add register declaration instance to program
Expand All @@ -80,11 +82,8 @@ IR::DpdkExternDeclaration* DirectionToRegRead::addRegDeclInstance(cstring instan

// add new fields in metadata structure
void DirectionToRegRead::addMetadataField(cstring fieldName) {
if (newFieldName.count(fieldName))
return;
newMetadataFields.push_back(new IR::StructField(IR::ID(fieldName),
newMetadataFields.push_back(new IR::StructField(IR::ID(fieldName),
IR::Type::Bits::get(32)));
newFieldName.insert(fieldName);
}

// check member expression using metadata direction field
Expand All @@ -111,8 +110,6 @@ const IR::Node *DirectionToRegRead::postorder(IR::DpdkAction *a) {
// replace direction field uses with register read i.e.
// istd.direction -> (direction_port_mask.read(0) & (32w0x1 << istd.input_port))
void DirectionToRegRead::replaceDirection(const IR::Member *m) {
addMetadataField(reg_read_tmp);
addMetadataField(left_shift_tmp);
auto reade = new IR::Member(new IR::PathExpression(IR::ID("m")),
IR::ID(reg_read_tmp));
auto reads = new IR::DpdkRegisterReadStatement(reade, registerInstanceName,
Expand Down
10 changes: 9 additions & 1 deletion backends/dpdk/dpdkMetadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,25 @@ limitations under the License.

namespace DPDK {

// If any pass requires to add metadata field to metadata structure
// then just have to create and append struct field to static member newMetadataFields
// In passmanager's passes list AddNewMetadataFields should follow the pass which
// added fields into newMetadataFields
class AddNewMetadataFields : public Transform {
mihaibudiu marked this conversation as resolved.
Show resolved Hide resolved
public:
static IR::IndexedVector<IR::StructField> newMetadataFields;
const IR::Node* preorder(IR::DpdkStructType *st) override;
};

// This pass adds decl instance of Register extern in dpdk pna program which will
// be used by dpdk backend for initializing the mask for calculating packet direction
// and all the use point of istd.direction will follow below calculation and assignment
// istd.direction = network_port_mask.read(0) & (32w0x1 << istd.input_port)
class DirectionToRegRead : public Transform {
ordered_map<cstring, cstring> dirToInput;
IR::IndexedVector<IR::DpdkAsmStatement> newStmts;
IR::IndexedVector<IR::StructField> &newMetadataFields = AddNewMetadataFields::newMetadataFields;
ordered_set<cstring> newFieldName;
ordered_set<cstring> usedNames;
cstring reg_read_tmp;
cstring left_shift_tmp;
cstring registerInstanceName;
Expand Down