aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/MemoryBuiltins.cpp
diff options
context:
space:
mode:
authorKazu Hirata <kazu@google.com>2022-12-11 01:32:26 -0800
committerKazu Hirata <kazu@google.com>2022-12-11 01:32:26 -0800
commite5ef6aced2e4e84069a9de45daed6ff8b2598e6f (patch)
treed455bf1c3a936541a1fc3b92780d9dbe4fbe2620 /llvm/lib/Analysis/MemoryBuiltins.cpp
parente275faa5fef3dd001e7e5bfda35bd541cc841c84 (diff)
downloadllvm-e5ef6aced2e4e84069a9de45daed6ff8b2598e6f.zip
llvm-e5ef6aced2e4e84069a9de45daed6ff8b2598e6f.tar.gz
llvm-e5ef6aced2e4e84069a9de45daed6ff8b2598e6f.tar.bz2
[Analysis] Use std::optional in MemoryBuiltins.cpp (NFC)
This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
Diffstat (limited to 'llvm/lib/Analysis/MemoryBuiltins.cpp')
-rw-r--r--llvm/lib/Analysis/MemoryBuiltins.cpp35
1 files changed, 18 insertions, 17 deletions
diff --git a/llvm/lib/Analysis/MemoryBuiltins.cpp b/llvm/lib/Analysis/MemoryBuiltins.cpp
index 5151783..679dd08 100644
--- a/llvm/lib/Analysis/MemoryBuiltins.cpp
+++ b/llvm/lib/Analysis/MemoryBuiltins.cpp
@@ -162,7 +162,7 @@ static const Function *getCalledFunction(const Value *V,
/// Returns the allocation data for the given value if it's a call to a known
/// allocation function.
-static Optional<AllocFnsTy>
+static std::optional<AllocFnsTy>
getAllocationDataForFunction(const Function *Callee, AllocType AllocTy,
const TargetLibraryInfo *TLI) {
// Don't perform a slow TLI lookup, if this function doesn't return a pointer
@@ -204,8 +204,9 @@ getAllocationDataForFunction(const Function *Callee, AllocType AllocTy,
return std::nullopt;
}
-static Optional<AllocFnsTy> getAllocationData(const Value *V, AllocType AllocTy,
- const TargetLibraryInfo *TLI) {
+static std::optional<AllocFnsTy>
+getAllocationData(const Value *V, AllocType AllocTy,
+ const TargetLibraryInfo *TLI) {
bool IsNoBuiltinCall;
if (const Function *Callee = getCalledFunction(V, IsNoBuiltinCall))
if (!IsNoBuiltinCall)
@@ -213,7 +214,7 @@ static Optional<AllocFnsTy> getAllocationData(const Value *V, AllocType AllocTy,
return std::nullopt;
}
-static Optional<AllocFnsTy>
+static std::optional<AllocFnsTy>
getAllocationData(const Value *V, AllocType AllocTy,
function_ref<const TargetLibraryInfo &(Function &)> GetTLI) {
bool IsNoBuiltinCall;
@@ -224,8 +225,8 @@ getAllocationData(const Value *V, AllocType AllocTy,
return std::nullopt;
}
-static Optional<AllocFnsTy> getAllocationSize(const Value *V,
- const TargetLibraryInfo *TLI) {
+static std::optional<AllocFnsTy>
+getAllocationSize(const Value *V, const TargetLibraryInfo *TLI) {
bool IsNoBuiltinCall;
const Function *Callee =
getCalledFunction(V, IsNoBuiltinCall);
@@ -235,7 +236,7 @@ static Optional<AllocFnsTy> getAllocationSize(const Value *V,
// Prefer to use existing information over allocsize. This will give us an
// accurate AllocTy.
if (!IsNoBuiltinCall)
- if (Optional<AllocFnsTy> Data =
+ if (std::optional<AllocFnsTy> Data =
getAllocationDataForFunction(Callee, AnyAlloc, TLI))
return Data;
@@ -340,7 +341,7 @@ bool llvm::isRemovableAlloc(const CallBase *CB, const TargetLibraryInfo *TLI) {
Value *llvm::getAllocAlignment(const CallBase *V,
const TargetLibraryInfo *TLI) {
- const Optional<AllocFnsTy> FnData = getAllocationData(V, AnyAlloc, TLI);
+ const std::optional<AllocFnsTy> FnData = getAllocationData(V, AnyAlloc, TLI);
if (FnData && FnData->AlignParam >= 0) {
return V->getOperand(FnData->AlignParam);
}
@@ -363,12 +364,12 @@ static bool CheckedZextOrTrunc(APInt &I, unsigned IntTyBits) {
return true;
}
-Optional<APInt>
+std::optional<APInt>
llvm::getAllocSize(const CallBase *CB, const TargetLibraryInfo *TLI,
function_ref<const Value *(const Value *)> Mapper) {
// Note: This handles both explicitly listed allocation functions and
// allocsize. The code structure could stand to be cleaned up a bit.
- Optional<AllocFnsTy> FnData = getAllocationSize(CB, TLI);
+ std::optional<AllocFnsTy> FnData = getAllocationSize(CB, TLI);
if (!FnData)
return std::nullopt;
@@ -485,8 +486,8 @@ static const std::pair<LibFunc, FreeFnsTy> FreeFnData[] = {
};
// clang-format on
-Optional<FreeFnsTy> getFreeFunctionDataForFunction(const Function *Callee,
- const LibFunc TLIFn) {
+std::optional<FreeFnsTy> getFreeFunctionDataForFunction(const Function *Callee,
+ const LibFunc TLIFn) {
const auto *Iter =
find_if(FreeFnData, [TLIFn](const std::pair<LibFunc, FreeFnsTy> &P) {
return P.first == TLIFn;
@@ -496,8 +497,8 @@ Optional<FreeFnsTy> getFreeFunctionDataForFunction(const Function *Callee,
return Iter->second;
}
-Optional<StringRef> llvm::getAllocationFamily(const Value *I,
- const TargetLibraryInfo *TLI) {
+std::optional<StringRef>
+llvm::getAllocationFamily(const Value *I, const TargetLibraryInfo *TLI) {
bool IsNoBuiltin;
const Function *Callee = getCalledFunction(I, IsNoBuiltin);
if (Callee == nullptr || IsNoBuiltin)
@@ -525,7 +526,7 @@ Optional<StringRef> llvm::getAllocationFamily(const Value *I,
/// isLibFreeFunction - Returns true if the function is a builtin free()
bool llvm::isLibFreeFunction(const Function *F, const LibFunc TLIFn) {
- Optional<FreeFnsTy> FnData = getFreeFunctionDataForFunction(F, TLIFn);
+ std::optional<FreeFnsTy> FnData = getFreeFunctionDataForFunction(F, TLIFn);
if (!FnData)
return checkFnAllocKind(F, AllocFnKind::Free);
@@ -781,7 +782,7 @@ SizeOffsetType ObjectSizeOffsetVisitor::visitArgument(Argument &A) {
}
SizeOffsetType ObjectSizeOffsetVisitor::visitCallBase(CallBase &CB) {
- if (Optional<APInt> Size = getAllocSize(&CB, TLI))
+ if (std::optional<APInt> Size = getAllocSize(&CB, TLI))
return std::make_pair(*Size, Zero);
return unknown();
}
@@ -1113,7 +1114,7 @@ SizeOffsetEvalType ObjectSizeOffsetEvaluator::visitAllocaInst(AllocaInst &I) {
}
SizeOffsetEvalType ObjectSizeOffsetEvaluator::visitCallBase(CallBase &CB) {
- Optional<AllocFnsTy> FnData = getAllocationSize(&CB, TLI);
+ std::optional<AllocFnsTy> FnData = getAllocationSize(&CB, TLI);
if (!FnData)
return unknown();