LLVM 23.0.0git
llvm::AA Namespace Reference

Abstract Attribute helper functions. More...

Namespaces

namespace  PointerInfo

Classes

struct  RangeTy
 Helper to represent an access offset and size, with logic to deal with uncertainty and check for overlapping accesses. More...
struct  ValueAndContext

Typedefs

using InstExclusionSetTy = SmallPtrSet<Instruction *, 4>

Enumerations

enum  ValueScope : uint8_t { Intraprocedural = 1 , Interprocedural = 2 , AnyScope = Intraprocedural | Interprocedural }
 Flags to distinguish intra-procedural queries from potentially inter-procedural queries. More...

Functions

LLVM_ABI bool isGPU (const Module &M)
 Return true iff M target a GPU (and we can use GPU AS reasoning).
LLVM_ABI bool isGPUGenericAddressSpace (const Module &M, unsigned AS)
 Check if the given address space AS corresponds to a GPU generic address space for the target triple in module M.
LLVM_ABI bool isGPUGlobalAddressSpace (const Module &M, unsigned AS)
 Check if the given address space AS corresponds to a GPU global address space for the target triple in module M.
LLVM_ABI bool isGPUSharedAddressSpace (const Module &M, unsigned AS)
 Check if the given address space AS corresponds to a GPU shared address space for the target triple in module M.
LLVM_ABI bool isGPUConstantAddressSpace (const Module &M, unsigned AS)
 Check if the given address space AS corresponds to a GPU constant address space for the target triple in module M.
LLVM_ABI bool isGPULocalAddressSpace (const Module &M, unsigned AS)
 Check if the given address space AS corresponds to a GPU local/private address space for the target triple in module M.
LLVM_ABI bool isNoSyncInst (Attributor &A, const Instruction &I, const AbstractAttribute &QueryingAA)
 Return true if I is a nosync instruction.
LLVM_ABI bool isDynamicallyUnique (Attributor &A, const AbstractAttribute &QueryingAA, const Value &V, bool ForAnalysisOnly=true)
 Return true if V is dynamically unique, that is, there are no two "instances" of V at runtime with different values.
LLVM_ABI bool isValidInScope (const Value &V, const Function *Scope)
 Return true if V is a valid value in Scope, that is a constant or an instruction/argument of Scope.
LLVM_ABI bool isValidAtPosition (const ValueAndContext &VAC, InformationCache &InfoCache)
 Return true if the value of VAC is a valid at the position of VAC, that is a constant, an argument of the same function, or an instruction in that function that dominates the position.
LLVM_ABI ValuegetWithType (Value &V, Type &Ty)
 Try to convert V to type Ty without introducing new instructions.
LLVM_ABI std::optional< Value * > combineOptionalValuesInAAValueLatice (const std::optional< Value * > &A, const std::optional< Value * > &B, Type *Ty)
 Return the combination of A and B such that the result is a possible value of both.
raw_ostreamoperator<< (raw_ostream &OS, const RangeTy &R)
bool operator== (const RangeTy &A, const RangeTy &B)
bool operator!= (const RangeTy &A, const RangeTy &B)
LLVM_ABI ConstantgetInitialValueForObj (Attributor &A, const AbstractAttribute &QueryingAA, Value &Obj, Type &Ty, const TargetLibraryInfo *TLI, const DataLayout &DL, RangeTy *RangePtr=nullptr)
 Return the initial value of Obj with type Ty if that is a constant.
LLVM_ABI bool getPotentiallyLoadedValues (Attributor &A, LoadInst &LI, SmallSetVector< Value *, 4 > &PotentialValues, SmallSetVector< Instruction *, 4 > &PotentialValueOrigins, const AbstractAttribute &QueryingAA, bool &UsedAssumedInformation, bool OnlyExact=false)
 Collect all potential values LI could read into PotentialValues.
LLVM_ABI bool getPotentialCopiesOfStoredValue (Attributor &A, StoreInst &SI, SmallSetVector< Value *, 4 > &PotentialCopies, const AbstractAttribute &QueryingAA, bool &UsedAssumedInformation, bool OnlyExact=false)
 Collect all potential values of the one stored by SI into PotentialCopies.
LLVM_ABI bool isAssumedReadOnly (Attributor &A, const IRPosition &IRP, const AbstractAttribute &QueryingAA, bool &IsKnown)
 Return true if IRP is readonly.
LLVM_ABI bool isAssumedReadNone (Attributor &A, const IRPosition &IRP, const AbstractAttribute &QueryingAA, bool &IsKnown)
 Return true if IRP is readnone.
