64 #define DEBUG_TYPE "basicaa" 74 STATISTIC(SearchLimitReached,
"Number of times the limit to " 75 "decompose GEPs is reached");
76 STATISTIC(SearchTimes,
"Number of times a GEP is decomposed");
124 if (
const Argument *A = dyn_cast<Argument>(V))
125 if (A->hasByValAttr() || A->hasNoAliasAttr())
140 if (isa<Argument>(V))
146 if (isa<LoadInst>(V))
156 bool RoundToAlign =
false) {
171 bool NullIsValidLoc) {
203 uint64_t ObjectSize =
getObjectSize(V, DL, TLI, NullIsValidLoc,
212 uint64_t ObjectSize =
getObjectSize(V, DL, TLI, NullIsValidLoc);
230 const Value *BasicAAResult::GetLinearExpression(
243 if (
const ConstantInt *Const = dyn_cast<ConstantInt>(V)) {
249 Offset += Const->getValue().zextOrSelf(Offset.
getBitWidth());
250 assert(Scale == 0 &&
"Constant values don't have a scale");
255 if (
ConstantInt *RHSC = dyn_cast<ConstantInt>(BOp->getOperand(1))) {
261 switch (BOp->getOpcode()) {
268 case Instruction::Or:
279 V = GetLinearExpression(BOp->getOperand(0), Scale,
Offset, ZExtBits,
280 SExtBits, DL, Depth + 1, AC, DT, NSW, NUW);
283 case Instruction::Sub:
284 V = GetLinearExpression(BOp->getOperand(0), Scale,
Offset, ZExtBits,
285 SExtBits, DL, Depth + 1, AC, DT, NSW, NUW);
288 case Instruction::Mul:
289 V = GetLinearExpression(BOp->getOperand(0), Scale,
Offset, ZExtBits,
290 SExtBits, DL, Depth + 1, AC, DT, NSW, NUW);
294 case Instruction::Shl:
295 V = GetLinearExpression(BOp->getOperand(0), Scale,
Offset, ZExtBits,
296 SExtBits, DL, Depth + 1, AC, DT, NSW, NUW);
318 if (isa<OverflowingBinaryOperator>(BOp)) {
319 NUW &= BOp->hasNoUnsignedWrap();
320 NSW &= BOp->hasNoSignedWrap();
329 if (isa<SExtInst>(V) || isa<ZExtInst>(V)) {
330 Value *CastOp = cast<CastInst>(V)->getOperand(0);
333 unsigned OldZExtBits = ZExtBits, OldSExtBits = SExtBits;
335 GetLinearExpression(CastOp, Scale, Offset, ZExtBits, SExtBits, DL,
336 Depth + 1, AC, DT, NSW, NUW);
340 unsigned ExtendedBy = NewWidth - SmallWidth;
342 if (isa<SExtInst>(V) && ZExtBits == 0) {
356 ZExtBits = OldZExtBits;
357 SExtBits = OldSExtBits;
359 SExtBits += ExtendedBy;
369 ZExtBits = OldZExtBits;
370 SExtBits = OldSExtBits;
372 ZExtBits += ExtendedBy;
388 assert(PointerSize <= 64 &&
"Invalid PointerSize!");
389 unsigned ShiftBits = 64 - PointerSize;
390 return (int64_t)((uint64_t)Offset << ShiftBits) >> ShiftBits;
406 bool BasicAAResult::DecomposeGEPExpression(
const Value *V,
413 Decomposed.StructOffset = 0;
414 Decomposed.OtherOffset = 0;
415 Decomposed.VarIndices.clear();
421 if (
const GlobalAlias *GA = dyn_cast<GlobalAlias>(V)) {
422 if (!GA->isInterposable()) {
423 V = GA->getAliasee();
431 if (Op->
getOpcode() == Instruction::BitCast ||
432 Op->
getOpcode() == Instruction::AddrSpaceCast) {
483 bool GepHasConstantOffset =
true;
485 I !=
E; ++
I, ++GTI) {
490 unsigned FieldNo = cast<ConstantInt>(
Index)->getZExtValue();
494 Decomposed.StructOffset +=
500 if (
const ConstantInt *CIdx = dyn_cast<ConstantInt>(Index)) {
503 Decomposed.OtherOffset +=
508 GepHasConstantOffset =
false;
511 unsigned ZExtBits = 0, SExtBits = 0;
516 if (PointerSize > Width)
517 SExtBits += PointerSize - Width;
520 APInt IndexScale(Width, 0), IndexOffset(Width, 0);
521 bool NSW =
true, NUW =
true;
522 Index = GetLinearExpression(Index, IndexScale, IndexOffset, ZExtBits,
523 SExtBits, DL, 0, AC, DT, NSW, NUW);
529 if (IndexScale.getBitWidth() > 64)
530 IndexScale = IndexScale.sextOrTrunc(64);
534 Decomposed.OtherOffset += IndexOffset.
getSExtValue() * Scale;
535 Scale *= IndexScale.getSExtValue();
541 for (
unsigned i = 0, e = Decomposed.VarIndices.size(); i != e; ++i) {
542 if (Decomposed.VarIndices[i].V == Index &&
543 Decomposed.VarIndices[i].ZExtBits == ZExtBits &&
544 Decomposed.VarIndices[i].SExtBits == SExtBits) {
545 Scale += Decomposed.VarIndices[i].Scale;
546 Decomposed.VarIndices.erase(Decomposed.VarIndices.begin() + i);
556 VariableGEPIndex Entry = {
Index, ZExtBits, SExtBits,
557 static_cast<int64_t
>(Scale)};
558 Decomposed.VarIndices.push_back(Entry);
563 if (GepHasConstantOffset) {
564 Decomposed.StructOffset =
566 Decomposed.OtherOffset =
572 }
while (--MaxLookup);
576 SearchLimitReached++;
585 assert(Visited.empty() &&
"Visited must be cleared after use!");
587 unsigned MaxLookup = 8;
592 if (!Visited.insert(V).second) {
598 if (OrLocal && isa<AllocaInst>(V))
606 if (!GV->isConstant()) {
622 if (
const PHINode *PN = dyn_cast<PHINode>(V)) {
624 if (PN->getNumIncomingValues() > MaxLookup) {
628 for (
Value *IncValue : PN->incoming_values())
636 }
while (!Worklist.
empty() && --MaxLookup);
639 return Worklist.
empty();
714 F == LibFunc_memset_pattern16 && TLI.
has(F))
747 if (
const Instruction *inst = dyn_cast<Instruction>(V)) {
748 if (!inst->getParent())
753 if (
const Argument *arg = dyn_cast<Argument>(V))
754 return arg->getParent();
764 return !F1 || !F2 || F1 == F2;
771 "BasicAliasAnalysis doesn't support interprocedural queries.");
776 auto CacheIt = AliasCache.
find(LocPair(LocA, LocB));
777 if (CacheIt != AliasCache.
end())
778 return CacheIt->second;
787 VisitedPhiBBs.
clear();
800 "AliasAnalysis query involving multiple functions!");
809 if (isa<AllocaInst>(Object))
811 if (CI->isTailCall() &&
812 !CI->getAttributes().hasAttrSomewhere(Attribute::ByVal))
824 bool IsMustAlias =
true;
826 unsigned OperandNo = 0;
828 CI != CE; ++CI, ++OperandNo) {
832 if (!(*CI)->getType()->isPointerTy() ||
1011 "Expected GEPs with the same pointer operand");
1049 for (
unsigned i = 1, e = GEP1->
getNumIndices() - 1; i != e; ++i) {
1060 if (isa<SequentialType>(Ty)) {
1072 const uint64_t ElementSize =
1074 if (V1Size != ElementSize || V2Size != ElementSize)
1077 for (
unsigned i = 0, e = GEP1->
getNumIndices() - 1; i != e; ++i)
1094 if (isa<PHINode>(GEP1LastIdx) || isa<PHINode>(GEP2LastIdx)) {
1101 if (GEP1LastIdx != GEP2LastIdx &&
1113 }
else if (!LastIndexedStruct || !C1 || !C2) {
1135 auto EltsDontOverlap = [StructSize](uint64_t V1Off, uint64_t V1Size,
1136 uint64_t V2Off, uint64_t V2Size) {
1137 return V1Off < V2Off && V1Off + V1Size <= V2Off &&
1138 ((V2Off + V2Size <= StructSize) ||
1139 (V2Off + V2Size - StructSize <= V1Off));
1142 if (EltsDontOverlap(V1Off, V1Size, V2Off, V2Size) ||
1143 EltsDontOverlap(V2Off, V2Size, V1Off, V1Size))
1180 bool BasicAAResult::isGEPBaseAtNegativeOffset(
const GEPOperator *GEPOp,
1181 const DecomposedGEP &DecompGEP,
const DecomposedGEP &DecompObject,
1190 if (!(isa<AllocaInst>(DecompObject.Base) ||
1191 isa<GlobalVariable>(DecompObject.Base)) ||
1192 !DecompObject.VarIndices.empty())
1195 int64_t ObjectBaseOffset = DecompObject.StructOffset +
1196 DecompObject.OtherOffset;
1202 if (!DecompGEP.VarIndices.empty())
1204 int64_t GEPBaseOffset = DecompGEP.StructOffset;
1205 GEPBaseOffset += DecompGEP.OtherOffset;
1207 return (GEPBaseOffset >= ObjectBaseOffset + (int64_t)ObjectAccessSize);
1220 const Value *UnderlyingV1,
const Value *UnderlyingV2) {
1221 DecomposedGEP DecompGEP1, DecompGEP2;
1222 bool GEP1MaxLookupReached =
1223 DecomposeGEPExpression(GEP1, DecompGEP1, DL, &AC, DT);
1224 bool GEP2MaxLookupReached =
1225 DecomposeGEPExpression(V2, DecompGEP2, DL, &AC, DT);
1227 int64_t GEP1BaseOffset = DecompGEP1.StructOffset + DecompGEP1.OtherOffset;
1228 int64_t GEP2BaseOffset = DecompGEP2.StructOffset + DecompGEP2.OtherOffset;
1230 assert(DecompGEP1.Base == UnderlyingV1 && DecompGEP2.Base == UnderlyingV2 &&
1231 "DecomposeGEPExpression returned a result different from " 1232 "GetUnderlyingObject");
1237 if (!GEP1MaxLookupReached && !GEP2MaxLookupReached &&
1238 isGEPBaseAtNegativeOffset(GEP1, DecompGEP1, DecompGEP2, V2Size))
1243 if (
const GEPOperator *GEP2 = dyn_cast<GEPOperator>(V2)) {
1246 if (!GEP1MaxLookupReached && !GEP2MaxLookupReached &&
1247 isGEPBaseAtNegativeOffset(GEP2, DecompGEP2, DecompGEP1, V1Size))
1256 if ((BaseAlias ==
MayAlias) && V1Size == V2Size) {
1258 AliasResult PreciseBaseAlias = aliasCheck(UnderlyingV1, V1Size, V1AAInfo,
1259 UnderlyingV2, V2Size, V2AAInfo);
1260 if (PreciseBaseAlias ==
NoAlias) {
1264 if (GEP2MaxLookupReached || GEP1MaxLookupReached)
1268 if (GEP1BaseOffset == GEP2BaseOffset &&
1269 DecompGEP1.VarIndices == DecompGEP2.VarIndices)
1297 if (GEP2MaxLookupReached || GEP1MaxLookupReached)
1302 GEP1BaseOffset -= GEP2BaseOffset;
1303 GetIndexDifference(DecompGEP1.VarIndices, DecompGEP2.VarIndices);
1317 V2AAInfo,
nullptr, UnderlyingV2);
1329 if (GEP1MaxLookupReached)
1339 if (GEP1BaseOffset == 0 && DecompGEP1.VarIndices.empty())
1346 if (GEP1BaseOffset != 0 && DecompGEP1.VarIndices.empty()) {
1347 if (GEP1BaseOffset >= 0) {
1349 if ((uint64_t)GEP1BaseOffset < V2Size)
1364 if (-(uint64_t)GEP1BaseOffset < V1Size)
1371 if (!DecompGEP1.VarIndices.empty()) {
1372 uint64_t Modulo = 0;
1373 bool AllPositive =
true;
1374 for (
unsigned i = 0, e = DecompGEP1.VarIndices.size(); i != e; ++i) {
1380 Modulo |= (uint64_t)DecompGEP1.VarIndices[i].Scale;
1386 const Value *V = DecompGEP1.VarIndices[i].V;
1394 bool IsZExt = DecompGEP1.VarIndices[i].ZExtBits > 0 || isa<ZExtInst>(V);
1395 SignKnownZero |= IsZExt;
1396 SignKnownOne &= !IsZExt;
1401 int64_t Scale = DecompGEP1.VarIndices[i].Scale;
1403 (SignKnownZero && Scale >= 0) || (SignKnownOne && Scale < 0);
1407 Modulo = Modulo ^ (Modulo & (Modulo - 1));
1412 uint64_t ModOffset = (uint64_t)GEP1BaseOffset & (Modulo - 1);
1415 V1Size <= Modulo - ModOffset)
1421 if (AllPositive && GEP1BaseOffset > 0 && V2Size <= (uint64_t)GEP1BaseOffset)
1424 if (constantOffsetHeuristic(DecompGEP1.VarIndices, V1Size, V2Size,
1425 GEP1BaseOffset, &AC, DT))
1454 const Value *UnderV2) {
1457 if (
const SelectInst *SI2 = dyn_cast<SelectInst>(V2))
1460 SI2->getTrueValue(), V2Size, V2AAInfo);
1465 SI2->getFalseValue(), V2Size, V2AAInfo);
1473 SISize, SIAAInfo, UnderV2);
1478 aliasCheck(V2, V2Size, V2AAInfo, SI->
getFalseValue(), SISize, SIAAInfo,
1489 const Value *UnderV2) {
1497 if (
const PHINode *PN2 = dyn_cast<PHINode>(V2))
1498 if (PN2->getParent() == PN->
getParent()) {
1512 "There must exist an entry for the phi node");
1528 AliasCache[Locs] = OrigAliasResult;
1534 bool isRecursive =
false;
1545 for (
Value *PV1 : PhiValueSet) {
1547 if (
GEPOperator *PV1GEP = dyn_cast<GEPOperator>(PV1)) {
1552 if (PV1GEP->getPointerOperand() == PN && PV1GEP->getNumIndices() == 1 &&
1553 isa<ConstantInt>(PV1GEP->idx_begin())) {
1566 if (isa<PHINode>(PV1))
1574 if (
GEPOperator *PV1GEP = dyn_cast<GEPOperator>(PV1)) {
1579 if (PV1GEP->getPointerOperand() == PN && PV1GEP->getNumIndices() == 1 &&
1580 isa<ConstantInt>(PV1GEP->idx_begin())) {
1586 if (UniqueSrc.
insert(PV1).second)
1604 aliasCheck(V2, V2Size, V2AAInfo, V1Srcs[0],
1605 PNSize, PNAAInfo, UnderV2);
1614 for (
unsigned i = 1, e = V1Srcs.
size(); i != e; ++i) {
1615 Value *V = V1Srcs[i];
1618 aliasCheck(V2, V2Size, V2AAInfo, V, PNSize, PNAAInfo, UnderV2);
1635 if (V1Size == 0 || V2Size == 0)
1644 if (isa<UndefValue>(V1) || isa<UndefValue>(V2))
1653 if (isValueEqualInPotentialCycles(V1, V2))
1721 std::pair<AliasCacheTy::iterator, bool> Pair =
1724 return Pair.first->second;
1728 if (!isa<GEPOperator>(V1) && isa<GEPOperator>(V2)) {
1734 if (
const GEPOperator *GV1 = dyn_cast<GEPOperator>(V1)) {
1736 aliasGEP(GV1, V1Size, V1AAInfo, V2, V2Size, V2AAInfo, O1, O2);
1738 return AliasCache[Locs] = Result;
1741 if (isa<PHINode>(V2) && !isa<PHINode>(V1)) {
1747 if (
const PHINode *PN = dyn_cast<PHINode>(V1)) {
1749 V2, V2Size, V2AAInfo, O2);
1751 return AliasCache[Locs] = Result;
1754 if (isa<SelectInst>(V2) && !isa<SelectInst>(V1)) {
1760 if (
const SelectInst *S1 = dyn_cast<SelectInst>(V1)) {
1762 aliasSelect(S1, V1Size, V1AAInfo, V2, V2Size, V2AAInfo, O2);
1764 return AliasCache[Locs] = Result;
1772 (
isObjectSize(O1, V1Size, DL, TLI, NullIsValidLocation) ||
1773 isObjectSize(O2, V2Size, DL, TLI, NullIsValidLocation)))
1780 return AliasCache[Locs] = Result;
1790 bool BasicAAResult::isValueEqualInPotentialCycles(
const Value *V,
1799 if (VisitedPhiBBs.
empty())
1808 for (
auto *
P : VisitedPhiBBs)
1819 void BasicAAResult::GetIndexDifference(
1825 for (
unsigned i = 0, e = Src.
size(); i != e; ++i) {
1826 const Value *V = Src[i].V;
1827 unsigned ZExtBits = Src[i].ZExtBits, SExtBits = Src[i].SExtBits;
1828 int64_t Scale = Src[i].Scale;
1832 for (
unsigned j = 0, e = Dest.
size(); j != e; ++j) {
1833 if (!isValueEqualInPotentialCycles(Dest[j].V, V) ||
1834 Dest[j].ZExtBits != ZExtBits || Dest[j].SExtBits != SExtBits)
1839 if (Dest[j].Scale != Scale)
1840 Dest[j].Scale -= Scale;
1849 VariableGEPIndex Entry = {V, ZExtBits, SExtBits, -Scale};
1855 bool BasicAAResult::constantOffsetHeuristic(
1863 const VariableGEPIndex &Var0 = VarIndices[0], &Var1 = VarIndices[1];
1865 if (Var0.ZExtBits != Var1.ZExtBits || Var0.SExtBits != Var1.SExtBits ||
1866 Var0.Scale != -Var1.Scale)
1869 unsigned Width = Var1.V->getType()->getIntegerBitWidth();
1875 APInt V0Scale(Width, 0), V0Offset(Width, 0), V1Scale(Width, 0),
1877 bool NSW =
true, NUW =
true;
1878 unsigned V0ZExtBits = 0, V0SExtBits = 0, V1ZExtBits = 0, V1SExtBits = 0;
1879 const Value *V0 = GetLinearExpression(Var0.V, V0Scale, V0Offset, V0ZExtBits,
1880 V0SExtBits, DL, 0, AC, DT, NSW, NUW);
1883 const Value *V1 = GetLinearExpression(Var1.V, V1Scale, V1Offset, V1ZExtBits,
1884 V1SExtBits, DL, 0, AC, DT, NSW, NUW);
1886 if (V0Scale != V1Scale || V0ZExtBits != V1ZExtBits ||
1887 V0SExtBits != V1SExtBits || !isValueEqualInPotentialCycles(V0, V1))
1897 APInt MinDiff = V0Offset - V1Offset, Wrapped = -MinDiff;
1905 return V1Size +
std::abs(BaseOffset) <= MinDiffBytes &&
1906 V2Size +
std::abs(BaseOffset) <= MinDiffBytes;
1931 void BasicAAWrapperPass::anchor() {}
1934 "Basic Alias Analysis (stateless AA impl)",
false,
true)
1946 auto &ACT = getAnalysis<AssumptionCacheTracker>();
1947 auto &TLIWP = getAnalysis<TargetLibraryInfoWrapperPass>();
1948 auto &DTWP = getAnalysis<DominatorTreeWrapperPass>();
1949 auto *LIWP = getAnalysisIfAvailable<LoopInfoWrapperPass>();
1950 auto *PVWP = getAnalysisIfAvailable<PhiValuesWrapperPass>();
1953 ACT.getAssumptionCache(F), &DTWP.getDomTree(),
1954 LIWP ? &LIWP->getLoopInfo() :
nullptr,
1955 PVWP ? &PVWP->getResult() :
nullptr));
The access may reference and may modify the value stored in memory.
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
void push_back(const T &Elt)
Basic Alias Analysis(stateless AA impl)"
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...
static bool isIntrinsicCall(ImmutableCallSite CS, Intrinsic::ID IID)
uint64_t getZExtValue() const
Get zero extended value.
APInt sext(unsigned width) const
Sign extend to a new width.
This class represents an incoming formal argument to a Function.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Compute iterated dominance frontiers using a linear time algorithm.
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)
bool onlyAccessesArgMemory() const
Determine if the call can access memmory only using pointers based on its arguments.
const StructLayout * getStructLayout(StructType *Ty) const
Returns a StructLayout object, indicating the alignment of the struct, its size, and the offsets of i...
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...
This class represents a function call, abstracting a target machine's calling convention.
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.
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.
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")
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
const ValueSet & getValuesForPhi(const PHINode *PN)
Get the underlying values of a phi.
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
Return the number of bits in the APInt.
This indicates that the function could not be classified into one of the behaviors above...
static AliasResult aliasSameBasePointerGEPs(const GEPOperator *GEP1, LocationSize V1Size, const GEPOperator *GEP2, LocationSize V2Size, const DataLayout &DL)
Provide ad-hoc rules to disambiguate accesses through two GEP operators, both having the exact same p...
bool onlyReadsMemory() const
Determine if the call does not access or only reads memory.
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
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)
This class represents the LLVM 'select' instruction.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
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...
InstrTy * getInstruction() const
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...
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
LLVM_NODISCARD ModRefInfo setRef(const ModRefInfo MRI)
IterTy data_operands_end() const
int64_t getSExtValue() const
Get sign extended value.
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.
FunctionModRefBehavior
Summary of how a function affects memory in the program.
bool has(LibFunc F) const
Tests whether a library function is available.
bool paramHasAttr(unsigned ArgNo, Attribute::AttrKind Kind) const
Return true if the call or the callee has the given attribute.
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
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)
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.
initializer< Ty > init(const Ty &Val)
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.
* if(!EatIfPresent(lltok::kw_thread_local)) return false
ParseOptionalThreadLocal := /*empty.
static bool isWriteOnlyParam(ImmutableCallSite CS, unsigned ArgIdx, const TargetLibraryInfo &TLI)
Returns true if this is a writeonly (i.e Mod only) parameter.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
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.
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)
Return true if 'V & Mask' is known to be zero.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
ModRefInfo getArgModRefInfo(ImmutableCallSite CS, unsigned ArgIdx)
FunctionModRefBehavior getModRefBehavior(ImmutableCallSite CS)
Returns the behavior when calling the given call site.
Represent the analysis usage information of a pass.
bool hasOperandBundles() const
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.
ModRefInfo getModRefInfo(ImmutableCallSite CS, const MemoryLocation &Loc)
Checks to see if the specified callsite can clobber the specified memory object.
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
bool doesNotCapture(unsigned OpNo) const
Determine whether this data operand is not captured.
Type * getIndexedType() const
iterator erase(const_iterator CI)
unsigned getNumArgOperands() const
bool PointerMayBeCaptured(const Value *V, bool ReturnCaptures, bool StoreCaptures)
PointerMayBeCaptured - Return true if this pointer value may be captured by the enclosing function (w...
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.
static int64_t adjustToPointerSize(int64_t Offset, unsigned PointerSize)
To ensure a pointer offset fits in an integer of size PointerSize (in bits) when that size is smaller...
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
bool doesNotReadMemory() const
Determine if the call does not access or only writes memory.
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...
bool onlyAccessesInaccessibleMemory() const
Determine if the function may only access memory that is inaccessible from the IR.
LLVM_NODISCARD T pop_back_val()
uint64_t getSizeInBytes() const
IterTy data_operands_begin() const
data_operands_begin/data_operands_end - Return iterators iterating over the call / invoke argument li...
unsigned getNumIncomingValues() const
Return the number of incoming edges.
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...
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.
LLVM_NODISCARD bool isNoModRef(const ModRefInfo MRI)
bool getLibFunc(StringRef funcName, LibFunc &F) const
Searches for a particular function name.
const Value * getArgumentAliasingToReturnedPointer(ImmutableCallSite CS)
This function returns call pointer argument that is considered the same by aliasing rules...
const Value * getFalseValue() const
bool doesNotAccessMemory() const
Determine if the call does not access memory.
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 ...
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.
Establish a view to a call site for examination.
BasicBlock * getIncomingBlock(unsigned i) const
Return incoming basic block number i.
AAResultsProxy getBestAAResults()
Get a proxy for the best AA result set to query at this time.
APFloat abs(APFloat X)
Returns the absolute value of the argument.
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)
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
FunctionModRefBehavior getModRefBehavior(ImmutableCallSite CS)
bool isKnownNonEqual(const Value *V1, const Value *V2, const DataLayout &DL, AssumptionCache *AC=nullptr, const Instruction *CxtI=nullptr, const DominatorTree *DT=nullptr)
Return true if the given values are known to be non-equal when defined.
bool isByValArgument(unsigned ArgNo) const
Determine whether this argument is passed by value.
ModRefInfo getModRefInfo(ImmutableCallSite CS, const MemoryLocation &Loc)
BasicAAResult run(Function &F, FunctionAnalysisManager &AM)
API to communicate dependencies between analyses during invalidation.
FunTy * getCalledFunction() const
Return the function being called if this is a direct call, otherwise return null (if it's an indirect...
Analysis pass providing the TargetLibraryInfo.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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.
ModRefInfo getArgModRefInfo(ImmutableCallSite CS, unsigned ArgIdx)
Get the location associated with a pointer argument of a callsite.
uint64_t getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type...
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
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.
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
This is the interface for LLVM's primary stateless and local alias analysis.
Various options to control the behavior of getObjectSize.
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.
int64_t getSExtValue() const
Return the constant as a 64-bit integer value after it has been sign extended as appropriate for the ...
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.
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)
Determine which bits of V are known to be either zero or one and return them in the KnownZero/KnownOn...
A special type used by analysis passes to provide an address that identifies that particular analysis...
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 onlyAccessesInaccessibleMemOrArgMem() const
Determine if the function may only access memory that is either inaccessible from the IR or pointed t...
static MemoryLocation getForSource(const MemTransferInst *MTI)
Return a location representing the source of a memory transfer.