63 #define DEBUG_TYPE "basicaa" 83 STATISTIC(SearchLimitReached,
"Number of times the limit to " 84 "decompose GEPs is reached");
85 STATISTIC(SearchTimes,
"Number of times a GEP is decomposed");
124 if (IsCapturedCache) {
126 std::tie(CacheIt, Inserted) = IsCapturedCache->
insert({V,
false});
129 return CacheIt->second;
141 CacheIt->second =
Ret;
148 if (
const Argument *A = dyn_cast<Argument>(V))
149 if (A->hasByValAttr() || A->hasNoAliasAttr()) {
155 CacheIt->second =
Ret;
165 if (isa<CallBase>(V))
168 if (isa<Argument>(V))
174 if (isa<LoadInst>(V))
184 bool RoundToAlign =
false) {
199 bool NullIsValidLoc) {
231 uint64_t ObjectSize =
getObjectSize(V, DL, TLI, NullIsValidLoc,
243 bool NullIsValidLoc) {
249 DerefBytes = (CanBeNull && NullIsValidLoc) ? 0 : DerefBytes;
260 uint64_t ObjectSize =
getObjectSize(V, DL, TLI, NullIsValidLoc);
278 const Value *BasicAAResult::GetLinearExpression(
291 if (
const ConstantInt *Const = dyn_cast<ConstantInt>(V)) {
297 Offset += Const->getValue().zextOrSelf(Offset.
getBitWidth());
298 assert(Scale == 0 &&
"Constant values don't have a scale");
303 if (
ConstantInt *RHSC = dyn_cast<ConstantInt>(BOp->getOperand(1))) {
309 switch (BOp->getOpcode()) {
316 case Instruction::Or:
327 V = GetLinearExpression(BOp->getOperand(0), Scale,
Offset, ZExtBits,
328 SExtBits, DL, Depth + 1, AC, DT, NSW, NUW);
331 case Instruction::Sub:
332 V = GetLinearExpression(BOp->getOperand(0), Scale,
Offset, ZExtBits,
333 SExtBits, DL, Depth + 1, AC, DT, NSW, NUW);
336 case Instruction::Mul:
337 V = GetLinearExpression(BOp->getOperand(0), Scale,
Offset, ZExtBits,
338 SExtBits, DL, Depth + 1, AC, DT, NSW, NUW);
342 case Instruction::Shl:
343 V = GetLinearExpression(BOp->getOperand(0), Scale,
Offset, ZExtBits,
344 SExtBits, DL, Depth + 1, AC, DT, NSW, NUW);
366 if (isa<OverflowingBinaryOperator>(BOp)) {
367 NUW &= BOp->hasNoUnsignedWrap();
368 NSW &= BOp->hasNoSignedWrap();
377 if (isa<SExtInst>(V) || isa<ZExtInst>(V)) {
378 Value *CastOp = cast<CastInst>(V)->getOperand(0);
381 unsigned OldZExtBits = ZExtBits, OldSExtBits = SExtBits;
382 const Value *Result =
383 GetLinearExpression(CastOp, Scale, Offset, ZExtBits, SExtBits, DL,
384 Depth + 1, AC, DT, NSW, NUW);
388 unsigned ExtendedBy = NewWidth - SmallWidth;
390 if (isa<SExtInst>(V) && ZExtBits == 0) {
404 ZExtBits = OldZExtBits;
405 SExtBits = OldSExtBits;
407 SExtBits += ExtendedBy;
417 ZExtBits = OldZExtBits;
418 SExtBits = OldSExtBits;
420 ZExtBits += ExtendedBy;
438 unsigned ShiftBits = Offset.
getBitWidth() - PointerSize;
439 return (Offset << ShiftBits).ashr(ShiftBits);
447 return MaxPointerSize;
463 bool BasicAAResult::DecomposeGEPExpression(
const Value *V,
471 Decomposed.VarIndices.clear();
477 if (
const GlobalAlias *GA = dyn_cast<GlobalAlias>(V)) {
478 if (!GA->isInterposable()) {
479 V = GA->getAliasee();
487 if (Op->
getOpcode() == Instruction::BitCast ||
488 Op->
getOpcode() == Instruction::AddrSpaceCast) {
495 if (
const auto *Call = dyn_cast<CallBase>(V)) {
539 bool GepHasConstantOffset =
true;
541 I !=
E; ++
I, ++GTI) {
546 unsigned FieldNo = cast<ConstantInt>(
Index)->getZExtValue();
550 Decomposed.StructOffset +=
556 if (
const ConstantInt *CIdx = dyn_cast<ConstantInt>(Index)) {
559 Decomposed.OtherOffset +=
561 CIdx->getValue().sextOrSelf(MaxPointerSize))
562 .sextOrTrunc(MaxPointerSize);
566 GepHasConstantOffset =
false;
569 unsigned ZExtBits = 0, SExtBits = 0;
574 if (PointerSize > Width)
575 SExtBits += PointerSize -
Width;
578 APInt IndexScale(Width, 0), IndexOffset(Width, 0);
579 bool NSW =
true, NUW =
true;
581 Index = GetLinearExpression(Index, IndexScale, IndexOffset, ZExtBits,
582 SExtBits, DL, 0, AC, DT, NSW, NUW);
595 Scale.
sext(MaxPointerSize*2);
601 ZExtBits = SExtBits = 0;
602 if (PointerSize > Width)
603 SExtBits += PointerSize -
Width;
605 Decomposed.OtherOffset += IndexOffset.
sextOrTrunc(MaxPointerSize) * Scale;
613 for (
unsigned i = 0,
e = Decomposed.VarIndices.size(); i !=
e; ++i) {
614 if (Decomposed.VarIndices[i].V == Index &&
615 Decomposed.VarIndices[i].ZExtBits == ZExtBits &&
616 Decomposed.VarIndices[i].SExtBits == SExtBits) {
617 Scale += Decomposed.VarIndices[i].Scale;
618 Decomposed.VarIndices.erase(Decomposed.VarIndices.begin() + i);
628 VariableGEPIndex
Entry = {
Index, ZExtBits, SExtBits, Scale};
629 Decomposed.VarIndices.push_back(Entry);
634 if (GepHasConstantOffset) {
635 Decomposed.StructOffset =
637 Decomposed.OtherOffset =
643 }
while (--MaxLookup);
647 SearchLimitReached++;
656 assert(Visited.empty() &&
"Visited must be cleared after use!");
658 unsigned MaxLookup = 8;
663 if (!Visited.insert(V).second) {
669 if (OrLocal && isa<AllocaInst>(V))
677 if (!GV->isConstant()) {
693 if (
const PHINode *PN = dyn_cast<PHINode>(V)) {
695 if (PN->getNumIncomingValues() > MaxLookup) {
699 for (
Value *IncValue : PN->incoming_values())
707 }
while (!Worklist.
empty() && --MaxLookup);
710 return Worklist.
empty();
786 F == LibFunc_memset_pattern16 && TLI.
has(F))
819 if (
const Instruction *inst = dyn_cast<Instruction>(V)) {
820 if (!inst->getParent())
825 if (
const Argument *arg = dyn_cast<Argument>(V))
826 return arg->getParent();
836 return !F1 || !F2 || F1 == F2;
844 "BasicAliasAnalysis doesn't support interprocedural queries.");
851 return CacheIt->second;
855 return CacheIt->second;
860 VisitedPhiBBs.
clear();
874 "AliasAnalysis query involving multiple functions!");
883 if (isa<AllocaInst>(Object))
884 if (
const CallInst *CI = dyn_cast<CallInst>(Call))
885 if (CI->isTailCall() &&
886 !CI->getAttributes().hasAttrSomewhere(Attribute::ByVal))
891 if (
auto *AI = dyn_cast<AllocaInst>(Object))
892 if (!AI->isStaticAlloca() &&
isIntrinsicCall(Call, Intrinsic::stackrestore))
898 if (!isa<Constant>(Object) && Call != Object &&
904 bool IsMustAlias =
true;
906 unsigned OperandNo = 0;
908 CI != CE; ++CI, ++OperandNo) {
912 if (!(*CI)->getType()->isPointerTy() ||
980 if (
auto *Inst = dyn_cast<AnyMemCpyInst>(Call)) {
1092 "Expected GEPs with the same pointer operand");
1107 const uint64_t V1Size = MaybeV1Size.
getValue();
1108 const uint64_t V2Size = MaybeV2Size.
getValue();
1148 if (isa<SequentialType>(Ty)) {
1160 const uint64_t ElementSize =
1162 if (V1Size != ElementSize || V2Size != ElementSize)
1182 if (isa<PHINode>(GEP1LastIdx) || isa<PHINode>(GEP2LastIdx)) {
1189 if (GEP1LastIdx != GEP2LastIdx &&
1201 }
else if (!LastIndexedStruct || !C1 || !C2) {
1227 auto EltsDontOverlap = [StructSize](uint64_t V1Off, uint64_t V1Size,
1228 uint64_t V2Off, uint64_t V2Size) {
1229 return V1Off < V2Off && V1Off + V1Size <= V2Off &&
1230 ((V2Off + V2Size <= StructSize) ||
1231 (V2Off + V2Size - StructSize <= V1Off));
1234 if (EltsDontOverlap(V1Off, V1Size, V2Off, V2Size) ||
1235 EltsDontOverlap(V2Off, V2Size, V1Off, V1Size))
1272 bool BasicAAResult::isGEPBaseAtNegativeOffset(
const GEPOperator *GEPOp,
1273 const DecomposedGEP &DecompGEP,
const DecomposedGEP &DecompObject,
1279 const uint64_t ObjectAccessSize = MaybeObjectAccessSize.
getValue();
1284 if (!(isa<AllocaInst>(DecompObject.Base) ||
1285 isa<GlobalVariable>(DecompObject.Base)) ||
1286 !DecompObject.VarIndices.empty())
1289 APInt ObjectBaseOffset = DecompObject.StructOffset +
1290 DecompObject.OtherOffset;
1296 if (!DecompGEP.VarIndices.empty())
1299 APInt GEPBaseOffset = DecompGEP.StructOffset;
1300 GEPBaseOffset += DecompGEP.OtherOffset;
1302 return GEPBaseOffset.
sge(ObjectBaseOffset + (int64_t)ObjectAccessSize);
1315 DecomposedGEP DecompGEP1, DecompGEP2;
1317 DecompGEP1.StructOffset = DecompGEP1.OtherOffset =
APInt(MaxPointerSize, 0);
1318 DecompGEP2.StructOffset = DecompGEP2.OtherOffset =
APInt(MaxPointerSize, 0);
1320 bool GEP1MaxLookupReached =
1321 DecomposeGEPExpression(GEP1, DecompGEP1, DL, &AC, DT);
1322 bool GEP2MaxLookupReached =
1323 DecomposeGEPExpression(V2, DecompGEP2, DL, &AC, DT);
1325 APInt GEP1BaseOffset = DecompGEP1.StructOffset + DecompGEP1.OtherOffset;
1326 APInt GEP2BaseOffset = DecompGEP2.StructOffset + DecompGEP2.OtherOffset;
1328 assert(DecompGEP1.Base == UnderlyingV1 && DecompGEP2.Base == UnderlyingV2 &&
1329 "DecomposeGEPExpression returned a result different from " 1330 "GetUnderlyingObject");
1335 if (!GEP1MaxLookupReached && !GEP2MaxLookupReached &&
1336 isGEPBaseAtNegativeOffset(GEP1, DecompGEP1, DecompGEP2, V2Size))
1341 if (
const GEPOperator *GEP2 = dyn_cast<GEPOperator>(V2)) {
1344 if (!GEP1MaxLookupReached && !GEP2MaxLookupReached &&
1345 isGEPBaseAtNegativeOffset(GEP2, DecompGEP2, DecompGEP1, V1Size))
1354 if ((BaseAlias ==
MayAlias) && V1Size == V2Size) {
1357 UnderlyingV1, V1Size, V1AAInfo, UnderlyingV2, V2Size, V2AAInfo, AAQI);
1358 if (PreciseBaseAlias ==
NoAlias) {
1362 if (GEP2MaxLookupReached || GEP1MaxLookupReached)
1366 if (GEP1BaseOffset == GEP2BaseOffset &&
1367 DecompGEP1.VarIndices == DecompGEP2.VarIndices)
1395 if (GEP2MaxLookupReached || GEP1MaxLookupReached)
1400 GEP1BaseOffset -= GEP2BaseOffset;
1401 GetIndexDifference(DecompGEP1.VarIndices, DecompGEP2.VarIndices);
1414 V2AAInfo, AAQI,
nullptr, UnderlyingV2);
1426 if (GEP1MaxLookupReached)
1436 if (GEP1BaseOffset == 0 && DecompGEP1.VarIndices.empty())
1443 if (GEP1BaseOffset != 0 && DecompGEP1.VarIndices.empty()) {
1444 if (GEP1BaseOffset.
sge(0)) {
1461 if ((-GEP1BaseOffset).ult(V1Size.
getValue()))
1468 if (!DecompGEP1.VarIndices.empty()) {
1469 APInt Modulo(MaxPointerSize, 0);
1470 bool AllPositive =
true;
1471 for (
unsigned i = 0,
e = DecompGEP1.VarIndices.size(); i !=
e; ++i) {
1477 Modulo |= DecompGEP1.VarIndices[i].Scale;
1483 const Value *V = DecompGEP1.VarIndices[i].V;
1492 bool IsZExt = DecompGEP1.VarIndices[i].ZExtBits > 0 || isa<ZExtInst>(V);
1493 SignKnownZero |= IsZExt;
1494 SignKnownOne &= !IsZExt;
1499 APInt Scale = DecompGEP1.VarIndices[i].Scale;
1501 (SignKnownZero && Scale.
sge(0)) || (SignKnownOne && Scale.
slt(0));
1505 Modulo = Modulo ^ (Modulo & (Modulo - 1));
1510 APInt ModOffset = GEP1BaseOffset & (Modulo - 1);
1513 (Modulo - ModOffset).uge(V1Size.
getValue()))
1519 if (AllPositive && GEP1BaseOffset.
sgt(0) &&
1524 if (constantOffsetHeuristic(DecompGEP1.VarIndices, V1Size, V2Size,
1525 GEP1BaseOffset, &AC, DT))
1556 if (
const SelectInst *SI2 = dyn_cast<SelectInst>(V2))
1559 aliasCheck(SI->
getTrueValue(), SISize, SIAAInfo, SI2->getTrueValue(),
1560 V2Size, V2AAInfo, AAQI);
1565 SI2->getFalseValue(), V2Size, V2AAInfo, AAQI);
1572 SISize, SIAAInfo, AAQI, UnderV2);
1577 SISize, SIAAInfo, AAQI, UnderV2);
1595 if (
const PHINode *PN2 = dyn_cast<PHINode>(V2))
1596 if (PN2->getParent() == PN->
getParent()) {
1614 "There must exist an entry for the phi node");
1615 OrigAliasResult = CacheIt->second;
1623 V2Size, V2AAInfo, AAQI);
1633 assert(!Pair.second &&
"Entry must have existed");
1634 Pair.first->second = OrigAliasResult;
1640 bool isRecursive =
false;
1651 for (
Value *PV1 : PhiValueSet) {
1653 if (
GEPOperator *PV1GEP = dyn_cast<GEPOperator>(PV1)) {
1658 if (PV1GEP->getPointerOperand() == PN && PV1GEP->getNumIndices() == 1 &&
1659 isa<ConstantInt>(PV1GEP->idx_begin())) {
1672 if (isa<PHINode>(PV1))
1680 if (
GEPOperator *PV1GEP = dyn_cast<GEPOperator>(PV1)) {
1685 if (PV1GEP->getPointerOperand() == PN && PV1GEP->getNumIndices() == 1 &&
1686 isa<ConstantInt>(PV1GEP->idx_begin())) {
1692 if (UniqueSrc.
insert(PV1).second)
1709 AliasResult Alias = aliasCheck(V2, V2Size, V2AAInfo, V1Srcs[0], PNSize,
1710 PNAAInfo, AAQI, UnderV2);
1719 for (
unsigned i = 1,
e = V1Srcs.
size(); i !=
e; ++i) {
1720 Value *V = V1Srcs[i];
1723 aliasCheck(V2, V2Size, V2AAInfo, V, PNSize, PNAAInfo, AAQI, UnderV2);
1750 if (isa<UndefValue>(V1) || isa<UndefValue>(V2))
1759 if (isValueEqualInPotentialCycles(V1, V2))
1819 TLI, NullIsValidLocation)) ||
1822 TLI, NullIsValidLocation)))
1831 std::pair<AAQueryInfo::AliasCacheT::iterator, bool> Pair =
1834 return Pair.first->second;
1838 if (!isa<GEPOperator>(V1) && isa<GEPOperator>(V2)) {
1844 if (
const GEPOperator *GV1 = dyn_cast<GEPOperator>(V1)) {
1846 aliasGEP(GV1, V1Size, V1AAInfo, V2, V2Size, V2AAInfo, O1, O2, AAQI);
1849 assert(!ItInsPair.second &&
"Entry must have existed");
1850 ItInsPair.first->second = Result;
1855 if (isa<PHINode>(V2) && !isa<PHINode>(V1)) {
1861 if (
const PHINode *PN = dyn_cast<PHINode>(V1)) {
1863 aliasPHI(PN, V1Size, V1AAInfo, V2, V2Size, V2AAInfo, O2, AAQI);
1866 assert(!Pair.second &&
"Entry must have existed");
1867 return Pair.first->second = Result;
1871 if (isa<SelectInst>(V2) && !isa<SelectInst>(V1)) {
1877 if (
const SelectInst *S1 = dyn_cast<SelectInst>(V1)) {
1879 aliasSelect(S1, V1Size, V1AAInfo, V2, V2Size, V2AAInfo, O2, AAQI);
1882 assert(!Pair.second &&
"Entry must have existed");
1883 return Pair.first->second = Result;
1894 assert(!Pair.second &&
"Entry must have existed");
1903 assert(!Pair.second &&
"Entry must have existed");
1904 return Pair.first->second = Result;
1914 bool BasicAAResult::isValueEqualInPotentialCycles(
const Value *V,
1923 if (VisitedPhiBBs.
empty())
1932 for (
auto *
P : VisitedPhiBBs)
1943 void BasicAAResult::GetIndexDifference(
1949 for (
unsigned i = 0,
e = Src.
size(); i !=
e; ++i) {
1950 const Value *V = Src[i].V;
1951 unsigned ZExtBits = Src[i].ZExtBits, SExtBits = Src[i].SExtBits;
1952 APInt Scale = Src[i].Scale;
1956 for (
unsigned j = 0,
e = Dest.
size(); j !=
e; ++j) {
1957 if (!isValueEqualInPotentialCycles(Dest[j].V, V) ||
1958 Dest[j].ZExtBits != ZExtBits || Dest[j].SExtBits != SExtBits)
1963 if (Dest[j].Scale != Scale)
1964 Dest[j].Scale -= Scale;
1973 VariableGEPIndex
Entry = {V, ZExtBits, SExtBits, -Scale};
1979 bool BasicAAResult::constantOffsetHeuristic(
1987 const uint64_t V1Size = MaybeV1Size.
getValue();
1988 const uint64_t V2Size = MaybeV2Size.
getValue();
1990 const VariableGEPIndex &Var0 = VarIndices[0], &Var1 = VarIndices[1];
1992 if (Var0.ZExtBits != Var1.ZExtBits || Var0.SExtBits != Var1.SExtBits ||
1993 Var0.Scale != -Var1.Scale)
1996 unsigned Width = Var1.V->getType()->getIntegerBitWidth();
2002 APInt V0Scale(Width, 0), V0Offset(Width, 0), V1Scale(Width, 0),
2004 bool NSW =
true, NUW =
true;
2005 unsigned V0ZExtBits = 0, V0SExtBits = 0, V1ZExtBits = 0, V1SExtBits = 0;
2006 const Value *V0 = GetLinearExpression(Var0.V, V0Scale, V0Offset, V0ZExtBits,
2007 V0SExtBits, DL, 0, AC, DT, NSW, NUW);
2010 const Value *V1 = GetLinearExpression(Var1.V, V1Scale, V1Offset, V1ZExtBits,
2011 V1SExtBits, DL, 0, AC, DT, NSW, NUW);
2013 if (V0Scale != V1Scale || V0ZExtBits != V1ZExtBits ||
2014 V0SExtBits != V1SExtBits || !isValueEqualInPotentialCycles(V0, V1))
2024 APInt MinDiff = V0Offset - V1Offset, Wrapped = -MinDiff;
2026 APInt MinDiffBytes =
2027 MinDiff.
zextOrTrunc(Var0.Scale.getBitWidth()) * Var0.Scale.
abs();
2033 return MinDiffBytes.
uge(V1Size + BaseOffset.
abs()) &&
2034 MinDiffBytes.
uge(V2Size + BaseOffset.
abs());
2059 void BasicAAWrapperPass::anchor() {}
2062 "Basic Alias Analysis (stateless AA impl)",
false,
true)
2074 auto &ACT = getAnalysis<AssumptionCacheTracker>();
2075 auto &TLIWP = getAnalysis<TargetLibraryInfoWrapperPass>();
2076 auto &DTWP = getAnalysis<DominatorTreeWrapperPass>();
2077 auto *LIWP = getAnalysisIfAvailable<LoopInfoWrapperPass>();
2078 auto *PVWP = getAnalysisIfAvailable<PhiValuesWrapperPass>();
2081 TLIWP.getTLI(F), ACT.getAssumptionCache(F),
2083 LIWP ? &LIWP->getLoopInfo() :
nullptr,
2084 PVWP ? &PVWP->getResult() :
nullptr));
The access may reference and may modify the value stored in memory.
APInt abs() const
Get the absolute value;.
Pass interface - Implemented by all 'passes'.
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.
bool onlyReadsMemory() const
Determine if the function does not access or only reads memory.
bool pointsToConstantMemory(const MemoryLocation &Loc, AAQueryInfo &AAQI, bool OrLocal)
Chases pointers until we find a (constant global) or not.
static const unsigned MaxLookupSearchDepth
bool hasOperandBundles() const
Return true if this User has any operand bundles.
void computeKnownBits(const Value *V, KnownBits &Known, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, OptimizationRemarkEmitter *ORE=nullptr, bool UseInstrInfo=true)
Determine which bits of V are known to be either zero or one and return them in the KnownZero/KnownOn...
User::op_iterator data_operands_end()
A parsed version of the target data layout string in and methods for querying it. ...
bool invalidate(IRUnitT &IR, const PreservedAnalyses &PA)
Trigger the invalidation of some other analysis pass if not already handled and return whether it was...
The access neither references nor modifies the value stored in memory.
LLVM_NODISCARD ModRefInfo clearMust(const ModRefInfo MRI)
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
APInt sext(unsigned width) const
Sign extend to a new width.
This class represents an incoming formal argument to a Function.
bool doesNotAccessMemory(unsigned OpNo) const
static cl::opt< bool > DoubleCalcBits("basicaa-double-calc-bits", cl::Hidden, cl::init(false))
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
This class represents lattice values for constants.
BasicAAResult createLegacyPMBasicAAResult(Pass &P, Function &F)
A helper for the legacy pass manager to create a BasicAAResult object populated to the best of our ab...
bool isSized(SmallPtrSetImpl< Type *> *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
bool isPotentiallyReachable(const Instruction *From, const Instruction *To, const SmallPtrSetImpl< BasicBlock *> *ExclusionSet=nullptr, const DominatorTree *DT=nullptr, const LoopInfo *LI=nullptr)
Determine whether instruction 'To' is reachable from 'From', without passing through any blocks in Ex...
static constexpr LocationSize unknown()
static bool isIntrinsicCall(const CallBase *Call, Intrinsic::ID IID)
const StructLayout * getStructLayout(StructType *Ty) const
Returns a StructLayout object, indicating the alignment of the struct, its size, and the offsets of i...
void push_back(const T &Elt)
bool NullIsUnknownSize
If this is true, null pointers in address space 0 will be treated as though they can't be evaluated...
bool slt(const APInt &RHS) const
Signed less than comparison.
This class stores info we want to provide to or retain within an alias query.
This class represents a function call, abstracting a target machine's calling convention.
static bool isWriteOnlyParam(const CallBase *Call, unsigned ArgIdx, const TargetLibraryInfo &TLI)
Returns true if this is a writeonly (i.e Mod only) parameter.
static bool isEscapeSource(const Value *V)
Returns true if the pointer is one which would have been considered an escape by isNonEscapingLocalOb...
An immutable pass that tracks lazily created AssumptionCache objects.
const Value * getTrueValue() const
The two locations do not alias at all.
ModRefInfo getArgModRefInfo(const CallBase *Call, unsigned ArgIdx)
unsigned getPointerAddressSpace() const
Method to return the address space of the pointer operand.
A cache of @llvm.assume calls within a function.
bool RoundToAlign
Whether to round the result up to the alignment of allocas, byval arguments, and global variables...
This is the AA result object for the basic, local, and stateless alias analysis.
bool sgt(const APInt &RHS) const
Signed greater than comparison.
APInt trunc(unsigned width) const
Truncate to new width.
unsigned getPointerSizeInBits(unsigned AS=0) const
Layout pointer size, in bits FIXME: The defaults need to be removed once all of the backends/clients ...
STATISTIC(NumFunctions, "Total number of functions")
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Analysis pass which computes a DominatorTree.
bool isNoAliasCall(const Value *V)
Return true if this pointer is returned by a noalias function.
block Block Frequency true
APInt zextOrTrunc(unsigned width) const
Zero extend or truncate to width.
const ValueSet & getValuesForPhi(const PHINode *PN)
Get the underlying values of a phi.
User::op_iterator data_operands_begin()
data_operands_begin/data_operands_end - Return iterators iterating over the call / invoke argument li...
ModRefInfo getArgModRefInfo(const CallBase *Call, unsigned ArgIdx)
Get the location associated with a pointer argument of a callsite.
LLVM_NODISCARD bool isModAndRefSet(const ModRefInfo MRI)
The analysis pass which yields a PhiValues.
unsigned getBitWidth() const
getBitWidth - Return the bitwidth of this constant.
unsigned getBitWidth() const
Return the number of bits in the APInt.
This indicates that the function could not be classified into one of the behaviors above...
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
bool doesNotCapture(unsigned OpNo) const
Determine whether this data operand is not captured.
AnalysisUsage & addRequired()
The only memory references in this function (if it has any) are references of memory that is otherwis...
Used to lazily calculate structure layout information for a target machine, based on the DataLayout s...
#define INITIALIZE_PASS_DEPENDENCY(depName)
static cl::opt< bool > ForceAtLeast64Bits("basicaa-force-at-least-64b", cl::Hidden, cl::init(true))
By default, even on 32-bit architectures we use 64-bit integers for calculations. ...
bool onlyAccessesInaccessibleMemory() const
Determine if the function may only access memory that is inaccessible from the IR.
This class represents the LLVM 'select' instruction.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
bool onlyAccessesArgMemory() const
Determine if the call can access memmory only using pointers based on its arguments.
Class to represent struct types.
APInt zextOrSelf(unsigned width) const
Zero extend or truncate to width.
bool pointsToConstantMemory(const MemoryLocation &Loc, AAQueryInfo &AAQI, bool OrLocal)
A Use represents the edge between a Value definition and its users.
Type * getPointerOperandType() const
Method to return the pointer operand as a PointerType.
const unsigned MaxNumPhiBBsValueReachabilityCheck
Cutoff after which to stop analysing a set of phi nodes potentially involved in a cycle...
bool runOnFunction(Function &F) override
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass...
bool isIntegerTy() const
True if this is an instance of IntegerType.
The access may reference the value stored in memory.
This file contains the simple types necessary to represent the attributes associated with functions a...
bool MaskedValueIsZero(const Value *V, const APInt &Mask, const DataLayout &DL, unsigned Depth=0, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true)
Return true if 'V & Mask' is known to be zero.
static AliasResult MergeAliasResults(AliasResult A, AliasResult B)
Analysis pass that exposes the LoopInfo for a function.
The function may perform non-volatile loads and stores of objects pointed to by its pointer-typed arg...
bool paramHasAttr(unsigned ArgNo, Attribute::AttrKind Kind) const
Determine whether the argument or parameter has the given attribute.
static uint64_t getMinimalExtentFrom(const Value &V, const LocationSize &LocSize, const DataLayout &DL, bool NullIsValidLoc)
Return the minimal extent from V to the end of the underlying object, assuming the result is used in ...
This file implements a class to represent arbitrary precision integral constant values and operations...
bool onlyAccessesInaccessibleMemory() const
Determine if the function may only access memory that is inaccessible from the IR.
bool isIdentifiedObject(const Value *V)
Return true if this pointer refers to a distinct and identifiable object.
place backedge safepoints impl
unsigned getActiveBits() const
Compute the number of active bits in the value.
LLVM_NODISCARD ModRefInfo setRef(const ModRefInfo MRI)
static APInt adjustToPointerSize(APInt Offset, unsigned PointerSize)
To ensure a pointer offset fits in an integer of size PointerSize (in bits) when that size is smaller...
Type * getType() const
All values are typed, get the type of this value.
TypeSize getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type...
static MemoryLocation getForDest(const MemIntrinsic *MI)
Return a location representing the destination of a memory set or transfer.
unsigned getNumIndices() const
static cl::opt< bool > EnableRecPhiAnalysis("basicaa-recphi", cl::Hidden, cl::init(false))
Enable analysis of recursive PHI nodes.
bool isInBounds() const
Test whether this is an inbounds GEP, as defined by LangRef.html.
APInt sextOrTrunc(unsigned width) const
Sign extend or truncate to width.
FunctionModRefBehavior
Summary of how a function affects memory in the program.
bool has(LibFunc F) const
Tests whether a library function is available.
const APInt & getValue() const
Return the constant as an APInt value reference.
Wrapper pass for the legacy pass manager.
AnalysisType & getAnalysis() const
getAnalysis<AnalysisType>() - This function is used by subclasses to get to the analysis information ...
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Value * getOperand(unsigned i) const
unsigned getMaxPointerSizeInBits() const
Returns the maximum pointer size over all address spaces.
AliasResult
The possible results of an alias query.
BasicAAResult(const DataLayout &DL, const Function &F, const TargetLibraryInfo &TLI, AssumptionCache &AC, DominatorTree *DT=nullptr, LoopInfo *LI=nullptr, PhiValues *PV=nullptr)
static AliasResult aliasSameBasePointerGEPs(const GEPOperator *GEP1, LocationSize MaybeV1Size, const GEPOperator *GEP2, LocationSize MaybeV2Size, const DataLayout &DL)
Provide ad-hoc rules to disambiguate accesses through two GEP operators, both having the exact same p...
iterator find(const_arg_type_t< KeyT > Val)
bool isNegative() const
Returns true if this value is known to be negative.
bool doesNotAccessMemory() const
Determine if the function does not access memory.
uint64_t getValue() const
initializer< Ty > init(const Ty &Val)
FunctionModRefBehavior getModRefBehavior(const CallBase *Call)
Returns the behavior when calling the given call site.
LLVM_NODISCARD ModRefInfo setMust(const ModRefInfo MRI)
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
A set of analyses that are preserved following a run of a transformation pass.
TypeSize getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
bool ult(const APInt &RHS) const
Unsigned less than comparison.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
LLVM_NODISCARD bool empty() const
This file contains the declarations for the subclasses of Constant, which represent the different fla...
bool isPointerTy() const
True if this is an instance of PointerType.
TypeSize getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Represent the analysis usage information of a pass.
FunctionModRefBehavior getModRefBehavior(const CallBase *Call)
IsCapturedCacheT IsCapturedCache
The only memory references in this function (if it has any) are non-volatile loads and stores from ob...
Value * getPointerOperand()
FunctionPass class - This class is used to implement most global optimizations.
LocationSize Size
The maximum size of the location, in address-units, or UnknownSize if the size is not known...
unsigned getAddressSpace() const
Return the address space of the Pointer type.
bool onlyAccessesInaccessibleMemOrArgMem() const
Determine if the function may only access memory that is either inaccessible from the IR or pointed t...
const Value * getCondition() const
Type * getIndexedType() const
std::pair< MemoryLocation, MemoryLocation > LocPair
iterator erase(const_iterator CI)
Value * getIncomingValue(unsigned i) const
Return incoming value number x.
Value * GetUnderlyingObject(Value *V, const DataLayout &DL, unsigned MaxLookup=6)
This method strips off any GEP address adjustments and pointer casts from the specified value...
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
This function does not perform any non-local loads or stores to memory.
std::pair< iterator, bool > try_emplace(KeyT &&Key, Ts &&... Args)
bool isByValArgument(unsigned ArgNo) const
Determine whether this argument is passed by value.
bool invalidate(Function &Fn, const PreservedAnalyses &PA, FunctionAnalysisManager::Invalidator &Inv)
Handle invalidation events in the new pass manager.
const APInt & umin(const APInt &A, const APInt &B)
Determine the smaller of two APInts considered to be signed.
bool isIdentifiedFunctionLocal(const Value *V)
Return true if V is umabigously identified at the function-level.
The two locations may or may not alias. This is the least precise result.
Intrinsic::ID getIntrinsicID() const
Return the intrinsic ID of this intrinsic.
const Value * Ptr
The address of the start of the location.
Representation for a specific memory location.
The two locations precisely alias each other.
A function analysis which provides an AssumptionCache.
unsigned getNumOperands() const
StructType * getStructTypeOrNull() const
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
This is the shared class of boolean and integer constants.
const Value * getArgumentAliasingToReturnedPointer(const CallBase *Call, bool MustPreserveNullness)
This function returns call pointer argument that is considered the same by aliasing rules...
Align max(MaybeAlign Lhs, Align Rhs)
LLVM_NODISCARD ModRefInfo setMod(const ModRefInfo MRI)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
This is a utility class that provides an abstraction for the common functionality between Instruction...
Provides information about what library functions are available for the current target.
A constant pointer value that points to null.
A collection of metadata nodes that might be associated with a memory access used by the alias-analys...
uint64_t getPointerDereferenceableBytes(const DataLayout &DL, bool &CanBeNull) const
Returns the number of bytes known to be dereferenceable for the pointer value.
LLVM_NODISCARD T pop_back_val()
uint64_t getSizeInBytes() const
unsigned getNumIncomingValues() const
Return the number of incoming edges.
bool uge(const APInt &RHS) const
Unsigned greater or equal comparison.
const Value * stripPointerCastsAndInvariantGroups() const
Strip off pointer casts, all-zero GEPs and invariant group info.
bool NullPointerIsDefined(const Function *F, unsigned AS=0)
Check whether null pointer dereferencing is considered undefined behavior for a given function or an ...
This function does not perform any non-local stores or volatile loads, but may read from any memory l...
The access may modify the value stored in memory.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Class for arbitrary precision integers.
static bool notDifferentParent(const Value *O1, const Value *O2)
FunctionPass * createBasicAAWrapperPass()
void setPreservesAll()
Set by analyses that do not transform their input at all.
bool sge(const APInt &RHS) const
Signed greater or equal comparison.
LLVM_NODISCARD bool isNoModRef(const ModRefInfo MRI)
bool getLibFunc(StringRef funcName, LibFunc &F) const
Searches for a particular function name.
const Value * getFalseValue() const
ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc, AAQueryInfo &AAQI)
Checks to see if the specified callsite can clobber the specified memory object.
LLVM_NODISCARD bool isModSet(const ModRefInfo MRI)
AAMDNodes AATags
The metadata nodes which describes the aliasing of the location (each member is null if that kind of ...
unsigned getNumArgOperands() const
bool intersects(const APInt &RHS) const
This operation tests if there are any pairs of corresponding bits between this APInt and RHS that are...
static bool isObjectSmallerThan(const Value *V, uint64_t Size, const DataLayout &DL, const TargetLibraryInfo &TLI, bool NullIsValidLoc)
Returns true if we can prove that the object specified by V is smaller than Size. ...
uint64_t getElementOffset(unsigned Idx) const
static Type * getIndexedType(Type *Ty, ArrayRef< Value *> IdxList)
Returns the type of the element that would be loaded with a load instruction with the specified param...
static bool isObjectSize(const Value *V, uint64_t Size, const DataLayout &DL, const TargetLibraryInfo &TLI, bool NullIsValidLoc)
Returns true if we can prove that the object specified by V has size Size.
unsigned getIntegerBitWidth() const
LLVM_NODISCARD bool empty() const
uint64_t getLimitedValue(uint64_t Limit=UINT64_MAX) const
If this value is smaller than the specified limit, return it, otherwise return the limit value...
bool isMallocOrCallocLikeFn(const Value *V, const TargetLibraryInfo *TLI, bool LookThroughBitCast=false)
Tests if a value is a call or invoke to a library function that allocates memory similar to malloc or...
This file provides utility analysis objects describing memory locations.
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation.
bool isKnownNonEqual(const Value *V1, const Value *V2, const DataLayout &DL, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr, bool UseInstrInfo=true)
Return true if the given values are known to be non-equal when defined.
bool onlyReadsMemory(unsigned OpNo) const
AAResultsProxy getBestAAResults()
Get a proxy for the best AA result set to query at this time.
bool onlyAccessesArgMemory() const
Determine if the call can access memmory only using pointers based on its arguments.
bool doesNotReadMemory() const
Determine if the function does not access or only writes memory.
PassT::Result * getCachedResult(IRUnitT &IR) const
Get the cached result of an analysis pass for a given IR unit.
bool onlyAccessesInaccessibleMemOrArgMem() const
Determine if the function may only access memory that is either inaccessible from the IR or pointed t...
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 doesNotReadMemory(unsigned OpNo) const
BasicAAResult run(Function &F, FunctionAnalysisManager &AM)
API to communicate dependencies between analyses during invalidation.
Analysis pass providing the TargetLibraryInfo.
AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB, AAQueryInfo &AAQI)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
unsigned getMinSignedBits() const
Get the minimum bit size for this signed APInt.
AnalysisUsage & addUsedIfAvailable()
Add the specified Pass class to the set of analyses used by this pass.
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
unsigned getOpcode() const
Return the opcode for this Instruction or ConstantExpr.
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
static const Function * getParent(const Value *V)
LLVM_NODISCARD ModRefInfo createModRefInfo(const FunctionModRefBehavior FMRB)
ModRefInfo
Flags indicating whether a memory access modifies or references memory.
static bool isNonEscapingLocalObject(const Value *V, SmallDenseMap< const Value *, bool, 8 > *IsCapturedCache=nullptr)
Returns true if the pointer is to a function-local object that never escapes from the function...
This is the interface for LLVM's primary stateless and local alias analysis.
Various options to control the behavior of getObjectSize.
static unsigned getMaxPointerSize(const DataLayout &DL)
Type * getSourceElementType() const
bool isNonNegative() const
Returns true if this value is known to be non-negative.
A container for analyses that lazily runs them and caches their results.
Legacy analysis pass which computes a DominatorTree.
INITIALIZE_PASS_BEGIN(BasicAAWrapperPass, "basicaa", "Basic Alias Analysis (stateless AA impl)", false, true) INITIALIZE_PASS_END(BasicAAWrapperPass
The two locations alias, but only due to a partial overlap.
op_range incoming_values()
Value * SimplifyInstruction(Instruction *I, const SimplifyQuery &Q, OptimizationRemarkEmitter *ORE=nullptr)
See if we can compute a simplified version of this instruction.
AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB, AAQueryInfo &AAQI)
ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc, AAQueryInfo &AAQI)
A special type used by analysis passes to provide an address that identifies that particular analysis...
APInt sextOrSelf(unsigned width) const
Sign extend or truncate to width.
PointerType * getType() const
Global values are always pointers.
A wrapper class for inspecting calls to intrinsic functions.
void initializeBasicAAWrapperPassPass(PassRegistry &)
const BasicBlock * getParent() const
Legacy wrapper pass to provide the BasicAAResult object.
gep_type_iterator gep_type_begin(const User *GEP)
bool PointerMayBeCaptured(const Value *V, bool ReturnCaptures, bool StoreCaptures, unsigned MaxUsesToExplore=DefaultMaxUsesToExplore)
PointerMayBeCaptured - Return true if this pointer value may be captured by the enclosing function (w...
static MemoryLocation getForSource(const MemTransferInst *MTI)
Return a location representing the source of a memory transfer.