-
Notifications
You must be signed in to change notification settings - Fork 445
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
Doxygen comments #614
Doxygen comments #614
Changes from 12 commits
cbb2329
7c18e91
d33e67f
deb9e6a
5f59a6d
e949988
77963bd
9e90674
38b609e
1009b53
005edb1
4033dc0
9e5d5bd
7de9191
bc99186
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,13 +23,16 @@ limitations under the License. | |
|
||
namespace P4 { | ||
|
||
// For each action that is invoked keep the list of arguments that it's called with. | ||
// There must be only one call of each action; this is done by LocalizeActions. | ||
/** | ||
* For each action that is invoked keep the list of arguments that | ||
* it's called with. There must be only one call of each action; | ||
* this is done by LocalizeActions. | ||
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. Would be nice to use 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. Done |
||
*/ | ||
class ActionInvocation { | ||
std::map<const IR::P4Action*, const IR::MethodCallExpression*> invocations; | ||
std::set<const IR::P4Action*> all; // for these actions remove all parameters | ||
std::set<const IR::MethodCallExpression*> calls; | ||
// how many arguments to remove from each default action | ||
/// how many arguments to remove from each default action | ||
std::map<const IR::MethodCallExpression*, unsigned> defaultActions; | ||
|
||
public: | ||
|
@@ -83,19 +86,30 @@ class FindActionParameters : public Inspector { | |
void postorder(const IR::MethodCallExpression* expression) override; | ||
}; | ||
|
||
// Removes parameters of an action which are in/inout/out. | ||
// For this to work each action must have a single caller. | ||
// (This is done by the LocalizeActions pass). | ||
// control c(inout bit<32> x) { | ||
// action a(in bit<32> arg) { x = arg; } | ||
// table t() { actions = { a(10); } } | ||
// apply { ... } } | ||
// is converted to | ||
// control c(inout bit<32> x) { | ||
// bit<32> arg; | ||
// action a() { arg = 10; x = arg; } | ||
// table t() { actions = { a; } } | ||
// apply { ... } } | ||
/** | ||
* Removes parameters of an action which are in/inout/out. | ||
* | ||
* \code{.cpp} | ||
* control c(inout bit<32> x) { | ||
* action a(in bit<32> arg) { x = arg; } | ||
* table t() { actions = { a(10); } } | ||
* apply { ... } } | ||
* \endcode | ||
* | ||
* is converted to | ||
* | ||
* \code{.cpp} | ||
* control c(inout bit<32> x) { | ||
* bit<32> arg; | ||
* action a() { arg = 10; x = arg; } | ||
* table t() { actions = { a; } } | ||
* apply { ... } } | ||
* \endcode | ||
* | ||
* @pre This pass requires each action to have a single caller. | ||
* It must run after the LocalizeActions pass. | ||
* @post in/inout/out parameters of an action are removed. | ||
*/ | ||
class DoRemoveActionParameters : public Transform { | ||
ActionInvocation* invocations; | ||
public: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,15 +23,19 @@ limitations under the License. | |
|
||
namespace P4 { | ||
|
||
// Policy used to decide whether a key expression is too complex. | ||
/** | ||
* Policy used to decide whether a key expression is too complex. | ||
*/ | ||
class KeyIsComplex { | ||
public: | ||
virtual ~KeyIsComplex() {} | ||
virtual bool isTooComplex(const IR::Expression* expression) const = 0; | ||
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 isTooComplex function requires a comment. |
||
}; | ||
|
||
// Policy which returns 'true' whenever a key is not a left value | ||
// or a call to the isValid(). | ||
/** | ||
* Policy that tracks whether a key is not a left value or a call to the isValid(). | ||
* It returns 'true' if any of the conditions is met. | ||
*/ | ||
class NonLeftValue : public KeyIsComplex { | ||
ReferenceMap* refMap; | ||
TypeMap* typeMap; | ||
|
@@ -42,7 +46,9 @@ class NonLeftValue : public KeyIsComplex { | |
bool isTooComplex(const IR::Expression* expression) const; | ||
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. How does "too complex" related to l-value-ness? 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 pass applies to non-lvalue expressions. All lvalues are considered not complex and therefore not transformed. |
||
}; | ||
|
||
// Policy that allows masked lvalues as well as simple lvalues or isValid() | ||
/** | ||
* Policy that tracks whether a expression is masked non-lvalue, simple non-lvalue or isValid() | ||
*/ | ||
class NonMaskLeftValue : public NonLeftValue { | ||
public: | ||
NonMaskLeftValue(ReferenceMap* refMap, TypeMap* typeMap) : NonLeftValue(refMap, typeMap) {} | ||
|
@@ -61,8 +67,36 @@ class TableInsertions { | |
std::vector<const IR::AssignmentStatement*> statements; | ||
}; | ||
|
||
// If some of the fields of a table key are "too complex", | ||
// turn them into simpler expressions. | ||
/** | ||
* Transform complex table keys into simpler expressions. | ||
* | ||
* \code{.cpp} | ||
* table t { | ||
* key = { h.a + 1 : exact; } | ||
* ... | ||
* } | ||
* apply { | ||
* t.apply(); | ||
* } | ||
* \endcode | ||
* | ||
* is transformed to | ||
* | ||
* \code{.cpp} | ||
* bit<32> key_0; | ||
* table t { | ||
* key = { key_0 : exact; } | ||
* ... | ||
* } | ||
* apply { | ||
* key_0 = h.a + 1; | ||
* t.apply(); | ||
* } | ||
* \endcode | ||
* | ||
* @pre none | ||
* @post all complex non-lvalue table key expressions are replaced with a lvalue expression. | ||
*/ | ||
class DoSimplifyKey : public Transform { | ||
ReferenceMap* refMap; | ||
TypeMap* typeMap; | ||
|
@@ -86,7 +120,12 @@ class DoSimplifyKey : public Transform { | |
const IR::Node* postorder(IR::P4Table* table) override; | ||
}; | ||
|
||
// Use a policy to decide when a key expression is too complex. | ||
/** | ||
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. This is incorrect, this pass actually simplifies the keys, it does not determine anything. |
||
* This pass uses 'policy' to determine whether a key expression is too complex. | ||
* Policies are defined in 'NonLeftValue' and 'NonMaskLeftValue', which consider | ||
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. This pass should not list all possible policies; we can't be updating this comment every time we write a new policy. |
||
* any non-lvalue, except built-in method (isValid) in table key expressions | ||
* as complex expressions. | ||
*/ | ||
class SimplifyKey : public PassManager { | ||
public: | ||
SimplifyKey(ReferenceMap* refMap, TypeMap* typeMap, const KeyIsComplex* policy) { | ||
|
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.
Nice! The example illustrates this transformation perfectly.
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 this be typeset as code in Doxygen?