Skip to content

Commit 8aaac80

Browse files
MaxGraeyjoker-eph
andauthored
[NFC] Use more isa and isa_and_nonnull instead dyn_cast for predicates (#137393)
Also fix some typos in comments --------- Co-authored-by: Mehdi Amini <[email protected]>
1 parent ac583df commit 8aaac80

File tree

26 files changed

+39
-40
lines changed

26 files changed

+39
-40
lines changed

clang/lib/Sema/SemaChecking.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10052,9 +10052,10 @@ void CheckFreeArgumentsAddressof(Sema &S, const std::string &CalleeName,
1005210052
const UnaryOperator *UnaryExpr) {
1005310053
if (const auto *Lvalue = dyn_cast<DeclRefExpr>(UnaryExpr->getSubExpr())) {
1005410054
const Decl *D = Lvalue->getDecl();
10055-
if (isa<DeclaratorDecl>(D))
10056-
if (!dyn_cast<DeclaratorDecl>(D)->getType()->isReferenceType())
10055+
if (auto *DD = dyn_cast<DeclaratorDecl>(D)) {
10056+
if (!DD->getType()->isReferenceType())
1005710057
return CheckFreeArgumentsOnLvalue(S, CalleeName, UnaryExpr, D);
10058+
}
1005810059
}
1005910060

1006010061
if (const auto *Lvalue = dyn_cast<MemberExpr>(UnaryExpr->getSubExpr()))

clang/lib/Sema/SemaModule.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,7 @@ static bool checkExportedDecl(Sema &S, Decl *D, SourceLocation BlockStart) {
942942
// HLSL: export declaration is valid only on functions
943943
if (S.getLangOpts().HLSL) {
944944
// Export-within-export was already diagnosed in ActOnStartExportDecl
945-
if (!dyn_cast<FunctionDecl>(D) && !dyn_cast<ExportDecl>(D)) {
945+
if (!isa<FunctionDecl, ExportDecl>(D)) {
946946
S.Diag(D->getBeginLoc(), diag::err_hlsl_export_not_on_function);
947947
D->setInvalidDecl();
948948
return false;

clang/lib/Sema/SemaOpenMP.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2307,7 +2307,7 @@ bool SemaOpenMP::isInOpenMPTargetExecutionDirective() const {
23072307

23082308
bool SemaOpenMP::isOpenMPRebuildMemberExpr(ValueDecl *D) {
23092309
// Only rebuild for Field.
2310-
if (!dyn_cast<FieldDecl>(D))
2310+
if (!isa<FieldDecl>(D))
23112311
return false;
23122312
DSAStackTy::DSAVarData DVarPrivate = DSAStack->hasDSA(
23132313
D,

clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLocalVarsChecker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ class RawPtrRefLocalVarsChecker
356356
SmallString<100> Buf;
357357
llvm::raw_svector_ostream Os(Buf);
358358

359-
if (dyn_cast<ParmVarDecl>(V)) {
359+
if (isa<ParmVarDecl>(V)) {
360360
Os << "Assignment to an " << ptrKind() << " parameter ";
361361
printQuotedQualifiedName(Os, V);
362362
Os << " is unsafe.";

lld/MachO/SymbolTable.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ static const Symbol *getAlternativeSpelling(const Undefined &sym,
518518

519519
// If in the symbol table and not undefined.
520520
if (const Symbol *s = symtab->find(newName))
521-
if (dyn_cast<Undefined>(s) == nullptr)
521+
if (!isa<Undefined>(s))
522522
return s;
523523

524524
return nullptr;
@@ -567,8 +567,7 @@ static const Symbol *getAlternativeSpelling(const Undefined &sym,
567567
if (name.equals_insensitive(it.first))
568568
return it.second;
569569
for (Symbol *sym : symtab->getSymbols())
570-
if (dyn_cast<Undefined>(sym) == nullptr &&
571-
name.equals_insensitive(sym->getName()))
570+
if (!isa<Undefined>(sym) && name.equals_insensitive(sym->getName()))
572571
return sym;
573572

574573
// The reference may be a mangled name while the definition is not. Suggest a

llvm/include/llvm/Analysis/LoopInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ class LoopInfo : public LoopInfoBase<BasicBlock, Loop> {
529529
}
530530

531531
// Return true if a new use of V added in ExitBB would require an LCSSA PHI
532-
// to be inserted at the begining of the block. Note that V is assumed to
532+
// to be inserted at the beginning of the block. Note that V is assumed to
533533
// dominate ExitBB, and ExitBB must be the exit block of some loop. The
534534
// IR is assumed to be in LCSSA form before the planned insertion.
535535
bool wouldBeOutOfLoopUseRequiringLCSSA(const Value *V,

llvm/lib/Bitcode/Reader/MetadataLoader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ class MetadataLoader::MetadataLoaderImpl {
558558
SetVector<Metadata *> EntitiesToRemove;
559559
for (Metadata *Op : CU->getImportedEntities()->operands()) {
560560
auto *IE = cast<DIImportedEntity>(Op);
561-
if (dyn_cast_or_null<DILocalScope>(IE->getScope())) {
561+
if (isa_and_nonnull<DILocalScope>(IE->getScope())) {
562562
EntitiesToRemove.insert(IE);
563563
}
564564
}

llvm/lib/IR/Verifier.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6584,7 +6584,7 @@ void Verifier::visitIntrinsicCall(Intrinsic::ID ID, CallBase &Call) {
65846584
for (BasicBlock *ColorFirstBB : CV)
65856585
if (auto It = ColorFirstBB->getFirstNonPHIIt();
65866586
It != ColorFirstBB->end())
6587-
if (dyn_cast_or_null<FuncletPadInst>(&*It))
6587+
if (isa_and_nonnull<FuncletPadInst>(&*It))
65886588
InEHFunclet = true;
65896589

65906590
// Check for funclet operand bundle

llvm/lib/Target/WebAssembly/WebAssemblyTargetTransformInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ bool WebAssemblyTTIImpl::isProfitableToSinkOperands(
294294

295295
Value *V = I->getOperand(1);
296296
// We dont need to sink constant splat.
297-
if (dyn_cast<Constant>(V))
297+
if (isa<Constant>(V))
298298
return false;
299299

300300
if (match(V, m_Shuffle(m_InsertElt(m_Value(), m_Value(), m_ZeroInt()),

mlir/lib/Conversion/LLVMCommon/TypeConverter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ LLVMTypeConverter::promoteOperands(Location loc, ValueRange opOperands,
755755
if (useBarePtrCallConv) {
756756
// For the bare-ptr calling convention, we only have to extract the
757757
// aligned pointer of a memref.
758-
if (dyn_cast<MemRefType>(operand.getType())) {
758+
if (isa<MemRefType>(operand.getType())) {
759759
MemRefDescriptor desc(llvmOperand);
760760
llvmOperand = desc.alignedPtr(builder, loc);
761761
} else if (isa<UnrankedMemRefType>(operand.getType())) {

mlir/lib/Conversion/MathToFuncs/MathToFuncs.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ static func::FuncOp createElementFPowIFunc(ModuleOp *module,
586586
LogicalResult
587587
FPowIOpLowering::matchAndRewrite(math::FPowIOp op,
588588
PatternRewriter &rewriter) const {
589-
if (dyn_cast<VectorType>(op.getType()))
589+
if (isa<VectorType>(op.getType()))
590590
return rewriter.notifyMatchFailure(op, "non-scalar operation");
591591

592592
FunctionType funcType = getElementalFuncTypeForOp(op);
@@ -751,7 +751,7 @@ static func::FuncOp createCtlzFunc(ModuleOp *module, Type elementType) {
751751
/// operation.
752752
LogicalResult CtlzOpLowering::matchAndRewrite(math::CountLeadingZerosOp op,
753753
PatternRewriter &rewriter) const {
754-
if (dyn_cast<VectorType>(op.getType()))
754+
if (isa<VectorType>(op.getType()))
755755
return rewriter.notifyMatchFailure(op, "non-scalar operation");
756756

757757
Type type = getElementTypeOrSelf(op.getResult().getType());

mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,7 @@ struct RankOpLowering : public ConvertOpToLLVMPattern<memref::RankOp> {
890890
ConversionPatternRewriter &rewriter) const override {
891891
Location loc = op.getLoc();
892892
Type operandType = op.getMemref().getType();
893-
if (dyn_cast<UnrankedMemRefType>(operandType)) {
893+
if (isa<UnrankedMemRefType>(operandType)) {
894894
UnrankedMemRefDescriptor desc(adaptor.getMemref());
895895
rewriter.replaceOp(op, {desc.rank(rewriter, loc)});
896896
return success();

mlir/lib/Dialect/AMDGPU/Transforms/TransferReadToLoad.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ static LogicalResult transferPreconditions(
6363
return rewriter.notifyMatchFailure(xferOp, "not a memref source");
6464

6565
Attribute addrSpace = memRefType.getMemorySpace();
66-
if (!addrSpace || !dyn_cast<amdgpu::AddressSpaceAttr>(addrSpace))
66+
if (!isa_and_nonnull<amdgpu::AddressSpaceAttr>(addrSpace))
6767
return rewriter.notifyMatchFailure(xferOp, "no address space");
6868

6969
if (dyn_cast<amdgpu::AddressSpaceAttr>(addrSpace).getValue() !=

mlir/lib/Dialect/Affine/IR/AffineOps.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2194,7 +2194,7 @@ static void printBound(AffineMapAttr boundMap,
21942194
// Print bound that consists of a single SSA symbol if the map is over a
21952195
// single symbol.
21962196
if (map.getNumDims() == 0 && map.getNumSymbols() == 1) {
2197-
if (dyn_cast<AffineSymbolExpr>(expr)) {
2197+
if (isa<AffineSymbolExpr>(expr)) {
21982198
p.printOperand(*boundOperands.begin());
21992199
return;
22002200
}

mlir/lib/Dialect/Arith/Utils/Utils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ static Value convertScalarToComplexDtype(ImplicitLocOpBuilder &b, Value operand,
205205
}
206206
}
207207

208-
if (dyn_cast<FloatType>(operand.getType())) {
208+
if (isa<FloatType>(operand.getType())) {
209209
FloatType toFpTy = cast<FloatType>(targetType.getElementType());
210210
auto toBitwidth = toFpTy.getIntOrFloatBitWidth();
211211
Value from = operand;
@@ -220,7 +220,7 @@ static Value convertScalarToComplexDtype(ImplicitLocOpBuilder &b, Value operand,
220220
return b.create<complex::CreateOp>(targetType, from, zero);
221221
}
222222

223-
if (dyn_cast<IntegerType>(operand.getType())) {
223+
if (isa<IntegerType>(operand.getType())) {
224224
FloatType toFpTy = cast<FloatType>(targetType.getElementType());
225225
Value from = operand;
226226
if (isUnsigned) {

mlir/lib/Dialect/Async/Transforms/AsyncRuntimeRefCounting.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -534,15 +534,15 @@ void AsyncRuntimePolicyBasedRefCountingPass::initializeDefaultPolicy() {
534534
bool isValue = isa<ValueType>(type);
535535

536536
// Drop reference after async token or group error check (coro await).
537-
if (dyn_cast<RuntimeIsErrorOp>(op))
537+
if (isa<RuntimeIsErrorOp>(op))
538538
return (isToken || isGroup) ? -1 : 0;
539539

540540
// Drop reference after async value load.
541-
if (dyn_cast<RuntimeLoadOp>(op))
541+
if (isa<RuntimeLoadOp>(op))
542542
return isValue ? -1 : 0;
543543

544544
// Drop reference after async token added to the group.
545-
if (dyn_cast<RuntimeAddToGroupOp>(op))
545+
if (isa<RuntimeAddToGroupOp>(op))
546546
return isToken ? -1 : 0;
547547

548548
return 0;

mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1296,7 +1296,7 @@ LogicalResult mlir::linalg::detail::verifyStructuredOpInterface(Operation *op) {
12961296
"unexpected result less than 0 at expression #")
12971297
<< dim << " in " << mapStr;
12981298
}
1299-
if (dyn_cast<AffineDimExpr>(indexingMap.getResult(dim))) {
1299+
if (isa<AffineDimExpr>(indexingMap.getResult(dim))) {
13001300
if (inferredDimSize != shape[dim]) {
13011301
return op->emitOpError("inferred input/output operand #")
13021302
<< opOperand.getOperandNumber() << " has shape's dimension #"

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,7 +1211,7 @@ DiagnosedSilenceableFailure transform::LinalgCopyToMemrefOp::applyToOne(
12111211
// linalg.copy supports different element types on source/dest whereas
12121212
// memref.copy does not, so we must check that the source and dest types can
12131213
// be handled by memref.copy and otherwise reject the transformation.
1214-
if (!dyn_cast<ShapedType>(input.getType())) {
1214+
if (!isa<ShapedType>(input.getType())) {
12151215
DiagnosedSilenceableFailure diag =
12161216
emitSilenceableError()
12171217
<< "cannot transform a linalg.copy which input has no shape";
@@ -1220,7 +1220,7 @@ DiagnosedSilenceableFailure transform::LinalgCopyToMemrefOp::applyToOne(
12201220
}
12211221

12221222
// linalg.copy destination must be a shaped type.
1223-
assert(dyn_cast<ShapedType>(output.getType()));
1223+
assert(isa<ShapedType>(output.getType()));
12241224

12251225
if (cast<ShapedType>(input.getType()).getElementType() !=
12261226
cast<ShapedType>(output.getType()).getElementType()) {

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,8 @@ struct LinalgDetensorize
317317
// * Add the argument to blockArgsToDetensor.
318318
// * Walk the use-def chain backwards to add each predecessor's
319319
// terminator-operands corresponding to currentItem to workList.
320-
if (dyn_cast<BlockArgument>(currentItem)) {
321-
BlockArgument currentItemBlockArgument =
322-
cast<BlockArgument>(currentItem);
320+
if (auto currentItemBlockArgument =
321+
dyn_cast<BlockArgument>(currentItem)) {
323322
Block *ownerBlock = currentItemBlockArgument.getOwner();
324323

325324
// Function arguments are not detensored/converted.
@@ -414,7 +413,7 @@ struct LinalgDetensorize
414413
Block *block = blockArg.getParentBlock();
415414

416415
// For the potentially detensorable block argument, find the
417-
// correpsonding operands in predecessor blocks.
416+
// corresponding operands in predecessor blocks.
418417
for (PredecessorIterator pred = block->pred_begin();
419418
pred != block->pred_end(); ++pred) {
420419
BranchOpInterface terminator =

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ struct FoldAffineOp : public RewritePattern {
303303
}
304304
return failure();
305305
}
306-
if (dyn_cast<AffineDimExpr>(expr) || dyn_cast<AffineSymbolExpr>(expr)) {
306+
if (isa<AffineDimExpr, AffineSymbolExpr>(expr)) {
307307
rewriter.replaceOp(op, op->getOperand(0));
308308
return success();
309309
}

mlir/lib/Dialect/Quant/Utils/UniformSupport.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Type ExpressedToQuantizedConverter::convert(QuantizedType elementalType) const {
3636
assert(expressedType && "convert() on unsupported conversion");
3737
if (auto tensorType = dyn_cast<RankedTensorType>(inputType))
3838
return RankedTensorType::get(tensorType.getShape(), elementalType);
39-
if (dyn_cast<UnrankedTensorType>(inputType))
39+
if (isa<UnrankedTensorType>(inputType))
4040
return UnrankedTensorType::get(elementalType);
4141
if (auto vectorType = dyn_cast<VectorType>(inputType))
4242
return VectorType::get(vectorType.getShape(), elementalType);

mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1284,7 +1284,7 @@ struct DirectConvertRewriter : public OpRewritePattern<ConvertOp> {
12841284

12851285
bool fromSparseConst = false;
12861286
if (auto constOp = op.getSource().getDefiningOp<arith::ConstantOp>())
1287-
if (dyn_cast<SparseElementsAttr>(constOp.getValue()))
1287+
if (isa<SparseElementsAttr>(constOp.getValue()))
12881288
fromSparseConst = true;
12891289

12901290
const AffineMapAttr foreachOrder =

mlir/lib/Dialect/SparseTensor/Transforms/Utils/CodegenUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ Value mlir::sparse_tensor::genIsNonzero(OpBuilder &builder, mlir::Location loc,
211211
if (tp.isIntOrIndex())
212212
return builder.create<arith::CmpIOp>(loc, arith::CmpIPredicate::ne, v,
213213
zero);
214-
if (dyn_cast<ComplexType>(tp))
214+
if (isa<ComplexType>(tp))
215215
return builder.create<complex::NotEqualOp>(loc, v, zero);
216216
llvm_unreachable("Non-numeric type");
217217
}

mlir/lib/Dialect/Tosa/IR/TosaCanonicalizations.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ struct TransposeIsReshape : public OpRewritePattern<tosa::TransposeOp> {
399399

400400
Value result = op.getResult();
401401
for (Operation *subop : result.getUsers()) {
402-
if (dyn_cast_or_null<tosa::TransposeOp>(subop))
402+
if (isa_and_nonnull<tosa::TransposeOp>(subop))
403403
return rewriter.notifyMatchFailure(
404404
op, "Dest is used by transpose, can compose transposes");
405405
}

mlir/lib/IR/Diagnostics.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,11 +392,11 @@ struct SourceMgrDiagnosticHandlerImpl {
392392

393393
/// Return a processable CallSiteLoc from the given location.
394394
static std::optional<CallSiteLoc> getCallSiteLoc(Location loc) {
395-
if (dyn_cast<NameLoc>(loc))
395+
if (isa<NameLoc>(loc))
396396
return getCallSiteLoc(cast<NameLoc>(loc).getChildLoc());
397397
if (auto callLoc = dyn_cast<CallSiteLoc>(loc))
398398
return callLoc;
399-
if (dyn_cast<FusedLoc>(loc)) {
399+
if (isa<FusedLoc>(loc)) {
400400
for (auto subLoc : cast<FusedLoc>(loc).getLocations()) {
401401
if (auto callLoc = getCallSiteLoc(subLoc)) {
402402
return callLoc;

mlir/lib/Target/LLVMIR/Dialect/NVVM/NVVMToLLVMIRTranslation.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,15 +344,15 @@ class NVVMDialectLLVMIRTranslationInterface
344344
llvm::Function *llvmFunc = moduleTranslation.lookupFunction(func.getName());
345345

346346
if (attribute.getName() == NVVM::NVVMDialect::getMaxntidAttrName()) {
347-
if (!dyn_cast<DenseI32ArrayAttr>(attribute.getValue()))
347+
if (!isa<DenseI32ArrayAttr>(attribute.getValue()))
348348
return failure();
349349
auto values = cast<DenseI32ArrayAttr>(attribute.getValue());
350350
const std::string attr = llvm::formatv(
351351
"{0:$[,]}", llvm::make_range(values.asArrayRef().begin(),
352352
values.asArrayRef().end()));
353353
llvmFunc->addFnAttr("nvvm.maxntid", attr);
354354
} else if (attribute.getName() == NVVM::NVVMDialect::getReqntidAttrName()) {
355-
if (!dyn_cast<DenseI32ArrayAttr>(attribute.getValue()))
355+
if (!isa<DenseI32ArrayAttr>(attribute.getValue()))
356356
return failure();
357357
auto values = cast<DenseI32ArrayAttr>(attribute.getValue());
358358
const std::string attr = llvm::formatv(
@@ -361,7 +361,7 @@ class NVVMDialectLLVMIRTranslationInterface
361361
llvmFunc->addFnAttr("nvvm.reqntid", attr);
362362
} else if (attribute.getName() ==
363363
NVVM::NVVMDialect::getClusterDimAttrName()) {
364-
if (!dyn_cast<DenseI32ArrayAttr>(attribute.getValue()))
364+
if (!isa<DenseI32ArrayAttr>(attribute.getValue()))
365365
return failure();
366366
auto values = cast<DenseI32ArrayAttr>(attribute.getValue());
367367
const std::string attr = llvm::formatv(

0 commit comments

Comments
 (0)