summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/MemoryBuiltins.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Analysis/MemoryBuiltins.cpp')
-rw-r--r--llvm/lib/Analysis/MemoryBuiltins.cpp38
1 files changed, 22 insertions, 16 deletions
diff --git a/llvm/lib/Analysis/MemoryBuiltins.cpp b/llvm/lib/Analysis/MemoryBuiltins.cpp
index 3e464f08f2e..d41af65d202 100644
--- a/llvm/lib/Analysis/MemoryBuiltins.cpp
+++ b/llvm/lib/Analysis/MemoryBuiltins.cpp
@@ -79,6 +79,10 @@ static const std::pair<LibFunc::Func, AllocFnsTy> AllocationFnData[] = {
static Function *getCalledFunction(const Value *V, bool LookThroughBitCast) {
+ // Don't care about intrinsics in this case.
+ if (isa<IntrinsicInst>(V))
+ return nullptr;
+
if (LookThroughBitCast)
V = V->stripPointerCasts();
@@ -98,17 +102,9 @@ static Function *getCalledFunction(const Value *V, bool LookThroughBitCast) {
/// Returns the allocation data for the given value if it's either a call to a
/// known allocation function, or a call to a function with the allocsize
/// attribute.
-static Optional<AllocFnsTy> getAllocationData(const Value *V, AllocType AllocTy,
- const TargetLibraryInfo *TLI,
- bool LookThroughBitCast = false) {
- // Skip intrinsics
- if (isa<IntrinsicInst>(V))
- return None;
-
- const Function *Callee = getCalledFunction(V, LookThroughBitCast);
- if (!Callee)
- return None;
-
+static Optional<AllocFnsTy>
+getAllocationDataForFunction(const Function *Callee, AllocType AllocTy,
+ const TargetLibraryInfo *TLI) {
// Make sure that the function is available.
StringRef FnName = Callee->getName();
LibFunc::Func TLIFn;
@@ -144,20 +140,30 @@ static Optional<AllocFnsTy> getAllocationData(const Value *V, AllocType AllocTy,
return None;
}
+static Optional<AllocFnsTy> getAllocationData(const Value *V, AllocType AllocTy,
+ const TargetLibraryInfo *TLI,
+ bool LookThroughBitCast = false) {
+ if (const Function *Callee = getCalledFunction(V, LookThroughBitCast))
+ return getAllocationDataForFunction(Callee, AllocTy, TLI);
+ return None;
+}
+
static Optional<AllocFnsTy> getAllocationSize(const Value *V,
const TargetLibraryInfo *TLI) {
+ const Function *Callee = getCalledFunction(V, /*LookThroughBitCast=*/false);
+ if (!Callee)
+ return None;
+
// Prefer to use existing information over allocsize. This will give us an
// accurate AllocTy.
if (Optional<AllocFnsTy> Data =
- getAllocationData(V, AnyAlloc, TLI, /*LookThroughBitCast=*/false))
+ getAllocationDataForFunction(Callee, AnyAlloc, TLI))
return Data;
- // FIXME: Not calling getCalledFunction twice would be nice.
- const Function *Callee = getCalledFunction(V, /*LookThroughBitCast=*/false);
- if (!Callee || !Callee->hasFnAttribute(Attribute::AllocSize))
+ Attribute Attr = Callee->getFnAttribute(Attribute::AllocSize);
+ if (Attr == Attribute())
return None;
- Attribute Attr = Callee->getFnAttribute(Attribute::AllocSize);
std::pair<unsigned, Optional<unsigned>> Args = Attr.getAllocSizeArgs();
AllocFnsTy Result;
OpenPOWER on IntegriCloud