From 49f9cffbc13ac775859efe2ae1d518e19e08db02 Mon Sep 17 00:00:00 2001 From: Jeremy Kun Date: Tue, 2 Apr 2024 20:59:36 -0700 Subject: [PATCH 1/4] Migrate method dyn_cast to llvm::dyn_cast ```bash perl -i -pe 's/([^ ]*)\.dyn_cast<([^>]*)>\(\)/llvm::dyn_cast<\2>(\1)/g' **/*.cpp **/*.h **/*.cc ``` --- lib/polygeist/Ops.cpp | 56 +++-- lib/polygeist/Passes/AffineCFG.cpp | 8 +- lib/polygeist/Passes/CanonicalizeFor.cpp | 28 +-- .../Passes/CollectKernelStatistics.cpp | 4 +- lib/polygeist/Passes/ConvertParallelToGPU.cpp | 8 +- .../Passes/ConvertPolygeistToLLVM.cpp | 16 +- lib/polygeist/Passes/ConvertToOpaquePtr.cpp | 17 +- lib/polygeist/Passes/ForBreakToWhile.cpp | 10 +- lib/polygeist/Passes/ParallelLICM.cpp | 4 +- .../Passes/ParallelLoopDistribute.cpp | 10 +- lib/polygeist/Passes/ParallelLoopUnroll.cpp | 2 +- lib/polygeist/Passes/ParallelLower.cpp | 18 +- lib/polygeist/Passes/PolygeistMem2Reg.cpp | 16 +- tools/cgeist/Lib/CGCall.cc | 42 ++-- tools/cgeist/Lib/CGStmt.cc | 16 +- tools/cgeist/Lib/ValueCategory.cc | 31 ++- tools/cgeist/Lib/clang-mlir.cc | 216 +++++++++--------- .../Target/OpenScop/ConvertFromOpenScop.cc | 2 +- tools/polymer/lib/Transforms/LoopAnnotate.cc | 2 +- tools/polymer/lib/Transforms/LoopExtract.cc | 2 +- .../polymer/lib/Transforms/PlutoTransform.cc | 2 +- tools/polymer/lib/Transforms/Reg2Mem.cc | 2 +- tools/polymer/lib/Transforms/ScopStmtOpt.cc | 2 +- 23 files changed, 255 insertions(+), 259 deletions(-) diff --git a/lib/polygeist/Ops.cpp b/lib/polygeist/Ops.cpp index af6a2059ace3..f73cb8ba9ff1 100644 --- a/lib/polygeist/Ops.cpp +++ b/lib/polygeist/Ops.cpp @@ -1631,9 +1631,9 @@ class CopySimplification final : public OpRewritePattern { Type elTy = dstTy.getElementType(); size_t width = 1; - if (auto IT = elTy.dyn_cast()) + if (auto IT = llvm::dyn_cast(elTy)) width = IT.getWidth() / 8; - else if (auto FT = elTy.dyn_cast()) + else if (auto FT = llvm::dyn_cast(elTy)) width = FT.getWidth() / 8; else { // TODO extend to llvm compatible type @@ -1734,9 +1734,9 @@ class SetSimplification final : public OpRewritePattern { return failure(); size_t width = 1; - if (auto IT = elTy.dyn_cast()) + if (auto IT = llvm::dyn_cast(elTy)) width = IT.getWidth() / 8; - else if (auto FT = elTy.dyn_cast()) + else if (auto FT = llvm::dyn_cast(elTy)) width = FT.getWidth() / 8; else { // TODO extend to llvm compatible type @@ -1787,7 +1787,7 @@ class SetSimplification final : public OpRewritePattern { SmallVector idxs; Value val; - if (auto IT = elTy.dyn_cast()) + if (auto IT = llvm::dyn_cast(elTy)) val = rewriter.create(op.getLoc(), 0, IT.getWidth()); else { @@ -2479,7 +2479,7 @@ class SelectOfExt final : public OpRewritePattern { LogicalResult matchAndRewrite(arith::SelectOp op, PatternRewriter &rewriter) const override { - auto ty = op.getType().dyn_cast(); + auto ty = llvm::dyn_cast(op.getType()); if (!ty) return failure(); IntegerAttr lhs, rhs; @@ -2589,10 +2589,10 @@ class CmpProp final : public OpRewritePattern { v.getDefiningOp() || v.getDefiningOp(); if (auto extOp = v.getDefiningOp()) - if (auto it = extOp.getIn().getType().dyn_cast()) + if (auto it = llvm::dyn_cast(extOp.getIn().getType())) change |= it.getWidth() == 1; if (auto extOp = v.getDefiningOp()) - if (auto it = extOp.getIn().getType().dyn_cast()) + if (auto it = llvm::dyn_cast(extOp.getIn().getType())) change |= it.getWidth() == 1; } if (!change) { @@ -3175,7 +3175,7 @@ bool valueCmp(Cmp cmp, Value bval, ValueOrInt val) { } } - if (auto baval = bval.dyn_cast()) { + if (auto baval = llvm::dyn_cast(bval)) { if (affine::AffineForOp afFor = dyn_cast(baval.getOwner()->getParentOp())) { auto for_lb = afFor.getLowerBoundMap().getResults()[baval.getArgNumber()]; @@ -3487,7 +3487,7 @@ bool valueCmp(Cmp cmp, AffineExpr expr, size_t numDim, ValueRange operands, // Range is [lb, ub) bool rangeIncludes(Value bval, ValueOrInt lb, ValueOrInt ub) { - if (auto baval = bval.dyn_cast()) { + if (auto baval = llvm::dyn_cast(bval)) { if (affine::AffineForOp afFor = dyn_cast(baval.getOwner()->getParentOp())) { return valueCmp( @@ -3621,7 +3621,7 @@ struct AffineIfSinking : public OpRewritePattern { if (!opd) { return failure(); } - auto ival = op.getOperands()[opd.getPosition()].dyn_cast(); + auto ival = llvm::dyn_cast(op.getOperands()[opd.getPosition()]); if (!ival) { return failure(); } @@ -3663,7 +3663,7 @@ struct AffineIfSinking : public OpRewritePattern { if (!par.getRegion().isAncestor(v.getParentRegion()) || op.getThenRegion().isAncestor(v.getParentRegion())) return; - if (auto ba = v.dyn_cast()) { + if (auto ba = llvm::dyn_cast(v)) { if (ba.getOwner()->getParentOp() == par) { return; } @@ -4285,7 +4285,7 @@ struct MergeNestedAffineParallelIf continue; } if (auto dim = cur.dyn_cast()) { - auto ival = operands[dim.getPosition()].dyn_cast(); + auto ival = llvm::dyn_cast(operands[dim.getPosition()]); if (!ival || ival.getOwner()->getParentOp() != op) { rhs = rhs + dim; if (failure) @@ -4315,7 +4315,7 @@ struct MergeNestedAffineParallelIf if (auto dim = bop.getLHS().dyn_cast()) { auto ival = - operands[dim.getPosition()].dyn_cast(); + llvm::dyn_cast(operands[dim.getPosition()]); if (!ival || ival.getOwner()->getParentOp() != op) { rhs = rhs + bop; // While legal, this may run before parallel merging @@ -4511,7 +4511,7 @@ struct MergeParallelInductions continue; } if (auto dim = cur.dyn_cast()) { - auto ival = operands[dim.getPosition()].dyn_cast(); + auto ival = llvm::dyn_cast(operands[dim.getPosition()]); if (!ival || ival.getOwner()->getParentOp() != op) { rhs = rhs + dim; continue; @@ -4538,7 +4538,7 @@ struct MergeParallelInductions } if (auto dim = bop.getLHS().dyn_cast()) { - auto ival = operands[dim.getPosition()].dyn_cast(); + auto ival = llvm::dyn_cast(operands[dim.getPosition()]); if (!ival || ival.getOwner()->getParentOp() != op) { rhs = rhs + bop; continue; @@ -4983,8 +4983,8 @@ template struct BufferElimination : public OpRewritePattern { auto opd = map.getResults()[0].dyn_cast(); if (!opd) continue; - auto val = ((Value)load.getMapOperands()[opd.getPosition()]) - .dyn_cast(); + auto val = llvm::dyn_cast( + ((Value)load.getMapOperands()[opd.getPosition()])); if (!val) continue; @@ -5033,8 +5033,8 @@ template struct BufferElimination : public OpRewritePattern { auto opd = map.getResults()[0].dyn_cast(); if (!opd) continue; - auto val = ((Value)load.getMapOperands()[opd.getPosition()]) - .dyn_cast(); + auto val = llvm::dyn_cast( + ((Value)load.getMapOperands()[opd.getPosition()])); if (!val) continue; @@ -5279,7 +5279,7 @@ struct AffineBufferElimination : public OpRewritePattern { } if (storeIdxs[pair.index()].isValue) { Value auval = storeIdxs[pair.index()].v_val; - BlockArgument bval = auval.dyn_cast(); + BlockArgument bval = llvm::dyn_cast(auval); if (!bval) { LLVM_DEBUG(llvm::dbgs() << " + non bval expr " << bval << "\n"); continue; @@ -5302,9 +5302,7 @@ struct AffineBufferElimination : public OpRewritePattern { auto i = idxp.index(); if (!idx.isValue) { if (auto ald = dyn_cast(ld)) { - if (auto ac = ald.getAffineMap() - .getResult(i) - .dyn_cast()) { + if (auto ac = ald.getAffineMap().getResult(i).dyn_cast()) { if (idx == ac.getValue()) continue; } @@ -5339,7 +5337,7 @@ struct AffineBufferElimination : public OpRewritePattern { if (!VI.isValue) continue; auto V = VI.v_val; - auto BA = V.dyn_cast(); + auto BA = llvm::dyn_cast(V); if (!BA) { LLVM_DEBUG(llvm::dbgs() << " + non map oper " << V << "\n"); return failure(); @@ -5426,7 +5424,7 @@ struct AffineBufferElimination : public OpRewritePattern { if (!VI.isValue) continue; auto V = VI.v_val; - auto BA = V.dyn_cast(); + auto BA = llvm::dyn_cast(V); Operation *c = BA.getOwner()->getParentOp(); if (isa(c) || isa(c)) { Operation *tmp = store; @@ -5468,7 +5466,7 @@ struct AffineBufferElimination : public OpRewritePattern { if (storeIdxSet.count(V)) continue; - if (auto BA = V.dyn_cast()) { + if (auto BA = llvm::dyn_cast(V)) { Operation *parent = BA.getOwner()->getParentOp(); if (auto sop = storeVal.getDefiningOp()) @@ -5518,10 +5516,10 @@ struct AffineBufferElimination : public OpRewritePattern { if (!isa(res.getEffect())) return false; unsigned addr = 0; - if (auto MT = v.getType().dyn_cast()) + if (auto MT = llvm::dyn_cast(v.getType())) addr = MT.getMemorySpaceAsInt(); else if (auto LT = - v.getType().dyn_cast()) + llvm::dyn_cast(v.getType())) addr = LT.getAddressSpace(); else return false; diff --git a/lib/polygeist/Passes/AffineCFG.cpp b/lib/polygeist/Passes/AffineCFG.cpp index b5cbbd4ce0a6..c2f0b1b0d20e 100644 --- a/lib/polygeist/Passes/AffineCFG.cpp +++ b/lib/polygeist/Passes/AffineCFG.cpp @@ -144,7 +144,7 @@ static bool legalCondition(Value en, bool dim = false) { // if (!outer || legalCondition(IC.getOperand(), false)) return true; //} if (!dim) - if (auto BA = en.dyn_cast()) { + if (auto BA = llvm::dyn_cast(en)) { if (isa( BA.getOwner()->getParentOp())) return true; @@ -730,7 +730,7 @@ static void setLocationAfter(PatternRewriter &b, mlir::Value val) { it++; b.setInsertionPoint(val.getDefiningOp()->getBlock(), it); } - if (auto bop = val.dyn_cast()) + if (auto bop = llvm::dyn_cast(val)) b.setInsertionPoint(bop.getOwner(), bop.getOwner()->begin()); } @@ -745,7 +745,7 @@ struct IndexCastMovement : public OpRewritePattern { } mlir::Value val = op.getOperand(); - if (auto bop = val.dyn_cast()) { + if (auto bop = llvm::dyn_cast(val)) { if (op.getOperation()->getBlock() != bop.getOwner()) { op.getOperation()->moveBefore(bop.getOwner(), bop.getOwner()->begin()); return success(); @@ -1010,7 +1010,7 @@ bool isValidIndex(Value val) { if (val.getDefiningOp()) return true; - if (auto ba = val.dyn_cast()) { + if (auto ba = llvm::dyn_cast(val)) { auto *owner = ba.getOwner(); assert(owner); diff --git a/lib/polygeist/Passes/CanonicalizeFor.cpp b/lib/polygeist/Passes/CanonicalizeFor.cpp index ae4b8ecb8376..0a682fb1cc3d 100644 --- a/lib/polygeist/Passes/CanonicalizeFor.cpp +++ b/lib/polygeist/Passes/CanonicalizeFor.cpp @@ -110,7 +110,7 @@ struct ForBreakAddUpgrade : public OpRewritePattern { auto condition = outerIfOp.getCondition(); // and that the outermost if's condition is an iter arg of the for - auto condArg = condition.dyn_cast(); + auto condArg = llvm::dyn_cast(condition); if (!condArg) return failure(); if (condArg.getOwner()->getParentOp() != forOp) @@ -121,7 +121,7 @@ struct ForBreakAddUpgrade : public OpRewritePattern { // and is false unless coming from inside the if auto forYieldOp = cast(block.getTerminator()); auto opres = - forYieldOp.getOperand(condArg.getArgNumber() - 1).dyn_cast(); + llvm::dyn_cast(forYieldOp.getOperand(condArg.getArgNumber() - 1)); if (!opres) return failure(); if (opres.getOwner() != outerIfOp) @@ -143,7 +143,7 @@ struct ForBreakAddUpgrade : public OpRewritePattern { if (opres.getResultNumber() == regionArg.getArgNumber() - 1) continue; - auto opres2 = forYieldOperand.dyn_cast(); + auto opres2 = llvm::dyn_cast(forYieldOperand); if (!opres2) continue; if (opres2.getOwner() != outerIfOp) @@ -627,13 +627,13 @@ yop2.results()[idx]); */ bool isTopLevelArgValue(Value value, Region *region) { - if (auto arg = value.dyn_cast()) + if (auto arg = llvm::dyn_cast(value)) return arg.getParentRegion() == region; return false; } bool isBlockArg(Value value) { - if (auto arg = value.dyn_cast()) + if (auto arg = llvm::dyn_cast(value)) return true; return false; } @@ -642,7 +642,7 @@ bool dominateWhile(Value value, WhileOp loop) { if (Operation *op = value.getDefiningOp()) { DominanceInfo dom(loop); return dom.properlyDominates(op, loop); - } else if (auto arg = value.dyn_cast()) { + } else if (auto arg = llvm::dyn_cast(value)) { return arg.getOwner()->getParentOp()->isProperAncestor(loop); } else { assert("????"); @@ -682,11 +682,11 @@ struct WhileToForHelper { negativeStep = false; auto condOp = loop.getConditionOp(); - indVar = cmpIOp.getLhs().dyn_cast(); + indVar = llvm::dyn_cast(cmpIOp.getLhs()); Type extType = nullptr; // todo handle ext if (auto ext = cmpIOp.getLhs().getDefiningOp()) { - indVar = ext.getIn().dyn_cast(); + indVar = llvm::dyn_cast(ext.getIn()); extType = ext.getType(); } // Condition is not the same as an induction variable @@ -1004,7 +1004,7 @@ struct MoveWhileAndDown : public OpRewritePattern { Value extraCmp = andIOp->getOperand(1 - i); Value lookThrough = nullptr; - if (auto BA = extraCmp.dyn_cast()) { + if (auto BA = llvm::dyn_cast(extraCmp)) { lookThrough = oldYield.getOperand(BA.getArgNumber()); } if (!helper.computeLegality(/*sizeCheck*/ false, lookThrough)) { @@ -1341,7 +1341,7 @@ struct MoveWhileDown2 : public OpRewritePattern { // yield i:pair<2> // } if (!std::get<0>(pair).use_empty()) { - if (auto blockArg = elseYielded.dyn_cast()) + if (auto blockArg = llvm::dyn_cast(elseYielded)) if (blockArg.getOwner() == &op.getBefore().front()) { if (afterYield.getResults()[blockArg.getArgNumber()] == std::get<2>(pair) && @@ -1580,7 +1580,7 @@ struct WhileCmpOffset : public OpRewritePattern { if (addI.getOperand(1).getDefiningOp() && !op.getBefore().isAncestor( addI.getOperand(1).getDefiningOp()->getParentRegion())) - if (auto blockArg = addI.getOperand(0).dyn_cast()) { + if (auto blockArg = llvm::dyn_cast(addI.getOperand(0))) { if (blockArg.getOwner() == &op.getBefore().front()) { auto rng = llvm::make_early_inc_range(blockArg.getUses()); @@ -1859,7 +1859,7 @@ struct WhileLICM : public OpRewritePattern { auto isDefinedOutsideOfBody = [&](Value value) { auto *definingOp = value.getDefiningOp(); if (!definingOp) { - if (auto ba = value.dyn_cast()) + if (auto ba = llvm::dyn_cast(value)) definingOp = ba.getOwner()->getParentOp(); assert(definingOp); } @@ -2125,7 +2125,7 @@ struct WhileShiftToInduction : public OpRewritePattern { if (!matchPattern(cmpIOp.getRhs(), m_Zero())) return failure(); - auto indVar = cmpIOp.getLhs().dyn_cast(); + auto indVar = llvm::dyn_cast(cmpIOp.getLhs()); if (!indVar) return failure(); @@ -2144,7 +2144,7 @@ struct WhileShiftToInduction : public OpRewritePattern { if (!matchPattern(shiftOp.getRhs(), m_One())) return failure(); - auto prevIndVar = shiftOp.getLhs().dyn_cast(); + auto prevIndVar = llvm::dyn_cast(shiftOp.getLhs()); if (!prevIndVar) return failure(); diff --git a/lib/polygeist/Passes/CollectKernelStatistics.cpp b/lib/polygeist/Passes/CollectKernelStatistics.cpp index 5c387d0da2d1..ea1a4905a593 100644 --- a/lib/polygeist/Passes/CollectKernelStatistics.cpp +++ b/lib/polygeist/Passes/CollectKernelStatistics.cpp @@ -197,7 +197,7 @@ std::array estimateStride(mlir::OperandRange indices, } else { return UNKNOWN; } - } else if (auto ba = v.dyn_cast()) { + } else if (auto ba = llvm::dyn_cast(v)) { return 0; if (isa(ba.getOwner()->getParentOp())) { return 0; @@ -339,7 +339,7 @@ static void generateAlternativeKernelDescs(mlir::ModuleOp m) { isa(&op) || isa(&op) || isa(&op) || false) { int width = - op.getOperand(0).getType().dyn_cast().getWidth(); + llvm::dyn_cast(op.getOperand(0).getType()).getWidth(); addTo(floatOps, width, blockTrips); } else if (isa(&op) || isa(&op) || isa(&op) || isa(&op) || diff --git a/lib/polygeist/Passes/ConvertParallelToGPU.cpp b/lib/polygeist/Passes/ConvertParallelToGPU.cpp index bdba0ffca53e..5ae277d6364f 100644 --- a/lib/polygeist/Passes/ConvertParallelToGPU.cpp +++ b/lib/polygeist/Passes/ConvertParallelToGPU.cpp @@ -222,7 +222,7 @@ struct AddLaunchBounds : public OpRewritePattern { succeeded = true; } else { assert(blockSize == - gpuFuncOp->getAttr(attrName).dyn_cast().getInt()); + llvm::dyn_cast(gpuFuncOp->getAttr(attrName)).getInt()); succeeded = false; } attrName = "rocdl.max_flat_work_group_size"; @@ -233,7 +233,7 @@ struct AddLaunchBounds : public OpRewritePattern { return success(); } else { assert(blockSize == - gpuFuncOp->getAttr(attrName).dyn_cast().getInt()); + llvm::dyn_cast(gpuFuncOp->getAttr(attrName)).getInt()); assert(!succeeded); return failure(); } @@ -525,7 +525,7 @@ struct SplitParallelOp : public OpRewritePattern { llvm::SmallVector syncIVs; pop->walk([&](polygeist::BarrierOp barrier) { for (auto o : barrier.getOperands()) - if (auto ba = o.dyn_cast()) + if (auto ba = llvm::dyn_cast(o)) if (std::find(syncIVs.begin(), syncIVs.end(), ba) == syncIVs.end()) syncIVs.push_back(ba); }); @@ -1330,7 +1330,7 @@ struct RemovePolygeistNoopOp : public OpRewritePattern { scf::ParallelOp pop = nullptr; SmallVector threadIndices; for (auto operand : noop.getOperands()) { - if (auto blockArg = operand.dyn_cast()) { + if (auto blockArg = llvm::dyn_cast(operand)) { if (auto _pop = dyn_cast( blockArg.getOwner()->getParentOp())) { if (!pop) diff --git a/lib/polygeist/Passes/ConvertPolygeistToLLVM.cpp b/lib/polygeist/Passes/ConvertPolygeistToLLVM.cpp index fd3d251f3184..205bcc173648 100644 --- a/lib/polygeist/Passes/ConvertPolygeistToLLVM.cpp +++ b/lib/polygeist/Passes/ConvertPolygeistToLLVM.cpp @@ -308,7 +308,7 @@ struct Pointer2MemrefOpLowering // MemRefDescriptor sourceMemRef(operands.front()); auto convertedType = getTypeConverter()->convertType(op.getType()); assert(convertedType && "unexpected failure in memref type conversion"); - if (auto PT = convertedType.dyn_cast()) { + if (auto PT = llvm::dyn_cast(convertedType)) { rewriter.replaceOpWithNewOp(op, PT, adaptor.getSource()); return success(); } @@ -551,7 +551,7 @@ struct LLVMOpLowering : public ConversionPattern { bool typeAttrsConverted = true; for (auto &attr : op->getAttrs()) - if (auto tyAttr = attr.getValue().dyn_cast()) + if (auto tyAttr = llvm::dyn_cast(attr.getValue())) if (converter->convertType(tyAttr.getValue()) != tyAttr.getValue()) typeAttrsConverted = false; @@ -565,7 +565,7 @@ struct LLVMOpLowering : public ConversionPattern { SmallVector convertedAttrs; for (auto &attr : op->getAttrs()) { NamedAttribute convertedAttr = attr; - if (auto tyAttr = attr.getValue().dyn_cast()) { + if (auto tyAttr = llvm::dyn_cast(attr.getValue())) { Type convertedTy = converter->convertType(tyAttr.getValue()); if (!convertedTy) return failure(); @@ -857,7 +857,7 @@ struct AsyncOpLowering : public ConvertOpToLLVMPattern { rewriter.create(execute.getLoc(), func))); for (auto dep : execute.getDependencies()) { auto src = dep.getDefiningOp().getSource(); - if (auto MT = src.getType().dyn_cast()) + if (auto MT = llvm::dyn_cast(src.getType())) src = rewriter.create( dep.getDefiningOp()->getLoc(), LLVM::LLVMPointerType::get(rewriter.getContext(), @@ -1531,7 +1531,7 @@ struct LowerGPUAlternativesOp isa(op) || isa(op) || isa(op)) { int width = - op->getOperand(0).getType().dyn_cast().getWidth(); + llvm::dyn_cast(op->getOperand(0).getType()).getWidth(); // TODO these are pretty random atm if (width == 16) { floatOps++; @@ -2256,7 +2256,7 @@ LogicalResult ConvertLaunchFuncOpToGpuRuntimeCallPattern::matchAndRewrite( auto bitcast = ctorBuilder.create(loc, llvmPointerType, aoo); auto globalTy = - aoo.getType().dyn_cast().getElementType(); + llvm::dyn_cast(aoo.getType()).getElementType(); // TODO This should actually be the GPUModuleOp's data layout I // believe, there were problems with assigning the data layout to the // gpumodule because MLIR didnt like the nested data layout, and @@ -2394,7 +2394,7 @@ struct GPUFuncOpLowering : public ConvertOpToLLVMPattern { llvm::enumerate(gpuFuncOp.getWorkgroupAttributions())) { Value attribution = en.value(); - auto type = attribution.getType().dyn_cast(); + auto type = llvm::dyn_cast(attribution.getType()); assert(type && type.hasStaticShape() && "unexpected type in attribution"); uint64_t numElements = type.getNumElements(); @@ -2892,7 +2892,7 @@ struct ConvertPolygeistToLLVMPass auto areAllTypesConverted = [&](Operation *op) -> std::optional { // Check if TyepAttrs got converted for (auto &attr : op->getAttrs()) - if (auto tyAttr = attr.getValue().dyn_cast()) + if (auto tyAttr = llvm::dyn_cast(attr.getValue())) if (converter.convertType(tyAttr.getValue()) != tyAttr.getValue()) return std::nullopt; diff --git a/lib/polygeist/Passes/ConvertToOpaquePtr.cpp b/lib/polygeist/Passes/ConvertToOpaquePtr.cpp index 8fcb7cde367b..7b8a2012794d 100644 --- a/lib/polygeist/Passes/ConvertToOpaquePtr.cpp +++ b/lib/polygeist/Passes/ConvertToOpaquePtr.cpp @@ -191,10 +191,9 @@ struct GEPConversion : public OpConversionPattern { TypeAttr elty = nullptr; if (!op->getAttr(kElemTypeAttrName)) elty = TypeAttr::get( - getTypeConverter()->convertType(op.getOperand(0) - .getType() - .dyn_cast() - .getElementType())); + getTypeConverter()->convertType( + llvm::dyn_cast( + op.getOperand(0).getType()).getElementType())); if (convertPtrsToOpaque(op, rewritten, elty, adaptor.getOperands(), rewriter, getTypeConverter()) .failed()) @@ -225,14 +224,14 @@ struct ConvertToOpaquePtrPass std::map typeCache; TypeConverter converter; converter.addConversion([&](Type ty) -> Type { - if (auto pt = ty.dyn_cast()) { + if (auto pt = llvm::dyn_cast(ty)) { return LLVM::LLVMPointerType::get(pt.getContext(), pt.getAddressSpace()); - } else if (auto mt = ty.dyn_cast()) { + } else if (auto mt = llvm::dyn_cast(ty)) { return MemRefType::get(mt.getShape(), converter.convertType(mt.getElementType()), mt.getLayout(), mt.getMemorySpace()); - } else if (auto st = ty.dyn_cast()) { + } else if (auto st = llvm::dyn_cast(ty)) { StringRef key = ""; if (st.isIdentified()) { key = st.getName(); @@ -247,7 +246,7 @@ struct ConvertToOpaquePtrPass } for (auto ty : st.getBody()) { StringRef fieldKey = ""; - if (auto fieldST = ty.dyn_cast()) { + if (auto fieldST = llvm::dyn_cast(ty)) { if (fieldST.isIdentified()) fieldKey = fieldST.getName(); } @@ -265,7 +264,7 @@ struct ConvertToOpaquePtrPass return LLVM::LLVMStructType::getLiteral(&getContext(), bodyTypes, st.isPacked()); } - } else if (auto at = ty.dyn_cast()) { + } else if (auto at = llvm::dyn_cast(ty)) { return LLVM::LLVMArrayType::get( converter.convertType(at.getElementType()), at.getNumElements()); } else { diff --git a/lib/polygeist/Passes/ForBreakToWhile.cpp b/lib/polygeist/Passes/ForBreakToWhile.cpp index b6e0fd6cdd1b..597ccef0c77c 100644 --- a/lib/polygeist/Passes/ForBreakToWhile.cpp +++ b/lib/polygeist/Passes/ForBreakToWhile.cpp @@ -39,7 +39,7 @@ struct ForBreakLoweringPattern : public OpRewritePattern { return failure(); // Its condition comes directly from iterargs. - auto condition = conditional.getCondition().dyn_cast(); + auto condition = llvm::dyn_cast(conditional.getCondition()); if (!condition || condition.getOwner()->getParentOp() != forOp) return failure(); unsigned iterArgPos = condition.getArgNumber() - 1; @@ -47,7 +47,7 @@ struct ForBreakLoweringPattern : public OpRewritePattern { // The condition is initially and remains false once changed to // false. Moveover, values don't change after the condition is set to false. auto yield = cast(body->back()); - auto yieldedCondition = yield.getOperand(iterArgPos).dyn_cast(); + auto yieldedCondition = llvm::dyn_cast(yield.getOperand(iterArgPos)); if (yieldedCondition.getOwner() != conditional) return failure(); @@ -61,7 +61,7 @@ struct ForBreakLoweringPattern : public OpRewritePattern { Block *forEnd = &forOp.getRegion().back(); auto forYield = cast(forEnd->getTerminator()); for (auto op : llvm::enumerate(forYield->getOperands())) { - auto opp = op.value().dyn_cast(); + auto opp = llvm::dyn_cast(op.value()); if (!opp) { return failure(); } @@ -69,7 +69,7 @@ struct ForBreakLoweringPattern : public OpRewritePattern { return failure(); auto BA = - elseYield.getOperand(opp.getResultNumber()).dyn_cast(); + llvm::dyn_cast(elseYield.getOperand(opp.getResultNumber())); if (!BA) { if (iterArgPos == op.index()) if (matchPattern(elseYield.getOperand(opp.getResultNumber()), @@ -88,7 +88,7 @@ struct ForBreakLoweringPattern : public OpRewritePattern { SmallVector continueArgs; for (auto op : forYield->getOperands()) { - if (auto opp = op.dyn_cast()) { + if (auto opp = llvm::dyn_cast(op)) { if (opp.getOwner() == conditional) { continueArgs.push_back( conditional.thenYield()->getOperand(opp.getResultNumber())); diff --git a/lib/polygeist/Passes/ParallelLICM.cpp b/lib/polygeist/Passes/ParallelLICM.cpp index 5654810ba7e6..9847882d1414 100644 --- a/lib/polygeist/Passes/ParallelLICM.cpp +++ b/lib/polygeist/Passes/ParallelLICM.cpp @@ -34,7 +34,7 @@ static bool canBeParallelHoisted(Operation *op, Operation *scope, // Helper to check whether an operation is loop invariant wrt. SSA properties. LLVM_DEBUG(llvm::dbgs() << "Checking for parallel hoist: " << *op << "\n"); auto definedOutside = [&](Value value) { - if (auto BA = value.dyn_cast()) + if (auto BA = llvm::dyn_cast(value)) if (willBeMoved.count(BA.getOwner()->getParentOp())) return true; auto *definingOp = value.getDefiningOp(); @@ -245,7 +245,7 @@ bool below(Value bval, int64_t val) { if (val == -1) return false; - if (auto baval = bval.dyn_cast()) { + if (auto baval = llvm::dyn_cast(bval)) { if (affine::AffineForOp afFor = dyn_cast(baval.getOwner()->getParentOp())) { for (auto ub : afFor.getUpperBoundMap().getResults()) { diff --git a/lib/polygeist/Passes/ParallelLoopDistribute.cpp b/lib/polygeist/Passes/ParallelLoopDistribute.cpp index ac43cda53a04..c41da5996fab 100644 --- a/lib/polygeist/Passes/ParallelLoopDistribute.cpp +++ b/lib/polygeist/Passes/ParallelLoopDistribute.cpp @@ -286,7 +286,7 @@ static void minCutCache(polygeist::BarrierOp barrier, for (auto N : pair.second) { if (parent.find(N) == parent.end()) { assert(pair.first.type == Node::OP && N.type == Node::VAL); - assert(pair.first.O == N.V.dyn_cast().getOwner()); + assert(pair.first.O == llvm::dyn_cast(N.V).getOwner()); Cache.insert(N.V); } } @@ -396,7 +396,7 @@ static bool hasNestedBarrier(Operation *op, SmallVector &vals) { // the `parallel` op is not an ancestor of `op` or `op` itself), the // barrier is considered nested in that `parallel` op and _not_ in `op`. for (auto arg : barrier->getOperands()) { - if (auto ba = arg.dyn_cast()) { + if (auto ba = llvm::dyn_cast(arg)) { if (auto parallel = dyn_cast(ba.getOwner()->getParentOp())) { if (parallel->isAncestor(op)) @@ -2326,7 +2326,7 @@ struct Reg2MemIf : public OpRewritePattern { while (!todo.empty()) { auto cur = todo.pop_back_val(); - if (auto BA = cur.dyn_cast()) + if (auto BA = llvm::dyn_cast(cur)) if (BA.getOwner() == op->getBlock()) continue; @@ -2426,7 +2426,7 @@ struct Reg2MemIf : public OpRewritePattern { while (!todo.empty()) { auto cur = todo.pop_back_val(); - if (auto BA = cur.dyn_cast()) + if (auto BA = llvm::dyn_cast(cur)) if (BA.getOwner() == op->getBlock()) continue; if (cur.getParentRegion()->isProperAncestor( @@ -2485,7 +2485,7 @@ struct Reg2MemIf : public OpRewritePattern { while (!todo.empty()) { auto cur = todo.pop_back_val(); - if (auto BA = cur.dyn_cast()) + if (auto BA = llvm::dyn_cast(cur)) if (BA.getOwner() == op->getBlock()) continue; diff --git a/lib/polygeist/Passes/ParallelLoopUnroll.cpp b/lib/polygeist/Passes/ParallelLoopUnroll.cpp index 2179a48c9a31..0be1711010ee 100644 --- a/lib/polygeist/Passes/ParallelLoopUnroll.cpp +++ b/lib/polygeist/Passes/ParallelLoopUnroll.cpp @@ -93,7 +93,7 @@ static LogicalResult generateUnrolledInterleavedLoop( .wasInterrupted(); }; auto threadIndependent = [&](Value v) -> bool { - if (auto BA = v.dyn_cast()) { + if (auto BA = llvm::dyn_cast(v)) { if (BA == srcIV) return false; return BA.getOwner()->getParentOp()->isAncestor(srcBlock->getParentOp()); diff --git a/lib/polygeist/Passes/ParallelLower.cpp b/lib/polygeist/Passes/ParallelLower.cpp index ed2354e5ca97..706b9c97bcc6 100644 --- a/lib/polygeist/Passes/ParallelLower.cpp +++ b/lib/polygeist/Passes/ParallelLower.cpp @@ -258,7 +258,7 @@ void ParallelLower::runOnOperation() { auto callable = caller.getCallableForCallee(); CallableOpInterface callableOp; - if (SymbolRefAttr symRef = callable.dyn_cast()) { + if (SymbolRefAttr symRef = llvm::dyn_cast(callable)) { if (!symRef.isa()) return; auto *symbolOp = @@ -312,7 +312,7 @@ void ParallelLower::runOnOperation() { auto callable = caller.getCallableForCallee(); CallableOpInterface callableOp; - if (SymbolRefAttr symRef = callable.dyn_cast()) { + if (SymbolRefAttr symRef = llvm::dyn_cast(callable)) { if (!symRef.isa()) return; auto *symbolOp = @@ -730,7 +730,7 @@ void FixGPUFunc::runOnOperation() { auto callable = caller.getCallableForCallee(); CallableOpInterface callableOp; - if (SymbolRefAttr symRef = callable.dyn_cast()) { + if (SymbolRefAttr symRef = llvm::dyn_cast(callable)) { auto *symbolOp = symbolTable.lookupNearestSymbolFrom(getOperation(), symRef); callableOp = dyn_cast_or_null(symbolOp); @@ -771,7 +771,7 @@ void FixGPUFunc::runOnOperation() { return; Operation *funcOp; if (SymbolRefAttr symRef = - callOp.getCallableForCallee().dyn_cast()) { + llvm::dyn_cast(callOp.getCallableForCallee())) { auto *symbolOp = symbolTable.lookupNearestSymbolFrom(getOperation(), symRef); funcOp = dyn_cast_or_null(symbolOp); @@ -806,7 +806,7 @@ void ConvertCudaRTtoCPU::runOnOperation() { OpBuilder bz(call); auto falsev = bz.create(call->getLoc(), false, 1); auto dst = call->getOperand(0); - if (auto mt = dst.getType().dyn_cast()) { + if (auto mt = llvm::dyn_cast(dst.getType())) { dst = bz.create( call->getLoc(), LLVM::LLVMPointerType::get(mt.getElementType(), @@ -814,7 +814,7 @@ void ConvertCudaRTtoCPU::runOnOperation() { dst); } auto src = call->getOperand(1); - if (auto mt = src.getType().dyn_cast()) { + if (auto mt = llvm::dyn_cast(src.getType())) { src = bz.create( call->getLoc(), LLVM::LLVMPointerType::get(mt.getElementType(), @@ -831,7 +831,7 @@ void ConvertCudaRTtoCPU::runOnOperation() { OpBuilder bz(call); auto falsev = bz.create(call->getLoc(), false, 1); auto dst = call->getOperand(0); - if (auto mt = dst.getType().dyn_cast()) { + if (auto mt = llvm::dyn_cast(dst.getType())) { dst = bz.create( call->getLoc(), LLVM::LLVMPointerType::get(mt.getElementType(), @@ -839,7 +839,7 @@ void ConvertCudaRTtoCPU::runOnOperation() { dst); } auto src = call->getOperand(1); - if (auto mt = src.getType().dyn_cast()) { + if (auto mt = llvm::dyn_cast(src.getType())) { src = bz.create( call->getLoc(), LLVM::LLVMPointerType::get(mt.getElementType(), @@ -859,7 +859,7 @@ void ConvertCudaRTtoCPU::runOnOperation() { OpBuilder bz(call); auto falsev = bz.create(call->getLoc(), false, 1); auto dst = call->getOperand(0); - if (auto mt = dst.getType().dyn_cast()) { + if (auto mt = llvm::dyn_cast(dst.getType())) { dst = bz.create( call->getLoc(), LLVM::LLVMPointerType::get(mt.getElementType(), diff --git a/lib/polygeist/Passes/PolygeistMem2Reg.cpp b/lib/polygeist/Passes/PolygeistMem2Reg.cpp index 7e04bbfa2969..0e228c1453f6 100644 --- a/lib/polygeist/Passes/PolygeistMem2Reg.cpp +++ b/lib/polygeist/Passes/PolygeistMem2Reg.cpp @@ -45,8 +45,8 @@ using namespace polygeist; enum class Match { Exact, Maybe, None }; bool operator<(Value lhs, Value rhs) { - if (auto lhsBA = lhs.dyn_cast()) { - if (auto rhsBA = rhs.dyn_cast()) { + if (auto lhsBA = llvm::dyn_cast(lhs)) { + if (auto rhsBA = llvm::dyn_cast(rhs)) { if (lhsBA.getOwner() != rhsBA.getOwner()) return lhsBA.getOwner() < rhsBA.getOwner(); else @@ -56,7 +56,7 @@ bool operator<(Value lhs, Value rhs) { } } auto lhsOR = lhs.cast(); - if (auto rhsBA = rhs.dyn_cast()) { + if (auto rhsBA = llvm::dyn_cast(rhs)) { return false; } else { auto rhsOR = rhs.cast(); @@ -502,7 +502,7 @@ class ValueOrPlaceholder { !exOp->isAncestor(values[0].getDefiningOp())) { return values[0]; } - if (auto ba = values[0].dyn_cast()) + if (auto ba = llvm::dyn_cast(values[0])) if (!exOp->isAncestor(ba.getOwner()->getParentOp())) { return values[0]; } @@ -1083,7 +1083,7 @@ bool PolygeistMem2Reg::forwardStoreToLoad( std::set allStoreOps; Type elType; - if (auto MT = AI.getType().dyn_cast()) + if (auto MT = llvm::dyn_cast(AI.getType())) elType = MT.getElementType(); else elType = AI.getType().cast().getElementType(); @@ -1101,11 +1101,11 @@ bool PolygeistMem2Reg::forwardStoreToLoad( while (list.size()) { auto pair = list.front(); auto val = pair.first; - if (auto MT = val.getType().dyn_cast()) { + if (auto MT = llvm::dyn_cast(val.getType())) { if (auto ia = MT.getMemorySpace().dyn_cast_or_null()) SharedMemAddr = ia.getValue() == 5; } else { - auto PT = val.getType().dyn_cast(); + auto PT = llvm::dyn_cast(val.getType()); SharedMemAddr = PT.getAddressSpace() == 5; } auto modified = pair.second; @@ -1707,7 +1707,7 @@ bool PolygeistMem2Reg::forwardStoreToLoad( Value maybeblockArg = valueAtStartOfBlock.find(block)->second->materialize(false); - auto blockArg = maybeblockArg.dyn_cast(); + auto blockArg = llvm::dyn_cast(maybeblockArg); assert(blockArg && blockArg.getOwner() == block); SetVector prepred(block->getPredecessors().begin(), diff --git a/tools/cgeist/Lib/CGCall.cc b/tools/cgeist/Lib/CGCall.cc index bbabd848517f..e5d029347d7b 100644 --- a/tools/cgeist/Lib/CGCall.cc +++ b/tools/cgeist/Lib/CGCall.cc @@ -35,7 +35,7 @@ static mlir::Value castCallerMemRefArg(mlir::Value callerArg, mlir::Type callerArgType = callerArg.getType(); if (MemRefType dstTy = calleeArgType.dyn_cast_or_null()) { - MemRefType srcTy = callerArgType.dyn_cast(); + MemRefType srcTy = llvm::dyn_cast(callerArgType); if (srcTy && dstTy.getElementType() == srcTy.getElementType() && dstTy.getMemorySpace() == srcTy.getMemorySpace()) { auto srcShape = srcTy.getShape(); @@ -126,7 +126,7 @@ ValueCategory MLIRScanner::CallHelper( QualType aType = (i == 0 && a == nullptr) ? objType : a->getType(); auto expectedType = Glob.getMLIRType(aType, &isArray); - if (auto PT = arg.val.getType().dyn_cast()) { + if (auto PT = llvm::dyn_cast(arg.val.getType())) { if (PT.getAddressSpace() == 5) arg.val = builder.create( loc, LLVM::LLVMPointerType::get(PT.getElementType(), 0), arg.val); @@ -174,7 +174,7 @@ ValueCategory MLIRScanner::CallHelper( val = builder.create(loc, expectedType, val); } - if (auto prevTy = val.getType().dyn_cast()) { + if (auto prevTy = llvm::dyn_cast(val.getType())) { auto ipostTy = expectedType.cast(); if (prevTy != ipostTy) val = builder.create(loc, ipostTy, val); @@ -258,7 +258,7 @@ ValueCategory MLIRScanner::CallHelper( assert(l0.isReference); mlir::Value blocks[3]; mlir::Value val = l0.val; - if (auto MT = val.getType().dyn_cast()) { + if (auto MT = llvm::dyn_cast(val.getType())) { if (MT.getElementType().isa() && MT.getShape().size() == 1) { val = builder.create( @@ -269,7 +269,7 @@ ValueCategory MLIRScanner::CallHelper( } } for (int i = 0; i < 3; i++) { - if (auto MT = val.getType().dyn_cast()) { + if (auto MT = llvm::dyn_cast(val.getType())) { mlir::Value idx[] = {getConstantIndex(0), getConstantIndex(i)}; assert(MT.getShape().size() == 2); blocks[i] = builder.create( @@ -294,7 +294,7 @@ ValueCategory MLIRScanner::CallHelper( assert(t0.isReference); mlir::Value threads[3]; val = t0.val; - if (auto MT = val.getType().dyn_cast()) { + if (auto MT = llvm::dyn_cast(val.getType())) { if (MT.getElementType().isa() && MT.getShape().size() == 1) { val = builder.create( @@ -305,7 +305,7 @@ ValueCategory MLIRScanner::CallHelper( } } for (int i = 0; i < 3; i++) { - if (auto MT = val.getType().dyn_cast()) { + if (auto MT = llvm::dyn_cast(val.getType())) { mlir::Value idx[] = {getConstantIndex(0), getConstantIndex(i)}; assert(MT.getShape().size() == 2); threads[i] = builder.create( @@ -383,10 +383,10 @@ mlir::Value MLIRScanner::getLLVM(Expr *E, bool isRef) { if (isReference) { assert(sub.isReference); mlir::Value val = sub.val; - if (auto mt = val.getType().dyn_cast()) { + if (auto mt = llvm::dyn_cast(val.getType())) { val = builder.create(loc, getOpaquePtr(), val); - } else if (auto pt = val.getType().dyn_cast()) { + } else if (auto pt = llvm::dyn_cast(val.getType())) { if (!pt.isOpaque()) val = builder.create(loc, getOpaquePtr(), val); } @@ -441,9 +441,9 @@ mlir::Value MLIRScanner::getLLVM(Expr *E, bool isRef) { val = sub.val; ct = Glob.CGM.getContext().getLValueReferenceType(E->getType()); } - if (auto mt = val.getType().dyn_cast()) { + if (auto mt = llvm::dyn_cast(val.getType())) { val = builder.create(loc, getOpaquePtr(), val); - } else if (auto pt = val.getType().dyn_cast()) { + } else if (auto pt = llvm::dyn_cast(val.getType())) { if (!pt.isOpaque()) val = builder.create(loc, getOpaquePtr(), val); } @@ -498,7 +498,7 @@ MLIRScanner::EmitClangBuiltinCallExpr(clang::CallExpr *expr) { loc, mlir::IndexType::get(builder.getContext()), count); auto ty = getMLIRType(expr->getType()); mlir::Value alloc; - if (auto mt = ty.dyn_cast()) { + if (auto mt = llvm::dyn_cast(ty)) { auto shape = std::vector(mt.getShape()); mlir::Value args[1] = {count}; alloc = builder.create(loc, mt, args); @@ -1288,7 +1288,7 @@ ValueCategory MLIRScanner::VisitCallExpr(clang::CallExpr *expr) { loc, offset, builder.create(loc, elemSize)); // assert(!dstArray); - if (auto mt = dst.getType().dyn_cast()) { + if (auto mt = llvm::dyn_cast(dst.getType())) { auto shape = std::vector(mt.getShape()); shape[0] = ShapedType::kDynamic; auto mt0 = mlir::MemRefType::get(shape, mt.getElementType(), @@ -1677,7 +1677,7 @@ ValueCategory MLIRScanner::VisitCallExpr(clang::CallExpr *expr) { builder.create(loc, strcmpF, args).getResult(); } else { mlir::Value fn = Visit(expr->getCallee()).getValue(loc, builder); - if (auto MT = fn.getType().dyn_cast()) { + if (auto MT = llvm::dyn_cast(fn.getType())) { fn = builder.create( loc, LLVM::LLVMPointerType::get(MT.getElementType(), 0), fn); } @@ -1688,14 +1688,14 @@ ValueCategory MLIRScanner::VisitCallExpr(clang::CallExpr *expr) { SmallVector argtys; bool needsChange = false; for (auto FT : PTF.getParams()) { - if (auto mt = FT.dyn_cast()) { + if (auto mt = llvm::dyn_cast(FT)) { argtys.push_back(LLVM::LLVMPointerType::get(mt.getElementType(), 0)); needsChange = true; } else argtys.push_back(FT); } auto rt = PTF.getReturnType(); - if (auto mt = rt.dyn_cast()) { + if (auto mt = llvm::dyn_cast(rt)) { rt = LLVM::LLVMPointerType::get(mt.getElementType(), 0); needsChange = true; } @@ -1788,7 +1788,7 @@ ValueCategory MLIRScanner::VisitCallExpr(clang::CallExpr *expr) { */ } i++; - if (auto mt = v.getType().dyn_cast()) { + if (auto mt = llvm::dyn_cast(v.getType())) { v = builder.create( loc, LLVM::LLVMPointerType::get(mt.getElementType(), 0), v); } @@ -1807,7 +1807,7 @@ ValueCategory MLIRScanner::VisitCallExpr(clang::CallExpr *expr) { assert(l0.isReference); mlir::Value val = l0.val; mlir::Value blocks[3]; - if (auto MT = val.getType().dyn_cast()) { + if (auto MT = llvm::dyn_cast(val.getType())) { if (MT.getElementType().isa() && MT.getShape().size() == 1) { val = builder.create( @@ -1818,7 +1818,7 @@ ValueCategory MLIRScanner::VisitCallExpr(clang::CallExpr *expr) { } } for (int i = 0; i < 3; i++) { - if (auto MT = val.getType().dyn_cast()) { + if (auto MT = llvm::dyn_cast(val.getType())) { mlir::Value idx[] = {getConstantIndex(0), getConstantIndex(i)}; assert(MT.getShape().size() == 2); blocks[i] = builder.create( @@ -1846,7 +1846,7 @@ ValueCategory MLIRScanner::VisitCallExpr(clang::CallExpr *expr) { assert(t0.isReference); mlir::Value threads[3]; val = t0.val; - if (auto MT = val.getType().dyn_cast()) { + if (auto MT = llvm::dyn_cast(val.getType())) { if (MT.getElementType().isa() && MT.getShape().size() == 1) { val = builder.create( @@ -1857,7 +1857,7 @@ ValueCategory MLIRScanner::VisitCallExpr(clang::CallExpr *expr) { } } for (int i = 0; i < 3; i++) { - if (auto MT = val.getType().dyn_cast()) { + if (auto MT = llvm::dyn_cast(val.getType())) { mlir::Value idx[] = {getConstantIndex(0), getConstantIndex(i)}; assert(MT.getShape().size() == 2); threads[i] = builder.create( diff --git a/tools/cgeist/Lib/CGStmt.cc b/tools/cgeist/Lib/CGStmt.cc index acaad6499238..68a65a22fef3 100644 --- a/tools/cgeist/Lib/CGStmt.cc +++ b/tools/cgeist/Lib/CGStmt.cc @@ -249,14 +249,14 @@ ValueCategory MLIRScanner::VisitForStmt(clang::ForStmt *fors) { if (auto *s = fors->getCond()) { auto condRes = Visit(s); auto cond = condRes.getValue(loc, builder); - if (auto mt = cond.getType().dyn_cast()) { + if (auto mt = llvm::dyn_cast(cond.getType())) { cond = builder.create( loc, LLVM::LLVMPointerType::get(mt.getElementType(), mt.getMemorySpaceAsInt()), cond); } - if (auto LT = cond.getType().dyn_cast()) { + if (auto LT = llvm::dyn_cast(cond.getType())) { auto nullptr_llvm = builder.create(loc, LT); cond = builder.create( loc, mlir::LLVM::ICmpPredicate::ne, cond, nullptr_llvm); @@ -342,7 +342,7 @@ ValueCategory MLIRScanner::VisitCXXForRangeStmt(clang::CXXForRangeStmt *fors) { if (auto *s = fors->getCond()) { auto condRes = Visit(s); auto cond = condRes.getValue(loc, builder); - if (auto LT = cond.getType().dyn_cast()) { + if (auto LT = llvm::dyn_cast(cond.getType())) { auto nullptr_llvm = builder.create(loc, LT); cond = builder.create( loc, mlir::LLVM::ICmpPredicate::ne, cond, nullptr_llvm); @@ -742,7 +742,7 @@ ValueCategory MLIRScanner::VisitDoStmt(clang::DoStmt *fors) { if (auto *s = fors->getCond()) { auto condRes = Visit(s); auto cond = condRes.getValue(loc, builder); - if (auto LT = cond.getType().dyn_cast()) { + if (auto LT = llvm::dyn_cast(cond.getType())) { auto nullptr_llvm = builder.create(loc, LT); cond = builder.create( loc, mlir::LLVM::ICmpPredicate::ne, cond, nullptr_llvm); @@ -805,7 +805,7 @@ ValueCategory MLIRScanner::VisitWhileStmt(clang::WhileStmt *stmt) { if (auto *s = stmt->getCond()) { auto condRes = Visit(s); auto cond = condRes.getValue(loc, builder); - if (auto LT = cond.getType().dyn_cast()) { + if (auto LT = llvm::dyn_cast(cond.getType())) { auto nullptr_llvm = builder.create(loc, LT); cond = builder.create( loc, mlir::LLVM::ICmpPredicate::ne, cond, nullptr_llvm); @@ -849,11 +849,11 @@ ValueCategory MLIRScanner::VisitIfStmt(clang::IfStmt *stmt) { auto oldpoint = builder.getInsertionPoint(); auto *oldblock = builder.getInsertionBlock(); - if (auto LT = cond.getType().dyn_cast()) { + if (auto LT = llvm::dyn_cast(cond.getType())) { cond = builder.create( loc, LLVM::LLVMPointerType::get(builder.getI8Type()), cond); } - if (auto LT = cond.getType().dyn_cast()) { + if (auto LT = llvm::dyn_cast(cond.getType())) { auto nullptr_llvm = builder.create(loc, LT); cond = builder.create( loc, mlir::LLVM::ICmpPredicate::ne, cond, nullptr_llvm); @@ -1164,7 +1164,7 @@ ValueCategory MLIRScanner::VisitReturnStmt(clang::ReturnStmt *stmt) { } auto postTy = returnVal.getType().cast().getElementType(); - if (auto prevTy = val.getType().dyn_cast()) { + if (auto prevTy = llvm::dyn_cast(val.getType())) { auto ipostTy = postTy.cast(); if (prevTy != ipostTy) { val = builder.create(loc, ipostTy, val); diff --git a/tools/cgeist/Lib/ValueCategory.cc b/tools/cgeist/Lib/ValueCategory.cc index 7a03a7112a70..b8cb59c3ef53 100644 --- a/tools/cgeist/Lib/ValueCategory.cc +++ b/tools/cgeist/Lib/ValueCategory.cc @@ -40,7 +40,7 @@ mlir::Value ValueCategory::getValue(mlir::Location loc, if (val.getType().isa()) { return builder.create(loc, val); } - if (auto mt = val.getType().dyn_cast()) { + if (auto mt = llvm::dyn_cast(val.getType())) { assert(mt.getShape().size() == 1 && "must have shape 1"); auto c0 = builder.create(loc, 0); return builder.create(loc, val, @@ -53,7 +53,7 @@ void ValueCategory::store(mlir::Location loc, mlir::OpBuilder &builder, mlir::Value toStore) const { assert(isReference && "must be a reference"); assert(val && "expect not-null"); - if (auto pt = val.getType().dyn_cast()) { + if (auto pt = llvm::dyn_cast(val.getType())) { if (auto p2m = toStore.getDefiningOp()) { if (pt.getElementType() == p2m.getSource().getType()) toStore = p2m.getSource(); @@ -64,9 +64,9 @@ void ValueCategory::store(mlir::Location loc, mlir::OpBuilder &builder, } } if (toStore.getType() != pt.getElementType()) { - if (auto mt = toStore.getType().dyn_cast()) { + if (auto mt = llvm::dyn_cast(toStore.getType())) { if (auto spt = - pt.getElementType().dyn_cast()) { + llvm::dyn_cast(pt.getElementType())) { if (mt.getElementType() != spt.getElementType()) { // llvm::errs() << " func: " << // val.getDefiningOp()->getParentOfType() << "\n"; @@ -84,13 +84,12 @@ void ValueCategory::store(mlir::Location loc, mlir::OpBuilder &builder, } return; } - if (auto mt = val.getType().dyn_cast()) { + if (auto mt = llvm::dyn_cast(val.getType())) { assert(mt.getShape().size() == 1 && "must have size 1"); - if (auto PT = toStore.getType().dyn_cast()) { - if (auto MT = val.getType() + if (auto PT = llvm::dyn_cast(toStore.getType())) { + if (auto MT = llvm::dyn_cast(val.getType() .cast() - .getElementType() - .dyn_cast()) { + .getElementType())) { assert(MT.getShape().size() == 1); assert(MT.getShape()[0] == ShapedType::kDynamic); assert(MT.getElementType() == PT.getElementType()); @@ -156,10 +155,10 @@ void ValueCategory::store(mlir::Location loc, mlir::OpBuilder &builder, assert(toStore.isReference); auto zeroIndex = builder.create(loc, 0); - if (auto smt = toStore.val.getType().dyn_cast()) { + if (auto smt = llvm::dyn_cast(toStore.val.getType())) { assert(smt.getShape().size() <= 2); - if (auto mt = val.getType().dyn_cast()) { + if (auto mt = llvm::dyn_cast(val.getType())) { assert(smt.getElementType() == mt.getElementType()); if (mt.getShape().size() != smt.getShape().size()) { llvm::errs() << " val: " << val << " tsv: " << toStore.val << "\n"; @@ -180,7 +179,7 @@ void ValueCategory::store(mlir::Location loc, mlir::OpBuilder &builder, } else { auto pt = val.getType().cast(); mlir::Type elty; - if (auto at = pt.getElementType().dyn_cast()) { + if (auto at = llvm::dyn_cast(pt.getElementType())) { elty = at.getElementType(); if (smt.getShape().back() != at.getNumElements()) { llvm::errs() << " pt: " << pt << " smt: " << smt << "\n"; @@ -191,7 +190,7 @@ void ValueCategory::store(mlir::Location loc, mlir::OpBuilder &builder, } assert(smt.getShape().back() == at.getNumElements()); } else { - auto st = pt.getElementType().dyn_cast(); + auto st = llvm::dyn_cast(pt.getElementType()); elty = st.getBody()[0]; assert(smt.getShape().back() == (ssize_t)st.getBody().size()); } @@ -221,16 +220,16 @@ void ValueCategory::store(mlir::Location loc, mlir::OpBuilder &builder, builder.create(loc, elty, val, lidx)); } } - } else if (auto smt = val.getType().dyn_cast()) { + } else if (auto smt = llvm::dyn_cast(val.getType())) { assert(smt.getShape().size() <= 2); auto pt = toStore.val.getType().cast(); mlir::Type elty; - if (auto at = pt.getElementType().dyn_cast()) { + if (auto at = llvm::dyn_cast(pt.getElementType())) { elty = at.getElementType(); assert(smt.getShape().back() == at.getNumElements()); } else { - auto st = pt.getElementType().dyn_cast(); + auto st = llvm::dyn_cast(pt.getElementType()); elty = st.getBody()[0]; assert(smt.getShape().back() == (ssize_t)st.getBody().size()); } diff --git a/tools/cgeist/Lib/clang-mlir.cc b/tools/cgeist/Lib/clang-mlir.cc index 229be553fd92..5d4281e8ac6d 100644 --- a/tools/cgeist/Lib/clang-mlir.cc +++ b/tools/cgeist/Lib/clang-mlir.cc @@ -77,7 +77,7 @@ ValueCategory MLIRScanner::createComplexFloat(mlir::Location loc, OpBuilder abuilder(builder.getContext()); abuilder.setInsertionPointToStart(allocationScope); mlir::Value result; - if (auto MT = elty.dyn_cast()) { + if (auto MT = llvm::dyn_cast(elty)) { mt = elty; elty = MT.getElementType(); ref = true; @@ -109,7 +109,7 @@ ValueCategory MLIRScanner::createComplexFloat(mlir::Location loc, ValueCategory MLIRScanner::getComplexPartRef(mlir::Location loc, mlir::Value val, int fnum) { - if (auto MT = val.getType().dyn_cast()) { + if (auto MT = llvm::dyn_cast(val.getType())) { if (MT.getElementType().isa() && MT.getShape().size() == 1) { val = builder.create( @@ -119,7 +119,7 @@ ValueCategory MLIRScanner::getComplexPartRef(mlir::Location loc, val); } } - if (auto mt = val.getType().dyn_cast()) { + if (auto mt = llvm::dyn_cast(val.getType())) { auto shape = std::vector(mt.getShape()); assert(shape.size() == 2); shape.erase(shape.begin()); @@ -135,9 +135,9 @@ ValueCategory MLIRScanner::getComplexPartRef(mlir::Location loc, si = builder.create(loc, mt1, si, getConstantIndex(fnum)); return ValueCategory(si, /*isReference*/ true); - } else if (auto PT = val.getType().dyn_cast()) { + } else if (auto PT = llvm::dyn_cast(val.getType())) { mlir::Type ET; - if (auto ST = PT.getElementType().dyn_cast()) { + if (auto ST = llvm::dyn_cast(PT.getElementType())) { ET = ST.getBody()[fnum]; } else { ET = PT.getElementType() @@ -159,7 +159,7 @@ ValueCategory MLIRScanner::getComplexPartRef(mlir::Location loc, /// Get real (fnum = 0) or imaginary (fnum = 1) part of a complex float mlir::Value MLIRScanner::getComplexPart(mlir::Location loc, mlir::Value complex, int fnum) { - if (auto ft = complex.getType().dyn_cast()) { + if (auto ft = llvm::dyn_cast(complex.getType())) { if (fnum == 0) return complex; else @@ -170,9 +170,9 @@ mlir::Value MLIRScanner::getComplexPart(mlir::Location loc, mlir::Value complex, return builder.create(loc, complex, fnum); } auto ref = getComplexPartRef(loc, complex, fnum).val; - if (auto mt = ref.getType().dyn_cast()) { + if (auto mt = llvm::dyn_cast(ref.getType())) { return builder.create(loc, ref); - } else if (auto PT = ref.getType().dyn_cast()) { + } else if (auto PT = llvm::dyn_cast(ref.getType())) { return builder.create(loc, ref); } else { assert(0); @@ -415,12 +415,12 @@ void MLIRScanner::init(mlir::func::FuncOp function, const FunctionDecl *fd) { if (D->getParent()->isUnion() && D->isDefaulted()) { mlir::Value V = ThisVal.val; assert(V); - if (auto MT = V.getType().dyn_cast()) { + if (auto MT = llvm::dyn_cast(V.getType())) { V = builder.create( loc, LLVM::LLVMPointerType::get(MT.getElementType()), V); } mlir::Value src = function.getArgument(1); - if (auto MT = src.getType().dyn_cast()) { + if (auto MT = llvm::dyn_cast(src.getType())) { src = builder.create( loc, LLVM::LLVMPointerType::get(MT.getElementType()), src); } @@ -608,7 +608,7 @@ MLIRScanner::VisitExtVectorElementExpr(clang::ExtVectorElementExpr *expr) { builder.create(exprLoc, indices[0], 32), }; - if (const auto pt = et.dyn_cast()) { + if (const auto pt = llvm::dyn_cast(et)) { auto pt0 = pt.getElementType().cast().getElementType(); base.val = builder.create( @@ -616,7 +616,7 @@ MLIRScanner::VisitExtVectorElementExpr(clang::ExtVectorElementExpr *expr) { base.val, idxs); result = ValueCategory(base.val, true); - } else if (const auto mt = et.dyn_cast()) { + } else if (const auto mt = llvm::dyn_cast(et)) { auto shape = std::vector(mt.getShape()); if (shape.size() == 1) { @@ -642,7 +642,7 @@ MLIRScanner::VisitExtVectorElementExpr(clang::ExtVectorElementExpr *expr) { ValueCategory MLIRScanner::VisitConstantExpr(clang::ConstantExpr *expr) { auto sv = Visit(expr->getSubExpr()); - if (auto ty = getMLIRType(expr->getType()).dyn_cast()) { + if (auto ty = llvm::dyn_cast(getMLIRType(expr->getType()))) { if (expr->hasAPValueResult()) { return ValueCategory(builder.create( getMLIRLocation(expr->getExprLoc()), @@ -699,7 +699,7 @@ MLIRScanner::VisitImaginaryLiteral(clang::ImaginaryLiteral *expr) { auto loc = getMLIRLocation(expr->getExprLoc()); auto convertedType = getMLIRType(expr->getType()); mlir::FloatType fty; - if (auto mt = convertedType.dyn_cast()) { + if (auto mt = llvm::dyn_cast(convertedType)) { auto elty = mt.getElementType(); if (auto ST = dyn_cast(elty)) { fty = ST.getBody()[0].cast(); @@ -743,21 +743,21 @@ MLIRScanner::VisitImplicitValueInitExpr(clang::ImplicitValueInitExpr *decl) { auto Mty = getMLIRType(decl->getType()); auto loc = getMLIRLocation(decl->getExprLoc()); - if (auto FT = Mty.dyn_cast()) + if (auto FT = llvm::dyn_cast(Mty)) return ValueCategory(builder.create( loc, APFloat(FT.getFloatSemantics(), "0"), FT), /*isReference*/ false); - if (auto IT = Mty.dyn_cast()) + if (auto IT = llvm::dyn_cast(Mty)) return ValueCategory(builder.create(loc, 0, IT), /*isReference*/ false); - if (auto MT = Mty.dyn_cast()) + if (auto MT = llvm::dyn_cast(Mty)) return ValueCategory( builder.create( loc, MT, builder.create( loc, LLVM::LLVMPointerType::get(builder.getI8Type()))), false); - if (auto PT = Mty.dyn_cast()) + if (auto PT = llvm::dyn_cast(Mty)) return ValueCategory(builder.create(loc, PT), false); for (auto child : decl->children()) { child->dump(); @@ -777,7 +777,7 @@ mlir::Attribute MLIRScanner::InitializeValueByInitListExpr(mlir::Value toInit, bool inner = false; if (isa(PTT) || isa(PTT)) { - if (auto mt = toInit.getType().dyn_cast()) { + if (auto mt = llvm::dyn_cast(toInit.getType())) { inner = true; } } @@ -794,7 +794,7 @@ mlir::Attribute MLIRScanner::InitializeValueByInitListExpr(mlir::Value toInit, if (InitListExpr *initListExpr = dyn_cast(expr)) { if (inner) { - if (auto mt = toInit.getType().dyn_cast()) { + if (auto mt = llvm::dyn_cast(toInit.getType())) { auto shape = std::vector(mt.getShape()); shape.erase(shape.begin()); auto mt0 = mlir::MemRefType::get(shape, mt.getElementType(), @@ -807,17 +807,17 @@ mlir::Attribute MLIRScanner::InitializeValueByInitListExpr(mlir::Value toInit, unsigned num = 0; if (initListExpr->hasArrayFiller()) { - if (auto MT = toInit.getType().dyn_cast()) { + if (auto MT = llvm::dyn_cast(toInit.getType())) { auto shape = MT.getShape(); assert(shape.size() > 0); assert(shape[0] != ShapedType::kDynamic); num = shape[0]; } else if (auto PT = - toInit.getType().dyn_cast()) { - if (auto AT = PT.getElementType().dyn_cast()) { + llvm::dyn_cast(toInit.getType())) { + if (auto AT = llvm::dyn_cast(PT.getElementType())) { num = AT.getNumElements(); } else if (auto AT = - PT.getElementType().dyn_cast()) { + llvm::dyn_cast(PT.getElementType())) { num = AT.getBody().size(); } else { toInit.getType().dump(); @@ -834,7 +834,7 @@ mlir::Attribute MLIRScanner::InitializeValueByInitListExpr(mlir::Value toInit, SmallVector attrs; bool allSub = true; - if (auto mt = toInit.getType().dyn_cast()) { + if (auto mt = llvm::dyn_cast(toInit.getType())) { auto shape = std::vector(mt.getShape()); if (shape.size() == 0) { auto ET = mt.getElementType(); @@ -853,7 +853,7 @@ mlir::Attribute MLIRScanner::InitializeValueByInitListExpr(mlir::Value toInit, for (unsigned i = 0, e = num; i < e; ++i) { mlir::Value next; - if (auto mt = toInit.getType().dyn_cast()) { + if (auto mt = llvm::dyn_cast(toInit.getType())) { auto shape = std::vector(mt.getShape()); assert(shape.size() > 0); shape[0] = ShapedType::kDynamic; @@ -866,9 +866,9 @@ mlir::Attribute MLIRScanner::InitializeValueByInitListExpr(mlir::Value toInit, auto PT = toInit.getType().cast(); auto ET = PT.getElementType(); mlir::Type nextType; - if (auto ST = ET.dyn_cast()) + if (auto ST = llvm::dyn_cast(ET)) nextType = ST.getBody()[i]; - else if (auto AT = ET.dyn_cast()) + else if (auto AT = llvm::dyn_cast(ET)) nextType = AT.getElementType(); else assert(0 && "unknown inner type"); @@ -900,7 +900,7 @@ mlir::Attribute MLIRScanner::InitializeValueByInitListExpr(mlir::Value toInit, } if (!allSub) return mlir::DenseElementsAttr(); - if (auto mt = toInit.getType().dyn_cast()) { + if (auto mt = llvm::dyn_cast(toInit.getType())) { std::vector shape(mt.getShape()); assert(shape.size() > 0); shape[0] = num; @@ -915,7 +915,7 @@ mlir::Attribute MLIRScanner::InitializeValueByInitListExpr(mlir::Value toInit, ValueCategory(toInit, /*isReference*/ true) .store(loc, builder, sub, isArray); if (!sub.isReference) - if (auto mt = toInit.getType().dyn_cast()) { + if (auto mt = llvm::dyn_cast(toInit.getType())) { if (auto cop = sub.val.getDefiningOp()) return DenseElementsAttr::get( RankedTensorType::get(std::vector({1}), @@ -1246,11 +1246,11 @@ ValueCategory MLIRScanner::VisitLambdaExpr(clang::LambdaExpr *expr) { bool isArray = false; Glob.getMLIRType(expr->getCallOperator()->getThisObjectType(), &isArray); - if (auto PT = t.dyn_cast()) { + if (auto PT = llvm::dyn_cast(t)) { LLVMABI = true; t = PT.getElementType(); } - if (auto mt = t.dyn_cast()) { + if (auto mt = llvm::dyn_cast(t)) { auto shape = std::vector(mt.getShape()); if (!isArray) { t = mt.getElementType(); @@ -1313,7 +1313,7 @@ ValueCategory MLIRScanner::VisitLambdaExpr(clang::LambdaExpr *expr) { auto val = result.val; - if (auto mt = val.getType().dyn_cast()) { + if (auto mt = llvm::dyn_cast(val.getType())) { auto shape = std::vector(mt.getShape()); shape[0] = ShapedType::kDynamic; val = builder.create( @@ -1401,8 +1401,8 @@ ValueCategory MLIRScanner::VisitCXXNewExpr(clang::CXXNewExpr *expr) { if (!expr->placement_arguments().empty()) { mlir::Value val = Visit(*expr->placement_arg_begin()).getValue(loc, builder); - if (auto mt = ty.dyn_cast()) { - if (auto mtin = val.getType().dyn_cast()) { + if (auto mt = llvm::dyn_cast(ty)) { + if (auto mtin = llvm::dyn_cast(val.getType())) { val = builder.create( loc, LLVM::LLVMPointerType::get(mtin.getElementType(), @@ -1422,7 +1422,7 @@ ValueCategory MLIRScanner::VisitCXXNewExpr(clang::CXXNewExpr *expr) { PT.getAddressSpace()), alloc); } - } else if (auto mt = ty.dyn_cast()) { + } else if (auto mt = llvm::dyn_cast(ty)) { auto shape = std::vector(mt.getShape()); mlir::Value args[1] = {count}; arrayCons = alloc = builder.create(loc, mt, args); @@ -1509,14 +1509,14 @@ MLIRScanner::VisitCXXScalarValueInitExpr(clang::CXXScalarValueInitExpr *expr) { if (melem.isa()) return ValueCategory(builder.create(loc, 0, melem), false); - else if (auto MT = melem.dyn_cast()) + else if (auto MT = llvm::dyn_cast(melem)) return ValueCategory( builder.create( loc, MT, builder.create( loc, LLVM::LLVMPointerType::get(builder.getI8Type()))), false); - else if (auto PT = melem.dyn_cast()) + else if (auto PT = llvm::dyn_cast(melem)) return ValueCategory(builder.create(loc, PT), false); else { if (!melem.isa()) @@ -1635,7 +1635,7 @@ ValueCategory MLIRScanner::CommonArrayToPointer(mlir::Location loc, ValueCategory scalar) { assert(scalar.val); assert(scalar.isReference); - if (auto PT = scalar.val.getType().dyn_cast()) { + if (auto PT = llvm::dyn_cast(scalar.val.getType())) { if (PT.getElementType().isa()) return ValueCategory(scalar.val, /*isRef*/ false); mlir::Value vec[2] = {builder.create(loc, 0, 32), @@ -1918,8 +1918,8 @@ MLIRScanner::EmitGPUCallExpr(clang::CallExpr *expr) { sub = BC->getSubExpr(); { auto dst = Visit(sub).getValue(loc, builder); - if (auto omt = dst.getType().dyn_cast()) { - if (auto mt = omt.getElementType().dyn_cast()) { + if (auto omt = llvm::dyn_cast(dst.getType())) { + if (auto mt = llvm::dyn_cast(omt.getElementType())) { auto shape = std::vector(mt.getShape()); auto elemSize = getTypeSize( @@ -2133,7 +2133,7 @@ ValueCategory MLIRScanner::VisitUnaryOperator(clang::UnaryOperator *U) { assert(sub.val); mlir::Value val = sub.getValue(loc, builder); - if (auto MT = val.getType().dyn_cast()) { + if (auto MT = llvm::dyn_cast(val.getType())) { val = builder.create( loc, LLVM::LLVMPointerType::get(MT.getElementType(), @@ -2142,7 +2142,7 @@ ValueCategory MLIRScanner::VisitUnaryOperator(clang::UnaryOperator *U) { } auto postTy = getMLIRType(U->getType()).cast(); - if (auto LT = val.getType().dyn_cast()) { + if (auto LT = llvm::dyn_cast(val.getType())) { auto nullptr_llvm = builder.create(loc, LT); mlir::Value ne = builder.create( loc, mlir::LLVM::ICmpPredicate::eq, val, nullptr_llvm); @@ -2211,7 +2211,7 @@ ValueCategory MLIRScanner::VisitUnaryOperator(clang::UnaryOperator *U) { case clang::UnaryOperator::Opcode::UO_Minus: { mlir::Value val = sub.getValue(loc, builder); auto ty = val.getType(); - if (auto ft = ty.dyn_cast()) { + if (auto ft = llvm::dyn_cast(ty)) { if (auto CI = val.getDefiningOp()) { auto api = CI.getValue().cast().getValue(); return ValueCategory(builder.create( @@ -2242,7 +2242,7 @@ ValueCategory MLIRScanner::VisitUnaryOperator(clang::UnaryOperator *U) { auto ty = prev.getType(); mlir::Value next; - if (auto ft = ty.dyn_cast()) { + if (auto ft = llvm::dyn_cast(ty)) { if (prev.getType() != ty) { U->dump(); llvm::errs() << " ty: " << ty << "prev: " << prev << "\n"; @@ -2252,7 +2252,7 @@ ValueCategory MLIRScanner::VisitUnaryOperator(clang::UnaryOperator *U) { loc, prev, builder.create( loc, APFloat(ft.getFloatSemantics(), "1"), ft)); - } else if (auto mt = ty.dyn_cast()) { + } else if (auto mt = llvm::dyn_cast(ty)) { auto shape = std::vector(mt.getShape()); shape[0] = ShapedType::kDynamic; auto mt0 = mlir::MemRefType::get(shape, mt.getElementType(), @@ -2260,7 +2260,7 @@ ValueCategory MLIRScanner::VisitUnaryOperator(clang::UnaryOperator *U) { mt.getMemorySpace()); next = builder.create(loc, mt0, prev, getConstantIndex(1)); - } else if (auto pt = ty.dyn_cast()) { + } else if (auto pt = llvm::dyn_cast(ty)) { auto ity = mlir::IntegerType::get(builder.getContext(), 64); next = builder.create( loc, pt, prev, @@ -2294,18 +2294,18 @@ ValueCategory MLIRScanner::VisitUnaryOperator(clang::UnaryOperator *U) { auto prev = sub.getValue(loc, builder); mlir::Value next; - if (auto ft = ty.dyn_cast()) { + if (auto ft = llvm::dyn_cast(ty)) { next = builder.create( loc, prev, builder.create( loc, APFloat(ft.getFloatSemantics(), "1"), ft)); - } else if (auto pt = ty.dyn_cast()) { + } else if (auto pt = llvm::dyn_cast(ty)) { auto ity = mlir::IntegerType::get(builder.getContext(), 64); next = builder.create( loc, pt, prev, std::vector( {builder.create(loc, ShapedType::kDynamic, ity)})); - } else if (auto mt = ty.dyn_cast()) { + } else if (auto mt = llvm::dyn_cast(ty)) { auto shape = std::vector(mt.getShape()); shape[0] = ShapedType::kDynamic; auto mt0 = mlir::MemRefType::get(shape, mt.getElementType(), @@ -2404,7 +2404,7 @@ bool hasAffineArith(Operation *op, AffineExpr &expr, if (!isa(maybeIndexCast)) return false; auto indexCastOperand = maybeIndexCast->getOperand(0); - if (auto blockArg = indexCastOperand.dyn_cast()) { + if (auto blockArg = llvm::dyn_cast(indexCastOperand)) { if (auto affineForOp = dyn_cast( blockArg.getOwner()->getParentOp())) affineForIndVar = affineForOp.getInductionVar(); @@ -2488,7 +2488,7 @@ ValueCategory MLIRScanner::VisitAtomicExpr(clang::AtomicExpr *BO) { auto a0 = Visit(BO->getPtr()).getValue(loc, builder); auto ret = Visit(BO->getVal1()).dereference(loc, builder); mlir::Type ty; - if (auto MT = a0.getType().dyn_cast()) { + if (auto MT = llvm::dyn_cast(a0.getType())) { ty = MT.getElementType(); } else { ty = a0.getType().cast().getElementType(); @@ -2533,7 +2533,7 @@ ValueCategory MLIRScanner::VisitAtomicExpr(clang::AtomicExpr *BO) { Visit(BO->getVal1()).dereference(loc, builder).getValue(loc, builder); auto a2 = Visit(BO->getVal2()).dereference(loc, builder).getValue(loc, builder); - if (auto mt = a0.getType().dyn_cast()) { + if (auto mt = llvm::dyn_cast(a0.getType())) { a0 = builder.create( loc, LLVM::LLVMPointerType::get(mt.getElementType(), @@ -2593,14 +2593,14 @@ ValueCategory MLIRScanner::VisitBinaryOperator(clang::BinaryOperator *BO) { case clang::BinaryOperator::Opcode::BO_LAnd: { mlir::Type types[] = {builder.getIntegerType(1)}; auto cond = lhs.getValue(loc, builder); - if (auto mt = cond.getType().dyn_cast()) { + if (auto mt = llvm::dyn_cast(cond.getType())) { cond = builder.create( loc, LLVM::LLVMPointerType::get(mt.getElementType(), mt.getMemorySpaceAsInt()), cond); } - if (auto LT = cond.getType().dyn_cast()) { + if (auto LT = llvm::dyn_cast(cond.getType())) { auto nullptr_llvm = builder.create(loc, LT); cond = builder.create( loc, mlir::LLVM::ICmpPredicate::ne, cond, nullptr_llvm); @@ -2625,7 +2625,7 @@ ValueCategory MLIRScanner::VisitBinaryOperator(clang::BinaryOperator *BO) { auto rhs = Visit(BO->getRHS()).getValue(loc, builder); assert(rhs != nullptr); - if (auto LT = rhs.getType().dyn_cast()) { + if (auto LT = llvm::dyn_cast(rhs.getType())) { auto nullptr_llvm = builder.create(loc, LT); rhs = builder.create( loc, mlir::LLVM::ICmpPredicate::ne, rhs, nullptr_llvm); @@ -2809,11 +2809,11 @@ ValueCategory MLIRScanner::VisitBinaryOperator(clang::BinaryOperator *BO) { auto lhs_v = lhs.getValue(loc, builder); auto rhs_v = rhs.getValue(loc, builder); - if (auto mt = lhs_v.getType().dyn_cast()) { + if (auto mt = llvm::dyn_cast(lhs_v.getType())) { lhs_v = builder.create( loc, LLVM::LLVMPointerType::get(mt.getElementType()), lhs_v); } - if (auto mt = rhs_v.getType().dyn_cast()) { + if (auto mt = llvm::dyn_cast(rhs_v.getType())) { rhs_v = builder.create( loc, LLVM::LLVMPointerType::get(mt.getElementType()), rhs_v); } @@ -2913,7 +2913,7 @@ ValueCategory MLIRScanner::VisitBinaryOperator(clang::BinaryOperator *BO) { } else if (rhs_v.getType().isa()) { return emitSubindex(rhs_v, lhs_v); } else if (auto pt = - lhs_v.getType().dyn_cast()) { + llvm::dyn_cast(lhs_v.getType())) { return ValueCategory( builder.create(loc, pt, lhs_v, std::vector({rhs_v})), @@ -2937,7 +2937,7 @@ ValueCategory MLIRScanner::VisitBinaryOperator(clang::BinaryOperator *BO) { } auto lhs_v = lhs.getValue(loc, builder); auto rhs_v = rhs.getValue(loc, builder); - if (auto mt = lhs_v.getType().dyn_cast()) { + if (auto mt = llvm::dyn_cast(lhs_v.getType())) { mlir::Type innerType = mt.getElementType(); auto shape = mt.getShape(); for (size_t i = 1; i < shape.size(); i++) @@ -2945,7 +2945,7 @@ ValueCategory MLIRScanner::VisitBinaryOperator(clang::BinaryOperator *BO) { lhs_v = builder.create( loc, LLVM::LLVMPointerType::get(innerType), lhs_v); } - if (auto mt = rhs_v.getType().dyn_cast()) { + if (auto mt = llvm::dyn_cast(rhs_v.getType())) { mlir::Type innerType = mt.getElementType(); auto shape = mt.getShape(); for (size_t i = 1; i < shape.size(); i++) @@ -2958,8 +2958,8 @@ ValueCategory MLIRScanner::VisitBinaryOperator(clang::BinaryOperator *BO) { return ValueCategory(builder.create(loc, lhs_v, rhs_v), /*isReference*/ false); } else if (auto pt = - lhs_v.getType().dyn_cast()) { - if (auto IT = rhs_v.getType().dyn_cast()) { + llvm::dyn_cast(lhs_v.getType())) { + if (auto IT = llvm::dyn_cast(rhs_v.getType())) { mlir::Value vals[1] = {builder.create( loc, builder.create(loc, 0, IT.getWidth()), rhs_v)}; return ValueCategory( @@ -2990,13 +2990,13 @@ ValueCategory MLIRScanner::VisitBinaryOperator(clang::BinaryOperator *BO) { assert(lhs.isReference); mlir::Value tostore = rhs.getValue(loc, builder); mlir::Type subType; - if (auto PT = lhs.val.getType().dyn_cast()) + if (auto PT = llvm::dyn_cast(lhs.val.getType())) subType = PT.getElementType(); else subType = lhs.val.getType().cast().getElementType(); if (tostore.getType() != subType) { - if (auto prevTy = tostore.getType().dyn_cast()) { - if (auto postTy = subType.dyn_cast()) { + if (auto prevTy = llvm::dyn_cast(tostore.getType())) { + if (auto postTy = llvm::dyn_cast(subType)) { bool signedType = true; if (auto bit = dyn_cast(&*BO->getType())) { if (bit->isUnsignedInteger()) @@ -3042,7 +3042,7 @@ ValueCategory MLIRScanner::VisitBinaryOperator(clang::BinaryOperator *BO) { return lhs; } auto prev = lhs.getValue(loc, builder); - if (auto postTy = prev.getType().dyn_cast()) { + if (auto postTy = llvm::dyn_cast(prev.getType())) { mlir::Value rhsV = rhs.getValue(loc, builder); auto prevTy = rhsV.getType().cast(); if (prevTy == postTy) { @@ -3054,11 +3054,11 @@ ValueCategory MLIRScanner::VisitBinaryOperator(clang::BinaryOperator *BO) { assert(rhsV.getType() == prev.getType()); result = builder.create(loc, prev, rhsV); } else if (auto pt = - prev.getType().dyn_cast()) { + llvm::dyn_cast(prev.getType())) { result = builder.create( loc, pt, prev, std::vector({rhs.getValue(loc, builder)})); - } else if (auto postTy = prev.getType().dyn_cast()) { + } else if (auto postTy = llvm::dyn_cast(prev.getType())) { mlir::Value rhsV = rhs.getValue(loc, builder); auto prevTy = rhsV.getType().cast(); if (prevTy == postTy) { @@ -3073,7 +3073,7 @@ ValueCategory MLIRScanner::VisitBinaryOperator(clang::BinaryOperator *BO) { } assert(rhsV.getType() == prev.getType()); result = builder.create(loc, prev, rhsV); - } else if (auto postTy = prev.getType().dyn_cast()) { + } else if (auto postTy = llvm::dyn_cast(prev.getType())) { mlir::Value rhsV = rhs.getValue(loc, builder); auto shape = std::vector(postTy.getShape()); shape[0] = ShapedType::kDynamic; @@ -3303,7 +3303,7 @@ ValueCategory MLIRScanner::CommonFieldLookup(mlir::Location loc, } } - if (auto mt = val.getType().dyn_cast()) { + if (auto mt = llvm::dyn_cast(val.getType())) { auto shape = std::vector(mt.getShape()); if (shape.size() > 1) { shape.erase(shape.begin()); @@ -3342,7 +3342,7 @@ ValueCategory MLIRScanner::CommonFieldLookup(mlir::Location loc, << " ST: " << *ST << "\n"; } mlir::Type ET; - if (auto ST = PT.getElementType().dyn_cast()) { + if (auto ST = llvm::dyn_cast(PT.getElementType())) { ET = ST.getBody()[fnum]; } else { ET = PT.getElementType().cast().getElementType(); @@ -3356,7 +3356,7 @@ ValueCategory MLIRScanner::CommonFieldLookup(mlir::Location loc, Glob.CGM.getContext().getPointerType(FD->getType()), &isArray); assert(!isArray); if (rd->isUnion()) { - if (auto PT2 = subType.dyn_cast()) + if (auto PT2 = llvm::dyn_cast(subType)) commonGEP = builder.create( loc, mlir::LLVM::LLVMPointerType::get(PT2.getElementType(), @@ -3372,7 +3372,7 @@ ValueCategory MLIRScanner::CommonFieldLookup(mlir::Location loc, commonGEP); } } else { - if (auto mt = subType.dyn_cast()) { + if (auto mt = llvm::dyn_cast(subType)) { commonGEP = builder.create( loc, mlir::MemRefType::get( @@ -3627,7 +3627,7 @@ mlir::Value MLIRScanner::GetAddressOfDerivedClass( } mlir::Value ptr = value; - if (auto PT = ptr.getType().dyn_cast()) { + if (auto PT = llvm::dyn_cast(ptr.getType())) { ptr = builder.create( loc, LLVM::LLVMPointerType::get(builder.getI8Type(), PT.getAddressSpace()), @@ -3643,7 +3643,7 @@ mlir::Value MLIRScanner::GetAddressOfDerivedClass( mlir::Value idx[] = {Offset}; ptr = builder.create(loc, ptr.getType(), ptr, idx); - if (auto PT = nt.dyn_cast()) + if (auto PT = llvm::dyn_cast(nt)) value = builder.create( loc, LLVM::LLVMPointerType::get( @@ -3704,7 +3704,7 @@ mlir::Value MLIRScanner::GetAddressOfBaseClass( if (subIndex) { bool done = false; - if (auto mt = value.getType().dyn_cast()) { + if (auto mt = llvm::dyn_cast(value.getType())) { auto shape = std::vector(mt.getShape()); if (shape.size() > 1) { shape.erase(shape.begin()); @@ -3730,7 +3730,7 @@ mlir::Value MLIRScanner::GetAddressOfBaseClass( auto PT = value.getType().cast(); mlir::Type ET; if (auto ST = - PT.getElementType().dyn_cast()) { + llvm::dyn_cast(PT.getElementType())) { ET = ST.getBody()[fnum]; } else { ET = PT.getElementType() @@ -3744,8 +3744,8 @@ mlir::Value MLIRScanner::GetAddressOfBaseClass( } } - auto pt = nt.dyn_cast(); - if (auto opt = value.getType().dyn_cast()) { + auto pt = llvm::dyn_cast(nt); + if (auto opt = llvm::dyn_cast(value.getType())) { if (!pt) { value = builder.create(loc, nt, value); } else { @@ -3820,14 +3820,14 @@ ValueCategory MLIRScanner::VisitCastExpr(CastExpr *E) { if (E->getCastKind() != clang::CastKind::CK_UncheckedDerivedToBase && !isa(E->IgnoreParens())) { mlir::Value ptr = val; - if (auto MT = ptr.getType().dyn_cast()) + if (auto MT = llvm::dyn_cast(ptr.getType())) ptr = builder.create( loc, LLVM::LLVMPointerType::get(MT.getElementType()), ptr); mlir::Value nullptr_llvm = builder.create(loc, ptr.getType()); auto ne = builder.create( loc, mlir::LLVM::ICmpPredicate::ne, ptr, nullptr_llvm); - if (auto MT = ptr.getType().dyn_cast()) + if (auto MT = llvm::dyn_cast(ptr.getType())) nullptr_llvm = builder.create(loc, MT, nullptr_llvm); val = builder.create(loc, ne, ptr, nullptr_llvm); @@ -3849,12 +3849,12 @@ ValueCategory MLIRScanner::VisitCastExpr(CastExpr *E) { /* if (ShouldNullCheckClassCastValue(E)) { mlir::Value ptr = val; - if (auto MT = ptr.getType().dyn_cast()) + if (auto MT = llvm::dyn_cast(ptr.getType())) ptr = builder.create(loc, LLVM::LLVMPointerType::get(MT.getElementType()), ptr); auto nullptr_llvm = builder.create(loc, ptr.getType()); auto ne = builder.create( loc, mlir::LLVM::ICmpPredicate::ne, ptr, - nullptr_llvm); if (auto MT = ptr.getType().dyn_cast()) + nullptr_llvm); if (auto MT = llvm::dyn_cast(ptr.getType())) nullptr_llvm = builder.create(loc, MT, nullptr_llvm); val = builder.create(loc, ne, val, nullptr_llvm); @@ -3869,9 +3869,9 @@ ValueCategory MLIRScanner::VisitCastExpr(CastExpr *E) { } auto scalar = se.val; assert(se.isReference); - if (auto spt = scalar.getType().dyn_cast()) { + if (auto spt = llvm::dyn_cast(scalar.getType())) { auto nt = getMLIRType(E->getType()); - LLVM::LLVMPointerType pt = nt.dyn_cast(); + LLVM::LLVMPointerType pt = llvm::dyn_cast(nt); if (!pt) { return ValueCategory( builder.create(loc, nt, scalar), @@ -3891,11 +3891,11 @@ ValueCategory MLIRScanner::VisitCastExpr(CastExpr *E) { auto mlirty = getMLIRType(Glob.CGM.getContext().getLValueReferenceType(E->getType())); - if (auto PT = mlirty.dyn_cast()) { + if (auto PT = llvm::dyn_cast(mlirty)) { return ValueCategory( builder.create(loc, PT, scalar), /*isReference*/ true); - } else if (auto mt = mlirty.dyn_cast()) { + } else if (auto mt = llvm::dyn_cast(mlirty)) { auto ty = mlir::MemRefType::get(mt.getShape(), mt.getElementType(), MemRefLayoutAttrInterface(), ut.getMemorySpace()); @@ -3940,7 +3940,7 @@ ValueCategory MLIRScanner::VisitCastExpr(CastExpr *E) { if (sr->getDecl()->getIdentifier() && sr->getDecl()->getName() == "polybench_alloc_data") { if (auto mt = - getMLIRType(E->getType()).dyn_cast()) { + llvm::dyn_cast(getMLIRType(E->getType()))) { auto shape = std::vector(mt.getShape()); // shape.erase(shape.begin()); auto mt0 = mlir::MemRefType::get(shape, mt.getElementType(), @@ -3960,7 +3960,7 @@ ValueCategory MLIRScanner::VisitCastExpr(CastExpr *E) { (sr->getDecl()->getName() == "malloc" || sr->getDecl()->getName() == "calloc")) if (auto mt = - getMLIRType(E->getType()).dyn_cast()) { + llvm::dyn_cast(getMLIRType(E->getType()))) { auto shape = std::vector(mt.getShape()); auto elemSize = getTypeSize( @@ -4011,9 +4011,9 @@ ValueCategory MLIRScanner::VisitCastExpr(CastExpr *E) { E->dump(); } auto scalar = se.getValue(loc, builder); - if (auto spt = scalar.getType().dyn_cast()) { + if (auto spt = llvm::dyn_cast(scalar.getType())) { auto nt = getMLIRType(E->getType()); - LLVM::LLVMPointerType pt = nt.dyn_cast(); + LLVM::LLVMPointerType pt = llvm::dyn_cast(nt); if (!pt) { return ValueCategory( builder.create(loc, nt, scalar), @@ -4032,11 +4032,11 @@ ValueCategory MLIRScanner::VisitCastExpr(CastExpr *E) { auto ut = scalar.getType().cast(); auto mlirty = getMLIRType(E->getType()); - if (auto PT = mlirty.dyn_cast()) { + if (auto PT = llvm::dyn_cast(mlirty)) { return ValueCategory( builder.create(loc, PT, scalar), /*isReference*/ false); - } else if (auto mt = mlirty.dyn_cast()) { + } else if (auto mt = llvm::dyn_cast(mlirty)) { auto ty = mlir::MemRefType::get(mt.getShape(), mt.getElementType(), MemRefLayoutAttrInterface(), ut.getMemorySpace()); @@ -4260,16 +4260,16 @@ ValueCategory MLIRScanner::VisitCastExpr(CastExpr *E) { mlir::FloatType postScalarTy; auto prevTy = complex.getType(); auto postTy = getMLIRType(E->getType()); - if (auto mt = postTy.dyn_cast()) { + if (auto mt = llvm::dyn_cast(postTy)) { postScalarTy = mt.getElementType().cast(); - } else if (auto ST = postTy.dyn_cast()) { + } else if (auto ST = llvm::dyn_cast(postTy)) { postScalarTy = ST.getBody()[0].cast(); } else { assert(0 && "unexpected complex type\n"); } - if (auto mt = prevTy.dyn_cast()) { + if (auto mt = llvm::dyn_cast(prevTy)) { prevScalarTy = mt.getElementType().cast(); - } else if (auto ST = prevTy.dyn_cast()) { + } else if (auto ST = llvm::dyn_cast(prevTy)) { prevScalarTy = ST.getBody()[0].cast(); } else { assert(0 && "unexpected complex type\n"); @@ -4325,11 +4325,11 @@ ValueCategory MLIRScanner::VisitCastExpr(CastExpr *E) { } case clang::CastKind::CK_PointerToBoolean: { auto scalar = Visit(E->getSubExpr()).getValue(loc, builder); - if (auto mt = scalar.getType().dyn_cast()) { + if (auto mt = llvm::dyn_cast(scalar.getType())) { scalar = builder.create( loc, LLVM::LLVMPointerType::get(mt.getElementType()), scalar); } - if (auto LT = scalar.getType().dyn_cast()) { + if (auto LT = llvm::dyn_cast(scalar.getType())) { auto nullptr_llvm = builder.create(loc, LT); auto ne = builder.create( loc, mlir::LLVM::ICmpPredicate::ne, scalar, nullptr_llvm); @@ -4342,11 +4342,11 @@ ValueCategory MLIRScanner::VisitCastExpr(CastExpr *E) { } case clang::CastKind::CK_PointerToIntegral: { auto scalar = Visit(E->getSubExpr()).getValue(loc, builder); - if (auto mt = scalar.getType().dyn_cast()) { + if (auto mt = llvm::dyn_cast(scalar.getType())) { scalar = builder.create( loc, LLVM::LLVMPointerType::get(mt.getElementType()), scalar); } - if (auto LT = scalar.getType().dyn_cast()) { + if (auto LT = llvm::dyn_cast(scalar.getType())) { auto mlirType = getMLIRType(E->getType()); auto val = builder.create(loc, mlirType, scalar); return ValueCategory(val, /*isReference*/ false); @@ -4426,7 +4426,7 @@ ValueCategory MLIRScanner::VisitCastExpr(CastExpr *E) { auto convertedType = getMLIRType(E->getType()); auto real = sub.getValue(loc, builder); mlir::FloatType fty; - if (auto mt = convertedType.dyn_cast()) { + if (auto mt = llvm::dyn_cast(convertedType)) { auto elty = mt.getElementType(); if (auto ST = dyn_cast(elty)) { fty = ST.getBody()[0].cast(); @@ -4456,14 +4456,14 @@ MLIRScanner::VisitConditionalOperator(clang::ConditionalOperator *E) { auto loc = getMLIRLocation(E->getExprLoc()); auto cond = Visit(E->getCond()).getValue(loc, builder); assert(cond != nullptr); - if (auto mt = cond.getType().dyn_cast()) { + if (auto mt = llvm::dyn_cast(cond.getType())) { cond = builder.create( loc, LLVM::LLVMPointerType::get(mt.getElementType(), mt.getMemorySpaceAsInt()), cond); } - if (auto LT = cond.getType().dyn_cast()) { + if (auto LT = llvm::dyn_cast(cond.getType())) { auto nullptr_llvm = builder.create(loc, LT); cond = builder.create( loc, mlir::LLVM::ICmpPredicate::ne, cond, nullptr_llvm); @@ -4507,7 +4507,7 @@ MLIRScanner::VisitConditionalOperator(clang::ConditionalOperator *E) { truev = trueExpr.val; } else { if (trueExpr.isReference) - if (auto mt = trueExpr.val.getType().dyn_cast()) + if (auto mt = llvm::dyn_cast(trueExpr.val.getType())) if (mt.getShape().size() != 1) { E->dump(); E->getTrueExpr()->dump(); @@ -5107,7 +5107,7 @@ MLIRASTConsumer::GetOrCreateMLIRFunction(const FunctionDecl *FD, bool isArray = false; // isa(CC->getThisType()); getMLIRType(CC->getThisObjectType(), &isArray); - if (auto mt = t.dyn_cast()) { + if (auto mt = llvm::dyn_cast(t)) { auto shape = std::vector(mt.getShape()); // shape[0] = 1; t = mlir::MemRefType::get(shape, mt.getElementType(), @@ -5513,7 +5513,7 @@ mlir::Type MLIRASTConsumer::getMLIRType(clang::QualType qt, bool *implicitRef, } // If -memref-fullrank is unset or it cannot be fulfilled. - auto mt = mlirty.dyn_cast(); + auto mt = llvm::dyn_cast(mlirty); auto shape2 = std::vector(mt.getShape()); shape2[0] = ShapedType::kDynamic; return mlir::MemRefType::get(shape2, mt.getElementType(), diff --git a/tools/polymer/lib/Target/OpenScop/ConvertFromOpenScop.cc b/tools/polymer/lib/Target/OpenScop/ConvertFromOpenScop.cc index f360064c42cd..e9826fb9055e 100644 --- a/tools/polymer/lib/Target/OpenScop/ConvertFromOpenScop.cc +++ b/tools/polymer/lib/Target/OpenScop/ConvertFromOpenScop.cc @@ -641,7 +641,7 @@ void Importer::initializeSymbol(mlir::Value val) { /// Symbols that are the block arguments won't be taken care of at this stage. /// initializeFuncOpInterface() should already have done that. - if (mlir::BlockArgument arg = val.dyn_cast()) + if (mlir::BlockArgument arg = llvm::dyn_cast(val)) return; // This defOp should be cloned to the target function, while its operands diff --git a/tools/polymer/lib/Transforms/LoopAnnotate.cc b/tools/polymer/lib/Transforms/LoopAnnotate.cc index 8a6753ce9d2e..2cf5ee15a0e4 100644 --- a/tools/polymer/lib/Transforms/LoopAnnotate.cc +++ b/tools/polymer/lib/Transforms/LoopAnnotate.cc @@ -36,7 +36,7 @@ using namespace polymer; static void annotatePointLoops(ValueRange operands, OpBuilder &b) { for (mlir::Value operand : operands) { // If a loop IV is directly passed into the statement call. - if (BlockArgument arg = operand.dyn_cast()) { + if (BlockArgument arg = llvm::dyn_cast(operand)) { mlir::affine::AffineForOp forOp = dyn_cast(arg.getOwner()->getParentOp()); if (forOp) { diff --git a/tools/polymer/lib/Transforms/LoopExtract.cc b/tools/polymer/lib/Transforms/LoopExtract.cc index 6669bb418c4b..d2ee0bec38b7 100644 --- a/tools/polymer/lib/Transforms/LoopExtract.cc +++ b/tools/polymer/lib/Transforms/LoopExtract.cc @@ -58,7 +58,7 @@ static void getArgs(Operation *parentOp, llvm::SetVector &args) { if (Operation *defOp = operand.getDefiningOp()) { if (!internalOps.contains(defOp)) args.insert(operand); - } else if (BlockArgument bArg = operand.dyn_cast()) { + } else if (BlockArgument bArg = llvm::dyn_cast(operand)) { if (!internalOps.contains(bArg.getOwner()->getParentOp())) args.insert(operand); } else { diff --git a/tools/polymer/lib/Transforms/PlutoTransform.cc b/tools/polymer/lib/Transforms/PlutoTransform.cc index 7e212022cd7c..41e23f2951ba 100644 --- a/tools/polymer/lib/Transforms/PlutoTransform.cc +++ b/tools/polymer/lib/Transforms/PlutoTransform.cc @@ -281,7 +281,7 @@ static void dedupIndexCast(func::FuncOp f) { SmallVector toErase; for (auto &op : entry) { if (auto indexCast = dyn_cast(&op)) { - auto arg = indexCast.getOperand().dyn_cast(); + auto arg = llvm::dyn_cast(indexCast.getOperand()); if (argToCast.count(arg)) { LLVM_DEBUG(dbgs() << "Found duplicated index_cast: " << indexCast << '\n'); diff --git a/tools/polymer/lib/Transforms/Reg2Mem.cc b/tools/polymer/lib/Transforms/Reg2Mem.cc index fdf72c1976aa..658b00f9958e 100644 --- a/tools/polymer/lib/Transforms/Reg2Mem.cc +++ b/tools/polymer/lib/Transforms/Reg2Mem.cc @@ -210,7 +210,7 @@ static void demoteRegisterToMemory(mlir::func::FuncOp f, OpBuilder &b) { // Create the alloca op for the scratchpad. memref::AllocaOp allocaOp = createScratchpadAllocaOp( - val.dyn_cast(), b, &entryBlock); + llvm::dyn_cast(val), b, &entryBlock); // Create the store op that stores val into the scratchpad for future uses. createScratchpadStoreOp(val, allocaOp, b); diff --git a/tools/polymer/lib/Transforms/ScopStmtOpt.cc b/tools/polymer/lib/Transforms/ScopStmtOpt.cc index 3a62ea9dccaf..36a41372dd0f 100644 --- a/tools/polymer/lib/Transforms/ScopStmtOpt.cc +++ b/tools/polymer/lib/Transforms/ScopStmtOpt.cc @@ -370,7 +370,7 @@ struct RewriteScratchpadTypePass // All the operands that are unranked memrefs. SmallVector unranked; for (auto operand : caller.getArgOperands()) - if (MemRefType type = operand.getType().dyn_cast()) + if (MemRefType type = llvm::dyn_cast(operand.getType())) if (!type.hasStaticShape()) unranked.push_back(operand); if (unranked.empty()) From aca43cf5f55f4e3fc47d384c7c7cd378f864e9a5 Mon Sep 17 00:00:00 2001 From: Jeremy Kun Date: Tue, 2 Apr 2024 21:02:50 -0700 Subject: [PATCH 2/4] manually migrate some dyn_cast_or_null --- lib/polygeist/Passes/ConvertPolygeistToLLVM.cpp | 17 +++++++++-------- lib/polygeist/Passes/ParallelLower.cpp | 2 +- lib/polygeist/Passes/PolygeistMem2Reg.cpp | 2 +- tools/cgeist/Lib/CGCall.cc | 2 +- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/polygeist/Passes/ConvertPolygeistToLLVM.cpp b/lib/polygeist/Passes/ConvertPolygeistToLLVM.cpp index 205bcc173648..18a77ab89bbe 100644 --- a/lib/polygeist/Passes/ConvertPolygeistToLLVM.cpp +++ b/lib/polygeist/Passes/ConvertPolygeistToLLVM.cpp @@ -985,9 +985,9 @@ struct CAllocaOpLowering : public AllocLikeOpLowering { ConversionPatternRewriter &rewriter) const override { Location loc = allocaOp.getLoc(); MemRefType originalType = allocaOp.getType(); - auto convertedType = getTypeConverter() - ->convertType(originalType) - .dyn_cast_or_null(); + auto convertedType = + llvm::dyn_cast_or_null( + getTypeConverter()->convertType(originalType)); auto elTy = convertMemrefElementTypeForLLVMPointer( originalType, *this->getTypeConverter()); if (!convertedType || !elTy) @@ -1015,9 +1015,10 @@ struct CAllocOpLowering : public AllocLikeOpLowering { auto module = allocOp->getParentOfType(); Location loc = allocOp.getLoc(); MemRefType originalType = allocOp.getType(); - auto convertedType = getTypeConverter() - ->convertType(originalType) - .dyn_cast_or_null(); + auto convertedType = + llvm::dyn_cast_or_null( + getTypeConverter()->convertType(originalType)); + if (!convertedType) return rewriter.notifyMatchFailure(loc, "unsupported memref type"); if (adaptor.getAlignment() && adaptor.getAlignment().value() != 0) @@ -1197,9 +1198,9 @@ struct CLoadStoreOpLowering : public ConvertOpToLLVMPattern { Location loc = op.getLoc(); MemRefType originalType = op.getMemRefType(); auto convertedType = + llvm::dyn_cast_or_null( this->getTypeConverter() - ->convertType(originalType) - .template dyn_cast_or_null(); + ->convertType(originalType)); if (!convertedType) { (void)rewriter.notifyMatchFailure(loc, "unsupported memref type"); return nullptr; diff --git a/lib/polygeist/Passes/ParallelLower.cpp b/lib/polygeist/Passes/ParallelLower.cpp index 706b9c97bcc6..89b1331aacc8 100644 --- a/lib/polygeist/Passes/ParallelLower.cpp +++ b/lib/polygeist/Passes/ParallelLower.cpp @@ -596,7 +596,7 @@ void ParallelLower::runOnOperation() { container.walk([&](mlir::memref::AllocaOp alop) { if (auto ia = - alop.getType().getMemorySpace().dyn_cast_or_null()) + dyn_cast_or_null(alop.getType().getMemorySpace())) if (ia.getValue() == 5) { builder.setInsertionPointToStart(blockB); auto newAlloca = builder.create( diff --git a/lib/polygeist/Passes/PolygeistMem2Reg.cpp b/lib/polygeist/Passes/PolygeistMem2Reg.cpp index 0e228c1453f6..a827fc20d960 100644 --- a/lib/polygeist/Passes/PolygeistMem2Reg.cpp +++ b/lib/polygeist/Passes/PolygeistMem2Reg.cpp @@ -1102,7 +1102,7 @@ bool PolygeistMem2Reg::forwardStoreToLoad( auto pair = list.front(); auto val = pair.first; if (auto MT = llvm::dyn_cast(val.getType())) { - if (auto ia = MT.getMemorySpace().dyn_cast_or_null()) + if (auto ia = llvm::dyn_cast_or_null(MT.getMemorySpace())) SharedMemAddr = ia.getValue() == 5; } else { auto PT = llvm::dyn_cast(val.getType()); diff --git a/tools/cgeist/Lib/CGCall.cc b/tools/cgeist/Lib/CGCall.cc index e5d029347d7b..4e9d839cdf23 100644 --- a/tools/cgeist/Lib/CGCall.cc +++ b/tools/cgeist/Lib/CGCall.cc @@ -34,7 +34,7 @@ static mlir::Value castCallerMemRefArg(mlir::Value callerArg, mlir::OpBuilder::InsertionGuard guard(b); mlir::Type callerArgType = callerArg.getType(); - if (MemRefType dstTy = calleeArgType.dyn_cast_or_null()) { + if (MemRefType dstTy = llvm::dyn_cast_or_null(calleeArgType)) { MemRefType srcTy = llvm::dyn_cast(callerArgType); if (srcTy && dstTy.getElementType() == srcTy.getElementType() && dstTy.getMemorySpace() == srcTy.getMemorySpace()) { From ec64164f0fa3e96b315468f4020641479ec93027 Mon Sep 17 00:00:00 2001 From: Jeremy Kun Date: Wed, 3 Apr 2024 09:10:19 -0700 Subject: [PATCH 3/4] strip llvm:: prefix --- lib/polygeist/Ops.cpp | 48 ++-- lib/polygeist/Passes/AffineCFG.cpp | 8 +- lib/polygeist/Passes/CanonicalizeFor.cpp | 28 +-- .../Passes/CollectKernelStatistics.cpp | 4 +- lib/polygeist/Passes/ConvertParallelToGPU.cpp | 8 +- .../Passes/ConvertPolygeistToLLVM.cpp | 22 +- lib/polygeist/Passes/ConvertToOpaquePtr.cpp | 12 +- lib/polygeist/Passes/ForBreakToWhile.cpp | 10 +- lib/polygeist/Passes/ParallelLICM.cpp | 4 +- .../Passes/ParallelLoopDistribute.cpp | 10 +- lib/polygeist/Passes/ParallelLoopUnroll.cpp | 2 +- lib/polygeist/Passes/ParallelLower.cpp | 18 +- lib/polygeist/Passes/PolygeistMem2Reg.cpp | 18 +- tools/cgeist/Lib/CGCall.cc | 44 ++-- tools/cgeist/Lib/CGStmt.cc | 16 +- tools/cgeist/Lib/ValueCategory.cc | 28 +-- tools/cgeist/Lib/clang-mlir.cc | 216 +++++++++--------- .../Target/OpenScop/ConvertFromOpenScop.cc | 2 +- tools/polymer/lib/Transforms/LoopAnnotate.cc | 2 +- tools/polymer/lib/Transforms/LoopExtract.cc | 2 +- .../polymer/lib/Transforms/PlutoTransform.cc | 2 +- tools/polymer/lib/Transforms/Reg2Mem.cc | 2 +- tools/polymer/lib/Transforms/ScopStmtOpt.cc | 2 +- 23 files changed, 254 insertions(+), 254 deletions(-) diff --git a/lib/polygeist/Ops.cpp b/lib/polygeist/Ops.cpp index f73cb8ba9ff1..f93e10030f41 100644 --- a/lib/polygeist/Ops.cpp +++ b/lib/polygeist/Ops.cpp @@ -1631,9 +1631,9 @@ class CopySimplification final : public OpRewritePattern { Type elTy = dstTy.getElementType(); size_t width = 1; - if (auto IT = llvm::dyn_cast(elTy)) + if (auto IT = dyn_cast(elTy)) width = IT.getWidth() / 8; - else if (auto FT = llvm::dyn_cast(elTy)) + else if (auto FT = dyn_cast(elTy)) width = FT.getWidth() / 8; else { // TODO extend to llvm compatible type @@ -1734,9 +1734,9 @@ class SetSimplification final : public OpRewritePattern { return failure(); size_t width = 1; - if (auto IT = llvm::dyn_cast(elTy)) + if (auto IT = dyn_cast(elTy)) width = IT.getWidth() / 8; - else if (auto FT = llvm::dyn_cast(elTy)) + else if (auto FT = dyn_cast(elTy)) width = FT.getWidth() / 8; else { // TODO extend to llvm compatible type @@ -1787,7 +1787,7 @@ class SetSimplification final : public OpRewritePattern { SmallVector idxs; Value val; - if (auto IT = llvm::dyn_cast(elTy)) + if (auto IT = dyn_cast(elTy)) val = rewriter.create(op.getLoc(), 0, IT.getWidth()); else { @@ -2479,7 +2479,7 @@ class SelectOfExt final : public OpRewritePattern { LogicalResult matchAndRewrite(arith::SelectOp op, PatternRewriter &rewriter) const override { - auto ty = llvm::dyn_cast(op.getType()); + auto ty = dyn_cast(op.getType()); if (!ty) return failure(); IntegerAttr lhs, rhs; @@ -2589,10 +2589,10 @@ class CmpProp final : public OpRewritePattern { v.getDefiningOp() || v.getDefiningOp(); if (auto extOp = v.getDefiningOp()) - if (auto it = llvm::dyn_cast(extOp.getIn().getType())) + if (auto it = dyn_cast(extOp.getIn().getType())) change |= it.getWidth() == 1; if (auto extOp = v.getDefiningOp()) - if (auto it = llvm::dyn_cast(extOp.getIn().getType())) + if (auto it = dyn_cast(extOp.getIn().getType())) change |= it.getWidth() == 1; } if (!change) { @@ -3175,7 +3175,7 @@ bool valueCmp(Cmp cmp, Value bval, ValueOrInt val) { } } - if (auto baval = llvm::dyn_cast(bval)) { + if (auto baval = dyn_cast(bval)) { if (affine::AffineForOp afFor = dyn_cast(baval.getOwner()->getParentOp())) { auto for_lb = afFor.getLowerBoundMap().getResults()[baval.getArgNumber()]; @@ -3487,7 +3487,7 @@ bool valueCmp(Cmp cmp, AffineExpr expr, size_t numDim, ValueRange operands, // Range is [lb, ub) bool rangeIncludes(Value bval, ValueOrInt lb, ValueOrInt ub) { - if (auto baval = llvm::dyn_cast(bval)) { + if (auto baval = dyn_cast(bval)) { if (affine::AffineForOp afFor = dyn_cast(baval.getOwner()->getParentOp())) { return valueCmp( @@ -3621,7 +3621,7 @@ struct AffineIfSinking : public OpRewritePattern { if (!opd) { return failure(); } - auto ival = llvm::dyn_cast(op.getOperands()[opd.getPosition()]); + auto ival = dyn_cast(op.getOperands()[opd.getPosition()]); if (!ival) { return failure(); } @@ -3663,7 +3663,7 @@ struct AffineIfSinking : public OpRewritePattern { if (!par.getRegion().isAncestor(v.getParentRegion()) || op.getThenRegion().isAncestor(v.getParentRegion())) return; - if (auto ba = llvm::dyn_cast(v)) { + if (auto ba = dyn_cast(v)) { if (ba.getOwner()->getParentOp() == par) { return; } @@ -4285,7 +4285,7 @@ struct MergeNestedAffineParallelIf continue; } if (auto dim = cur.dyn_cast()) { - auto ival = llvm::dyn_cast(operands[dim.getPosition()]); + auto ival = dyn_cast(operands[dim.getPosition()]); if (!ival || ival.getOwner()->getParentOp() != op) { rhs = rhs + dim; if (failure) @@ -4315,7 +4315,7 @@ struct MergeNestedAffineParallelIf if (auto dim = bop.getLHS().dyn_cast()) { auto ival = - llvm::dyn_cast(operands[dim.getPosition()]); + dyn_cast(operands[dim.getPosition()]); if (!ival || ival.getOwner()->getParentOp() != op) { rhs = rhs + bop; // While legal, this may run before parallel merging @@ -4511,7 +4511,7 @@ struct MergeParallelInductions continue; } if (auto dim = cur.dyn_cast()) { - auto ival = llvm::dyn_cast(operands[dim.getPosition()]); + auto ival = dyn_cast(operands[dim.getPosition()]); if (!ival || ival.getOwner()->getParentOp() != op) { rhs = rhs + dim; continue; @@ -4538,7 +4538,7 @@ struct MergeParallelInductions } if (auto dim = bop.getLHS().dyn_cast()) { - auto ival = llvm::dyn_cast(operands[dim.getPosition()]); + auto ival = dyn_cast(operands[dim.getPosition()]); if (!ival || ival.getOwner()->getParentOp() != op) { rhs = rhs + bop; continue; @@ -4983,7 +4983,7 @@ template struct BufferElimination : public OpRewritePattern { auto opd = map.getResults()[0].dyn_cast(); if (!opd) continue; - auto val = llvm::dyn_cast( + auto val = dyn_cast( ((Value)load.getMapOperands()[opd.getPosition()])); if (!val) continue; @@ -5033,7 +5033,7 @@ template struct BufferElimination : public OpRewritePattern { auto opd = map.getResults()[0].dyn_cast(); if (!opd) continue; - auto val = llvm::dyn_cast( + auto val = dyn_cast( ((Value)load.getMapOperands()[opd.getPosition()])); if (!val) continue; @@ -5279,7 +5279,7 @@ struct AffineBufferElimination : public OpRewritePattern { } if (storeIdxs[pair.index()].isValue) { Value auval = storeIdxs[pair.index()].v_val; - BlockArgument bval = llvm::dyn_cast(auval); + BlockArgument bval = dyn_cast(auval); if (!bval) { LLVM_DEBUG(llvm::dbgs() << " + non bval expr " << bval << "\n"); continue; @@ -5337,7 +5337,7 @@ struct AffineBufferElimination : public OpRewritePattern { if (!VI.isValue) continue; auto V = VI.v_val; - auto BA = llvm::dyn_cast(V); + auto BA = dyn_cast(V); if (!BA) { LLVM_DEBUG(llvm::dbgs() << " + non map oper " << V << "\n"); return failure(); @@ -5424,7 +5424,7 @@ struct AffineBufferElimination : public OpRewritePattern { if (!VI.isValue) continue; auto V = VI.v_val; - auto BA = llvm::dyn_cast(V); + auto BA = dyn_cast(V); Operation *c = BA.getOwner()->getParentOp(); if (isa(c) || isa(c)) { Operation *tmp = store; @@ -5466,7 +5466,7 @@ struct AffineBufferElimination : public OpRewritePattern { if (storeIdxSet.count(V)) continue; - if (auto BA = llvm::dyn_cast(V)) { + if (auto BA = dyn_cast(V)) { Operation *parent = BA.getOwner()->getParentOp(); if (auto sop = storeVal.getDefiningOp()) @@ -5516,10 +5516,10 @@ struct AffineBufferElimination : public OpRewritePattern { if (!isa(res.getEffect())) return false; unsigned addr = 0; - if (auto MT = llvm::dyn_cast(v.getType())) + if (auto MT = dyn_cast(v.getType())) addr = MT.getMemorySpaceAsInt(); else if (auto LT = - llvm::dyn_cast(v.getType())) + dyn_cast(v.getType())) addr = LT.getAddressSpace(); else return false; diff --git a/lib/polygeist/Passes/AffineCFG.cpp b/lib/polygeist/Passes/AffineCFG.cpp index c2f0b1b0d20e..1e5ca001fd9d 100644 --- a/lib/polygeist/Passes/AffineCFG.cpp +++ b/lib/polygeist/Passes/AffineCFG.cpp @@ -144,7 +144,7 @@ static bool legalCondition(Value en, bool dim = false) { // if (!outer || legalCondition(IC.getOperand(), false)) return true; //} if (!dim) - if (auto BA = llvm::dyn_cast(en)) { + if (auto BA = dyn_cast(en)) { if (isa( BA.getOwner()->getParentOp())) return true; @@ -730,7 +730,7 @@ static void setLocationAfter(PatternRewriter &b, mlir::Value val) { it++; b.setInsertionPoint(val.getDefiningOp()->getBlock(), it); } - if (auto bop = llvm::dyn_cast(val)) + if (auto bop = dyn_cast(val)) b.setInsertionPoint(bop.getOwner(), bop.getOwner()->begin()); } @@ -745,7 +745,7 @@ struct IndexCastMovement : public OpRewritePattern { } mlir::Value val = op.getOperand(); - if (auto bop = llvm::dyn_cast(val)) { + if (auto bop = dyn_cast(val)) { if (op.getOperation()->getBlock() != bop.getOwner()) { op.getOperation()->moveBefore(bop.getOwner(), bop.getOwner()->begin()); return success(); @@ -1010,7 +1010,7 @@ bool isValidIndex(Value val) { if (val.getDefiningOp()) return true; - if (auto ba = llvm::dyn_cast(val)) { + if (auto ba = dyn_cast(val)) { auto *owner = ba.getOwner(); assert(owner); diff --git a/lib/polygeist/Passes/CanonicalizeFor.cpp b/lib/polygeist/Passes/CanonicalizeFor.cpp index 0a682fb1cc3d..d04487d4689f 100644 --- a/lib/polygeist/Passes/CanonicalizeFor.cpp +++ b/lib/polygeist/Passes/CanonicalizeFor.cpp @@ -110,7 +110,7 @@ struct ForBreakAddUpgrade : public OpRewritePattern { auto condition = outerIfOp.getCondition(); // and that the outermost if's condition is an iter arg of the for - auto condArg = llvm::dyn_cast(condition); + auto condArg = dyn_cast(condition); if (!condArg) return failure(); if (condArg.getOwner()->getParentOp() != forOp) @@ -121,7 +121,7 @@ struct ForBreakAddUpgrade : public OpRewritePattern { // and is false unless coming from inside the if auto forYieldOp = cast(block.getTerminator()); auto opres = - llvm::dyn_cast(forYieldOp.getOperand(condArg.getArgNumber() - 1)); + dyn_cast(forYieldOp.getOperand(condArg.getArgNumber() - 1)); if (!opres) return failure(); if (opres.getOwner() != outerIfOp) @@ -143,7 +143,7 @@ struct ForBreakAddUpgrade : public OpRewritePattern { if (opres.getResultNumber() == regionArg.getArgNumber() - 1) continue; - auto opres2 = llvm::dyn_cast(forYieldOperand); + auto opres2 = dyn_cast(forYieldOperand); if (!opres2) continue; if (opres2.getOwner() != outerIfOp) @@ -627,13 +627,13 @@ yop2.results()[idx]); */ bool isTopLevelArgValue(Value value, Region *region) { - if (auto arg = llvm::dyn_cast(value)) + if (auto arg = dyn_cast(value)) return arg.getParentRegion() == region; return false; } bool isBlockArg(Value value) { - if (auto arg = llvm::dyn_cast(value)) + if (auto arg = dyn_cast(value)) return true; return false; } @@ -642,7 +642,7 @@ bool dominateWhile(Value value, WhileOp loop) { if (Operation *op = value.getDefiningOp()) { DominanceInfo dom(loop); return dom.properlyDominates(op, loop); - } else if (auto arg = llvm::dyn_cast(value)) { + } else if (auto arg = dyn_cast(value)) { return arg.getOwner()->getParentOp()->isProperAncestor(loop); } else { assert("????"); @@ -682,11 +682,11 @@ struct WhileToForHelper { negativeStep = false; auto condOp = loop.getConditionOp(); - indVar = llvm::dyn_cast(cmpIOp.getLhs()); + indVar = dyn_cast(cmpIOp.getLhs()); Type extType = nullptr; // todo handle ext if (auto ext = cmpIOp.getLhs().getDefiningOp()) { - indVar = llvm::dyn_cast(ext.getIn()); + indVar = dyn_cast(ext.getIn()); extType = ext.getType(); } // Condition is not the same as an induction variable @@ -1004,7 +1004,7 @@ struct MoveWhileAndDown : public OpRewritePattern { Value extraCmp = andIOp->getOperand(1 - i); Value lookThrough = nullptr; - if (auto BA = llvm::dyn_cast(extraCmp)) { + if (auto BA = dyn_cast(extraCmp)) { lookThrough = oldYield.getOperand(BA.getArgNumber()); } if (!helper.computeLegality(/*sizeCheck*/ false, lookThrough)) { @@ -1341,7 +1341,7 @@ struct MoveWhileDown2 : public OpRewritePattern { // yield i:pair<2> // } if (!std::get<0>(pair).use_empty()) { - if (auto blockArg = llvm::dyn_cast(elseYielded)) + if (auto blockArg = dyn_cast(elseYielded)) if (blockArg.getOwner() == &op.getBefore().front()) { if (afterYield.getResults()[blockArg.getArgNumber()] == std::get<2>(pair) && @@ -1580,7 +1580,7 @@ struct WhileCmpOffset : public OpRewritePattern { if (addI.getOperand(1).getDefiningOp() && !op.getBefore().isAncestor( addI.getOperand(1).getDefiningOp()->getParentRegion())) - if (auto blockArg = llvm::dyn_cast(addI.getOperand(0))) { + if (auto blockArg = dyn_cast(addI.getOperand(0))) { if (blockArg.getOwner() == &op.getBefore().front()) { auto rng = llvm::make_early_inc_range(blockArg.getUses()); @@ -1859,7 +1859,7 @@ struct WhileLICM : public OpRewritePattern { auto isDefinedOutsideOfBody = [&](Value value) { auto *definingOp = value.getDefiningOp(); if (!definingOp) { - if (auto ba = llvm::dyn_cast(value)) + if (auto ba = dyn_cast(value)) definingOp = ba.getOwner()->getParentOp(); assert(definingOp); } @@ -2125,7 +2125,7 @@ struct WhileShiftToInduction : public OpRewritePattern { if (!matchPattern(cmpIOp.getRhs(), m_Zero())) return failure(); - auto indVar = llvm::dyn_cast(cmpIOp.getLhs()); + auto indVar = dyn_cast(cmpIOp.getLhs()); if (!indVar) return failure(); @@ -2144,7 +2144,7 @@ struct WhileShiftToInduction : public OpRewritePattern { if (!matchPattern(shiftOp.getRhs(), m_One())) return failure(); - auto prevIndVar = llvm::dyn_cast(shiftOp.getLhs()); + auto prevIndVar = dyn_cast(shiftOp.getLhs()); if (!prevIndVar) return failure(); diff --git a/lib/polygeist/Passes/CollectKernelStatistics.cpp b/lib/polygeist/Passes/CollectKernelStatistics.cpp index ea1a4905a593..176f2b311cc0 100644 --- a/lib/polygeist/Passes/CollectKernelStatistics.cpp +++ b/lib/polygeist/Passes/CollectKernelStatistics.cpp @@ -197,7 +197,7 @@ std::array estimateStride(mlir::OperandRange indices, } else { return UNKNOWN; } - } else if (auto ba = llvm::dyn_cast(v)) { + } else if (auto ba = dyn_cast(v)) { return 0; if (isa(ba.getOwner()->getParentOp())) { return 0; @@ -339,7 +339,7 @@ static void generateAlternativeKernelDescs(mlir::ModuleOp m) { isa(&op) || isa(&op) || isa(&op) || false) { int width = - llvm::dyn_cast(op.getOperand(0).getType()).getWidth(); + dyn_cast(op.getOperand(0).getType()).getWidth(); addTo(floatOps, width, blockTrips); } else if (isa(&op) || isa(&op) || isa(&op) || isa(&op) || diff --git a/lib/polygeist/Passes/ConvertParallelToGPU.cpp b/lib/polygeist/Passes/ConvertParallelToGPU.cpp index 5ae277d6364f..866282215e50 100644 --- a/lib/polygeist/Passes/ConvertParallelToGPU.cpp +++ b/lib/polygeist/Passes/ConvertParallelToGPU.cpp @@ -222,7 +222,7 @@ struct AddLaunchBounds : public OpRewritePattern { succeeded = true; } else { assert(blockSize == - llvm::dyn_cast(gpuFuncOp->getAttr(attrName)).getInt()); + dyn_cast(gpuFuncOp->getAttr(attrName)).getInt()); succeeded = false; } attrName = "rocdl.max_flat_work_group_size"; @@ -233,7 +233,7 @@ struct AddLaunchBounds : public OpRewritePattern { return success(); } else { assert(blockSize == - llvm::dyn_cast(gpuFuncOp->getAttr(attrName)).getInt()); + dyn_cast(gpuFuncOp->getAttr(attrName)).getInt()); assert(!succeeded); return failure(); } @@ -525,7 +525,7 @@ struct SplitParallelOp : public OpRewritePattern { llvm::SmallVector syncIVs; pop->walk([&](polygeist::BarrierOp barrier) { for (auto o : barrier.getOperands()) - if (auto ba = llvm::dyn_cast(o)) + if (auto ba = dyn_cast(o)) if (std::find(syncIVs.begin(), syncIVs.end(), ba) == syncIVs.end()) syncIVs.push_back(ba); }); @@ -1330,7 +1330,7 @@ struct RemovePolygeistNoopOp : public OpRewritePattern { scf::ParallelOp pop = nullptr; SmallVector threadIndices; for (auto operand : noop.getOperands()) { - if (auto blockArg = llvm::dyn_cast(operand)) { + if (auto blockArg = dyn_cast(operand)) { if (auto _pop = dyn_cast( blockArg.getOwner()->getParentOp())) { if (!pop) diff --git a/lib/polygeist/Passes/ConvertPolygeistToLLVM.cpp b/lib/polygeist/Passes/ConvertPolygeistToLLVM.cpp index 18a77ab89bbe..a652c80e78f3 100644 --- a/lib/polygeist/Passes/ConvertPolygeistToLLVM.cpp +++ b/lib/polygeist/Passes/ConvertPolygeistToLLVM.cpp @@ -308,7 +308,7 @@ struct Pointer2MemrefOpLowering // MemRefDescriptor sourceMemRef(operands.front()); auto convertedType = getTypeConverter()->convertType(op.getType()); assert(convertedType && "unexpected failure in memref type conversion"); - if (auto PT = llvm::dyn_cast(convertedType)) { + if (auto PT = dyn_cast(convertedType)) { rewriter.replaceOpWithNewOp(op, PT, adaptor.getSource()); return success(); } @@ -551,7 +551,7 @@ struct LLVMOpLowering : public ConversionPattern { bool typeAttrsConverted = true; for (auto &attr : op->getAttrs()) - if (auto tyAttr = llvm::dyn_cast(attr.getValue())) + if (auto tyAttr = dyn_cast(attr.getValue())) if (converter->convertType(tyAttr.getValue()) != tyAttr.getValue()) typeAttrsConverted = false; @@ -565,7 +565,7 @@ struct LLVMOpLowering : public ConversionPattern { SmallVector convertedAttrs; for (auto &attr : op->getAttrs()) { NamedAttribute convertedAttr = attr; - if (auto tyAttr = llvm::dyn_cast(attr.getValue())) { + if (auto tyAttr = dyn_cast(attr.getValue())) { Type convertedTy = converter->convertType(tyAttr.getValue()); if (!convertedTy) return failure(); @@ -857,7 +857,7 @@ struct AsyncOpLowering : public ConvertOpToLLVMPattern { rewriter.create(execute.getLoc(), func))); for (auto dep : execute.getDependencies()) { auto src = dep.getDefiningOp().getSource(); - if (auto MT = llvm::dyn_cast(src.getType())) + if (auto MT = dyn_cast(src.getType())) src = rewriter.create( dep.getDefiningOp()->getLoc(), LLVM::LLVMPointerType::get(rewriter.getContext(), @@ -986,7 +986,7 @@ struct CAllocaOpLowering : public AllocLikeOpLowering { Location loc = allocaOp.getLoc(); MemRefType originalType = allocaOp.getType(); auto convertedType = - llvm::dyn_cast_or_null( + dyn_cast_or_null( getTypeConverter()->convertType(originalType)); auto elTy = convertMemrefElementTypeForLLVMPointer( originalType, *this->getTypeConverter()); @@ -1016,7 +1016,7 @@ struct CAllocOpLowering : public AllocLikeOpLowering { Location loc = allocOp.getLoc(); MemRefType originalType = allocOp.getType(); auto convertedType = - llvm::dyn_cast_or_null( + dyn_cast_or_null( getTypeConverter()->convertType(originalType)); if (!convertedType) @@ -1198,7 +1198,7 @@ struct CLoadStoreOpLowering : public ConvertOpToLLVMPattern { Location loc = op.getLoc(); MemRefType originalType = op.getMemRefType(); auto convertedType = - llvm::dyn_cast_or_null( + dyn_cast_or_null( this->getTypeConverter() ->convertType(originalType)); if (!convertedType) { @@ -1532,7 +1532,7 @@ struct LowerGPUAlternativesOp isa(op) || isa(op) || isa(op)) { int width = - llvm::dyn_cast(op->getOperand(0).getType()).getWidth(); + dyn_cast(op->getOperand(0).getType()).getWidth(); // TODO these are pretty random atm if (width == 16) { floatOps++; @@ -2257,7 +2257,7 @@ LogicalResult ConvertLaunchFuncOpToGpuRuntimeCallPattern::matchAndRewrite( auto bitcast = ctorBuilder.create(loc, llvmPointerType, aoo); auto globalTy = - llvm::dyn_cast(aoo.getType()).getElementType(); + dyn_cast(aoo.getType()).getElementType(); // TODO This should actually be the GPUModuleOp's data layout I // believe, there were problems with assigning the data layout to the // gpumodule because MLIR didnt like the nested data layout, and @@ -2395,7 +2395,7 @@ struct GPUFuncOpLowering : public ConvertOpToLLVMPattern { llvm::enumerate(gpuFuncOp.getWorkgroupAttributions())) { Value attribution = en.value(); - auto type = llvm::dyn_cast(attribution.getType()); + auto type = dyn_cast(attribution.getType()); assert(type && type.hasStaticShape() && "unexpected type in attribution"); uint64_t numElements = type.getNumElements(); @@ -2893,7 +2893,7 @@ struct ConvertPolygeistToLLVMPass auto areAllTypesConverted = [&](Operation *op) -> std::optional { // Check if TyepAttrs got converted for (auto &attr : op->getAttrs()) - if (auto tyAttr = llvm::dyn_cast(attr.getValue())) + if (auto tyAttr = dyn_cast(attr.getValue())) if (converter.convertType(tyAttr.getValue()) != tyAttr.getValue()) return std::nullopt; diff --git a/lib/polygeist/Passes/ConvertToOpaquePtr.cpp b/lib/polygeist/Passes/ConvertToOpaquePtr.cpp index 7b8a2012794d..7ef97adb2079 100644 --- a/lib/polygeist/Passes/ConvertToOpaquePtr.cpp +++ b/lib/polygeist/Passes/ConvertToOpaquePtr.cpp @@ -192,7 +192,7 @@ struct GEPConversion : public OpConversionPattern { if (!op->getAttr(kElemTypeAttrName)) elty = TypeAttr::get( getTypeConverter()->convertType( - llvm::dyn_cast( + dyn_cast( op.getOperand(0).getType()).getElementType())); if (convertPtrsToOpaque(op, rewritten, elty, adaptor.getOperands(), rewriter, getTypeConverter()) @@ -224,14 +224,14 @@ struct ConvertToOpaquePtrPass std::map typeCache; TypeConverter converter; converter.addConversion([&](Type ty) -> Type { - if (auto pt = llvm::dyn_cast(ty)) { + if (auto pt = dyn_cast(ty)) { return LLVM::LLVMPointerType::get(pt.getContext(), pt.getAddressSpace()); - } else if (auto mt = llvm::dyn_cast(ty)) { + } else if (auto mt = dyn_cast(ty)) { return MemRefType::get(mt.getShape(), converter.convertType(mt.getElementType()), mt.getLayout(), mt.getMemorySpace()); - } else if (auto st = llvm::dyn_cast(ty)) { + } else if (auto st = dyn_cast(ty)) { StringRef key = ""; if (st.isIdentified()) { key = st.getName(); @@ -246,7 +246,7 @@ struct ConvertToOpaquePtrPass } for (auto ty : st.getBody()) { StringRef fieldKey = ""; - if (auto fieldST = llvm::dyn_cast(ty)) { + if (auto fieldST = dyn_cast(ty)) { if (fieldST.isIdentified()) fieldKey = fieldST.getName(); } @@ -264,7 +264,7 @@ struct ConvertToOpaquePtrPass return LLVM::LLVMStructType::getLiteral(&getContext(), bodyTypes, st.isPacked()); } - } else if (auto at = llvm::dyn_cast(ty)) { + } else if (auto at = dyn_cast(ty)) { return LLVM::LLVMArrayType::get( converter.convertType(at.getElementType()), at.getNumElements()); } else { diff --git a/lib/polygeist/Passes/ForBreakToWhile.cpp b/lib/polygeist/Passes/ForBreakToWhile.cpp index 597ccef0c77c..8d3927dcc16d 100644 --- a/lib/polygeist/Passes/ForBreakToWhile.cpp +++ b/lib/polygeist/Passes/ForBreakToWhile.cpp @@ -39,7 +39,7 @@ struct ForBreakLoweringPattern : public OpRewritePattern { return failure(); // Its condition comes directly from iterargs. - auto condition = llvm::dyn_cast(conditional.getCondition()); + auto condition = dyn_cast(conditional.getCondition()); if (!condition || condition.getOwner()->getParentOp() != forOp) return failure(); unsigned iterArgPos = condition.getArgNumber() - 1; @@ -47,7 +47,7 @@ struct ForBreakLoweringPattern : public OpRewritePattern { // The condition is initially and remains false once changed to // false. Moveover, values don't change after the condition is set to false. auto yield = cast(body->back()); - auto yieldedCondition = llvm::dyn_cast(yield.getOperand(iterArgPos)); + auto yieldedCondition = dyn_cast(yield.getOperand(iterArgPos)); if (yieldedCondition.getOwner() != conditional) return failure(); @@ -61,7 +61,7 @@ struct ForBreakLoweringPattern : public OpRewritePattern { Block *forEnd = &forOp.getRegion().back(); auto forYield = cast(forEnd->getTerminator()); for (auto op : llvm::enumerate(forYield->getOperands())) { - auto opp = llvm::dyn_cast(op.value()); + auto opp = dyn_cast(op.value()); if (!opp) { return failure(); } @@ -69,7 +69,7 @@ struct ForBreakLoweringPattern : public OpRewritePattern { return failure(); auto BA = - llvm::dyn_cast(elseYield.getOperand(opp.getResultNumber())); + dyn_cast(elseYield.getOperand(opp.getResultNumber())); if (!BA) { if (iterArgPos == op.index()) if (matchPattern(elseYield.getOperand(opp.getResultNumber()), @@ -88,7 +88,7 @@ struct ForBreakLoweringPattern : public OpRewritePattern { SmallVector continueArgs; for (auto op : forYield->getOperands()) { - if (auto opp = llvm::dyn_cast(op)) { + if (auto opp = dyn_cast(op)) { if (opp.getOwner() == conditional) { continueArgs.push_back( conditional.thenYield()->getOperand(opp.getResultNumber())); diff --git a/lib/polygeist/Passes/ParallelLICM.cpp b/lib/polygeist/Passes/ParallelLICM.cpp index 9847882d1414..2fce2676954a 100644 --- a/lib/polygeist/Passes/ParallelLICM.cpp +++ b/lib/polygeist/Passes/ParallelLICM.cpp @@ -34,7 +34,7 @@ static bool canBeParallelHoisted(Operation *op, Operation *scope, // Helper to check whether an operation is loop invariant wrt. SSA properties. LLVM_DEBUG(llvm::dbgs() << "Checking for parallel hoist: " << *op << "\n"); auto definedOutside = [&](Value value) { - if (auto BA = llvm::dyn_cast(value)) + if (auto BA = dyn_cast(value)) if (willBeMoved.count(BA.getOwner()->getParentOp())) return true; auto *definingOp = value.getDefiningOp(); @@ -245,7 +245,7 @@ bool below(Value bval, int64_t val) { if (val == -1) return false; - if (auto baval = llvm::dyn_cast(bval)) { + if (auto baval = dyn_cast(bval)) { if (affine::AffineForOp afFor = dyn_cast(baval.getOwner()->getParentOp())) { for (auto ub : afFor.getUpperBoundMap().getResults()) { diff --git a/lib/polygeist/Passes/ParallelLoopDistribute.cpp b/lib/polygeist/Passes/ParallelLoopDistribute.cpp index c41da5996fab..e31345aa20bf 100644 --- a/lib/polygeist/Passes/ParallelLoopDistribute.cpp +++ b/lib/polygeist/Passes/ParallelLoopDistribute.cpp @@ -286,7 +286,7 @@ static void minCutCache(polygeist::BarrierOp barrier, for (auto N : pair.second) { if (parent.find(N) == parent.end()) { assert(pair.first.type == Node::OP && N.type == Node::VAL); - assert(pair.first.O == llvm::dyn_cast(N.V).getOwner()); + assert(pair.first.O == dyn_cast(N.V).getOwner()); Cache.insert(N.V); } } @@ -396,7 +396,7 @@ static bool hasNestedBarrier(Operation *op, SmallVector &vals) { // the `parallel` op is not an ancestor of `op` or `op` itself), the // barrier is considered nested in that `parallel` op and _not_ in `op`. for (auto arg : barrier->getOperands()) { - if (auto ba = llvm::dyn_cast(arg)) { + if (auto ba = dyn_cast(arg)) { if (auto parallel = dyn_cast(ba.getOwner()->getParentOp())) { if (parallel->isAncestor(op)) @@ -2326,7 +2326,7 @@ struct Reg2MemIf : public OpRewritePattern { while (!todo.empty()) { auto cur = todo.pop_back_val(); - if (auto BA = llvm::dyn_cast(cur)) + if (auto BA = dyn_cast(cur)) if (BA.getOwner() == op->getBlock()) continue; @@ -2426,7 +2426,7 @@ struct Reg2MemIf : public OpRewritePattern { while (!todo.empty()) { auto cur = todo.pop_back_val(); - if (auto BA = llvm::dyn_cast(cur)) + if (auto BA = dyn_cast(cur)) if (BA.getOwner() == op->getBlock()) continue; if (cur.getParentRegion()->isProperAncestor( @@ -2485,7 +2485,7 @@ struct Reg2MemIf : public OpRewritePattern { while (!todo.empty()) { auto cur = todo.pop_back_val(); - if (auto BA = llvm::dyn_cast(cur)) + if (auto BA = dyn_cast(cur)) if (BA.getOwner() == op->getBlock()) continue; diff --git a/lib/polygeist/Passes/ParallelLoopUnroll.cpp b/lib/polygeist/Passes/ParallelLoopUnroll.cpp index 0be1711010ee..4d37f255454f 100644 --- a/lib/polygeist/Passes/ParallelLoopUnroll.cpp +++ b/lib/polygeist/Passes/ParallelLoopUnroll.cpp @@ -93,7 +93,7 @@ static LogicalResult generateUnrolledInterleavedLoop( .wasInterrupted(); }; auto threadIndependent = [&](Value v) -> bool { - if (auto BA = llvm::dyn_cast(v)) { + if (auto BA = dyn_cast(v)) { if (BA == srcIV) return false; return BA.getOwner()->getParentOp()->isAncestor(srcBlock->getParentOp()); diff --git a/lib/polygeist/Passes/ParallelLower.cpp b/lib/polygeist/Passes/ParallelLower.cpp index 89b1331aacc8..449e29a9adb4 100644 --- a/lib/polygeist/Passes/ParallelLower.cpp +++ b/lib/polygeist/Passes/ParallelLower.cpp @@ -258,7 +258,7 @@ void ParallelLower::runOnOperation() { auto callable = caller.getCallableForCallee(); CallableOpInterface callableOp; - if (SymbolRefAttr symRef = llvm::dyn_cast(callable)) { + if (SymbolRefAttr symRef = dyn_cast(callable)) { if (!symRef.isa()) return; auto *symbolOp = @@ -312,7 +312,7 @@ void ParallelLower::runOnOperation() { auto callable = caller.getCallableForCallee(); CallableOpInterface callableOp; - if (SymbolRefAttr symRef = llvm::dyn_cast(callable)) { + if (SymbolRefAttr symRef = dyn_cast(callable)) { if (!symRef.isa()) return; auto *symbolOp = @@ -730,7 +730,7 @@ void FixGPUFunc::runOnOperation() { auto callable = caller.getCallableForCallee(); CallableOpInterface callableOp; - if (SymbolRefAttr symRef = llvm::dyn_cast(callable)) { + if (SymbolRefAttr symRef = dyn_cast(callable)) { auto *symbolOp = symbolTable.lookupNearestSymbolFrom(getOperation(), symRef); callableOp = dyn_cast_or_null(symbolOp); @@ -771,7 +771,7 @@ void FixGPUFunc::runOnOperation() { return; Operation *funcOp; if (SymbolRefAttr symRef = - llvm::dyn_cast(callOp.getCallableForCallee())) { + dyn_cast(callOp.getCallableForCallee())) { auto *symbolOp = symbolTable.lookupNearestSymbolFrom(getOperation(), symRef); funcOp = dyn_cast_or_null(symbolOp); @@ -806,7 +806,7 @@ void ConvertCudaRTtoCPU::runOnOperation() { OpBuilder bz(call); auto falsev = bz.create(call->getLoc(), false, 1); auto dst = call->getOperand(0); - if (auto mt = llvm::dyn_cast(dst.getType())) { + if (auto mt = dyn_cast(dst.getType())) { dst = bz.create( call->getLoc(), LLVM::LLVMPointerType::get(mt.getElementType(), @@ -814,7 +814,7 @@ void ConvertCudaRTtoCPU::runOnOperation() { dst); } auto src = call->getOperand(1); - if (auto mt = llvm::dyn_cast(src.getType())) { + if (auto mt = dyn_cast(src.getType())) { src = bz.create( call->getLoc(), LLVM::LLVMPointerType::get(mt.getElementType(), @@ -831,7 +831,7 @@ void ConvertCudaRTtoCPU::runOnOperation() { OpBuilder bz(call); auto falsev = bz.create(call->getLoc(), false, 1); auto dst = call->getOperand(0); - if (auto mt = llvm::dyn_cast(dst.getType())) { + if (auto mt = dyn_cast(dst.getType())) { dst = bz.create( call->getLoc(), LLVM::LLVMPointerType::get(mt.getElementType(), @@ -839,7 +839,7 @@ void ConvertCudaRTtoCPU::runOnOperation() { dst); } auto src = call->getOperand(1); - if (auto mt = llvm::dyn_cast(src.getType())) { + if (auto mt = dyn_cast(src.getType())) { src = bz.create( call->getLoc(), LLVM::LLVMPointerType::get(mt.getElementType(), @@ -859,7 +859,7 @@ void ConvertCudaRTtoCPU::runOnOperation() { OpBuilder bz(call); auto falsev = bz.create(call->getLoc(), false, 1); auto dst = call->getOperand(0); - if (auto mt = llvm::dyn_cast(dst.getType())) { + if (auto mt = dyn_cast(dst.getType())) { dst = bz.create( call->getLoc(), LLVM::LLVMPointerType::get(mt.getElementType(), diff --git a/lib/polygeist/Passes/PolygeistMem2Reg.cpp b/lib/polygeist/Passes/PolygeistMem2Reg.cpp index a827fc20d960..fb3027ad5dbd 100644 --- a/lib/polygeist/Passes/PolygeistMem2Reg.cpp +++ b/lib/polygeist/Passes/PolygeistMem2Reg.cpp @@ -45,8 +45,8 @@ using namespace polygeist; enum class Match { Exact, Maybe, None }; bool operator<(Value lhs, Value rhs) { - if (auto lhsBA = llvm::dyn_cast(lhs)) { - if (auto rhsBA = llvm::dyn_cast(rhs)) { + if (auto lhsBA = dyn_cast(lhs)) { + if (auto rhsBA = dyn_cast(rhs)) { if (lhsBA.getOwner() != rhsBA.getOwner()) return lhsBA.getOwner() < rhsBA.getOwner(); else @@ -56,7 +56,7 @@ bool operator<(Value lhs, Value rhs) { } } auto lhsOR = lhs.cast(); - if (auto rhsBA = llvm::dyn_cast(rhs)) { + if (auto rhsBA = dyn_cast(rhs)) { return false; } else { auto rhsOR = rhs.cast(); @@ -502,7 +502,7 @@ class ValueOrPlaceholder { !exOp->isAncestor(values[0].getDefiningOp())) { return values[0]; } - if (auto ba = llvm::dyn_cast(values[0])) + if (auto ba = dyn_cast(values[0])) if (!exOp->isAncestor(ba.getOwner()->getParentOp())) { return values[0]; } @@ -1083,7 +1083,7 @@ bool PolygeistMem2Reg::forwardStoreToLoad( std::set allStoreOps; Type elType; - if (auto MT = llvm::dyn_cast(AI.getType())) + if (auto MT = dyn_cast(AI.getType())) elType = MT.getElementType(); else elType = AI.getType().cast().getElementType(); @@ -1101,11 +1101,11 @@ bool PolygeistMem2Reg::forwardStoreToLoad( while (list.size()) { auto pair = list.front(); auto val = pair.first; - if (auto MT = llvm::dyn_cast(val.getType())) { - if (auto ia = llvm::dyn_cast_or_null(MT.getMemorySpace())) + if (auto MT = dyn_cast(val.getType())) { + if (auto ia = dyn_cast_or_null(MT.getMemorySpace())) SharedMemAddr = ia.getValue() == 5; } else { - auto PT = llvm::dyn_cast(val.getType()); + auto PT = dyn_cast(val.getType()); SharedMemAddr = PT.getAddressSpace() == 5; } auto modified = pair.second; @@ -1707,7 +1707,7 @@ bool PolygeistMem2Reg::forwardStoreToLoad( Value maybeblockArg = valueAtStartOfBlock.find(block)->second->materialize(false); - auto blockArg = llvm::dyn_cast(maybeblockArg); + auto blockArg = dyn_cast(maybeblockArg); assert(blockArg && blockArg.getOwner() == block); SetVector prepred(block->getPredecessors().begin(), diff --git a/tools/cgeist/Lib/CGCall.cc b/tools/cgeist/Lib/CGCall.cc index 4e9d839cdf23..164f72b0e7e5 100644 --- a/tools/cgeist/Lib/CGCall.cc +++ b/tools/cgeist/Lib/CGCall.cc @@ -34,8 +34,8 @@ static mlir::Value castCallerMemRefArg(mlir::Value callerArg, mlir::OpBuilder::InsertionGuard guard(b); mlir::Type callerArgType = callerArg.getType(); - if (MemRefType dstTy = llvm::dyn_cast_or_null(calleeArgType)) { - MemRefType srcTy = llvm::dyn_cast(callerArgType); + if (MemRefType dstTy = dyn_cast_or_null(calleeArgType)) { + MemRefType srcTy = dyn_cast(callerArgType); if (srcTy && dstTy.getElementType() == srcTy.getElementType() && dstTy.getMemorySpace() == srcTy.getMemorySpace()) { auto srcShape = srcTy.getShape(); @@ -126,7 +126,7 @@ ValueCategory MLIRScanner::CallHelper( QualType aType = (i == 0 && a == nullptr) ? objType : a->getType(); auto expectedType = Glob.getMLIRType(aType, &isArray); - if (auto PT = llvm::dyn_cast(arg.val.getType())) { + if (auto PT = dyn_cast(arg.val.getType())) { if (PT.getAddressSpace() == 5) arg.val = builder.create( loc, LLVM::LLVMPointerType::get(PT.getElementType(), 0), arg.val); @@ -174,7 +174,7 @@ ValueCategory MLIRScanner::CallHelper( val = builder.create(loc, expectedType, val); } - if (auto prevTy = llvm::dyn_cast(val.getType())) { + if (auto prevTy = dyn_cast(val.getType())) { auto ipostTy = expectedType.cast(); if (prevTy != ipostTy) val = builder.create(loc, ipostTy, val); @@ -258,7 +258,7 @@ ValueCategory MLIRScanner::CallHelper( assert(l0.isReference); mlir::Value blocks[3]; mlir::Value val = l0.val; - if (auto MT = llvm::dyn_cast(val.getType())) { + if (auto MT = dyn_cast(val.getType())) { if (MT.getElementType().isa() && MT.getShape().size() == 1) { val = builder.create( @@ -269,7 +269,7 @@ ValueCategory MLIRScanner::CallHelper( } } for (int i = 0; i < 3; i++) { - if (auto MT = llvm::dyn_cast(val.getType())) { + if (auto MT = dyn_cast(val.getType())) { mlir::Value idx[] = {getConstantIndex(0), getConstantIndex(i)}; assert(MT.getShape().size() == 2); blocks[i] = builder.create( @@ -294,7 +294,7 @@ ValueCategory MLIRScanner::CallHelper( assert(t0.isReference); mlir::Value threads[3]; val = t0.val; - if (auto MT = llvm::dyn_cast(val.getType())) { + if (auto MT = dyn_cast(val.getType())) { if (MT.getElementType().isa() && MT.getShape().size() == 1) { val = builder.create( @@ -305,7 +305,7 @@ ValueCategory MLIRScanner::CallHelper( } } for (int i = 0; i < 3; i++) { - if (auto MT = llvm::dyn_cast(val.getType())) { + if (auto MT = dyn_cast(val.getType())) { mlir::Value idx[] = {getConstantIndex(0), getConstantIndex(i)}; assert(MT.getShape().size() == 2); threads[i] = builder.create( @@ -383,10 +383,10 @@ mlir::Value MLIRScanner::getLLVM(Expr *E, bool isRef) { if (isReference) { assert(sub.isReference); mlir::Value val = sub.val; - if (auto mt = llvm::dyn_cast(val.getType())) { + if (auto mt = dyn_cast(val.getType())) { val = builder.create(loc, getOpaquePtr(), val); - } else if (auto pt = llvm::dyn_cast(val.getType())) { + } else if (auto pt = dyn_cast(val.getType())) { if (!pt.isOpaque()) val = builder.create(loc, getOpaquePtr(), val); } @@ -441,9 +441,9 @@ mlir::Value MLIRScanner::getLLVM(Expr *E, bool isRef) { val = sub.val; ct = Glob.CGM.getContext().getLValueReferenceType(E->getType()); } - if (auto mt = llvm::dyn_cast(val.getType())) { + if (auto mt = dyn_cast(val.getType())) { val = builder.create(loc, getOpaquePtr(), val); - } else if (auto pt = llvm::dyn_cast(val.getType())) { + } else if (auto pt = dyn_cast(val.getType())) { if (!pt.isOpaque()) val = builder.create(loc, getOpaquePtr(), val); } @@ -498,7 +498,7 @@ MLIRScanner::EmitClangBuiltinCallExpr(clang::CallExpr *expr) { loc, mlir::IndexType::get(builder.getContext()), count); auto ty = getMLIRType(expr->getType()); mlir::Value alloc; - if (auto mt = llvm::dyn_cast(ty)) { + if (auto mt = dyn_cast(ty)) { auto shape = std::vector(mt.getShape()); mlir::Value args[1] = {count}; alloc = builder.create(loc, mt, args); @@ -1288,7 +1288,7 @@ ValueCategory MLIRScanner::VisitCallExpr(clang::CallExpr *expr) { loc, offset, builder.create(loc, elemSize)); // assert(!dstArray); - if (auto mt = llvm::dyn_cast(dst.getType())) { + if (auto mt = dyn_cast(dst.getType())) { auto shape = std::vector(mt.getShape()); shape[0] = ShapedType::kDynamic; auto mt0 = mlir::MemRefType::get(shape, mt.getElementType(), @@ -1677,7 +1677,7 @@ ValueCategory MLIRScanner::VisitCallExpr(clang::CallExpr *expr) { builder.create(loc, strcmpF, args).getResult(); } else { mlir::Value fn = Visit(expr->getCallee()).getValue(loc, builder); - if (auto MT = llvm::dyn_cast(fn.getType())) { + if (auto MT = dyn_cast(fn.getType())) { fn = builder.create( loc, LLVM::LLVMPointerType::get(MT.getElementType(), 0), fn); } @@ -1688,14 +1688,14 @@ ValueCategory MLIRScanner::VisitCallExpr(clang::CallExpr *expr) { SmallVector argtys; bool needsChange = false; for (auto FT : PTF.getParams()) { - if (auto mt = llvm::dyn_cast(FT)) { + if (auto mt = dyn_cast(FT)) { argtys.push_back(LLVM::LLVMPointerType::get(mt.getElementType(), 0)); needsChange = true; } else argtys.push_back(FT); } auto rt = PTF.getReturnType(); - if (auto mt = llvm::dyn_cast(rt)) { + if (auto mt = dyn_cast(rt)) { rt = LLVM::LLVMPointerType::get(mt.getElementType(), 0); needsChange = true; } @@ -1788,7 +1788,7 @@ ValueCategory MLIRScanner::VisitCallExpr(clang::CallExpr *expr) { */ } i++; - if (auto mt = llvm::dyn_cast(v.getType())) { + if (auto mt = dyn_cast(v.getType())) { v = builder.create( loc, LLVM::LLVMPointerType::get(mt.getElementType(), 0), v); } @@ -1807,7 +1807,7 @@ ValueCategory MLIRScanner::VisitCallExpr(clang::CallExpr *expr) { assert(l0.isReference); mlir::Value val = l0.val; mlir::Value blocks[3]; - if (auto MT = llvm::dyn_cast(val.getType())) { + if (auto MT = dyn_cast(val.getType())) { if (MT.getElementType().isa() && MT.getShape().size() == 1) { val = builder.create( @@ -1818,7 +1818,7 @@ ValueCategory MLIRScanner::VisitCallExpr(clang::CallExpr *expr) { } } for (int i = 0; i < 3; i++) { - if (auto MT = llvm::dyn_cast(val.getType())) { + if (auto MT = dyn_cast(val.getType())) { mlir::Value idx[] = {getConstantIndex(0), getConstantIndex(i)}; assert(MT.getShape().size() == 2); blocks[i] = builder.create( @@ -1846,7 +1846,7 @@ ValueCategory MLIRScanner::VisitCallExpr(clang::CallExpr *expr) { assert(t0.isReference); mlir::Value threads[3]; val = t0.val; - if (auto MT = llvm::dyn_cast(val.getType())) { + if (auto MT = dyn_cast(val.getType())) { if (MT.getElementType().isa() && MT.getShape().size() == 1) { val = builder.create( @@ -1857,7 +1857,7 @@ ValueCategory MLIRScanner::VisitCallExpr(clang::CallExpr *expr) { } } for (int i = 0; i < 3; i++) { - if (auto MT = llvm::dyn_cast(val.getType())) { + if (auto MT = dyn_cast(val.getType())) { mlir::Value idx[] = {getConstantIndex(0), getConstantIndex(i)}; assert(MT.getShape().size() == 2); threads[i] = builder.create( diff --git a/tools/cgeist/Lib/CGStmt.cc b/tools/cgeist/Lib/CGStmt.cc index 68a65a22fef3..200f5a70739c 100644 --- a/tools/cgeist/Lib/CGStmt.cc +++ b/tools/cgeist/Lib/CGStmt.cc @@ -249,14 +249,14 @@ ValueCategory MLIRScanner::VisitForStmt(clang::ForStmt *fors) { if (auto *s = fors->getCond()) { auto condRes = Visit(s); auto cond = condRes.getValue(loc, builder); - if (auto mt = llvm::dyn_cast(cond.getType())) { + if (auto mt = dyn_cast(cond.getType())) { cond = builder.create( loc, LLVM::LLVMPointerType::get(mt.getElementType(), mt.getMemorySpaceAsInt()), cond); } - if (auto LT = llvm::dyn_cast(cond.getType())) { + if (auto LT = dyn_cast(cond.getType())) { auto nullptr_llvm = builder.create(loc, LT); cond = builder.create( loc, mlir::LLVM::ICmpPredicate::ne, cond, nullptr_llvm); @@ -342,7 +342,7 @@ ValueCategory MLIRScanner::VisitCXXForRangeStmt(clang::CXXForRangeStmt *fors) { if (auto *s = fors->getCond()) { auto condRes = Visit(s); auto cond = condRes.getValue(loc, builder); - if (auto LT = llvm::dyn_cast(cond.getType())) { + if (auto LT = dyn_cast(cond.getType())) { auto nullptr_llvm = builder.create(loc, LT); cond = builder.create( loc, mlir::LLVM::ICmpPredicate::ne, cond, nullptr_llvm); @@ -742,7 +742,7 @@ ValueCategory MLIRScanner::VisitDoStmt(clang::DoStmt *fors) { if (auto *s = fors->getCond()) { auto condRes = Visit(s); auto cond = condRes.getValue(loc, builder); - if (auto LT = llvm::dyn_cast(cond.getType())) { + if (auto LT = dyn_cast(cond.getType())) { auto nullptr_llvm = builder.create(loc, LT); cond = builder.create( loc, mlir::LLVM::ICmpPredicate::ne, cond, nullptr_llvm); @@ -805,7 +805,7 @@ ValueCategory MLIRScanner::VisitWhileStmt(clang::WhileStmt *stmt) { if (auto *s = stmt->getCond()) { auto condRes = Visit(s); auto cond = condRes.getValue(loc, builder); - if (auto LT = llvm::dyn_cast(cond.getType())) { + if (auto LT = dyn_cast(cond.getType())) { auto nullptr_llvm = builder.create(loc, LT); cond = builder.create( loc, mlir::LLVM::ICmpPredicate::ne, cond, nullptr_llvm); @@ -849,11 +849,11 @@ ValueCategory MLIRScanner::VisitIfStmt(clang::IfStmt *stmt) { auto oldpoint = builder.getInsertionPoint(); auto *oldblock = builder.getInsertionBlock(); - if (auto LT = llvm::dyn_cast(cond.getType())) { + if (auto LT = dyn_cast(cond.getType())) { cond = builder.create( loc, LLVM::LLVMPointerType::get(builder.getI8Type()), cond); } - if (auto LT = llvm::dyn_cast(cond.getType())) { + if (auto LT = dyn_cast(cond.getType())) { auto nullptr_llvm = builder.create(loc, LT); cond = builder.create( loc, mlir::LLVM::ICmpPredicate::ne, cond, nullptr_llvm); @@ -1164,7 +1164,7 @@ ValueCategory MLIRScanner::VisitReturnStmt(clang::ReturnStmt *stmt) { } auto postTy = returnVal.getType().cast().getElementType(); - if (auto prevTy = llvm::dyn_cast(val.getType())) { + if (auto prevTy = dyn_cast(val.getType())) { auto ipostTy = postTy.cast(); if (prevTy != ipostTy) { val = builder.create(loc, ipostTy, val); diff --git a/tools/cgeist/Lib/ValueCategory.cc b/tools/cgeist/Lib/ValueCategory.cc index b8cb59c3ef53..5c9fd4c0323d 100644 --- a/tools/cgeist/Lib/ValueCategory.cc +++ b/tools/cgeist/Lib/ValueCategory.cc @@ -40,7 +40,7 @@ mlir::Value ValueCategory::getValue(mlir::Location loc, if (val.getType().isa()) { return builder.create(loc, val); } - if (auto mt = llvm::dyn_cast(val.getType())) { + if (auto mt = dyn_cast(val.getType())) { assert(mt.getShape().size() == 1 && "must have shape 1"); auto c0 = builder.create(loc, 0); return builder.create(loc, val, @@ -53,7 +53,7 @@ void ValueCategory::store(mlir::Location loc, mlir::OpBuilder &builder, mlir::Value toStore) const { assert(isReference && "must be a reference"); assert(val && "expect not-null"); - if (auto pt = llvm::dyn_cast(val.getType())) { + if (auto pt = dyn_cast(val.getType())) { if (auto p2m = toStore.getDefiningOp()) { if (pt.getElementType() == p2m.getSource().getType()) toStore = p2m.getSource(); @@ -64,9 +64,9 @@ void ValueCategory::store(mlir::Location loc, mlir::OpBuilder &builder, } } if (toStore.getType() != pt.getElementType()) { - if (auto mt = llvm::dyn_cast(toStore.getType())) { + if (auto mt = dyn_cast(toStore.getType())) { if (auto spt = - llvm::dyn_cast(pt.getElementType())) { + dyn_cast(pt.getElementType())) { if (mt.getElementType() != spt.getElementType()) { // llvm::errs() << " func: " << // val.getDefiningOp()->getParentOfType() << "\n"; @@ -84,10 +84,10 @@ void ValueCategory::store(mlir::Location loc, mlir::OpBuilder &builder, } return; } - if (auto mt = llvm::dyn_cast(val.getType())) { + if (auto mt = dyn_cast(val.getType())) { assert(mt.getShape().size() == 1 && "must have size 1"); - if (auto PT = llvm::dyn_cast(toStore.getType())) { - if (auto MT = llvm::dyn_cast(val.getType() + if (auto PT = dyn_cast(toStore.getType())) { + if (auto MT = dyn_cast(val.getType() .cast() .getElementType())) { assert(MT.getShape().size() == 1); @@ -155,10 +155,10 @@ void ValueCategory::store(mlir::Location loc, mlir::OpBuilder &builder, assert(toStore.isReference); auto zeroIndex = builder.create(loc, 0); - if (auto smt = llvm::dyn_cast(toStore.val.getType())) { + if (auto smt = dyn_cast(toStore.val.getType())) { assert(smt.getShape().size() <= 2); - if (auto mt = llvm::dyn_cast(val.getType())) { + if (auto mt = dyn_cast(val.getType())) { assert(smt.getElementType() == mt.getElementType()); if (mt.getShape().size() != smt.getShape().size()) { llvm::errs() << " val: " << val << " tsv: " << toStore.val << "\n"; @@ -179,7 +179,7 @@ void ValueCategory::store(mlir::Location loc, mlir::OpBuilder &builder, } else { auto pt = val.getType().cast(); mlir::Type elty; - if (auto at = llvm::dyn_cast(pt.getElementType())) { + if (auto at = dyn_cast(pt.getElementType())) { elty = at.getElementType(); if (smt.getShape().back() != at.getNumElements()) { llvm::errs() << " pt: " << pt << " smt: " << smt << "\n"; @@ -190,7 +190,7 @@ void ValueCategory::store(mlir::Location loc, mlir::OpBuilder &builder, } assert(smt.getShape().back() == at.getNumElements()); } else { - auto st = llvm::dyn_cast(pt.getElementType()); + auto st = dyn_cast(pt.getElementType()); elty = st.getBody()[0]; assert(smt.getShape().back() == (ssize_t)st.getBody().size()); } @@ -220,16 +220,16 @@ void ValueCategory::store(mlir::Location loc, mlir::OpBuilder &builder, builder.create(loc, elty, val, lidx)); } } - } else if (auto smt = llvm::dyn_cast(val.getType())) { + } else if (auto smt = dyn_cast(val.getType())) { assert(smt.getShape().size() <= 2); auto pt = toStore.val.getType().cast(); mlir::Type elty; - if (auto at = llvm::dyn_cast(pt.getElementType())) { + if (auto at = dyn_cast(pt.getElementType())) { elty = at.getElementType(); assert(smt.getShape().back() == at.getNumElements()); } else { - auto st = llvm::dyn_cast(pt.getElementType()); + auto st = dyn_cast(pt.getElementType()); elty = st.getBody()[0]; assert(smt.getShape().back() == (ssize_t)st.getBody().size()); } diff --git a/tools/cgeist/Lib/clang-mlir.cc b/tools/cgeist/Lib/clang-mlir.cc index 5d4281e8ac6d..058464c323ef 100644 --- a/tools/cgeist/Lib/clang-mlir.cc +++ b/tools/cgeist/Lib/clang-mlir.cc @@ -77,7 +77,7 @@ ValueCategory MLIRScanner::createComplexFloat(mlir::Location loc, OpBuilder abuilder(builder.getContext()); abuilder.setInsertionPointToStart(allocationScope); mlir::Value result; - if (auto MT = llvm::dyn_cast(elty)) { + if (auto MT = dyn_cast(elty)) { mt = elty; elty = MT.getElementType(); ref = true; @@ -109,7 +109,7 @@ ValueCategory MLIRScanner::createComplexFloat(mlir::Location loc, ValueCategory MLIRScanner::getComplexPartRef(mlir::Location loc, mlir::Value val, int fnum) { - if (auto MT = llvm::dyn_cast(val.getType())) { + if (auto MT = dyn_cast(val.getType())) { if (MT.getElementType().isa() && MT.getShape().size() == 1) { val = builder.create( @@ -119,7 +119,7 @@ ValueCategory MLIRScanner::getComplexPartRef(mlir::Location loc, val); } } - if (auto mt = llvm::dyn_cast(val.getType())) { + if (auto mt = dyn_cast(val.getType())) { auto shape = std::vector(mt.getShape()); assert(shape.size() == 2); shape.erase(shape.begin()); @@ -135,9 +135,9 @@ ValueCategory MLIRScanner::getComplexPartRef(mlir::Location loc, si = builder.create(loc, mt1, si, getConstantIndex(fnum)); return ValueCategory(si, /*isReference*/ true); - } else if (auto PT = llvm::dyn_cast(val.getType())) { + } else if (auto PT = dyn_cast(val.getType())) { mlir::Type ET; - if (auto ST = llvm::dyn_cast(PT.getElementType())) { + if (auto ST = dyn_cast(PT.getElementType())) { ET = ST.getBody()[fnum]; } else { ET = PT.getElementType() @@ -159,7 +159,7 @@ ValueCategory MLIRScanner::getComplexPartRef(mlir::Location loc, /// Get real (fnum = 0) or imaginary (fnum = 1) part of a complex float mlir::Value MLIRScanner::getComplexPart(mlir::Location loc, mlir::Value complex, int fnum) { - if (auto ft = llvm::dyn_cast(complex.getType())) { + if (auto ft = dyn_cast(complex.getType())) { if (fnum == 0) return complex; else @@ -170,9 +170,9 @@ mlir::Value MLIRScanner::getComplexPart(mlir::Location loc, mlir::Value complex, return builder.create(loc, complex, fnum); } auto ref = getComplexPartRef(loc, complex, fnum).val; - if (auto mt = llvm::dyn_cast(ref.getType())) { + if (auto mt = dyn_cast(ref.getType())) { return builder.create(loc, ref); - } else if (auto PT = llvm::dyn_cast(ref.getType())) { + } else if (auto PT = dyn_cast(ref.getType())) { return builder.create(loc, ref); } else { assert(0); @@ -415,12 +415,12 @@ void MLIRScanner::init(mlir::func::FuncOp function, const FunctionDecl *fd) { if (D->getParent()->isUnion() && D->isDefaulted()) { mlir::Value V = ThisVal.val; assert(V); - if (auto MT = llvm::dyn_cast(V.getType())) { + if (auto MT = dyn_cast(V.getType())) { V = builder.create( loc, LLVM::LLVMPointerType::get(MT.getElementType()), V); } mlir::Value src = function.getArgument(1); - if (auto MT = llvm::dyn_cast(src.getType())) { + if (auto MT = dyn_cast(src.getType())) { src = builder.create( loc, LLVM::LLVMPointerType::get(MT.getElementType()), src); } @@ -608,7 +608,7 @@ MLIRScanner::VisitExtVectorElementExpr(clang::ExtVectorElementExpr *expr) { builder.create(exprLoc, indices[0], 32), }; - if (const auto pt = llvm::dyn_cast(et)) { + if (const auto pt = dyn_cast(et)) { auto pt0 = pt.getElementType().cast().getElementType(); base.val = builder.create( @@ -616,7 +616,7 @@ MLIRScanner::VisitExtVectorElementExpr(clang::ExtVectorElementExpr *expr) { base.val, idxs); result = ValueCategory(base.val, true); - } else if (const auto mt = llvm::dyn_cast(et)) { + } else if (const auto mt = dyn_cast(et)) { auto shape = std::vector(mt.getShape()); if (shape.size() == 1) { @@ -642,7 +642,7 @@ MLIRScanner::VisitExtVectorElementExpr(clang::ExtVectorElementExpr *expr) { ValueCategory MLIRScanner::VisitConstantExpr(clang::ConstantExpr *expr) { auto sv = Visit(expr->getSubExpr()); - if (auto ty = llvm::dyn_cast(getMLIRType(expr->getType()))) { + if (auto ty = dyn_cast(getMLIRType(expr->getType()))) { if (expr->hasAPValueResult()) { return ValueCategory(builder.create( getMLIRLocation(expr->getExprLoc()), @@ -699,7 +699,7 @@ MLIRScanner::VisitImaginaryLiteral(clang::ImaginaryLiteral *expr) { auto loc = getMLIRLocation(expr->getExprLoc()); auto convertedType = getMLIRType(expr->getType()); mlir::FloatType fty; - if (auto mt = llvm::dyn_cast(convertedType)) { + if (auto mt = dyn_cast(convertedType)) { auto elty = mt.getElementType(); if (auto ST = dyn_cast(elty)) { fty = ST.getBody()[0].cast(); @@ -743,21 +743,21 @@ MLIRScanner::VisitImplicitValueInitExpr(clang::ImplicitValueInitExpr *decl) { auto Mty = getMLIRType(decl->getType()); auto loc = getMLIRLocation(decl->getExprLoc()); - if (auto FT = llvm::dyn_cast(Mty)) + if (auto FT = dyn_cast(Mty)) return ValueCategory(builder.create( loc, APFloat(FT.getFloatSemantics(), "0"), FT), /*isReference*/ false); - if (auto IT = llvm::dyn_cast(Mty)) + if (auto IT = dyn_cast(Mty)) return ValueCategory(builder.create(loc, 0, IT), /*isReference*/ false); - if (auto MT = llvm::dyn_cast(Mty)) + if (auto MT = dyn_cast(Mty)) return ValueCategory( builder.create( loc, MT, builder.create( loc, LLVM::LLVMPointerType::get(builder.getI8Type()))), false); - if (auto PT = llvm::dyn_cast(Mty)) + if (auto PT = dyn_cast(Mty)) return ValueCategory(builder.create(loc, PT), false); for (auto child : decl->children()) { child->dump(); @@ -777,7 +777,7 @@ mlir::Attribute MLIRScanner::InitializeValueByInitListExpr(mlir::Value toInit, bool inner = false; if (isa(PTT) || isa(PTT)) { - if (auto mt = llvm::dyn_cast(toInit.getType())) { + if (auto mt = dyn_cast(toInit.getType())) { inner = true; } } @@ -794,7 +794,7 @@ mlir::Attribute MLIRScanner::InitializeValueByInitListExpr(mlir::Value toInit, if (InitListExpr *initListExpr = dyn_cast(expr)) { if (inner) { - if (auto mt = llvm::dyn_cast(toInit.getType())) { + if (auto mt = dyn_cast(toInit.getType())) { auto shape = std::vector(mt.getShape()); shape.erase(shape.begin()); auto mt0 = mlir::MemRefType::get(shape, mt.getElementType(), @@ -807,17 +807,17 @@ mlir::Attribute MLIRScanner::InitializeValueByInitListExpr(mlir::Value toInit, unsigned num = 0; if (initListExpr->hasArrayFiller()) { - if (auto MT = llvm::dyn_cast(toInit.getType())) { + if (auto MT = dyn_cast(toInit.getType())) { auto shape = MT.getShape(); assert(shape.size() > 0); assert(shape[0] != ShapedType::kDynamic); num = shape[0]; } else if (auto PT = - llvm::dyn_cast(toInit.getType())) { - if (auto AT = llvm::dyn_cast(PT.getElementType())) { + dyn_cast(toInit.getType())) { + if (auto AT = dyn_cast(PT.getElementType())) { num = AT.getNumElements(); } else if (auto AT = - llvm::dyn_cast(PT.getElementType())) { + dyn_cast(PT.getElementType())) { num = AT.getBody().size(); } else { toInit.getType().dump(); @@ -834,7 +834,7 @@ mlir::Attribute MLIRScanner::InitializeValueByInitListExpr(mlir::Value toInit, SmallVector attrs; bool allSub = true; - if (auto mt = llvm::dyn_cast(toInit.getType())) { + if (auto mt = dyn_cast(toInit.getType())) { auto shape = std::vector(mt.getShape()); if (shape.size() == 0) { auto ET = mt.getElementType(); @@ -853,7 +853,7 @@ mlir::Attribute MLIRScanner::InitializeValueByInitListExpr(mlir::Value toInit, for (unsigned i = 0, e = num; i < e; ++i) { mlir::Value next; - if (auto mt = llvm::dyn_cast(toInit.getType())) { + if (auto mt = dyn_cast(toInit.getType())) { auto shape = std::vector(mt.getShape()); assert(shape.size() > 0); shape[0] = ShapedType::kDynamic; @@ -866,9 +866,9 @@ mlir::Attribute MLIRScanner::InitializeValueByInitListExpr(mlir::Value toInit, auto PT = toInit.getType().cast(); auto ET = PT.getElementType(); mlir::Type nextType; - if (auto ST = llvm::dyn_cast(ET)) + if (auto ST = dyn_cast(ET)) nextType = ST.getBody()[i]; - else if (auto AT = llvm::dyn_cast(ET)) + else if (auto AT = dyn_cast(ET)) nextType = AT.getElementType(); else assert(0 && "unknown inner type"); @@ -900,7 +900,7 @@ mlir::Attribute MLIRScanner::InitializeValueByInitListExpr(mlir::Value toInit, } if (!allSub) return mlir::DenseElementsAttr(); - if (auto mt = llvm::dyn_cast(toInit.getType())) { + if (auto mt = dyn_cast(toInit.getType())) { std::vector shape(mt.getShape()); assert(shape.size() > 0); shape[0] = num; @@ -915,7 +915,7 @@ mlir::Attribute MLIRScanner::InitializeValueByInitListExpr(mlir::Value toInit, ValueCategory(toInit, /*isReference*/ true) .store(loc, builder, sub, isArray); if (!sub.isReference) - if (auto mt = llvm::dyn_cast(toInit.getType())) { + if (auto mt = dyn_cast(toInit.getType())) { if (auto cop = sub.val.getDefiningOp()) return DenseElementsAttr::get( RankedTensorType::get(std::vector({1}), @@ -1246,11 +1246,11 @@ ValueCategory MLIRScanner::VisitLambdaExpr(clang::LambdaExpr *expr) { bool isArray = false; Glob.getMLIRType(expr->getCallOperator()->getThisObjectType(), &isArray); - if (auto PT = llvm::dyn_cast(t)) { + if (auto PT = dyn_cast(t)) { LLVMABI = true; t = PT.getElementType(); } - if (auto mt = llvm::dyn_cast(t)) { + if (auto mt = dyn_cast(t)) { auto shape = std::vector(mt.getShape()); if (!isArray) { t = mt.getElementType(); @@ -1313,7 +1313,7 @@ ValueCategory MLIRScanner::VisitLambdaExpr(clang::LambdaExpr *expr) { auto val = result.val; - if (auto mt = llvm::dyn_cast(val.getType())) { + if (auto mt = dyn_cast(val.getType())) { auto shape = std::vector(mt.getShape()); shape[0] = ShapedType::kDynamic; val = builder.create( @@ -1401,8 +1401,8 @@ ValueCategory MLIRScanner::VisitCXXNewExpr(clang::CXXNewExpr *expr) { if (!expr->placement_arguments().empty()) { mlir::Value val = Visit(*expr->placement_arg_begin()).getValue(loc, builder); - if (auto mt = llvm::dyn_cast(ty)) { - if (auto mtin = llvm::dyn_cast(val.getType())) { + if (auto mt = dyn_cast(ty)) { + if (auto mtin = dyn_cast(val.getType())) { val = builder.create( loc, LLVM::LLVMPointerType::get(mtin.getElementType(), @@ -1422,7 +1422,7 @@ ValueCategory MLIRScanner::VisitCXXNewExpr(clang::CXXNewExpr *expr) { PT.getAddressSpace()), alloc); } - } else if (auto mt = llvm::dyn_cast(ty)) { + } else if (auto mt = dyn_cast(ty)) { auto shape = std::vector(mt.getShape()); mlir::Value args[1] = {count}; arrayCons = alloc = builder.create(loc, mt, args); @@ -1509,14 +1509,14 @@ MLIRScanner::VisitCXXScalarValueInitExpr(clang::CXXScalarValueInitExpr *expr) { if (melem.isa()) return ValueCategory(builder.create(loc, 0, melem), false); - else if (auto MT = llvm::dyn_cast(melem)) + else if (auto MT = dyn_cast(melem)) return ValueCategory( builder.create( loc, MT, builder.create( loc, LLVM::LLVMPointerType::get(builder.getI8Type()))), false); - else if (auto PT = llvm::dyn_cast(melem)) + else if (auto PT = dyn_cast(melem)) return ValueCategory(builder.create(loc, PT), false); else { if (!melem.isa()) @@ -1635,7 +1635,7 @@ ValueCategory MLIRScanner::CommonArrayToPointer(mlir::Location loc, ValueCategory scalar) { assert(scalar.val); assert(scalar.isReference); - if (auto PT = llvm::dyn_cast(scalar.val.getType())) { + if (auto PT = dyn_cast(scalar.val.getType())) { if (PT.getElementType().isa()) return ValueCategory(scalar.val, /*isRef*/ false); mlir::Value vec[2] = {builder.create(loc, 0, 32), @@ -1918,8 +1918,8 @@ MLIRScanner::EmitGPUCallExpr(clang::CallExpr *expr) { sub = BC->getSubExpr(); { auto dst = Visit(sub).getValue(loc, builder); - if (auto omt = llvm::dyn_cast(dst.getType())) { - if (auto mt = llvm::dyn_cast(omt.getElementType())) { + if (auto omt = dyn_cast(dst.getType())) { + if (auto mt = dyn_cast(omt.getElementType())) { auto shape = std::vector(mt.getShape()); auto elemSize = getTypeSize( @@ -2133,7 +2133,7 @@ ValueCategory MLIRScanner::VisitUnaryOperator(clang::UnaryOperator *U) { assert(sub.val); mlir::Value val = sub.getValue(loc, builder); - if (auto MT = llvm::dyn_cast(val.getType())) { + if (auto MT = dyn_cast(val.getType())) { val = builder.create( loc, LLVM::LLVMPointerType::get(MT.getElementType(), @@ -2142,7 +2142,7 @@ ValueCategory MLIRScanner::VisitUnaryOperator(clang::UnaryOperator *U) { } auto postTy = getMLIRType(U->getType()).cast(); - if (auto LT = llvm::dyn_cast(val.getType())) { + if (auto LT = dyn_cast(val.getType())) { auto nullptr_llvm = builder.create(loc, LT); mlir::Value ne = builder.create( loc, mlir::LLVM::ICmpPredicate::eq, val, nullptr_llvm); @@ -2211,7 +2211,7 @@ ValueCategory MLIRScanner::VisitUnaryOperator(clang::UnaryOperator *U) { case clang::UnaryOperator::Opcode::UO_Minus: { mlir::Value val = sub.getValue(loc, builder); auto ty = val.getType(); - if (auto ft = llvm::dyn_cast(ty)) { + if (auto ft = dyn_cast(ty)) { if (auto CI = val.getDefiningOp()) { auto api = CI.getValue().cast().getValue(); return ValueCategory(builder.create( @@ -2242,7 +2242,7 @@ ValueCategory MLIRScanner::VisitUnaryOperator(clang::UnaryOperator *U) { auto ty = prev.getType(); mlir::Value next; - if (auto ft = llvm::dyn_cast(ty)) { + if (auto ft = dyn_cast(ty)) { if (prev.getType() != ty) { U->dump(); llvm::errs() << " ty: " << ty << "prev: " << prev << "\n"; @@ -2252,7 +2252,7 @@ ValueCategory MLIRScanner::VisitUnaryOperator(clang::UnaryOperator *U) { loc, prev, builder.create( loc, APFloat(ft.getFloatSemantics(), "1"), ft)); - } else if (auto mt = llvm::dyn_cast(ty)) { + } else if (auto mt = dyn_cast(ty)) { auto shape = std::vector(mt.getShape()); shape[0] = ShapedType::kDynamic; auto mt0 = mlir::MemRefType::get(shape, mt.getElementType(), @@ -2260,7 +2260,7 @@ ValueCategory MLIRScanner::VisitUnaryOperator(clang::UnaryOperator *U) { mt.getMemorySpace()); next = builder.create(loc, mt0, prev, getConstantIndex(1)); - } else if (auto pt = llvm::dyn_cast(ty)) { + } else if (auto pt = dyn_cast(ty)) { auto ity = mlir::IntegerType::get(builder.getContext(), 64); next = builder.create( loc, pt, prev, @@ -2294,18 +2294,18 @@ ValueCategory MLIRScanner::VisitUnaryOperator(clang::UnaryOperator *U) { auto prev = sub.getValue(loc, builder); mlir::Value next; - if (auto ft = llvm::dyn_cast(ty)) { + if (auto ft = dyn_cast(ty)) { next = builder.create( loc, prev, builder.create( loc, APFloat(ft.getFloatSemantics(), "1"), ft)); - } else if (auto pt = llvm::dyn_cast(ty)) { + } else if (auto pt = dyn_cast(ty)) { auto ity = mlir::IntegerType::get(builder.getContext(), 64); next = builder.create( loc, pt, prev, std::vector( {builder.create(loc, ShapedType::kDynamic, ity)})); - } else if (auto mt = llvm::dyn_cast(ty)) { + } else if (auto mt = dyn_cast(ty)) { auto shape = std::vector(mt.getShape()); shape[0] = ShapedType::kDynamic; auto mt0 = mlir::MemRefType::get(shape, mt.getElementType(), @@ -2404,7 +2404,7 @@ bool hasAffineArith(Operation *op, AffineExpr &expr, if (!isa(maybeIndexCast)) return false; auto indexCastOperand = maybeIndexCast->getOperand(0); - if (auto blockArg = llvm::dyn_cast(indexCastOperand)) { + if (auto blockArg = dyn_cast(indexCastOperand)) { if (auto affineForOp = dyn_cast( blockArg.getOwner()->getParentOp())) affineForIndVar = affineForOp.getInductionVar(); @@ -2488,7 +2488,7 @@ ValueCategory MLIRScanner::VisitAtomicExpr(clang::AtomicExpr *BO) { auto a0 = Visit(BO->getPtr()).getValue(loc, builder); auto ret = Visit(BO->getVal1()).dereference(loc, builder); mlir::Type ty; - if (auto MT = llvm::dyn_cast(a0.getType())) { + if (auto MT = dyn_cast(a0.getType())) { ty = MT.getElementType(); } else { ty = a0.getType().cast().getElementType(); @@ -2533,7 +2533,7 @@ ValueCategory MLIRScanner::VisitAtomicExpr(clang::AtomicExpr *BO) { Visit(BO->getVal1()).dereference(loc, builder).getValue(loc, builder); auto a2 = Visit(BO->getVal2()).dereference(loc, builder).getValue(loc, builder); - if (auto mt = llvm::dyn_cast(a0.getType())) { + if (auto mt = dyn_cast(a0.getType())) { a0 = builder.create( loc, LLVM::LLVMPointerType::get(mt.getElementType(), @@ -2593,14 +2593,14 @@ ValueCategory MLIRScanner::VisitBinaryOperator(clang::BinaryOperator *BO) { case clang::BinaryOperator::Opcode::BO_LAnd: { mlir::Type types[] = {builder.getIntegerType(1)}; auto cond = lhs.getValue(loc, builder); - if (auto mt = llvm::dyn_cast(cond.getType())) { + if (auto mt = dyn_cast(cond.getType())) { cond = builder.create( loc, LLVM::LLVMPointerType::get(mt.getElementType(), mt.getMemorySpaceAsInt()), cond); } - if (auto LT = llvm::dyn_cast(cond.getType())) { + if (auto LT = dyn_cast(cond.getType())) { auto nullptr_llvm = builder.create(loc, LT); cond = builder.create( loc, mlir::LLVM::ICmpPredicate::ne, cond, nullptr_llvm); @@ -2625,7 +2625,7 @@ ValueCategory MLIRScanner::VisitBinaryOperator(clang::BinaryOperator *BO) { auto rhs = Visit(BO->getRHS()).getValue(loc, builder); assert(rhs != nullptr); - if (auto LT = llvm::dyn_cast(rhs.getType())) { + if (auto LT = dyn_cast(rhs.getType())) { auto nullptr_llvm = builder.create(loc, LT); rhs = builder.create( loc, mlir::LLVM::ICmpPredicate::ne, rhs, nullptr_llvm); @@ -2809,11 +2809,11 @@ ValueCategory MLIRScanner::VisitBinaryOperator(clang::BinaryOperator *BO) { auto lhs_v = lhs.getValue(loc, builder); auto rhs_v = rhs.getValue(loc, builder); - if (auto mt = llvm::dyn_cast(lhs_v.getType())) { + if (auto mt = dyn_cast(lhs_v.getType())) { lhs_v = builder.create( loc, LLVM::LLVMPointerType::get(mt.getElementType()), lhs_v); } - if (auto mt = llvm::dyn_cast(rhs_v.getType())) { + if (auto mt = dyn_cast(rhs_v.getType())) { rhs_v = builder.create( loc, LLVM::LLVMPointerType::get(mt.getElementType()), rhs_v); } @@ -2913,7 +2913,7 @@ ValueCategory MLIRScanner::VisitBinaryOperator(clang::BinaryOperator *BO) { } else if (rhs_v.getType().isa()) { return emitSubindex(rhs_v, lhs_v); } else if (auto pt = - llvm::dyn_cast(lhs_v.getType())) { + dyn_cast(lhs_v.getType())) { return ValueCategory( builder.create(loc, pt, lhs_v, std::vector({rhs_v})), @@ -2937,7 +2937,7 @@ ValueCategory MLIRScanner::VisitBinaryOperator(clang::BinaryOperator *BO) { } auto lhs_v = lhs.getValue(loc, builder); auto rhs_v = rhs.getValue(loc, builder); - if (auto mt = llvm::dyn_cast(lhs_v.getType())) { + if (auto mt = dyn_cast(lhs_v.getType())) { mlir::Type innerType = mt.getElementType(); auto shape = mt.getShape(); for (size_t i = 1; i < shape.size(); i++) @@ -2945,7 +2945,7 @@ ValueCategory MLIRScanner::VisitBinaryOperator(clang::BinaryOperator *BO) { lhs_v = builder.create( loc, LLVM::LLVMPointerType::get(innerType), lhs_v); } - if (auto mt = llvm::dyn_cast(rhs_v.getType())) { + if (auto mt = dyn_cast(rhs_v.getType())) { mlir::Type innerType = mt.getElementType(); auto shape = mt.getShape(); for (size_t i = 1; i < shape.size(); i++) @@ -2958,8 +2958,8 @@ ValueCategory MLIRScanner::VisitBinaryOperator(clang::BinaryOperator *BO) { return ValueCategory(builder.create(loc, lhs_v, rhs_v), /*isReference*/ false); } else if (auto pt = - llvm::dyn_cast(lhs_v.getType())) { - if (auto IT = llvm::dyn_cast(rhs_v.getType())) { + dyn_cast(lhs_v.getType())) { + if (auto IT = dyn_cast(rhs_v.getType())) { mlir::Value vals[1] = {builder.create( loc, builder.create(loc, 0, IT.getWidth()), rhs_v)}; return ValueCategory( @@ -2990,13 +2990,13 @@ ValueCategory MLIRScanner::VisitBinaryOperator(clang::BinaryOperator *BO) { assert(lhs.isReference); mlir::Value tostore = rhs.getValue(loc, builder); mlir::Type subType; - if (auto PT = llvm::dyn_cast(lhs.val.getType())) + if (auto PT = dyn_cast(lhs.val.getType())) subType = PT.getElementType(); else subType = lhs.val.getType().cast().getElementType(); if (tostore.getType() != subType) { - if (auto prevTy = llvm::dyn_cast(tostore.getType())) { - if (auto postTy = llvm::dyn_cast(subType)) { + if (auto prevTy = dyn_cast(tostore.getType())) { + if (auto postTy = dyn_cast(subType)) { bool signedType = true; if (auto bit = dyn_cast(&*BO->getType())) { if (bit->isUnsignedInteger()) @@ -3042,7 +3042,7 @@ ValueCategory MLIRScanner::VisitBinaryOperator(clang::BinaryOperator *BO) { return lhs; } auto prev = lhs.getValue(loc, builder); - if (auto postTy = llvm::dyn_cast(prev.getType())) { + if (auto postTy = dyn_cast(prev.getType())) { mlir::Value rhsV = rhs.getValue(loc, builder); auto prevTy = rhsV.getType().cast(); if (prevTy == postTy) { @@ -3054,11 +3054,11 @@ ValueCategory MLIRScanner::VisitBinaryOperator(clang::BinaryOperator *BO) { assert(rhsV.getType() == prev.getType()); result = builder.create(loc, prev, rhsV); } else if (auto pt = - llvm::dyn_cast(prev.getType())) { + dyn_cast(prev.getType())) { result = builder.create( loc, pt, prev, std::vector({rhs.getValue(loc, builder)})); - } else if (auto postTy = llvm::dyn_cast(prev.getType())) { + } else if (auto postTy = dyn_cast(prev.getType())) { mlir::Value rhsV = rhs.getValue(loc, builder); auto prevTy = rhsV.getType().cast(); if (prevTy == postTy) { @@ -3073,7 +3073,7 @@ ValueCategory MLIRScanner::VisitBinaryOperator(clang::BinaryOperator *BO) { } assert(rhsV.getType() == prev.getType()); result = builder.create(loc, prev, rhsV); - } else if (auto postTy = llvm::dyn_cast(prev.getType())) { + } else if (auto postTy = dyn_cast(prev.getType())) { mlir::Value rhsV = rhs.getValue(loc, builder); auto shape = std::vector(postTy.getShape()); shape[0] = ShapedType::kDynamic; @@ -3303,7 +3303,7 @@ ValueCategory MLIRScanner::CommonFieldLookup(mlir::Location loc, } } - if (auto mt = llvm::dyn_cast(val.getType())) { + if (auto mt = dyn_cast(val.getType())) { auto shape = std::vector(mt.getShape()); if (shape.size() > 1) { shape.erase(shape.begin()); @@ -3342,7 +3342,7 @@ ValueCategory MLIRScanner::CommonFieldLookup(mlir::Location loc, << " ST: " << *ST << "\n"; } mlir::Type ET; - if (auto ST = llvm::dyn_cast(PT.getElementType())) { + if (auto ST = dyn_cast(PT.getElementType())) { ET = ST.getBody()[fnum]; } else { ET = PT.getElementType().cast().getElementType(); @@ -3356,7 +3356,7 @@ ValueCategory MLIRScanner::CommonFieldLookup(mlir::Location loc, Glob.CGM.getContext().getPointerType(FD->getType()), &isArray); assert(!isArray); if (rd->isUnion()) { - if (auto PT2 = llvm::dyn_cast(subType)) + if (auto PT2 = dyn_cast(subType)) commonGEP = builder.create( loc, mlir::LLVM::LLVMPointerType::get(PT2.getElementType(), @@ -3372,7 +3372,7 @@ ValueCategory MLIRScanner::CommonFieldLookup(mlir::Location loc, commonGEP); } } else { - if (auto mt = llvm::dyn_cast(subType)) { + if (auto mt = dyn_cast(subType)) { commonGEP = builder.create( loc, mlir::MemRefType::get( @@ -3627,7 +3627,7 @@ mlir::Value MLIRScanner::GetAddressOfDerivedClass( } mlir::Value ptr = value; - if (auto PT = llvm::dyn_cast(ptr.getType())) { + if (auto PT = dyn_cast(ptr.getType())) { ptr = builder.create( loc, LLVM::LLVMPointerType::get(builder.getI8Type(), PT.getAddressSpace()), @@ -3643,7 +3643,7 @@ mlir::Value MLIRScanner::GetAddressOfDerivedClass( mlir::Value idx[] = {Offset}; ptr = builder.create(loc, ptr.getType(), ptr, idx); - if (auto PT = llvm::dyn_cast(nt)) + if (auto PT = dyn_cast(nt)) value = builder.create( loc, LLVM::LLVMPointerType::get( @@ -3704,7 +3704,7 @@ mlir::Value MLIRScanner::GetAddressOfBaseClass( if (subIndex) { bool done = false; - if (auto mt = llvm::dyn_cast(value.getType())) { + if (auto mt = dyn_cast(value.getType())) { auto shape = std::vector(mt.getShape()); if (shape.size() > 1) { shape.erase(shape.begin()); @@ -3730,7 +3730,7 @@ mlir::Value MLIRScanner::GetAddressOfBaseClass( auto PT = value.getType().cast(); mlir::Type ET; if (auto ST = - llvm::dyn_cast(PT.getElementType())) { + dyn_cast(PT.getElementType())) { ET = ST.getBody()[fnum]; } else { ET = PT.getElementType() @@ -3744,8 +3744,8 @@ mlir::Value MLIRScanner::GetAddressOfBaseClass( } } - auto pt = llvm::dyn_cast(nt); - if (auto opt = llvm::dyn_cast(value.getType())) { + auto pt = dyn_cast(nt); + if (auto opt = dyn_cast(value.getType())) { if (!pt) { value = builder.create(loc, nt, value); } else { @@ -3820,14 +3820,14 @@ ValueCategory MLIRScanner::VisitCastExpr(CastExpr *E) { if (E->getCastKind() != clang::CastKind::CK_UncheckedDerivedToBase && !isa(E->IgnoreParens())) { mlir::Value ptr = val; - if (auto MT = llvm::dyn_cast(ptr.getType())) + if (auto MT = dyn_cast(ptr.getType())) ptr = builder.create( loc, LLVM::LLVMPointerType::get(MT.getElementType()), ptr); mlir::Value nullptr_llvm = builder.create(loc, ptr.getType()); auto ne = builder.create( loc, mlir::LLVM::ICmpPredicate::ne, ptr, nullptr_llvm); - if (auto MT = llvm::dyn_cast(ptr.getType())) + if (auto MT = dyn_cast(ptr.getType())) nullptr_llvm = builder.create(loc, MT, nullptr_llvm); val = builder.create(loc, ne, ptr, nullptr_llvm); @@ -3849,12 +3849,12 @@ ValueCategory MLIRScanner::VisitCastExpr(CastExpr *E) { /* if (ShouldNullCheckClassCastValue(E)) { mlir::Value ptr = val; - if (auto MT = llvm::dyn_cast(ptr.getType())) + if (auto MT = dyn_cast(ptr.getType())) ptr = builder.create(loc, LLVM::LLVMPointerType::get(MT.getElementType()), ptr); auto nullptr_llvm = builder.create(loc, ptr.getType()); auto ne = builder.create( loc, mlir::LLVM::ICmpPredicate::ne, ptr, - nullptr_llvm); if (auto MT = llvm::dyn_cast(ptr.getType())) + nullptr_llvm); if (auto MT = dyn_cast(ptr.getType())) nullptr_llvm = builder.create(loc, MT, nullptr_llvm); val = builder.create(loc, ne, val, nullptr_llvm); @@ -3869,9 +3869,9 @@ ValueCategory MLIRScanner::VisitCastExpr(CastExpr *E) { } auto scalar = se.val; assert(se.isReference); - if (auto spt = llvm::dyn_cast(scalar.getType())) { + if (auto spt = dyn_cast(scalar.getType())) { auto nt = getMLIRType(E->getType()); - LLVM::LLVMPointerType pt = llvm::dyn_cast(nt); + LLVM::LLVMPointerType pt = dyn_cast(nt); if (!pt) { return ValueCategory( builder.create(loc, nt, scalar), @@ -3891,11 +3891,11 @@ ValueCategory MLIRScanner::VisitCastExpr(CastExpr *E) { auto mlirty = getMLIRType(Glob.CGM.getContext().getLValueReferenceType(E->getType())); - if (auto PT = llvm::dyn_cast(mlirty)) { + if (auto PT = dyn_cast(mlirty)) { return ValueCategory( builder.create(loc, PT, scalar), /*isReference*/ true); - } else if (auto mt = llvm::dyn_cast(mlirty)) { + } else if (auto mt = dyn_cast(mlirty)) { auto ty = mlir::MemRefType::get(mt.getShape(), mt.getElementType(), MemRefLayoutAttrInterface(), ut.getMemorySpace()); @@ -3940,7 +3940,7 @@ ValueCategory MLIRScanner::VisitCastExpr(CastExpr *E) { if (sr->getDecl()->getIdentifier() && sr->getDecl()->getName() == "polybench_alloc_data") { if (auto mt = - llvm::dyn_cast(getMLIRType(E->getType()))) { + dyn_cast(getMLIRType(E->getType()))) { auto shape = std::vector(mt.getShape()); // shape.erase(shape.begin()); auto mt0 = mlir::MemRefType::get(shape, mt.getElementType(), @@ -3960,7 +3960,7 @@ ValueCategory MLIRScanner::VisitCastExpr(CastExpr *E) { (sr->getDecl()->getName() == "malloc" || sr->getDecl()->getName() == "calloc")) if (auto mt = - llvm::dyn_cast(getMLIRType(E->getType()))) { + dyn_cast(getMLIRType(E->getType()))) { auto shape = std::vector(mt.getShape()); auto elemSize = getTypeSize( @@ -4011,9 +4011,9 @@ ValueCategory MLIRScanner::VisitCastExpr(CastExpr *E) { E->dump(); } auto scalar = se.getValue(loc, builder); - if (auto spt = llvm::dyn_cast(scalar.getType())) { + if (auto spt = dyn_cast(scalar.getType())) { auto nt = getMLIRType(E->getType()); - LLVM::LLVMPointerType pt = llvm::dyn_cast(nt); + LLVM::LLVMPointerType pt = dyn_cast(nt); if (!pt) { return ValueCategory( builder.create(loc, nt, scalar), @@ -4032,11 +4032,11 @@ ValueCategory MLIRScanner::VisitCastExpr(CastExpr *E) { auto ut = scalar.getType().cast(); auto mlirty = getMLIRType(E->getType()); - if (auto PT = llvm::dyn_cast(mlirty)) { + if (auto PT = dyn_cast(mlirty)) { return ValueCategory( builder.create(loc, PT, scalar), /*isReference*/ false); - } else if (auto mt = llvm::dyn_cast(mlirty)) { + } else if (auto mt = dyn_cast(mlirty)) { auto ty = mlir::MemRefType::get(mt.getShape(), mt.getElementType(), MemRefLayoutAttrInterface(), ut.getMemorySpace()); @@ -4260,16 +4260,16 @@ ValueCategory MLIRScanner::VisitCastExpr(CastExpr *E) { mlir::FloatType postScalarTy; auto prevTy = complex.getType(); auto postTy = getMLIRType(E->getType()); - if (auto mt = llvm::dyn_cast(postTy)) { + if (auto mt = dyn_cast(postTy)) { postScalarTy = mt.getElementType().cast(); - } else if (auto ST = llvm::dyn_cast(postTy)) { + } else if (auto ST = dyn_cast(postTy)) { postScalarTy = ST.getBody()[0].cast(); } else { assert(0 && "unexpected complex type\n"); } - if (auto mt = llvm::dyn_cast(prevTy)) { + if (auto mt = dyn_cast(prevTy)) { prevScalarTy = mt.getElementType().cast(); - } else if (auto ST = llvm::dyn_cast(prevTy)) { + } else if (auto ST = dyn_cast(prevTy)) { prevScalarTy = ST.getBody()[0].cast(); } else { assert(0 && "unexpected complex type\n"); @@ -4325,11 +4325,11 @@ ValueCategory MLIRScanner::VisitCastExpr(CastExpr *E) { } case clang::CastKind::CK_PointerToBoolean: { auto scalar = Visit(E->getSubExpr()).getValue(loc, builder); - if (auto mt = llvm::dyn_cast(scalar.getType())) { + if (auto mt = dyn_cast(scalar.getType())) { scalar = builder.create( loc, LLVM::LLVMPointerType::get(mt.getElementType()), scalar); } - if (auto LT = llvm::dyn_cast(scalar.getType())) { + if (auto LT = dyn_cast(scalar.getType())) { auto nullptr_llvm = builder.create(loc, LT); auto ne = builder.create( loc, mlir::LLVM::ICmpPredicate::ne, scalar, nullptr_llvm); @@ -4342,11 +4342,11 @@ ValueCategory MLIRScanner::VisitCastExpr(CastExpr *E) { } case clang::CastKind::CK_PointerToIntegral: { auto scalar = Visit(E->getSubExpr()).getValue(loc, builder); - if (auto mt = llvm::dyn_cast(scalar.getType())) { + if (auto mt = dyn_cast(scalar.getType())) { scalar = builder.create( loc, LLVM::LLVMPointerType::get(mt.getElementType()), scalar); } - if (auto LT = llvm::dyn_cast(scalar.getType())) { + if (auto LT = dyn_cast(scalar.getType())) { auto mlirType = getMLIRType(E->getType()); auto val = builder.create(loc, mlirType, scalar); return ValueCategory(val, /*isReference*/ false); @@ -4426,7 +4426,7 @@ ValueCategory MLIRScanner::VisitCastExpr(CastExpr *E) { auto convertedType = getMLIRType(E->getType()); auto real = sub.getValue(loc, builder); mlir::FloatType fty; - if (auto mt = llvm::dyn_cast(convertedType)) { + if (auto mt = dyn_cast(convertedType)) { auto elty = mt.getElementType(); if (auto ST = dyn_cast(elty)) { fty = ST.getBody()[0].cast(); @@ -4456,14 +4456,14 @@ MLIRScanner::VisitConditionalOperator(clang::ConditionalOperator *E) { auto loc = getMLIRLocation(E->getExprLoc()); auto cond = Visit(E->getCond()).getValue(loc, builder); assert(cond != nullptr); - if (auto mt = llvm::dyn_cast(cond.getType())) { + if (auto mt = dyn_cast(cond.getType())) { cond = builder.create( loc, LLVM::LLVMPointerType::get(mt.getElementType(), mt.getMemorySpaceAsInt()), cond); } - if (auto LT = llvm::dyn_cast(cond.getType())) { + if (auto LT = dyn_cast(cond.getType())) { auto nullptr_llvm = builder.create(loc, LT); cond = builder.create( loc, mlir::LLVM::ICmpPredicate::ne, cond, nullptr_llvm); @@ -4507,7 +4507,7 @@ MLIRScanner::VisitConditionalOperator(clang::ConditionalOperator *E) { truev = trueExpr.val; } else { if (trueExpr.isReference) - if (auto mt = llvm::dyn_cast(trueExpr.val.getType())) + if (auto mt = dyn_cast(trueExpr.val.getType())) if (mt.getShape().size() != 1) { E->dump(); E->getTrueExpr()->dump(); @@ -5107,7 +5107,7 @@ MLIRASTConsumer::GetOrCreateMLIRFunction(const FunctionDecl *FD, bool isArray = false; // isa(CC->getThisType()); getMLIRType(CC->getThisObjectType(), &isArray); - if (auto mt = llvm::dyn_cast(t)) { + if (auto mt = dyn_cast(t)) { auto shape = std::vector(mt.getShape()); // shape[0] = 1; t = mlir::MemRefType::get(shape, mt.getElementType(), @@ -5513,7 +5513,7 @@ mlir::Type MLIRASTConsumer::getMLIRType(clang::QualType qt, bool *implicitRef, } // If -memref-fullrank is unset or it cannot be fulfilled. - auto mt = llvm::dyn_cast(mlirty); + auto mt = dyn_cast(mlirty); auto shape2 = std::vector(mt.getShape()); shape2[0] = ShapedType::kDynamic; return mlir::MemRefType::get(shape2, mt.getElementType(), diff --git a/tools/polymer/lib/Target/OpenScop/ConvertFromOpenScop.cc b/tools/polymer/lib/Target/OpenScop/ConvertFromOpenScop.cc index e9826fb9055e..723d2d3706e4 100644 --- a/tools/polymer/lib/Target/OpenScop/ConvertFromOpenScop.cc +++ b/tools/polymer/lib/Target/OpenScop/ConvertFromOpenScop.cc @@ -641,7 +641,7 @@ void Importer::initializeSymbol(mlir::Value val) { /// Symbols that are the block arguments won't be taken care of at this stage. /// initializeFuncOpInterface() should already have done that. - if (mlir::BlockArgument arg = llvm::dyn_cast(val)) + if (mlir::BlockArgument arg = dyn_cast(val)) return; // This defOp should be cloned to the target function, while its operands diff --git a/tools/polymer/lib/Transforms/LoopAnnotate.cc b/tools/polymer/lib/Transforms/LoopAnnotate.cc index 2cf5ee15a0e4..c72edd41ed82 100644 --- a/tools/polymer/lib/Transforms/LoopAnnotate.cc +++ b/tools/polymer/lib/Transforms/LoopAnnotate.cc @@ -36,7 +36,7 @@ using namespace polymer; static void annotatePointLoops(ValueRange operands, OpBuilder &b) { for (mlir::Value operand : operands) { // If a loop IV is directly passed into the statement call. - if (BlockArgument arg = llvm::dyn_cast(operand)) { + if (BlockArgument arg = dyn_cast(operand)) { mlir::affine::AffineForOp forOp = dyn_cast(arg.getOwner()->getParentOp()); if (forOp) { diff --git a/tools/polymer/lib/Transforms/LoopExtract.cc b/tools/polymer/lib/Transforms/LoopExtract.cc index d2ee0bec38b7..c3a7c164a513 100644 --- a/tools/polymer/lib/Transforms/LoopExtract.cc +++ b/tools/polymer/lib/Transforms/LoopExtract.cc @@ -58,7 +58,7 @@ static void getArgs(Operation *parentOp, llvm::SetVector &args) { if (Operation *defOp = operand.getDefiningOp()) { if (!internalOps.contains(defOp)) args.insert(operand); - } else if (BlockArgument bArg = llvm::dyn_cast(operand)) { + } else if (BlockArgument bArg = dyn_cast(operand)) { if (!internalOps.contains(bArg.getOwner()->getParentOp())) args.insert(operand); } else { diff --git a/tools/polymer/lib/Transforms/PlutoTransform.cc b/tools/polymer/lib/Transforms/PlutoTransform.cc index 41e23f2951ba..a5198e3a86ff 100644 --- a/tools/polymer/lib/Transforms/PlutoTransform.cc +++ b/tools/polymer/lib/Transforms/PlutoTransform.cc @@ -281,7 +281,7 @@ static void dedupIndexCast(func::FuncOp f) { SmallVector toErase; for (auto &op : entry) { if (auto indexCast = dyn_cast(&op)) { - auto arg = llvm::dyn_cast(indexCast.getOperand()); + auto arg = dyn_cast(indexCast.getOperand()); if (argToCast.count(arg)) { LLVM_DEBUG(dbgs() << "Found duplicated index_cast: " << indexCast << '\n'); diff --git a/tools/polymer/lib/Transforms/Reg2Mem.cc b/tools/polymer/lib/Transforms/Reg2Mem.cc index 658b00f9958e..ba7a02cf243f 100644 --- a/tools/polymer/lib/Transforms/Reg2Mem.cc +++ b/tools/polymer/lib/Transforms/Reg2Mem.cc @@ -210,7 +210,7 @@ static void demoteRegisterToMemory(mlir::func::FuncOp f, OpBuilder &b) { // Create the alloca op for the scratchpad. memref::AllocaOp allocaOp = createScratchpadAllocaOp( - llvm::dyn_cast(val), b, &entryBlock); + dyn_cast(val), b, &entryBlock); // Create the store op that stores val into the scratchpad for future uses. createScratchpadStoreOp(val, allocaOp, b); diff --git a/tools/polymer/lib/Transforms/ScopStmtOpt.cc b/tools/polymer/lib/Transforms/ScopStmtOpt.cc index 36a41372dd0f..eb6298681293 100644 --- a/tools/polymer/lib/Transforms/ScopStmtOpt.cc +++ b/tools/polymer/lib/Transforms/ScopStmtOpt.cc @@ -370,7 +370,7 @@ struct RewriteScratchpadTypePass // All the operands that are unranked memrefs. SmallVector unranked; for (auto operand : caller.getArgOperands()) - if (MemRefType type = llvm::dyn_cast(operand.getType())) + if (MemRefType type = dyn_cast(operand.getType())) if (!type.hasStaticShape()) unranked.push_back(operand); if (unranked.empty()) From 9c65adaca36392a6eb386d1ddd1d78152aae0c11 Mon Sep 17 00:00:00 2001 From: Jeremy Kun Date: Wed, 3 Apr 2024 09:12:02 -0700 Subject: [PATCH 4/4] clang-format --- lib/polygeist/Ops.cpp | 8 +++++--- lib/polygeist/Passes/ConvertPolygeistToLLVM.cpp | 12 ++++-------- lib/polygeist/Passes/ConvertToOpaquePtr.cpp | 7 +++---- tools/cgeist/Lib/ValueCategory.cc | 5 ++--- tools/polymer/lib/Transforms/Reg2Mem.cc | 4 ++-- 5 files changed, 16 insertions(+), 20 deletions(-) diff --git a/lib/polygeist/Ops.cpp b/lib/polygeist/Ops.cpp index f93e10030f41..926891b40611 100644 --- a/lib/polygeist/Ops.cpp +++ b/lib/polygeist/Ops.cpp @@ -4984,7 +4984,7 @@ template struct BufferElimination : public OpRewritePattern { if (!opd) continue; auto val = dyn_cast( - ((Value)load.getMapOperands()[opd.getPosition()])); + ((Value)load.getMapOperands()[opd.getPosition()])); if (!val) continue; @@ -5034,7 +5034,7 @@ template struct BufferElimination : public OpRewritePattern { if (!opd) continue; auto val = dyn_cast( - ((Value)load.getMapOperands()[opd.getPosition()])); + ((Value)load.getMapOperands()[opd.getPosition()])); if (!val) continue; @@ -5302,7 +5302,9 @@ struct AffineBufferElimination : public OpRewritePattern { auto i = idxp.index(); if (!idx.isValue) { if (auto ald = dyn_cast(ld)) { - if (auto ac = ald.getAffineMap().getResult(i).dyn_cast()) { + if (auto ac = ald.getAffineMap() + .getResult(i) + .dyn_cast()) { if (idx == ac.getValue()) continue; } diff --git a/lib/polygeist/Passes/ConvertPolygeistToLLVM.cpp b/lib/polygeist/Passes/ConvertPolygeistToLLVM.cpp index a652c80e78f3..f1d6a6ffa3ac 100644 --- a/lib/polygeist/Passes/ConvertPolygeistToLLVM.cpp +++ b/lib/polygeist/Passes/ConvertPolygeistToLLVM.cpp @@ -985,8 +985,7 @@ struct CAllocaOpLowering : public AllocLikeOpLowering { ConversionPatternRewriter &rewriter) const override { Location loc = allocaOp.getLoc(); MemRefType originalType = allocaOp.getType(); - auto convertedType = - dyn_cast_or_null( + auto convertedType = dyn_cast_or_null( getTypeConverter()->convertType(originalType)); auto elTy = convertMemrefElementTypeForLLVMPointer( originalType, *this->getTypeConverter()); @@ -1015,8 +1014,7 @@ struct CAllocOpLowering : public AllocLikeOpLowering { auto module = allocOp->getParentOfType(); Location loc = allocOp.getLoc(); MemRefType originalType = allocOp.getType(); - auto convertedType = - dyn_cast_or_null( + auto convertedType = dyn_cast_or_null( getTypeConverter()->convertType(originalType)); if (!convertedType) @@ -1197,10 +1195,8 @@ struct CLoadStoreOpLowering : public ConvertOpToLLVMPattern { ConversionPatternRewriter &rewriter) const { Location loc = op.getLoc(); MemRefType originalType = op.getMemRefType(); - auto convertedType = - dyn_cast_or_null( - this->getTypeConverter() - ->convertType(originalType)); + auto convertedType = dyn_cast_or_null( + this->getTypeConverter()->convertType(originalType)); if (!convertedType) { (void)rewriter.notifyMatchFailure(loc, "unsupported memref type"); return nullptr; diff --git a/lib/polygeist/Passes/ConvertToOpaquePtr.cpp b/lib/polygeist/Passes/ConvertToOpaquePtr.cpp index 7ef97adb2079..12a2698f2334 100644 --- a/lib/polygeist/Passes/ConvertToOpaquePtr.cpp +++ b/lib/polygeist/Passes/ConvertToOpaquePtr.cpp @@ -190,10 +190,9 @@ struct GEPConversion : public OpConversionPattern { Operation *rewritten; TypeAttr elty = nullptr; if (!op->getAttr(kElemTypeAttrName)) - elty = TypeAttr::get( - getTypeConverter()->convertType( - dyn_cast( - op.getOperand(0).getType()).getElementType())); + elty = TypeAttr::get(getTypeConverter()->convertType( + dyn_cast(op.getOperand(0).getType()) + .getElementType())); if (convertPtrsToOpaque(op, rewritten, elty, adaptor.getOperands(), rewriter, getTypeConverter()) .failed()) diff --git a/tools/cgeist/Lib/ValueCategory.cc b/tools/cgeist/Lib/ValueCategory.cc index 5c9fd4c0323d..3817a64ee14f 100644 --- a/tools/cgeist/Lib/ValueCategory.cc +++ b/tools/cgeist/Lib/ValueCategory.cc @@ -87,9 +87,8 @@ void ValueCategory::store(mlir::Location loc, mlir::OpBuilder &builder, if (auto mt = dyn_cast(val.getType())) { assert(mt.getShape().size() == 1 && "must have size 1"); if (auto PT = dyn_cast(toStore.getType())) { - if (auto MT = dyn_cast(val.getType() - .cast() - .getElementType())) { + if (auto MT = dyn_cast( + val.getType().cast().getElementType())) { assert(MT.getShape().size() == 1); assert(MT.getShape()[0] == ShapedType::kDynamic); assert(MT.getElementType() == PT.getElementType()); diff --git a/tools/polymer/lib/Transforms/Reg2Mem.cc b/tools/polymer/lib/Transforms/Reg2Mem.cc index ba7a02cf243f..042bcd283bf1 100644 --- a/tools/polymer/lib/Transforms/Reg2Mem.cc +++ b/tools/polymer/lib/Transforms/Reg2Mem.cc @@ -209,8 +209,8 @@ static void demoteRegisterToMemory(mlir::func::FuncOp f, OpBuilder &b) { mlir::Value val = defUsesPair.first; // Create the alloca op for the scratchpad. - memref::AllocaOp allocaOp = createScratchpadAllocaOp( - dyn_cast(val), b, &entryBlock); + memref::AllocaOp allocaOp = + createScratchpadAllocaOp(dyn_cast(val), b, &entryBlock); // Create the store op that stores val into the scratchpad for future uses. createScratchpadStoreOp(val, allocaOp, b);