LLVM_ABI bool isPotentiallyReachable (Attributor &A, const Instruction &FromI, const Instruction &ToI, const AbstractAttribute &QueryingAA, const AA::InstExclusionSetTy *ExclusionSet=nullptr, std::function< bool(const Function &F)> GoBackwardsCB=nullptr)
 Return true if ToI is potentially reachable from FromI without running into any instruction in ExclusionSet The two instructions do not need to be in the same function.
LLVM_ABI bool isPotentiallyReachable (Attributor &A, const Instruction &FromI, const Function &ToFn, const AbstractAttribute &QueryingAA, const AA::InstExclusionSetTy *ExclusionSet=nullptr, std::function< bool(const Function &F)> GoBackwardsCB=nullptr)
 Same as above but it is sufficient to reach any instruction in ToFn.
LLVM_ABI bool isAssumedThreadLocalObject (Attributor &A, Value &Obj, const AbstractAttribute &QueryingAA)
 Return true if Obj is assumed to be a thread local object.
LLVM_ABI bool isPotentiallyAffectedByBarrier (Attributor &A, const Instruction &I, const AbstractAttribute &QueryingAA)
 Return true if I is potentially affected by a barrier.
LLVM_ABI bool isPotentiallyAffectedByBarrier (Attributor &A, ArrayRef< const Value * > Ptrs, const AbstractAttribute &QueryingAA, const Instruction *CtxI)
template<Attribute::AttrKind AK, typename AAType = AbstractAttribute>
bool hasAssumedIRAttr (Attributor &A, const AbstractAttribute *QueryingAA, const IRPosition &IRP, DepClassTy DepClass, bool &IsKnown, bool IgnoreSubsumingPositions=false, const AAType **AAPtr=nullptr)
 Helper to avoid creating an AA for IR Attributes that might already be set.

Detailed Description

Abstract Attribute helper functions.

Typedef Documentation

◆ InstExclusionSetTy

Definition at line 166 of file Attributor.h.

Enumeration Type Documentation

◆ ValueScope

Flags to distinguish intra-procedural queries from potentially inter-procedural queries.

Not that information can be valid for both and therefore both bits might be set.

Enumerator
Intraprocedural 
Interprocedural 
AnyScope 

Definition at line 194 of file Attributor.h.

Function Documentation

◆ combineOptionalValuesInAAValueLatice()

std::optional< Value * > llvm::AA::combineOptionalValuesInAAValueLatice ( const std::optional< Value * > & A,
const std::optional< Value * > & B,
Type * Ty )

Return the combination of A and B such that the result is a possible value of both.

B is potentially casted to match the type Ty or the type of A if Ty is null.

Examples: X + none => X not_none + undef => not_none V1 + V2 => nullptr

Definition at line 411 of file Attributor.cpp.

References A(), B(), getWithType(), llvm::isa(), and llvm::isa_and_nonnull().

Referenced by llvm::AAPotentialValues::getSingleValue(), llvm::AAPointerInfo::Access::operator&=(), and llvm::ValueSimplifyStateType::unionAssumed().

◆ getInitialValueForObj()

Constant * llvm::AA::getInitialValueForObj ( Attributor & A,
const AbstractAttribute & QueryingAA,
Value & Obj,
Type & Ty,
const TargetLibraryInfo * TLI,
const DataLayout & DL,
AA::RangeTy * RangePtr = nullptr )

◆ getPotentialCopiesOfStoredValue()

bool llvm::AA::getPotentialCopiesOfStoredValue ( Attributor & A,
StoreInst & SI,
SmallSetVector< Value *, 4 > & PotentialCopies,
const AbstractAttribute & QueryingAA,
bool & UsedAssumedInformation,
bool OnlyExact = false )

Collect all potential values of the one stored by SI into PotentialCopies.

That is, the only copies that were made via the store are assumed to be known and all are in PotentialCopies. Dependences onto QueryingAA are properly tracked, UsedAssumedInformation will inform the caller if assumed information was used.

Returns
True if the assumed potential copies are all in PotentialCopies, false if something went wrong and the copies could not be determined.

Definition at line 671 of file Attributor.cpp.

References A(), and getPotentialCopiesOfMemoryValue().

Referenced by llvm::Attributor::checkForAllUses().

◆ getPotentiallyLoadedValues()

