-
Notifications
You must be signed in to change notification settings - Fork 448
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
Conversation
frontends/p4/redundantParsers.h
Outdated
|
||
} | ||
|
||
#endif |
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.
cpplint will want this to be followed by a comment
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.
Done
frontends/p4/redundantParsers.h
Outdated
limitations under the License. | ||
*/ | ||
|
||
#ifndef _P4_REDUNDANT_PARSERS_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.
please use the same format for the macro as in other frontend files; otherwise cpplint will be upset.
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.
Done
frontends/p4/redundantParsers.h
Outdated
@@ -0,0 +1,63 @@ | |||
/* | |||
Copyright 2013-present Barefoot Networks, Inc. |
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 not 2022?
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.
Fixed
frontends/p4/redundantParsers.h
Outdated
* state, and put them in redundantParsers. | ||
*/ | ||
class FindRedundantParsers : public Inspector { | ||
std::set<cstring> &redundantParsers; |
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 in RemoveRedundantParsers
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
frontends/p4/redundantParsers.h
Outdated
RemoveRedundantParsers(TypeMap *typeMap) | ||
: PassManager { | ||
new FindRedundantParsers(redundantParsers), | ||
new EliminateSubparserCalls(redundantParsers, typeMap) |
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.
The typeMap will always be empty the way you inserted this pass.
Don't you need to invoke the typechecker first?
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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
I changed it to run before ClearTypeMap
. Though from my testing, even before the type map was not empty when this pass was run.
frontends/p4/redundantParsers.cpp
Outdated
} | ||
|
||
const IR::Node *EliminateSubparserCalls::postorder(IR::MethodCallStatement *mcs) { | ||
auto method = mcs->methodCall->method; |
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.
There's a helper class called MethodInstance which can help with this.
It will return an ApplyMethod
object for a parser invocation.
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 that, but I was hitting some assertion failures. Maybe there are still some issues with MethodInstance
, I can look into that.
00f1389
to
13cb8ca
Compare
I've updated the code to use |
frontends/p4/redundantParsers.cpp
Outdated
@@ -0,0 +1,66 @@ | |||
/* | |||
Copyright 2013-present Barefoot Networks, Inc. |
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.
Did you really wait 9 years to subit this patch?
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.
Fixed
frontends/p4/redundantParsers.cpp
Outdated
} | ||
|
||
const IR::Node *EliminateSubparserCalls::postorder(IR::MethodCallStatement *mcs) { | ||
if (mcs->methodCall->method->type->is<IR::Type_Unknown>()) return mcs; |
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
public: | ||
explicit RemoveRedundantParsers(ReferenceMap *refMap) | ||
: PassManager { | ||
new FindRedundantParsers(redundantParsers), |
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.
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.
A parser with an unconditional accept in its start state is effectively a redundant/dummy parser and can be eliminated when it is called as a subparser. This removes the apply() calls to these subparsers, which also removes the generation of the setInvalid() call in resetHeaders.
Also change the parser tracking to use IR::P4Parser pointers
Also update copyright fields
13cb8ca
to
13842c2
Compare
It looks like the one CI failure is from an internal build system issue, otherwise it's passing. Is this ready to merge in? |
A parser with an unconditional accept in its start state is
effectively a redundant/dummy parser and can be eliminated when it is
called as a subparser. This removes the apply() calls to these
subparsers, which also removes the generation of the setInvalid() call
in resetHeaders.