-
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
Midend def-use pass #4489
Midend def-use pass #4489
Conversation
75a1c72
to
4fb2858
Compare
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.
Awesome, thanks a lot for contributing this! Quick initial comments.
941610f
to
11ea3b2
Compare
a2c1f38
to
e4f6e68
Compare
05d38ac
to
3ffef19
Compare
3ffef19
to
a67e80b
Compare
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 am surprised this code does not have any impact on existing ref files.
Why do you say that? The information collected by this pass in the p4test backend is not currently being used by any subsequent passes. |
Nevermind, for some reason I thought this would be used by a latter pass. Ignore my drive-by comment. |
Ideally it will be used by a latter pass. We've just got to wait for someone to write that latter pass 🙂 |
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.
Overall I think this is not quite fully-baked and needs more testing, but getting it in will make that easier to do.
@grg Just to understand the place of this pass as compared to frontend use-def pass. Is it possible to provide some explanation, etc. about the intended usage? |
Co-authored-by: Chris Dodd <[email protected]>
Modify split_slice to add slices when the range doesn't overlap with exisitng slices.
a67e80b
to
f1f07f1
Compare
Fixes: - Mark input parameters as live upon entring a control. (Not trying to propagate liveness information across parser/control boundaries.) - In do_write, when recursively calling do_write for structlike objects, copy struct liveness to all the fields before calling do_write on the target field.
f1f07f1
to
4479239
Compare
I believe the front-end def-use passes identify all the defs of fields (ComputeWriteSet in def_use.h/cpp), and identify which writes have uses (FindUnitialized in simplifyDefUse.cpp), but I don't think these record where the defs are used. This new pass computes the defs and uses for each field, allowing for queries of the form "give me all the defs for node A" or "give me all the uses for node B". Similar defuse information is used in the Tofino compiler for things like live range analysis, which is part of the PHV allocation (roughly register allocation), identifying uninitialized reads coming from P4 code, and additional unused field elimination. The Tofino code uses a backend def-use pass to do this, but Chris has implemented this midend version before switching roles to allow some of this functionality/additional functionality to be placed in the midend. @ChrisDodd Feel free to correct anything I've got wrong or elaborate where you feel it might be useful. |
Contributing a midend def-use analysis pass.
The pass is an inspector named ComputeDefUse. The pass populates a private attribute named
defuse
. This defuse information is queried via one of two functions:getDefs
andgetUses
. Both functions take aconst IR::Node*
parameter and return the defs or uses for that node.There is also a ostream operator that takes a ComputeDefUse object and prints the defuse information in human-readable form. For example:
The
defs
sections show for each element what the corresponding defs are (e.g., the useh.h1.f1
on line 4 of control has a corresponding def on line 0 of control). Similarly, theuses
section shows for each element what the corresponding uses are.This pass has not been extensively tested.
@ChrisDodd The second, third, and fourth commits are changes on top of the original def-use code: they fix a few issues that were uncovered while testing:
The test issue1914-1.p4 provides an example of a control block type declaration:
The midend def-use pass sees this as:
Without the protection in the fourth commit, the pass would call resolveUnique on H and M which both fail.