Control-flow support for PtrAnalysis
#362
nhat-nguyen
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
We have internally implemented control-flow support for
PtrAnalysis. This allows thetriton-to-structuredpass to generate block-pointers in presence of control-flow operations such asscf.if. We would appreciate any feedbacks!General control flow support in PtrAnalysis
Background
PtrAnalysis supports loops (
scf.for) but fails on conditionals (scf.if) that produce pointers, requiring us to fallback to scalar loads and stores. Where applicable, we want the analysis to identify structured loads and stores and lower them to more efficient DMA operations.The Problem
Pointer analysis recursively visits operations and produces
PtrStatefor each op: source pointer, offsets, strides, etc.Challenge: An
scf.ifproduces two pointer states (one per branch) that must be reconciled into a single result state.Solution: Leverage existing transformation that exposes the pointer states through
tts.get_structured_stateto derive the correct pointer states that represent both branches. This allows the analysis to correctly populate the pointer state forscf.ifoperations.Solutions
Background on
tts.get_structured_stateThis operation decouples analysis from IR rewriting:
tts.get_structured_stateops in strategic places where an operation can producePtrState.PtrStatefor each operation.tts.get_structured_stateops and replace the uses of their return values with the correct offsets and strides populated during step 2.Example for
scf.for:1. Reconciling states using
scf.ifresultsLeverage existing
tts.get_structured_stateinfrastructure: makescf.ifyield all PtrState components (offsets, strides, and source). The reconciled state then references thescf.ifresults directly:This creates “phi nodes” for each state component and is the key solution to generalized control flow support since the analysis can now recursively visit across arbitrary control-flow ops.
2.
tts.make_tptrafter each conditionWhen ops need a structured pointer from
scf.if, insert a singletts.make_tptrafter the conditional:Why not inside each branch?
tts.make_tptris a descriptor operation that encodes how memory should be accessed, not a value-producing operation.tts.make_tptrresult in each branch will also confuse the bufferization pass.3. Handling Mixed Structured/Unstructured Branches
When branches produce incompatible structuredness (e.g.: one is structured when the other isn’t), we will fallback to using unstructured pointers. Handling this problem is tricky in practice, especially in nested
scf.if.Example:
Assume that:
Since both branches are incompatible, we want to use unstructured pointers for this
scf.if. However, since thetts.get_structured_stateoperations are processed independently, marking an operation to be skipped during rewriting because othertts.get_structured_statehave failed is tricky.For such cases, for simplicity, we will mark all nested operations inside the
scf.ifto be unstructured since it is not likely that users will write such code.4. Extension to handling pointers returned by other control-flow ops
The above approach also scales to other kinds of control-flow ops that return pointers such as
scf.for,scf.while,… We just need to create the appropriate visit and rewrite methods for such operations.Conclusion
This work provides a framework for supporting arbitrary control-flow within the triton-to-structured pass by leveraging the existing transformation provided by the
tts.get_structured_statetransformation.Beta Was this translation helpful? Give feedback.
All reactions