LLVM 20.0.0git
Namespaces | Classes | Typedefs | Enumerations | Functions
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 class  GPUAddressSpace : unsigned {
  Generic = 0 , Global = 1 , Shared = 3 , Constant = 4 ,
  Local = 5
}
 
enum  ValueScope : uint8_t { Intraprocedural = 1 , Interprocedural = 2 , AnyScope = Intraprocedural | Interprocedural }
 Flags to distinguish intra-procedural queries from potentially inter-procedural queries. More...
 

Functions

bool isGPU (const Module &M)
 Return true iff M target a GPU (and we can use GPU AS reasoning).
 
bool isNoSyncInst (Attributor &A, const Instruction &I, const AbstractAttribute &QueryingAA)
 Return true if I is a nosync instruction.
 
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.
 
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.
 
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.
 
ValuegetWithType (Value &V, Type &Ty)
 Try to convert V to type Ty without introducing new instructions.
 
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)
 
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.
 
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.
 
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.
 
bool isAssumedReadOnly (Attributor &A, const IRPosition &IRP, const AbstractAttribute &QueryingAA, bool &IsKnown)
 Return true if IRP is readonly.
 
bool isAssumedReadNone (Attributor &A, const IRPosition &IRP, const AbstractAttribute &QueryingAA, bool &IsKnown)
 Return true if IRP is readnone.
 
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.
 
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.
 
bool isAssumedThreadLocalObject (Attributor &A, Value &Obj, const AbstractAttribute &QueryingAA)
 Return true if Obj is assumed to be a thread local object.
 
bool isPotentiallyAffectedByBarrier (Attributor &A, const Instruction &I, const AbstractAttribute &QueryingAA)
 Return true if I is potentially affected by a barrier.
 
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 164 of file Attributor.h.

Enumeration Type Documentation

◆ GPUAddressSpace

enum class llvm::AA::GPUAddressSpace : unsigned
strong
Enumerator
Generic 
Global 
Shared 
Constant 
Local 

Definition at line 166 of file Attributor.h.

◆ 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 180 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 339 of file Attributor.cpp.

References A, B, and getWithType().

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 599 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 589 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 
)

Helper to avoid creating an AA for IR Attributes that might already be set.

Definition at line 6485 of file Attributor.h.

References CASE, llvm_unreachable, llvm::AAMemoryBehavior::NO_ACCESSES, llvm::AAMemoryBehavior::NO_READS, and llvm::AAMemoryBehavior::NO_WRITES.

◆ 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 653 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 648 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 231 of file Attributor.cpp.

References A, llvm::AAInstanceInfo::isAssumedUniqueForAnalysis(), 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 200 of file Attributor.cpp.

◆ 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 205 of file Attributor.cpp.

References A, llvm::IRPosition::callsite_function(), I, llvm::AANoSync::isNonRelaxedAtomic(), and llvm::AANoSync::isNoSyncIntrinsic().

◆ isPotentiallyAffectedByBarrier() [1/2]

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

◆ isPotentiallyAffectedByBarrier() [2/2]

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

◆ 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 826 of file Attributor.cpp.

References A.

◆ 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 816 of file Attributor.cpp.

References A, 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 290 of file Attributor.cpp.

References A, llvm::any_of(), llvm::DominatorTree::dominates(), llvm::InformationCache::getAnalysisResultForFunction(), llvm::Instruction::getFunction(), llvm::ilist_detail::node_parent_access< NodeTy, ParentTy >::getParent(), I, 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 280 of file Attributor.cpp.

References A, and I.

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

◆ operator!=()

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

Definition at line 328 of file Attributor.h.

References A, and B.

◆ operator<<()

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

Definition at line 319 of file Attributor.h.

References OS.

◆ operator==()

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

Definition at line 324 of file Attributor.h.

References A, B, and llvm::operator==().