diff --git a/clang/lib/CIR/CodeGen/Address.h b/clang/lib/CIR/CodeGen/Address.h index 5f82dd6b7eff..adde82604548 100644 --- a/clang/lib/CIR/CodeGen/Address.h +++ b/clang/lib/CIR/CodeGen/Address.h @@ -179,6 +179,10 @@ class Address { return nullptr; return getPointer().getDefiningOp(); } + + template T getDefiningOp() const { + return mlir::dyn_cast_or_null(getDefiningOp()); + } }; } // namespace clang::CIRGen diff --git a/clang/lib/CIR/CodeGen/CIRGenDecl.cpp b/clang/lib/CIR/CodeGen/CIRGenDecl.cpp index bd999c077640..eec7a1211739 100644 --- a/clang/lib/CIR/CodeGen/CIRGenDecl.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenDecl.cpp @@ -331,7 +331,7 @@ void CIRGenFunction::emitAutoVarInit(const AutoVarEmission &emission) { // out of it while trying to build the expression, mark it as such. auto addr = lv.getAddress().getPointer(); assert(addr && "Should have an address"); - auto allocaOp = dyn_cast_or_null(addr.getDefiningOp()); + auto allocaOp = addr.getDefiningOp(); assert(allocaOp && "Address should come straight out of the alloca"); if (!allocaOp.use_empty()) @@ -617,7 +617,7 @@ void CIRGenFunction::emitStaticVarDecl(const VarDecl &D, // TODO(cir): we should have a way to represent global ops as values without // having to emit a get global op. Sometimes these emissions are not used. auto addr = getBuilder().createGetGlobal(globalOp); - auto getAddrOp = mlir::cast(addr.getDefiningOp()); + auto getAddrOp = addr.getDefiningOp(); CharUnits alignment = getContext().getDeclAlign(&D); diff --git a/clang/lib/CIR/CodeGen/CIRGenExpr.cpp b/clang/lib/CIR/CodeGen/CIRGenExpr.cpp index 883b60e31895..0abd55488f70 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExpr.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExpr.cpp @@ -652,8 +652,7 @@ void CIRGenFunction::emitStoreOfScalar(mlir::Value value, Address addr, // Update the alloca with more info on initialization. assert(addr.getPointer() && "expected pointer to exist"); - auto SrcAlloca = - dyn_cast_or_null(addr.getPointer().getDefiningOp()); + auto SrcAlloca = addr.getDefiningOp(); if (currVarDecl && SrcAlloca) { const VarDecl *VD = currVarDecl; assert(VD && "VarDecl expected"); @@ -1328,8 +1327,7 @@ LValue CIRGenFunction::emitUnaryOpLValue(const UnaryOperator *E) { emitPointerWithAlignment(E->getSubExpr(), &BaseInfo, &TBAAInfo); // Tag 'load' with deref attribute. - if (auto loadOp = - dyn_cast(Addr.getPointer().getDefiningOp())) { + if (auto loadOp = Addr.getDefiningOp()) { loadOp.setIsDerefAttr(mlir::UnitAttr::get(&getMLIRContext())); } @@ -2221,8 +2219,7 @@ static Address createReferenceTemporary(CIRGenFunction &CGF, if (const clang::ValueDecl *extDecl = M->getExtendingDecl()) { auto extDeclAddrIter = CGF.LocalDeclMap.find(extDecl); if (extDeclAddrIter != CGF.LocalDeclMap.end()) { - extDeclAlloca = dyn_cast_if_present( - extDeclAddrIter->second.getDefiningOp()); + extDeclAlloca = extDeclAddrIter->second.getDefiningOp(); } } mlir::OpBuilder::InsertPoint ip; @@ -2337,7 +2334,7 @@ LValue CIRGenFunction::emitMaterializeTemporaryExpr( Address Alloca = Address::invalid(); Address Object = createReferenceTemporary(*this, M, E, &Alloca); - if (auto Var = dyn_cast(Object.getPointer().getDefiningOp())) { + if (auto Var = Object.getDefiningOp()) { // TODO(cir): add something akin to stripPointerCasts() to ptr above assert(0 && "NYI"); } else { @@ -2867,7 +2864,7 @@ mlir::Value CIRGenFunction::emitAlloca(StringRef name, mlir::Type ty, addr = builder.createAlloca(loc, /*addr type*/ localVarPtrTy, /*var type*/ ty, name, alignIntAttr, arraySize); if (currVarDecl) { - auto alloca = cast(addr.getDefiningOp()); + auto alloca = addr.getDefiningOp(); alloca.setAstAttr(ASTVarDeclAttr::get(&getMLIRContext(), currVarDecl)); } } @@ -3097,9 +3094,9 @@ cir::AllocaOp CIRGenFunction::CreateTempAlloca(mlir::Type Ty, const Twine &Name, mlir::Value ArraySize, bool insertIntoFnEntryBlock) { - return cast(emitAlloca(Name.str(), Ty, Loc, CharUnits(), - insertIntoFnEntryBlock, ArraySize) - .getDefiningOp()); + return emitAlloca(Name.str(), Ty, Loc, CharUnits(), insertIntoFnEntryBlock, + ArraySize) + .getDefiningOp(); } /// This creates an alloca and inserts it into the provided insertion point @@ -3109,9 +3106,8 @@ cir::AllocaOp CIRGenFunction::CreateTempAlloca(mlir::Type Ty, mlir::OpBuilder::InsertPoint ip, mlir::Value ArraySize) { assert(ip.isSet() && "Insertion point is not set"); - return cast( - emitAlloca(Name.str(), Ty, Loc, CharUnits(), ip, ArraySize) - .getDefiningOp()); + return emitAlloca(Name.str(), Ty, Loc, CharUnits(), ip, ArraySize) + .getDefiningOp(); } /// Just like CreateTempAlloca above, but place the alloca into the function diff --git a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp index 48d9c032b5a2..24dd900aafcd 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp @@ -370,7 +370,7 @@ class ScalarExprEmitter : public StmtVisitor { // direclty in the parent scope removing the need to hoist it. assert(retAlloca.getDefiningOp() && "expected a alloca op"); CGF.getBuilder().hoistAllocaToParentRegion( - cast(retAlloca.getDefiningOp())); + retAlloca.getDefiningOp()); return CGF.emitLoadOfScalar(CGF.makeAddrLValue(retAlloca, E->getType()), E->getExprLoc()); diff --git a/clang/lib/CIR/CodeGen/CIRGenFunction.cpp b/clang/lib/CIR/CodeGen/CIRGenFunction.cpp index da11937e2417..aa4993af48c6 100644 --- a/clang/lib/CIR/CodeGen/CIRGenFunction.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenFunction.cpp @@ -293,7 +293,7 @@ mlir::LogicalResult CIRGenFunction::declare(const Decl *var, QualType ty, assert(!symbolTable.count(var) && "not supposed to be available just yet"); addr = emitAlloca(namedVar->getName(), ty, loc, alignment); - auto allocaOp = cast(addr.getDefiningOp()); + auto allocaOp = addr.getDefiningOp(); if (isParam) allocaOp.setInitAttr(mlir::UnitAttr::get(&getMLIRContext())); if (ty->isReferenceType() || ty.isConstQualified()) @@ -313,7 +313,7 @@ mlir::LogicalResult CIRGenFunction::declare(Address addr, const Decl *var, assert(!symbolTable.count(var) && "not supposed to be available just yet"); addrVal = addr.getPointer(); - auto allocaOp = cast(addrVal.getDefiningOp()); + auto allocaOp = addrVal.getDefiningOp(); if (isParam) allocaOp.setInitAttr(mlir::UnitAttr::get(&getMLIRContext())); if (ty->isReferenceType() || ty.isConstQualified()) @@ -1986,7 +1986,7 @@ void CIRGenFunction::emitVarAnnotations(const VarDecl *decl, mlir::Value val) { for (const auto *annot : decl->specific_attrs()) { annotations.push_back(CGM.emitAnnotateAttr(annot)); } - auto allocaOp = dyn_cast_or_null(val.getDefiningOp()); + auto allocaOp = val.getDefiningOp(); assert(allocaOp && "expects available alloca"); allocaOp.setAnnotationsAttr(builder.getArrayAttr(annotations)); } diff --git a/clang/lib/CIR/CodeGen/CIRGenFunction.h b/clang/lib/CIR/CodeGen/CIRGenFunction.h index 1622555e0c4a..d49cf2eeeba3 100644 --- a/clang/lib/CIR/CodeGen/CIRGenFunction.h +++ b/clang/lib/CIR/CodeGen/CIRGenFunction.h @@ -2653,10 +2653,10 @@ inline mlir::Value DominatingCIRValue::restore(CIRGenFunction &CGF, return value.getPointer(); // Otherwise, it should be an alloca instruction, as set up in save(). - auto alloca = mlir::cast(value.getPointer().getDefiningOp()); + auto alloca = value.getPointer().getDefiningOp(); mlir::Value val = CGF.getBuilder().createAlignedLoad( alloca.getLoc(), alloca.getType(), alloca); - cir::LoadOp loadOp = mlir::cast(val.getDefiningOp()); + cir::LoadOp loadOp = val.getDefiningOp(); loadOp.setAlignment(alloca.getAlignment()); return val; } diff --git a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp index a127aac0c3cc..ce4ff5dbb1d3 100644 --- a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp +++ b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp @@ -778,7 +778,7 @@ Value tryFoldCastChain(cir::CastOp op) { if (!isIntOrBoolCast(op)) break; head = op; - op = dyn_cast_or_null(head.getSrc().getDefiningOp()); + op = head.getSrc().getDefiningOp(); } if (head == tail) @@ -841,7 +841,7 @@ static bool isBoolNot(cir::UnaryOp op) { // and the argument of the first one (%0) will be used instead. OpFoldResult cir::UnaryOp::fold(FoldAdaptor adaptor) { if (isBoolNot(*this)) - if (auto previous = dyn_cast_or_null(getInput().getDefiningOp())) + if (auto previous = getInput().getDefiningOp()) if (isBoolNot(previous)) return previous.getInput(); diff --git a/clang/lib/CIR/Dialect/Transforms/LibOpt.cpp b/clang/lib/CIR/Dialect/Transforms/LibOpt.cpp index c6e8bcac378e..ebc128c8a421 100644 --- a/clang/lib/CIR/Dialect/Transforms/LibOpt.cpp +++ b/clang/lib/CIR/Dialect/Transforms/LibOpt.cpp @@ -172,8 +172,8 @@ void LibOptPass::xformStdFindIntoMemchr(StdFindOp findOp) { // Build memchr op: // void *memchr(const void *s, int c, size_t n); auto memChr = [&] { - if (auto iterBegin = dyn_cast(first.getDefiningOp()); - iterBegin && isa(last.getDefiningOp())) { + if (auto iterBegin = first.getDefiningOp(); + iterBegin && last.getDefiningOp()) { // Both operands have the same type, use iterBegin. // Look at this pointer to retrieve container information. diff --git a/clang/lib/CIR/Dialect/Transforms/LifetimeCheck.cpp b/clang/lib/CIR/Dialect/Transforms/LifetimeCheck.cpp index cc83ec639bdf..0d7c7482d147 100644 --- a/clang/lib/CIR/Dialect/Transforms/LifetimeCheck.cpp +++ b/clang/lib/CIR/Dialect/Transforms/LifetimeCheck.cpp @@ -477,7 +477,7 @@ static std::string getVarNameFromValue(mlir::Value v) { if (auto allocaOp = dyn_cast(srcOp)) return allocaOp.getName().str(); if (auto getElemOp = dyn_cast(srcOp)) { - auto parent = dyn_cast(getElemOp.getAddr().getDefiningOp()); + auto parent = getElemOp.getAddr().getDefiningOp(); if (parent) { llvm::SmallString<128> finalName; llvm::raw_svector_ostream Out(finalName); @@ -760,9 +760,9 @@ void LifetimeCheckPass::checkReturn(ReturnOp retOp) { // The return value is loaded from the return slot before // returning. - auto loadOp = dyn_cast(retOp.getOperand(0).getDefiningOp()); + auto loadOp = retOp.getOperand(0).getDefiningOp(); assert(loadOp && "expected cir.load"); - if (!isa(loadOp.getAddr().getDefiningOp())) + if (!loadOp.getAddr().getDefiningOp()) return; // Keep track of interesting lambda. @@ -1083,10 +1083,10 @@ void LifetimeCheckPass::checkCoroTaskStore(StoreOp storeOp) { // Bind values that are coming from alloca's (like %arg0 above) to the // pset of %task - this effectively leads to some invalidation of %task // when %arg0 finishes its lifetime at the end of the enclosing cir.scope. - if (auto call = dyn_cast(taskTmp.getDefiningOp())) { + if (auto call = taskTmp.getDefiningOp()) { bool potentialTaintedTask = false; for (auto arg : call.getArgOperands()) { - auto alloca = dyn_cast(arg.getDefiningOp()); + auto alloca = arg.getDefiningOp(); if (alloca && currScope->localValues.count(alloca)) { getPmap()[taskAddr].insert(State::getLocalValue(alloca)); potentialTaintedTask = true; @@ -1103,11 +1103,11 @@ void LifetimeCheckPass::checkCoroTaskStore(StoreOp storeOp) { } mlir::Value LifetimeCheckPass::getLambdaFromMemberAccess(mlir::Value addr) { - auto op = addr.getDefiningOp(); // FIXME: we likely want to consider more indirections here... - if (!isa(op)) + auto op = addr.getDefiningOp(); + if (!op) return nullptr; - auto allocaOp = dyn_cast(op->getOperand(0).getDefiningOp()); + auto allocaOp = op->getOperand(0).getDefiningOp(); if (!allocaOp || !isLambdaType(allocaOp.getAllocaType())) return nullptr; return allocaOp; @@ -1117,7 +1117,7 @@ void LifetimeCheckPass::checkLambdaCaptureStore(StoreOp storeOp) { auto localByRefAddr = storeOp.getValue(); auto lambdaCaptureAddr = storeOp.getAddr(); - if (!isa_and_nonnull(localByRefAddr.getDefiningOp())) + if (!localByRefAddr.getDefiningOp()) return; auto lambdaAddr = getLambdaFromMemberAccess(lambdaCaptureAddr); if (!lambdaAddr) @@ -1178,7 +1178,7 @@ void LifetimeCheckPass::updatePointsTo(mlir::Value addr, mlir::Value data, mlir::Location loc) { auto getArrayFromSubscript = [&](PtrStrideOp strideOp) -> mlir::Value { - auto castOp = dyn_cast(strideOp.getBase().getDefiningOp()); + auto castOp = strideOp.getBase().getDefiningOp(); if (!castOp) return {}; if (castOp.getKind() != cir::CastKind::array_to_ptrdecay) @@ -1284,11 +1284,11 @@ void LifetimeCheckPass::checkStore(StoreOp storeOp) { // Decompose store's to aggregates into multiple updates to individual fields. if (aggregates.count(addr)) { auto data = storeOp.getValue(); - auto dataSrcOp = data.getDefiningOp(); - // Only interested in updating and tracking fields, anything besides - // constants isn't really relevant. - if (dataSrcOp && isa(dataSrcOp)) + if (data.getDefiningOp()) { + // Only interested in updating and tracking fields, anything besides + // constants isn't really relevant. updatePointsTo(addr, data, data.getLoc()); + } return; } @@ -1343,7 +1343,7 @@ void LifetimeCheckPass::emitInvalidHistory(mlir::InFlightDiagnostic &D, case InvalidStyle::EndOfScope: { if (tasks.count(histKey)) { llvm::StringRef resource = "resource"; - if (auto allocaOp = dyn_cast(info.val->getDefiningOp())) { + if (auto allocaOp = info.val->getDefiningOp()) { if (isLambdaType(allocaOp.getAllocaType())) resource = "lambda"; } @@ -1419,7 +1419,7 @@ void LifetimeCheckPass::checkPointerDeref(mlir::Value addr, mlir::Location loc, D << "returned lambda captures local variable"; else if (derefStyle == DerefStyle::CallParam || derefStyle == DerefStyle::IndirectCallParam) { - bool isAgg = isa_and_nonnull(addr.getDefiningOp()); + bool isAgg = addr.getDefiningOp(); D << "passing "; if (!isAgg) D << "invalid pointer"; @@ -1464,7 +1464,7 @@ mlir::Value LifetimeCheckPass::getThisParamPointerCategory(CallOp callOp) { auto thisptr = callOp.getArgOperand(0); if (ptrs.count(thisptr)) return thisptr; - if (auto loadOp = dyn_cast_or_null(thisptr.getDefiningOp())) { + if (auto loadOp = thisptr.getDefiningOp()) { if (ptrs.count(loadOp.getAddr())) return loadOp.getAddr(); } @@ -1476,7 +1476,7 @@ mlir::Value LifetimeCheckPass::getThisParamOwnerCategory(CallOp callOp) { auto thisptr = callOp.getArgOperand(0); if (owners.count(thisptr)) return thisptr; - if (auto loadOp = dyn_cast_or_null(thisptr.getDefiningOp())) { + if (auto loadOp = thisptr.getDefiningOp()) { if (owners.count(loadOp.getAddr())) return loadOp.getAddr(); } @@ -1580,7 +1580,7 @@ void LifetimeCheckPass::checkCtor(CallOp callOp, cir::CXXCtorAttr ctor) { // Not interested in block/function arguments or any indirect // provided alloca address. - if (!dyn_cast_or_null(addr.getDefiningOp())) + if (!addr.getDefiningOp()) return; markPsetNull(addr, callOp.getLoc()); diff --git a/clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp b/clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp index 54f3a96cdfa2..38012ec5e795 100644 --- a/clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp +++ b/clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp @@ -1412,7 +1412,7 @@ static std::string getGlobalVarNameForConstString(cir::StoreOp op, Out << "module."; } - auto allocaOp = dyn_cast_or_null(op.getAddr().getDefiningOp()); + auto allocaOp = op.getAddr().getDefiningOp(); if (allocaOp && !allocaOp.getName().empty()) Out << allocaOp.getName(); else diff --git a/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerFunction.cpp b/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerFunction.cpp index 32f660024125..49f17df27491 100644 --- a/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerFunction.cpp +++ b/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerFunction.cpp @@ -45,7 +45,7 @@ mlir::Value createCoercedBitcast(mlir::Value Src, mlir::Type DestTy, LowerFunction &CGF) { auto destPtrTy = cir::PointerType::get(DestTy); - if (auto load = mlir::dyn_cast(Src.getDefiningOp())) + if (auto load = Src.getDefiningOp()) return CGF.getRewriter().create(Src.getLoc(), destPtrTy, CastKind::bitcast, load.getAddr()); @@ -89,7 +89,7 @@ mlir::Value enterRecordPointerForCoercedAccess(mlir::Value SrcPtr, auto ptrTy = PointerType::get(FirstElt); if (mlir::isa(SrcPtr.getType())) { auto addr = SrcPtr; - if (auto load = mlir::dyn_cast(SrcPtr.getDefiningOp())) + if (auto load = SrcPtr.getDefiningOp()) addr = load.getAddr(); cir_cconv_assert(mlir::isa(addr.getType())); // we can not use getMemberOp here since we need a pointer to the first @@ -369,11 +369,11 @@ mlir::Value emitAddressAtOffset(LowerFunction &LF, mlir::Value addr, /// a non fundamental integer type mlir::Value createCoercedNonFundamental(mlir::Value src, mlir::Type ty, LowerFunction &LF) { - if (auto load = mlir::dyn_cast(src.getDefiningOp())) { + if (auto load = src.getDefiningOp()) { auto &bld = LF.getRewriter(); auto addr = load.getAddr(); - auto oldAlloca = mlir::dyn_cast(addr.getDefiningOp()); + auto oldAlloca = addr.getDefiningOp(); auto alloca = bld.create( src.getLoc(), cir::PointerType::get(ty), ty, /*name=*/llvm::StringRef(""), oldAlloca.getAlignmentAttr()); @@ -751,7 +751,7 @@ LowerFunction::buildFunctionEpilog(const LowerFunctionInfo &FI) { auto retInputs = ret.getInput(); assert(retInputs.size() == 1 && "return should only have one input"); - if (auto load = mlir::dyn_cast(retInputs[0].getDefiningOp())) + if (auto load = retInputs[0].getDefiningOp()) if (load.getResult().use_empty()) rewriter.eraseOp(load); diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp index d094e323cf8f..3cd648b35d5c 100644 --- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp +++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp @@ -968,8 +968,8 @@ static mlir::Value promoteIndex(mlir::ConversionPatternRewriter &rewriter, bool rewriteSub = false; auto sub = mlir::dyn_cast(indexOp); if (sub) { - if (auto lhsConst = dyn_cast( - sub.getOperand(0).getDefiningOp())) { + if (auto lhsConst = + sub.getOperand(0).getDefiningOp()) { auto lhsConstInt = mlir::dyn_cast(lhsConst.getValue()); if (lhsConstInt && lhsConstInt.getValue() == 0) { rewriteSub = true; @@ -1220,14 +1220,12 @@ mlir::LogicalResult CIRToLLVMBrCondOpLowering::matchAndRewrite( if (auto defOp = brOp.getCond().getDefiningOp()) hasOneUse = defOp->getResult(0).hasOneUse(); - if (auto defOp = adaptor.getCond().getDefiningOp()) { - if (auto zext = dyn_cast(defOp)) { - if (zext->use_empty() && - zext->getOperand(0).getType() == rewriter.getI1Type()) { - i1Condition = zext->getOperand(0); - if (hasOneUse) - rewriter.eraseOp(zext); - } + if (auto zext = adaptor.getCond().getDefiningOp()) { + if (zext->use_empty() && + zext->getOperand(0).getType() == rewriter.getI1Type()) { + i1Condition = zext->getOperand(0); + if (hasOneUse) + rewriter.eraseOp(zext); } } @@ -1773,10 +1771,9 @@ getLLVMMemOrder(std::optional &memorder) { } static bool isLoadOrStoreInvariant(mlir::Value addr) { - if (auto addrAllocaOp = - mlir::dyn_cast_if_present(addr.getDefiningOp())) + if (auto addrAllocaOp = addr.getDefiningOp()) return addrAllocaOp.getConstant(); - if (mlir::isa_and_present(addr.getDefiningOp())) + if (addr.getDefiningOp()) return true; return false; } @@ -2087,7 +2084,7 @@ mlir::LogicalResult CIRToLLVMVecSplatOpLowering::matchAndRewrite( mlir::Value indexValue = rewriter.create(loc, rewriter.getI64Type(), 0); mlir::Value elementValue = adaptor.getValue(); - if (mlir::isa(elementValue.getDefiningOp())) { + if (elementValue.getDefiningOp()) { // If the splat value is poison, then we can just use poison value // for the entire vector. rewriter.replaceOp(op, poison); diff --git a/clang/lib/CIR/Lowering/ThroughMLIR/LowerCIRLoopToSCF.cpp b/clang/lib/CIR/Lowering/ThroughMLIR/LowerCIRLoopToSCF.cpp index 1b826dfa7a36..52e9adb75ba0 100644 --- a/clang/lib/CIR/Lowering/ThroughMLIR/LowerCIRLoopToSCF.cpp +++ b/clang/lib/CIR/Lowering/ThroughMLIR/LowerCIRLoopToSCF.cpp @@ -149,8 +149,8 @@ mlir::LogicalResult SCFLoop::findStepAndIV() { return mlir::failure(); mlir::Value value = binary.getRhs(); - if (auto constValue = dyn_cast(value.getDefiningOp()); - isa(constValue.getValue())) + if (auto constValue = value.getDefiningOp(); + constValue.getValueAttr()) step = getConstant(constValue); if (binary.getKind() == BinOpKind::Add) diff --git a/clang/lib/CIR/Lowering/ThroughMLIR/LowerCIRToMLIR.cpp b/clang/lib/CIR/Lowering/ThroughMLIR/LowerCIRToMLIR.cpp index 1a3cb5db1fa4..b40293ce7417 100644 --- a/clang/lib/CIR/Lowering/ThroughMLIR/LowerCIRToMLIR.cpp +++ b/clang/lib/CIR/Lowering/ThroughMLIR/LowerCIRToMLIR.cpp @@ -138,11 +138,11 @@ class CIRCallOpLowering : public mlir::OpConversionPattern { // %global = memref.get_global %frm_str // %* = memref.reinterpret_cast (%global, 0) if (auto reinterpret_castOP = - mlir::dyn_cast_or_null( - adaptor.getOperands()[0].getDefiningOp())) { + adaptor.getOperands()[0] + .getDefiningOp()) { if (auto getGlobalOp = - mlir::dyn_cast_or_null( - reinterpret_castOP->getOperand(0).getDefiningOp())) { + reinterpret_castOP->getOperand(0) + .getDefiningOp()) { mlir::ModuleOp parentModule = op->getParentOfType(); auto context = rewriter.getContext(); @@ -310,9 +310,8 @@ static bool findBaseAndIndices(mlir::Value addr, mlir::Value &base, SmallVector &indices, SmallVector &eraseList, mlir::ConversionPatternRewriter &rewriter) { - while (mlir::Operation *addrOp = addr.getDefiningOp()) { - if (!isa(addrOp)) - break; + while (mlir::Operation *addrOp = + addr.getDefiningOp()) { indices.push_back(addrOp->getOperand(1)); addr = addrOp->getOperand(0); eraseList.push_back(addrOp); @@ -1392,10 +1391,7 @@ class CIRPtrStrideOpLowering // Return true if PtrStrideOp is produced by cast with array_to_ptrdecay kind // and they are in the same block. inline bool isCastArrayToPtrConsumer(cir::PtrStrideOp op) const { - auto defOp = op->getOperand(0).getDefiningOp(); - if (!defOp) - return false; - auto castOp = dyn_cast(defOp); + auto castOp = op->getOperand(0).getDefiningOp(); if (!castOp) return false; if (castOp.getKind() != cir::CastKind::array_to_ptrdecay) @@ -1445,11 +1441,10 @@ class CIRPtrStrideOpLowering return mlir::failure(); if (!isLoadStoreOrCastArrayToPtrProduer(op)) return mlir::failure(); - auto baseOp = adaptor.getBase().getDefiningOp(); + auto baseOp = + adaptor.getBase().getDefiningOp(); if (!baseOp) return mlir::failure(); - if (!isa(baseOp)) - return mlir::failure(); auto base = baseOp->getOperand(0); auto dstType = op.getType(); auto newDstType = mlir::cast(convertTy(dstType));