I have a custom dataflow analysis based on the SparseDataFlowAnalysis class. My pass is loading both the mlir::dataflow::DeadCodeAnalysis and my custom analysis.
In an example MLIR (below) using the linalg.generic operation, the operation doesn’t seem to be visited by the visitOperation method, and the reason seems to be that the block of the generic operation has been marked as non-live by the DeadCodeAnalysis.
Is there a reason for the DeadCodeAnalysis to do so, or is it something that isn’t supported yet?
Linalg operations don’t implement region-based control flow interfaces, so the dead code analysis dataflow analysis doesn’t know that the control can enter the body of a linalg.generic and considers the operation instead it “non-live”. They don’t implement the interface because the kind of flow Linalg operations actually have cannot be expressed in terms those interfaces require. Specifically, the interface expects that data flows unaltered from operands of the parent operation to a block argument (and similarly from terminator operands to the result of the parent operation), which isn’t correct for linalg.generic where only a subset of data flows, moreover a different one on each iteration. As a matter of fact, I removed the interface from this operation in [mlir] remove RegionBranchOpInterface from linalg ops · llvm/llvm-project@2469cdd · GitHub precisely because it was producing unexpected/wrong results in (downstream) dataflow analyses.
Is the operation itself not visited, or its body?
Also please double-check if you are using a sufficiently recent version.
The operation itself isn’t visited. So no call to visitiOperation with the GenericOp. If the operation was visited, I could at least try to compute the value of the analysis for it, without requiring the analysis to go through the body.
You can try cherry-picking my patch into your tree. Without it, the linalg.generic operation is treated as a control-flow only operation and therefore is not visited by itself.