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

dpdk: Eliminate unused metadata fields #3096

Merged
merged 1 commit into from
Feb 26, 2022

Conversation

kamleshbhalui
Copy link
Contributor

The PSA and PNA architecture require a lot of architecture-specific meta-data fields, but most of them are not actually used by a typical P4 program.

If an architecture-specific meta-data field is defined in the P4 because it is required by the architecture (e.g. PSA or PNA), but this field is not used at all by the P4 program, then this field should not be carried into the output .spec file generated by the P4C-DPDK compiler.

const IR::Node* RemoveUnusedMetadataFields::preorder(IR::DpdkAsmProgram *p) {
auto usedFieldsCollector = new CollectUsedMetadataField();
usedFieldsCollector->setCalledBy(this);
p->apply(*usedFieldsCollector);
Copy link
Contributor

Choose a reason for hiding this comment

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

you can probably call prune() too after this, this visitor does not need to traverse p.
This pattern of allocating the visitor in the preorder makes the program just a bit harder to read, why not just put CollectUsedMetadataFields in the list of backend passes and pass a reference to it to RemoveUnusedMetadataFields (or a reference to the used_fields structure)?
Frankly, it's not a big difference, it up to you, but the other pattern is the one used almost everywhere. We do allocate visitors locally too, but that's usually when we want to apply them to inner nodes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Incorporated the suggestions.

@@ -135,6 +135,27 @@ class RemoveLabelAfterLabel : public Transform {
}
};


// This pass Collects all metadata struct member used in program
class CollectUsedMetadataField : public Inspector {
Copy link
Contributor

Choose a reason for hiding this comment

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

Alternatively, if this pass is used only within dpdkAsmOpt.cpp, it does not need to have a declaration in the header, it can be local to the file (within an empty namespace to avoid name clashes).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now it's used in backend.cpp

class CollectUsedMetadataField : public Inspector {
ordered_set<cstring> used_fields;
public:
bool preorder(const IR::Member *m) override {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not necessarily a field of the metadata structure, but I guess it will include all the fields. So you may keep some extra fields here if they happen to show up in other structures.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now only insert if it's metadata's member.


const IR::Node* RemoveUnusedMetadataFields::preorder(IR::DpdkAsmProgram *p) {
IR::IndexedVector<IR::DpdkStructType> usedStruct;
bool isMetadataStruct = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

I would call this "foundMetadataStruct".
Perhaps you can change it in a future PR.

@mihaibudiu mihaibudiu merged commit ad8baa5 into p4lang:main Feb 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants