mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-23 11:13:28 +01:00
[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
This commit is contained in:
parent
17201bf9c4
commit
fc289b9de6
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user