[flang-commits] [flang] c82fb16 - [flang] Use has_value instead of hasValue (NFC)

Kazu Hirata via flang-commits flang-commits at lists.llvm.org
Mon Jul 11 20:41:21 PDT 2022


Author: Kazu Hirata
Date: 2022-07-11T20:41:12-07:00
New Revision: c82fb16f580c80b961cb1971df66ce70eaf7d87a

URL: https://github.com/llvm/llvm-project/commit/c82fb16f580c80b961cb1971df66ce70eaf7d87a
DIFF: https://github.com/llvm/llvm-project/commit/c82fb16f580c80b961cb1971df66ce70eaf7d87a.diff

LOG: [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

Added: 
    

Modified: 
    flang/include/flang/Lower/IterationSpace.h
    flang/include/flang/Lower/StatementContext.h
    flang/lib/Lower/ConvertExpr.cpp
    flang/lib/Lower/IterationSpace.cpp
    flang/lib/Optimizer/CodeGen/CodeGen.cpp
    flang/lib/Optimizer/Dialect/FIROps.cpp
    flang/lib/Optimizer/Transforms/AffinePromotion.cpp
    flang/unittests/Optimizer/Builder/FIRBuilderTest.cpp
    flang/unittests/Optimizer/Builder/Runtime/RuntimeCallTestBase.h

Removed: 
    


################################################################################
diff  --git a/flang/include/flang/Lower/IterationSpace.h b/flang/include/flang/Lower/IterationSpace.h
index 9ad3bd15274fc..25c3f30aa166a 100644
--- a/flang/include/flang/Lower/IterationSpace.h
+++ b/flang/include/flang/Lower/IterationSpace.h
@@ -446,7 +446,9 @@ class ExplicitIterSpace {
   /// `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 @@ class ExplicitIterSpace {
 
   /// Return the outermost loop in this FORALL nest.
   fir::DoLoopOp getOuterLoop() {
-    assert(outerLoop.hasValue());
+    assert(outerLoop.has_value());
     return outerLoop.getValue();
   }
 

diff  --git a/flang/include/flang/Lower/StatementContext.h b/flang/include/flang/Lower/StatementContext.h
index 69ceeaebfbbc8..1ab1bd0faee38 100644
--- a/flang/include/flang/Lower/StatementContext.h
+++ b/flang/include/flang/Lower/StatementContext.h
@@ -82,7 +82,7 @@ class StatementContext {
 
   bool workListIsEmpty() const {
     return cufs.empty() || llvm::all_of(cufs, [](auto &opt) -> bool {
-             return !opt.hasValue();
+             return !opt.has_value();
            });
   }
 

diff  --git a/flang/lib/Lower/ConvertExpr.cpp b/flang/lib/Lower/ConvertExpr.cpp
index 0351df2f91fa2..5fe5314b6ab89 100644
--- a/flang/lib/Lower/ConvertExpr.cpp
+++ b/flang/lib/Lower/ConvertExpr.cpp
@@ -7291,14 +7291,14 @@ class ArrayExprLowering {
 
   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(

diff  --git a/flang/lib/Lower/IterationSpace.cpp b/flang/lib/Lower/IterationSpace.cpp
index f41bc5124753b..e2825632928e8 100644
--- a/flang/lib/Lower/IterationSpace.cpp
+++ b/flang/lib/Lower/IterationSpace.cpp
@@ -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;

diff  --git a/flang/lib/Optimizer/CodeGen/CodeGen.cpp b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
index 632ab28005788..f9f6f939705c5 100644
--- a/flang/lib/Optimizer/CodeGen/CodeGen.cpp
+++ b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
@@ -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();

diff  --git a/flang/lib/Optimizer/Dialect/FIROps.cpp b/flang/lib/Optimizer/Dialect/FIROps.cpp
index 0119bca098ce8..8337b16fca879 100644
--- a/flang/lib/Optimizer/Dialect/FIROps.cpp
+++ b/flang/lib/Optimizer/Dialect/FIROps.cpp
@@ -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();
 }
 

diff  --git a/flang/lib/Optimizer/Transforms/AffinePromotion.cpp b/flang/lib/Optimizer/Transforms/AffinePromotion.cpp
index dad4b476ca86b..e9f017c9384fa 100644
--- a/flang/lib/Optimizer/Transforms/AffinePromotion.cpp
+++ b/flang/lib/Optimizer/Transforms/AffinePromotion.cpp
@@ -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");

diff  --git a/flang/unittests/Optimizer/Builder/FIRBuilderTest.cpp b/flang/unittests/Optimizer/Builder/FIRBuilderTest.cpp
index 3997d8fd50fe6..9fca611617d0f 100644
--- a/flang/unittests/Optimizer/Builder/FIRBuilderTest.cpp
+++ b/flang/unittests/Optimizer/Builder/FIRBuilderTest.cpp
@@ -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());

diff  --git a/flang/unittests/Optimizer/Builder/Runtime/RuntimeCallTestBase.h b/flang/unittests/Optimizer/Builder/Runtime/RuntimeCallTestBase.h
index 8d549c54a0530..4b7c9f18543a8 100644
--- a/flang/unittests/Optimizer/Builder/Runtime/RuntimeCallTestBase.h
+++ b/flang/unittests/Optimizer/Builder/Runtime/RuntimeCallTestBase.h
@@ -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.


        


More information about the flang-commits mailing list