From cc554167f2dded033c700a11d6add38e70f8e84c Mon Sep 17 00:00:00 2001 From: Christian Sigg Date: Tue, 15 Apr 2025 23:05:27 -0700 Subject: [PATCH] NFC: Use the free function variants for dyn_cast/cast/isa/.... The member functions in Type/Attribute/Value/Location/AffineExpr got [removed](https://github.com/llvm/llvm-project/commit/0078cf79adc2f24a168bc774cba1f39dda5e3752). PiperOrigin-RevId: 748166276 --- loop_nest.cc | 19 ++++++++++--------- sair_op_interfaces.h | 7 ++++--- sequence.cc | 3 ++- test/passes.cc | 3 ++- transforms/lower_proj_any.cc | 3 ++- util.h | 3 ++- 6 files changed, 22 insertions(+), 16 deletions(-) diff --git a/loop_nest.cc b/loop_nest.cc index da9605c0..959750fd 100644 --- a/loop_nest.cc +++ b/loop_nest.cc @@ -17,6 +17,7 @@ #include "llvm/ADT/SetVector.h" #include "llvm/ADT/SmallString.h" #include "mlir/IR/Builders.h" +#include "mlir/Support/LLVM.h" #include "sequence.h" #include "util.h" @@ -106,7 +107,7 @@ const IterationSpace &IterationSpaceAnalysis::ComputeIterationSpace( loop_names.reserve(num_loops); for (mlir::Attribute attr : compute_op.Loops()) { - LoopAttr loop = attr.cast(); + LoopAttr loop = mlir::cast(attr); loop_names.push_back(loop.name()); exprs.push_back(loop.iter()); } @@ -265,10 +266,10 @@ mlir::LogicalResult VerifyLoopNestWellFormed( int domain_size = shape.Dimensions().size(); for (int i = 0, e = loop_nest.size(); i < e; ++i) { - LoopAttr loop = loop_nest[i].dyn_cast(); + LoopAttr loop = mlir::dyn_cast(loop_nest[i]); // Ensure that symbols are unique in the loop nest. for (int j = 0; j < i; ++j) { - if (loop.name() == loop_nest[j].cast().name()) { + if (loop.name() == mlir::cast(loop_nest[j]).name()) { return mlir::emitError(loc) << "name " << loop.name() << " used twice in the same loop nest"; } @@ -317,7 +318,7 @@ class LoopNestState { int common_prefix_size = 0; for (int e = std::min(loop_nest.size(), open_loops_.size()); common_prefix_size < e; ++common_prefix_size) { - LoopAttr loop = loop_nest[common_prefix_size].cast(); + LoopAttr loop = mlir::cast(loop_nest[common_prefix_size]); if (loop.name() != open_loops_[common_prefix_size]) break; } @@ -326,7 +327,7 @@ class LoopNestState { // Add remaining loops to the current fusion prefix. for (mlir::Attribute attribute : loop_nest.drop_front(common_prefix_size)) { - LoopAttr loop = attribute.cast(); + LoopAttr loop = mlir::cast(attribute); if (closed_loops_.count(loop.name()) > 0) { return op.EmitError() << "occurrences of loop " << loop.name() @@ -500,7 +501,7 @@ static mlir::LogicalResult VerifyLoopRanges( const LoopFusionAnalysis &fusion_analysis, const SequenceAnalysis &sequence_analysis) { for (mlir::Attribute attr : loop_nest) { - LoopAttr loop = attr.cast(); + LoopAttr loop = mlir::cast(attr); const LoopFusionClass &fusion_class = fusion_analysis.GetClass(loop.name()); for (const auto &dimension : fusion_class.getDomain()) { if (sequence_analysis.IsBefore(op, dimension.value.defining_op())) { @@ -670,7 +671,7 @@ mlir::LogicalResult LoopFusionAnalysis::Init( // Returns the unroll factor of the `pos`-th loop in the given compute op. // Expects the op to have a well-formed loop nest attribute. static unsigned ExtractUnrollFactor(const ComputeOpInstance &op, unsigned pos) { - auto loop = op.Loops()[pos].cast(); + auto loop = mlir::cast(op.Loops()[pos]); if (mlir::IntegerAttr unroll_factor = loop.unroll()) { return unroll_factor.getInt(); } @@ -686,7 +687,7 @@ mlir::LogicalResult LoopFusionAnalysis::RegisterLoop( loop_names.reserve(loop_pos); iter_exprs.reserve(loop_pos); for (int i = 0; i < loop_pos; ++i) { - LoopAttr loop = op.Loops()[i].cast(); + LoopAttr loop = mlir::cast(op.Loops()[i]); loop_names.push_back(loop.name()); iter_exprs.push_back(loop.iter()); } @@ -698,7 +699,7 @@ mlir::LogicalResult LoopFusionAnalysis::RegisterLoop( auto loop_nest_mapping = MappingAttr::get(op.context(), op.domain_size(), iter_exprs); - LoopAttr loop = op.Loops()[loop_pos].cast(); + LoopAttr loop = mlir::cast(op.Loops()[loop_pos]); auto [it, was_inserted] = fusion_classes_.try_emplace(loop.name(), loop.name(), op, loop_nest); LoopFusionClass &fusion_class = it->second; diff --git a/sair_op_interfaces.h b/sair_op_interfaces.h index 6047cfc7..ea0dc3a2 100644 --- a/sair_op_interfaces.h +++ b/sair_op_interfaces.h @@ -26,6 +26,7 @@ #include "mlir/IR/Operation.h" #include "mlir/IR/Value.h" #include "mlir/Interfaces/SideEffectInterfaces.h" +#include "mlir/Support/LLVM.h" #include "mlir/Support/LogicalResult.h" #include "sair_attributes.h" #include "sair_types.h" @@ -67,7 +68,7 @@ class ValueOperand { // Returns the type of the value referenced by the operand. ValueType GetType() const { - return operand_->get().getType().cast(); + return mlir::cast(operand_->get().getType()); } // Returns the operation owning the operand. @@ -510,14 +511,14 @@ class OperandInstance { inline auto OpInstance::getDomain() const { return llvm::map_range(GetDomainValues(), [](mlir::Value v) { OpInstance dim_op = OpInstance(llvm::cast(v.getDefiningOp())); - return ResultInstance(dim_op, v.cast().getResultNumber()); + return ResultInstance(dim_op, mlir::cast(v).getResultNumber()); }); } inline auto OpInstance::DomainWithDependencies() const { DomainShapeAttr shape = GetShape(); return llvm::map_range(llvm::enumerate(GetDomainValues()), [=](auto p) { - auto value = p.value().template cast(); + auto value = mlir::cast(p.value()); OpInstance dim_op = OpInstance(llvm::cast(value.getOwner())); ValueAccessInstance access = { .value = ResultInstance(dim_op, value.getResultNumber()), diff --git a/sequence.cc b/sequence.cc index 896546fe..dcc0923c 100644 --- a/sequence.cc +++ b/sequence.cc @@ -20,6 +20,7 @@ #include "llvm/ADT/iterator_range.h" #include "llvm/Support/Debug.h" +#include "mlir/Support/LLVM.h" #include "loop_nest.h" #include "sair_op_interfaces.h" #include "sair_ops.h" @@ -454,7 +455,7 @@ ProgramPoint SequenceAnalysis::FindInsertionPoint( llvm::ArrayRef new_loops = new_op.Loops(); num_common_loops = std::min(new_loops.size(), num_common_loops); for (; num_common_loops > 0; --num_common_loops) { - auto loop = new_loops[num_common_loops - 1].cast(); + auto loop = mlir::cast(new_loops[num_common_loops - 1]); if (loop.name() == start_loop_nest[num_common_loops - 1]) break; } if (num_common_loops <= num_loops) break; diff --git a/test/passes.cc b/test/passes.cc index 56850889..59bb169f 100644 --- a/test/passes.cc +++ b/test/passes.cc @@ -15,6 +15,7 @@ #include "test/passes.h" #include "mlir/IR/Builders.h" +#include "mlir/Support/LLVM.h" #include "sair_attributes.h" #include "sair_dialect.h" @@ -34,7 +35,7 @@ static llvm::SmallVector GetAttrVector(llvm::StringRef name, llvm::SmallVector vector; vector.reserve(array.size()); for (mlir::Attribute element : array.getValue()) { - vector.push_back(element.cast()); + vector.push_back(mlir::cast(element)); } return vector; } diff --git a/transforms/lower_proj_any.cc b/transforms/lower_proj_any.cc index 6bf5bd59..a4405a2b 100644 --- a/transforms/lower_proj_any.cc +++ b/transforms/lower_proj_any.cc @@ -15,6 +15,7 @@ #include "mlir/Dialect/Func/IR/FuncOps.h" #include "mlir/Dialect/SCF/IR/SCF.h" #include "mlir/Pass/Pass.h" +#include "mlir/Support/LLVM.h" #include "loop_nest.h" #include "sair_dialect.h" #include "sair_ops.h" @@ -86,7 +87,7 @@ class LowerProjAny : public impl::LowerProjAnyPassBase { // guaranteed to be identity by verifiers. for (MappingExpr expr : mapping.Dimensions().drop_front(num_common_loops)) { - if (!expr.isa()) { + if (!mlir::isa(expr)) { return op.emitError() << "cannot lower operation to proj_last on scalars"; } diff --git a/util.h b/util.h index c3883f60..b094fcad 100644 --- a/util.h +++ b/util.h @@ -16,6 +16,7 @@ #define THIRD_PARTY_SAIR_TRANSFORMS_UTIL_H_ #include "mlir/IR/Builders.h" +#include "mlir/Support/LLVM.h" #include "sair_attributes.h" #include "sair_op_interfaces.h" @@ -95,7 +96,7 @@ std::function MkArrayAttrMapper( llvm::SmallVector output; output.reserve(array.size()); for (mlir::Attribute attr : array.getValue()) { - output.push_back(scalar_fn(attr.cast())); + output.push_back(scalar_fn(mlir::cast(attr))); } return mlir::ArrayAttr::get(array.getContext(), output); };