-
Notifications
You must be signed in to change notification settings - Fork 18
feat(dataflow): sparse fact api #859
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
Changes from all commits
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 |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| module | ||
|
|
||
| public import Veir.Analysis.DataFlowFramework | ||
| public import Veir.Analysis.DataFlow.Domains.AbstractDomain | ||
|
|
||
| public section | ||
|
|
||
| namespace Veir | ||
|
|
||
| /-- | ||
| Implement this class to register a custom type to be recognized as | ||
| a sparse fact type by the dataflow framework. | ||
| -/ | ||
| class SparseFactSpec (kind : FactKind) (Domain : outParam Type) where | ||
| payloadEq : FactPayload kind = SparsePayload Domain | ||
|
|
||
| namespace SparseFact | ||
|
|
||
| variable {kind : FactKind} {Domain : Type} | ||
| variable [SparseFactSpec kind Domain] | ||
|
|
||
| def getPayload (fact : Fact kind) : SparsePayload Domain := | ||
| cast SparseFactSpec.payloadEq fact.payload | ||
|
|
||
| def setPayload (fact : Fact kind) (payload : SparsePayload Domain) : Fact kind := | ||
| { fact with payload := cast (Eq.symm SparseFactSpec.payloadEq) payload } | ||
|
|
||
| def latticeElement (fact : Fact kind) : Domain := | ||
| (getPayload fact).latticeElement | ||
|
|
||
| def setLatticeElement (fact : Fact kind) (latticeElement : Domain) : Fact kind := | ||
| let payload := getPayload fact | ||
| setPayload fact { payload with latticeElement := latticeElement } | ||
|
|
||
| /-- | ||
| 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 | ||
| match InsertPoint.after? user irCtx with | ||
| | some point => | ||
| for analysisKind in state.subscribers do | ||
| dfCtx := dfCtx.enqueue (point, analysisKind) | ||
| | none => pure () | ||
| maybeUse := (use.get! irCtx).nextUse | ||
| | _ => | ||
| pure () | ||
| dfCtx | ||
|
Comment on lines
+35
to
+55
Collaborator
Author
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. @math-fehr Here is an example of |
||
|
|
||
| section | ||
|
|
||
| variable [Bot Domain] | ||
|
|
||
| /-- Default sparse lattice fact for the given anchor. -/ | ||
| def mkDefault : Fact kind := | ||
| { payload := cast (Eq.symm SparseFactSpec.payloadEq) { latticeElement := ⊥ } } | ||
|
|
||
| instance : FactSpec kind where | ||
| mkDefault := SparseFact.mkDefault (kind := kind) | ||
| propagate := SparseFact.propagate (kind := kind) | ||
|
|
||
| end | ||
|
|
||
| def getElement? (kind : FactKind) [SparseFactSpec kind Domain] [FactSpec kind] | ||
| (ssaValue : ValuePtr) (dfCtx : DataFlowContext) : Option Domain := do | ||
| let state ← dfCtx.getFact? kind (.ValuePtr ssaValue) | ||
| return latticeElement state | ||
|
|
||
| def getElementD (kind : FactKind) [SparseFactSpec kind Domain] [FactSpec kind] | ||
| (ssaValue : ValuePtr) (fallback : Domain) | ||
| (dfCtx : DataFlowContext) : Domain := | ||
| (getElement? kind ssaValue dfCtx).getD fallback | ||
|
|
||
| end SparseFact | ||
|
|
||
| end Veir | ||
Uh oh!
There was an error while loading. Please reload this page.