44 assert(APAlign.isPowerOf2() &&
"must be a power of 2!");
45 return APBaseAlign.uge(APAlign) && !(Offset & (APAlign - 1));
57 if (!Visited.
insert(V).second)
66 Size, DL, CtxI, DT, Visited);
68 bool CheckForNonNull =
false;
69 APInt KnownDerefBytes(Size.getBitWidth(),
71 if (KnownDerefBytes.getBoolValue() && KnownDerefBytes.uge(Size))
72 if (!CheckForNonNull ||
isKnownNonZero(V, DL, 0,
nullptr, CtxI, DT)) {
87 if (!
GEP->accumulateConstantOffset(DL, Offset) || Offset.
isNegative() ||
106 if (
const GCRelocateInst *RelocateInst = dyn_cast<GCRelocateInst>(V))
108 RelocateInst->getDerivedPtr(), Alignment,
Size, DL, CtxI, DT, Visited);
112 Size, DL, CtxI, DT, Visited);
114 if (
const auto *
Call = dyn_cast<CallBase>(V))
187 if (isa<BinaryOperator>(A) || isa<CastInst>(A) || isa<PHINode>(A) ||
188 isa<GetElementPtrInst>(A))
189 if (
const Instruction *BI = dyn_cast<Instruction>(B))
190 if (cast<Instruction>(A)->isIdenticalToWhenDefined(BI))
203 APInt EltSize(DL.getIndexTypeSizeInBits(Ptr->
getType()),
204 DL.getTypeStoreSize(LI->
getType()));
205 const Align Alignment = DL.getValueOrABITypeAlignment(
214 HeaderFirstNonPHI, &DT);
219 if (!AddRec || AddRec->getLoop() != L || !AddRec->isAffine())
225 if (Step->getAPInt() != EltSize)
234 const APInt AccessSize = TC * EltSize;
245 if (EltSize.urem(Alignment.
value()) != 0)
248 HeaderFirstNonPHI, &DT);
267 const Align Alignment =
299 if (isa<CallInst>(BBI) && BBI->mayWriteToMemory() &&
300 !isa<DbgInfoIntrinsic>(BBI))
305 if (
LoadInst *LI = dyn_cast<LoadInst>(BBI)) {
309 if (LI->isVolatile())
311 AccessedPtr = LI->getPointerOperand();
312 MaybeAccessedAlign =
MaybeAlign(LI->getAlignment());
313 }
else if (
StoreInst *
SI = dyn_cast<StoreInst>(BBI)) {
315 if (
SI->isVolatile())
317 AccessedPtr =
SI->getPointerOperand();
324 const Align AccessedAlign =
326 if (AccessedAlign < Alignment)
330 if (AccessedPtr == V &&
357 cl::desc(
"Use this to specify the default maximum number of instructions " 358 "to scan backward from a given instruction, when searching for " 359 "available loaded value"));
364 unsigned MaxInstsToScan,
366 unsigned *NumScanedInst) {
373 ScanFrom, MaxInstsToScan, AA, IsLoad, NumScanedInst);
379 unsigned MaxInstsToScan,
381 unsigned *NumScanedInst) {
382 if (MaxInstsToScan == 0)
383 MaxInstsToScan = ~0U;
388 while (ScanFrom != ScanBB->
begin()) {
392 if (isa<DbgInfoIntrinsic>(Inst))
402 if (MaxInstsToScan-- == 0)
409 if (
LoadInst *LI = dyn_cast<LoadInst>(Inst))
411 LI->getPointerOperand()->stripPointerCasts(), StrippedPtr) &&
416 if (LI->isAtomic() < AtLeastAtomic)
428 Value *StorePtr =
SI->getPointerOperand()->stripPointerCasts();
438 if (
SI->isAtomic() < AtLeastAtomic)
443 return SI->getOperand(0);
449 if ((isa<AllocaInst>(StrippedPtr) || isa<GlobalVariable>(StrippedPtr)) &&
450 (isa<AllocaInst>(StorePtr) || isa<GlobalVariable>(StorePtr)) &&
451 StrippedPtr != StorePtr)
unsigned getSmallConstantTripCount(const Loop *L)
Returns the maximum trip count of the loop if it is a single-exit loop and we can compute a small max...
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 getZExtValue() const
Get zero extended value.
This class represents lattice values for constants.
bool isSafeToLoadUnconditionally(Value *V, MaybeAlign Alignment, APInt &Size, const DataLayout &DL, Instruction *ScanFrom=nullptr, const DominatorTree *DT=nullptr)
Return true if we know that executing a load from this value cannot trap.
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.
The main scalar evolution driver.
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.
bool isDereferenceableAndAlignedPointer(const Value *V, Type *Ty, MaybeAlign Alignment, 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 LocationSize precise(uint64_t Value)
bool isLoopInvariant(const SCEV *S, const Loop *L)
Return true if the value of the given SCEV is unchanging in the specified loop.
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.
unsigned getBitWidth() const
Return the number of bits in the APInt.
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.
unsigned getPointerTypeSizeInBits(Type *) const
Layout pointer size, in bits, based on the type.
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 ...
BlockT * getHeader() const
Type * getType() const
All values are typed, get the type of this value.
This node represents a polynomial recurrence on the trip count of the specified loop.
TypeSize getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type...
APInt sextOrTrunc(unsigned width) const
Sign extend or truncate to width.
An instruction for storing to memory.
Align getValueOrABITypeAlignment(MaybeAlign Alignment, Type *Ty) const
Helper function to return Alignment if it's set or the result of getABITypeAlignment(Ty), in any case the result is a valid alignment.
uint64_t value() const
This is a hole in the type system and should not be abused.
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
bool isNegative() const
Determine sign of this APInt.
This means that we are dealing with an entirely unknown SCEV value, and only represent it as its LLVM...
initializer< Ty > init(const Ty &Val)
const Instruction * getFirstNonPHI() const
Returns a pointer to the first instruction in this block that is not a PHINode instruction.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
APInt urem(const APInt &RHS) const
Unsigned remainder operation.
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.
MaybeAlign getPointerAlignment(const DataLayout &DL) const
Returns an alignment of the pointer value.
Value * getPointerOperand()
self_iterator getIterator()
unsigned getIndexTypeSizeInBits(Type *Ty) const
Layout size of the index used in GEP calculation.
static constexpr const Align None()
Returns a default constructed Align which corresponds to no alignment.
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
This struct is a compact representation of a valid (non-zero power of two) alignment.
bool isLoopInvariant(const Value *V) const
Return true if the specified value is loop invariant.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
const Value * getArgumentAliasingToReturnedPointer(const CallBase *Call, bool MustPreserveNullness)
This function returns call pointer argument that is considered the same by aliasing rules...
bool isDereferenceablePointer(const Value *V, Type *Ty, const DataLayout &DL, const Instruction *CtxI=nullptr, const DominatorTree *DT=nullptr)
Return true if this is always a dereferenceable pointer.
This struct is a compact representation of a valid (power of two) or undefined (0) alignment...
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.
bool isAligned(Align Lhs, uint64_t SizeInBytes)
Checks that SizeInBytes is a multiple of the alignment.
static bool AreEquivalentAddressValues(const Value *A, const Value *B)
Test if A and B will obviously have the same value.
const Module * getModule() const
Return the module owning the function this instruction belongs to or nullptr it the function does not...
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...
bool isDereferenceableAndAlignedInLoop(LoadInst *LI, Loop *L, ScalarEvolution &SE, DominatorTree &DT)
Return true if we can prove that the given load (which is assumed to be within the specified loop) wo...
LLVM_NODISCARD bool isModSet(const ModRefInfo MRI)
unsigned getAlignment() const
Return the alignment of the access that is being performed.
Represents a single loop in the control flow graph.
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static bool isDereferenceableAndAlignedPointer(const Value *V, Align Alignment, 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...
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
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.
const SCEV * getSCEV(Value *V)
Return a SCEV expression for the full generality of the specified expression.
static MaybeAlign getBaseAlign(const Value *Base, const DataLayout &DL)
ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc)
getModRefInfo (for call sites) - Return information about whether a particular call site modifies or ...
const BasicBlock * getParent() const
This class represents a constant integer value.