52#define DEBUG_TYPE "memory-builtins"
59 "object-size-offset-visitor-max-visit-instructions",
60 cl::desc(
"Maximum number of instructions for ObjectSizeOffsetVisitor to "
65 return LF == LibFunc_strndup || LF == LibFunc_dunder_strndup;
69 return LF == LibFunc_strdup || LF == LibFunc_dunder_strdup ||
76 return {
nullptr,
nullptr};
81 return {FirstArg, SecondArg};
86 Attribute Attr = CB->getFnAttr(Attribute::AllocKind);
94 return F->getAttributes().getAllocKind();
110 if (!V->getType()->isPointerTy())
119 if (!V->getType()->isPointerTy())
148 return V->getArgOperandWithAttribute(Attribute::AllocAlign);
160 if (
I.getBitWidth() > IntTyBits &&
I.getActiveBits() > IntTyBits)
162 if (
I.getBitWidth() != IntTyBits)
163 I =
I.zextOrTrunc(IntTyBits);
173 const unsigned IntTyBits =
DL.getIndexTypeSizeInBits(CB->
getType());
199 Size =
Size.umul_ov(NumElems, Overflow);
209 LibFunc LF =
TLI->getLibFunc(*CB);
225 if (
Size.ugt(MaxSize))
279 if (!V->getType()->isIntegerTy())
307 if (!
Data.bothKnown())
319 "Other modes are currently not supported");
337 if (!GV->getValueType()->isSized() || GV->hasExternalWeakLinkage() ||
338 !GV->hasInitializer() || GV->isInterposable())
344 Type *MemoryTy =
A->getPointeeInMemoryValueType();
345 if (!MemoryTy || !MemoryTy->
isSized())
347 return Align(
DL.getTypeAllocSize(MemoryTy),
A->getParamAlign());
351 if (std::optional<TypeSize>
Size = AI->getAllocationSize(
DL))
358 if (std::optional<uint64_t> ZExtSize =
Size->tryZExtValue())
380 "ObjectSize must be a call to llvm.objectsize!");
406 return ConstantInt::get(ResultType,
Size);
415 if (InsertedInstructions)
426 ResultSize = Builder.CreateZExtOrTrunc(ResultSize, ResultType);
427 Value *Ret = Builder.CreateSelect(
428 UseZero, ConstantInt::get(ResultType, 0), ResultSize);
432 Builder.CreateAssumption(Builder.CreateICmpNE(
447 "Number of arguments with unsolved size and offset");
449 "Number of load instructions with unsolved size and offset");
451static std::optional<APInt>
453 std::optional<APInt>
RHS,
464 unsigned RecursionDepth) {
465 constexpr unsigned MaxRecursionDepth = 4;
466 if (RecursionDepth == MaxRecursionDepth)
470 return CI->getValue().sextOrTrunc(
BitWidth);
479 unsigned Count = PN->getNumIncomingValues();
483 PN->getIncomingValue(0), EvalMode,
BitWidth, RecursionDepth + 1);
484 for (
unsigned I = 1; Acc &&
I <
Count; ++
I) {
486 PN->getIncomingValue(
I), EvalMode,
BitWidth, RecursionDepth + 1);
495static std::optional<APInt>
499 return CI->getValue().sextOrTrunc(
BitWidth);
515 if (Options.RoundToAlign && Alignment)
518 return Size.isNegative() ? APInt() :
Size;
525 : DL(DL), TLI(TLI), Options(Options) {
531 InstructionsVisited = 0;
547 unsigned InitialIntTyBits =
DL.getIndexTypeSizeInBits(V->getType());
555 V = V->stripAndAccumulateConstantOffsets(
573 unsigned IdxTyBits =
DL.getIndexTypeSizeInBits(V->getType());
574 auto OffsetRangeAnalysis = [EvalMode, IdxTyBits](
Value &VOffset,
576 if (
auto PossibleOffset =
584 V =
V->stripAndAccumulateConstantOffsets(
586 OffsetRangeAnalysis);
591 IntTyBits = DL.getIndexTypeSizeInBits(
V->getType());
593 OffsetSpan ORT = computeValue(
V);
595 bool IndexTypeSizeChanged = InitialIntTyBits != IntTyBits;
596 if (!IndexTypeSizeChanged &&
Offset.isZero())
602 if (IndexTypeSizeChanged) {
604 !::checkedZextOrTrunc(ORT.
Before, InitialIntTyBits))
606 if (ORT.
knownAfter() && !::checkedZextOrTrunc(ORT.
After, InitialIntTyBits))
632 return ObjectSizeOffsetVisitor::unknown();
643 auto P = SeenInsts.try_emplace(
I, ObjectSizeOffsetVisitor::unknown());
645 return P.first->second;
646 ++InstructionsVisited;
648 return ObjectSizeOffsetVisitor::unknown();
649 OffsetSpan Res =
visit(*
I);
666 LLVM_DEBUG(
dbgs() <<
"ObjectSizeOffsetVisitor::compute() unhandled value: "
668 return ObjectSizeOffsetVisitor::unknown();
671bool ObjectSizeOffsetVisitor::checkedZextOrTrunc(
APInt &
I) {
672 return ::checkedZextOrTrunc(
I, IntTyBits);
676 TypeSize ElemSize =
I.getAllocationBaseSize(DL);
678 return ObjectSizeOffsetVisitor::unknown();
680 return ObjectSizeOffsetVisitor::unknown();
683 if (!
I.isArrayAllocation())
686 Value *ArraySize =
I.getArraySize();
688 ArraySize, Options.EvalMode,
690 APInt NumElems = *PossibleSize;
691 if (!checkedZextOrTrunc(NumElems))
692 return ObjectSizeOffsetVisitor::unknown();
695 Size =
Size.umul_ov(NumElems, Overflow);
697 return Overflow ? ObjectSizeOffsetVisitor::unknown()
700 return ObjectSizeOffsetVisitor::unknown();
704 Type *MemoryTy =
A.getPointeeInMemoryValueType();
706 if (!MemoryTy || !MemoryTy->
isSized()) {
707 ++ObjectVisitorArgument;
708 return ObjectSizeOffsetVisitor::unknown();
711 APInt Size(IntTyBits, DL.getTypeAllocSize(MemoryTy));
716 auto Mapper = [
this](
const Value *V) ->
const Value * {
717 if (!V->getType()->isIntegerTy())
721 V, Options.EvalMode, V->getType()->getScalarSizeInBits()))
722 return ConstantInt::get(V->getType(), *PossibleBound);
729 if (
Size->isNegative())
730 return ObjectSizeOffsetVisitor::unknown();
733 return ObjectSizeOffsetVisitor::unknown();
746 return ObjectSizeOffsetVisitor::unknown();
752 return ObjectSizeOffsetVisitor::unknown();
757 return ObjectSizeOffsetVisitor::unknown();
762 return ObjectSizeOffsetVisitor::unknown();
770 return ObjectSizeOffsetVisitor::unknown();
778 return ObjectSizeOffsetVisitor::unknown();
781OffsetSpan ObjectSizeOffsetVisitor::findLoadOffsetRange(
784 unsigned &ScannedInstCount) {
785 constexpr unsigned MaxInstsToScan = 128;
789 return Where->second;
792 return VisitedBlocks[&BB] = ObjectSizeOffsetVisitor::unknown();
804 if (++ScannedInstCount > MaxInstsToScan)
807 if (!
I.mayWriteToMemory())
812 Options.AA->alias(
SI->getPointerOperand(),
Load.getPointerOperand());
817 if (
SI->getValueOperand()->getType()->isPointerTy())
818 return Known(computeImpl(
SI->getValueOperand()));
836 if (!TLI->has(TLIFn))
840 if (TLIFn != LibFunc_posix_memalign)
859 if (!Checked || !*Checked)
867 APInt CSize =
C->getValue();
875 }
while (From-- != BB.
begin());
879 PredecessorSizeOffsets.
push_back(findLoadOffsetRange(
882 if (!PredecessorSizeOffsets.
back().bothKnown())
886 if (PredecessorSizeOffsets.
empty())
889 return Known(std::accumulate(
890 PredecessorSizeOffsets.
begin() + 1, PredecessorSizeOffsets.
end(),
891 PredecessorSizeOffsets.
front(), [
this](OffsetSpan
LHS, OffsetSpan
RHS) {
892 return combineOffsetRange(LHS, RHS);
899 return ObjectSizeOffsetVisitor::unknown();
903 unsigned ScannedInstCount = 0;
914 if (!LHS.bothKnown() || !RHS.bothKnown())
915 return ObjectSizeOffsetVisitor::unknown();
919 return {LHS.Before.slt(RHS.Before) ? LHS.Before : RHS.Before,
920 LHS.After.slt(RHS.After) ? LHS.After : RHS.After};
922 return {
LHS.Before.sgt(
RHS.Before) ?
LHS.Before :
RHS.Before,
926 return {
LHS.Before.eq(
RHS.Before) ?
LHS.Before : APInt(),
927 LHS.After.eq(
RHS.After) ?
LHS.After : APInt()};
929 return (
LHS ==
RHS) ?
LHS : ObjectSizeOffsetVisitor::unknown();
936 return ObjectSizeOffsetVisitor::unknown();
938 return std::accumulate(IncomingValues.begin() + 1, IncomingValues.end(),
939 computeImpl(*IncomingValues.begin()),
941 return combineOffsetRange(LHS, computeImpl(VRHS));
946 return combineOffsetRange(computeImpl(
I.getTrueValue()),
947 computeImpl(
I.getFalseValue()));
955 LLVM_DEBUG(
dbgs() <<
"ObjectSizeOffsetVisitor unknown instruction:" <<
I
957 return ObjectSizeOffsetVisitor::unknown();
966 : DL(M.getDataLayout()), TLI(TLI), Context(M.
getContext()),
978 Zero = ConstantInt::get(IntTy, 0);
982 if (!Result.bothKnown()) {
986 for (
const Value *SeenVal : SeenVals) {
989 if (CacheIt != CacheMap.end() && CacheIt->second.anyKnown())
990 CacheMap.erase(CacheIt);
996 I->eraseFromParent();
1001 InsertedInstructions.clear();
1014 if (Const.bothKnown())
1016 ConstantInt::get(
Context, Const.Offset));
1018 V = V->stripPointerCasts();
1022 if (CacheIt != CacheMap.
end())
1023 return CacheIt->second;
1029 Builder.SetInsertPoint(
I);
1037 if (!SeenVals.
insert(V).second) {
1051 dbgs() <<
"ObjectSizeOffsetEvaluator::compute() unhandled value: " << *
V
1057 CacheMap[
V] = SizeOffsetWeakTrackingVH(Result);
1063 assert(
I.isArrayAllocation() ||
I.isScalable());
1067 Type *IndexTy = DL.getIndexType(
I.getContext(), DL.getAllocaAddrSpace());
1068 assert(IndexTy == Zero->getType() &&
1069 "Expected zero constant to have pointer index type");
1071 Value *
Size = Builder.CreateAllocationSize(IndexTy, &
I);
1080 FirstArg = Builder.CreateZExtOrTrunc(FirstArg, IntTy);
1084 SecondArg = Builder.CreateZExtOrTrunc(SecondArg, IntTy);
1085 Value *
Size = Builder.CreateMul(FirstArg, SecondArg);
1120 PHINode *SizePHI = Builder.CreatePHI(IntTy,
PHI.getNumIncomingValues());
1121 PHINode *OffsetPHI = Builder.CreatePHI(IntTy,
PHI.getNumIncomingValues());
1127 for (
unsigned i = 0, e =
PHI.getNumIncomingValues(); i != e; ++i) {
1135 InsertedInstructions.erase(OffsetPHI);
1138 InsertedInstructions.erase(SizePHI);
1150 InsertedInstructions.erase(SizePHI);
1156 InsertedInstructions.erase(OffsetPHI);
1167 if (TrueSide == FalseSide)
1171 Builder.CreateSelect(
I.getCondition(), TrueSide.
Size, FalseSide.
Size,
"",
1174 Builder.CreateSelect(
I.getCondition(), TrueSide.
Offset, FalseSide.
Offset,
1180 LLVM_DEBUG(
dbgs() <<
"ObjectSizeOffsetEvaluator unknown instruction:" <<
I
const TargetLowering & TLI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file implements a class to represent arbitrary precision integral constant values and operations...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file contains the simple types necessary to represent the attributes associated with functions a...
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
SmallPtrSet< const BasicBlock *, 8 > VisitedBlocks
static bool isStrDupLike(LibFunc LF)
static std::optional< APInt > combinePossibleConstantValues(std::optional< APInt > LHS, std::optional< APInt > RHS, ObjectSizeOpts::Mode EvalMode)
static AllocFnKind getAllocFnKind(const Value *V)
static std::optional< APInt > aggregatePossibleConstantValuesImpl(const Value *V, ObjectSizeOpts::Mode EvalMode, unsigned BitWidth, unsigned RecursionDepth)
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....
static bool checkFnAllocKind(const Value *V, AllocFnKind Wanted)
static bool isStrNDupLike(LibFunc LF)
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 std::pair< Value *, Value * > getAllocSizePair(const CallBase *CB)
static APInt getSizeWithOverflow(const SizeOffsetAPInt &Data)
static std::optional< APInt > aggregatePossibleConstantValues(const Value *V, ObjectSizeOpts::Mode EvalMode, unsigned BitWidth)
This file contains the declarations for profiling metadata utility functions.
Func getContext().diagnose(DiagnosticInfoUnsupported(Func
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
Class for arbitrary precision integers.
LLVM_ABI APInt zext(unsigned width) const
Zero extend to a new width.
uint64_t getZExtValue() const
Get zero extended value.
unsigned getBitWidth() const
Return the number of bits in the APInt.
bool isNegative() const
Determine sign of this APInt.
LLVM_ABI APInt sadd_ov(const APInt &RHS, bool &Overflow) const
static APInt getZero(unsigned numBits)
Get the '0' value for the specified bit-width.
LLVM_ABI APInt ssub_ov(const APInt &RHS, bool &Overflow) const
@ NoAlias
The two locations do not alias at all.
@ MustAlias
The two locations precisely alias each other.
an instruction to allocate memory on the stack
This class represents an incoming formal argument to a Function.
Functions, function parameters, and return types can have attributes to indicate how they should be t...
LLVM_ABI uint64_t getValueAsInt() const
Return the attribute's value as an integer.
LLVM_ABI std::pair< unsigned, std::optional< unsigned > > getAllocSizeArgs() const
Returns the argument numbers for the allocsize attribute.
LLVM_ABI StringRef getValueAsString() const
Return the attribute's value as a string.
bool isValid() const
Return true if the attribute is any kind of attribute.
LLVM Basic Block Representation.
iterator begin()
Instruction iterator methods.
LLVM_ABI const_iterator getFirstInsertionPt() const
Returns an iterator to the first instruction in this block that is suitable for inserting a non-PHI i...
InstListType::iterator iterator
Instruction iterators...
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
Attribute getFnAttr(StringRef Kind) const
Get the attribute of a given kind for the function.
Value * getArgOperand(unsigned i) const
LLVM_ABI Value * getArgOperandWithAttribute(Attribute::AttrKind Kind) const
If one of the arguments has the specified attribute, returns its operand value.
This is the shared class of boolean and integer constants.
const APInt & getValue() const
Return the constant as an APInt value reference.
A constant pointer value that points to null.
PointerType * getPointerType() const
Return the scalar pointer type for this null value.
This is an important base class in LLVM.
static LLVM_ABI Constant * getAllOnesValue(Type *Ty)
static LLVM_ABI Constant * getNullValue(Type *Ty)
Constructor to create a '0' constant of arbitrary type.
A parsed version of the target data layout string in and methods for querying it.
iterator find(const_arg_type_t< KeyT > Val)
DenseMapIterator< KeyT, ValueT, KeyInfoT, BucketT > iterator
const Constant * getAliasee() const
bool hasExternalWeakLinkage() const
Type * getValueType() const
LLVM_ABI bool isInterposable(bool CheckNoIPA=true) const
Return true if this global's definition can be substituted with an arbitrary definition at link time ...
bool hasInitializer() const
Definitions have initializers, declarations don't.
MaybeAlign getAlign() const
Returns the alignment of the given variable.
LLVM_ABI uint64_t getGlobalSize(const DataLayout &DL) const
Get the size of this global variable in bytes.
Provides an 'InsertHelper' that calls a user-provided callback after performing the default insertion...
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
void visit(Iterator Start, Iterator End)
LLVM_ABI const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
LLVM_ABI InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
LLVM_ABI const DataLayout & getDataLayout() const
Get the data layout of the module this instruction belongs to.
This class represents a cast from an integer to a pointer.
A wrapper class for inspecting calls to intrinsic functions.
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of this intrinsic.
This is an important class for using LLVM in a threaded context.
An instruction for reading from memory.
A Module instance is used to store all the information related to an LLVM module.
Evaluate the size and offset of an object pointed to by a Value*.
LLVM_ABI SizeOffsetValue visitExtractValueInst(ExtractValueInst &I)
LLVM_ABI SizeOffsetValue visitExtractElementInst(ExtractElementInst &I)
LLVM_ABI SizeOffsetValue compute(Value *V)
LLVM_ABI SizeOffsetValue visitInstruction(Instruction &I)
LLVM_ABI SizeOffsetValue visitLoadInst(LoadInst &I)
LLVM_ABI SizeOffsetValue visitGEPOperator(GEPOperator &GEP)
LLVM_ABI SizeOffsetValue visitIntToPtrInst(IntToPtrInst &)
LLVM_ABI SizeOffsetValue visitPHINode(PHINode &PHI)
LLVM_ABI SizeOffsetValue visitCallBase(CallBase &CB)
LLVM_ABI ObjectSizeOffsetEvaluator(Module &M, const TargetLibraryInfo *TLI, ObjectSizeOpts EvalOpts={})
LLVM_ABI SizeOffsetValue visitSelectInst(SelectInst &I)
LLVM_ABI SizeOffsetValue visitAllocaInst(AllocaInst &I)
static SizeOffsetValue unknown()
Evaluate the size and offset of an object pointed to by a Value* statically.
LLVM_ABI OffsetSpan visitSelectInst(SelectInst &I)
LLVM_ABI OffsetSpan visitExtractValueInst(ExtractValueInst &I)
LLVM_ABI OffsetSpan visitConstantPointerNull(ConstantPointerNull &)
LLVM_ABI OffsetSpan visitExtractElementInst(ExtractElementInst &I)
LLVM_ABI OffsetSpan visitGlobalVariable(GlobalVariable &GV)
LLVM_ABI OffsetSpan visitCallBase(CallBase &CB)
LLVM_ABI OffsetSpan visitIntToPtrInst(IntToPtrInst &)
LLVM_ABI OffsetSpan visitAllocaInst(AllocaInst &I)
LLVM_ABI ObjectSizeOffsetVisitor(const DataLayout &DL, const TargetLibraryInfo *TLI, LLVMContext &Context, ObjectSizeOpts Options={})
LLVM_ABI OffsetSpan visitLoadInst(LoadInst &I)
LLVM_ABI OffsetSpan visitPHINode(PHINode &)
LLVM_ABI OffsetSpan visitGlobalAlias(GlobalAlias &GA)
LLVM_ABI OffsetSpan visitInstruction(Instruction &I)
LLVM_ABI SizeOffsetAPInt compute(Value *V)
LLVM_ABI OffsetSpan visitUndefValue(UndefValue &)
LLVM_ABI OffsetSpan visitArgument(Argument &A)
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
op_range incoming_values()
LLVM_ABI Value * hasConstantValue() const
If the specified PHI node always merges together the same value, return the value,...
unsigned getNumIncomingValues() const
Return the number of incoming edges.
unsigned getAddressSpace() const
Return the address space of the Pointer type.
static LLVM_ABI PoisonValue * get(Type *T)
Static factory methods - Return an 'poison' object of the specified type.
This class represents the LLVM 'select' instruction.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
LLVM_NO_SANITIZE_CFI_UNRELATED_CAST iterator begin()
TargetFolder - Create constants with target dependent folding.
Provides information about what library functions are available for the current target.
static constexpr TypeSize getFixed(ScalarTy ExactSize)
static constexpr TypeSize getZero()
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM_ABI unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
bool isSized() const
Return true if it makes sense to take the size of this type.
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
bool isIntegerTy() const
True if this is an instance of IntegerType.
bool isVoidTy() const
Return true if this is 'void'.
'undef' values are things that do not have specified contents.
static LLVM_ABI UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
Value * getOperand(unsigned i) const
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
LLVM_ABI void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
LLVMContext & getContext() const
All values hold a context through their type.
constexpr bool isScalable() const
Returns whether the quantity is scaled by a runtime quantity (vscale).
constexpr ScalarTy getKnownMinValue() const
Returns the minimum value this quantity can represent.
An efficient, type-erasing, non-owning reference to a callable.
const ParentTy * getParent() const
self_iterator getIterator()
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Abstract Attribute helper functions.
initializer< Ty > init(const Ty &Val)
friend class Instruction
Iterator for Instructions in a `BasicBlock.
unsigned getOpcode(const VPValue *V)
Return the instruction opcode for the recipe defining V or 0 for unsupported recipes and VPValues not...
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI Value * getAllocAlignment(const CallBase *V)
Gets the alignment argument for an aligned_alloc-like function based on the allocalign attribute.
LLVM_ABI cl::opt< bool > ProfcheckDisableMetadataFixes
LLVM_ABI std::optional< StringRef > getAllocationFamily(const Value *I)
If a function is part of an allocation family (e.g.
@ Known
Known to have no common set bits.
@ Unknown
Not known to have no common set bits.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
@ Load
The value being inserted comes from a load (InsertElement only).
LLVM_ABI 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.
constexpr bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
LLVM_ABI Value * getReallocatedOperand(const CallBase *CB)
If this is a call to a realloc function, return the reallocated operand.
LLVM_ABI std::optional< TypeSize > getBaseObjectSize(const Value *Ptr, const DataLayout &DL, const TargetLibraryInfo *TLI, ObjectSizeOpts Opts={})
Like getObjectSize(), but only returns the size of base objects (like allocas, global variables and a...
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
LLVM_ABI 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.
LLVM_ABI Value * emitGEPOffset(IRBuilderBase *Builder, const DataLayout &DL, User *GEP, bool NoAssumptions=false)
Given a getelementptr instruction/constantexpr, emit the code necessary to compute the offset from th...
LLVM_ABI bool isAllocLikeFn(const Value *V)
Tests if a value is a call or invoke to a library function that allocates memory (either malloc,...
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
constexpr uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
LLVM_ABI 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'.
LLVM_ABI Constant * getInitialValueOfAllocation(const Value *V, Type *Ty)
If this is a call to an allocation function that initializes memory to a fixed value,...
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ABI bool isFreeLikeFn(const Function *F)
Returns true if the function has allockind(free).
LLVM_ABI bool isReallocLikeFn(const Function *F)
Tests if a function is a call or invoke to a library function that reallocates memory (e....
LLVM_ABI bool isAllocationFn(const Value *V)
Tests if a value is a call or invoke to a library function that allocates or reallocates memory (eith...
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
constexpr unsigned BitWidth
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
auto predecessors(const MachineBasicBlock *BB)
LLVM_ABI std::optional< APInt > getAllocSize(const CallBase *CB, const TargetLibraryInfo *TLI, function_ref< const Value *(const Value *)> Mapper=[](const Value *V) { return V;})
Return the size of the requested allocation.
LLVM_ABI std::optional< bool > isImpliedByDomCondition(const Value *Cond, const Instruction *ContextI, const DataLayout &DL)
Return the boolean condition value in the context of the given instruction if it is known based on do...
LLVM_ABI Constant * getElidedFreeResult(const Value *V)
If this is a call to a free function that returns a value, return the value that will be returned whe...
LLVM_ABI Value * getFreedOperand(const CallBase *CB)
If this if a call to a free function, return the freed operand.
LLVM_ABI bool isRemovableAlloc(const CallBase *V)
Return true if this is a call to an allocation function that does not have side effects that we are r...
This struct is a compact representation of a valid (non-zero power of two) alignment.
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Various options to control the behavior of getObjectSize.
bool NullIsUnknownSize
If this is true, null pointers in address space 0 will be treated as though they can't be evaluated.
Mode EvalMode
How we want to evaluate this object's size.
AAResults * AA
If set, used for more accurate evaluation.
bool RoundToAlign
Whether to round the result up to the alignment of allocas, byval arguments, and global variables.
Mode
Controls how we handle conditional statements with unknown conditions.
@ ExactUnderlyingSizeAndOffset
All branches must be known and have the same underlying size and offset to be merged.
@ Max
Same as Min, except we pick the maximum size of all of the branches.
@ Min
Evaluate all branches of an unknown condition.
@ ExactSizeFromOffset
All branches must be known and have the same size, starting from the offset, to be merged.
OffsetSpan - Used internally by ObjectSizeOffsetVisitor.
APInt After
Number of allocated bytes before this point.
SizeOffsetAPInt - Used by ObjectSizeOffsetVisitor, which works with APInts.
SizeOffsetWeakTrackingVH - Used by ObjectSizeOffsetEvaluator in a DenseMap.