-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[NFC] Use more isa and isa_and_nonnull instead dyn_cast for predicates #137393
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-llvm-analysis @llvm/pr-subscribers-backend-webassembly Author: Max Graey (MaxGraey) ChangesAlso fix some typos in comments Patch is 21.62 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/137393.diff 26 Files Affected:
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 9c9372d9ee2b0..9d723903d75b5 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -9987,9 +9987,10 @@ void CheckFreeArgumentsAddressof(Sema &S, const std::string &CalleeName,
const UnaryOperator *UnaryExpr) {
if (const auto *Lvalue = dyn_cast<DeclRefExpr>(UnaryExpr->getSubExpr())) {
const Decl *D = Lvalue->getDecl();
- if (isa<DeclaratorDecl>(D))
- if (!dyn_cast<DeclaratorDecl>(D)->getType()->isReferenceType())
+ if (auto *DD = dyn_cast<DeclaratorDecl>(D)) {
+ if (!DD->getType()->isReferenceType())
return CheckFreeArgumentsOnLvalue(S, CalleeName, UnaryExpr, D);
+ }
}
if (const auto *Lvalue = dyn_cast<MemberExpr>(UnaryExpr->getSubExpr()))
diff --git a/clang/lib/Sema/SemaModule.cpp b/clang/lib/Sema/SemaModule.cpp
index 4bba57193ded6..f080fdeeec8b1 100644
--- a/clang/lib/Sema/SemaModule.cpp
+++ b/clang/lib/Sema/SemaModule.cpp
@@ -942,7 +942,7 @@ static bool checkExportedDecl(Sema &S, Decl *D, SourceLocation BlockStart) {
// HLSL: export declaration is valid only on functions
if (S.getLangOpts().HLSL) {
// Export-within-export was already diagnosed in ActOnStartExportDecl
- if (!dyn_cast<FunctionDecl>(D) && !dyn_cast<ExportDecl>(D)) {
+ if (!isa<FunctionDecl, ExportDecl>(D)) {
S.Diag(D->getBeginLoc(), diag::err_hlsl_export_not_on_function);
D->setInvalidDecl();
return false;
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 274d3b90ff30f..221f4e953aa0e 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -2299,7 +2299,7 @@ bool SemaOpenMP::isInOpenMPTargetExecutionDirective() const {
bool SemaOpenMP::isOpenMPRebuildMemberExpr(ValueDecl *D) {
// Only rebuild for Field.
- if (!dyn_cast<FieldDecl>(D))
+ if (!isa<FieldDecl>(D))
return false;
DSAStackTy::DSAVarData DVarPrivate = DSAStack->hasDSA(
D,
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLocalVarsChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLocalVarsChecker.cpp
index a23f3aa356cb0..4fb47703e3984 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLocalVarsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLocalVarsChecker.cpp
@@ -356,7 +356,7 @@ class RawPtrRefLocalVarsChecker
SmallString<100> Buf;
llvm::raw_svector_ostream Os(Buf);
- if (dyn_cast<ParmVarDecl>(V)) {
+ if (isa<ParmVarDecl>(V)) {
Os << "Assignment to an " << ptrKind() << " parameter ";
printQuotedQualifiedName(Os, V);
Os << " is unsafe.";
diff --git a/lld/MachO/SymbolTable.cpp b/lld/MachO/SymbolTable.cpp
index ad48e909903b5..baddddcb76fbf 100644
--- a/lld/MachO/SymbolTable.cpp
+++ b/lld/MachO/SymbolTable.cpp
@@ -518,7 +518,7 @@ static const Symbol *getAlternativeSpelling(const Undefined &sym,
// If in the symbol table and not undefined.
if (const Symbol *s = symtab->find(newName))
- if (dyn_cast<Undefined>(s) == nullptr)
+ if (!isa<Undefined>(s))
return s;
return nullptr;
@@ -567,8 +567,7 @@ static const Symbol *getAlternativeSpelling(const Undefined &sym,
if (name.equals_insensitive(it.first))
return it.second;
for (Symbol *sym : symtab->getSymbols())
- if (dyn_cast<Undefined>(sym) == nullptr &&
- name.equals_insensitive(sym->getName()))
+ if (!isa<Undefined>(sym) && name.equals_insensitive(sym->getName()))
return sym;
// The reference may be a mangled name while the definition is not. Suggest a
diff --git a/llvm/include/llvm/Analysis/LoopInfo.h b/llvm/include/llvm/Analysis/LoopInfo.h
index abc0bb8588fa8..814c61bf4c350 100644
--- a/llvm/include/llvm/Analysis/LoopInfo.h
+++ b/llvm/include/llvm/Analysis/LoopInfo.h
@@ -529,7 +529,7 @@ class LoopInfo : public LoopInfoBase<BasicBlock, Loop> {
}
// Return true if a new use of V added in ExitBB would require an LCSSA PHI
- // to be inserted at the begining of the block. Note that V is assumed to
+ // to be inserted at the beginning of the block. Note that V is assumed to
// dominate ExitBB, and ExitBB must be the exit block of some loop. The
// IR is assumed to be in LCSSA form before the planned insertion.
bool wouldBeOutOfLoopUseRequiringLCSSA(const Value *V,
diff --git a/llvm/lib/Bitcode/Reader/MetadataLoader.cpp b/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
index 4879569200549..c724488b45d48 100644
--- a/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
+++ b/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
@@ -558,7 +558,7 @@ class MetadataLoader::MetadataLoaderImpl {
SetVector<Metadata *> EntitiesToRemove;
for (Metadata *Op : CU->getImportedEntities()->operands()) {
auto *IE = cast<DIImportedEntity>(Op);
- if (dyn_cast_or_null<DILocalScope>(IE->getScope())) {
+ if (isa_and_nonnull<DILocalScope>(IE->getScope())) {
EntitiesToRemove.insert(IE);
}
}
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 84054ddd0298c..e33b0b30c3b5f 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -6576,7 +6576,7 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
for (BasicBlock *ColorFirstBB : CV)
if (auto It = ColorFirstBB->getFirstNonPHIIt();
It != ColorFirstBB->end())
- if (dyn_cast_or_null<FuncletPadInst>(&*It))
+ if (isa_and_nonnull<FuncletPadInst>(&*It))
InEHFunclet = true;
// Check for funclet operand bundle
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyTargetTransformInfo.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyTargetTransformInfo.cpp
index 49aa94956bda6..24b95ac8bbd51 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyTargetTransformInfo.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyTargetTransformInfo.cpp
@@ -294,7 +294,7 @@ bool WebAssemblyTTIImpl::isProfitableToSinkOperands(
Value *V = I->getOperand(1);
// We dont need to sink constant splat.
- if (dyn_cast<Constant>(V))
+ if (isa<Constant>(V))
return false;
if (match(V, m_Shuffle(m_InsertElt(m_Value(), m_Value(), m_ZeroInt()),
diff --git a/mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp b/mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp
index ea251e4564ea8..57c8f4402cf4b 100644
--- a/mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp
+++ b/mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp
@@ -755,7 +755,7 @@ LLVMTypeConverter::promoteOperands(Location loc, ValueRange opOperands,
if (useBarePtrCallConv) {
// For the bare-ptr calling convention, we only have to extract the
// aligned pointer of a memref.
- if (dyn_cast<MemRefType>(operand.getType())) {
+ if (isa<MemRefType>(operand.getType())) {
MemRefDescriptor desc(llvmOperand);
llvmOperand = desc.alignedPtr(builder, loc);
} else if (isa<UnrankedMemRefType>(operand.getType())) {
diff --git a/mlir/lib/Conversion/MathToFuncs/MathToFuncs.cpp b/mlir/lib/Conversion/MathToFuncs/MathToFuncs.cpp
index df5396ac628cf..7f4655e53609e 100644
--- a/mlir/lib/Conversion/MathToFuncs/MathToFuncs.cpp
+++ b/mlir/lib/Conversion/MathToFuncs/MathToFuncs.cpp
@@ -586,7 +586,7 @@ static func::FuncOp createElementFPowIFunc(ModuleOp *module,
LogicalResult
FPowIOpLowering::matchAndRewrite(math::FPowIOp op,
PatternRewriter &rewriter) const {
- if (dyn_cast<VectorType>(op.getType()))
+ if (isa<VectorType>(op.getType()))
return rewriter.notifyMatchFailure(op, "non-scalar operation");
FunctionType funcType = getElementalFuncTypeForOp(op);
@@ -751,7 +751,7 @@ static func::FuncOp createCtlzFunc(ModuleOp *module, Type elementType) {
/// operation.
LogicalResult CtlzOpLowering::matchAndRewrite(math::CountLeadingZerosOp op,
PatternRewriter &rewriter) const {
- if (dyn_cast<VectorType>(op.getType()))
+ if (isa<VectorType>(op.getType()))
return rewriter.notifyMatchFailure(op, "non-scalar operation");
Type type = getElementTypeOrSelf(op.getResult().getType());
diff --git a/mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp b/mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp
index c8b2c0bdc6c20..158de6dea58c9 100644
--- a/mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp
+++ b/mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp
@@ -890,7 +890,7 @@ struct RankOpLowering : public ConvertOpToLLVMPattern<memref::RankOp> {
ConversionPatternRewriter &rewriter) const override {
Location loc = op.getLoc();
Type operandType = op.getMemref().getType();
- if (dyn_cast<UnrankedMemRefType>(operandType)) {
+ if (isa<UnrankedMemRefType>(operandType)) {
UnrankedMemRefDescriptor desc(adaptor.getMemref());
rewriter.replaceOp(op, {desc.rank(rewriter, loc)});
return success();
diff --git a/mlir/lib/Dialect/AMDGPU/Transforms/TransferReadToLoad.cpp b/mlir/lib/Dialect/AMDGPU/Transforms/TransferReadToLoad.cpp
index 9f64abb5a8860..fe7c1d5bdbbe4 100644
--- a/mlir/lib/Dialect/AMDGPU/Transforms/TransferReadToLoad.cpp
+++ b/mlir/lib/Dialect/AMDGPU/Transforms/TransferReadToLoad.cpp
@@ -63,10 +63,10 @@ static LogicalResult transferPreconditions(
return rewriter.notifyMatchFailure(xferOp, "not a memref source");
Attribute addrSpace = memRefType.getMemorySpace();
- if (!addrSpace || !dyn_cast<amdgpu::AddressSpaceAttr>(addrSpace))
+ if (!isa_and_nonnull<amdgpu::AddressSpaceAttr>(addrSpace))
return rewriter.notifyMatchFailure(xferOp, "no address space");
- if (dyn_cast<amdgpu::AddressSpaceAttr>(addrSpace).getValue() !=
+ if (isa<amdgpu::AddressSpaceAttr>(addrSpace).getValue() !=
amdgpu::AddressSpace::FatRawBuffer)
return rewriter.notifyMatchFailure(xferOp, "not in buffer address space");
diff --git a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
index eb23403a68813..6f99306b54b45 100644
--- a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
+++ b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
@@ -2194,7 +2194,7 @@ static void printBound(AffineMapAttr boundMap,
// Print bound that consists of a single SSA symbol if the map is over a
// single symbol.
if (map.getNumDims() == 0 && map.getNumSymbols() == 1) {
- if (dyn_cast<AffineSymbolExpr>(expr)) {
+ if (isa<AffineSymbolExpr>(expr)) {
p.printOperand(*boundOperands.begin());
return;
}
diff --git a/mlir/lib/Dialect/Arith/Utils/Utils.cpp b/mlir/lib/Dialect/Arith/Utils/Utils.cpp
index 6b1074e454bd5..bb4807ab39cd6 100644
--- a/mlir/lib/Dialect/Arith/Utils/Utils.cpp
+++ b/mlir/lib/Dialect/Arith/Utils/Utils.cpp
@@ -205,7 +205,7 @@ static Value convertScalarToComplexDtype(ImplicitLocOpBuilder &b, Value operand,
}
}
- if (dyn_cast<FloatType>(operand.getType())) {
+ if (isa<FloatType>(operand.getType())) {
FloatType toFpTy = cast<FloatType>(targetType.getElementType());
auto toBitwidth = toFpTy.getIntOrFloatBitWidth();
Value from = operand;
@@ -220,7 +220,7 @@ static Value convertScalarToComplexDtype(ImplicitLocOpBuilder &b, Value operand,
return b.create<complex::CreateOp>(targetType, from, zero);
}
- if (dyn_cast<IntegerType>(operand.getType())) {
+ if (isa<IntegerType>(operand.getType())) {
FloatType toFpTy = cast<FloatType>(targetType.getElementType());
Value from = operand;
if (isUnsigned) {
diff --git a/mlir/lib/Dialect/Async/Transforms/AsyncRuntimeRefCounting.cpp b/mlir/lib/Dialect/Async/Transforms/AsyncRuntimeRefCounting.cpp
index 5cc30b629aef4..dffb965cb6616 100644
--- a/mlir/lib/Dialect/Async/Transforms/AsyncRuntimeRefCounting.cpp
+++ b/mlir/lib/Dialect/Async/Transforms/AsyncRuntimeRefCounting.cpp
@@ -533,15 +533,15 @@ void AsyncRuntimePolicyBasedRefCountingPass::initializeDefaultPolicy() {
bool isValue = isa<ValueType>(type);
// Drop reference after async token or group error check (coro await).
- if (dyn_cast<RuntimeIsErrorOp>(op))
+ if (isa<RuntimeIsErrorOp>(op))
return (isToken || isGroup) ? -1 : 0;
// Drop reference after async value load.
- if (dyn_cast<RuntimeLoadOp>(op))
+ if (isa<RuntimeLoadOp>(op))
return isValue ? -1 : 0;
// Drop reference after async token added to the group.
- if (dyn_cast<RuntimeAddToGroupOp>(op))
+ if (isa<RuntimeAddToGroupOp>(op))
return isToken ? -1 : 0;
return 0;
diff --git a/mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp b/mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp
index c16c38ea22a5d..7d1844df42195 100644
--- a/mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp
+++ b/mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp
@@ -1296,7 +1296,7 @@ LogicalResult mlir::linalg::detail::verifyStructuredOpInterface(Operation *op) {
"unexpected result less than 0 at expression #")
<< dim << " in " << mapStr;
}
- if (dyn_cast<AffineDimExpr>(indexingMap.getResult(dim))) {
+ if (isa<AffineDimExpr>(indexingMap.getResult(dim))) {
if (inferredDimSize != shape[dim]) {
return op->emitOpError("inferred input/output operand #")
<< opOperand.getOperandNumber() << " has shape's dimension #"
diff --git a/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp b/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
index b20e6050fb4f8..9c909bb30c420 100644
--- a/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
+++ b/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
@@ -1212,7 +1212,7 @@ DiagnosedSilenceableFailure transform::LinalgCopyToMemrefOp::applyToOne(
// linalg.copy supports different element types on source/dest whereas
// memref.copy does not, so we must check that the source and dest types can
// be handled by memref.copy and otherwise reject the transformation.
- if (!dyn_cast<ShapedType>(input.getType())) {
+ if (!isa<ShapedType>(input.getType())) {
DiagnosedSilenceableFailure diag =
emitSilenceableError()
<< "cannot transform a linalg.copy which input has no shape";
@@ -1221,7 +1221,7 @@ DiagnosedSilenceableFailure transform::LinalgCopyToMemrefOp::applyToOne(
}
// linalg.copy destination must be a shaped type.
- assert(dyn_cast<ShapedType>(output.getType()));
+ assert(isa<ShapedType>(output.getType()));
if (cast<ShapedType>(input.getType()).getElementType() !=
cast<ShapedType>(output.getType()).getElementType()) {
diff --git a/mlir/lib/Dialect/Linalg/Transforms/Detensorize.cpp b/mlir/lib/Dialect/Linalg/Transforms/Detensorize.cpp
index 0d62d72abd076..20ab5ecbe3c4a 100644
--- a/mlir/lib/Dialect/Linalg/Transforms/Detensorize.cpp
+++ b/mlir/lib/Dialect/Linalg/Transforms/Detensorize.cpp
@@ -317,9 +317,8 @@ struct LinalgDetensorize
// * Add the argument to blockArgsToDetensor.
// * Walk the use-def chain backwards to add each predecessor's
// terminator-operands corresponding to currentItem to workList.
- if (dyn_cast<BlockArgument>(currentItem)) {
- BlockArgument currentItemBlockArgument =
- cast<BlockArgument>(currentItem);
+ if (auto currentItemBlockArgument =
+ dyn_cast<BlockArgument>(currentItem)) {
Block *ownerBlock = currentItemBlockArgument.getOwner();
// Function arguments are not detensored/converted.
@@ -414,7 +413,7 @@ struct LinalgDetensorize
Block *block = blockArg.getParentBlock();
// For the potentially detensorable block argument, find the
- // correpsonding operands in predecessor blocks.
+ // corresponding operands in predecessor blocks.
for (PredecessorIterator pred = block->pred_begin();
pred != block->pred_end(); ++pred) {
BranchOpInterface terminator =
diff --git a/mlir/lib/Dialect/Linalg/Transforms/Loops.cpp b/mlir/lib/Dialect/Linalg/Transforms/Loops.cpp
index 984f3f5a34ab1..5b2ec4a6ff528 100644
--- a/mlir/lib/Dialect/Linalg/Transforms/Loops.cpp
+++ b/mlir/lib/Dialect/Linalg/Transforms/Loops.cpp
@@ -303,7 +303,7 @@ struct FoldAffineOp : public RewritePattern {
}
return failure();
}
- if (dyn_cast<AffineDimExpr>(expr) || dyn_cast<AffineSymbolExpr>(expr)) {
+ if (isa<AffineDimExpr, AffineSymbolExpr>(expr)) {
rewriter.replaceOp(op, op->getOperand(0));
return success();
}
diff --git a/mlir/lib/Dialect/Quant/Utils/UniformSupport.cpp b/mlir/lib/Dialect/Quant/Utils/UniformSupport.cpp
index 62c7a7128d63a..b66390819103e 100644
--- a/mlir/lib/Dialect/Quant/Utils/UniformSupport.cpp
+++ b/mlir/lib/Dialect/Quant/Utils/UniformSupport.cpp
@@ -36,7 +36,7 @@ Type ExpressedToQuantizedConverter::convert(QuantizedType elementalType) const {
assert(expressedType && "convert() on unsupported conversion");
if (auto tensorType = dyn_cast<RankedTensorType>(inputType))
return RankedTensorType::get(tensorType.getShape(), elementalType);
- if (dyn_cast<UnrankedTensorType>(inputType))
+ if (isa<UnrankedTensorType>(inputType))
return UnrankedTensorType::get(elementalType);
if (auto vectorType = dyn_cast<VectorType>(inputType))
return VectorType::get(vectorType.getShape(), elementalType);
diff --git a/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp b/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp
index 60db71d96547f..dcb0237070885 100644
--- a/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp
+++ b/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp
@@ -1284,7 +1284,7 @@ struct DirectConvertRewriter : public OpRewritePattern<ConvertOp> {
bool fromSparseConst = false;
if (auto constOp = op.getSource().getDefiningOp<arith::ConstantOp>())
- if (dyn_cast<SparseElementsAttr>(constOp.getValue()))
+ if (isa<SparseElementsAttr>(constOp.getValue()))
fromSparseConst = true;
const AffineMapAttr foreachOrder =
diff --git a/mlir/lib/Dialect/SparseTensor/Transforms/Utils/CodegenUtils.cpp b/mlir/lib/Dialect/SparseTensor/Transforms/Utils/CodegenUtils.cpp
index f92382472b478..0ebdc3a54e61b 100644
--- a/mlir/lib/Dialect/SparseTensor/Transforms/Utils/CodegenUtils.cpp
+++ b/mlir/lib/Dialect/SparseTensor/Transforms/Utils/CodegenUtils.cpp
@@ -211,7 +211,7 @@ Value mlir::sparse_tensor::genIsNonzero(OpBuilder &builder, mlir::Location loc,
if (tp.isIntOrIndex())
return builder.create<arith::CmpIOp>(loc, arith::CmpIPredicate::ne, v,
zero);
- if (dyn_cast<ComplexType>(tp))
+ if (isa<ComplexType>(tp))
return builder.create<complex::NotEqualOp>(loc, v, zero);
llvm_unreachable("Non-numeric type");
}
diff --git a/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp b/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp
index 47368532df169..142928d836546 100644
--- a/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp
+++ b/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp
@@ -399,7 +399,7 @@ struct TransposeIsReshape : public OpRewritePattern<tosa::TransposeOp> {
Value result = op.getResult();
for (Operation *subop : result.getUsers()) {
- if (dyn_cast_or_null<tosa::TransposeOp>(subop))
+ if (isa_and_nonnull<tosa::TransposeOp>(subop))
return rewriter.notifyMatchFailure(
op, "Dest is used by transpose, can compose transposes");
}
diff --git a/mlir/lib/IR/Diagnostics.cpp b/mlir/lib/IR/Diagnostics.cpp
index 59d803035bda0..79697be2b45ea 100644
--- a/mlir/lib/IR/Diagnostics.cpp
+++ b/mlir/lib/IR/Diagnostics.cpp
@@ -392,11 +392,11 @@ struct SourceMgrDiagnosticHandlerImpl {
/// Return a processable CallSiteLoc from the given location.
static std::optional<CallSiteLoc> getCallSiteLoc(Location loc) {
- if (dyn_cast<NameLoc>(loc))
+ if (isa<NameLoc>(loc))
return getCallSiteLoc(cast<NameLoc>(loc).getChildLoc());
if (auto callLoc = dyn_cast<CallSiteLoc>(loc))
return callLoc;
- if (dyn_cast<FusedLoc>(loc)) {
+ if (isa<FusedLoc>(loc)) {
for (auto subLoc : cast<FusedLoc>(loc).getLocations()) {
if (auto callLoc = getCallSiteLoc(subLoc)) {
return callLoc;
diff --git a/mlir/lib/Target/LLVMIR/Dialect/NVVM/NVVMToLLVMIRTranslation.cpp b/mlir/lib/Target/LLVMIR/Dialect/NVVM/NVVMToLLVMIRTranslation.cpp
index 7dfe32...
[truncated]
|
@llvm/pr-subscribers-clang Author: Max Graey (MaxGraey) ChangesAlso fix some typos in comments Patch is 21.62 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/137393.diff 26 Files Affected:
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 9c9372d9ee2b0..9d723903d75b5 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -9987,9 +9987,10 @@ void CheckFreeArgumentsAddressof(Sema &S, const std::string &CalleeName,
const UnaryOperator *UnaryExpr) {
if (const auto *Lvalue = dyn_cast<DeclRefExpr>(UnaryExpr->getSubExpr())) {
const Decl *D = Lvalue->getDecl();
- if (isa<DeclaratorDecl>(D))
- if (!dyn_cast<DeclaratorDecl>(D)->getType()->isReferenceType())
+ if (auto *DD = dyn_cast<DeclaratorDecl>(D)) {
+ if (!DD->getType()->isReferenceType())
return CheckFreeArgumentsOnLvalue(S, CalleeName, UnaryExpr, D);
+ }
}
if (const auto *Lvalue = dyn_cast<MemberExpr>(UnaryExpr->getSubExpr()))
diff --git a/clang/lib/Sema/SemaModule.cpp b/clang/lib/Sema/SemaModule.cpp
index 4bba57193ded6..f080fdeeec8b1 100644
--- a/clang/lib/Sema/SemaModule.cpp
+++ b/clang/lib/Sema/SemaModule.cpp
@@ -942,7 +942,7 @@ static bool checkExportedDecl(Sema &S, Decl *D, SourceLocation BlockStart) {
// HLSL: export declaration is valid only on functions
if (S.getLangOpts().HLSL) {
// Export-within-export was already diagnosed in ActOnStartExportDecl
- if (!dyn_cast<FunctionDecl>(D) && !dyn_cast<ExportDecl>(D)) {
+ if (!isa<FunctionDecl, ExportDecl>(D)) {
S.Diag(D->getBeginLoc(), diag::err_hlsl_export_not_on_function);
D->setInvalidDecl();
return false;
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 274d3b90ff30f..221f4e953aa0e 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -2299,7 +2299,7 @@ bool SemaOpenMP::isInOpenMPTargetExecutionDirective() const {
bool SemaOpenMP::isOpenMPRebuildMemberExpr(ValueDecl *D) {
// Only rebuild for Field.
- if (!dyn_cast<FieldDecl>(D))
+ if (!isa<FieldDecl>(D))
return false;
DSAStackTy::DSAVarData DVarPrivate = DSAStack->hasDSA(
D,
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLocalVarsChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLocalVarsChecker.cpp
index a23f3aa356cb0..4fb47703e3984 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLocalVarsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLocalVarsChecker.cpp
@@ -356,7 +356,7 @@ class RawPtrRefLocalVarsChecker
SmallString<100> Buf;
llvm::raw_svector_ostream Os(Buf);
- if (dyn_cast<ParmVarDecl>(V)) {
+ if (isa<ParmVarDecl>(V)) {
Os << "Assignment to an " << ptrKind() << " parameter ";
printQuotedQualifiedName(Os, V);
Os << " is unsafe.";
diff --git a/lld/MachO/SymbolTable.cpp b/lld/MachO/SymbolTable.cpp
index ad48e909903b5..baddddcb76fbf 100644
--- a/lld/MachO/SymbolTable.cpp
+++ b/lld/MachO/SymbolTable.cpp
@@ -518,7 +518,7 @@ static const Symbol *getAlternativeSpelling(const Undefined &sym,
// If in the symbol table and not undefined.
if (const Symbol *s = symtab->find(newName))
- if (dyn_cast<Undefined>(s) == nullptr)
+ if (!isa<Undefined>(s))
return s;
return nullptr;
@@ -567,8 +567,7 @@ static const Symbol *getAlternativeSpelling(const Undefined &sym,
if (name.equals_insensitive(it.first))
return it.second;
for (Symbol *sym : symtab->getSymbols())
- if (dyn_cast<Undefined>(sym) == nullptr &&
- name.equals_insensitive(sym->getName()))
+ if (!isa<Undefined>(sym) && name.equals_insensitive(sym->getName()))
return sym;
// The reference may be a mangled name while the definition is not. Suggest a
diff --git a/llvm/include/llvm/Analysis/LoopInfo.h b/llvm/include/llvm/Analysis/LoopInfo.h
index abc0bb8588fa8..814c61bf4c350 100644
--- a/llvm/include/llvm/Analysis/LoopInfo.h
+++ b/llvm/include/llvm/Analysis/LoopInfo.h
@@ -529,7 +529,7 @@ class LoopInfo : public LoopInfoBase<BasicBlock, Loop> {
}
// Return true if a new use of V added in ExitBB would require an LCSSA PHI
- // to be inserted at the begining of the block. Note that V is assumed to
+ // to be inserted at the beginning of the block. Note that V is assumed to
// dominate ExitBB, and ExitBB must be the exit block of some loop. The
// IR is assumed to be in LCSSA form before the planned insertion.
bool wouldBeOutOfLoopUseRequiringLCSSA(const Value *V,
diff --git a/llvm/lib/Bitcode/Reader/MetadataLoader.cpp b/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
index 4879569200549..c724488b45d48 100644
--- a/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
+++ b/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
@@ -558,7 +558,7 @@ class MetadataLoader::MetadataLoaderImpl {
SetVector<Metadata *> EntitiesToRemove;
for (Metadata *Op : CU->getImportedEntities()->operands()) {
auto *IE = cast<DIImportedEntity>(Op);
- if (dyn_cast_or_null<DILocalScope>(IE->getScope())) {
+ if (isa_and_nonnull<DILocalScope>(IE->getScope())) {
EntitiesToRemove.insert(IE);
}
}
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 84054ddd0298c..e33b0b30c3b5f 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -6576,7 +6576,7 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
for (BasicBlock *ColorFirstBB : CV)
if (auto It = ColorFirstBB->getFirstNonPHIIt();
It != ColorFirstBB->end())
- if (dyn_cast_or_null<FuncletPadInst>(&*It))
+ if (isa_and_nonnull<FuncletPadInst>(&*It))
InEHFunclet = true;
// Check for funclet operand bundle
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyTargetTransformInfo.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyTargetTransformInfo.cpp
index 49aa94956bda6..24b95ac8bbd51 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyTargetTransformInfo.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyTargetTransformInfo.cpp
@@ -294,7 +294,7 @@ bool WebAssemblyTTIImpl::isProfitableToSinkOperands(
Value *V = I->getOperand(1);
// We dont need to sink constant splat.
- if (dyn_cast<Constant>(V))
+ if (isa<Constant>(V))
return false;
if (match(V, m_Shuffle(m_InsertElt(m_Value(), m_Value(), m_ZeroInt()),
diff --git a/mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp b/mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp
index ea251e4564ea8..57c8f4402cf4b 100644
--- a/mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp
+++ b/mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp
@@ -755,7 +755,7 @@ LLVMTypeConverter::promoteOperands(Location loc, ValueRange opOperands,
if (useBarePtrCallConv) {
// For the bare-ptr calling convention, we only have to extract the
// aligned pointer of a memref.
- if (dyn_cast<MemRefType>(operand.getType())) {
+ if (isa<MemRefType>(operand.getType())) {
MemRefDescriptor desc(llvmOperand);
llvmOperand = desc.alignedPtr(builder, loc);
} else if (isa<UnrankedMemRefType>(operand.getType())) {
diff --git a/mlir/lib/Conversion/MathToFuncs/MathToFuncs.cpp b/mlir/lib/Conversion/MathToFuncs/MathToFuncs.cpp
index df5396ac628cf..7f4655e53609e 100644
--- a/mlir/lib/Conversion/MathToFuncs/MathToFuncs.cpp
+++ b/mlir/lib/Conversion/MathToFuncs/MathToFuncs.cpp
@@ -586,7 +586,7 @@ static func::FuncOp createElementFPowIFunc(ModuleOp *module,
LogicalResult
FPowIOpLowering::matchAndRewrite(math::FPowIOp op,
PatternRewriter &rewriter) const {
- if (dyn_cast<VectorType>(op.getType()))
+ if (isa<VectorType>(op.getType()))
return rewriter.notifyMatchFailure(op, "non-scalar operation");
FunctionType funcType = getElementalFuncTypeForOp(op);
@@ -751,7 +751,7 @@ static func::FuncOp createCtlzFunc(ModuleOp *module, Type elementType) {
/// operation.
LogicalResult CtlzOpLowering::matchAndRewrite(math::CountLeadingZerosOp op,
PatternRewriter &rewriter) const {
- if (dyn_cast<VectorType>(op.getType()))
+ if (isa<VectorType>(op.getType()))
return rewriter.notifyMatchFailure(op, "non-scalar operation");
Type type = getElementTypeOrSelf(op.getResult().getType());
diff --git a/mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp b/mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp
index c8b2c0bdc6c20..158de6dea58c9 100644
--- a/mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp
+++ b/mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp
@@ -890,7 +890,7 @@ struct RankOpLowering : public ConvertOpToLLVMPattern<memref::RankOp> {
ConversionPatternRewriter &rewriter) const override {
Location loc = op.getLoc();
Type operandType = op.getMemref().getType();
- if (dyn_cast<UnrankedMemRefType>(operandType)) {
+ if (isa<UnrankedMemRefType>(operandType)) {
UnrankedMemRefDescriptor desc(adaptor.getMemref());
rewriter.replaceOp(op, {desc.rank(rewriter, loc)});
return success();
diff --git a/mlir/lib/Dialect/AMDGPU/Transforms/TransferReadToLoad.cpp b/mlir/lib/Dialect/AMDGPU/Transforms/TransferReadToLoad.cpp
index 9f64abb5a8860..fe7c1d5bdbbe4 100644
--- a/mlir/lib/Dialect/AMDGPU/Transforms/TransferReadToLoad.cpp
+++ b/mlir/lib/Dialect/AMDGPU/Transforms/TransferReadToLoad.cpp
@@ -63,10 +63,10 @@ static LogicalResult transferPreconditions(
return rewriter.notifyMatchFailure(xferOp, "not a memref source");
Attribute addrSpace = memRefType.getMemorySpace();
- if (!addrSpace || !dyn_cast<amdgpu::AddressSpaceAttr>(addrSpace))
+ if (!isa_and_nonnull<amdgpu::AddressSpaceAttr>(addrSpace))
return rewriter.notifyMatchFailure(xferOp, "no address space");
- if (dyn_cast<amdgpu::AddressSpaceAttr>(addrSpace).getValue() !=
+ if (isa<amdgpu::AddressSpaceAttr>(addrSpace).getValue() !=
amdgpu::AddressSpace::FatRawBuffer)
return rewriter.notifyMatchFailure(xferOp, "not in buffer address space");
diff --git a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
index eb23403a68813..6f99306b54b45 100644
--- a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
+++ b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
@@ -2194,7 +2194,7 @@ static void printBound(AffineMapAttr boundMap,
// Print bound that consists of a single SSA symbol if the map is over a
// single symbol.
if (map.getNumDims() == 0 && map.getNumSymbols() == 1) {
- if (dyn_cast<AffineSymbolExpr>(expr)) {
+ if (isa<AffineSymbolExpr>(expr)) {
p.printOperand(*boundOperands.begin());
return;
}
diff --git a/mlir/lib/Dialect/Arith/Utils/Utils.cpp b/mlir/lib/Dialect/Arith/Utils/Utils.cpp
index 6b1074e454bd5..bb4807ab39cd6 100644
--- a/mlir/lib/Dialect/Arith/Utils/Utils.cpp
+++ b/mlir/lib/Dialect/Arith/Utils/Utils.cpp
@@ -205,7 +205,7 @@ static Value convertScalarToComplexDtype(ImplicitLocOpBuilder &b, Value operand,
}
}
- if (dyn_cast<FloatType>(operand.getType())) {
+ if (isa<FloatType>(operand.getType())) {
FloatType toFpTy = cast<FloatType>(targetType.getElementType());
auto toBitwidth = toFpTy.getIntOrFloatBitWidth();
Value from = operand;
@@ -220,7 +220,7 @@ static Value convertScalarToComplexDtype(ImplicitLocOpBuilder &b, Value operand,
return b.create<complex::CreateOp>(targetType, from, zero);
}
- if (dyn_cast<IntegerType>(operand.getType())) {
+ if (isa<IntegerType>(operand.getType())) {
FloatType toFpTy = cast<FloatType>(targetType.getElementType());
Value from = operand;
if (isUnsigned) {
diff --git a/mlir/lib/Dialect/Async/Transforms/AsyncRuntimeRefCounting.cpp b/mlir/lib/Dialect/Async/Transforms/AsyncRuntimeRefCounting.cpp
index 5cc30b629aef4..dffb965cb6616 100644
--- a/mlir/lib/Dialect/Async/Transforms/AsyncRuntimeRefCounting.cpp
+++ b/mlir/lib/Dialect/Async/Transforms/AsyncRuntimeRefCounting.cpp
@@ -533,15 +533,15 @@ void AsyncRuntimePolicyBasedRefCountingPass::initializeDefaultPolicy() {
bool isValue = isa<ValueType>(type);
// Drop reference after async token or group error check (coro await).
- if (dyn_cast<RuntimeIsErrorOp>(op))
+ if (isa<RuntimeIsErrorOp>(op))
return (isToken || isGroup) ? -1 : 0;
// Drop reference after async value load.
- if (dyn_cast<RuntimeLoadOp>(op))
+ if (isa<RuntimeLoadOp>(op))
return isValue ? -1 : 0;
// Drop reference after async token added to the group.
- if (dyn_cast<RuntimeAddToGroupOp>(op))
+ if (isa<RuntimeAddToGroupOp>(op))
return isToken ? -1 : 0;
return 0;
diff --git a/mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp b/mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp
index c16c38ea22a5d..7d1844df42195 100644
--- a/mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp
+++ b/mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp
@@ -1296,7 +1296,7 @@ LogicalResult mlir::linalg::detail::verifyStructuredOpInterface(Operation *op) {
"unexpected result less than 0 at expression #")
<< dim << " in " << mapStr;
}
- if (dyn_cast<AffineDimExpr>(indexingMap.getResult(dim))) {
+ if (isa<AffineDimExpr>(indexingMap.getResult(dim))) {
if (inferredDimSize != shape[dim]) {
return op->emitOpError("inferred input/output operand #")
<< opOperand.getOperandNumber() << " has shape's dimension #"
diff --git a/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp b/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
index b20e6050fb4f8..9c909bb30c420 100644
--- a/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
+++ b/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
@@ -1212,7 +1212,7 @@ DiagnosedSilenceableFailure transform::LinalgCopyToMemrefOp::applyToOne(
// linalg.copy supports different element types on source/dest whereas
// memref.copy does not, so we must check that the source and dest types can
// be handled by memref.copy and otherwise reject the transformation.
- if (!dyn_cast<ShapedType>(input.getType())) {
+ if (!isa<ShapedType>(input.getType())) {
DiagnosedSilenceableFailure diag =
emitSilenceableError()
<< "cannot transform a linalg.copy which input has no shape";
@@ -1221,7 +1221,7 @@ DiagnosedSilenceableFailure transform::LinalgCopyToMemrefOp::applyToOne(
}
// linalg.copy destination must be a shaped type.
- assert(dyn_cast<ShapedType>(output.getType()));
+ assert(isa<ShapedType>(output.getType()));
if (cast<ShapedType>(input.getType()).getElementType() !=
cast<ShapedType>(output.getType()).getElementType()) {
diff --git a/mlir/lib/Dialect/Linalg/Transforms/Detensorize.cpp b/mlir/lib/Dialect/Linalg/Transforms/Detensorize.cpp
index 0d62d72abd076..20ab5ecbe3c4a 100644
--- a/mlir/lib/Dialect/Linalg/Transforms/Detensorize.cpp
+++ b/mlir/lib/Dialect/Linalg/Transforms/Detensorize.cpp
@@ -317,9 +317,8 @@ struct LinalgDetensorize
// * Add the argument to blockArgsToDetensor.
// * Walk the use-def chain backwards to add each predecessor's
// terminator-operands corresponding to currentItem to workList.
- if (dyn_cast<BlockArgument>(currentItem)) {
- BlockArgument currentItemBlockArgument =
- cast<BlockArgument>(currentItem);
+ if (auto currentItemBlockArgument =
+ dyn_cast<BlockArgument>(currentItem)) {
Block *ownerBlock = currentItemBlockArgument.getOwner();
// Function arguments are not detensored/converted.
@@ -414,7 +413,7 @@ struct LinalgDetensorize
Block *block = blockArg.getParentBlock();
// For the potentially detensorable block argument, find the
- // correpsonding operands in predecessor blocks.
+ // corresponding operands in predecessor blocks.
for (PredecessorIterator pred = block->pred_begin();
pred != block->pred_end(); ++pred) {
BranchOpInterface terminator =
diff --git a/mlir/lib/Dialect/Linalg/Transforms/Loops.cpp b/mlir/lib/Dialect/Linalg/Transforms/Loops.cpp
index 984f3f5a34ab1..5b2ec4a6ff528 100644
--- a/mlir/lib/Dialect/Linalg/Transforms/Loops.cpp
+++ b/mlir/lib/Dialect/Linalg/Transforms/Loops.cpp
@@ -303,7 +303,7 @@ struct FoldAffineOp : public RewritePattern {
}
return failure();
}
- if (dyn_cast<AffineDimExpr>(expr) || dyn_cast<AffineSymbolExpr>(expr)) {
+ if (isa<AffineDimExpr, AffineSymbolExpr>(expr)) {
rewriter.replaceOp(op, op->getOperand(0));
return success();
}
diff --git a/mlir/lib/Dialect/Quant/Utils/UniformSupport.cpp b/mlir/lib/Dialect/Quant/Utils/UniformSupport.cpp
index 62c7a7128d63a..b66390819103e 100644
--- a/mlir/lib/Dialect/Quant/Utils/UniformSupport.cpp
+++ b/mlir/lib/Dialect/Quant/Utils/UniformSupport.cpp
@@ -36,7 +36,7 @@ Type ExpressedToQuantizedConverter::convert(QuantizedType elementalType) const {
assert(expressedType && "convert() on unsupported conversion");
if (auto tensorType = dyn_cast<RankedTensorType>(inputType))
return RankedTensorType::get(tensorType.getShape(), elementalType);
- if (dyn_cast<UnrankedTensorType>(inputType))
+ if (isa<UnrankedTensorType>(inputType))
return UnrankedTensorType::get(elementalType);
if (auto vectorType = dyn_cast<VectorType>(inputType))
return VectorType::get(vectorType.getShape(), elementalType);
diff --git a/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp b/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp
index 60db71d96547f..dcb0237070885 100644
--- a/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp
+++ b/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp
@@ -1284,7 +1284,7 @@ struct DirectConvertRewriter : public OpRewritePattern<ConvertOp> {
bool fromSparseConst = false;
if (auto constOp = op.getSource().getDefiningOp<arith::ConstantOp>())
- if (dyn_cast<SparseElementsAttr>(constOp.getValue()))
+ if (isa<SparseElementsAttr>(constOp.getValue()))
fromSparseConst = true;
const AffineMapAttr foreachOrder =
diff --git a/mlir/lib/Dialect/SparseTensor/Transforms/Utils/CodegenUtils.cpp b/mlir/lib/Dialect/SparseTensor/Transforms/Utils/CodegenUtils.cpp
index f92382472b478..0ebdc3a54e61b 100644
--- a/mlir/lib/Dialect/SparseTensor/Transforms/Utils/CodegenUtils.cpp
+++ b/mlir/lib/Dialect/SparseTensor/Transforms/Utils/CodegenUtils.cpp
@@ -211,7 +211,7 @@ Value mlir::sparse_tensor::genIsNonzero(OpBuilder &builder, mlir::Location loc,
if (tp.isIntOrIndex())
return builder.create<arith::CmpIOp>(loc, arith::CmpIPredicate::ne, v,
zero);
- if (dyn_cast<ComplexType>(tp))
+ if (isa<ComplexType>(tp))
return builder.create<complex::NotEqualOp>(loc, v, zero);
llvm_unreachable("Non-numeric type");
}
diff --git a/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp b/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp
index 47368532df169..142928d836546 100644
--- a/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp
+++ b/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp
@@ -399,7 +399,7 @@ struct TransposeIsReshape : public OpRewritePattern<tosa::TransposeOp> {
Value result = op.getResult();
for (Operation *subop : result.getUsers()) {
- if (dyn_cast_or_null<tosa::TransposeOp>(subop))
+ if (isa_and_nonnull<tosa::TransposeOp>(subop))
return rewriter.notifyMatchFailure(
op, "Dest is used by transpose, can compose transposes");
}
diff --git a/mlir/lib/IR/Diagnostics.cpp b/mlir/lib/IR/Diagnostics.cpp
index 59d803035bda0..79697be2b45ea 100644
--- a/mlir/lib/IR/Diagnostics.cpp
+++ b/mlir/lib/IR/Diagnostics.cpp
@@ -392,11 +392,11 @@ struct SourceMgrDiagnosticHandlerImpl {
/// Return a processable CallSiteLoc from the given location.
static std::optional<CallSiteLoc> getCallSiteLoc(Location loc) {
- if (dyn_cast<NameLoc>(loc))
+ if (isa<NameLoc>(loc))
return getCallSiteLoc(cast<NameLoc>(loc).getChildLoc());
if (auto callLoc = dyn_cast<CallSiteLoc>(loc))
return callLoc;
- if (dyn_cast<FusedLoc>(loc)) {
+ if (isa<FusedLoc>(loc)) {
for (auto subLoc : cast<FusedLoc>(loc).getLocations()) {
if (auto callLoc = getCallSiteLoc(subLoc)) {
return callLoc;
diff --git a/mlir/lib/Target/LLVMIR/Dialect/NVVM/NVVMToLLVMIRTranslation.cpp b/mlir/lib/Target/LLVMIR/Dialect/NVVM/NVVMToLLVMIRTranslation.cpp
index 7dfe32...
[truncated]
|
@llvm/pr-subscribers-clang-static-analyzer-1 Author: Max Graey (MaxGraey) ChangesAlso fix some typos in comments Patch is 21.62 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/137393.diff 26 Files Affected:
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 9c9372d9ee2b0..9d723903d75b5 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -9987,9 +9987,10 @@ void CheckFreeArgumentsAddressof(Sema &S, const std::string &CalleeName,
const UnaryOperator *UnaryExpr) {
if (const auto *Lvalue = dyn_cast<DeclRefExpr>(UnaryExpr->getSubExpr())) {
const Decl *D = Lvalue->getDecl();
- if (isa<DeclaratorDecl>(D))
- if (!dyn_cast<DeclaratorDecl>(D)->getType()->isReferenceType())
+ if (auto *DD = dyn_cast<DeclaratorDecl>(D)) {
+ if (!DD->getType()->isReferenceType())
return CheckFreeArgumentsOnLvalue(S, CalleeName, UnaryExpr, D);
+ }
}
if (const auto *Lvalue = dyn_cast<MemberExpr>(UnaryExpr->getSubExpr()))
diff --git a/clang/lib/Sema/SemaModule.cpp b/clang/lib/Sema/SemaModule.cpp
index 4bba57193ded6..f080fdeeec8b1 100644
--- a/clang/lib/Sema/SemaModule.cpp
+++ b/clang/lib/Sema/SemaModule.cpp
@@ -942,7 +942,7 @@ static bool checkExportedDecl(Sema &S, Decl *D, SourceLocation BlockStart) {
// HLSL: export declaration is valid only on functions
if (S.getLangOpts().HLSL) {
// Export-within-export was already diagnosed in ActOnStartExportDecl
- if (!dyn_cast<FunctionDecl>(D) && !dyn_cast<ExportDecl>(D)) {
+ if (!isa<FunctionDecl, ExportDecl>(D)) {
S.Diag(D->getBeginLoc(), diag::err_hlsl_export_not_on_function);
D->setInvalidDecl();
return false;
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 274d3b90ff30f..221f4e953aa0e 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -2299,7 +2299,7 @@ bool SemaOpenMP::isInOpenMPTargetExecutionDirective() const {
bool SemaOpenMP::isOpenMPRebuildMemberExpr(ValueDecl *D) {
// Only rebuild for Field.
- if (!dyn_cast<FieldDecl>(D))
+ if (!isa<FieldDecl>(D))
return false;
DSAStackTy::DSAVarData DVarPrivate = DSAStack->hasDSA(
D,
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLocalVarsChecker.cpp b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLocalVarsChecker.cpp
index a23f3aa356cb0..4fb47703e3984 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLocalVarsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLocalVarsChecker.cpp
@@ -356,7 +356,7 @@ class RawPtrRefLocalVarsChecker
SmallString<100> Buf;
llvm::raw_svector_ostream Os(Buf);
- if (dyn_cast<ParmVarDecl>(V)) {
+ if (isa<ParmVarDecl>(V)) {
Os << "Assignment to an " << ptrKind() << " parameter ";
printQuotedQualifiedName(Os, V);
Os << " is unsafe.";
diff --git a/lld/MachO/SymbolTable.cpp b/lld/MachO/SymbolTable.cpp
index ad48e909903b5..baddddcb76fbf 100644
--- a/lld/MachO/SymbolTable.cpp
+++ b/lld/MachO/SymbolTable.cpp
@@ -518,7 +518,7 @@ static const Symbol *getAlternativeSpelling(const Undefined &sym,
// If in the symbol table and not undefined.
if (const Symbol *s = symtab->find(newName))
- if (dyn_cast<Undefined>(s) == nullptr)
+ if (!isa<Undefined>(s))
return s;
return nullptr;
@@ -567,8 +567,7 @@ static const Symbol *getAlternativeSpelling(const Undefined &sym,
if (name.equals_insensitive(it.first))
return it.second;
for (Symbol *sym : symtab->getSymbols())
- if (dyn_cast<Undefined>(sym) == nullptr &&
- name.equals_insensitive(sym->getName()))
+ if (!isa<Undefined>(sym) && name.equals_insensitive(sym->getName()))
return sym;
// The reference may be a mangled name while the definition is not. Suggest a
diff --git a/llvm/include/llvm/Analysis/LoopInfo.h b/llvm/include/llvm/Analysis/LoopInfo.h
index abc0bb8588fa8..814c61bf4c350 100644
--- a/llvm/include/llvm/Analysis/LoopInfo.h
+++ b/llvm/include/llvm/Analysis/LoopInfo.h
@@ -529,7 +529,7 @@ class LoopInfo : public LoopInfoBase<BasicBlock, Loop> {
}
// Return true if a new use of V added in ExitBB would require an LCSSA PHI
- // to be inserted at the begining of the block. Note that V is assumed to
+ // to be inserted at the beginning of the block. Note that V is assumed to
// dominate ExitBB, and ExitBB must be the exit block of some loop. The
// IR is assumed to be in LCSSA form before the planned insertion.
bool wouldBeOutOfLoopUseRequiringLCSSA(const Value *V,
diff --git a/llvm/lib/Bitcode/Reader/MetadataLoader.cpp b/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
index 4879569200549..c724488b45d48 100644
--- a/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
+++ b/llvm/lib/Bitcode/Reader/MetadataLoader.cpp
@@ -558,7 +558,7 @@ class MetadataLoader::MetadataLoaderImpl {
SetVector<Metadata *> EntitiesToRemove;
for (Metadata *Op : CU->getImportedEntities()->operands()) {
auto *IE = cast<DIImportedEntity>(Op);
- if (dyn_cast_or_null<DILocalScope>(IE->getScope())) {
+ if (isa_and_nonnull<DILocalScope>(IE->getScope())) {
EntitiesToRemove.insert(IE);
}
}
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 84054ddd0298c..e33b0b30c3b5f 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -6576,7 +6576,7 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
for (BasicBlock *ColorFirstBB : CV)
if (auto It = ColorFirstBB->getFirstNonPHIIt();
It != ColorFirstBB->end())
- if (dyn_cast_or_null<FuncletPadInst>(&*It))
+ if (isa_and_nonnull<FuncletPadInst>(&*It))
InEHFunclet = true;
// Check for funclet operand bundle
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyTargetTransformInfo.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyTargetTransformInfo.cpp
index 49aa94956bda6..24b95ac8bbd51 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyTargetTransformInfo.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyTargetTransformInfo.cpp
@@ -294,7 +294,7 @@ bool WebAssemblyTTIImpl::isProfitableToSinkOperands(
Value *V = I->getOperand(1);
// We dont need to sink constant splat.
- if (dyn_cast<Constant>(V))
+ if (isa<Constant>(V))
return false;
if (match(V, m_Shuffle(m_InsertElt(m_Value(), m_Value(), m_ZeroInt()),
diff --git a/mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp b/mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp
index ea251e4564ea8..57c8f4402cf4b 100644
--- a/mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp
+++ b/mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp
@@ -755,7 +755,7 @@ LLVMTypeConverter::promoteOperands(Location loc, ValueRange opOperands,
if (useBarePtrCallConv) {
// For the bare-ptr calling convention, we only have to extract the
// aligned pointer of a memref.
- if (dyn_cast<MemRefType>(operand.getType())) {
+ if (isa<MemRefType>(operand.getType())) {
MemRefDescriptor desc(llvmOperand);
llvmOperand = desc.alignedPtr(builder, loc);
} else if (isa<UnrankedMemRefType>(operand.getType())) {
diff --git a/mlir/lib/Conversion/MathToFuncs/MathToFuncs.cpp b/mlir/lib/Conversion/MathToFuncs/MathToFuncs.cpp
index df5396ac628cf..7f4655e53609e 100644
--- a/mlir/lib/Conversion/MathToFuncs/MathToFuncs.cpp
+++ b/mlir/lib/Conversion/MathToFuncs/MathToFuncs.cpp
@@ -586,7 +586,7 @@ static func::FuncOp createElementFPowIFunc(ModuleOp *module,
LogicalResult
FPowIOpLowering::matchAndRewrite(math::FPowIOp op,
PatternRewriter &rewriter) const {
- if (dyn_cast<VectorType>(op.getType()))
+ if (isa<VectorType>(op.getType()))
return rewriter.notifyMatchFailure(op, "non-scalar operation");
FunctionType funcType = getElementalFuncTypeForOp(op);
@@ -751,7 +751,7 @@ static func::FuncOp createCtlzFunc(ModuleOp *module, Type elementType) {
/// operation.
LogicalResult CtlzOpLowering::matchAndRewrite(math::CountLeadingZerosOp op,
PatternRewriter &rewriter) const {
- if (dyn_cast<VectorType>(op.getType()))
+ if (isa<VectorType>(op.getType()))
return rewriter.notifyMatchFailure(op, "non-scalar operation");
Type type = getElementTypeOrSelf(op.getResult().getType());
diff --git a/mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp b/mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp
index c8b2c0bdc6c20..158de6dea58c9 100644
--- a/mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp
+++ b/mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp
@@ -890,7 +890,7 @@ struct RankOpLowering : public ConvertOpToLLVMPattern<memref::RankOp> {
ConversionPatternRewriter &rewriter) const override {
Location loc = op.getLoc();
Type operandType = op.getMemref().getType();
- if (dyn_cast<UnrankedMemRefType>(operandType)) {
+ if (isa<UnrankedMemRefType>(operandType)) {
UnrankedMemRefDescriptor desc(adaptor.getMemref());
rewriter.replaceOp(op, {desc.rank(rewriter, loc)});
return success();
diff --git a/mlir/lib/Dialect/AMDGPU/Transforms/TransferReadToLoad.cpp b/mlir/lib/Dialect/AMDGPU/Transforms/TransferReadToLoad.cpp
index 9f64abb5a8860..fe7c1d5bdbbe4 100644
--- a/mlir/lib/Dialect/AMDGPU/Transforms/TransferReadToLoad.cpp
+++ b/mlir/lib/Dialect/AMDGPU/Transforms/TransferReadToLoad.cpp
@@ -63,10 +63,10 @@ static LogicalResult transferPreconditions(
return rewriter.notifyMatchFailure(xferOp, "not a memref source");
Attribute addrSpace = memRefType.getMemorySpace();
- if (!addrSpace || !dyn_cast<amdgpu::AddressSpaceAttr>(addrSpace))
+ if (!isa_and_nonnull<amdgpu::AddressSpaceAttr>(addrSpace))
return rewriter.notifyMatchFailure(xferOp, "no address space");
- if (dyn_cast<amdgpu::AddressSpaceAttr>(addrSpace).getValue() !=
+ if (isa<amdgpu::AddressSpaceAttr>(addrSpace).getValue() !=
amdgpu::AddressSpace::FatRawBuffer)
return rewriter.notifyMatchFailure(xferOp, "not in buffer address space");
diff --git a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
index eb23403a68813..6f99306b54b45 100644
--- a/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
+++ b/mlir/lib/Dialect/Affine/IR/AffineOps.cpp
@@ -2194,7 +2194,7 @@ static void printBound(AffineMapAttr boundMap,
// Print bound that consists of a single SSA symbol if the map is over a
// single symbol.
if (map.getNumDims() == 0 && map.getNumSymbols() == 1) {
- if (dyn_cast<AffineSymbolExpr>(expr)) {
+ if (isa<AffineSymbolExpr>(expr)) {
p.printOperand(*boundOperands.begin());
return;
}
diff --git a/mlir/lib/Dialect/Arith/Utils/Utils.cpp b/mlir/lib/Dialect/Arith/Utils/Utils.cpp
index 6b1074e454bd5..bb4807ab39cd6 100644
--- a/mlir/lib/Dialect/Arith/Utils/Utils.cpp
+++ b/mlir/lib/Dialect/Arith/Utils/Utils.cpp
@@ -205,7 +205,7 @@ static Value convertScalarToComplexDtype(ImplicitLocOpBuilder &b, Value operand,
}
}
- if (dyn_cast<FloatType>(operand.getType())) {
+ if (isa<FloatType>(operand.getType())) {
FloatType toFpTy = cast<FloatType>(targetType.getElementType());
auto toBitwidth = toFpTy.getIntOrFloatBitWidth();
Value from = operand;
@@ -220,7 +220,7 @@ static Value convertScalarToComplexDtype(ImplicitLocOpBuilder &b, Value operand,
return b.create<complex::CreateOp>(targetType, from, zero);
}
- if (dyn_cast<IntegerType>(operand.getType())) {
+ if (isa<IntegerType>(operand.getType())) {
FloatType toFpTy = cast<FloatType>(targetType.getElementType());
Value from = operand;
if (isUnsigned) {
diff --git a/mlir/lib/Dialect/Async/Transforms/AsyncRuntimeRefCounting.cpp b/mlir/lib/Dialect/Async/Transforms/AsyncRuntimeRefCounting.cpp
index 5cc30b629aef4..dffb965cb6616 100644
--- a/mlir/lib/Dialect/Async/Transforms/AsyncRuntimeRefCounting.cpp
+++ b/mlir/lib/Dialect/Async/Transforms/AsyncRuntimeRefCounting.cpp
@@ -533,15 +533,15 @@ void AsyncRuntimePolicyBasedRefCountingPass::initializeDefaultPolicy() {
bool isValue = isa<ValueType>(type);
// Drop reference after async token or group error check (coro await).
- if (dyn_cast<RuntimeIsErrorOp>(op))
+ if (isa<RuntimeIsErrorOp>(op))
return (isToken || isGroup) ? -1 : 0;
// Drop reference after async value load.
- if (dyn_cast<RuntimeLoadOp>(op))
+ if (isa<RuntimeLoadOp>(op))
return isValue ? -1 : 0;
// Drop reference after async token added to the group.
- if (dyn_cast<RuntimeAddToGroupOp>(op))
+ if (isa<RuntimeAddToGroupOp>(op))
return isToken ? -1 : 0;
return 0;
diff --git a/mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp b/mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp
index c16c38ea22a5d..7d1844df42195 100644
--- a/mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp
+++ b/mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp
@@ -1296,7 +1296,7 @@ LogicalResult mlir::linalg::detail::verifyStructuredOpInterface(Operation *op) {
"unexpected result less than 0 at expression #")
<< dim << " in " << mapStr;
}
- if (dyn_cast<AffineDimExpr>(indexingMap.getResult(dim))) {
+ if (isa<AffineDimExpr>(indexingMap.getResult(dim))) {
if (inferredDimSize != shape[dim]) {
return op->emitOpError("inferred input/output operand #")
<< opOperand.getOperandNumber() << " has shape's dimension #"
diff --git a/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp b/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
index b20e6050fb4f8..9c909bb30c420 100644
--- a/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
+++ b/mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
@@ -1212,7 +1212,7 @@ DiagnosedSilenceableFailure transform::LinalgCopyToMemrefOp::applyToOne(
// linalg.copy supports different element types on source/dest whereas
// memref.copy does not, so we must check that the source and dest types can
// be handled by memref.copy and otherwise reject the transformation.
- if (!dyn_cast<ShapedType>(input.getType())) {
+ if (!isa<ShapedType>(input.getType())) {
DiagnosedSilenceableFailure diag =
emitSilenceableError()
<< "cannot transform a linalg.copy which input has no shape";
@@ -1221,7 +1221,7 @@ DiagnosedSilenceableFailure transform::LinalgCopyToMemrefOp::applyToOne(
}
// linalg.copy destination must be a shaped type.
- assert(dyn_cast<ShapedType>(output.getType()));
+ assert(isa<ShapedType>(output.getType()));
if (cast<ShapedType>(input.getType()).getElementType() !=
cast<ShapedType>(output.getType()).getElementType()) {
diff --git a/mlir/lib/Dialect/Linalg/Transforms/Detensorize.cpp b/mlir/lib/Dialect/Linalg/Transforms/Detensorize.cpp
index 0d62d72abd076..20ab5ecbe3c4a 100644
--- a/mlir/lib/Dialect/Linalg/Transforms/Detensorize.cpp
+++ b/mlir/lib/Dialect/Linalg/Transforms/Detensorize.cpp
@@ -317,9 +317,8 @@ struct LinalgDetensorize
// * Add the argument to blockArgsToDetensor.
// * Walk the use-def chain backwards to add each predecessor's
// terminator-operands corresponding to currentItem to workList.
- if (dyn_cast<BlockArgument>(currentItem)) {
- BlockArgument currentItemBlockArgument =
- cast<BlockArgument>(currentItem);
+ if (auto currentItemBlockArgument =
+ dyn_cast<BlockArgument>(currentItem)) {
Block *ownerBlock = currentItemBlockArgument.getOwner();
// Function arguments are not detensored/converted.
@@ -414,7 +413,7 @@ struct LinalgDetensorize
Block *block = blockArg.getParentBlock();
// For the potentially detensorable block argument, find the
- // correpsonding operands in predecessor blocks.
+ // corresponding operands in predecessor blocks.
for (PredecessorIterator pred = block->pred_begin();
pred != block->pred_end(); ++pred) {
BranchOpInterface terminator =
diff --git a/mlir/lib/Dialect/Linalg/Transforms/Loops.cpp b/mlir/lib/Dialect/Linalg/Transforms/Loops.cpp
index 984f3f5a34ab1..5b2ec4a6ff528 100644
--- a/mlir/lib/Dialect/Linalg/Transforms/Loops.cpp
+++ b/mlir/lib/Dialect/Linalg/Transforms/Loops.cpp
@@ -303,7 +303,7 @@ struct FoldAffineOp : public RewritePattern {
}
return failure();
}
- if (dyn_cast<AffineDimExpr>(expr) || dyn_cast<AffineSymbolExpr>(expr)) {
+ if (isa<AffineDimExpr, AffineSymbolExpr>(expr)) {
rewriter.replaceOp(op, op->getOperand(0));
return success();
}
diff --git a/mlir/lib/Dialect/Quant/Utils/UniformSupport.cpp b/mlir/lib/Dialect/Quant/Utils/UniformSupport.cpp
index 62c7a7128d63a..b66390819103e 100644
--- a/mlir/lib/Dialect/Quant/Utils/UniformSupport.cpp
+++ b/mlir/lib/Dialect/Quant/Utils/UniformSupport.cpp
@@ -36,7 +36,7 @@ Type ExpressedToQuantizedConverter::convert(QuantizedType elementalType) const {
assert(expressedType && "convert() on unsupported conversion");
if (auto tensorType = dyn_cast<RankedTensorType>(inputType))
return RankedTensorType::get(tensorType.getShape(), elementalType);
- if (dyn_cast<UnrankedTensorType>(inputType))
+ if (isa<UnrankedTensorType>(inputType))
return UnrankedTensorType::get(elementalType);
if (auto vectorType = dyn_cast<VectorType>(inputType))
return VectorType::get(vectorType.getShape(), elementalType);
diff --git a/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp b/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp
index 60db71d96547f..dcb0237070885 100644
--- a/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp
+++ b/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp
@@ -1284,7 +1284,7 @@ struct DirectConvertRewriter : public OpRewritePattern<ConvertOp> {
bool fromSparseConst = false;
if (auto constOp = op.getSource().getDefiningOp<arith::ConstantOp>())
- if (dyn_cast<SparseElementsAttr>(constOp.getValue()))
+ if (isa<SparseElementsAttr>(constOp.getValue()))
fromSparseConst = true;
const AffineMapAttr foreachOrder =
diff --git a/mlir/lib/Dialect/SparseTensor/Transforms/Utils/CodegenUtils.cpp b/mlir/lib/Dialect/SparseTensor/Transforms/Utils/CodegenUtils.cpp
index f92382472b478..0ebdc3a54e61b 100644
--- a/mlir/lib/Dialect/SparseTensor/Transforms/Utils/CodegenUtils.cpp
+++ b/mlir/lib/Dialect/SparseTensor/Transforms/Utils/CodegenUtils.cpp
@@ -211,7 +211,7 @@ Value mlir::sparse_tensor::genIsNonzero(OpBuilder &builder, mlir::Location loc,
if (tp.isIntOrIndex())
return builder.create<arith::CmpIOp>(loc, arith::CmpIPredicate::ne, v,
zero);
- if (dyn_cast<ComplexType>(tp))
+ if (isa<ComplexType>(tp))
return builder.create<complex::NotEqualOp>(loc, v, zero);
llvm_unreachable("Non-numeric type");
}
diff --git a/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp b/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp
index 47368532df169..142928d836546 100644
--- a/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp
+++ b/mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp
@@ -399,7 +399,7 @@ struct TransposeIsReshape : public OpRewritePattern<tosa::TransposeOp> {
Value result = op.getResult();
for (Operation *subop : result.getUsers()) {
- if (dyn_cast_or_null<tosa::TransposeOp>(subop))
+ if (isa_and_nonnull<tosa::TransposeOp>(subop))
return rewriter.notifyMatchFailure(
op, "Dest is used by transpose, can compose transposes");
}
diff --git a/mlir/lib/IR/Diagnostics.cpp b/mlir/lib/IR/Diagnostics.cpp
index 59d803035bda0..79697be2b45ea 100644
--- a/mlir/lib/IR/Diagnostics.cpp
+++ b/mlir/lib/IR/Diagnostics.cpp
@@ -392,11 +392,11 @@ struct SourceMgrDiagnosticHandlerImpl {
/// Return a processable CallSiteLoc from the given location.
static std::optional<CallSiteLoc> getCallSiteLoc(Location loc) {
- if (dyn_cast<NameLoc>(loc))
+ if (isa<NameLoc>(loc))
return getCallSiteLoc(cast<NameLoc>(loc).getChildLoc());
if (auto callLoc = dyn_cast<CallSiteLoc>(loc))
return callLoc;
- if (dyn_cast<FusedLoc>(loc)) {
+ if (isa<FusedLoc>(loc)) {
for (auto subLoc : cast<FusedLoc>(loc).getLocations()) {
if (auto callLoc = getCallSiteLoc(subLoc)) {
return callLoc;
diff --git a/mlir/lib/Target/LLVMIR/Dialect/NVVM/NVVMToLLVMIRTranslation.cpp b/mlir/lib/Target/LLVMIR/Dialect/NVVM/NVVMToLLVMIRTranslation.cpp
index 7dfe32...
[truncated]
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice cleanups!
Do we have clang-tidy checks for these? It would be nice for tooling to take care of all this.
There is a Static Analyzer checker, but I'm not exactly sure if it would catch this of the top of my head. I think the Static Analyzer is anyway overkill for checking this, probably an easy clang-tidy check would be better for looking for implicit conversions to bool of a CallExpr of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Also fix some typos in comments