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))
75 if (!CheckForNonNull ||
isKnownNonZero(V, DL, 0,
nullptr, CtxI, DT))
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);
110 if (
const auto *
Call = dyn_cast<CallBase>(V))
180 if (isa<BinaryOperator>(A) || isa<CastInst>(A) || isa<PHINode>(A) ||
181 isa<GetElementPtrInst>(A))
182 if (
const Instruction *BI = dyn_cast<Instruction>(B))
183 if (cast<Instruction>(A)->isIdenticalToWhenDefined(BI))
215 int64_t ByteOffset = 0;
223 unsigned BaseAlign = 0;
224 if (
const AllocaInst *AI = dyn_cast<AllocaInst>(Base)) {
226 BaseType = AI->getAllocatedType();
227 BaseAlign = AI->getAlignment();
228 }
else if (
const GlobalVariable *GV = dyn_cast<GlobalVariable>(Base)) {
232 if (!GV->isInterposable()) {
233 BaseType = GV->getType()->getElementType();
234 BaseAlign = GV->getAlignment();
245 if (BaseType && BaseType->
isSized()) {
249 if (Align <= BaseAlign) {
252 ((ByteOffset %
Align) == 0))
277 if (isa<CallInst>(BBI) && BBI->mayWriteToMemory() &&
278 !isa<DbgInfoIntrinsic>(BBI))
282 unsigned AccessedAlign;
283 if (
LoadInst *LI = dyn_cast<LoadInst>(BBI)) {
284 AccessedPtr = LI->getPointerOperand();
285 AccessedAlign = LI->getAlignment();
286 }
else if (
StoreInst *
SI = dyn_cast<StoreInst>(BBI)) {
287 AccessedPtr =
SI->getPointerOperand();
288 AccessedAlign =
SI->getAlignment();
293 if (AccessedAlign == 0)
295 if (AccessedAlign < Align)
299 if (AccessedPtr == V)
317 cl::desc(
"Use this to specify the default maximum number of instructions " 318 "to scan backward from a given instruction, when searching for " 319 "available loaded value"));
324 unsigned MaxInstsToScan,
326 unsigned *NumScanedInst) {
333 ScanFrom, MaxInstsToScan, AA, IsLoad, NumScanedInst);
339 unsigned MaxInstsToScan,
341 unsigned *NumScanedInst) {
342 if (MaxInstsToScan == 0)
343 MaxInstsToScan = ~0U;
352 while (ScanFrom != ScanBB->
begin()) {
356 if (isa<DbgInfoIntrinsic>(Inst))
366 if (MaxInstsToScan-- == 0)
373 if (
LoadInst *LI = dyn_cast<LoadInst>(Inst))
375 LI->getPointerOperand()->stripPointerCasts(), StrippedPtr) &&
380 if (LI->isAtomic() < AtLeastAtomic)
389 Value *StorePtr =
SI->getPointerOperand()->stripPointerCasts();
399 if (
SI->isAtomic() < AtLeastAtomic)
404 return SI->getOperand(0);
410 if ((isa<AllocaInst>(StrippedPtr) || isa<GlobalVariable>(StrippedPtr)) &&
411 (isa<AllocaInst>(StorePtr) || isa<GlobalVariable>(StorePtr)) &&
412 StrippedPtr != StorePtr)
A parsed version of the target data layout string in and methods for querying it. ...
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
uint64_t getTypeStoreSizeInBits(Type *Ty) const
Returns the maximum number of bits that may be overwritten by storing the specified type; always a mu...
This class represents lattice values for constants.
bool isAtomic() const
Return true if this instruction has an AtomicOrdering of unordered or higher.
bool isSized(SmallPtrSetImpl< Type *> *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
cl::opt< unsigned > DefMaxInstsToScan
The default number of maximum instructions to scan in the block, used by FindAvailableLoadedValue().
bool mayWriteToMemory() const
Return true if this instruction may modify memory.
static LocationSize precise(uint64_t Value)
Value * FindAvailablePtrLoadStore(Value *Ptr, Type *AccessTy, bool AtLeastAtomic, BasicBlock *ScanBB, BasicBlock::iterator &ScanFrom, unsigned MaxInstsToScan, AliasAnalysis *AA, bool *IsLoad, unsigned *NumScanedInst)
Scan backwards to see if we have the value of the given pointer available locally within a small numb...
An instruction for reading from memory.
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)
unsigned getBitWidth() const
Return the number of bits in the APInt.
unsigned getPointerAlignment(const DataLayout &DL) const
Returns an alignment of the pointer value.
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...
iterator begin()
Instruction iterator methods.
const Module * getModule() const
Return the module owning the function this basic block belongs to, or nullptr if the function does no...
This class represents a conversion between pointers from one address space to another.
Type * getPointerElementType() const
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Value * FindAvailableLoadedValue(LoadInst *Load, BasicBlock *ScanBB, BasicBlock::iterator &ScanFrom, unsigned MaxInstsToScan=DefMaxInstsToScan, AliasAnalysis *AA=nullptr, bool *IsLoadCSE=nullptr, unsigned *NumScanedInst=nullptr)
Scan backwards to see if we have the value of the given load available locally within a small number ...
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...
Type * getType() const
All values are typed, get the type of this value.
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...
APInt sextOrTrunc(unsigned width) const
Sign extend or truncate to width.
An instruction for storing to memory.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Class to represent pointers.
bool isNegative() const
Determine sign of this APInt.
initializer< Ty > init(const Ty &Val)
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
APInt urem(const APInt &RHS) const
Unsigned remainder operation.
constexpr bool isPowerOf2_32(uint32_t Value)
Return 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...
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
unsigned getPrefTypeAlignment(Type *Ty) const
Returns the preferred stack/global alignment for the specified type.
Value * getPointerOperand()
self_iterator getIterator()
unsigned getIndexTypeSizeInBits(Type *Ty) const
Layout size of the index used in GEP calculation.
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs, and aliases.
const Value * getArgumentAliasingToReturnedPointer(const CallBase *Call)
This function returns call pointer argument that is considered the same by aliasing rules...
BaseType
A given derived pointer can have multiple base pointers through phi/selects.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
Module.h This file contains the declarations for the Module class.
unsigned getABITypeAlignment(Type *Ty) const
Returns the minimum ABI-required alignment for the specified type.
uint64_t getPointerDereferenceableBytes(const DataLayout &DL, bool &CanBeNull) const
Returns the number of bytes known to be dereferenceable for the pointer value.
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.
bool isKnownNonZero(const Value *V, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true)
Return true if the given value is known to be non-zero when defined.
InstListType::iterator iterator
Instruction iterators...
uint64_t getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
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.
LLVM_NODISCARD bool isModSet(const ModRefInfo MRI)
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
bool isMinValue() const
Determine if this is the smallest unsigned value.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Represents calls to the gc.relocate intrinsic.
LLVM Value Representation.
uint64_t getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type...
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...
ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc)
getModRefInfo (for call sites) - Return information about whether a particular call site modifies or ...
Type * getElementType() const
const BasicBlock * getParent() const
an instruction to allocate memory on the stack