50 #define DEBUG_TYPE "memory-builtins" 76 {LibFunc_ZnwjRKSt9nothrow_t, {
MallocLike, 2, 0, -1}},
77 {LibFunc_ZnwjSt11align_val_t, {
OpNewLike, 2, 0, -1}},
78 {LibFunc_ZnwjSt11align_val_tRKSt9nothrow_t,
81 {LibFunc_ZnwmRKSt9nothrow_t, {
MallocLike, 2, 0, -1}},
82 {LibFunc_ZnwmSt11align_val_t, {
OpNewLike, 2, 0, -1}},
83 {LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t,
86 {LibFunc_ZnajRKSt9nothrow_t, {
MallocLike, 2, 0, -1}},
87 {LibFunc_ZnajSt11align_val_t, {
OpNewLike, 2, 0, -1}},
88 {LibFunc_ZnajSt11align_val_tRKSt9nothrow_t,
91 {LibFunc_ZnamRKSt9nothrow_t, {
MallocLike, 2, 0, -1}},
92 {LibFunc_ZnamSt11align_val_t, {
OpNewLike, 2, 0, -1}},
93 {LibFunc_ZnamSt11align_val_tRKSt9nothrow_t,
95 {LibFunc_msvc_new_int, {
OpNewLike, 1, 0, -1}},
96 {LibFunc_msvc_new_int_nothrow, {
MallocLike, 2, 0, -1}},
97 {LibFunc_msvc_new_longlong, {
OpNewLike, 1, 0, -1}},
98 {LibFunc_msvc_new_longlong_nothrow, {
MallocLike, 2, 0, -1}},
99 {LibFunc_msvc_new_array_int, {
OpNewLike, 1, 0, -1}},
100 {LibFunc_msvc_new_array_int_nothrow, {
MallocLike, 2, 0, -1}},
101 {LibFunc_msvc_new_array_longlong, {
OpNewLike, 1, 0, -1}},
102 {LibFunc_msvc_new_array_longlong_nothrow, {
MallocLike, 2, 0, -1}},
114 if (isa<IntrinsicInst>(V))
117 if (LookThroughBitCast)
140 if (!TLI || !TLI->
getLibFunc(FnName, TLIFn) || !TLI->
has(TLIFn))
145 return P.first == TLIFn;
174 bool LookThroughBitCast =
false) {
175 bool IsNoBuiltinCall;
178 if (!IsNoBuiltinCall)
186 bool LookThroughBitCast =
false) {
187 bool IsNoBuiltinCall;
190 if (!IsNoBuiltinCall)
192 Callee, AllocTy, &GetTLI(const_cast<Function &>(*
Callee)));
198 bool IsNoBuiltinCall;
206 if (!IsNoBuiltinCall)
223 Result.
SndParam = Args.second.getValueOr(-1);
236 bool LookThroughBitCast) {
241 bool LookThroughBitCast) {
248 bool LookThroughBitCast) {
258 bool LookThroughBitCast) {
263 bool LookThroughBitCast) {
271 bool LookThroughBitCast) {
278 bool LookThroughBitCast) {
280 LookThroughBitCast).hasValue();
286 bool LookThroughBitCast) {
293 bool LookThroughBitCast) {
306 bool LookThroughBitCast) {
313 bool LookThroughBitCast) {
328 bool LookThroughSExt =
false) {
344 Value *Multiple =
nullptr;
345 if (
ComputeMultiple(MallocArg, ElementSize, Multiple, LookThroughSExt))
361 unsigned NumOfBitCastUses = 0;
366 if (
const BitCastInst *BCI = dyn_cast<BitCastInst>(*UI++)) {
367 MallocType = cast<PointerType>(BCI->getDestTy());
372 if (NumOfBitCastUses == 1)
376 if (NumOfBitCastUses == 0)
377 return cast<PointerType>(CI->
getType());
401 bool LookThroughSExt) {
415 unsigned ExpectedNumParams;
416 if (TLIFn == LibFunc_free ||
417 TLIFn == LibFunc_ZdlPv ||
418 TLIFn == LibFunc_ZdaPv ||
419 TLIFn == LibFunc_msvc_delete_ptr32 ||
420 TLIFn == LibFunc_msvc_delete_ptr64 ||
421 TLIFn == LibFunc_msvc_delete_array_ptr32 ||
422 TLIFn == LibFunc_msvc_delete_array_ptr64)
423 ExpectedNumParams = 1;
424 else if (TLIFn == LibFunc_ZdlPvj ||
425 TLIFn == LibFunc_ZdlPvm ||
426 TLIFn == LibFunc_ZdlPvRKSt9nothrow_t ||
427 TLIFn == LibFunc_ZdlPvSt11align_val_t ||
428 TLIFn == LibFunc_ZdaPvj ||
429 TLIFn == LibFunc_ZdaPvm ||
430 TLIFn == LibFunc_ZdaPvRKSt9nothrow_t ||
431 TLIFn == LibFunc_ZdaPvSt11align_val_t ||
432 TLIFn == LibFunc_msvc_delete_ptr32_int ||
433 TLIFn == LibFunc_msvc_delete_ptr64_longlong ||
434 TLIFn == LibFunc_msvc_delete_ptr32_nothrow ||
435 TLIFn == LibFunc_msvc_delete_ptr64_nothrow ||
436 TLIFn == LibFunc_msvc_delete_array_ptr32_int ||
437 TLIFn == LibFunc_msvc_delete_array_ptr64_longlong ||
438 TLIFn == LibFunc_msvc_delete_array_ptr32_nothrow ||
439 TLIFn == LibFunc_msvc_delete_array_ptr64_nothrow)
440 ExpectedNumParams = 2;
441 else if (TLIFn == LibFunc_ZdaPvSt11align_val_tRKSt9nothrow_t ||
442 TLIFn == LibFunc_ZdlPvSt11align_val_tRKSt9nothrow_t)
443 ExpectedNumParams = 3;
463 bool IsNoBuiltinCall;
466 if (Callee ==
nullptr || IsNoBuiltinCall)
471 if (!TLI || !TLI->
getLibFunc(FnName, TLIFn) || !TLI->
has(TLIFn))
482 if (Data.second.isNegative() || Data.first.ult(Data.second))
483 return APInt(Data.first.getBitWidth(), 0);
484 return Data.first - Data.second;
495 if (!Visitor.bothKnown(Data))
507 "ObjectSize must be a call to llvm.objectsize!");
522 auto *ResultType = cast<IntegerType>(ObjectSize->
getType());
544 Builder.
CreateSub(SizeOffsetPair.first, SizeOffsetPair.second);
546 Builder.
CreateICmpULT(SizeOffsetPair.first, SizeOffsetPair.second);
560 "Number of arguments with unsolved size and offset");
562 "Number of load instructions with unsolved size and offset");
564 APInt ObjectSizeOffsetVisitor::align(
APInt Size, uint64_t Alignment) {
565 if (Options.RoundToAlign && Alignment)
574 : DL(DL), TLI(TLI), Options(Options) {
587 if (!SeenInsts.insert(I).second)
594 if (
Argument *A = dyn_cast<Argument>(V))
605 if (CE->getOpcode() == Instruction::IntToPtr)
607 if (CE->getOpcode() == Instruction::GetElementPtr)
611 LLVM_DEBUG(
dbgs() <<
"ObjectSizeOffsetVisitor::compute() unhandled value: " 621 bool ObjectSizeOffsetVisitor::CheckedZextOrTrunc(
APInt &I) {
638 return std::make_pair(align(Size, I.
getAlignment()), Zero);
641 if (
const ConstantInt *
C = dyn_cast<ConstantInt>(ArraySize)) {
642 APInt NumElems =
C->getValue();
643 if (!CheckedZextOrTrunc(NumElems))
647 Size = Size.
umul_ov(NumElems, Overflow);
648 return Overflow ? unknown() : std::make_pair(align(Size, I.
getAlignment()),
657 ++ObjectVisitorArgument;
684 if (Size.
ugt(MaxSize))
687 return std::make_pair(Size, Zero);
695 if (!CheckedZextOrTrunc(Size))
700 return std::make_pair(Size, Zero);
707 if (!CheckedZextOrTrunc(NumElems))
711 Size = Size.
umul_ov(NumElems, Overflow);
712 return Overflow ? unknown() : std::make_pair(Size, Zero);
734 return std::make_pair(Zero, Zero);
754 return std::make_pair(PtrData.first, PtrData.second + Offset);
768 return std::make_pair(align(Size, GV.
getAlignment()), Zero);
790 if (TrueSide == FalseSide) {
797 if (TrueResult == FalseResult) {
801 if (TrueResult.
slt(FalseResult))
806 if (TrueResult.
sgt(FalseResult))
815 return std::make_pair(Zero, Zero);
819 LLVM_DEBUG(
dbgs() <<
"ObjectSizeOffsetVisitor unknown instruction:" << I
827 : DL(DL), TLI(TLI), Context(Context),
830 [&](
Instruction *I) { InsertedInstructions.insert(I); })),
847 for (
const Value *SeenVal : SeenVals) {
850 if (CacheIt != CacheMap.
end() &&
anyKnown(CacheIt->second))
851 CacheMap.
erase(CacheIt);
857 I->eraseFromParent();
862 InsertedInstructions.clear();
877 if (CacheIt != CacheMap.
end())
878 return CacheIt->second;
892 if (!SeenVals.
insert(V).second) {
896 }
else if (
Instruction *I = dyn_cast<Instruction>(V)) {
898 }
else if (isa<Argument>(V) ||
899 (isa<ConstantExpr>(V) &&
900 cast<ConstantExpr>(V)->
getOpcode() == Instruction::IntToPtr) ||
901 isa<GlobalAlias>(V) ||
902 isa<GlobalVariable>(V)) {
907 dbgs() <<
"ObjectSizeOffsetEvaluator::compute() unhandled value: " << *V
913 CacheMap[V] = Result;
926 Size = Builder.
CreateMul(Size, ArraySize);
927 return std::make_pair(Size, Zero);
944 return std::make_pair(FirstArg, Zero);
949 return std::make_pair(Size, Zero);
977 Offset = Builder.
CreateAdd(PtrData.second, Offset);
978 return std::make_pair(PtrData.first, Offset);
996 CacheMap[&PHI] = std::make_pair(SizePHI, OffsetPHI);
1006 InsertedInstructions.erase(OffsetPHI);
1009 InsertedInstructions.erase(SizePHI);
1021 InsertedInstructions.erase(SizePHI);
1027 InsertedInstructions.erase(OffsetPHI);
1029 return std::make_pair(Size, Offset);
1038 if (TrueSide == FalseSide)
1045 return std::make_pair(Size, Offset);
1049 LLVM_DEBUG(
dbgs() <<
"ObjectSizeOffsetEvaluator unknown instruction:" << I
bool getObjectSize(const Value *Ptr, uint64_t &Size, const DataLayout &DL, const TargetLibraryInfo *TLI, ObjectSizeOpts Opts={})
Compute the size of the object pointed by Ptr.
Value * EmitGEPOffset(IRBuilderTy *Builder, const DataLayout &DL, User *GEP, bool NoAssumptions=false)
Given a getelementptr instruction/constantexpr, emit the code necessary to compute the offset from th...
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
unsigned getAlignment() const
bool isAllocationFn(const Value *V, const TargetLibraryInfo *TLI, bool LookThroughBitCast=false)
Tests if a value is a call or invoke to a library function that allocates or reallocates memory (eith...
A parsed version of the target data layout string in and methods for querying it. ...
const_iterator end(StringRef path)
Get end iterator over path.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
bool hasDefinitiveInitializer() const
hasDefinitiveInitializer - Whether the global variable has an initializer, and any other instances of...
static const std::pair< LibFunc, AllocFnsTy > AllocationFnData[]
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
uint64_t getZExtValue() const
Get zero extended value.
This class represents an incoming formal argument to a Function.
Value * CreateZExtOrTrunc(Value *V, Type *DestTy, const Twine &Name="")
Create a ZExt or Trunc from the integer value V to DestTy.
This class represents lattice values for constants.
Type * getParamType(unsigned i) const
Parameter type accessors.
Value * CreateICmpULT(Value *LHS, Value *RHS, const Twine &Name="")
static SizeOffsetEvalType unknown()
bool isSized(SmallPtrSetImpl< Type *> *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
const CallInst * extractCallocCall(const Value *I, const TargetLibraryInfo *TLI)
extractCallocCall - Returns the corresponding CallInst if the instruction is a calloc call...
const StructLayout * getStructLayout(StructType *Ty) const
Returns a StructLayout object, indicating the alignment of the struct, its size, and the offsets of i...
bool hasByValOrInAllocaAttr() const
Return true if this argument has the byval attribute or inalloca attribute.
std::pair< Value *, Value * > SizeOffsetEvalType
bool NullIsUnknownSize
If this is true, null pointers in address space 0 will be treated as though they can't be evaluated...
bool slt(const APInt &RHS) const
Signed less than comparison.
This class represents a function call, abstracting a target machine's calling convention.
static Optional< AllocFnsTy > getAllocationDataForFunction(const Function *Callee, AllocType AllocTy, const TargetLibraryInfo *TLI)
Returns the allocation data for the given value if it's either a call to a known allocation function...
const Value * getTrueValue() const
The two locations do not alias at all.
An efficient, type-erasing, non-owning reference to a callable.
LLVMContext & getContext() const
All values hold a context through their type.
bool hasRetAttr(Attribute::AttrKind Kind) const
Return true if this return value has the given attribute.
SizeOffsetType visitAllocaInst(AllocaInst &I)
bool isInterposable() const
Return true if this global's definition can be substituted with an arbitrary definition at link time...
bool sgt(const APInt &RHS) const
Signed greater than comparison.
STATISTIC(NumFunctions, "Total number of functions")
bool isLibFreeFunction(const Function *F, const LibFunc TLIFn)
isLibFreeFunction - Returns true if the function is a builtin free()
An instruction for reading from memory.
FunTy * getCalledFunction() const
Return the function being called if this is a direct call, otherwise return null (if it's an indirect...
bool isReallocLikeFn(const Value *V, const TargetLibraryInfo *TLI, bool LookThroughBitCast=false)
Tests if a value is a call or invoke to a library function that reallocates memory (e...
APInt zextOrTrunc(unsigned width) const
Zero extend or truncate to width.
SizeOffsetType visitArgument(Argument &A)
unsigned getBitWidth() const
Return the number of bits in the APInt.
bool accumulateConstantOffset(const DataLayout &DL, APInt &Offset) const
Accumulate the constant address offset of this GEP if possible.
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
const CallInst * isFreeCall(const Value *I, const TargetLibraryInfo *TLI)
isFreeCall - Returns non-null if the value is a call to the builtin free()
Value * getArgOperand(unsigned i) const
Type * getIndexType(Type *PtrTy) const
Returns the type of a GEP index.
This class represents the LLVM 'select' instruction.
const CallInst * extractMallocCall(const Value *I, function_ref< const TargetLibraryInfo &(Function &)> GetTLI)
extractMallocCall - Returns the corresponding CallInst if the instruction is a malloc call...
unsigned getAlignment() const
Return the alignment of the memory that is being allocated by the instruction.
SizeOffsetEvalType visitGEPOperator(GEPOperator &GEP)
SizeOffsetType visitExtractValueInst(ExtractValueInst &I)
SizeOffsetType visitGEPOperator(GEPOperator &GEP)
'undef' values are things that do not have specified contents.
static Optional< AllocFnsTy > getAllocationSize(const Value *V, const TargetLibraryInfo *TLI)
Class to represent struct types.
APInt zextOrSelf(unsigned width) const
Zero extend or truncate to width.
static Optional< unsigned > getOpcode(ArrayRef< VPValue *> Values)
Returns the opcode of Values or ~0 if they do not all agree.
bool isIntegerTy() const
True if this is an instance of IntegerType.
SizeOffsetEvalType visitCallSite(CallSite CS)
SizeOffsetType visitIntToPtrInst(IntToPtrInst &)
This file contains the simple types necessary to represent the attributes associated with functions a...
Value * CreateAdd(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
This file implements a class to represent arbitrary precision integral constant values and operations...
void visit(Iterator Start, Iterator End)
Value * lowerObjectSizeCall(IntrinsicInst *ObjectSize, const DataLayout &DL, const TargetLibraryInfo *TLI, bool MustSucceed)
Try to turn a call to @llvm.objectsize into an integer value of the given Type.
InstrTy * getInstruction() const
unsigned getActiveBits() const
Compute the number of active bits in the value.
bool isNoAliasFn(const Value *V, const TargetLibraryInfo *TLI, bool LookThroughBitCast=false)
Tests if a value is a call or invoke to a function that returns a NoAlias pointer (including malloc/c...
Same as Min, except we pick the maximum size of all of the branches.
A constant value that is initialized with an expression using other constant values.
Class to represent function types.
Type * getType() const
All values are typed, get the type of this value.
Evaluate all branches of an unknown condition.
Evaluate the size and offset of an object pointed to by a Value*.
bool has(LibFunc F) const
Tests whether a library function is available.
This class represents a no-op cast from one type to another.
bool isOpNewLikeFn(const Value *V, const TargetLibraryInfo *TLI, bool LookThroughBitCast=false)
Tests if a value is a call or invoke to a library function that allocates memory and throws if an all...
const APInt & getValue() const
Return the constant as an APInt value reference.
TargetFolder - Create constants with target dependent folding.
Value * CreateSub(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
std::pair< unsigned, Optional< unsigned > > getAllocSizeArgs() const
Returns the argument numbers for the allocsize attribute (or pair(0, 0) if not known).
uint64_t GetStringLength(const Value *V, unsigned CharSize=8)
If we can compute the length of the string pointed to by the specified pointer, return 'len+1'...
SizeOffsetType visitInstruction(Instruction &I)
void SetInsertPoint(BasicBlock *TheBB)
This specifies that created instructions should be appended to the end of the specified block...
Class to represent pointers.
iterator find(const_arg_type_t< KeyT > Val)
Value * getMallocArraySize(CallInst *CI, const DataLayout &DL, const TargetLibraryInfo *TLI, bool LookThroughSExt=false)
getMallocArraySize - Returns the array size of a malloc call.
SizeOffsetType visitGlobalVariable(GlobalVariable &GV)
bool isVoidTy() const
Return true if this is 'void'.
bool erase(const KeyT &Val)
bool isNoBuiltin() const
Return true if the call should not be treated as a call to a builtin.
SizeOffsetEvalType visitSelectInst(SelectInst &I)
const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
ObjectSizeOffsetEvaluator(const DataLayout &DL, const TargetLibraryInfo *TLI, LLVMContext &Context, ObjectSizeOpts EvalOpts={})
The instances of the Type class are immutable: once they are created, they are never changed...
This is an important class for using LLVM in a threaded context.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Value * CreateSelect(Value *C, Value *True, Value *False, const Twine &Name="", Instruction *MDFrom=nullptr)
TypeSize getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
ValTy * getArgument(unsigned ArgNo) const
unsigned getNumParams() const
Return the number of fixed parameters this function type requires.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
static Value * computeArraySize(const CallInst *CI, const DataLayout &DL, const TargetLibraryInfo *TLI, bool LookThroughSExt=false)
static APInt getSizeWithOverflow(const SizeOffsetType &Data)
Value * getPointerOperand()
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
static bool hasNoAliasAttr(const Value *V, bool LookThroughBitCast)
unsigned getAddressSpace() const
Return the address space of the Pointer type.
static Optional< AllocFnsTy > getAllocationData(const Value *V, AllocType AllocTy, const TargetLibraryInfo *TLI, bool LookThroughBitCast=false)
auto find_if(R &&Range, UnaryPredicate P) -> decltype(adl_begin(Range))
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly...
unsigned getIndexTypeSizeInBits(Type *Ty) const
Layout size of the index used in GEP calculation.
const Function * getFunction() const
Return the function this instruction belongs to.
This class represents a cast from an integer to a pointer.
const Value * getCondition() const
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function. ...
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
SizeOffsetType visitCallSite(CallSite CS)
const Value * getArraySize() const
Get the number of elements allocated.
std::pair< APInt, APInt > SizeOffsetType
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
static PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
PointerType * getMallocType(const CallInst *CI, const TargetLibraryInfo *TLI)
getMallocType - Returns the PointerType resulting from the malloc call.
Value * CreateMul(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
SizeOffsetType visitSelectInst(SelectInst &I)
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of this intrinsic.
SizeOffsetType visitExtractElementInst(ExtractElementInst &I)
SizeOffsetType visitGlobalAlias(GlobalAlias &GA)
PHINode * CreatePHI(Type *Ty, unsigned NumReservedValues, const Twine &Name="")
SizeOffsetEvalType visitInstruction(Instruction &I)
Value * hasConstantValue() const
If the specified PHI node always merges together the same value, return the value, otherwise return null.
unsigned getNumOperands() const
Mode EvalMode
How we want to evaluate this object's size.
This is the shared class of boolean and integer constants.
Evaluate the size and offset of an object pointed to by a Value* statically.
unsigned getParamAlignment() const
If this is a byval or inalloca argument, return its alignment.
Provides information about what library functions are available for the current target.
SizeOffsetType visitPHINode(PHINode &)
A constant pointer value that points to null.
Type * getReturnType() const
uint64_t getSizeInBytes() const
SizeOffsetType visitUndefValue(UndefValue &)
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
unsigned getNumIncomingValues() const
Return the number of incoming edges.
static const Function * getCalledFunction(const Value *V, bool LookThroughBitCast, bool &IsNoBuiltin)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
SizeOffsetType compute(Value *V)
FunctionType * getFunctionType() const
Returns the FunctionType for me.
Class for arbitrary precision integers.
amdgpu Simplify well known AMD library false FunctionCallee Callee
SizeOffsetEvalType visitIntToPtrInst(IntToPtrInst &)
Type * getMallocAllocatedType(const CallInst *CI, const TargetLibraryInfo *TLI)
getMallocAllocatedType - Returns the Type allocated by malloc call.
SizeOffsetEvalType visitPHINode(PHINode &PHI)
bool getLibFunc(StringRef funcName, LibFunc &F) const
Searches for a particular function name.
bool isMallocLikeFn(const Value *V, const TargetLibraryInfo *TLI, bool LookThroughBitCast=false)
Tests if a value is a call or invoke to a library function that allocates uninitialized memory (such ...
const Value * getFalseValue() const
user_iterator_impl< const User > const_user_iterator
Fail to evaluate an unknown condition.
SizeOffsetEvalType compute(Value *V)
bool ugt(const APInt &RHS) const
Unsigned greater than comparison.
static bool isZero(Value *V, const DataLayout &DL, DominatorTree *DT, AssumptionCache *AC)
Provides an 'InsertHelper' that calls a user-provided callback after performing the default insertion...
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
ObjectSizeOffsetVisitor(const DataLayout &DL, const TargetLibraryInfo *TLI, LLVMContext &Context, ObjectSizeOpts Options={})
SizeOffsetEvalType visitLoadInst(LoadInst &I)
bool isMallocOrCallocLikeFn(const Value *V, const TargetLibraryInfo *TLI, bool LookThroughBitCast=false)
Tests if a value is a call or invoke to a library function that allocates memory similar to malloc or...
StringRef getName() const
Return a constant reference to the value's name.
Establish a view to a call site for examination.
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
bool isCallocLikeFn(const Value *V, const TargetLibraryInfo *TLI, bool LookThroughBitCast=false)
Tests if a value is a call or invoke to a library function that allocates zero-filled memory (such as...
PointerType * getType() const
Specialize the getType() method to always return an PointerType, which reduces the amount of casting ...
bool isAllocLikeFn(const Value *V, const TargetLibraryInfo *TLI, bool LookThroughBitCast=false)
Tests if a value is a call or invoke to a library function that allocates memory (either malloc...
bool ComputeMultiple(Value *V, unsigned Base, Value *&Multiple, bool LookThroughSExt=false, unsigned Depth=0)
This function computes the integer multiple of Base that equals V.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Type * getValueType() const
bool anyKnown(SizeOffsetEvalType SizeOffset)
APInt umul_ov(const APInt &RHS, bool &Overflow) const
bool isArrayAllocation() const
Return true if there is an allocation size parameter to the allocation instruction that is not 1...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
user_iterator user_begin()
static bool bothKnown(const SizeOffsetType &SizeOffset)
LLVM Value Representation.
SizeOffsetEvalType visitExtractElementInst(ExtractElementInst &I)
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
StringRef - Represent a constant reference to a string, i.e.
Various options to control the behavior of getObjectSize.
static APInt getNullValue(unsigned numBits)
Get the '0' value.
bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
SizeOffsetType visitLoadInst(LoadInst &I)
SizeOffsetEvalType visitAllocaInst(AllocaInst &I)
bool isStrdupLikeFn(const Value *V, const TargetLibraryInfo *TLI, bool LookThroughBitCast=false)
Tests if a value is a call or invoke to a library function that allocates memory (strdup, strndup).
bool bothKnown(SizeOffsetEvalType SizeOffset)
SizeOffsetType visitConstantPointerNull(ConstantPointerNull &)
SizeOffsetEvalType visitExtractValueInst(ExtractValueInst &I)
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Type * getElementType() const
A wrapper class for inspecting calls to intrinsic functions.
an instruction to allocate memory on the stack
const Constant * getAliasee() const