51#define DEBUG_TYPE "memory-builtins"
54 "object-size-offset-visitor-max-visit-instructions",
55 cl::desc(
"Maximum number of instructions for ObjectSizeOffsetVisitor to "
87 return "_ZnwmSt11align_val_t";
91 return "_ZnamSt11align_val_t";
93 return "??2@YAPAXI@Z";
95 return "??_U@YAPAXI@Z";
99 return "__kmpc_alloc_shared";
168 if (CB->isNoBuiltin())
171 return CB->getCalledFunction();
176static std::optional<AllocFnsTy>
181 if (!Callee->getReturnType()->isPointerTy())
186 if (!TLI || !TLI->
getLibFunc(*Callee, TLIFn) || !TLI->
has(TLIFn))
191 return P.first == TLIFn;
206 if (FTy->getReturnType()->isPointerTy() &&
207 FTy->getNumParams() == FnData->
NumParams &&
209 (FTy->getParamType(FstParam)->isIntegerTy(32) ||
210 FTy->getParamType(FstParam)->isIntegerTy(64))) &&
212 FTy->getParamType(SndParam)->isIntegerTy(32) ||
213 FTy->getParamType(SndParam)->isIntegerTy(64)))
218static std::optional<AllocFnsTy>
226static std::optional<AllocFnsTy>
231 Callee, AllocTy, &GetTLI(
const_cast<Function &
>(*Callee)));
235static std::optional<AllocFnsTy>
240 if (std::optional<AllocFnsTy>
Data =
249 std::pair<unsigned, std::optional<unsigned>> Args = Attr.
getAllocSizeArgs();
256 Result.FstParam = Args.first;
257 Result.SndParam = Args.second.value_or(-1);
259 Result.AlignParam = -1;
265 Attribute Attr = CB->getFnAttr(Attribute::AllocKind);
273 return F->getAttributes().getAllocKind();
344 if (FnData && FnData->AlignParam >= 0) {
345 return V->getOperand(FnData->AlignParam);
347 return V->getArgOperandWithAttribute(Attribute::AllocAlign);
359 if (
I.getBitWidth() > IntTyBits &&
I.getActiveBits() > IntTyBits)
361 if (
I.getBitWidth() != IntTyBits)
362 I =
I.zextOrTrunc(IntTyBits);
378 const unsigned IntTyBits =
DL.getIndexTypeSizeInBits(CB->
getType());
387 if (FnData->FstParam > 0) {
394 if (
Size.ugt(MaxSize))
410 if (FnData->SndParam < 0)
422 Size =
Size.umul_ov(NumElems, Overflow);
492 const LibFunc TLIFn) {
495 return P.first == TLIFn;
502std::optional<StringRef>
506 if (TLI && TLI->
getLibFunc(*Callee, TLIFn) && TLI->
has(TLIFn)) {
508 const auto AllocData =
551 if (TLI && TLI->
getLibFunc(*Callee, TLIFn) && TLI->
has(TLIFn) &&
585 if (!
Data.bothKnown())
597 "Other modes are currently not supported");
615 if (!GV->getValueType()->isSized() || GV->hasExternalWeakLinkage() ||
616 !GV->hasInitializer() || GV->isInterposable())
618 return Align(
DL.getTypeAllocSize(GV->getValueType()), GV->getAlign());
622 Type *MemoryTy =
A->getPointeeInMemoryValueType();
623 if (!MemoryTy || !MemoryTy->
isSized())
625 return Align(
DL.getTypeAllocSize(MemoryTy),
A->getParamAlign());
629 if (std::optional<TypeSize>
Size = AI->getAllocationSize(
DL))
636 if (std::optional<uint64_t> ZExtSize =
Size->tryZExtValue())
658 "ObjectSize must be a call to llvm.objectsize!");
683 return ConstantInt::get(ResultType,
Size);
692 if (InsertedInstructions)
704 ResultSize = Builder.CreateZExtOrTrunc(ResultSize, ResultType);
705 Value *Ret = Builder.CreateSelect(
706 UseZero, ConstantInt::get(ResultType, 0), ResultSize);
710 Builder.CreateAssumption(Builder.CreateICmpNE(
725 "Number of arguments with unsolved size and offset");
727 "Number of load instructions with unsolved size and offset");
729static std::optional<APInt>
731 std::optional<APInt>
RHS,
743 unsigned recursionDepth) {
744 constexpr unsigned maxRecursionDepth = 4;
745 if (recursionDepth == maxRecursionDepth)
749 return CI->getValue().sextOrTrunc(
BitWidth);
758 unsigned Count = PN->getNumIncomingValues();
762 PN->getIncomingValue(0), EvalMode,
BitWidth, recursionDepth + 1);
763 for (
unsigned I = 1; Acc &&
I <
Count; ++
I) {
765 PN->getIncomingValue(
I), EvalMode,
BitWidth, recursionDepth + 1);
774static std::optional<APInt>
778 return CI->getValue().sextOrTrunc(
BitWidth);
794 if (Options.RoundToAlign && Alignment)
797 return Size.isNegative() ? APInt() :
Size;
804 : DL(DL), TLI(TLI), Options(Options) {
810 InstructionsVisited = 0;
826 unsigned InitialIntTyBits =
DL.getIndexTypeSizeInBits(V->getType());
834 V = V->stripAndAccumulateConstantOffsets(
852 unsigned IdxTyBits =
DL.getIndexTypeSizeInBits(V->getType());
853 auto OffsetRangeAnalysis = [EvalMode, IdxTyBits](
Value &VOffset,
855 if (
auto PossibleOffset =
863 V =
V->stripAndAccumulateConstantOffsets(
865 OffsetRangeAnalysis);
870 IntTyBits = DL.getIndexTypeSizeInBits(
V->getType());
872 OffsetSpan ORT = computeValue(V);
874 bool IndexTypeSizeChanged = InitialIntTyBits != IntTyBits;
875 if (!IndexTypeSizeChanged &&
Offset.isZero())
881 if (IndexTypeSizeChanged) {
883 !::CheckedZextOrTrunc(ORT.
Before, InitialIntTyBits))
885 if (ORT.
knownAfter() && !::CheckedZextOrTrunc(ORT.
After, InitialIntTyBits))
911 return ObjectSizeOffsetVisitor::unknown();
922 auto P = SeenInsts.try_emplace(
I, ObjectSizeOffsetVisitor::unknown());
924 return P.first->second;
925 ++InstructionsVisited;
927 return ObjectSizeOffsetVisitor::unknown();
928 OffsetSpan Res =
visit(*
I);
945 LLVM_DEBUG(
dbgs() <<
"ObjectSizeOffsetVisitor::compute() unhandled value: "
947 return ObjectSizeOffsetVisitor::unknown();
950bool ObjectSizeOffsetVisitor::CheckedZextOrTrunc(
APInt &
I) {
951 return ::CheckedZextOrTrunc(
I, IntTyBits);
955 TypeSize ElemSize = DL.getTypeAllocSize(
I.getAllocatedType());
957 return ObjectSizeOffsetVisitor::unknown();
959 return ObjectSizeOffsetVisitor::unknown();
962 if (!
I.isArrayAllocation())
965 Value *ArraySize =
I.getArraySize();
967 ArraySize, Options.EvalMode,
969 APInt NumElems = *PossibleSize;
970 if (!CheckedZextOrTrunc(NumElems))
971 return ObjectSizeOffsetVisitor::unknown();
974 Size =
Size.umul_ov(NumElems, Overflow);
976 return Overflow ? ObjectSizeOffsetVisitor::unknown()
979 return ObjectSizeOffsetVisitor::unknown();
983 Type *MemoryTy =
A.getPointeeInMemoryValueType();
985 if (!MemoryTy|| !MemoryTy->
isSized()) {
986 ++ObjectVisitorArgument;
987 return ObjectSizeOffsetVisitor::unknown();
990 APInt Size(IntTyBits, DL.getTypeAllocSize(MemoryTy));
995 auto Mapper = [
this](
const Value *V) ->
const Value * {
996 if (!V->getType()->isIntegerTy())
1000 V, Options.EvalMode, V->getType()->getScalarSizeInBits()))
1001 return ConstantInt::get(V->getType(), *PossibleBound);
1008 if (
Size->isNegative())
1009 return ObjectSizeOffsetVisitor::unknown();
1012 return ObjectSizeOffsetVisitor::unknown();
1025 return ObjectSizeOffsetVisitor::unknown();
1031 return ObjectSizeOffsetVisitor::unknown();
1036 return ObjectSizeOffsetVisitor::unknown();
1041 return ObjectSizeOffsetVisitor::unknown();
1049 return ObjectSizeOffsetVisitor::unknown();
1057 return ObjectSizeOffsetVisitor::unknown();
1060OffsetSpan ObjectSizeOffsetVisitor::findLoadOffsetRange(
1063 unsigned &ScannedInstCount) {
1064 constexpr unsigned MaxInstsToScan = 128;
1068 return Where->second;
1071 return VisitedBlocks[&BB] = ObjectSizeOffsetVisitor::unknown();
1080 if (
I.isDebugOrPseudoInst())
1083 if (++ScannedInstCount > MaxInstsToScan)
1086 if (!
I.mayWriteToMemory())
1091 Options.AA->alias(
SI->getPointerOperand(),
Load.getPointerOperand());
1096 if (
SI->getValueOperand()->getType()->isPointerTy())
1097 return Known(computeImpl(
SI->getValueOperand()));
1117 if (TLIFn != LibFunc_posix_memalign)
1136 if (!Checked || !*Checked)
1144 APInt CSize =
C->getValue();
1148 return Known({APInt(CSize.
getBitWidth(), 0), CSize});
1152 }
while (From-- != BB.
begin());
1156 PredecessorSizeOffsets.
push_back(findLoadOffsetRange(
1159 if (!PredecessorSizeOffsets.
back().bothKnown())
1163 if (PredecessorSizeOffsets.
empty())
1166 return Known(std::accumulate(
1167 PredecessorSizeOffsets.
begin() + 1, PredecessorSizeOffsets.
end(),
1168 PredecessorSizeOffsets.
front(), [
this](OffsetSpan
LHS, OffsetSpan
RHS) {
1169 return combineOffsetRange(LHS, RHS);
1175 ++ObjectVisitorLoad;
1176 return ObjectSizeOffsetVisitor::unknown();
1180 unsigned ScannedInstCount = 0;
1185 ++ObjectVisitorLoad;
1191 if (!LHS.bothKnown() || !RHS.bothKnown())
1192 return ObjectSizeOffsetVisitor::unknown();
1196 return {LHS.Before.slt(RHS.Before) ? LHS.Before : RHS.Before,
1197 LHS.After.slt(RHS.After) ? LHS.After : RHS.After};
1199 return {
LHS.Before.sgt(
RHS.Before) ?
LHS.Before :
RHS.Before,
1203 return {
LHS.Before.eq(
RHS.Before) ?
LHS.Before : APInt(),
1204 LHS.After.eq(
RHS.After) ?
LHS.After : APInt()};
1206 return (
LHS ==
RHS) ?
LHS : ObjectSizeOffsetVisitor::unknown();
1213 return ObjectSizeOffsetVisitor::unknown();
1215 return std::accumulate(IncomingValues.begin() + 1, IncomingValues.end(),
1216 computeImpl(*IncomingValues.begin()),
1218 return combineOffsetRange(LHS, computeImpl(VRHS));
1223 return combineOffsetRange(computeImpl(
I.getTrueValue()),
1224 computeImpl(
I.getFalseValue()));
1232 LLVM_DEBUG(
dbgs() <<
"ObjectSizeOffsetVisitor unknown instruction:" <<
I
1234 return ObjectSizeOffsetVisitor::unknown();
1244 : DL(DL), TLI(TLI), Context(Context),
1248 EvalOpts(EvalOpts) {
1256 Zero = ConstantInt::get(IntTy, 0);
1260 if (!Result.bothKnown()) {
1264 for (
const Value *SeenVal : SeenVals) {
1267 if (CacheIt != CacheMap.end() && CacheIt->second.anyKnown())
1268 CacheMap.erase(CacheIt);
1274 I->eraseFromParent();
1279 InsertedInstructions.clear();
1292 if (Const.bothKnown())
1294 ConstantInt::get(Context, Const.Offset));
1296 V = V->stripPointerCasts();
1300 if (CacheIt != CacheMap.
end())
1301 return CacheIt->second;
1307 Builder.SetInsertPoint(
I);
1315 if (!SeenVals.
insert(V).second) {
1330 dbgs() <<
"ObjectSizeOffsetEvaluator::compute() unhandled value: " << *V
1336 CacheMap[
V] = SizeOffsetWeakTrackingVH(Result);
1341 if (!
I.getAllocatedType()->isSized())
1345 assert(
I.isArrayAllocation() ||
I.getAllocatedType()->isScalableTy());
1349 Value *ArraySize = Builder.CreateZExtOrTrunc(
1351 DL.getIndexType(
I.getContext(), DL.getAllocaAddrSpace()));
1353 "Expected zero constant to have pointer index type");
1356 ArraySize->
getType(), DL.getTypeAllocSize(
I.getAllocatedType()));
1357 Size = Builder.CreateMul(
Size, ArraySize);
1373 FirstArg = Builder.CreateZExtOrTrunc(FirstArg, IntTy);
1374 if (FnData->SndParam < 0)
1378 SecondArg = Builder.CreateZExtOrTrunc(SecondArg, IntTy);
1379 Value *
Size = Builder.CreateMul(FirstArg, SecondArg);
1414 PHINode *SizePHI = Builder.CreatePHI(IntTy,
PHI.getNumIncomingValues());
1415 PHINode *OffsetPHI = Builder.CreatePHI(IntTy,
PHI.getNumIncomingValues());
1421 for (
unsigned i = 0, e =
PHI.getNumIncomingValues(); i != e; ++i) {
1429 InsertedInstructions.erase(OffsetPHI);
1432 InsertedInstructions.erase(SizePHI);
1444 InsertedInstructions.erase(SizePHI);
1450 InsertedInstructions.erase(OffsetPHI);
1461 if (TrueSide == FalseSide)
1465 Builder.CreateSelect(
I.getCondition(), TrueSide.
Size, FalseSide.
Size);
1467 Builder.CreateSelect(
I.getCondition(), TrueSide.
Offset, FalseSide.
Offset);
1472 LLVM_DEBUG(
dbgs() <<
"ObjectSizeOffsetEvaluator unknown instruction:" <<
I
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< 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 std::optional< APInt > combinePossibleConstantValues(std::optional< APInt > LHS, std::optional< APInt > RHS, ObjectSizeOpts::Mode EvalMode)
static AllocFnKind getAllocFnKind(const Value *V)
static std::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.
static std::optional< AllocFnsTy > getAllocationData(const Value *V, AllocType AllocTy, const TargetLibraryInfo *TLI)
std::optional< FreeFnsTy > getFreeFunctionDataForFunction(const Function *Callee, const LibFunc TLIFn)
static bool checkFnAllocKind(const Value *V, AllocFnKind Wanted)
StringRef mangledNameForMallocFamily(const MallocFamily &Family)
static std::optional< AllocFnsTy > getAllocationSize(const CallBase *CB, const TargetLibraryInfo *TLI)
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 std::optional< APInt > aggregatePossibleConstantValuesImpl(const Value *V, ObjectSizeOpts::Mode EvalMode, unsigned BitWidth, unsigned recursionDepth)
static const std::pair< LibFunc, FreeFnsTy > FreeFnData[]
static const Function * getCalledFunction(const Value *V)
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 APInt getSizeWithOverflow(const SizeOffsetAPInt &Data)
static std::optional< APInt > aggregatePossibleConstantValues(const Value *V, ObjectSizeOpts::Mode EvalMode, unsigned BitWidth)
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
static std::optional< unsigned > getOpcode(ArrayRef< VPValue * > Values)
Returns the opcode of Values or ~0 if they do not all agree.
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.
unsigned arg_size() const
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 * getType() const
Specialize the getType() method to always return an PointerType, which reduces the amount of casting ...
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
Class to represent function types.
unsigned getNumParams() const
Return the number of fixed parameters this function type requires.
Type * getParamType(unsigned i) const
Parameter type accessors.
Type * getReturnType() const
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
const Constant * getAliasee() const
bool hasExternalWeakLinkage() const
LLVM_ABI bool isInterposable() const
Return true if this global's definition can be substituted with an arbitrary definition at link time ...
Type * getValueType() const
bool hasInitializer() const
Definitions have initializers, declarations don't.
MaybeAlign getAlign() const
Returns the alignment of the given variable.
void SetInsertPoint(BasicBlock *TheBB)
This specifies that created instructions should be appended to the end of the specified block.
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 InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
LLVM_ABI const Function * getFunction() const
Return the function this instruction belongs to.
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.
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 ObjectSizeOffsetEvaluator(const DataLayout &DL, const TargetLibraryInfo *TLI, LLVMContext &Context, ObjectSizeOpts EvalOpts={})
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 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)
StringRef - Represent a constant reference to a string, i.e.
TargetFolder - Create constants with target dependent folding.
Provides information about what library functions are available for the current target.
bool has(LibFunc F) const
Tests whether a library function is available.
bool getLibFunc(StringRef funcName, LibFunc &F) const
Searches for a particular function name.
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.
bool isPointerTy() const
True if this is an instance of PointerType.
LLVM_ABI unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
LLVM_ABI unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type.
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.
LLVM_ABI 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
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Abstract Attribute helper functions.
@ C
The default llvm calling convention, compatible with C.
initializer< Ty > init(const Ty &Val)
friend class Instruction
Iterator for Instructions in a `BasicBlock.
This is an optimization pass for GlobalISel generic memory operations.
FunctionAddr VTableAddr Value
LLVM_ABI Constant * getInitialValueOfAllocation(const Value *V, const TargetLibraryInfo *TLI, Type *Ty)
If this is a call to an allocation function that initializes memory to a fixed value,...
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI bool isRemovableAlloc(const CallBase *V, const TargetLibraryInfo *TLI)
Return true if this is a call to an allocation function that does not have side effects that we are r...
LLVM_ABI std::optional< StringRef > getAllocationFamily(const Value *I, const TargetLibraryInfo *TLI)
If a function is part of an allocation family (e.g.
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.
LLVM_ABI Value * getAllocAlignment(const CallBase *V, const TargetLibraryInfo *TLI)
Gets the alignment argument for an aligned_alloc-like function, using either built-in knowledge based...
constexpr bool isUIntN(unsigned N, uint64_t x)
Checks if an unsigned integer fits into the given (dynamic) bit width.
LLVM_ABI bool isLibFreeFunction(const Function *F, const LibFunc TLIFn)
isLibFreeFunction - Returns true if the function is a builtin free()
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...
LLVM_ABI bool isAllocLikeFn(const Value *V, const TargetLibraryInfo *TLI)
Tests if a value is a call or invoke to a library function that allocates memory (either malloc,...
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 raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
FunctionAddr VTableAddr Count
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 bool isMallocOrCallocLikeFn(const Value *V, const TargetLibraryInfo *TLI)
Tests if a value is a call or invoke to a library function that allocates memory similar to malloc or...
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 isReallocLikeFn(const Function *F)
Tests if a function is a call or invoke to a library function that reallocates memory (e....
FunctionAddr VTableAddr uintptr_t uintptr_t Data
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
LLVM_ABI Value * getFreedOperand(const CallBase *CB, const TargetLibraryInfo *TLI)
If this if a call to a free function, return the freed operand.
constexpr unsigned BitWidth
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
auto predecessors(const MachineBasicBlock *BB)
LLVM_ABI bool isAllocationFn(const Value *V, const TargetLibraryInfo *TLI)
Tests if a value is a call or invoke to a library function that allocates or reallocates memory (eith...
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 bool isNewLikeFn(const Value *V, const TargetLibraryInfo *TLI)
Tests if a value is a call or invoke to a library function that allocates memory via new.
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.