Don't use Optional::hasValue (NFC)
authorKazu Hirata <kazu@google.com>
Tue, 21 Jun 2022 03:26:05 +0000 (20:26 -0700)
committerKazu Hirata <kazu@google.com>
Tue, 21 Jun 2022 03:26:05 +0000 (20:26 -0700)
18 files changed:
clang/include/clang/APINotes/Types.h
clang/include/clang/Basic/DarwinSDKInfo.h
clang/lib/Lex/MacroInfo.cpp
lldb/tools/lldb-vscode/FifoFiles.cpp
llvm/include/llvm/DebugInfo/GSYM/FunctionInfo.h
llvm/include/llvm/ProfileData/MemProf.h
llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h
llvm/lib/ObjectYAML/ELFYAML.cpp
llvm/lib/Target/SystemZ/SystemZISelLowering.h
llvm/lib/Transforms/Scalar/LoopSimplifyCFG.cpp
llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
llvm/tools/llvm-cov/CodeCoverage.cpp
mlir/include/mlir/TableGen/CodeGenHelpers.h
mlir/lib/Analysis/Presburger/IntegerRelation.cpp
mlir/lib/Conversion/SPIRVToLLVM/SPIRVToLLVM.cpp
mlir/lib/Dialect/Affine/Analysis/Utils.cpp
mlir/lib/Dialect/Affine/Transforms/LoopFusion.cpp
mlir/lib/Dialect/Affine/Utils/LoopUtils.cpp

index cd02db3..ed5250f 100644 (file)
@@ -440,8 +440,7 @@ public:
   }
   void
   setRetainCountConvention(llvm::Optional<RetainCountConventionKind> Value) {
-    RawRetainCountConvention =
-        Value.hasValue() ? static_cast<unsigned>(Value.getValue()) + 1 : 0;
+    RawRetainCountConvention = Value ? static_cast<unsigned>(*Value) + 1 : 0;
     assert(getRetainCountConvention() == Value && "bitfield too small");
   }
 
@@ -559,8 +558,7 @@ public:
   }
   void
   setRetainCountConvention(llvm::Optional<RetainCountConventionKind> Value) {
-    RawRetainCountConvention =
-        Value.hasValue() ? static_cast<unsigned>(Value.getValue()) + 1 : 0;
+    RawRetainCountConvention = Value ? static_cast<unsigned>(*Value) + 1 : 0;
     assert(getRetainCountConvention() == Value && "bitfield too small");
   }
 
index df16827..728bbc1 100644 (file)
@@ -142,8 +142,7 @@ public:
     auto Mapping = VersionMappings.find(Kind.Value);
     if (Mapping == VersionMappings.end())
       return nullptr;
-    return Mapping->getSecond().hasValue() ? Mapping->getSecond().getPointer()
-                                           : nullptr;
+    return Mapping->getSecond() ? Mapping->getSecond().getPointer() : nullptr;
   }
 
   static Optional<DarwinSDKInfo>
