forked from OSchip/llvm-project
[flang] Don't use Optional::hasValue (NFC)
Flang C++ Style Guide tells us to avoid .has_value() in the predicate expressions of control flow statements. I am treating ternary expressions as control flow statements for the purpose of this patch. Differential Revision: https://reviews.llvm.org/D128622
This commit is contained in:
parent
1fd6611fc8
commit
86b8c1d9c4
|
@ -465,7 +465,7 @@ public:
|
|||
|
||||
llvm::Optional<fir::ArrayLoadOp> getLhsLoad(size_t i) {
|
||||
assert(i < lhsBases.size());
|
||||
if (lhsBases[counter].hasValue())
|
||||
if (lhsBases[counter])
|
||||
return findBinding(lhsBases[counter].getValue());
|
||||
return llvm::None;
|
||||
}
|
||||
|
|
|
@ -4266,7 +4266,7 @@ private:
|
|||
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 @@ private:
|
|||
}
|
||||
|
||||
// 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 @@ private:
|
|||
fir::ArrayLoadOp
|
||||
createAndLoadSomeArrayTemp(mlir::Type type,
|
||||
llvm::ArrayRef<mlir::Value> shape) {
|
||||
if (ccLoadDest.hasValue())
|
||||
if (ccLoadDest)
|
||||
return ccLoadDest.getValue()(shape);
|
||||
auto seqTy = type.dyn_cast<fir::SequenceType>();
|
||||
assert(seqTy && "must be an array");
|
||||
|
@ -5934,7 +5934,7 @@ private:
|
|||
// 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 @@ private:
|
|||
|
||||
// Return the continuation.
|
||||
if (fir::isa_char(seqTy.getEleTy())) {
|
||||
if (charLen.hasValue()) {
|
||||
if (charLen) {
|
||||
auto len = builder.create<fir::LoadOp>(loc, charLen.getValue());
|
||||
return genarr(fir::CharArrayBoxValue{mem, len, extents});
|
||||
}
|
||||
|
@ -7625,7 +7625,7 @@ void Fortran::lower::createArrayLoads(
|
|||
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 @@ void Fortran::lower::createArrayMergeStores(
|
|||
load.getMemref(), load.getSlice(),
|
||||
load.getTypeparams());
|
||||
}
|
||||
if (esp.loopCleanup.hasValue()) {
|
||||
if (esp.loopCleanup) {
|
||||
esp.loopCleanup.getValue()(builder);
|
||||
esp.loopCleanup = llvm::None;
|
||||
}
|
||||
|
|
|
@ -862,7 +862,7 @@ void Fortran::lower::ExplicitIterSpace::conditionalCleanup() {
|
|||
|
||||
llvm::Optional<size_t>
|
||||
Fortran::lower::ExplicitIterSpace::findArgPosition(fir::ArrayLoadOp load) {
|
||||
if (lhsBases[counter].hasValue()) {
|
||||
if (lhsBases[counter]) {
|
||||
auto ld = loadBindings.find(lhsBases[counter].getValue());
|
||||
llvm::Optional<size_t> optPos;
|
||||
if (ld != loadBindings.end() && ld->second == load)
|
||||
|
@ -919,7 +919,7 @@ Fortran::lower::operator<<(llvm::raw_ostream &s,
|
|||
s << "LHS bases:\n";
|
||||
for (const llvm::Optional<Fortran::lower::ExplicitIterSpace::ArrayBases> &u :
|
||||
e.lhsBases)
|
||||
if (u.hasValue())
|
||||
if (u)
|
||||
dump(u.getValue());
|
||||
s << "RHS bases:\n";
|
||||
for (const llvm::SmallVector<Fortran::lower::ExplicitIterSpace::ArrayBases>
|
||||
|
|
|
@ -252,10 +252,10 @@ public:
|
|||
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<AllocaOp>(
|
||||
mem, toTy, uniqName, bindcName, isPinned, mem.getTypeparams(),
|
||||
|
@ -267,10 +267,10 @@ public:
|
|||
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<AllocMemOp>(
|
||||
mem, toTy, uniqName, bindcName, mem.getTypeparams(),
|
||||
|
|
|
@ -2689,7 +2689,7 @@ struct GlobalOpConversion : public FIROpConversion<fir::GlobalOp> {
|
|||
// enumeration.
|
||||
mlir::LLVM::Linkage
|
||||
convertLinkage(llvm::Optional<llvm::StringRef> optLinkage) const {
|
||||
if (optLinkage.hasValue()) {
|
||||
if (optLinkage) {
|
||||
auto name = optLinkage.getValue();
|
||||
if (name == "internal")
|
||||
return mlir::LLVM::Linkage::Internal;
|
||||
|
@ -2746,7 +2746,7 @@ static void genCondBrOp(mlir::Location loc, mlir::Value cmp, mlir::Block *dest,
|
|||
llvm::Optional<mlir::ValueRange> destOps,
|
||||
mlir::ConversionPatternRewriter &rewriter,
|
||||
mlir::Block *newBlock) {
|
||||
if (destOps.hasValue())
|
||||
if (destOps)
|
||||
rewriter.create<mlir::LLVM::CondBrOp>(loc, cmp, dest, destOps.getValue(),
|
||||
newBlock, mlir::ValueRange());
|
||||
else
|
||||
|
@ -2756,7 +2756,7 @@ static void genCondBrOp(mlir::Location loc, mlir::Value cmp, mlir::Block *dest,
|
|||
template <typename A, typename B>
|
||||
static void genBrOp(A caseOp, mlir::Block *dest, llvm::Optional<B> destOps,
|
||||
mlir::ConversionPatternRewriter &rewriter) {
|
||||
if (destOps.hasValue())
|
||||
if (destOps)
|
||||
rewriter.replaceOpWithNewOp<mlir::LLVM::BrOp>(caseOp, destOps.getValue(),
|
||||
dest);
|
||||
else
|
||||
|
@ -2881,15 +2881,14 @@ static void selectMatchAndRewrite(fir::LLVMTypeConverter &lowering, OP select,
|
|||
const mlir::Attribute &attr = cases[t];
|
||||
if (auto intAttr = attr.template dyn_cast<mlir::IntegerAttr>()) {
|
||||
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<mlir::UnitAttr>());
|
||||
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.
|
||||
|
|
|
@ -316,7 +316,7 @@ public:
|
|||
newOpers.insert(newOpers.end(), trailingOpers.begin(), trailingOpers.end());
|
||||
if constexpr (std::is_same_v<std::decay_t<A>, fir::CallOp>) {
|
||||
fir::CallOp newCall;
|
||||
if (callOp.getCallee().hasValue()) {
|
||||
if (callOp.getCallee()) {
|
||||
newCall = rewriter->create<A>(loc, callOp.getCallee().getValue(),
|
||||
newResTys, newOpers);
|
||||
} else {
|
||||
|
|
|
@ -1294,7 +1294,7 @@ mlir::ParseResult fir::GlobalOp::parse(mlir::OpAsmParser &parser,
|
|||
}
|
||||
|
||||
void fir::GlobalOp::print(mlir::OpAsmPrinter &p) {
|
||||
if (getLinkName().hasValue())
|
||||
if (getLinkName())
|
||||
p << ' ' << getLinkName().getValue();
|
||||
p << ' ';
|
||||
p.printAttributeWithoutType(getSymrefAttr());
|
||||
|
|
|
@ -51,7 +51,7 @@ convertToStringRef(llvm::ArrayRef<std::string> from) {
|
|||
inline llvm::Optional<llvm::StringRef>
|
||||
convertToStringRef(const llvm::Optional<std::string> &from) {
|
||||
llvm::Optional<llvm::StringRef> to;
|
||||
if (from.hasValue())
|
||||
if (from)
|
||||
to = from.getValue();
|
||||
return to;
|
||||
}
|
||||
|
|
|
@ -188,7 +188,7 @@ private:
|
|||
|
||||
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 @@ private:
|
|||
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());
|
||||
|
|
|
@ -49,7 +49,7 @@ public:
|
|||
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 @@ void ExternalNameConversionPass::runOnOperation() {
|
|||
acc::OpenACCDialect, omp::OpenMPDialect>();
|
||||
|
||||
target.addDynamicallyLegalOp<fir::CallOp>([](fir::CallOp op) {
|
||||
if (op.getCallee().hasValue())
|
||||
if (op.getCallee())
|
||||
return !fir::NameUniquer::needExternalNameMangling(
|
||||
op.getCallee().getValue().getRootReference().getValue());
|
||||
return true;
|
||||
|
|
Loading…
Reference in New Issue