diff --git a/flang/include/flang/Lower/IterationSpace.h b/flang/include/flang/Lower/IterationSpace.h --- a/flang/include/flang/Lower/IterationSpace.h +++ b/flang/include/flang/Lower/IterationSpace.h @@ -465,7 +465,7 @@ llvm::Optional getLhsLoad(size_t i) { assert(i < lhsBases.size()); - if (lhsBases[counter].hasValue()) + if (lhsBases[counter]) return findBinding(lhsBases[counter].getValue()); return llvm::None; } diff --git a/flang/lib/Lower/ConvertExpr.cpp b/flang/lib/Lower/ConvertExpr.cpp --- a/flang/lib/Lower/ConvertExpr.cpp +++ b/flang/lib/Lower/ConvertExpr.cpp @@ -4266,7 +4266,7 @@ auto [iterSpace, insPt] = genIterSpace(resultTy); auto exv = f(iterSpace); iterSpace.setElement(std::move(exv)); - auto lambda = ccStoreToDest.hasValue() + auto lambda = ccStoreToDest ? ccStoreToDest.getValue() : defaultStoreToDestination(/*substring=*/nullptr); mlir::Value updVal = fir::getBase(lambda(iterSpace)); @@ -4603,7 +4603,7 @@ } // Generate the lazy mask allocation, if one was given. - if (ccPrelude.hasValue()) + if (ccPrelude) ccPrelude.getValue()(shape); // Now handle the implicit loops. @@ -4663,7 +4663,7 @@ fir::ArrayLoadOp createAndLoadSomeArrayTemp(mlir::Type type, llvm::ArrayRef shape) { - if (ccLoadDest.hasValue()) + if (ccLoadDest) return ccLoadDest.getValue()(shape); auto seqTy = type.dyn_cast(); assert(seqTy && "must be an array"); @@ -5934,7 +5934,7 @@ // always loaded at the beginning of the statement and merged at the // end. destination = arrLoad; - auto lambda = ccStoreToDest.hasValue() + auto lambda = ccStoreToDest ? ccStoreToDest.getValue() : defaultStoreToDestination(components.substring); return [=](IterSpace iters) -> ExtValue { return lambda(iters); }; @@ -6573,7 +6573,7 @@ // Return the continuation. if (fir::isa_char(seqTy.getEleTy())) { - if (charLen.hasValue()) { + if (charLen) { auto len = builder.create(loc, charLen.getValue()); return genarr(fir::CharArrayBoxValue{mem, len, extents}); } @@ -7625,7 +7625,7 @@ auto genLoad = [&](const auto *x) -> fir::ArrayLoadOp { return genArrayLoad(loc, converter, builder, x, symMap, stmtCtx); }; - if (esp.lhsBases[counter].hasValue()) { + if (esp.lhsBases[counter]) { auto &base = esp.lhsBases[counter].getValue(); auto load = std::visit(genLoad, base); esp.initialArgs.push_back(load); @@ -7650,7 +7650,7 @@ load.getMemref(), load.getSlice(), load.getTypeparams()); } - if (esp.loopCleanup.hasValue()) { + if (esp.loopCleanup) { esp.loopCleanup.getValue()(builder); esp.loopCleanup = llvm::None; } diff --git a/flang/lib/Lower/IterationSpace.cpp b/flang/lib/Lower/IterationSpace.cpp --- a/flang/lib/Lower/IterationSpace.cpp +++ b/flang/lib/Lower/IterationSpace.cpp @@ -862,7 +862,7 @@ llvm::Optional Fortran::lower::ExplicitIterSpace::findArgPosition(fir::ArrayLoadOp load) { - if (lhsBases[counter].hasValue()) { + if (lhsBases[counter]) { auto ld = loadBindings.find(lhsBases[counter].getValue()); llvm::Optional optPos; if (ld != loadBindings.end() && ld->second == load) @@ -919,7 +919,7 @@ s << "LHS bases:\n"; for (const llvm::Optional &u : e.lhsBases) - if (u.hasValue()) + if (u) dump(u.getValue()); s << "RHS bases:\n"; for (const llvm::SmallVector diff --git a/flang/lib/Optimizer/CodeGen/BoxedProcedure.cpp b/flang/lib/Optimizer/CodeGen/BoxedProcedure.cpp --- a/flang/lib/Optimizer/CodeGen/BoxedProcedure.cpp +++ b/flang/lib/Optimizer/CodeGen/BoxedProcedure.cpp @@ -252,10 +252,10 @@ auto toTy = typeConverter.convertType(unwrapRefType(ty)); bool isPinned = mem.getPinned(); llvm::StringRef uniqName; - if (mem.getUniqName().hasValue()) + if (mem.getUniqName()) uniqName = mem.getUniqName().getValue(); llvm::StringRef bindcName; - if (mem.getBindcName().hasValue()) + if (mem.getBindcName()) bindcName = mem.getBindcName().getValue(); rewriter.replaceOpWithNewOp( mem, toTy, uniqName, bindcName, isPinned, mem.getTypeparams(), @@ -267,10 +267,10 @@ rewriter.setInsertionPoint(mem); auto toTy = typeConverter.convertType(unwrapRefType(ty)); llvm::StringRef uniqName; - if (mem.getUniqName().hasValue()) + if (mem.getUniqName()) uniqName = mem.getUniqName().getValue(); llvm::StringRef bindcName; - if (mem.getBindcName().hasValue()) + if (mem.getBindcName()) bindcName = mem.getBindcName().getValue(); rewriter.replaceOpWithNewOp( mem, toTy, uniqName, bindcName, mem.getTypeparams(), diff --git a/flang/lib/Optimizer/CodeGen/CodeGen.cpp b/flang/lib/Optimizer/CodeGen/CodeGen.cpp --- a/flang/lib/Optimizer/CodeGen/CodeGen.cpp +++ b/flang/lib/Optimizer/CodeGen/CodeGen.cpp @@ -2689,7 +2689,7 @@ // enumeration. mlir::LLVM::Linkage convertLinkage(llvm::Optional optLinkage) const { - if (optLinkage.hasValue()) { + if (optLinkage) { auto name = optLinkage.getValue(); if (name == "internal") return mlir::LLVM::Linkage::Internal; @@ -2746,7 +2746,7 @@ llvm::Optional destOps, mlir::ConversionPatternRewriter &rewriter, mlir::Block *newBlock) { - if (destOps.hasValue()) + if (destOps) rewriter.create(loc, cmp, dest, destOps.getValue(), newBlock, mlir::ValueRange()); else @@ -2756,7 +2756,7 @@ template static void genBrOp(A caseOp, mlir::Block *dest, llvm::Optional destOps, mlir::ConversionPatternRewriter &rewriter) { - if (destOps.hasValue()) + if (destOps) rewriter.replaceOpWithNewOp(caseOp, destOps.getValue(), dest); else @@ -2881,15 +2881,14 @@ const mlir::Attribute &attr = cases[t]; if (auto intAttr = attr.template dyn_cast()) { destinations.push_back(dest); - destinationsOperands.push_back(destOps.hasValue() ? *destOps - : mlir::ValueRange{}); + destinationsOperands.push_back(destOps ? *destOps : mlir::ValueRange{}); caseValues.push_back(intAttr.getInt()); continue; } assert(attr.template dyn_cast_or_null()); assert((t + 1 == conds) && "unit must be last"); defaultDestination = dest; - defaultOperands = destOps.hasValue() ? *destOps : mlir::ValueRange{}; + defaultOperands = destOps ? *destOps : mlir::ValueRange{}; } // LLVM::SwitchOp takes a i32 type for the selector. diff --git a/flang/lib/Optimizer/CodeGen/TargetRewrite.cpp b/flang/lib/Optimizer/CodeGen/TargetRewrite.cpp --- a/flang/lib/Optimizer/CodeGen/TargetRewrite.cpp +++ b/flang/lib/Optimizer/CodeGen/TargetRewrite.cpp @@ -316,7 +316,7 @@ newOpers.insert(newOpers.end(), trailingOpers.begin(), trailingOpers.end()); if constexpr (std::is_same_v, fir::CallOp>) { fir::CallOp newCall; - if (callOp.getCallee().hasValue()) { + if (callOp.getCallee()) { newCall = rewriter->create(loc, callOp.getCallee().getValue(), newResTys, newOpers); } else { diff --git a/flang/lib/Optimizer/Dialect/FIROps.cpp b/flang/lib/Optimizer/Dialect/FIROps.cpp --- a/flang/lib/Optimizer/Dialect/FIROps.cpp +++ b/flang/lib/Optimizer/Dialect/FIROps.cpp @@ -1294,7 +1294,7 @@ } void fir::GlobalOp::print(mlir::OpAsmPrinter &p) { - if (getLinkName().hasValue()) + if (getLinkName()) p << ' ' << getLinkName().getValue(); p << ' '; p.printAttributeWithoutType(getSymrefAttr()); diff --git a/flang/lib/Optimizer/Support/InternalNames.cpp b/flang/lib/Optimizer/Support/InternalNames.cpp --- a/flang/lib/Optimizer/Support/InternalNames.cpp +++ b/flang/lib/Optimizer/Support/InternalNames.cpp @@ -51,7 +51,7 @@ inline llvm::Optional convertToStringRef(const llvm::Optional &from) { llvm::Optional to; - if (from.hasValue()) + if (from) to = from.getValue(); return to; } diff --git a/flang/lib/Optimizer/Transforms/AffinePromotion.cpp b/flang/lib/Optimizer/Transforms/AffinePromotion.cpp --- a/flang/lib/Optimizer/Transforms/AffinePromotion.cpp +++ b/flang/lib/Optimizer/Transforms/AffinePromotion.cpp @@ -188,7 +188,7 @@ MaybeAffineExpr affineBinaryOp(mlir::AffineExprKind kind, MaybeAffineExpr lhs, MaybeAffineExpr rhs) { - if (lhs.hasValue() && rhs.hasValue()) + if (lhs && rhs) return mlir::getAffineBinaryOpExpr(kind, lhs.getValue(), rhs.getValue()); return {}; } @@ -233,7 +233,7 @@ void fromCmpIOp(mlir::arith::CmpIOp cmpOp) { auto lhsAffine = toAffineExpr(cmpOp.getLhs()); auto rhsAffine = toAffineExpr(cmpOp.getRhs()); - if (!lhsAffine.hasValue() || !rhsAffine.hasValue()) + if (!lhsAffine || !rhsAffine) return; auto constraintPair = constraint( cmpOp.getPredicate(), rhsAffine.getValue() - lhsAffine.getValue()); diff --git a/flang/lib/Optimizer/Transforms/ExternalNameConversion.cpp b/flang/lib/Optimizer/Transforms/ExternalNameConversion.cpp --- a/flang/lib/Optimizer/Transforms/ExternalNameConversion.cpp +++ b/flang/lib/Optimizer/Transforms/ExternalNameConversion.cpp @@ -49,7 +49,7 @@ mlir::PatternRewriter &rewriter) const override { rewriter.startRootUpdate(op); auto callee = op.getCallee(); - if (callee.hasValue()) { + if (callee) { auto result = fir::NameUniquer::deconstruct( callee.getValue().getRootReference().getValue()); if (fir::NameUniquer::isExternalFacingUniquedName(result)) @@ -137,7 +137,7 @@ acc::OpenACCDialect, omp::OpenMPDialect>(); target.addDynamicallyLegalOp([](fir::CallOp op) { - if (op.getCallee().hasValue()) + if (op.getCallee()) return !fir::NameUniquer::needExternalNameMangling( op.getCallee().getValue().getRootReference().getValue()); return true;