bool llvm::AA::getPotentiallyLoadedValues ( Attributor & A,
LoadInst & LI,
SmallSetVector< Value *, 4 > & PotentialValues,
SmallSetVector< Instruction *, 4 > & PotentialValueOrigins,
const AbstractAttribute & QueryingAA,
bool & UsedAssumedInformation,
bool OnlyExact = false )

Collect all potential values LI could read into PotentialValues.

That is, the only values read by LI are assumed to be known and all are in PotentialValues. PotentialValueOrigins will contain all the instructions that might have put a potential value into PotentialValues. Dependences onto QueryingAA are properly tracked, UsedAssumedInformation will inform the caller if assumed information was used.

Returns
True if the assumed potential copies are all in PotentialValues, false if something went wrong and the copies could not be determined.

Definition at line 661 of file Attributor.cpp.

References A(), and getPotentialCopiesOfMemoryValue().

◆ getWithType()

Value * llvm::AA::getWithType ( Value & V,
Type & Ty )

◆ hasAssumedIRAttr()

template<Attribute::AttrKind AK, typename AAType = AbstractAttribute>
bool llvm::AA::hasAssumedIRAttr ( Attributor & A,
const AbstractAttribute * QueryingAA,
const IRPosition & IRP,
DepClassTy DepClass,
bool & IsKnown,
bool IgnoreSubsumingPositions = false,
const AAType ** AAPtr = nullptr )

◆ isAssumedReadNone()

bool llvm::AA::isAssumedReadNone ( Attributor & A,
const IRPosition & IRP,
const AbstractAttribute & QueryingAA,
bool & IsKnown )

Return true if IRP is readnone.

This will query respective AAs that deduce the information and introduce dependences for QueryingAA.

Definition at line 725 of file Attributor.cpp.

References A(), and isAssumedReadOnlyOrReadNone().

◆ isAssumedReadOnly()

bool llvm::AA::isAssumedReadOnly ( Attributor & A,
const IRPosition & IRP,
const AbstractAttribute & QueryingAA,
bool & IsKnown )

Return true if IRP is readonly.

This will query respective AAs that deduce the information and introduce dependences for QueryingAA.

Definition at line 720 of file Attributor.cpp.

References A(), and isAssumedReadOnlyOrReadNone().

◆ isAssumedThreadLocalObject()

bool llvm::AA::isAssumedThreadLocalObject ( Attributor & A,
Value & Obj,
const AbstractAttribute & QueryingAA )

◆ isDynamicallyUnique()

bool llvm::AA::isDynamicallyUnique ( Attributor & A,
const AbstractAttribute & QueryingAA,
const Value & V,
bool ForAnalysisOnly = true )

Return true if V is dynamically unique, that is, there are no two "instances" of V at runtime with different values.

Note: If ForAnalysisOnly is set we only check that the Attributor will never use V to represent two "instances" not that V could not technically represent them.

Definition at line 298 of file Attributor.cpp.

References A(), llvm::AAInstanceInfo::isAssumedUniqueForAnalysis(), llvm::OPTIONAL, and llvm::IRPosition::value().

◆ isGPU()

bool llvm::AA::isGPU ( const Module & M)

Return true iff M target a GPU (and we can use GPU AS reasoning).

Definition at line 220 of file Attributor.cpp.

References T.

Referenced by isGPUConstantAddressSpace(), isGPUGenericAddressSpace(), isGPUGlobalAddressSpace(), isGPULocalAddressSpace(), and isGPUSharedAddressSpace().

◆ isGPUConstantAddressSpace()

bool llvm::AA::isGPUConstantAddressSpace ( const Module & M,
unsigned AS )

Check if the given address space AS corresponds to a GPU constant address space for the target triple in module M.

Definition at line 255 of file Attributor.cpp.

References assert(), isGPU(), and T.

Referenced by isAssumedThreadLocalObject().

◆ isGPUGenericAddressSpace()

bool llvm::AA::isGPUGenericAddressSpace ( const Module & M,
unsigned AS )

Check if the given address space AS corresponds to a GPU generic address space for the target triple in module M.

Definition at line 225 of file Attributor.cpp.

References assert(), isGPU(), and T.

◆ isGPUGlobalAddressSpace()

bool llvm::AA::isGPUGlobalAddressSpace ( const Module & M,
unsigned AS )

Check if the given address space AS corresponds to a GPU global address space for the target triple in module M.

Definition at line 235 of file Attributor.cpp.

References assert(), isGPU(), and T.

◆ isGPULocalAddressSpace()

