-
Notifications
You must be signed in to change notification settings - Fork 463
Move some P4Tool compiler passes to the midend folder. #3726
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
Conversation
27c9148
to
4c41ce4
Compare
These passes should probably have been moved in separate PRs. |
I think you should consider breaking this PR into pieces, shouldn't be too difficult I expect. |
I can split off the CopyStructures pass. The other passes require few file changes. |
4c41ce4
to
66993ee
Compare
@@ -8,7 +8,12 @@ | |||
#include "ir/visitor.h" | |||
#include "lib/source_file.h" | |||
|
|||
namespace P4Tools { | |||
/// This file is a collection of utilities for coverage tracking in P4 programs. Currently, this |
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 question is whether this file should stile in tools or move to the mid end. If there is no use for it, it can stay in tools.
@@ -16,98 +16,77 @@ limitations under the License. | |||
#ifndef _MIDEND_CONVERTERRORS_H_ | |||
#define _MIDEND_CONVERTERRORS_H_ | |||
|
|||
#include <map> |
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 toosl version of convertErrors was merged with the mid end version. They are basically equivalent, it is just that the mid end version did not have a cpp file.
@@ -29,9 +29,9 @@ void HSIndexFinder::addNewVariable() { | |||
newVariable = arrayIndex->right->to<IR::PathExpression>(); |
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.
All the edits here are just linter fixes.
midend/hsIndexSimplify.cpp
Outdated
@@ -225,4 +224,17 @@ IR::Node* HSIndexContretizer::preorder(IR::SwitchStatement* switchStatement) { | |||
return eliminateArrayIndexes(aiFinder, switchStatement, nullptr); | |||
} | |||
|
|||
const IR::Node* HSIndexToMember::postorder(IR::ArrayIndex* curArrayIndex) { |
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.
This class was merged into the hsIndexSimplify file.
midend/hsIndexSimplify.h
Outdated
@@ -102,6 +102,19 @@ class HSIndexSimplifier : public PassManager { | |||
} | |||
}; | |||
|
|||
/// Replaces all ArrayIndex classes with a member classes that have the integer index as string | |||
/// member. | |||
/// WARNING: After applying this pass, the IR will not type check any longer. |
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.
This is important. Maybe worth printing a warning when invoking this pass? But this could be considered spam.
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.
This does not really make it a midend pass, these are supposed to be mixed and matched, but if you run this you're finished.
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 can move this back then. It is a utility pass in some form.
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 move it back?
66993ee
to
d96486d
Compare
I split the mid end passes into individual commits. |
midend/booleanKeys.h
Outdated
* | ||
* \code{.cpp} | ||
* table t { | ||
* key = { (bit<1<) h.a : exact; } |
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.
typo
* \endcode | ||
* | ||
* @pre none | ||
* @post all boolean table key expressions are replaced with a bit<1> cast. Constant entries are |
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.
any problems with the control-plane API after this?
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.
Will check with a dummy commit. There might be issues.
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.
p4c/backends/bmv2/common/expression.cpp
Line 621 in e26a49d
::error(ErrorType::ERR_UNSUPPORTED_ON_TARGET, "%1%: expression too complex for this target", |
This error will fire if we use the pass for the simple switch.
|
||
namespace P4 { | ||
|
||
/** | ||
* Policy function: Determines if the error type should be converted to Ser_Enum. |
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 are you removing this code?
Are you sure no one needs it?
auto tmp = refMap->newName("tmp"); | ||
auto decl = new IR::Declaration_Variable(IR::ID(tmp), type->getP4Type(), nullptr); | ||
auto* decl = new IR::Declaration_Variable(IR::ID(tmp), type->getP4Type(), nullptr); |
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 don't really think these improve the code in any way.
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.
This is a clang-tidy recommendation to comply with this https://llvm.org/docs/CodingStandards.html#beware-unnecessary-copies-with-auto. I do not think it can hurt to use references by default.
midend/hsIndexSimplify.h
Outdated
@@ -102,6 +102,19 @@ class HSIndexSimplifier : public PassManager { | |||
} | |||
}; | |||
|
|||
/// Replaces all ArrayIndex classes with a member classes that have the integer index as string | |||
/// member. | |||
/// WARNING: After applying this pass, the IR will not type check any longer. |
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 move it back?
b652d7d
to
28abe02
Compare
@mbudiu-vmw Are all discussion points resolved? |
I thought you were planning to move hsIndex back into tools. |
I did. The other code was there before. |
Fixes #3518.
I merged the
CopyHeaders
pass into theCopyStructures
pass. This should be checked since I am not sure whether I preserved its semantics correctly.Also there is a question whether
coverage.cpp
should become a part of the midend or remain part of tools. I think it can be generally useful.