LLVM 20.0.0git
|
#include "llvm/Analysis/MemoryBuiltins.h"
#include "llvm/ADT/APInt.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/CommandLine.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 <optional>
#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 , StrDupLike = 1<<2 , MallocOrOpNewLike = MallocLike | OpNewLike , AllocLike = MallocOrOpNewLike | StrDupLike , AnyAlloc = AllocLike } |
enum class | MallocFamily { Malloc , CPPNew , CPPNewAligned , CPPNewArray , CPPNewArrayAligned , MSVCNew , MSVCArrayNew , VecMalloc , KmpcAllocShared } |
Variables | |
static cl::opt< unsigned > | ObjectSizeOffsetVisitorMaxVisitInstructions ("object-size-offset-visitor-max-visit-instructions", cl::desc("Maximum number of instructions for ObjectSizeOffsetVisitor to " "look at"), cl::init(100)) |
static const std::pair< LibFunc, AllocFnsTy > | AllocationFnData [] |
static const std::pair< LibFunc, FreeFnsTy > | FreeFnData [] |
#define DEBUG_TYPE "memory-builtins" |
Definition at line 51 of file MemoryBuiltins.cpp.
Enumerator | |
---|---|
OpNewLike | |
MallocLike | |
StrDupLike | |
MallocOrOpNewLike | |
AllocLike | |
AnyAlloc |
Definition at line 59 of file MemoryBuiltins.cpp.
|
strong |
Enumerator | |
---|---|
Malloc | |
CPPNew | |
CPPNewAligned | |
CPPNewArray | |
CPPNewArrayAligned | |
MSVCNew | |
MSVCArrayNew | |
VecMalloc | |
KmpcAllocShared |
Definition at line 68 of file MemoryBuiltins.cpp.
|
static |
Definition at line 718 of file MemoryBuiltins.cpp.
References aggregatePossibleConstantValuesImpl().
Referenced by llvm::ObjectSizeOffsetVisitor::visitAllocaInst(), and llvm::ObjectSizeOffsetVisitor::visitCallBase().
|
static |
Definition at line 685 of file MemoryBuiltins.cpp.
References aggregatePossibleConstantValuesImpl(), combinePossibleConstantValues(), and I.
Referenced by aggregatePossibleConstantValues(), and aggregatePossibleConstantValuesImpl().
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 355 of file MemoryBuiltins.cpp.
References I.
Referenced by llvm::getAllocSize().
|
static |
Definition at line 280 of file MemoryBuiltins.cpp.
References F, and getAllocFnKind().
|
static |
Definition at line 276 of file MemoryBuiltins.cpp.
References getAllocFnKind().
Referenced by llvm::getAllocationFamily(), llvm::getFreedOperand(), llvm::getReallocatedOperand(), llvm::isAllocationFn(), llvm::isAllocLikeFn(), llvm::isLibFreeFunction(), and llvm::isReallocLikeFn().
|
static |
Definition at line 674 of file MemoryBuiltins.cpp.
Referenced by aggregatePossibleConstantValuesImpl().
|
static |
Definition at line 219 of file MemoryBuiltins.cpp.
References getAllocationDataForFunction(), and getCalledFunction().
Referenced by llvm::getAllocAlignment(), llvm::getInitialValueOfAllocation(), llvm::isAllocationFn(), llvm::isAllocLikeFn(), llvm::isMallocOrCallocLikeFn(), and llvm::isNewLikeFn().
|
static |
Definition at line 227 of file MemoryBuiltins.cpp.
References getAllocationDataForFunction(), and getCalledFunction().
|
static |
Returns the allocation data for the given value if it's a call to a known allocation function.
Definition at line 177 of file MemoryBuiltins.cpp.
References AllocationFnData, AllocFnsTy::AllocTy, llvm::find_if(), AllocFnsTy::FstParam, llvm::TargetLibraryInfo::getLibFunc(), llvm::TargetLibraryInfo::has(), AllocFnsTy::NumParams, P, and AllocFnsTy::SndParam.
Referenced by getAllocationData(), llvm::getAllocationFamily(), and getAllocationSize().
|
static |
Definition at line 236 of file MemoryBuiltins.cpp.
References AnyAlloc, llvm::CallBase::arg_size(), getAllocationDataForFunction(), llvm::Attribute::getAllocSizeArgs(), getCalledFunction(), llvm::CallBase::getFnAttr(), and MallocLike.
Referenced by llvm::getAllocSize(), and llvm::ObjectSizeOffsetEvaluator::visitCallBase().
|
static |
Definition at line 272 of file MemoryBuiltins.cpp.
References F.
|
static |
Definition at line 263 of file MemoryBuiltins.cpp.
References llvm::Attribute::getValueAsInt(), and llvm::Attribute::isValid().
Referenced by checkFnAllocKind(), and llvm::getInitialValueOfAllocation().
Definition at line 159 of file MemoryBuiltins.cpp.
Referenced by llvm::orc::SpeculateQuery::findCalles(), FindPreallocatedCall(), getAllocationData(), llvm::getAllocationFamily(), getAllocationSize(), llvm::getFreedOperand(), llvm::BasicTTIImplBase< T >::getUnrollingPreferences(), llvm::AArch64TTIImpl::getUnrollingPreferences(), llvm::ARMTTIImpl::getUnrollingPreferences(), llvm::RISCVTTIImpl::getUnrollingPreferences(), llvm::SystemZTTIImpl::getUnrollingPreferences(), llvm::WebAssemblyTTIImpl::getUnrollingPreferences(), and isNoReturnDef().
std::optional< FreeFnsTy > getFreeFunctionDataForFunction | ( | const Function * | Callee, |
const LibFunc | TLIFn | ||
) |
Definition at line 488 of file MemoryBuiltins.cpp.
References llvm::find_if(), FreeFnData, and P.
Referenced by llvm::getAllocationFamily(), and llvm::isLibFreeFunction().
|
static |
Definition at line 564 of file MemoryBuiltins.cpp.
References llvm::APInt::getZero(), llvm::Offset, and Size.
Referenced by llvm::getObjectSize().
StringRef mangledNameForMallocFamily | ( | const MallocFamily & | Family | ) |
Definition at line 80 of file MemoryBuiltins.cpp.
References CPPNew, CPPNewAligned, CPPNewArray, CPPNewArrayAligned, KmpcAllocShared, llvm_unreachable, Malloc, MSVCArrayNew, MSVCNew, and VecMalloc.
Referenced by llvm::getAllocationFamily().
STATISTIC | ( | ObjectVisitorArgument | , |
"Number of arguments with unsolved size and offset" | |||
) |
STATISTIC | ( | ObjectVisitorLoad | , |
"Number of load instructions with unsolved size and offset" | |||
) |
|
static |
Definition at line 118 of file MemoryBuiltins.cpp.
Referenced by getAllocationDataForFunction().
Definition at line 455 of file MemoryBuiltins.cpp.
Referenced by getFreeFunctionDataForFunction().
|
static |