feat(dataflow): dead code analysis#659
Conversation
d0d5c42 to
a0c7ca0
Compare
2d0f49c to
426f54f
Compare
75fee26 to
2a358ff
Compare
b291656 to
44a9a71
Compare
…f the dead code TODOs are covered)
axelcool1234
left a comment
There was a problem hiding this comment.
Review for myself
| if point.prev! irCtx = none then | ||
| return dfCtx |
There was a problem hiding this comment.
Go back to MLIR and change this to a panic if needed.
| -- Recurse on nested operations. | ||
| for regionPtr in (op.get! irCtx).regions do | ||
| -- TODO: If we haven't seen a symbol table yet, check if the current | ||
| -- operation has one. If so, update the flag to allow for resolving | ||
| -- callables in nested regions. | ||
| let region := regionPtr.get! irCtx | ||
| let mut maybeBlock := region.firstBlock | ||
| while let some block := maybeBlock do | ||
| let mut maybeOp := (block.get! irCtx).firstOp | ||
| while let some nestedOp := maybeOp do | ||
| dfCtx := initializeRecursively nestedOp dfCtx irCtx | ||
| maybeOp := (nestedOp.get! irCtx).next | ||
| maybeBlock := (block.get! irCtx).next | ||
| dfCtx |
There was a problem hiding this comment.
This is a common pattern that I have done many many times, and I know @regehr has done for CSE. Perhaps this should be a helper in Basic.lean? @math-fehr
There was a problem hiding this comment.
this does seem like a useful helper. we don't want to return a list-- that's slow. rather is should be some sort of visitor / iterator / callback.
| | return "analysis did not converge" | ||
| return renderReport (check top dfCtx parserState) | ||
|
|
||
| /-- Dead code helpers. -/ |
There was a problem hiding this comment.
@axelcool1234 if this code is potentially useful for multiple analyses, then this file seems like a good place to put it. but if it is only helping dead code analysis, then just put it there and don't create this extra file
| def isBlockLive (dfCtx : DataFlowContext) (block : BlockPtr) (irCtx : IRContext OpCode) : Bool := | ||
| match dfCtx.getFact? .executable (.InsertPoint (InsertPoint.atStart! block irCtx)) with | ||
| | some fact => fact.live | ||
| | none => false |
There was a problem hiding this comment.
what are the circumstances in which there would not be a fact available here? can these circumstances be avoided? if not, should you signal a real error here instead of merely returning false?
Implements a dataflow analysis for unreachable code.
Note - MLIR has a much more advanced understanding of region semantics I didn't know how to implement with VeIR's current capabilities. I have left a large number of TODOs in places where they should be handled.