[flang] Use has_value instead of hasValue (NFC)

This patch replaces hasValue with has_value in an effort to deprecate
Optional<X>::hasValue.

Differential Revision: https://reviews.llvm.org/D129458
This commit is contained in:
Kazu Hirata 2022-07-11 20:41:12 -07:00
parent ec9a0e36d9
commit c82fb16f58
9 changed files with 23 additions and 21 deletions

View File

@ -446,7 +446,9 @@ public:
/// `load` must be a LHS array_load. Returns `llvm::None` on error.
llvm::Optional<size_t> findArgPosition(fir::ArrayLoadOp load);
bool isLHS(fir::ArrayLoadOp load) { return findArgPosition(load).hasValue(); }
bool isLHS(fir::ArrayLoadOp load) {
return findArgPosition(load).has_value();
}
/// `load` must be a LHS array_load. Determine the threaded inner argument
/// corresponding to this load.
@ -472,7 +474,7 @@ public:
/// Return the outermost loop in this FORALL nest.
fir::DoLoopOp getOuterLoop() {
assert(outerLoop.hasValue());
assert(outerLoop.has_value());
return outerLoop.getValue();
}

View File

@ -82,7 +82,7 @@ public:
bool workListIsEmpty() const {
return cufs.empty() || llvm::all_of(cufs, [](auto &opt) -> bool {
return !opt.hasValue();
return !opt.has_value();
});
}

View File

