-
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Rewrite EliminateSubparserCalls to use MethodInstance
Also change the parser tracking to use IR::P4Parser pointers
- Loading branch information
commit bdf58074f92a655980e6d1186d453fc4294df392
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,39 +21,40 @@ limitations under the License. | |
|
||
namespace P4 { | ||
|
||
class TypeMap; | ||
class ReferenceMap; | ||
|
||
/** Find parsers that have an unconditional "accept" in their start | ||
* state, and put them in redundantParsers. | ||
*/ | ||
class FindRedundantParsers : public Inspector { | ||
std::set<cstring> &redundantParsers; | ||
std::set<const IR::P4Parser *> &redundantParsers; | ||
bool preorder(const IR::P4Parser *parser) override; | ||
public: | ||
explicit FindRedundantParsers(std::set<cstring> &redundantParsers) | ||
explicit FindRedundantParsers(std::set<const IR::P4Parser *> &redundantParsers) | ||
: redundantParsers(redundantParsers) { } | ||
}; | ||
|
||
/** Find .apply() calls on parsers that are on redundantParsers, and | ||
* eliminate them. | ||
*/ | ||
class EliminateSubparserCalls : public Transform { | ||
const std::set<cstring> &redundantParsers; | ||
TypeMap *typeMap; | ||
const std::set<const IR::P4Parser *> &redundantParsers; | ||
ReferenceMap *refMap; | ||
const IR::Node *postorder(IR::MethodCallStatement *methodCallStmt) override; | ||
public: | ||
EliminateSubparserCalls(const std::set<cstring> &redundantParsers, TypeMap *typeMap) | ||
: redundantParsers(redundantParsers), typeMap(typeMap) | ||
EliminateSubparserCalls(const std::set<const IR::P4Parser *> &redundantParsers, | ||
ReferenceMap *refMap) | ||
: redundantParsers(redundantParsers), refMap(refMap) | ||
{ } | ||
}; | ||
|
||
class RemoveRedundantParsers : public PassManager { | ||
std::set<cstring> redundantParsers; | ||
std::set<const IR::P4Parser *> redundantParsers; | ||
public: | ||
explicit RemoveRedundantParsers(TypeMap *typeMap) | ||
explicit RemoveRedundantParsers(ReferenceMap *refMap) | ||
: 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) | ||
new EliminateSubparserCalls(redundantParsers, refMap) | ||
} { | ||
setName("RemoveRedundantParsers"); | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 general the type field of an expression is not to be trusted unless you just set it up yourself (probably by calling typeChecking with a 'true' flag).
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.
Updated to run type checking before the new passes