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");
133 if (
const Argument *A = dyn_cast<Argument>(V))
134 if (A->hasByValAttr() || A->hasNoAliasAttr())
146 if (isa<CallBase>(V))
149 if (isa<Argument>(V))
155 if (isa<LoadInst>(V))
165 bool RoundToAlign =
false) {
180 bool NullIsValidLoc) {
212 uint64_t ObjectSize =
getObjectSize(V, DL, TLI, NullIsValidLoc,
221 uint64_t ObjectSize =
getObjectSize(V, DL, TLI, NullIsValidLoc);
239 const Value *BasicAAResult::GetLinearExpression(
252 if (
const ConstantInt *Const = dyn_cast<ConstantInt>(V)) {
258 Offset += Const->getValue().zextOrSelf(Offset.
getBitWidth());
259 assert(Scale == 0 &&
"Constant values don't have a scale");
264 if (
ConstantInt *RHSC = dyn_cast<ConstantInt>(BOp->getOperand(1))) {
270 switch (BOp->getOpcode()) {
277 case Instruction::Or:
288 V = GetLinearExpression(BOp->getOperand(0), Scale,
Offset, ZExtBits,
289 SExtBits, DL, Depth + 1, AC, DT, NSW, NUW);
292 case Instruction::Sub:
293 V = GetLinearExpression(BOp->getOperand(0), Scale,
Offset, ZExtBits,
294 SExtBits, DL, Depth + 1, AC, DT, NSW, NUW);
297 case Instruction::Mul:
298 V = GetLinearExpression(BOp->getOperand(0), Scale,
Offset, ZExtBits,
299 SExtBits, DL, Depth + 1, AC, DT, NSW, NUW);
303 case Instruction::Shl:
304 V = GetLinearExpression(BOp->getOperand(0), Scale,
Offset, ZExtBits,
305 SExtBits, DL, Depth + 1, AC, DT, NSW, NUW);
327 if (isa<OverflowingBinaryOperator>(BOp)) {
328 NUW &= BOp->hasNoUnsignedWrap();
329 NSW &= BOp->hasNoSignedWrap();
338 if (isa<SExtInst>(V) || isa<ZExtInst>(V)) {
339 Value *CastOp = cast<CastInst>(V)->getOperand(0);
342 unsigned OldZExtBits = ZExtBits, OldSExtBits = SExtBits;
343 const Value *Result =
344 GetLinearExpression(CastOp, Scale, Offset, ZExtBits, SExtBits, DL,
345 Depth + 1, AC, DT, NSW, NUW);
349 unsigned ExtendedBy = NewWidth - SmallWidth;
351 if (isa<SExtInst>(V) && ZExtBits == 0) {
365 ZExtBits = OldZExtBits;
366 SExtBits = OldSExtBits;
368 SExtBits += ExtendedBy;
378 ZExtBits = OldZExtBits;
379 SExtBits = OldSExtBits;
381 ZExtBits += ExtendedBy;
399 unsigned ShiftBits = Offset.
getBitWidth() - PointerSize;
400 return (Offset << ShiftBits).ashr(ShiftBits);
408 return MaxPointerSize;
424 bool BasicAAResult::DecomposeGEPExpression(
const Value *V,
432 Decomposed.VarIndices.clear();
438 if (
const GlobalAlias *GA = dyn_cast<GlobalAlias>(V)) {
439 if (!GA->isInterposable()) {
440 V = GA->getAliasee();
448 if (Op->
getOpcode() == Instruction::BitCast ||
449 Op->
getOpcode() == Instruction::AddrSpaceCast) {
456 if (
const auto *Call = dyn_cast<CallBase>(V)) {
500 bool GepHasConstantOffset =
true;
502 I !=
E; ++
I, ++GTI) {
507 unsigned FieldNo = cast<ConstantInt>(
Index)->getZExtValue();
511 Decomposed.StructOffset +=
517 if (
const ConstantInt *CIdx = dyn_cast<ConstantInt>(Index)) {
520 Decomposed.OtherOffset +=
522 CIdx->getValue().sextOrSelf(MaxPointerSize))
523 .sextOrTrunc(MaxPointerSize);
527 GepHasConstantOffset =
false;
530 unsigned ZExtBits = 0, SExtBits = 0;
535 if (PointerSize > Width)
536 SExtBits += PointerSize - Width;
539 APInt IndexScale(Width, 0), IndexOffset(Width, 0);
540 bool NSW =
true, NUW =
true;
542 Index = GetLinearExpression(Index, IndexScale, IndexOffset, ZExtBits,
543 SExtBits, DL, 0, AC, DT, NSW, NUW);
556 Scale.
sext(MaxPointerSize*2);
562 ZExtBits = SExtBits = 0;
563 if (PointerSize > Width)
564 SExtBits += PointerSize - Width;
566 Decomposed.OtherOffset += IndexOffset.
sextOrTrunc(MaxPointerSize) * Scale;
574 for (
unsigned i = 0, e = Decomposed.VarIndices.size(); i != e; ++i) {
575 if (Decomposed.VarIndices[i].V == Index &&
576 Decomposed.VarIndices[i].ZExtBits == ZExtBits &&
577 Decomposed.VarIndices[i].SExtBits == SExtBits) {
578 Scale += Decomposed.VarIndices[i].Scale;
579 Decomposed.VarIndices.erase(Decomposed.VarIndices.begin() + i);
589 VariableGEPIndex Entry = {
Index, ZExtBits, SExtBits, Scale};
590 Decomposed.VarIndices.push_back(Entry);
595 if (GepHasConstantOffset) {
596 Decomposed.StructOffset =
598 Decomposed.OtherOffset =
604 }
while (--MaxLookup);
608 SearchLimitReached++;
617 assert(Visited.empty() &&
"Visited must be cleared after use!");
619 unsigned MaxLookup = 8;
624 if (!Visited.insert(V).second) {
630 if (OrLocal && isa<AllocaInst>(V))
638 if (!GV->isConstant()) {
654 if (
const PHINode *PN = dyn_cast<PHINode>(V)) {
656 if (PN->getNumIncomingValues() > MaxLookup) {
660 for (
Value *IncValue : PN->incoming_values())
668 }
while (!Worklist.
empty() && --MaxLookup);
671 return Worklist.
empty();
747 F == LibFunc_memset_pattern16 && TLI.
has(F))
780 if (
const Instruction *inst = dyn_cast<Instruction>(V)) {
781 if (!inst->getParent())
786 if (
const Argument *arg = dyn_cast<Argument>(V))
787 return arg->getParent();
797 return !F1 || !F2 || F1 == F2;
804 "BasicAliasAnalysis doesn't support interprocedural queries.");
809 auto CacheIt = AliasCache.
find(LocPair(LocA, LocB));
810 if (CacheIt != AliasCache.
end())
811 return CacheIt->second;
820 VisitedPhiBBs.
clear();
833 "AliasAnalysis query involving multiple functions!");
842 if (isa<AllocaInst>(Object))
843 if (
const CallInst *CI = dyn_cast<CallInst>(Call))
844 if (CI->isTailCall() &&
850 if (
auto *AI = dyn_cast<AllocaInst>(Object))
857 if (!isa<Constant>(Object) && Call != Object &&
863 bool IsMustAlias =
true;
865 unsigned OperandNo = 0;
867 CI != CE; ++CI, ++OperandNo) {
871 if (!(*CI)->getType()->isPointerTy() ||
939 if (
auto *Inst = dyn_cast<AnyMemCpyInst>(Call)) {
1050 "Expected GEPs with the same pointer operand");
1065 const uint64_t V1Size = MaybeV1Size.
getValue();
1066 const uint64_t V2Size = MaybeV2Size.
getValue();
1095 for (
unsigned i = 1, e = GEP1->
getNumIndices() - 1; i != e; ++i) {
1106 if (isa<SequentialType>(Ty)) {
1118 const uint64_t ElementSize =
1120 if (V1Size != ElementSize || V2Size != ElementSize)
1123 for (
unsigned i = 0, e = GEP1->
getNumIndices() - 1; i != e; ++i)
1140 if (isa<PHINode>(GEP1LastIdx) || isa<PHINode>(GEP2LastIdx)) {
1147 if (GEP1LastIdx != GEP2LastIdx &&
1159 }
else if (!LastIndexedStruct || !C1 || !C2) {
1185 auto EltsDontOverlap = [StructSize](uint64_t V1Off, uint64_t V1Size,
1186 uint64_t V2Off, uint64_t V2Size) {
1187 return V1Off < V2Off && V1Off + V1Size <= V2Off &&
1188 ((V2Off + V2Size <= StructSize) ||
1189 (V2Off + V2Size - StructSize <= V1Off));
1192 if (EltsDontOverlap(V1Off, V1Size, V2Off, V2Size) ||
1193 EltsDontOverlap(V2Off, V2Size, V1Off, V1Size))
1230 bool BasicAAResult::isGEPBaseAtNegativeOffset(
const GEPOperator *GEPOp,
1231 const DecomposedGEP &DecompGEP,
const DecomposedGEP &DecompObject,
1237 const uint64_t ObjectAccessSize = MaybeObjectAccessSize.
getValue();
1242 if (!(isa<AllocaInst>(DecompObject.Base) ||
1243 isa<GlobalVariable>(DecompObject.Base)) ||
1244 !DecompObject.VarIndices.empty())
1247 APInt ObjectBaseOffset = DecompObject.StructOffset +
1248 DecompObject.OtherOffset;
1254 if (!DecompGEP.VarIndices.empty())
1257 APInt GEPBaseOffset = DecompGEP.StructOffset;
1258 GEPBaseOffset += DecompGEP.OtherOffset;
1260 return GEPBaseOffset.
sge(ObjectBaseOffset + (int64_t)ObjectAccessSize);
1273 const Value *UnderlyingV1,
const Value *UnderlyingV2) {
1274 DecomposedGEP DecompGEP1, DecompGEP2;
1276 DecompGEP1.StructOffset = DecompGEP1.OtherOffset =
APInt(MaxPointerSize, 0);
1277 DecompGEP2.StructOffset = DecompGEP2.OtherOffset =
APInt(MaxPointerSize, 0);
1279 bool GEP1MaxLookupReached =
1280 DecomposeGEPExpression(GEP1, DecompGEP1, DL, &AC, DT);
1281 bool GEP2MaxLookupReached =
1282 DecomposeGEPExpression(V2, DecompGEP2, DL, &AC, DT);
1284 APInt GEP1BaseOffset = DecompGEP1.StructOffset + DecompGEP1.OtherOffset;
1285 APInt GEP2BaseOffset = DecompGEP2.StructOffset + DecompGEP2.OtherOffset;
1287 assert(DecompGEP1.Base == UnderlyingV1 && DecompGEP2.Base == UnderlyingV2 &&
1288 "DecomposeGEPExpression returned a result different from " 1289 "GetUnderlyingObject");
1294 if (!GEP1MaxLookupReached && !GEP2MaxLookupReached &&
1295 isGEPBaseAtNegativeOffset(GEP1, DecompGEP1, DecompGEP2, V2Size))
1300 if (
const GEPOperator *GEP2 = dyn_cast<GEPOperator>(V2)) {
1303 if (!GEP1MaxLookupReached && !GEP2MaxLookupReached &&
1304 isGEPBaseAtNegativeOffset(GEP2, DecompGEP2, DecompGEP1, V1Size))
1313 if ((BaseAlias ==
MayAlias) && V1Size == V2Size) {
1315 AliasResult PreciseBaseAlias = aliasCheck(UnderlyingV1, V1Size, V1AAInfo,
1316 UnderlyingV2, V2Size, V2AAInfo);
1317 if (PreciseBaseAlias ==
NoAlias) {
1321 if (GEP2MaxLookupReached || GEP1MaxLookupReached)
1325 if (GEP1BaseOffset == GEP2BaseOffset &&
1326 DecompGEP1.VarIndices == DecompGEP2.VarIndices)
1354 if (GEP2MaxLookupReached || GEP1MaxLookupReached)
1359 GEP1BaseOffset -= GEP2BaseOffset;
1360 GetIndexDifference(DecompGEP1.VarIndices, DecompGEP2.VarIndices);
1385 if (GEP1MaxLookupReached)
1395 if (GEP1BaseOffset == 0 && DecompGEP1.VarIndices.empty())
1402 if (GEP1BaseOffset != 0 && DecompGEP1.VarIndices.empty()) {
1403 if (GEP1BaseOffset.
sge(0)) {
1420 if ((-GEP1BaseOffset).ult(V1Size.
getValue()))
1427 if (!DecompGEP1.VarIndices.empty()) {
1428 APInt Modulo(MaxPointerSize, 0);
1429 bool AllPositive =
true;
1430 for (
unsigned i = 0, e = DecompGEP1.VarIndices.size(); i != e; ++i) {
1436 Modulo |= DecompGEP1.VarIndices[i].Scale;
1442 const Value *V = DecompGEP1.VarIndices[i].V;
1450 bool IsZExt = DecompGEP1.VarIndices[i].ZExtBits > 0 || isa<ZExtInst>(V);
1451 SignKnownZero |= IsZExt;
1452 SignKnownOne &= !IsZExt;
1457 APInt Scale = DecompGEP1.VarIndices[i].Scale;
1459 (SignKnownZero && Scale.
sge(0)) || (SignKnownOne && Scale.
slt(0));
1463 Modulo = Modulo ^ (Modulo & (Modulo - 1));
1468 APInt ModOffset = GEP1BaseOffset & (Modulo - 1);
1471 (Modulo - ModOffset).uge(V1Size.
getValue()))
1477 if (AllPositive && GEP1BaseOffset.
sgt(0) &&
1482 if (constantOffsetHeuristic(DecompGEP1.VarIndices, V1Size, V2Size,
1483 GEP1BaseOffset, &AC, DT))
1512 const Value *UnderV2) {
1515 if (
const SelectInst *SI2 = dyn_cast<SelectInst>(V2))
1518 SI2->getTrueValue(), V2Size, V2AAInfo);
1523 SI2->getFalseValue(), V2Size, V2AAInfo);
1531 SISize, SIAAInfo, UnderV2);
1536 aliasCheck(V2, V2Size, V2AAInfo, SI->
getFalseValue(), SISize, SIAAInfo,
1547 const Value *UnderV2) {
1555 if (
const PHINode *PN2 = dyn_cast<PHINode>(V2))
1556 if (PN2->getParent() == PN->
getParent()) {
1570 "There must exist an entry for the phi node");
1586 AliasCache[Locs] = OrigAliasResult;
1592 bool isRecursive =
false;
1603 for (
Value *PV1 : PhiValueSet) {
1605 if (
GEPOperator *PV1GEP = dyn_cast<GEPOperator>(PV1)) {
1610 if (PV1GEP->getPointerOperand() == PN && PV1GEP->getNumIndices() == 1 &&
1611 isa<ConstantInt>(PV1GEP->idx_begin())) {
1624 if (isa<PHINode>(PV1))
1632 if (
GEPOperator *PV1GEP = dyn_cast<GEPOperator>(PV1)) {
1637 if (PV1GEP->getPointerOperand() == PN && PV1GEP->getNumIndices() == 1 &&
1638 isa<ConstantInt>(PV1GEP->idx_begin())) {
1644 if (UniqueSrc.
insert(PV1).second)
1662 aliasCheck(V2, V2Size, V2AAInfo, V1Srcs[0],
1663 PNSize, PNAAInfo, UnderV2);
1672 for (
unsigned i = 1, e = V1Srcs.
size(); i != e; ++i) {
1673 Value *V = V1Srcs[i];
1676 aliasCheck(V2, V2Size, V2AAInfo, V, PNSize, PNAAInfo, UnderV2);
1702 if (isa<UndefValue>(V1) || isa<UndefValue>(V2))
1711 if (isValueEqualInPotentialCycles(V1, V2))
1768 NullIsValidLocation)) ||
1770 NullIsValidLocation)))
1779 std::pair<AliasCacheTy::iterator, bool> Pair =
1782 return Pair.first->second;
1786 if (!isa<GEPOperator>(V1) && isa<GEPOperator>(V2)) {
1792 if (
const GEPOperator *GV1 = dyn_cast<GEPOperator>(V1)) {
1794 aliasGEP(GV1, V1Size, V1AAInfo, V2, V2Size, V2AAInfo, O1, O2);
1796 return AliasCache[Locs] = Result;
1799 if (isa<PHINode>(V2) && !isa<PHINode>(V1)) {
1805 if (
const PHINode *PN = dyn_cast<PHINode>(V1)) {
1806 AliasResult Result = aliasPHI(PN, V1Size, V1AAInfo,
1807 V2, V2Size, V2AAInfo, O2);
1809 return AliasCache[Locs] = Result;
1812 if (isa<SelectInst>(V2) && !isa<SelectInst>(V1)) {
1818 if (
const SelectInst *S1 = dyn_cast<SelectInst>(V1)) {
1820 aliasSelect(S1, V1Size, V1AAInfo, V2, V2Size, V2AAInfo, O2);
1822 return AliasCache[Locs] = Result;
1837 return AliasCache[Locs] = Result;
1847 bool BasicAAResult::isValueEqualInPotentialCycles(
const Value *V,
1856 if (VisitedPhiBBs.
empty())
1865 for (
auto *
P : VisitedPhiBBs)
1876 void BasicAAResult::GetIndexDifference(
1882 for (
unsigned i = 0, e = Src.
size(); i != e; ++i) {
1883 const Value *V = Src[i].V;
1884 unsigned ZExtBits = Src[i].ZExtBits, SExtBits = Src[i].SExtBits;
1885 APInt Scale = Src[i].Scale;
1889 for (
unsigned j = 0, e = Dest.
size(); j != e; ++j) {
1890 if (!isValueEqualInPotentialCycles(Dest[j].V, V) ||
1891 Dest[j].ZExtBits != ZExtBits || Dest[j].SExtBits != SExtBits)
1896 if (Dest[j].Scale != Scale)
1897 Dest[j].Scale -= Scale;
1906 VariableGEPIndex Entry = {V, ZExtBits, SExtBits, -Scale};
1912 bool BasicAAResult::constantOffsetHeuristic(
1920 const uint64_t V1Size = MaybeV1Size.
getValue();
1921 const uint64_t V2Size = MaybeV2Size.
getValue();
1923 const VariableGEPIndex &Var0 = VarIndices[0], &Var1 = VarIndices[1];
1925 if (Var0.ZExtBits != Var1.ZExtBits || Var0.SExtBits != Var1.SExtBits ||
1926 Var0.Scale != -Var1.Scale)
1929 unsigned Width = Var1.V->getType()->getIntegerBitWidth();
1935 APInt V0Scale(Width, 0), V0Offset(Width, 0), V1Scale(Width, 0),
1937 bool NSW =
true, NUW =
true;
1938 unsigned V0ZExtBits = 0, V0SExtBits = 0, V1ZExtBits = 0, V1SExtBits = 0;
1939 const Value *V0 = GetLinearExpression(Var0.V, V0Scale, V0Offset, V0ZExtBits,
1940 V0SExtBits, DL, 0, AC, DT, NSW, NUW);
1943 const Value *V1 = GetLinearExpression(Var1.V, V1Scale, V1Offset, V1ZExtBits,
1944 V1SExtBits, DL, 0, AC, DT, NSW, NUW);
1946 if (V0Scale != V1Scale || V0ZExtBits != V1ZExtBits ||
1947 V0SExtBits != V1SExtBits || !isValueEqualInPotentialCycles(V0, V1))
1957 APInt MinDiff = V0Offset - V1Offset, Wrapped = -MinDiff;
1959 APInt MinDiffBytes =
1960 MinDiff.
zextOrTrunc(Var0.Scale.getBitWidth()) * Var0.Scale.
abs();
1966 return MinDiffBytes.
uge(V1Size + BaseOffset.
abs()) &&
1967 MinDiffBytes.
uge(V2Size + BaseOffset.
abs());
1992 void BasicAAWrapperPass::anchor() {}
1995 "Basic Alias Analysis (stateless AA impl)",
false,
true)
2007 auto &ACT = getAnalysis<AssumptionCacheTracker>();
2008 auto &TLIWP = getAnalysis<TargetLibraryInfoWrapperPass>();
2009 auto &DTWP = getAnalysis<DominatorTreeWrapperPass>();
2010 auto *LIWP = getAnalysisIfAvailable<LoopInfoWrapperPass>();
2011 auto *PVWP = getAnalysisIfAvailable<PhiValuesWrapperPass>();
2014 ACT.getAssumptionCache(F), &DTWP.getDomTree(),
2015 LIWP ? &LIWP->getLoopInfo() :
nullptr,
2016 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.
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...
Basic Alias Analysis(stateless AA impl)"
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.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
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 pointsToConstantMemory(const MemoryLocation &Loc, bool OrLocal)
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)
AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB)
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 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 greather 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.
bool pointsToConstantMemory(const MemoryLocation &Loc, bool OrLocal)
Chases pointers until we find a (constant global) or not.
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.
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.
AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB)
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.
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.
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.
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
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
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.
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)
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 isPotentiallyReachable(const Instruction *From, const Instruction *To, const DominatorTree *DT=nullptr, const LoopInfo *LI=nullptr)
Determine whether instruction 'To' is reachable from 'From', returning true if uncertain.
bool onlyAccessesInaccessibleMemOrArgMem() const
Determine if the function may only access memory that is either inaccessible from the IR or pointed t...
static bool isNonEscapingLocalObject(const Value *V)
Returns true if the pointer is to a function-local object that never escapes from the function...
const Value * getCondition() const
Type * getIndexedType() const
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.
const Value * getArgumentAliasingToReturnedPointer(const CallBase *Call)
This function returns call pointer argument that is considered the same by aliasing rules...
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.
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...
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, aliases 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...
ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc)
Checks to see if the specified callsite can clobber the specified memory object.
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
uint64_t getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
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
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
BasicAAResult run(Function &F, FunctionAnalysisManager &AM)
API to communicate dependencies between analyses during invalidation.
Analysis pass providing the TargetLibraryInfo.
ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc)
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.
unsigned getPrimitiveSizeInBits() const LLVM_READONLY
Return the basic size of this type if it is a primitive type.
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
uint64_t getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type...
unsigned getOpcode() const
Return the opcode for this Instruction or ConstantExpr.
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.
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.
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.