@ -7291,14 +7291,14 @@ private:
void setUnordered(bool b) { unordered = b; }
inline bool isPointerAssignment() const { return lbounds.hasValue(); }
inline bool isPointerAssignment() const { return lbounds.has_value(); }
inline bool isBoundsSpec() const {
return isPointerAssignment() && !ubounds.hasValue();
return isPointerAssignment() && !ubounds.has_value();
}
inline bool isBoundsRemap() const {
return isPointerAssignment() && ubounds.hasValue();
return isPointerAssignment() && ubounds.has_value();
}
void setPointerAssignmentBounds(

View File

@ -867,7 +867,7 @@ Fortran::lower::ExplicitIterSpace::findArgPosition(fir::ArrayLoadOp load) {
llvm::Optional<size_t> optPos;
if (ld != loadBindings.end() && ld->second == load)
optPos = static_cast<size_t>(0u);
assert(optPos.hasValue() && "load does not correspond to lhs");
assert(optPos.has_value() && "load does not correspond to lhs");
return optPos;
}
return llvm::None;

View File

@ -2635,7 +2635,7 @@ struct GlobalOpConversion : public FIROpConversion<fir::GlobalOp> {
if (global.getInitVal())
initAttr = global.getInitVal().getValue();
auto linkage = convertLinkage(global.getLinkName());
auto isConst = global.getConstant().hasValue();
auto isConst = global.getConstant().has_value();
auto g = rewriter.create<mlir::LLVM::GlobalOp>(
loc, tyAttr, isConst, linkage, global.getSymName(), initAttr);
auto &gr = g.getInitializerRegion();

View File

@ -647,7 +647,7 @@ mlir::FunctionType fir::CallOp::getFunctionType() {
}
void fir::CallOp::print(mlir::OpAsmPrinter &p) {
bool isDirect = getCallee().hasValue();
bool isDirect = getCallee().has_value();
p << ' ';
if (isDirect)
p << getCallee().getValue();
@ -749,7 +749,7 @@ static void printCmpOp(mlir::OpAsmPrinter &p, OPTY op) {
op->template getAttrOfType<mlir::IntegerAttr>(
OPTY::getPredicateAttrName())
.getInt());
assert(predSym.hasValue() && "invalid symbol value for predicate");
assert(predSym.has_value() && "invalid symbol value for predicate");
p << '"' << mlir::arith::stringifyCmpFPredicate(predSym.getValue()) << '"'
<< ", ";
p.printOperand(op.getLhs());
@ -808,7 +808,7 @@ void fir::buildCmpCOp(mlir::OpBuilder &builder, mlir::OperationState &result,
mlir::arith::CmpFPredicate
fir::CmpcOp::getPredicateByName(llvm::StringRef name) {
auto pred = mlir::arith::symbolizeCmpFPredicate(name);
assert(pred.hasValue() && "invalid predicate name");
assert(pred.has_value() && "invalid predicate name");
return pred.getValue();
}

View File

@ -171,7 +171,7 @@ struct AffineIfCondition {
fromCmpIOp(condDef);
}
bool hasIntegerSet() const { return integerSet.hasValue(); }
bool hasIntegerSet() const { return integerSet.has_value(); }
mlir::IntegerSet getIntegerSet() const {
assert(hasIntegerSet() && "integer set is missing");

View File

@ -189,12 +189,12 @@ TEST_F(FIRBuilderTest, createGlobal1) {
loc, i64Type, "global1", builder.createInternalLinkage(), {}, true);
EXPECT_TRUE(mlir::isa<fir::GlobalOp>(global));
EXPECT_EQ("global1", global.getSymName());
EXPECT_TRUE(global.getConstant().hasValue());
EXPECT_TRUE(global.getConstant().has_value());
EXPECT_EQ(i64Type, global.getType());
EXPECT_TRUE(global.getLinkName().hasValue());
EXPECT_TRUE(global.getLinkName().has_value());
EXPECT_EQ(builder.createInternalLinkage().getValue(),
global.getLinkName().getValue());
EXPECT_FALSE(global.getInitVal().hasValue());
EXPECT_FALSE(global.getInitVal().has_value());
auto g1 = builder.getNamedGlobal("global1");
EXPECT_EQ(global, g1);
@ -213,13 +213,13 @@ TEST_F(FIRBuilderTest, createGlobal2) {
loc, i32Type, "global2", builder.createLinkOnceLinkage(), attr, false);
EXPECT_TRUE(mlir::isa<fir::GlobalOp>(global));
EXPECT_EQ("global2", global.getSymName());
EXPECT_FALSE(global.getConstant().hasValue());
EXPECT_FALSE(global.getConstant().has_value());
EXPECT_EQ(i32Type, global.getType());
EXPECT_TRUE(global.getInitVal().hasValue());
EXPECT_TRUE(global.getInitVal().has_value());
EXPECT_TRUE(global.getInitVal().getValue().isa<mlir::IntegerAttr>());
EXPECT_EQ(
16, global.getInitVal().getValue().cast<mlir::IntegerAttr>().getValue());
EXPECT_TRUE(global.getLinkName().hasValue());
EXPECT_TRUE(global.getLinkName().has_value());
EXPECT_EQ(builder.createLinkOnceLinkage().getValue(),
global.getLinkName().getValue());
}
@ -333,9 +333,9 @@ TEST_F(FIRBuilderTest, allocateLocal) {
EXPECT_TRUE(mlir::isa<fir::AllocaOp>(var.getDefiningOp()));
auto allocaOp = dyn_cast<fir::AllocaOp>(var.getDefiningOp());
EXPECT_EQ(builder.getI64Type(), allocaOp.getInType());
EXPECT_TRUE(allocaOp.getBindcName().hasValue());
EXPECT_TRUE(allocaOp.getBindcName().has_value());
EXPECT_EQ(varName, allocaOp.getBindcName().getValue());
EXPECT_FALSE(allocaOp.getUniqName().hasValue());
EXPECT_FALSE(allocaOp.getUniqName().has_value());
EXPECT_FALSE(allocaOp.getPinned());
EXPECT_EQ(0u, allocaOp.getTypeparams().size());
EXPECT_EQ(0u, allocaOp.getShape().size());

View File

@ -87,7 +87,7 @@ static inline void checkCallOp(mlir::Operation *op, llvm::StringRef fctName,
unsigned nbArgs, bool addLocArgs = true) {
EXPECT_TRUE(mlir::isa<fir::CallOp>(*op));
auto callOp = mlir::dyn_cast<fir::CallOp>(*op);
EXPECT_TRUE(callOp.getCallee().hasValue());
EXPECT_TRUE(callOp.getCallee().has_value());
mlir::SymbolRefAttr callee = *callOp.getCallee();
EXPECT_EQ(fctName, callee.getRootReference().getValue());
// sourceFile and sourceLine are added arguments.