LLVM
15.0.0git
|
#include "llvm/Analysis/MemoryBuiltins.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/None.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Analysis/TargetFolder.h"
#include "llvm/Analysis/TargetLibraryInfo.h"
#include "llvm/Analysis/Utils/Local.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/IR/Argument.h"
#include "llvm/IR/Attributes.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GlobalAlias.h"
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Operator.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Value.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/raw_ostream.h"
#include <cassert>
#include <cstdint>
#include <iterator>
#include <numeric>
#include <type_traits>
#include <utility>
Go to the source code of this file.
Classes | |
struct | AllocFnsTy |
struct | FreeFnsTy |
Macros | |
#define | DEBUG_TYPE "memory-builtins" |
Enumerations | |
enum | AllocType : uint8_t { OpNewLike = 1<<0, MallocLike = 1<<1, AlignedAllocLike = 1<<2, CallocLike = 1<<3, ReallocLike = 1<<4, StrDupLike = 1<<5, MallocOrOpNewLike = MallocLike | OpNewLike, MallocOrCallocLike = MallocLike | OpNewLike | CallocLike | AlignedAllocLike, AllocLike = MallocOrCallocLike | StrDupLike, AnyAlloc = AllocLike | ReallocLike } |
enum | MallocFamily { MallocFamily::Malloc, MallocFamily::CPPNew, MallocFamily::CPPNewAligned, MallocFamily::CPPNewArray, MallocFamily::CPPNewArrayAligned, MallocFamily::MSVCNew, MallocFamily::MSVCArrayNew, MallocFamily::VecMalloc, MallocFamily::KmpcAllocShared } |
Functions | |
StringRef | mangledNameForMallocFamily (const MallocFamily &Family) |
static const Function * | getCalledFunction (const Value *V, bool &IsNoBuiltin) |
static Optional< AllocFnsTy > | getAllocationDataForFunction (const Function *Callee, AllocType AllocTy, const TargetLibraryInfo *TLI) |
Returns the allocation data for the given value if it's a call to a known allocation function. More... | |
static Optional< AllocFnsTy > | getAllocationData (const Value *V, AllocType AllocTy, const TargetLibraryInfo *TLI) |
static Optional< AllocFnsTy > | getAllocationData (const Value *V, AllocType AllocTy, function_ref< const TargetLibraryInfo &(Function &)> GetTLI) |
static Optional< AllocFnsTy > | getAllocationSize (const Value *V, const TargetLibraryInfo *TLI) |
static bool | isMallocLikeFn (const Value *V, const TargetLibraryInfo *TLI) |
Tests if a value is a call or invoke to a library function that allocates uninitialized memory (such as malloc). More... | |
static bool | isAlignedAllocLikeFn (const Value *V, const TargetLibraryInfo *TLI) |
Tests if a value is a call or invoke to a library function that allocates uninitialized memory with alignment (such as aligned_alloc). More... | |
static bool | isCallocLikeFn (const Value *V, const TargetLibraryInfo *TLI) |
Tests if a value is a call or invoke to a library function that allocates zero-filled memory (such as calloc). More... | |
static bool | CheckedZextOrTrunc (APInt &I, unsigned IntTyBits) |
When we're compiling N-bit code, and the user uses parameters that are greater than N bits (e.g. More... | |
Optional< FreeFnsTy > | getFreeFunctionDataForFunction (const Function *Callee, const LibFunc TLIFn) |
static APInt | getSizeWithOverflow (const SizeOffsetType &Data) |
STATISTIC (ObjectVisitorArgument, "Number of arguments with unsolved size and offset") | |
STATISTIC (ObjectVisitorLoad, "Number of load instructions with unsolved size and offset") | |
Variables | |
static const std::pair< LibFunc, AllocFnsTy > | AllocationFnData [] |
static const std::pair< LibFunc, FreeFnsTy > | FreeFnData [] |
#define DEBUG_TYPE "memory-builtins" |
Definition at line 52 of file MemoryBuiltins.cpp.
enum AllocType : uint8_t |
Enumerator | |
---|---|
OpNewLike | |
MallocLike | |
AlignedAllocLike | |
CallocLike | |
ReallocLike | |
StrDupLike | |
MallocOrOpNewLike | |
MallocOrCallocLike | |
AllocLike | |
AnyAlloc |
Definition at line 54 of file MemoryBuiltins.cpp.
|
strong |
Enumerator | |
---|---|
Malloc | |
CPPNew | |
CPPNewAligned | |
CPPNewArray | |
CPPNewArrayAligned | |
MSVCNew | |
MSVCArrayNew | |
VecMalloc | |
KmpcAllocShared |
Definition at line 67 of file MemoryBuiltins.cpp.
|
static |
When we're compiling N-bit code, and the user uses parameters that are greater than N bits (e.g.
uint64_t on a 32-bit build), we can run into trouble with APInt size issues. This function handles resizing + overflow checks for us. Check and zext or trunc I
depending on IntTyBits and I's value.
Definition at line 348 of file MemoryBuiltins.cpp.
References I.
Referenced by llvm::getAllocSize().
|
static |
Definition at line 216 of file MemoryBuiltins.cpp.
References Callee, getAllocationDataForFunction(), getCalledFunction(), and llvm::None.
Referenced by llvm::getAllocAlignment(), isAlignedAllocLikeFn(), llvm::isAllocationFn(), llvm::isAllocLikeFn(), isCallocLikeFn(), isMallocLikeFn(), llvm::isMallocOrCallocLikeFn(), and llvm::isReallocLikeFn().
|
static |
Definition at line 226 of file MemoryBuiltins.cpp.
References Callee, getAllocationDataForFunction(), getCalledFunction(), and llvm::None.
|
static |
Returns the allocation data for the given value if it's a call to a known allocation function.
Definition at line 180 of file MemoryBuiltins.cpp.
References AllocationFnData, AllocFnsTy::AllocTy, Callee, llvm::sys::path::end(), llvm::find_if(), AllocFnsTy::FstParam, llvm::Type::getContext(), llvm::FunctionCallee::getFunctionType(), llvm::Type::getInt8PtrTy(), llvm::TargetLibraryInfo::getLibFunc(), llvm::FunctionType::getNumParams(), llvm::FunctionType::getParamType(), llvm::FunctionType::getReturnType(), llvm::TargetLibraryInfo::has(), llvm::Type::isIntegerTy(), llvm::None, AllocFnsTy::NumParams, P, and AllocFnsTy::SndParam.
Referenced by getAllocationData(), llvm::getAllocationFamily(), getAllocationSize(), and llvm::isReallocLikeFn().
|
static |
Definition at line 236 of file MemoryBuiltins.cpp.
References AnyAlloc, llvm::AMDGPU::HSAMD::Kernel::Key::Args, Callee, llvm::Data, getAllocationDataForFunction(), llvm::Attribute::getAllocSizeArgs(), getCalledFunction(), MallocLike, and llvm::None.
Referenced by llvm::getAllocSize(), and llvm::ObjectSizeOffsetEvaluator::visitCallBase().
Definition at line 160 of file MemoryBuiltins.cpp.
References Callee.
Referenced by llvm::orc::SpeculateQuery::findCalles(), FindPreallocatedCall(), getAllocationData(), llvm::getAllocationFamily(), getAllocationSize(), llvm::WebAssemblyTTIImpl::getUnrollingPreferences(), llvm::SystemZTTIImpl::getUnrollingPreferences(), llvm::RISCVTTIImpl::getUnrollingPreferences(), llvm::AArch64TTIImpl::getUnrollingPreferences(), llvm::ARMTTIImpl::getUnrollingPreferences(), llvm::BasicTTIImplBase< AMDGPUTTIImpl >::getUnrollingPreferences(), and llvm::isFreeCall().
Definition at line 482 of file MemoryBuiltins.cpp.
References llvm::sys::path::end(), llvm::find_if(), FreeFnData, llvm::None, and P.
Referenced by llvm::getAllocationFamily(), and llvm::isLibFreeFunction().
|
static |
Definition at line 549 of file MemoryBuiltins.cpp.
References llvm::Data.
Referenced by llvm::getObjectSize().
|
static |
Tests if a value is a call or invoke to a library function that allocates uninitialized memory with alignment (such as aligned_alloc).
Definition at line 288 of file MemoryBuiltins.cpp.
References AlignedAllocLike, and getAllocationData().
Referenced by llvm::getInitialValueOfAllocation().
|
static |
Tests if a value is a call or invoke to a library function that allocates zero-filled memory (such as calloc).
Definition at line 294 of file MemoryBuiltins.cpp.
References CallocLike, and getAllocationData().
Referenced by llvm::getInitialValueOfAllocation().
|
static |
Tests if a value is a call or invoke to a library function that allocates uninitialized memory (such as malloc).
Definition at line 282 of file MemoryBuiltins.cpp.
References getAllocationData(), and MallocOrOpNewLike.
Referenced by llvm::getInitialValueOfAllocation().
StringRef mangledNameForMallocFamily | ( | const MallocFamily & | Family | ) |
Definition at line 79 of file MemoryBuiltins.cpp.
References CPPNew, CPPNewAligned, CPPNewArray, CPPNewArrayAligned, KmpcAllocShared, llvm_unreachable, Malloc, MSVCArrayNew, MSVCNew, and VecMalloc.
Referenced by llvm::getAllocationFamily().
STATISTIC | ( | ObjectVisitorLoad | , |
"Number of load instructions with unsolved size and offset" | |||
) |
|
static |
Definition at line 117 of file MemoryBuiltins.cpp.
Referenced by getAllocationDataForFunction().
Definition at line 447 of file MemoryBuiltins.cpp.
Referenced by getFreeFunctionDataForFunction().