-
Notifications
You must be signed in to change notification settings - Fork 156
[CIR] Add get_element
operation for computing pointer to array element
#1748
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
base: main
Are you sure you want to change the base?
Conversation
I don't really have a comment and didn't come up with anything on my review, but IMO, this seems like a good idea. |
I think this is a very good addition to the dialect. |
Thanks for the review @andykaylor! I've applied the requested changes and responded to your comments above. |
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.
lgtm, with one last nit
Wicked, thanks for the help @andykaylor |
I have rebased the PR after the incubator rebase this morning. Looks like there are some errors, digging into that now. |
Co-authored-by: Andy Kaylor <[email protected]>
Co-authored-by: Henrich Lauko <[email protected]>
Co-authored-by: Henrich Lauko <[email protected]>
Co-authored-by: Henrich Lauko <[email protected]>
Rebased PR again, works with the new main branch. |
Overview
Currently, getting the pointer to an element of an array requires a pointer decay and a (possible) pointer stride. A similar pattern for records has been eliminated with the
cir.get_member
operation. This PR provides a similar level of abstraction for arrays with theget_element
operation.get_element
replaces the above pattern with a single operation, which takes a pointer to an array and an index, and produces a pointer to the element at that index.There are many places in CIR analysis and lowering where the
ptr_stride(array_to_ptrdecay(x), i)
pattern is handled as a special case. By subsuming the special case pattern with an explicit operation, we make these analyses and lowering more robust.Changes
Adds the
cir.get_element
operation.Extends CIRGen to emit
cir.get_element
for array subscript expressions.Updated LifetimeCheck to handle
get_element
operation, subsuming special case analysis ofcir.ptr_stride
operation (did not remove the special case).Extends CIR-to-LLVM lowering to lower
cir.get_element
tollvm.getelementptr
Extends CIR-to-MLIR lowering to lower
cir.get_element
tomemref
operations, matching existing special casecir.ptr_stride
lowering.Additional Notes
Currently, 47.6% of
cir.ptr_stride
operations in the llvm-test-suite (SingleSource and MultiSource) can be replaced bycir.get_element
operations.Operator Breakdown (current)
Operator Breakdown (with
get_element
)