[Mlir-commits] [mlir] [mlir][dataflow] Update dataflow tutorial doc and add dataflow example code (PR #149296)
lonely eagle
llvmlistbot at llvm.org
Thu Jul 17 09:01:05 PDT 2025
================
@@ -237,60 +228,91 @@ function for the operation, that is specific to our analysis. A simple
implementation for our example is shown below:
```c++
-class MetadataAnalysis : public ForwardDataFlowAnalysis<MetadataLatticeValue> {
+class MetadataAnalysis
+ : public SparseForwardDataFlowAnalysis<MetadataLatticeValueLattice> {
public:
- using ForwardDataFlowAnalysis<MetadataLatticeValue>::ForwardDataFlowAnalysis;
-
- ChangeResult visitOperation(
- Operation *op, ArrayRef<LatticeElement<ValueT> *> operands) override {
- DictionaryAttr metadata = op->getAttrOfType<DictionaryAttr>("metadata");
-
- // If we have no metadata for this operation, we will conservatively mark
- // all of the results as having reached a pessimistic fixpoint.
- if (!metadata)
- return markAllPessimisticFixPoint(op->getResults());
-
- // Otherwise, we will compute a lattice value for the metadata and join it
- // into the current lattice element for all of our results.
- MetadataLatticeValue latticeValue(metadata);
- ChangeResult result = ChangeResult::NoChange;
- for (Value value : op->getResults()) {
- // We grab the lattice element for `value` via `getLatticeElement` and
- // then join it with the lattice value for this operation's metadata. Note
- // that during the analysis phase, it is fine to freely create a new
- // lattice element for a value. This is why we don't use the
- // `lookupLatticeElement` method here.
- result |= getLatticeElement(value).join(latticeValue);
+ using SparseForwardDataFlowAnalysis::SparseForwardDataFlowAnalysis;
+ LogicalResult
+ visitOperation(Operation *op,
+ ArrayRef<const MetadataLatticeValueLattice *> operands,
+ ArrayRef<MetadataLatticeValueLattice *> results) override {
+ DictionaryAttr metadata = op->getAttrOfType<DictionaryAttr>("metadata");
+ // If we have no metadata for this operation and the operands is empty, we
+ // will conservatively mark all of the results as having reached a pessimistic
+ // fixpoint.
+ if (!metadata && operands.empty()) {
+ setAllToEntryStates(results);
+ return success();
+ }
+
+ MetadataLatticeValue latticeValue;
+ if (metadata)
+ latticeValue = MetadataLatticeValue(metadata);
+
+ // Otherwise, we will compute a lattice value for the metadata and join it
+ // into the current lattice element for all of our results.`results` stores
+ // the lattices corresponding to the results of op, We use a loop to traverse
+ // them.
+ for (int i = 0, e = results.size(); i < e; ++i) {
----------------
linuxlonelyeagle wrote:
I will make changes tomorrow when I have time.
https://github.com/llvm/llvm-project/pull/149296
More information about the Mlir-commits
mailing list