41 assert(Alignment.isPowerOf2() &&
"must be a power of 2!");
42 return BaseAlign.uge(Alignment) && !(Offset & (Alignment-1));
59 if (!Visited.
insert(V).second)
68 DL, CtxI, DT, Visited);
70 bool CheckForNonNull =
false;
71 APInt KnownDerefBytes(Size.getBitWidth(),
73 if (KnownDerefBytes.getBoolValue()) {
74 if (KnownDerefBytes.uge(Size))
81 const Value *Base =
GEP->getPointerOperand();
84 if (!
GEP->accumulateConstantOffset(DL, Offset) || Offset.
isNegative() ||
98 DL, CtxI, DT, Visited);
102 if (
const GCRelocateInst *RelocateInst = dyn_cast<GCRelocateInst>(V))
104 RelocateInst->getDerivedPtr(), Align, Size, DL, CtxI, DT, Visited);
108 DL, CtxI, DT, Visited);
111 if (
const Value *RV = CS.getReturnedArgOperand())
170 if (isa<BinaryOperator>(A) || isa<CastInst>(A) || isa<PHINode>(A) ||
171 isa<GetElementPtrInst>(A))
172 if (
const Instruction *BI = dyn_cast<Instruction>(B))
173 if (cast<Instruction>(A)->isIdenticalToWhenDefined(BI))
205 int64_t ByteOffset = 0;
212 Type *BaseType =
nullptr;
213 unsigned BaseAlign = 0;
214 if (
const AllocaInst *AI = dyn_cast<AllocaInst>(Base)) {
216 BaseType = AI->getAllocatedType();
217 BaseAlign = AI->getAlignment();
218 }
else if (
const GlobalVariable *GV = dyn_cast<GlobalVariable>(Base)) {
222 if (!GV->isInterposable()) {
223 BaseType = GV->getType()->getElementType();
224 BaseAlign = GV->getAlignment();
235 if (BaseType && BaseType->
isSized()) {
239 if (Align <= BaseAlign) {
242 ((ByteOffset % Align) == 0))
267 if (isa<CallInst>(BBI) && BBI->mayWriteToMemory() &&
268 !isa<DbgInfoIntrinsic>(BBI))
272 unsigned AccessedAlign;
273 if (
LoadInst *LI = dyn_cast<LoadInst>(BBI)) {
274 AccessedPtr = LI->getPointerOperand();
275 AccessedAlign = LI->getAlignment();
276 }
else if (
StoreInst *
SI = dyn_cast<StoreInst>(BBI)) {
277 AccessedPtr =
SI->getPointerOperand();
278 AccessedAlign =
SI->getAlignment();
283 if (AccessedAlign == 0)
285 if (AccessedAlign < Align)
289 if (AccessedPtr == V)
307 cl::desc(
"Use this to specify the default maximum number of instructions "
308 "to scan backward from a given instruction, when searching for "
309 "available loaded value"));
314 unsigned MaxInstsToScan,
316 if (MaxInstsToScan == 0)
317 MaxInstsToScan = ~0U;
337 while (ScanFrom != ScanBB->
begin()) {
341 if (isa<DbgInfoIntrinsic>(Inst))
348 if (MaxInstsToScan-- == 0)
355 if (
LoadInst *LI = dyn_cast<LoadInst>(Inst))
357 LI->getPointerOperand()->stripPointerCasts(), StrippedPtr) &&
362 if (LI->isAtomic() < Load->
isAtomic())
371 Value *StorePtr =
SI->getPointerOperand()->stripPointerCasts();
386 return SI->getOperand(0);
392 if ((isa<AllocaInst>(StrippedPtr) || isa<GlobalVariable>(StrippedPtr)) &&
393 (isa<AllocaInst>(StorePtr) || isa<GlobalVariable>(StorePtr)) &&
394 StrippedPtr != StorePtr)
A parsed version of the target data layout string in and methods for querying it. ...
unsigned getPrefTypeAlignment(Type *Ty) const
Returns the preferred stack/global alignment for the specified type.
cl::opt< unsigned > DefMaxInstsToScan
The default number of maximum instructions to scan in the block, used by FindAvailableLoadedValue().
An instruction for reading from memory.
Type * getElementType() const
bool isSafeToLoadUnconditionally(Value *V, unsigned Align, const DataLayout &DL, Instruction *ScanFrom=nullptr, const DominatorTree *DT=nullptr)
Return true if we know that executing a load from this value cannot trap.
static bool isAligned(const Value *Base, const APInt &Offset, unsigned Align, const DataLayout &DL)
The access modifies the value stored in memory.
Type * getPointerElementType() const
static bool isBitOrNoopPointerCastable(Type *SrcTy, Type *DestTy, const DataLayout &DL)
Check whether a bitcast, inttoptr, or ptrtoint cast between these types is valid and a no-op...
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
iterator begin()
Instruction iterator methods.
bool isNegative() const
Determine sign of this APInt.
APInt urem(const APInt &RHS) const
Unsigned remainder operation.
This class represents a conversion between pointers from one address space to another.
unsigned getPointerAlignment(const DataLayout &DL) const
Returns an alignment of the pointer value.
const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr it the function does no...
Value * GetPointerBaseWithConstantOffset(Value *Ptr, int64_t &Offset, const DataLayout &DL)
Analyze the specified pointer to see if it can be expressed as a base pointer plus a constant offset...
static GCRegistry::Add< OcamlGC > B("ocaml","ocaml 3.10-compatible GC")
An instruction for storing to memory.
Value * FindAvailableLoadedValue(LoadInst *Load, BasicBlock *ScanBB, BasicBlock::iterator &ScanFrom, unsigned MaxInstsToScan=DefMaxInstsToScan, AliasAnalysis *AA=nullptr, bool *IsLoadCSE=nullptr)
Scan backwards to see if we have the value of the given load available locally within a small number ...
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
bool isAtomic() const
Return true if this instruction has an AtomicOrdering of unordered or higher.
Class to represent pointers.
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
static bool isDereferenceableAndAlignedPointer(const Value *V, unsigned Align, const APInt &Size, const DataLayout &DL, const Instruction *CtxI, const DominatorTree *DT, SmallPtrSetImpl< const Value * > &Visited)
Test if V is always a pointer to allocated and suitably aligned memory for a simple load or store...
initializer< Ty > init(const Ty &Val)
constexpr bool isPowerOf2_32(uint32_t Value)
isPowerOf2_32 - This function returns true if the argument is a power of two > 0. ...
LLVM Basic Block Representation.
The instances of the Type class are immutable: once they are created, they are never changed...
uint64_t getTypeStoreSizeInBits(Type *Ty) const
Returns the maximum number of bits that may be overwritten by storing the specified type; always a mu...
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
unsigned getBitWidth() const
Return the number of bits in the APInt.
Value * getPointerOperand()
self_iterator getIterator()
bool mayWriteToMemory() const
Return true if this instruction may modify memory.
unsigned getABITypeAlignment(Type *Ty) const
Returns the minimum ABI-required alignment for the specified type.
Iterator for intrusive lists based on ilist_node.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
uint64_t getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
Module.h This file contains the declarations for the Module class.
Type * getType() const
All values are typed, get the type of this value.
bool isVolatile() const
Return true if this is a load from a volatile memory location.
Value * stripPointerCasts()
Strip off pointer casts, all-zero GEPs, and aliases.
static bool AreEquivalentAddressValues(const Value *A, const Value *B)
Test if A and B will obviously have the same value.
Class for arbitrary precision integers.
ModRefInfo getModRefInfo(ImmutableCallSite CS, const MemoryLocation &Loc)
getModRefInfo (for call sites) - Return information about whether a particular call site modifies or ...
bool isMinValue() const
Determine if this is the smallest unsigned value.
bool isDereferenceablePointer(const Value *V, const DataLayout &DL, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr)
Return true if this is always a dereferenceable pointer.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
unsigned getPointerDereferenceableBytes(const DataLayout &DL, bool &CanBeNull) const
Returns the number of bytes known to be dereferenceable for the pointer value.
ImmutableCallSite - establish a view to a call site for examination.
bool isKnownNonNullAt(const Value *V, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr)
Return true if this pointer couldn't possibly be null.
uint64_t getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Represents calls to the gc.relocate intrinsic.
LLVM Value Representation.
APInt sextOrTrunc(unsigned width) const
Sign extend or truncate to width.
uint64_t getTypeSizeInBits(Type *Ty) const
Size examples:
bool isDereferenceableAndAlignedPointer(const Value *V, unsigned Align, const DataLayout &DL, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr)
Returns true if V is always a dereferenceable pointer with alignment greater or equal than requested...
static GCRegistry::Add< ErlangGC > A("erlang","erlang-compatible garbage collector")
const BasicBlock * getParent() const
an instruction to allocate memory on the stack