[llvm] 29041bc - [APInt] Convert GetMostSignificantDifferentBit to std::optional

Krzysztof Parzyszek via llvm-commits llvm-commits at lists.llvm.org
Sat Dec 10 12:04:03 PST 2022


Author: Krzysztof Parzyszek
Date: 2022-12-10T14:03:29-06:00
New Revision: 29041bc0507f2b04d116ee3150bfd61ea01c5565

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

LOG: [APInt] Convert GetMostSignificantDifferentBit to std::optional

Added: 
    

Modified: 
    clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h
    llvm/include/llvm/ADT/APInt.h
    llvm/lib/IR/ConstantRange.cpp
    llvm/lib/Support/APInt.cpp
    llvm/unittests/ADT/APIntTest.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h
index e10ee4ae7a145..5815742d57ac7 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h
@@ -10,6 +10,7 @@
 #define LLVM_CLANG_ANALYZER_WEBKIT_PTRTYPESEMANTICS_H
 
 #include "llvm/ADT/APInt.h"
+#include "llvm/ADT/Optional.h"
 
 namespace clang {
 class CXXBaseSpecifier;

diff  --git a/llvm/include/llvm/ADT/APInt.h b/llvm/include/llvm/ADT/APInt.h
index c8ca617360c89..15e696ef91935 100644
--- a/llvm/include/llvm/ADT/APInt.h
+++ b/llvm/include/llvm/ADT/APInt.h
@@ -31,7 +31,6 @@ class raw_ostream;
 
 template <typename T> class SmallVectorImpl;
 template <typename T> class ArrayRef;
-template <typename T> class Optional;
 template <typename T, typename Enable> struct DenseMapInfo;
 
 class APInt;
@@ -2254,8 +2253,8 @@ std::optional<APInt> SolveQuadraticEquationWrap(APInt A, APInt B, APInt C,
 
 /// Compare two values, and if they are 
diff erent, return the position of the
 /// most significant bit that is 
diff erent in the values.
-Optional<unsigned> GetMostSignificantDifferentBit(const APInt &A,
-                                                  const APInt &B);
+std::optional<unsigned> GetMostSignificantDifferentBit(const APInt &A,
+                                                       const APInt &B);
 
 /// Splat/Merge neighboring bits to widen/narrow the bitmask represented
 /// by \param A to \param NewBitWidth bits.

diff  --git a/llvm/lib/IR/ConstantRange.cpp b/llvm/lib/IR/ConstantRange.cpp
index bae1e550a6a3d..2f0d3d1e3a5ac 100644
--- a/llvm/lib/IR/ConstantRange.cpp
+++ b/llvm/lib/IR/ConstantRange.cpp
@@ -37,6 +37,7 @@
 #include <algorithm>
 #include <cassert>
 #include <cstdint>
+#include <optional>
 
 using namespace llvm;
 
@@ -85,7 +86,7 @@ KnownBits ConstantRange::toKnownBits() const {
   APInt Min = getUnsignedMin();
   APInt Max = getUnsignedMax();
   KnownBits Known = KnownBits::makeConstant(Min);
-  if (Optional<unsigned> DifferentBit =
+  if (std::optional<unsigned> DifferentBit =
           APIntOps::GetMostSignificantDifferentBit(Min, Max)) {
     Known.Zero.clearLowBits(*DifferentBit + 1);
     Known.One.clearLowBits(*DifferentBit + 1);

diff  --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp
index b19de75a68f43..db55fd02396d6 100644
--- a/llvm/lib/Support/APInt.cpp
+++ b/llvm/lib/Support/APInt.cpp
@@ -2961,7 +2961,7 @@ llvm::APIntOps::SolveQuadraticEquationWrap(APInt A, APInt B, APInt C,
   return X;
 }
 
-Optional<unsigned>
+std::optional<unsigned>
 llvm::APIntOps::GetMostSignificantDifferentBit(const APInt &A, const APInt &B) {
   assert(A.getBitWidth() == B.getBitWidth() && "Must have the same bitwidth");
   if (A == B)

diff  --git a/llvm/unittests/ADT/APIntTest.cpp b/llvm/unittests/ADT/APIntTest.cpp
index b306a6d370645..3055581c7dd30 100644
--- a/llvm/unittests/ADT/APIntTest.cpp
+++ b/llvm/unittests/ADT/APIntTest.cpp
@@ -13,6 +13,7 @@
 #include "llvm/ADT/Twine.h"
 #include "gtest/gtest.h"
 #include <array>
+#include <optional>
 
 using namespace llvm;
 
@@ -2956,7 +2957,7 @@ TEST(APIntTest, GetMostSignificantDifferentBit) {
 
 TEST(APIntTest, GetMostSignificantDifferentBitExaustive) {
   auto GetHighestDifferentBitBruteforce =
-      [](const APInt &V0, const APInt &V1) -> llvm::Optional<unsigned> {
+      [](const APInt &V0, const APInt &V1) -> std::optional<unsigned> {
     assert(V0.getBitWidth() == V1.getBitWidth() && "Must have same bitwidth");
     if (V0 == V1)
       return std::nullopt; // Bitwise identical.


        


More information about the llvm-commits mailing list