-
Notifications
You must be signed in to change notification settings - Fork 444
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
Make sure P4 expression optimization does not strip away types #4300
Changes from all commits
2f5e9e9
3e02097
220c9e3
f23a2cc
720927a
2915f4f
5e29632
fc66333
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 |
---|---|---|
|
@@ -37,7 +37,9 @@ std::vector<std::pair<IR::StateVariable, const IR::Expression *>> ExprStepper::s | |
ExecutionState &nextState, const std::vector<IR::StateVariable> &flatFields, | ||
int varBitFieldSize) { | ||
std::vector<std::pair<IR::StateVariable, const IR::Expression *>> fields; | ||
for (const auto &fieldRef : flatFields) { | ||
// Make a copy of the StateVariable so it can be modified in the varbit case (and it is just a | ||
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. Hmm, in this case we are making a copy for the common case (no Varbit). Is that really better? 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 quite small class (one pointer + vptr) so I'd say this does not matter either way. Could be even better since there will be no dereference, but could be also exactly the same if the optimizer is smart enough (I haven't checked). 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. Yeah I think that is a check we should keep in this particular setter. The other code can be moved out. 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. I'm confused, you have presubmably replied to a different thread, did you mean that the check for type being set in the expression should be (also) in 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. Yes, the comment was meant for #4300 (comment). Not sure what happened. |
||
// pointer wrapper anyway). | ||
for (IR::StateVariable fieldRef : flatFields) { | ||
const auto *fieldType = fieldRef->type; | ||
// If the header had a varbit, the header needs to be updated. | ||
// We assign @param varbitFeldSize to the varbit field. | ||
|
@@ -62,15 +64,12 @@ std::vector<std::pair<IR::StateVariable, const IR::Expression *>> ExprStepper::s | |
// We need to cast the generated variable to the appropriate type. | ||
if (fieldType->is<IR::Extracted_Varbits>()) { | ||
pktVar = new IR::Cast(fieldType, pktVar); | ||
// Update the field and add the field to the return list. | ||
// TODO: Better way to handle varbits here? | ||
auto *newRef = fieldRef->clone(); | ||
newRef->type = fieldType; | ||
nextState.set(fieldRef, pktVar); | ||
fields.emplace_back(fieldRef, pktVar); | ||
continue; | ||
} | ||
if (const auto *bits = fieldType->to<IR::Type_Bits>()) { | ||
// Rewrite the type of the field so it matches the extracted varbit type. | ||
// TODO: is there a better way to do this? | ||
auto *newRefExpr = fieldRef->clone(); | ||
newRefExpr->type = fieldType; | ||
fieldRef.ref = newRefExpr; | ||
} else if (const auto *bits = fieldType->to<IR::Type_Bits>()) { | ||
if (bits->isSigned) { | ||
pktVar = new IR::Cast(fieldType, pktVar); | ||
} | ||
|
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 we remove the optimization, I'm not sure if the check if type is set should be here too? May not be necessary for all tools that use
SymbolicEnv
.