Skip to content

Commit c82fb16

Browse files
[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
1 parent ec9a0e3 commit c82fb16

File tree

9 files changed

+23
-21
lines changed

9 files changed

+23
-21
lines changed

flang/include/flang/Lower/IterationSpace.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,9 @@ class ExplicitIterSpace {
446446
/// `load` must be a LHS array_load. Returns `llvm::None` on error.
447447
llvm::Optional<size_t> findArgPosition(fir::ArrayLoadOp load);
448448

449-
bool isLHS(fir::ArrayLoadOp load) { return findArgPosition(load).hasValue(); }
449+
bool isLHS(fir::ArrayLoadOp load) {
450+
return findArgPosition(load).has_value();
451+
}
450452

451453
/// `load` must be a LHS array_load. Determine the threaded inner argument
452454
/// corresponding to this load.
@@ -472,7 +474,7 @@ class ExplicitIterSpace {
472474

473475
/// Return the outermost loop in this FORALL nest.
474476
fir::DoLoopOp getOuterLoop() {
475-
assert(outerLoop.hasValue());
477+
assert(outerLoop.has_value());
476478
return outerLoop.getValue();
477479
}
478480

flang/include/flang/Lower/StatementContext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class StatementContext {
8282

8383
bool workListIsEmpty() const {
8484
return cufs.empty() || llvm::all_of(cufs, [](auto &opt) -> bool {
85-
return !opt.hasValue();
85+
return !opt.has_value();
8686
});
8787
}
8888

flang/lib/Lower/ConvertExpr.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7291,14 +7291,14 @@ class ArrayExprLowering {
72917291

72927292
void setUnordered(bool b) { unordered = b; }
72937293

7294-
inline bool isPointerAssignment() const { return lbounds.hasValue(); }
7294+
inline bool isPointerAssignment() const { return lbounds.has_value(); }
72957295

72967296
inline bool isBoundsSpec() const {
7297-
return isPointerAssignment() && !ubounds.hasValue();
7297+
return isPointerAssignment() && !ubounds.has_value();
72987298
}
72997299

73007300
inline bool isBoundsRemap() const {
7301-
return isPointerAssignment() && ubounds.hasValue();
7301+
return isPointerAssignment() && ubounds.has_value();
73027302
}
73037303

73047304
void setPointerAssignmentBounds(

flang/lib/Lower/IterationSpace.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ Fortran::lower::ExplicitIterSpace::findArgPosition(fir::ArrayLoadOp load) {
867867
llvm::Optional<size_t> optPos;
868868
if (ld != loadBindings.end() && ld->second == load)
869869
optPos = static_cast<size_t>(0u);
870-
assert(optPos.hasValue() && "load does not correspond to lhs");
870+
assert(optPos.has_value() && "load does not correspond to lhs");
871871
return optPos;
872872
}
873873
return llvm::None;

flang/lib/Optimizer/CodeGen/CodeGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2635,7 +2635,7 @@ struct GlobalOpConversion : public FIROpConversion<fir::GlobalOp> {
26352635
if (global.getInitVal())
26362636
initAttr = global.getInitVal().getValue();
26372637
auto linkage = convertLinkage(global.getLinkName());
2638-
auto isConst = global.getConstant().hasValue();
2638+
auto isConst = global.getConstant().has_value();
26392639
auto g = rewriter.create<mlir::LLVM::GlobalOp>(
26402640
loc, tyAttr, isConst, linkage, global.getSymName(), initAttr);
26412641
auto &gr = g.getInitializerRegion();

flang/lib/Optimizer/Dialect/FIROps.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ mlir::FunctionType fir::CallOp::getFunctionType() {
647647
}
648648

649649
void fir::CallOp::print(mlir::OpAsmPrinter &p) {
650-
bool isDirect = getCallee().hasValue();
650+
bool isDirect = getCallee().has_value();
651651
p << ' ';
652652
if (isDirect)
653653
p << getCallee().getValue();
@@ -749,7 +749,7 @@ static void printCmpOp(mlir::OpAsmPrinter &p, OPTY op) {
749749
op->template getAttrOfType<mlir::IntegerAttr>(
750750
OPTY::getPredicateAttrName())
751751
.getInt());
752-
assert(predSym.hasValue() && "invalid symbol value for predicate");
752+
assert(predSym.has_value() && "invalid symbol value for predicate");
753753
p << '"' << mlir::arith::stringifyCmpFPredicate(predSym.getValue()) << '"'
754754
<< ", ";
755755
p.printOperand(op.getLhs());
@@ -808,7 +808,7 @@ void fir::buildCmpCOp(mlir::OpBuilder &builder, mlir::OperationState &result,
808808
mlir::arith::CmpFPredicate
809809
fir::CmpcOp::getPredicateByName(llvm::StringRef name) {
810810
auto pred = mlir::arith::symbolizeCmpFPredicate(name);
811-
assert(pred.hasValue() && "invalid predicate name");
811+
assert(pred.has_value() && "invalid predicate name");
812812
return pred.getValue();
813813
}
814814

flang/lib/Optimizer/Transforms/AffinePromotion.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ struct AffineIfCondition {
171171
fromCmpIOp(condDef);
172172
}
173173

174-
bool hasIntegerSet() const { return integerSet.hasValue(); }
174+
bool hasIntegerSet() const { return integerSet.has_value(); }
175175

176176
mlir::IntegerSet getIntegerSet() const {
177177
assert(hasIntegerSet() && "integer set is missing");

flang/unittests/Optimizer/Builder/FIRBuilderTest.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,12 @@ TEST_F(FIRBuilderTest, createGlobal1) {
189189
loc, i64Type, "global1", builder.createInternalLinkage(), {}, true);
190190
EXPECT_TRUE(mlir::isa<fir::GlobalOp>(global));
191191
EXPECT_EQ("global1", global.getSymName());
192-
EXPECT_TRUE(global.getConstant().hasValue());
192+
EXPECT_TRUE(global.getConstant().has_value());
193193
EXPECT_EQ(i64Type, global.getType());
194-
EXPECT_TRUE(global.getLinkName().hasValue());
194+
EXPECT_TRUE(global.getLinkName().has_value());
195195
EXPECT_EQ(builder.createInternalLinkage().getValue(),
196196
global.getLinkName().getValue());
197-
EXPECT_FALSE(global.getInitVal().hasValue());
197+
EXPECT_FALSE(global.getInitVal().has_value());
198198

199199
auto g1 = builder.getNamedGlobal("global1");
200200
EXPECT_EQ(global, g1);
@@ -213,13 +213,13 @@ TEST_F(FIRBuilderTest, createGlobal2) {
213213
loc, i32Type, "global2", builder.createLinkOnceLinkage(), attr, false);
214214
EXPECT_TRUE(mlir::isa<fir::GlobalOp>(global));
215215
EXPECT_EQ("global2", global.getSymName());
216-
EXPECT_FALSE(global.getConstant().hasValue());
216+
EXPECT_FALSE(global.getConstant().has_value());
217217
EXPECT_EQ(i32Type, global.getType());
218-
EXPECT_TRUE(global.getInitVal().hasValue());
218+
EXPECT_TRUE(global.getInitVal().has_value());
219219
EXPECT_TRUE(global.getInitVal().getValue().isa<mlir::IntegerAttr>());
220220
EXPECT_EQ(
221221
16, global.getInitVal().getValue().cast<mlir::IntegerAttr>().getValue());
222-
EXPECT_TRUE(global.getLinkName().hasValue());
222+
EXPECT_TRUE(global.getLinkName().has_value());
223223
EXPECT_EQ(builder.createLinkOnceLinkage().getValue(),
224224
global.getLinkName().getValue());
225225
}
@@ -333,9 +333,9 @@ TEST_F(FIRBuilderTest, allocateLocal) {
333333
EXPECT_TRUE(mlir::isa<fir::AllocaOp>(var.getDefiningOp()));
334334
auto allocaOp = dyn_cast<fir::AllocaOp>(var.getDefiningOp());
335335
EXPECT_EQ(builder.getI64Type(), allocaOp.getInType());
336-
EXPECT_TRUE(allocaOp.getBindcName().hasValue());
336+
EXPECT_TRUE(allocaOp.getBindcName().has_value());
337337
EXPECT_EQ(varName, allocaOp.getBindcName().getValue());
338-
EXPECT_FALSE(allocaOp.getUniqName().hasValue());
338+
EXPECT_FALSE(allocaOp.getUniqName().has_value());
339339
EXPECT_FALSE(allocaOp.getPinned());
340340
EXPECT_EQ(0u, allocaOp.getTypeparams().size());
341341
EXPECT_EQ(0u, allocaOp.getShape().size());

flang/unittests/Optimizer/Builder/Runtime/RuntimeCallTestBase.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static inline void checkCallOp(mlir::Operation *op, llvm::StringRef fctName,
8787
unsigned nbArgs, bool addLocArgs = true) {
8888
EXPECT_TRUE(mlir::isa<fir::CallOp>(*op));
8989
auto callOp = mlir::dyn_cast<fir::CallOp>(*op);
90-
EXPECT_TRUE(callOp.getCallee().hasValue());
90+
EXPECT_TRUE(callOp.getCallee().has_value());
9191
mlir::SymbolRefAttr callee = *callOp.getCallee();
9292
EXPECT_EQ(fctName, callee.getRootReference().getValue());
9393
// sourceFile and sourceLine are added arguments.

0 commit comments

Comments
 (0)