diff options
author | Nikita Popov <npopov@redhat.com> | 2023-10-23 14:55:36 +0200 |
---|---|---|
committer | Nikita Popov <npopov@redhat.com> | 2023-10-23 14:56:39 +0200 |
commit | a3fb2348b19167dfb027e20f8e1306ebbf31cfbf (patch) | |
tree | d1da658c81019d2783f5930958ceef18dd95cd79 /llvm/lib/Analysis/BasicAliasAnalysis.cpp | |
parent | 324d1bb35aefec737ef381d98211f7771c4b0ab5 (diff) | |
download | llvm-a3fb2348b19167dfb027e20f8e1306ebbf31cfbf.zip llvm-a3fb2348b19167dfb027e20f8e1306ebbf31cfbf.tar.gz llvm-a3fb2348b19167dfb027e20f8e1306ebbf31cfbf.tar.bz2 |
[BasicAA] Return std::optional from getObjectSize() (NFC)
Prefer this over UnknownSize, especially once the return value
switches to something other than uint64_t.
Diffstat (limited to 'llvm/lib/Analysis/BasicAliasAnalysis.cpp')
-rw-r--r-- | llvm/lib/Analysis/BasicAliasAnalysis.cpp | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/llvm/lib/Analysis/BasicAliasAnalysis.cpp b/llvm/lib/Analysis/BasicAliasAnalysis.cpp index 3e59970..b516590 100644 --- a/llvm/lib/Analysis/BasicAliasAnalysis.cpp +++ b/llvm/lib/Analysis/BasicAliasAnalysis.cpp @@ -101,17 +101,18 @@ bool BasicAAResult::invalidate(Function &Fn, const PreservedAnalyses &PA, //===----------------------------------------------------------------------===// /// Returns the size of the object specified by V or UnknownSize if unknown. -static uint64_t getObjectSize(const Value *V, const DataLayout &DL, - const TargetLibraryInfo &TLI, - bool NullIsValidLoc, - bool RoundToAlign = false) { +static std::optional<uint64_t> getObjectSize(const Value *V, + const DataLayout &DL, + const TargetLibraryInfo &TLI, + bool NullIsValidLoc, + bool RoundToAlign = false) { uint64_t Size; ObjectSizeOpts Opts; Opts.RoundToAlign = RoundToAlign; Opts.NullIsUnknownSize = NullIsValidLoc; if (getObjectSize(V, Size, DL, &TLI, Opts)) return Size; - return MemoryLocation::UnknownSize; + return std::nullopt; } /// Returns true if we can prove that the object specified by V is smaller than @@ -151,10 +152,10 @@ static bool isObjectSmallerThan(const Value *V, uint64_t Size, // This function needs to use the aligned object size because we allow // reads a bit past the end given sufficient alignment. - uint64_t ObjectSize = getObjectSize(V, DL, TLI, NullIsValidLoc, - /*RoundToAlign*/ true); + std::optional<uint64_t> ObjectSize = getObjectSize(V, DL, TLI, NullIsValidLoc, + /*RoundToAlign*/ true); - return ObjectSize != MemoryLocation::UnknownSize && ObjectSize < Size; + return ObjectSize && *ObjectSize < Size; } /// Return the minimal extent from \p V to the end of the underlying object, @@ -182,8 +183,9 @@ static uint64_t getMinimalExtentFrom(const Value &V, /// Returns true if we can prove that the object specified by V has size Size. static bool isObjectSize(const Value *V, uint64_t Size, const DataLayout &DL, const TargetLibraryInfo &TLI, bool NullIsValidLoc) { - uint64_t ObjectSize = getObjectSize(V, DL, TLI, NullIsValidLoc); - return ObjectSize != MemoryLocation::UnknownSize && ObjectSize == Size; + std::optional<uint64_t> ObjectSize = + getObjectSize(V, DL, TLI, NullIsValidLoc); + return ObjectSize && *ObjectSize == Size; } //===----------------------------------------------------------------------===// |