feat(dataflow): sparse fact api - #859
Conversation
4bd5d12 to
abbbe5e
Compare
9c78f96 to
d642161
Compare
| /-- | ||
| Propagate a sparse lattice update by revisiting dependents and all users of the | ||
| updated SSA value for subscribed analyses. | ||
| -/ | ||
| def propagate (state : Fact kind) (anchor : LatticeAnchor) | ||
| (dfCtx : DataFlowContext) (irCtx : IRContext OpCode) : DataFlowContext := Id.run do | ||
| let mut dfCtx := { dfCtx with workList := state.enqueueDependents dfCtx.workList } | ||
| match anchor with | ||
| | .ValuePtr ssaValue => | ||
| let mut maybeUse := ssaValue.getFirstUse! irCtx | ||
| while let some use := maybeUse do | ||
| let user := (use.get! irCtx).owner | ||
| for analysisKind in state.subscribers do | ||
| match InsertPoint.after? user irCtx with | ||
| | some point => | ||
| dfCtx := dfCtx.enqueue (point, analysisKind) | ||
| | none => | ||
| pure () | ||
| maybeUse := (use.get! irCtx).nextUse | ||
| | _ => | ||
| pure () | ||
| dfCtx |
There was a problem hiding this comment.
@math-fehr Here is an example of subscribers being used. For any fact that attaches to SSA Values, it enqueues into the worklist all of its uses for each subscribed analysis whenever said SSA fact changes. That's because its uses will be affected by that change. Analyses concerned about said change of this fact will be subscribed so that it can run its transfer function on the uses.
d642161 to
6e940a5
Compare
|
Cc @math-fehr @regehr @ineol this is the first step towards supporting transfer functions on SSA values, which is what John is mostly concerned with. I need some review of this code, thank you 🙏 |
math-fehr
left a comment
There was a problem hiding this comment.
Sorry for the delay!
I just added some small comments, but otherwise I think that's good!
6e940a5 to
3dc7fb5
Compare
math-fehr
left a comment
There was a problem hiding this comment.
Thanks, just add the documentation for the class and then I'll merge it!
71c92c0 to
2ed12e6
Compare
The following is a type that builds off of the generic
Facttype. You can define "sparse facts" - facts that attach toValues, using this type. It'll handle notifying dependents and subscribed analyses for you when it changes.