This is an archive of the discontinued LLVM Phabricator instance.

[mlir][dataflow] Consolidate AbstractSparseLattice::markPessimisticFixpoint() and AbstractDenseLattice::reset() into Abstract{Sparse,Dense}DataFlowAnalysis::setToEntryState().
ClosedPublic

Authored by phisiart on Aug 17 2022, 5:40 PM.

Details

Summary

Rationale

For a program point where we cannot reason about incoming dataflow (e.g. an argument of an entry block), the framework needs to initialize the state.

Currently, AbstractSparseDataFlowAnalysis initializes such state to the "pessimistic fixpoint", and AbstractDenseDataFlowAnalysis calls the state's reset() function.

However, entry states aren't necessarily the pessimistic fixpoint. Example: in reaching definition, the pessimistic fixpoint is {all definitions}, but the entry state is {}.

This awkwardness might be why the dense analysis API currently uses reset() instead of markPessimisticFixpoint().

This patch consolidates entry point initialization into a single function setToEntryState().

API Location

Note that setToEntryState() is defined in the analysis rather than the lattice, so that we allow different analyses to use the same lattice but different entry states.

Removal of the concept of optimistic/known value

The concept of optimistic/known value is too specific to SCCP.

Furthermore, the known value is not really used: In the current SCCP implementation, the known value (pessimistic fixpoint) is always Attribute{} (non-constant). This means there's no point storing a knownValue in each state.

If we do need to re-introduce optimistic/known value, we should put it in the SCCP analysis, not the sparse analysis API.

Terminology

Please let me know if "entry state" is a good terminology.

I chose "entry" from Wikipedia (https://en.wikipedia.org/wiki/Data-flow_analysis#Basic_principles).

Another term I can think of is "boundary" (https://suif.stanford.edu/~courses/cs243/lectures/L3-DFA2-revised.pdf) which might be better since it also makes sense for backward analysis.

Diff Detail

Event Timeline

phisiart created this revision.Aug 17 2022, 5:40 PM
Herald added a project: Restricted Project. · View Herald Transcript
phisiart requested review of this revision.Aug 17 2022, 5:40 PM
phisiart retitled this revision from Consolidate AbstractSparseLattice::markPessimisticFixpoint() and AbstractDenseLattice::reset() into Abstract{Sparse,Dense}DataFlowAnalysis::setToEntryState(). to [mlir][dataflow] Consolidate AbstractSparseLattice::markPessimisticFixpoint() and AbstractDenseLattice::reset() into Abstract{Sparse,Dense}DataFlowAnalysis::setToEntryState()..Aug 17 2022, 5:42 PM
phisiart added a reviewer: Mogball.
phisiart edited the summary of this revision. (Show Details)Aug 17 2022, 6:47 PM

Can you take a look at the failures?

ConstantPropagationAnalysis.cpp:42:5: error: use of undeclared identifier 'markAllPessimisticFixpoint'
    markAllPessimisticFixpoint(results);
mlir/include/mlir/Analysis/DataFlow/ConstantPropagationAnalysis.h
50

Nit: I would call it getUnknownConstant

phisiart updated this revision to Diff 453852.Aug 18 2022, 6:21 PM

Rename NonConstant to UnknownConstant.

Can you take a look at the failures?

ConstantPropagationAnalysis.cpp:42:5: error: use of undeclared identifier 'markAllPessimisticFixpoint'
    markAllPessimisticFixpoint(results);

I suspect that the failures are due to the fact that internally we are still using an older version of LLVM and there are problems with generating the external patch.

I think what I should do is to wait until our internal version catches up.

You can try rebasing your commit

phisiart updated this revision to Diff 455249.Aug 24 2022, 9:16 AM

Reformat.

Overall, I agree with the direction of this patch. My main concern is around having setValue on Lattice. I don't see the need for the function since join(any, entry_state) should result in entry_state.

I'm also not particularly fond of EntryState as the name, but I can't come up with anything better than DefaultValue but that's kind of vague.

mlir/include/mlir/Analysis/DataFlow/IntegerRangeAnalysis.h
79

Why do you need to be able to overwrite the value in lattice? join with an uninitialized value will always take the RHS value. In what cases would a lattice value be overwritten and changed back to its entry state? This wouldn't be guaranteed to be monotonic.

mlir/include/mlir/Analysis/DataFlow/SparseAnalysis.h
93

Can you name this something else, like newValue? And then drop this->

93–99

I would drop the rvalue reference. It doesn't add anything over just plain value here.

mlir/lib/Analysis/DataFlow/IntegerRangeAnalysis.cpp
110

This should be join. I don't see the need to use setValue

phisiart updated this revision to Diff 456148.Aug 27 2022, 1:56 PM

Remove setValue() - join() should be enough for a monotonic framework.

phisiart marked 5 inline comments as done.Aug 27 2022, 2:02 PM
phisiart added inline comments.
mlir/include/mlir/Analysis/DataFlow/SparseAnalysis.h
93

Removed setValue() entirely.

93–99

Removed setValue() entirely.

phisiart marked 2 inline comments as done.Aug 27 2022, 2:34 PM
Mogball accepted this revision.Aug 27 2022, 5:24 PM

LGTM thanks!

jsetoain resigned from this revision.Aug 29 2022, 4:29 AM

Apologies. Broken herald rule.

This revision is now accepted and ready to land.Aug 29 2022, 4:29 AM