[llvm] r290585 - [Analysis] Refactor as promised in r290397.
George Burgess IV via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 26 22:10:51 PST 2016
Author: gbiv
Date: Tue Dec 27 00:10:50 2016
New Revision: 290585
URL: http://llvm.org/viewvc/llvm-project?rev=290585&view=rev
Log:
[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.
Modified:
llvm/trunk/lib/Analysis/MemoryBuiltins.cpp
Modified: llvm/trunk/lib/Analysis/MemoryBuiltins.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/MemoryBuiltins.cpp?rev=290585&r1=290584&r2=290585&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/MemoryBuiltins.cpp (original)
+++ llvm/trunk/lib/Analysis/MemoryBuiltins.cpp Tue Dec 27 00:10:50 2016
@@ -79,6 +79,10 @@ static const std::pair<LibFunc::Func, Al
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
/// 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> getAllocatio
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;
More information about the llvm-commits
mailing list