-
Notifications
You must be signed in to change notification settings - Fork 449
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
Remove apply() calls to redundant parsers #3356
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
Copyright 2013-present Barefoot Networks, Inc. | ||
Copyright 2022-present Barefoot Networks, Inc. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
|
@@ -14,22 +14,23 @@ See the License for the specific language governing permissions and | |
limitations under the License. | ||
*/ | ||
|
||
#ifndef _P4_REDUNDANT_PARSERS_H | ||
#define _P4_REDUNDANT_PARSERS_H | ||
#ifndef FRONTENDS_P4_REDUNDANTPARSERS_H_ | ||
#define FRONTENDS_P4_REDUNDANTPARSERS_H_ | ||
|
||
#include "ir/ir.h" | ||
#include "typeMap.h" | ||
|
||
namespace P4 { | ||
|
||
class TypeMap; | ||
|
||
/** Find parsers that have an unconditional "accept" in their start | ||
* state, and put them in redundantParsers. | ||
*/ | ||
class FindRedundantParsers : public Inspector { | ||
std::set<cstring> &redundantParsers; | ||
bool preorder(const IR::P4Parser *parser) override; | ||
public: | ||
FindRedundantParsers(std::set<cstring> &redundantParsers) | ||
explicit FindRedundantParsers(std::set<cstring> &redundantParsers) | ||
: redundantParsers(redundantParsers) { } | ||
}; | ||
|
||
|
@@ -40,16 +41,16 @@ class EliminateSubparserCalls : public Transform { | |
const std::set<cstring> &redundantParsers; | ||
TypeMap *typeMap; | ||
const IR::Node *postorder(IR::MethodCallStatement *methodCallStmt) override; | ||
public: | ||
public: | ||
EliminateSubparserCalls(const std::set<cstring> &redundantParsers, TypeMap *typeMap) | ||
: redundantParsers(redundantParsers), typeMap(typeMap) | ||
{ } | ||
}; | ||
|
||
class RemoveRedundantParsers : public PassManager { | ||
std::set<cstring> redundantParsers; | ||
public: | ||
RemoveRedundantParsers(TypeMap *typeMap) | ||
public: | ||
explicit RemoveRedundantParsers(TypeMap *typeMap) | ||
: PassManager { | ||
new FindRedundantParsers(redundantParsers), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you want the 'type' field to be correct then you have to insert a call to typeChecking here. But it's probably simpler in that case to pass the computed typeMap annd use MethodInstance with a typeMap argument. |
||
new EliminateSubparserCalls(redundantParsers, typeMap) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The typeMap will always be empty the way you inserted this pass. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you do you will need a handle to the referenceMap too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I changed it to run before |
||
|
@@ -60,4 +61,4 @@ class RemoveRedundantParsers : public PassManager { | |
|
||
} | ||
|
||
#endif | ||
#endif /* FRONTENDS_P4_REDUNDANTPARSERS_H_ */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why string and not IR::P4Parser?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried using
IR::P4Parser *
, it didn't quite work because the pointers discovered inRemoveRedundantParsers
did not match those found earlier, despite having the same name. Is there supposed to be a single instance of every declaration in the IR?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a transform you should use getOriginal(), there are lots of examples in the code