[Mlir-commits] [mlir] 3c849d0 - Modernize Optional::{getValueOr, hasValue}

Fangrui Song llvmlistbot at llvm.org
Fri Jul 15 01:20:43 PDT 2022


Author: Fangrui Song
Date: 2022-07-15T01:20:39-07:00
New Revision: 3c849d0aefa1101cf38586449c2105a97797c414

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

LOG: Modernize Optional::{getValueOr,hasValue}

Added: 
    

Modified: 
    clang-tools-extra/clangd/AST.cpp
    clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
    clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
    lldb/source/Plugins/Process/Linux/IntelPTCollector.cpp
    lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
    llvm/include/llvm/Support/Casting.h
    llvm/lib/Target/LoongArch/LoongArchTargetMachine.cpp
    mlir/include/mlir/IR/OpImplementation.h
    mlir/lib/Dialect/Vector/Transforms/VectorTransforms.cpp

Removed: 
    


################################################################################
diff  --git a/clang-tools-extra/clangd/AST.cpp b/clang-tools-extra/clangd/AST.cpp
index 6ceff56115721..4df043d18cfb7 100644
--- a/clang-tools-extra/clangd/AST.cpp
+++ b/clang-tools-extra/clangd/AST.cpp
@@ -942,7 +942,7 @@ resolveForwardingParameters(const FunctionDecl *D, unsigned MaxDepth) {
       TailIt = std::copy(Info.Tail.rbegin(), Info.Tail.rend(), TailIt);
       // Prepare next recursion level
       Pack = Info.Pack;
-      CurrentFunction = Info.PackTarget.getValueOr(nullptr);
+      CurrentFunction = Info.PackTarget.value_or(nullptr);
       Depth++;
       // If we are recursing into a previously encountered function: Abort
       if (CurrentFunction) {

diff  --git a/clang/lib/Analysis/FlowSensitive/DebugSupport.cpp b/clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
index 305d9d346089a..a2895d0197b1d 100644
--- a/clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DebugSupport.cpp
@@ -103,8 +103,7 @@ Constraints
 
     auto StatusString = debugString(Result.getStatus());
     auto Solution = Result.getSolution();
-    auto SolutionString =
-        Solution.hasValue() ? "\n" + debugString(Solution.value()) : "";
+    auto SolutionString = Solution ? "\n" + debugString(Solution.value()) : "";
 
     return formatv(
         Template,

diff  --git a/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp b/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
index 825b11adad405..08fac9fb2e698 100644
--- a/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ExprEngineCXX.cpp
@@ -504,7 +504,7 @@ void ExprEngine::handleConstructor(const Expr *E,
 
     unsigned Idx = 0;
     if (CE->getType()->isArrayType()) {
-      Idx = getIndexOfElementToConstruct(State, CE, LCtx).getValueOr(0u);
+      Idx = getIndexOfElementToConstruct(State, CE, LCtx).value_or(0u);
       State = setIndexOfElementToConstruct(State, CE, LCtx, Idx + 1);
     }
 

diff  --git a/lldb/source/Plugins/Process/Linux/IntelPTCollector.cpp b/lldb/source/Plugins/Process/Linux/IntelPTCollector.cpp
index 2c44683ab1356..f89936445b2ba 100644
--- a/lldb/source/Plugins/Process/Linux/IntelPTCollector.cpp
+++ b/lldb/source/Plugins/Process/Linux/IntelPTCollector.cpp
@@ -124,7 +124,7 @@ Error IntelPTCollector::TraceStart(const TraceIntelPTStartRequest &request) {
 
       // We try to use cgroup filtering whenever possible
       Optional<int> cgroup_fd;
-      if (!request.disable_cgroup_filtering.getValueOr(false))
+      if (!request.disable_cgroup_filtering.value_or(false))
         cgroup_fd = GetCGroupFileDescriptor(m_process.GetID());
 
       if (Expected<IntelPTProcessTraceUP> trace =

diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
index cbc24b1550c7c..8ee709db9cdb5 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -3475,10 +3475,9 @@ VariableSP SymbolFileDWARF::ParseVariableDIE(const SymbolContext &sc,
 
   if (use_type_size_for_value && type_sp->GetType()) {
     DWARFExpression *location = location_list.GetMutableExpressionAtAddress();
-    location->UpdateValue(
-        const_value_form.Unsigned(),
-        type_sp->GetType()->GetByteSize(nullptr).getValueOr(0),
-        die.GetCU()->GetAddressByteSize());
+    location->UpdateValue(const_value_form.Unsigned(),
+                          type_sp->GetType()->GetByteSize(nullptr).value_or(0),
+                          die.GetCU()->GetAddressByteSize());
   }
 
   return std::make_shared<Variable>(

diff  --git a/llvm/include/llvm/Support/Casting.h b/llvm/include/llvm/Support/Casting.h
index 5444d777b7493..b6bbff8ada10b 100644
--- a/llvm/include/llvm/Support/Casting.h
+++ b/llvm/include/llvm/Support/Casting.h
@@ -265,7 +265,7 @@ struct CastIsPossible {
 template <typename To, typename From>
 struct CastIsPossible<To, Optional<From>> {
   static inline bool isPossible(const Optional<From> &f) {
-    assert(f.hasValue() && "CastIsPossible::isPossible called on a nullopt!");
+    assert(f && "CastIsPossible::isPossible called on a nullopt!");
     return isa_impl_wrap<
         To, const From,
         typename simplify_type<const From>::SimpleType>::doit(*f);

diff  --git a/llvm/lib/Target/LoongArch/LoongArchTargetMachine.cpp b/llvm/lib/Target/LoongArch/LoongArchTargetMachine.cpp
index 468c4f43cb902..2d08d5c674bc9 100644
--- a/llvm/lib/Target/LoongArch/LoongArchTargetMachine.cpp
+++ b/llvm/lib/Target/LoongArch/LoongArchTargetMachine.cpp
@@ -38,9 +38,7 @@ static std::string computeDataLayout(const Triple &TT) {
 
 static Reloc::Model getEffectiveRelocModel(const Triple &TT,
                                            Optional<Reloc::Model> RM) {
-  if (!RM.hasValue())
-    return Reloc::Static;
-  return *RM;
+  return RM.value_or(Reloc::Static);
 }
 
 LoongArchTargetMachine::LoongArchTargetMachine(

diff  --git a/mlir/include/mlir/IR/OpImplementation.h b/mlir/include/mlir/IR/OpImplementation.h
index c4bbac91bd938..bfb8adda2871f 100644
--- a/mlir/include/mlir/IR/OpImplementation.h
+++ b/mlir/include/mlir/IR/OpImplementation.h
@@ -723,7 +723,7 @@ class AsmParser {
     }
 
     /// Returns true if this switch has a value yet.
-    bool hasValue() const { return result.hasValue(); }
+    bool hasValue() const { return result.has_value(); }
 
     /// Return the result of the switch.
     LLVM_NODISCARD operator ResultT() {

diff  --git a/mlir/lib/Dialect/Vector/Transforms/VectorTransforms.cpp b/mlir/lib/Dialect/Vector/Transforms/VectorTransforms.cpp
index 868aff9ae5bf4..a423cd2eca8f2 100644
--- a/mlir/lib/Dialect/Vector/Transforms/VectorTransforms.cpp
+++ b/mlir/lib/Dialect/Vector/Transforms/VectorTransforms.cpp
@@ -1878,14 +1878,14 @@ ContractionOpLowering::lowerParallel(vector::ContractionOp op, int64_t lhsIndex,
       diag << "expected either lhsIndex=" << lhsIndex
            << " or rhsIndex=" << rhsIndex << " to be nonnegative";
     });
-  // getValueOr(-1) means that we tolerate a dimension not appearing
+  // value_or(-1) means that we tolerate a dimension not appearing
   // in the result map. That can't happen for actual parallel iterators, but
   // the caller ContractionOpLowering::matchAndRewrite is currently calling
   // lowerParallel also for the case of unit-size reduction dims appearing only
   // on one of LHS or RHS, not both. At the moment, such cases are created by
   // CastAwayContractionLeadingOneDim, so we need to either support that or
   // modify that pattern.
-  int64_t resIndex = getResultIndex(iMap[2], iterIndex).getValueOr(-1);
+  int64_t resIndex = getResultIndex(iMap[2], iterIndex).value_or(-1);
   if (resIndex == -1 && dimSize != 1)
     return rewriter.notifyMatchFailure(op, [&](Diagnostic &diag) {
       diag << "expected the dimension for iterIndex=" << iterIndex
@@ -1932,11 +1932,11 @@ ContractionOpLowering::lowerReduction(vector::ContractionOp op,
   SmallVector<AffineMap, 4> iMap = op.getIndexingMaps();
   Optional<int64_t> lookupLhs = getResultIndex(iMap[0], iterIndex);
   Optional<int64_t> lookupRhs = getResultIndex(iMap[1], iterIndex);
-  if (!lookupLhs.hasValue())
+  if (!lookupLhs.has_value())
     return rewriter.notifyMatchFailure(op, [&](Diagnostic &diag) {
       diag << "expected iterIndex=" << iterIndex << "to map to a LHS dimension";
     });
-  if (!lookupRhs.hasValue())
+  if (!lookupRhs.has_value())
     return rewriter.notifyMatchFailure(op, [&](Diagnostic &diag) {
       diag << "expected iterIndex=" << iterIndex << "to map to a RHS dimension";
     });


        


More information about the Mlir-commits mailing list