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