bool llvm::AA::isGPULocalAddressSpace ( const Module & M,
unsigned AS )

Check if the given address space AS corresponds to a GPU local/private address space for the target triple in module M.

Definition at line 265 of file Attributor.cpp.

References assert(), isGPU(), and T.

Referenced by isAssumedThreadLocalObject().

◆ isGPUSharedAddressSpace()

bool llvm::AA::isGPUSharedAddressSpace ( const Module & M,
unsigned AS )

Check if the given address space AS corresponds to a GPU shared address space for the target triple in module M.

Definition at line 245 of file Attributor.cpp.

References assert(), isGPU(), and T.

◆ isNoSyncInst()

bool llvm::AA::isNoSyncInst ( Attributor & A,
const Instruction & I,
const AbstractAttribute & QueryingAA )

Return true if I is a nosync instruction.

Use generic reasoning and potentially the corresponding AANoSync.

Definition at line 275 of file Attributor.cpp.

References A(), llvm::IRPosition::callsite_function(), llvm::dyn_cast(), hasAssumedIRAttr(), I, llvm::AANoSync::isNonRelaxedAtomic(), and llvm::OPTIONAL.

◆ isPotentiallyAffectedByBarrier() [1/2]

bool llvm::AA::isPotentiallyAffectedByBarrier ( Attributor & A,
ArrayRef< const Value * > Ptrs,
const AbstractAttribute & QueryingAA,
const Instruction * CtxI )

◆ isPotentiallyAffectedByBarrier() [2/2]

◆ isPotentiallyReachable() [1/2]

bool llvm::AA::isPotentiallyReachable ( Attributor & A,
const Instruction & FromI,
const Function & ToFn,
const AbstractAttribute & QueryingAA,
const AA::InstExclusionSetTy * ExclusionSet = nullptr,
std::function< bool(const Function &F)> GoBackwardsCB = nullptr )

Same as above but it is sufficient to reach any instruction in ToFn.

Definition at line 898 of file Attributor.cpp.

References A(), and F.

◆ isPotentiallyReachable() [2/2]

bool llvm::AA::isPotentiallyReachable ( Attributor & A,
const Instruction & FromI,
const Instruction & ToI,
const AbstractAttribute & QueryingAA,
const AA::InstExclusionSetTy * ExclusionSet = nullptr,
std::function< bool(const Function &F)> GoBackwardsCB = nullptr )

Return true if ToI is potentially reachable from FromI without running into any instruction in ExclusionSet The two instructions do not need to be in the same function.

GoBackwardsCB can be provided to convey domain knowledge about the "lifespan" the user is interested in. By default, the callers of FromI are checked as well to determine if ToI can be reached. If the query is not interested in callers beyond a certain point, e.g., a GPU kernel entry or the function containing an alloca, the GoBackwardsCB should return false.

Definition at line 888 of file Attributor.cpp.

References A(), F, and llvm::Instruction::getFunction().

◆ isValidAtPosition()

bool llvm::AA::isValidAtPosition ( const ValueAndContext & VAC,
InformationCache & InfoCache )

Return true if the value of VAC is a valid at the position of VAC, that is a constant, an argument of the same function, or an instruction in that function that dominates the position.

Definition at line 362 of file Attributor.cpp.

References A(), llvm::any_of(), llvm::dyn_cast(), llvm::InformationCache::getAnalysisResultForFunction(), llvm::AA::ValueAndContext::getCtxI(), llvm::Instruction::getFunction(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), llvm::AA::ValueAndContext::getValue(), I, llvm::isa(), and llvm::make_range().

◆ isValidInScope()

bool llvm::AA::isValidInScope ( const Value & V,
const Function * Scope )

Return true if V is a valid value in Scope, that is a constant or an instruction/argument of Scope.

Definition at line 352 of file Attributor.cpp.

References A(), llvm::dyn_cast(), I, and llvm::isa().

Referenced by llvm::Attributor::getAssumedSimplifiedValues().

◆ operator!=()

bool llvm::AA::operator!= ( const RangeTy & A,
const RangeTy & B )
inline

Definition at line 344 of file Attributor.h.

References A(), and B().

◆ operator<<()

raw_ostream & llvm::AA::operator<< ( raw_ostream & OS,
const RangeTy & R )
inline

Definition at line 335 of file Attributor.h.

◆ operator==()

bool llvm::AA::operator== ( const RangeTy & A,
const RangeTy & B )
inline

Definition at line 340 of file Attributor.h.

References A(), and B().