Skip to content

feat(dataflow): sparse forward dataflow analysis api - #854

Open
axelcool1234 wants to merge 2 commits into
opencompl:mainfrom
axelcool1234:sparse-analysis-api
Open

feat(dataflow): sparse forward dataflow analysis api#854
axelcool1234 wants to merge 2 commits into
opencompl:mainfrom
axelcool1234:sparse-analysis-api

Conversation

@axelcool1234

@axelcool1234 axelcool1234 commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

Any transfer function that works on OperationPtr will use this API. Simply implementing a (transfer) function of the form OperationPtr -> DataFlowContext -> IRContext OpCode -> DataFlowContext gets you a sparse forward analysis plugged into the dataflow framework for free. This API handles most of the stuff the implementer of a transfer function shouldn't concern themselves with.

@axelcool1234
axelcool1234 marked this pull request as draft June 11, 2026 23:16
@axelcool1234
axelcool1234 force-pushed the sparse-analysis-api branch 4 times, most recently from 7d86346 to 84799d7 Compare June 12, 2026 03:46
@axelcool1234 axelcool1234 changed the title feat(dataflow): sparse analysis api feat(dataflow): sparse forward dataflow analysis api Jun 12, 2026
@axelcool1234
axelcool1234 force-pushed the sparse-analysis-api branch 8 times, most recently from f50cb06 to e6412e3 Compare June 14, 2026 00:06
@axelcool1234
axelcool1234 force-pushed the sparse-analysis-api branch 2 times, most recently from 9529f81 to f072c4f Compare July 16, 2026 00:06
@axelcool1234
axelcool1234 force-pushed the sparse-analysis-api branch 4 times, most recently from 38d6512 to b8429f1 Compare July 28, 2026 00:07
@axelcool1234
axelcool1234 marked this pull request as ready for review July 28, 2026 00:14
@axelcool1234
axelcool1234 force-pushed the sparse-analysis-api branch from b8429f1 to fe25c77 Compare July 28, 2026 00:17
@axelcool1234
axelcool1234 requested a review from math-fehr July 28, 2026 00:23
@axelcool1234
axelcool1234 force-pushed the sparse-analysis-api branch 2 times, most recently from 559572d to 7c5e2b0 Compare July 28, 2026 02:13
private def isBranchOp
(op : OperationPtr)
(irCtx : IRContext OpCode) : Bool :=
-- TODO: Replace this `.test .test` check once VeIR has proper branch ops.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are plenty of branch ops in Veir right now!
but you do not want to be making these decisions here, take a look at Veir/GlobalOpInfo.lean which has some helpers for answering questions like this, that might be the place to put this information

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

branch ops include cf.br, cf.cond_br, llvm.br, llvm cond_br, and also some RISC-V branches

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, I implemented an interface: #1237

panic! s!"SparseForwardDataFlowAnalysis.getSuccessorOperand?: successor index {successorIndex} out of range"
else
match (op.get! irCtx).opType with
-- TODO: Replace this `.test .test` check once VeIR has proper branch ops.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also here-- I'm not exactly sure what you're doing, but don't hard-code information about dialects here if you can help it

-- TODO: Replace this `.test .test` check once VeIR has proper branch ops.
-- `successorIndex` will become relevant then.
| .test .test =>
if argumentIndex < op.getNumOperands! irCtx then

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you need this dynamic check? if I understand correctly, the called is making sure this is in-bounds, you should be able to attach a little proof of that

Comment thread Veir/Analysis/DataFlow/SparseAnalysis.lean Outdated
@regehr

regehr commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

@math-fehr should this be using WfIRContext instead of IRContext?

@regehr

regehr commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

if I understand correctly, an unrecognized branch causes the analysis to start putting tops into successor blocks. but maybe it would be better to error out with a message that the analysis is unable to continue? I feel like we don't want to paper over something that's a serious problem

@regehr

regehr commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

I also had claude review this PR and it came up with a list of stuff to look at-- I don't want to paste it here, please do this on your own

@math-fehr

Copy link
Copy Markdown
Collaborator

@math-fehr should this be using WfIRContext instead of IRContext?

That would be better indeed! I'm not sure it's strictly necessary, but it might definitely bite us later if we don't do this.
We can fix this in a later PR though, but we should do it soon-ish.

Otherwise, I'll just wait that axel fixes your changes and take a look at claude comments, so then I can review it when it's more ready!

@axelcool1234

axelcool1234 commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator Author

@math-fehr @regehr Sounds good guys, thanks for the review. I might only be able to get back to this next week. I'm wrapping up my internship (I have two presentations to prepare for this weekend and do this coming week). I really appreciate your patience, I know I have taken forever on this stuff. I look forward to finally getting this into VeIR :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants