Go to the documentation of this file.
14 #ifndef LLVM_ANALYSIS_MEMORYBUILTINS_H
15 #define LLVM_ANALYSIS_MEMORYBUILTINS_H
34 class ConstantPointerNull;
36 class ExtractElementInst;
37 class ExtractValueInst;
58 function_ref<
const TargetLibraryInfo &(Function &)> GetTLI);
115 const TargetLibraryInfo *TLI,
122 const TargetLibraryInfo *TLI,
129 const TargetLibraryInfo *TLI);
177 const TargetLibraryInfo *TLI,
bool MustSucceed);
179 const TargetLibraryInfo *TLI, AAResults *
AA,
187 :
public InstVisitor<ObjectSizeOffsetVisitor, SizeOffsetType> {
208 return SizeOffset.first.getBitWidth() > 1;
212 return SizeOffset.second.getBitWidth() > 1;
240 unsigned &ScannedInstCount);
243 bool CheckedZextOrTrunc(
APInt &
I);
251 :
public InstVisitor<ObjectSizeOffsetEvaluator, SizeOffsetEvalType> {
253 using WeakEvalType = std::pair<WeakTrackingVH, WeakTrackingVH>;
272 return std::make_pair(
nullptr,
nullptr);
281 return SizeOffset.first;
285 return SizeOffset.second;
311 #endif // LLVM_ANALYSIS_MEMORYBUILTINS_H
static SizeOffsetEvalType unknown()
std::pair< APInt, APInt > SizeOffsetType
This class represents an incoming formal argument to a Function.
SizeOffsetType visitGlobalAlias(GlobalAlias &GA)
This is an optimization pass for GlobalISel generic memory operations.
A parsed version of the target data layout string in and methods for querying it.
InstListType::iterator iterator
Instruction iterators...
SizeOffsetEvalType compute(Value *V)
SizeOffsetType visitExtractValueInst(ExtractValueInst &I)
SizeOffsetEvalType visitSelectInst(SelectInst &I)
SizeOffsetEvalType visitGEPOperator(GEPOperator &GEP)
bool NullIsUnknownSize
If this is true, null pointers in address space 0 will be treated as though they can't be evaluated.
SizeOffsetEvalType visitCallBase(CallBase &CB)
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
bool RoundToAlign
Whether to round the result up to the alignment of allocas, byval arguments, and global variables.
SizeOffsetEvalType visitLoadInst(LoadInst &I)
LLVM Basic Block Representation.
SizeOffsetEvalType visitIntToPtrInst(IntToPtrInst &)
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...
A constant pointer value that points to null.
static bool bothKnown(const SizeOffsetType &SizeOffset)
bool knownSize(SizeOffsetEvalType SizeOffset)
SizeOffsetType visitIntToPtrInst(IntToPtrInst &)
ObjectSizeOffsetEvaluator(const DataLayout &DL, const TargetLibraryInfo *TLI, LLVMContext &Context, ObjectSizeOpts EvalOpts={})
@ Exact
Fail to evaluate an unknown condition.
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Class to represent integer types.
SizeOffsetType visitGlobalVariable(GlobalVariable &GV)
SizeOffsetType visitAllocaInst(AllocaInst &I)
SizeOffsetEvalType visitExtractElementInst(ExtractElementInst &I)
const char LLVMTargetMachineRef LLVMPassBuilderOptionsRef Options
Evaluate the size and offset of an object pointed to by a Value*.
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.
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,...
This is an important class for using LLVM in a threaded context.
SizeOffsetType visitUndefValue(UndefValue &)
'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.
SizeOffsetType visitSelectInst(SelectInst &I)
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,...
@ Min
Evaluate all branches of an unknown condition.
This class represents the LLVM 'select' instruction.
print Print MemDeps of function
Class for arbitrary precision integers.
SizeOffsetEvalType visitAllocaInst(AllocaInst &I)
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Base class for instruction visitors.
Various options to control the behavior of getObjectSize.
An instruction for reading from memory.
@ Max
Same as Min, except we pick the maximum size of all of the branches.
SizeOffsetType visitLoadInst(LoadInst &I)
bool knownOffset(SizeOffsetEvalType SizeOffset)
SizeOffsetType visitInstruction(Instruction &I)
SizeOffsetType visitCallBase(CallBase &CB)
SizeOffsetType visitArgument(Argument &A)
Mode
Controls how we handle conditional statements with unknown conditions.
Optional< StringRef > getAllocationFamily(const Value *I, const TargetLibraryInfo *TLI)
If a function is part of an allocation family (e.g.
Mode EvalMode
How we want to evaluate this object's size.
Value * getAllocAlignment(const CallBase *V, const TargetLibraryInfo *TLI)
Gets the alignment argument for an aligned_alloc-like function, using either built-in knowledge based...
std::pair< Value *, Value * > SizeOffsetEvalType
static bool knownOffset(const SizeOffsetType &SizeOffset)
Provides information about what library functions are available for the current target.
This class represents a cast from an integer to a pointer.
SizeOffsetType compute(Value *V)
SizeOffsetType visitConstantPointerNull(ConstantPointerNull &)
Optional< APInt > getAllocSize(const CallBase *CB, const TargetLibraryInfo *TLI, std::function< const Value *(const Value *)> Mapper)
Return the size of the requested allocation.
SizeOffsetEvalType visitExtractValueInst(ExtractValueInst &I)
bool isReallocLikeFn(const Value *V, const TargetLibraryInfo *TLI)
Tests if a value is a call or invoke to a library function that reallocates memory (e....
SizeOffsetEvalType visitInstruction(Instruction &I)
static bool knownSize(const SizeOffsetType &SizeOffset)
bool bothKnown(SizeOffsetEvalType SizeOffset)
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
This class represents a function call, abstracting a target machine's calling convention.
ObjectSizeOffsetVisitor(const DataLayout &DL, const TargetLibraryInfo *TLI, LLVMContext &Context, ObjectSizeOpts Options={})
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM BB
BlockVerifier::State From
bool isAllocRemovable(const CallBase *V, const TargetLibraryInfo *TLI)
Return false if the allocation can have side effects on the program state we are required to preserve...
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)
LLVM Value Representation.
bool anyKnown(SizeOffsetEvalType SizeOffset)
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...
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 &)