
Public Member Functions | |
| HandleValidityHeaderUnion (P4::ReferenceMap *refMap, P4::TypeMap *typeMap) | |
| const IR::Node * | expandIsValid (const IR::Statement *a, const IR::MethodCallExpression *mce, IR::IndexedVector< IR::StatOrDecl > &code_block) |
| const IR::Node * | postorder (IR::AssignmentStatement *assn) override |
| const IR::Node * | postorder (IR::IfStatement *a) override |
| const IR::Node * | postorder (IR::MethodCallStatement *mcs) override |
| const IR::Node * | postorder (IR::P4Action *action) override |
| const IR::Node * | postorder (IR::P4Control *control) override |
| const IR::Node * | postorder (IR::P4Parser *parser) override |
| const IR::Node * | postorder (IR::SwitchStatement *a) override |
| const IR::MethodCallStatement * | processValidityForStr (const IR::Statement *s, const IR::Member *m, cstring headerElement, cstring setValid) |
| const IR::Node * | setInvalidforRest (const IR::Statement *s, const IR::Member *m, const IR::Type_HeaderUnion *hu, cstring exclude, bool setValidforCurrMem) |
This pass handles the validity semantics of header union. 1) On assignment to any element of the header union, it is set to Valid and other elements of the header union are set to Invalid. a) U u; | if (my_h1.isValid()) { H1 my_h1 = { 8w0 }; | u_h1.setValid(); u.h1 = my_h1; | // all other elements set to Invalid | u_h1 = my_h1; | } else { | u_h1.setInvalid() | } b) u.h1 = {16W1} | This is already transformed into individual element copy | by earlier passes and individual assignment is translated | as same as (a) c) u1.h1 = u2.h1 | same as a) with my_h1 replaced with u2_h1 d) u1 = u2 | This is already transformed into individual element copy | by earlier passes and individual assignment is translated | same as (c) e) a = u.isValid() | tmp = 0; Only one element should be valid | for elements in union | if (element.isvalid) | tmp += 1; | a = tmp == 1
2) When isValid is used as if statement's condition or switch expression, the expression is replaced with tmp calculated in (1e) a) switch(u.isValid()) | switch (tmp == 1) b) if(u.isValid()) | if (tmp == 1) 3) When setValid method is called on a header element, it is translated to setValid for the given element and setInvalid for rest of the elements 4) Equality/inequality comparisons on unions are unrolled into element-wise comparisons by earlier passes and hence no-action required here.