Skip to content

Commit f047b73

Browse files
authored
[mlir][NFC] Use getDefiningOp<OpTy>() instead of dyn_cast<OpTy>(getDefiningOp()) (#150428)
This PR uses `val.getDefiningOp<OpTy>()` to replace `dyn_cast<OpTy>(val.getDefiningOp())` , `dyn_cast_or_null<OpTy>(val.getDefiningOp())` and `dyn_cast_if_present<OpTy>(val.getDefiningOp())`.
1 parent b16ef20 commit f047b73

File tree

23 files changed

+37
-56
lines changed

23 files changed

+37
-56
lines changed

mlir/lib/Conversion/PDLToPDLInterp/PredicateTree.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ static void getTreePredicates(std::vector<PositionalPredicate> &predList,
4949
assert(isa<pdl::AttributeType>(val.getType()) && "expected attribute type");
5050
predList.emplace_back(pos, builder.getIsNotNull());
5151

52-
if (auto attr = dyn_cast<pdl::AttributeOp>(val.getDefiningOp())) {
52+
if (auto attr = val.getDefiningOp<pdl::AttributeOp>()) {
5353
// If the attribute has a type or value, add a constraint.
5454
if (Value type = attr.getValueType())
5555
getTreePredicates(predList, type, builder, inputs, builder.getType(pos));

mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1322,7 +1322,7 @@ static bool isNeutralElementConst(arith::AtomicRMWKind reductionKind,
13221322
return false;
13231323
Attribute valueAttr = getIdentityValueAttr(reductionKind, scalarTy,
13241324
state.builder, value.getLoc());
1325-
if (auto constOp = dyn_cast_or_null<arith::ConstantOp>(value.getDefiningOp()))
1325+
if (auto constOp = value.getDefiningOp<arith::ConstantOp>())
13261326
return constOp.getValue() == valueAttr;
13271327
return false;
13281328
}

mlir/lib/Dialect/Arith/IR/ArithOps.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2498,7 +2498,7 @@ OpFoldResult arith::SelectOp::fold(FoldAdaptor adaptor) {
24982498
matchPattern(adaptor.getFalseValue(), m_Zero()))
24992499
return condition;
25002500

2501-
if (auto cmp = dyn_cast_or_null<arith::CmpIOp>(condition.getDefiningOp())) {
2501+
if (auto cmp = condition.getDefiningOp<arith::CmpIOp>()) {
25022502
auto pred = cmp.getPredicate();
25032503
if (pred == arith::CmpIPredicate::eq || pred == arith::CmpIPredicate::ne) {
25042504
auto cmpLhs = cmp.getLhs();

mlir/lib/Dialect/ArmNeon/Transforms/LowerContractToNeonPatterns.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ std::optional<Value> getExtOperand(Value v) {
4949

5050
// If the operand is not defined by an explicit extend operation of the
5151
// accepted operation type allow for an implicit sign-extension.
52-
auto extOp = dyn_cast_or_null<Op>(v.getDefiningOp());
52+
auto extOp = v.getDefiningOp<Op>();
5353
if (!extOp) {
5454
if constexpr (std::is_same<Op, arith::ExtSIOp>::value) {
5555
auto eltTy = cast<VectorType>(v.getType()).getElementType();

mlir/lib/Dialect/ArmSVE/Transforms/LowerContractToSVEPatterns.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ std::optional<Value> getExtOperand(Value v) {
5050

5151
// If the operand is not defined by an explicit extend operation of the
5252
// accepted operation type allow for an implicit sign-extension.
53-
auto extOp = dyn_cast_or_null<Op>(v.getDefiningOp());
53+
auto extOp = v.getDefiningOp<Op>();
5454
if (!extOp) {
5555
if constexpr (std::is_same<Op, arith::ExtSIOp>::value) {
5656
auto vTy = cast<VectorType>(v.getType());

mlir/lib/Dialect/EmitC/Transforms/Transforms.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@ struct FoldExpressionOp : public OpRewritePattern<ExpressionOp> {
6262
continue;
6363

6464
for (Value operand : op.getOperands()) {
65-
auto usedExpression =
66-
dyn_cast_if_present<ExpressionOp>(operand.getDefiningOp());
67-
65+
auto usedExpression = operand.getDefiningOp<ExpressionOp>();
6866
if (!usedExpression)
6967
continue;
7068

mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2707,7 +2707,7 @@ LogicalResult IFuncOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
27072707
while (alias) {
27082708
Block &initBlock = alias.getInitializerBlock();
27092709
auto returnOp = cast<ReturnOp>(initBlock.getTerminator());
2710-
auto addrOp = dyn_cast<AddressOfOp>(returnOp.getArg().getDefiningOp());
2710+
auto addrOp = returnOp.getArg().getDefiningOp<AddressOfOp>();
27112711
// FIXME: This is a best effort solution. The AliasOp body might be more
27122712
// complex and in that case we bail out with success. To completely match
27132713
// the LLVM IR logic it would be necessary to implement proper alias and

mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1852,7 +1852,7 @@ transform::PackTransposeOp::apply(transform::TransformRewriter &rewriter,
18521852
assert(!packOp && "packOp must be null on entry when unPackOp is not null");
18531853
OpOperand *packUse = linalgOp.getDpsInitOperand(
18541854
cast<OpResult>(unPackOp.getSource()).getResultNumber());
1855-
packOp = dyn_cast_or_null<linalg::PackOp>(packUse->get().getDefiningOp());
1855+
packOp = packUse->get().getDefiningOp<linalg::PackOp>();
18561856
if (!packOp || !packOp.getResult().hasOneUse())
18571857
return emitSilenceableError() << "could not find matching pack op";
18581858
}

mlir/lib/Dialect/Linalg/Transforms/HoistPadding.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -757,8 +757,7 @@ static bool tracesBackToExpectedValue(tensor::ExtractSliceOp extractSliceOp,
757757
Value source = extractSliceOp.getSource();
758758
LLVM_DEBUG(DBGS() << "--with starting source: " << source << "\n");
759759
while (source && source != expectedSource) {
760-
auto destOp =
761-
dyn_cast_or_null<DestinationStyleOpInterface>(source.getDefiningOp());
760+
auto destOp = source.getDefiningOp<DestinationStyleOpInterface>();
762761
if (!destOp)
763762
break;
764763
LLVM_DEBUG(DBGS() << "--step dest op: " << destOp << "\n");

mlir/lib/Dialect/Linalg/Transforms/Hoisting.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,7 @@ static bool noAliasingUseInLoop(vector::TransferReadOp transferRead,
165165
Value source = transferRead.getBase();
166166

167167
// Skip view-like Ops and retrive the actual soruce Operation
168-
while (auto srcOp =
169-
dyn_cast_or_null<ViewLikeOpInterface>(source.getDefiningOp()))
168+
while (auto srcOp = source.getDefiningOp<ViewLikeOpInterface>())
170169
source = srcOp.getViewSource();
171170

172171
llvm::SmallVector<Operation *, 32> users(source.getUsers().begin(),

0 commit comments

Comments
 (0)