summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/MemoryBuiltins.cpp
diff options
context:
space:
mode:
authorGeorge Burgess IV <george.burgess.iv@gmail.com>2016-12-27 06:10:50 +0000
committerGeorge Burgess IV <george.burgess.iv@gmail.com>2016-12-27 06:10:50 +0000
commitce044895150be24f6238bbf85146948c2d802d60 (patch)
treeb1604680375ae5595f279992d0fe47a1c3a7b51e /llvm/lib/Analysis/MemoryBuiltins.cpp
parentb531698ff0f3d85a225d26ee84714088dfd48636 (diff)
downloadbcm5719-llvm-ce044895150be24f6238bbf85146948c2d802d60.tar.gz
bcm5719-llvm-ce044895150be24f6238bbf85146948c2d802d60.zip
[Analysis] Refactor as promised in r290397.
This also makes us no longer check for `allocsize` on intrinsic calls. This shouldn't matter, since intrinsics should provide the information we get from `allocsize` on their own. llvm-svn: 290585
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