[Mlir-commits] [mlir] [DataFlow] Migrate away from PointerUnion::{is, get} (NFC) (PR #119950)
Kazu Hirata
llvmlistbot at llvm.org
Fri Dec 13 22:27:41 PST 2024
https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/119950
Note that PointerUnion::{is,get} have been soft deprecated in
PointerUnion.h:
// FIXME: Replace the uses of is(), get() and dyn_cast() with
// isa<T>, cast<T> and the llvm::dyn_cast<T>
I'm not touching PointerUnion::dyn_cast for now because it's a bit
complicated; we could blindly migrate it to dyn_cast_if_present, but
we should probably use dyn_cast when the operand is known to be
non-null.
>From 303f43ee2ff1d15f0afa6357e6171cebf42b0133 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Fri, 13 Dec 2024 08:03:19 -0800
Subject: [PATCH] [DataFlow] Migrate away from PointerUnion::{is,get} (NFC)
Note that PointerUnion::{is,get} have been soft deprecated in
PointerUnion.h:
// FIXME: Replace the uses of is(), get() and dyn_cast() with
// isa<T>, cast<T> and the llvm::dyn_cast<T>
I'm not touching PointerUnion::dyn_cast for now because it's a bit
complicated; we could blindly migrate it to dyn_cast_if_present, but
we should probably use dyn_cast when the operand is known to be
non-null.
---
mlir/include/mlir/Analysis/DataFlow/SparseAnalysis.h | 2 +-
mlir/lib/Analysis/DataFlow/ConstantPropagationAnalysis.cpp | 4 ++--
mlir/lib/Analysis/DataFlow/IntegerRangeAnalysis.cpp | 6 +++---
mlir/lib/Analysis/DataFlow/SparseAnalysis.cpp | 2 +-
4 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/mlir/include/mlir/Analysis/DataFlow/SparseAnalysis.h b/mlir/include/mlir/Analysis/DataFlow/SparseAnalysis.h
index dce7ab3bb5ee79..507087d5575e9e 100644
--- a/mlir/include/mlir/Analysis/DataFlow/SparseAnalysis.h
+++ b/mlir/include/mlir/Analysis/DataFlow/SparseAnalysis.h
@@ -87,7 +87,7 @@ class Lattice : public AbstractSparseLattice {
using AbstractSparseLattice::AbstractSparseLattice;
/// Return the value this lattice is located at.
- Value getAnchor() const { return anchor.get<Value>(); }
+ Value getAnchor() const { return cast<Value>(anchor); }
/// Return the value held by this lattice. This requires that the value is
/// initialized.
diff --git a/mlir/lib/Analysis/DataFlow/ConstantPropagationAnalysis.cpp b/mlir/lib/Analysis/DataFlow/ConstantPropagationAnalysis.cpp
index 56529acd71bbf8..51fa7739e19386 100644
--- a/mlir/lib/Analysis/DataFlow/ConstantPropagationAnalysis.cpp
+++ b/mlir/lib/Analysis/DataFlow/ConstantPropagationAnalysis.cpp
@@ -103,9 +103,9 @@ LogicalResult SparseConstantPropagation::visitOperation(
lattice->join(ConstantValue(attr, op->getDialect())));
} else {
LLVM_DEBUG(llvm::dbgs()
- << "Folded to value: " << foldResult.get<Value>() << "\n");
+ << "Folded to value: " << cast<Value>(foldResult) << "\n");
AbstractSparseForwardDataFlowAnalysis::join(
- lattice, *getLatticeElement(foldResult.get<Value>()));
+ lattice, *getLatticeElement(cast<Value>(foldResult)));
}
}
return success();
diff --git a/mlir/lib/Analysis/DataFlow/IntegerRangeAnalysis.cpp b/mlir/lib/Analysis/DataFlow/IntegerRangeAnalysis.cpp
index a97e43708d9a37..c0b477b47ef191 100644
--- a/mlir/lib/Analysis/DataFlow/IntegerRangeAnalysis.cpp
+++ b/mlir/lib/Analysis/DataFlow/IntegerRangeAnalysis.cpp
@@ -43,7 +43,7 @@ void IntegerValueRangeLattice::onUpdate(DataFlowSolver *solver) const {
// If the integer range can be narrowed to a constant, update the constant
// value of the SSA value.
std::optional<APInt> constant = getValue().getValue().getConstantValue();
- auto value = anchor.get<Value>();
+ auto value = cast<Value>(anchor);
auto *cv = solver->getOrCreateState<Lattice<ConstantValue>>(value);
if (!constant)
return solver->propagateIfChanged(
@@ -155,9 +155,9 @@ void IntegerRangeAnalysis::visitNonControlFlowArguments(
Type boundType, bool getUpper) {
unsigned int width = ConstantIntRanges::getStorageBitwidth(boundType);
if (loopBound.has_value()) {
- if (loopBound->is<Attribute>()) {
+ if (isa<Attribute>(*loopBound)) {
if (auto bound =
- dyn_cast_or_null<IntegerAttr>(loopBound->get<Attribute>()))
+ dyn_cast_or_null<IntegerAttr>(cast<Attribute>(*loopBound)))
return bound.getValue();
} else if (auto value = llvm::dyn_cast_if_present<Value>(*loopBound)) {
const IntegerValueRangeLattice *lattice =
diff --git a/mlir/lib/Analysis/DataFlow/SparseAnalysis.cpp b/mlir/lib/Analysis/DataFlow/SparseAnalysis.cpp
index 67cf8c9c5b81f2..0b39d140424937 100644
--- a/mlir/lib/Analysis/DataFlow/SparseAnalysis.cpp
+++ b/mlir/lib/Analysis/DataFlow/SparseAnalysis.cpp
@@ -34,7 +34,7 @@ void AbstractSparseLattice::onUpdate(DataFlowSolver *solver) const {
AnalysisState::onUpdate(solver);
// Push all users of the value to the queue.
- for (Operation *user : anchor.get<Value>().getUsers())
+ for (Operation *user : cast<Value>(anchor).getUsers())
for (DataFlowAnalysis *analysis : useDefSubscribers)
solver->enqueue({solver->getProgramPointAfter(user), analysis});
}
More information about the Mlir-commits
mailing list