Go to the documentation of this file.
50 #define DEBUG_TYPE "memory-builtins"
78 {LibFunc_ZnwjRKSt9nothrow_t, {
MallocLike, 2, 0, -1}},
79 {LibFunc_ZnwjSt11align_val_t, {
OpNewLike, 2, 0, -1}},
80 {LibFunc_ZnwjSt11align_val_tRKSt9nothrow_t,
83 {LibFunc_ZnwmRKSt9nothrow_t, {
MallocLike, 2, 0, -1}},
84 {LibFunc_ZnwmSt11align_val_t, {
OpNewLike, 2, 0, -1}},
85 {LibFunc_ZnwmSt11align_val_tRKSt9nothrow_t,
88 {LibFunc_ZnajRKSt9nothrow_t, {
MallocLike, 2, 0, -1}},
89 {LibFunc_ZnajSt11align_val_t, {
OpNewLike, 2, 0, -1}},
90 {LibFunc_ZnajSt11align_val_tRKSt9nothrow_t,
93 {LibFunc_ZnamRKSt9nothrow_t, {
MallocLike, 2, 0, -1}},
94 {LibFunc_ZnamSt11align_val_t, {
OpNewLike, 2, 0, -1}},
95 {LibFunc_ZnamSt11align_val_tRKSt9nothrow_t,
97 {LibFunc_msvc_new_int, {
OpNewLike, 1, 0, -1}},
98 {LibFunc_msvc_new_int_nothrow, {
MallocLike, 2, 0, -1}},
99 {LibFunc_msvc_new_longlong, {
OpNewLike, 1, 0, -1}},
100 {LibFunc_msvc_new_longlong_nothrow, {
MallocLike, 2, 0, -1}},
101 {LibFunc_msvc_new_array_int, {
OpNewLike, 1, 0, -1}},
102 {LibFunc_msvc_new_array_int_nothrow, {
MallocLike, 2, 0, -1}},
103 {LibFunc_msvc_new_array_longlong, {
OpNewLike, 1, 0, -1}},
104 {LibFunc_msvc_new_array_longlong_nothrow, {
MallocLike, 2, 0, -1}},
119 if (isa<IntrinsicInst>(V))
122 if (LookThroughBitCast)
125 const auto *CB = dyn_cast<CallBase>(V);
129 IsNoBuiltin = CB->isNoBuiltin();
145 if (!TLI || !TLI->
getLibFunc(FnName, TLIFn) || !TLI->
has(TLIFn))
150 return P.first == TLIFn;
179 bool LookThroughBitCast =
false) {
180 bool IsNoBuiltinCall;
183 if (!IsNoBuiltinCall)
191 bool LookThroughBitCast =
false) {
192 bool IsNoBuiltinCall;
195 if (!IsNoBuiltinCall)
203 bool IsNoBuiltinCall;
211 if (!IsNoBuiltinCall)
226 Result.NumParams =
Callee->getNumOperands();
227 Result.FstParam =
Args.first;
228 Result.SndParam =
Args.second.getValueOr(-1);
235 return CB && CB->hasRetAttr(Attribute::NoAlias);
242 bool LookThroughBitCast) {
247 bool LookThroughBitCast) {
254 bool LookThroughBitCast) {
264 bool LookThroughBitCast) {
269 bool LookThroughBitCast) {
277 bool LookThroughBitCast) {
283 bool LookThroughBitCast) {
291 bool LookThroughBitCast) {
298 bool LookThroughBitCast) {
300 LookThroughBitCast).hasValue();
306 bool LookThroughBitCast) {
313 bool LookThroughBitCast) {
326 bool LookThroughBitCast) {
333 bool LookThroughBitCast) {
348 bool LookThroughSExt =
false) {
354 if (!
T || !
T->isSized())
357 unsigned ElementSize =
DL.getTypeAllocSize(
T);
359 ElementSize =
DL.getStructLayout(
ST)->getSizeInBytes();
364 Value *Multiple =
nullptr;
365 if (
ComputeMultiple(MallocArg, ElementSize, Multiple, LookThroughSExt))
381 unsigned NumOfBitCastUses = 0;
385 if (
const BitCastInst *BCI = dyn_cast<BitCastInst>(U)) {
386 MallocType = cast<PointerType>(BCI->getDestTy());
391 if (NumOfBitCastUses == 1)
395 if (NumOfBitCastUses == 0)
396 return cast<PointerType>(CI->
getType());
420 bool LookThroughSExt) {
434 unsigned ExpectedNumParams;
435 if (TLIFn == LibFunc_free ||
436 TLIFn == LibFunc_ZdlPv ||
437 TLIFn == LibFunc_ZdaPv ||
438 TLIFn == LibFunc_msvc_delete_ptr32 ||
439 TLIFn == LibFunc_msvc_delete_ptr64 ||
440 TLIFn == LibFunc_msvc_delete_array_ptr32 ||
441 TLIFn == LibFunc_msvc_delete_array_ptr64)
442 ExpectedNumParams = 1;
443 else if (TLIFn == LibFunc_ZdlPvj ||
444 TLIFn == LibFunc_ZdlPvm ||
445 TLIFn == LibFunc_ZdlPvRKSt9nothrow_t ||
446 TLIFn == LibFunc_ZdlPvSt11align_val_t ||
447 TLIFn == LibFunc_ZdaPvj ||
448 TLIFn == LibFunc_ZdaPvm ||
449 TLIFn == LibFunc_ZdaPvRKSt9nothrow_t ||
450 TLIFn == LibFunc_ZdaPvSt11align_val_t ||
451 TLIFn == LibFunc_msvc_delete_ptr32_int ||
452 TLIFn == LibFunc_msvc_delete_ptr64_longlong ||
453 TLIFn == LibFunc_msvc_delete_ptr32_nothrow ||
454 TLIFn == LibFunc_msvc_delete_ptr64_nothrow ||
455 TLIFn == LibFunc_msvc_delete_array_ptr32_int ||
456 TLIFn == LibFunc_msvc_delete_array_ptr64_longlong ||
457 TLIFn == LibFunc_msvc_delete_array_ptr32_nothrow ||
458 TLIFn == LibFunc_msvc_delete_array_ptr64_nothrow)
459 ExpectedNumParams = 2;
460 else if (TLIFn == LibFunc_ZdaPvSt11align_val_tRKSt9nothrow_t ||
461 TLIFn == LibFunc_ZdlPvSt11align_val_tRKSt9nothrow_t ||
462 TLIFn == LibFunc_ZdlPvjSt11align_val_t ||
463 TLIFn == LibFunc_ZdlPvmSt11align_val_t ||
464 TLIFn == LibFunc_ZdaPvjSt11align_val_t ||
465 TLIFn == LibFunc_ZdaPvmSt11align_val_t)
466 ExpectedNumParams = 3;
486 bool IsNoBuiltinCall;
489 if (
Callee ==
nullptr || IsNoBuiltinCall)
494 if (!TLI || !TLI->
getLibFunc(FnName, TLIFn) || !TLI->
has(TLIFn))
505 if (
Data.second.isNegative() ||
Data.first.ult(
Data.second))
506 return APInt(
Data.first.getBitWidth(), 0);
530 "ObjectSize must be a call to llvm.objectsize!");
532 bool MaxVal = cast<ConstantInt>(ObjectSize->
getArgOperand(1))->isZero();
545 auto *ResultType = cast<IntegerType>(ObjectSize->
getType());
546 bool StaticOnly = cast<ConstantInt>(ObjectSize->
getArgOperand(3))->isZero();
562 Builder.SetInsertPoint(ObjectSize);
567 Builder.CreateSub(SizeOffsetPair.first, SizeOffsetPair.second);
569 Builder.CreateICmpULT(SizeOffsetPair.first, SizeOffsetPair.second);
570 ResultSize =
Builder.CreateZExtOrTrunc(ResultSize, ResultType);
575 if (!isa<Constant>(SizeOffsetPair.first) ||
576 !isa<Constant>(SizeOffsetPair.second))
591 "Number of arguments with unsolved size and offset");
593 "Number of load instructions with unsolved size and offset");
595 APInt ObjectSizeOffsetVisitor::align(
APInt Size, uint64_t Alignment) {
605 :
DL(
DL), TLI(TLI), Options(Options) {
618 if (!SeenInsts.insert(
I).second)
625 if (
Argument *A = dyn_cast<Argument>(V))
636 if (CE->getOpcode() == Instruction::IntToPtr)
638 if (CE->getOpcode() == Instruction::GetElementPtr)
642 LLVM_DEBUG(
dbgs() <<
"ObjectSizeOffsetVisitor::compute() unhandled value: "
652 bool ObjectSizeOffsetVisitor::CheckedZextOrTrunc(
APInt &
I) {
656 if (
I.getBitWidth() > IntTyBits &&
I.getActiveBits() > IntTyBits)
658 if (
I.getBitWidth() != IntTyBits)
659 I =
I.zextOrTrunc(IntTyBits);
664 if (!
I.getAllocatedType()->isSized())
667 if (isa<ScalableVectorType>(
I.getAllocatedType()))
671 if (!
I.isArrayAllocation())
672 return std::make_pair(align(
Size,
I.getAlignment()), Zero);
674 Value *ArraySize =
I.getArraySize();
675 if (
const ConstantInt *
C = dyn_cast<ConstantInt>(ArraySize)) {
676 APInt NumElems =
C->getValue();
677 if (!CheckedZextOrTrunc(NumElems))
681 Size =
Size.umul_ov(NumElems, Overflow);
682 return Overflow ? unknown() : std::make_pair(align(
Size,
I.getAlignment()),
689 Type *MemoryTy = A.getPointeeInMemoryValueType();
691 if (!MemoryTy|| !MemoryTy->
isSized()) {
692 ++ObjectVisitorArgument;
697 return std::make_pair(align(
Size, A.getParamAlignment()), Zero);
718 APInt MaxSize =
Arg->getValue().zextOrSelf(IntTyBits);
719 if (
Size.ugt(MaxSize))
722 return std::make_pair(
Size, Zero);
730 if (!CheckedZextOrTrunc(
Size))
735 return std::make_pair(
Size, Zero);
742 if (!CheckedZextOrTrunc(NumElems))
746 Size =
Size.umul_ov(NumElems, Overflow);
747 return Overflow ? unknown() : std::make_pair(
Size, Zero);
769 return std::make_pair(Zero, Zero);
789 return std::make_pair(PtrData.first, PtrData.second +
Offset);
825 if (TrueSide == FalseSide) {
832 if (TrueResult == FalseResult) {
836 if (TrueResult.
slt(FalseResult))
841 if (TrueResult.
sgt(FalseResult))
850 return std::make_pair(Zero, Zero);
854 LLVM_DEBUG(
dbgs() <<
"ObjectSizeOffsetVisitor unknown instruction:" <<
I
882 for (
const Value *SeenVal : SeenVals) {
885 if (CacheIt != CacheMap.
end() &&
anyKnown(CacheIt->second))
886 CacheMap.
erase(CacheIt);
892 I->eraseFromParent();
897 InsertedInstructions.clear();
904 if (Visitor.bothKnown(Const))
912 if (CacheIt != CacheMap.
end())
913 return CacheIt->second;
927 if (!SeenVals.
insert(V).second) {
933 }
else if (isa<Argument>(V) ||
934 (isa<ConstantExpr>(V) &&
935 cast<ConstantExpr>(V)->
getOpcode() == Instruction::IntToPtr) ||
936 isa<GlobalAlias>(V) ||
937 isa<GlobalVariable>(V)) {
942 dbgs() <<
"ObjectSizeOffsetEvaluator::compute() unhandled value: " << *V
953 if (!
I.getAllocatedType()->isSized())
958 Value *ArraySize =
I.getArraySize();
962 return std::make_pair(
Size, Zero);
979 return std::make_pair(FirstArg, Zero);
984 return std::make_pair(
Size, Zero);
1013 return std::make_pair(PtrData.first,
Offset);
1031 CacheMap[&PHI] = std::make_pair(SizePHI, OffsetPHI);
1041 InsertedInstructions.erase(OffsetPHI);
1044 InsertedInstructions.erase(SizePHI);
1056 InsertedInstructions.erase(SizePHI);
1062 InsertedInstructions.erase(OffsetPHI);
1073 if (TrueSide == FalseSide)
1084 LLVM_DEBUG(
dbgs() <<
"ObjectSizeOffsetEvaluator unknown instruction:" <<
I
static SizeOffsetEvalType unknown()
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
std::pair< APInt, APInt > SizeOffsetType
This class represents an incoming formal argument to a Function.
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
static Optional< AllocFnsTy > getAllocationSize(const Value *V, const TargetLibraryInfo *TLI)
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...
SizeOffsetType visitGlobalAlias(GlobalAlias &GA)
void SetInsertPoint(BasicBlock *TheBB)
This specifies that created instructions should be appended to the end of the specified block.
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...
unsigned getIndexTypeSizeInBits(Type *Ty) const
Layout size of the index used in GEP calculation.
A parsed version of the target data layout string in and methods for querying it.
static PointerType * getInt8PtrTy(LLVMContext &C, unsigned AS=0)
Type * getElementType() const
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of this intrinsic.
This class represents a no-op cast from one type to another.
SizeOffsetEvalType compute(Value *V)
SizeOffsetType visitExtractValueInst(ExtractValueInst &I)
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
unsigned getAddressSpace() const
Return the address space of the Pointer type.
SizeOffsetEvalType visitSelectInst(SelectInst &I)
SizeOffsetEvalType visitGEPOperator(GEPOperator &GEP)
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 erase(const KeyT &Val)
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
Type * getIndexType(Type *PtrTy) const
Returns the type of a GEP index.
The instances of the Type class are immutable: once they are created, they are never changed.
bool NullIsUnknownSize
If this is true, null pointers in address space 0 will be treated as though they can't be evaluated.
const_iterator end(StringRef path)
Get end iterator over path.
SizeOffsetEvalType visitCallBase(CallBase &CB)
bool RoundToAlign
Whether to round the result up to the alignment of allocas, byval arguments, and global variables.
unsigned getNumParams() const
Return the number of fixed parameters this function type requires.
SizeOffsetEvalType visitLoadInst(LoadInst &I)
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...
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...
static Value * computeArraySize(const CallInst *CI, const DataLayout &DL, const TargetLibraryInfo *TLI, bool LookThroughSExt=false)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
SizeOffsetEvalType visitIntToPtrInst(IntToPtrInst &)
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
A constant pointer value that points to null.
Value * getMallocArraySize(CallInst *CI, const DataLayout &DL, const TargetLibraryInfo *TLI, bool LookThroughSExt=false)
getMallocArraySize - Returns the array size of a malloc call.
This is the shared class of boolean and integer constants.
Type * getMallocAllocatedType(const CallInst *CI, const TargetLibraryInfo *TLI)
getMallocAllocatedType - Returns the Type allocated by malloc call.
static bool bothKnown(const SizeOffsetType &SizeOffset)
Value * CreateMul(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
static bool hasNoAliasAttr(const Value *V, bool LookThroughBitCast)
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
(vector float) vec_cmpeq(*A, *B) C
SizeOffsetType visitIntToPtrInst(IntToPtrInst &)
ObjectSizeOffsetEvaluator(const DataLayout &DL, const TargetLibraryInfo *TLI, LLVMContext &Context, ObjectSizeOpts EvalOpts={})
@ Exact
Fail to evaluate an unknown condition.
PointerType * getMallocType(const CallInst *CI, const TargetLibraryInfo *TLI)
getMallocType - Returns the PointerType resulting from the malloc call.
static Optional< unsigned > getOpcode(ArrayRef< VPValue * > Values)
Returns the opcode of Values or ~0 if they do not all agree.
const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
bool getLibFunc(StringRef funcName, LibFunc &F) const
Searches for a particular function name.
SizeOffsetType visitGlobalVariable(GlobalVariable &GV)
SizeOffsetType visitAllocaInst(AllocaInst &I)
SizeOffsetEvalType visitExtractElementInst(ExtractElementInst &I)
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.
uint64_t getZExtValue() const
Get zero extended value.
STATISTIC(NumFunctions, "Total number of functions")
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
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.
Evaluate the size and offset of an object pointed to by a Value*.
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....
FunctionType * getFunctionType()
SizeOffsetEvalType visitPHINode(PHINode &PHI)
This struct is a compact representation of a valid (non-zero power of two) alignment.
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.
unsigned getNumIncomingValues() const
Return the number of incoming edges.
static const Function * getCalledFunction(const Value *V, bool LookThroughBitCast, bool &IsNoBuiltin)
bool isIntegerTy() const
True if this is an instance of IntegerType.
An efficient, type-erasing, non-owning reference to a callable.
bool slt(const APInt &RHS) const
Signed less than comparison.
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 ...
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
Value * hasConstantValue() const
If the specified PHI node always merges together the same value, return the value,...
const CallInst * extractCallocCall(const Value *I, const TargetLibraryInfo *TLI)
extractCallocCall - Returns the corresponding CallInst if the instruction is a calloc call.
bool hasDefinitiveInitializer() const
hasDefinitiveInitializer - Whether the global variable has an initializer, and any other instances of...
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,...
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
This is an important class for using LLVM in a threaded context.
SizeOffsetType visitUndefValue(UndefValue &)
Type * getParamType(unsigned i) const
Parameter type accessors.
'undef' values are things that do not have specified contents.
Evaluate the size and offset of an object pointed to by a Value* statically.
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.
Value * CreateSelect(Value *C, Value *True, Value *False, const Twine &Name="", Instruction *MDFrom=nullptr)
SizeOffsetType visitSelectInst(SelectInst &I)
Class to represent pointers.
void visit(Iterator Start, Iterator End)
Value * CreateAdd(Value *LHS, Value *RHS, const Twine &Name="", bool HasNUW=false, bool HasNSW=false)
iterator find(const_arg_type_t< KeyT > Val)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
const CallInst * extractMallocCall(const Value *I, function_ref< const TargetLibraryInfo &(Function &)> GetTLI)
extractMallocCall - Returns the corresponding CallInst if the instruction is a malloc call.
@ Min
Evaluate all branches of an unknown condition.
bool isAlignedAllocLikeFn(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 with a...
This class represents the LLVM 'select' instruction.
bool has(LibFunc F) const
Tests whether a library function is available.
bool isVoidTy() const
Return true if this is 'void'.
unsigned getAlignment() const
FIXME: Remove this function once transition to Align is over.
Provides an 'InsertHelper' that calls a user-provided callback after performing the default insertion...
Class for arbitrary precision integers.
PHINode * CreatePHI(Type *Ty, unsigned NumReservedValues, const Twine &Name="")
SizeOffsetEvalType visitAllocaInst(AllocaInst &I)
Class to represent struct types.
StringRef - Represent a constant reference to a string, i.e.
Type * getType() const
All values are typed, get the type of this value.
const Function * getFunction() const
Return the function this instruction belongs to.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
SizeOffsetType visitGEPOperator(GEPOperator &GEP)
LLVMContext & getContext() const
All values hold a context through their type.
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Various options to control the behavior of getObjectSize.
const Constant * getAliasee() const
static const std::pair< LibFunc, AllocFnsTy > AllocationFnData[]
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
An instruction for reading from memory.
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...
@ Max
Same as Min, except we pick the maximum size of all of the branches.
SizeOffsetType visitLoadInst(LoadInst &I)
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
SizeOffsetType visitInstruction(Instruction &I)
amdgpu Simplify well known AMD library false FunctionCallee Callee
static APInt getNullValue(unsigned numBits)
Get the '0' value.
bool isInterposable() const
Return true if this global's definition can be substituted with an arbitrary definition at link time ...
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'.
A constant value that is initialized with an expression using other constant values.
TargetFolder - Create constants with target dependent folding.
SizeOffsetType visitCallBase(CallBase &CB)
SizeOffsetType visitArgument(Argument &A)
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...
Mode EvalMode
How we want to evaluate this object's size.
static Optional< AllocFnsTy > getAllocationData(const Value *V, AllocType AllocTy, const TargetLibraryInfo *TLI, bool LookThroughBitCast=false)
std::pair< Value *, Value * > SizeOffsetEvalType
Provides information about what library functions are available for the current target.
This class represents a cast from an integer to a pointer.
A wrapper class for inspecting calls to intrinsic functions.
SizeOffsetType compute(Value *V)
SizeOffsetType visitConstantPointerNull(ConstantPointerNull &)
static APInt getSizeWithOverflow(const SizeOffsetType &Data)
DenseMapIterator< const Value *, WeakEvalType, DenseMapInfo< const Value * >, llvm::detail::DenseMapPair< const Value *, WeakEvalType > > iterator
SizeOffsetEvalType visitExtractValueInst(ExtractValueInst &I)
Value * getArgOperand(unsigned i) const
SizeOffsetEvalType visitInstruction(Instruction &I)
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
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,...
Value * CreateZExtOrTrunc(Value *V, Type *DestTy, const Twine &Name="")
Create a ZExt or Trunc from the integer value V to DestTy.
bool bothKnown(SizeOffsetEvalType SizeOffset)
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
bool sgt(const APInt &RHS) const
Signed greater than comparison.
Type * getValueType() const
This class represents a function call, abstracting a target machine's calling convention.
ObjectSizeOffsetVisitor(const DataLayout &DL, const TargetLibraryInfo *TLI, LLVMContext &Context, ObjectSizeOpts Options={})
PointerType * getType() const
Specialize the getType() method to always return an PointerType, which reduces the amount of casting ...
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
an instruction to allocate memory on the stack
bool isLibFreeFunction(const Function *F, const LibFunc TLIFn)
isLibFreeFunction - Returns true if the function is a builtin free()
SizeOffsetType visitExtractElementInst(ExtractElementInst &I)
Type * getReturnType() const
LLVM Value Representation.
bool anyKnown(SizeOffsetEvalType SizeOffset)
iterator_range< user_iterator > users()
const CallInst * isFreeCall(const Value *I, const TargetLibraryInfo *TLI)
isFreeCall - Returns non-null if the value is a call to the builtin free()
SizeOffsetType visitPHINode(PHINode &)
std::pair< unsigned, Optional< unsigned > > getAllocSizeArgs() const
Returns the argument numbers for the allocsize attribute (or pair(0, 0) if not known).
Class to represent function types.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
TypeSize getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...