index f570213..4a8127d 100644 (file)
@@ -201,8 +201,7 @@ MacroDirective::DefInfo MacroDirective::getDefinition() {
   Optional<bool> isPublic;
   for (; MD; MD = MD->getPrevious()) {
     if (DefMacroDirective *DefMD = dyn_cast<DefMacroDirective>(MD))
-      return DefInfo(DefMD, UndefLoc,
-                     !isPublic.hasValue() || isPublic.getValue());
+      return DefInfo(DefMD, UndefLoc, !isPublic || *isPublic);
 
     if (UndefMacroDirective *UndefMD = dyn_cast<UndefMacroDirective>(MD)) {
       UndefLoc = UndefMD->getLocation();
index e37f202..b97455b 100644 (file)
@@ -61,8 +61,7 @@ Expected<json::Value> FifoFileIO::ReadJSON(std::chrono::milliseconds timeout) {
         if (!buffer.empty())
           line = buffer;
       }));
-  if (future->wait_for(timeout) == std::future_status::timeout ||
-      !line.hasValue())
+  if (future->wait_for(timeout) == std::future_status::timeout || !line)
     return createStringError(inconvertibleErrorCode(),
                              "Timed out trying to get messages from the " +
                                  m_other_endpoint_name);
index ed41d2b..a41b2fe 100644 (file)
@@ -102,9 +102,7 @@ struct FunctionInfo {
   /// debug info, we might end up with multiple FunctionInfo objects for the
   /// same range and we need to be able to tell which one is the better object
   /// to use.
-  bool hasRichInfo() const {
-    return OptLineTable.hasValue() || Inline.hasValue();
-  }
+  bool hasRichInfo() const { return OptLineTable || Inline; }
 
   /// Query if a FunctionInfo object is valid.
   ///
index 0406d4f..bcee3b2 100644 (file)
@@ -221,8 +221,7 @@ struct Frame {
   void printYAML(raw_ostream &OS) const {
     OS << "      -\n"
        << "        Function: " << Function << "\n"
-       << "        SymbolName: "
-       << (SymbolName.hasValue() ? SymbolName.getValue() : "<None>") << "\n"
+       << "        SymbolName: " << SymbolName.value_or("<None>") << "\n"
        << "        LineOffset: " << LineOffset << "\n"
        << "        Column: " << Column << "\n"
        << "        Inline: " << IsInlineFrame << "\n";
index 9e3489e..a26eb98 100644 (file)
@@ -689,9 +689,7 @@ struct RegsForValue {
                const DataLayout &DL, unsigned Reg, Type *Ty,
                Optional<CallingConv::ID> CC);
 
-  bool isABIMangled() const {
-    return CallConv.hasValue();
-  }
+  bool isABIMangled() const { return CallConv.has_value(); }
 
   /// Add the specified values to this one.
   void append(const RegsForValue &RHS) {
index f64ee2a..bcae5a2 100644 (file)
@@ -1364,8 +1364,7 @@ static void sectionMapping(IO &IO, ELFYAML::HashSection &Section) {
 
   // obj2yaml does not dump these fields. They can be used to override nchain
   // and nbucket values for creating broken sections.
-  assert(!IO.outputting() ||
-         (!Section.NBucket.hasValue() && !Section.NChain.hasValue()));
+  assert(!IO.outputting() || (!Section.NBucket && !Section.NChain));
   IO.mapOptional("NChain", Section.NChain);
   IO.mapOptional("NBucket", Section.NBucket);
 }
index 16a0a95..b9c9527 100644 (file)
@@ -419,8 +419,7 @@ public:
   getNumRegisters(LLVMContext &Context, EVT VT,
                   Optional<MVT> RegisterVT) const override {
     // i128 inline assembly operand.
-    if (VT == MVT::i128 &&
-        RegisterVT.hasValue() && RegisterVT.getValue() == MVT::Untyped)
+    if (VT == MVT::i128 && RegisterVT && *RegisterVT == MVT::Untyped)
       return 1;
     return TargetLowering::getNumRegisters(Context, VT);
   }
index 81368bc..c2c29d9 100644 (file)
@@ -701,8 +701,7 @@ PreservedAnalyses LoopSimplifyCFGPass::run(Loop &L, LoopAnalysisManager &AM,
     MSSAU = MemorySSAUpdater(AR.MSSA);
   bool DeleteCurrentLoop = false;
   if (!simplifyLoopCFG(L, AR.DT, AR.LI, AR.SE,
-                       MSSAU.hasValue() ? MSSAU.getPointer() : nullptr,
-                       DeleteCurrentLoop))
+                       MSSAU ? MSSAU.getPointer() : nullptr, DeleteCurrentLoop))
     return PreservedAnalyses::all();
 
   if (DeleteCurrentLoop)
index 273ebe0..e37d7c0 100644 (file)
@@ -3151,8 +3151,7 @@ PreservedAnalyses SimpleLoopUnswitchPass::run(Loop &L, LoopAnalysisManager &AM,
       AR.MSSA->verifyMemorySSA();
   }
   if (!unswitchLoop(L, AR.DT, AR.LI, AR.AC, AR.AA, AR.TTI, Trivial, NonTrivial,
-                    UnswitchCB, &AR.SE,
-                    MSSAU.hasValue() ? MSSAU.getPointer() : nullptr,
+                    UnswitchCB, &AR.SE, MSSAU ? MSSAU.getPointer() : nullptr,
                     DestroyLoopCB))
     return PreservedAnalyses::all();
 
index b333f7f..6932e9b 100644 (file)
@@ -265,8 +265,7 @@ bool CodeCoverageTool::isEquivalentFile(StringRef FilePath1,
                                         StringRef FilePath2) {
   auto Status1 = getFileStatus(FilePath1);
   auto Status2 = getFileStatus(FilePath2);
-  return Status1.hasValue() && Status2.hasValue() &&
-         sys::fs::equivalent(Status1.getValue(), Status2.getValue());
+  return Status1 && Status2 && sys::fs::equivalent(*Status1, *Status2);
 }
 
 ErrorOr<const MemoryBuffer &>
index 69b3a89..3f55e3b 100644 (file)
@@ -229,8 +229,7 @@ template <> struct stringifier<Twine> {
 template <typename OptionalT>
 struct stringifier<Optional<OptionalT>> {
   static std::string apply(Optional<OptionalT> optional) {
-    return optional.hasValue() ? stringifier<OptionalT>::apply(*optional)
-                               : std::string();
+    return optional ? stringifier<OptionalT>::apply(*optional) : std::string();
   }
 };
 } // namespace detail
index 6411a04..fc2fbd5 100644 (file)
@@ -626,9 +626,7 @@ Matrix IntegerRelation::getBoundedDirections() const {
   return dirs;
 }
 
-bool IntegerRelation::isIntegerEmpty() const {
-  return !findIntegerSample().hasValue();
-}
+bool IntegerRelation::isIntegerEmpty() const { return !findIntegerSample(); }
 
 /// Let this set be S. If S is bounded then we directly call into the GBR
 /// sampling algorithm. Otherwise, there are some unbounded directions, i.e.,
index 65d3862..1a830b9 100644 (file)
@@ -251,8 +251,7 @@ static Optional<Type> convertArrayType(spirv::ArrayType type,
   unsigned stride = type.getArrayStride();
   Type elementType = type.getElementType();
   auto sizeInBytes = elementType.cast<spirv::SPIRVType>().getSizeInBytes();
-  if (stride != 0 &&
-      !(sizeInBytes.hasValue() && sizeInBytes.getValue() == stride))
+  if (stride != 0 && !(sizeInBytes && *sizeInBytes == stride))
     return llvm::None;
 
   auto llvmElementType = converter.convertType(elementType);
index a0a9fc7..00331a9 100644 (file)
@@ -1134,8 +1134,7 @@ void mlir::getComputationSliceState(
     //    3. Is being inserted at the innermost insertion point.
     Optional<bool> isMaximal = sliceState->isMaximal();
     if (isLoopParallelAndContainsReduction(getSliceLoop(i)) &&
-        isInnermostInsertion() && srcIsUnitSlice() && isMaximal.hasValue() &&
-        isMaximal.getValue())
+        isInnermostInsertion() && srcIsUnitSlice() && isMaximal && *isMaximal)
       continue;
     for (unsigned j = i; j < numSliceLoopIVs; ++j) {
       sliceState->lbs[j] = AffineMap();
index bcd9b5d..9d22053 100644 (file)
@@ -1297,9 +1297,7 @@ static bool isFusionProfitable(Operation *srcOpInst, Operation *srcStoreOpInst,
     msg << " fusion is most profitable at depth " << *dstLoopDepth << " with "
         << std::setprecision(2) << additionalComputeFraction
         << "% redundant computation and a ";
-    msg << (storageReduction.hasValue()
-                ? std::to_string(storageReduction.getValue())
-                : "<unknown>");
+    msg << (storageReduction ? std::to_string(*storageReduction) : "<unknown>");
     msg << "% storage reduction.\n";
     llvm::dbgs() << msg.str();
   });
index 7452647..ea10dbb 100644 (file)
@@ -1108,8 +1108,7 @@ LogicalResult mlir::loopUnrollByFactor(
 
   // If the trip count is lower than the unroll factor, no unrolled body.
   // TODO: option to specify cleanup loop unrolling.
-  if (mayBeConstantTripCount.hasValue() &&
-      mayBeConstantTripCount.getValue() < unrollFactor)
+  if (mayBeConstantTripCount && *mayBeConstantTripCount < unrollFactor)
     return failure();
 
   // Generate the cleanup loop if trip count isn't a multiple of unrollFactor.
@@ -1216,8 +1215,7 @@ LogicalResult mlir::loopUnrollJamByFactor(AffineForOp forOp,
     return success();
 
   // If the trip count is lower than the unroll jam factor, no unroll jam.
-  if (mayBeConstantTripCount.hasValue() &&
-      mayBeConstantTripCount.getValue() < unrollJamFactor) {
+  if (mayBeConstantTripCount && *mayBeConstantTripCount < unrollJamFactor) {
     LLVM_DEBUG(llvm::dbgs() << "[failed] trip count < unroll-jam factor\n");
     return failure();
   }