97 #ifndef LLVM_TRANSFORMS_IPO_ATTRIBUTOR_H 98 #define LLVM_TRANSFORMS_IPO_ATTRIBUTOR_H 113 struct AbstractAttribute;
114 struct InformationCache;
158 IRP_CALL_SITE_RETURNED = -3,
162 IRP_CALL_SITE_ARGUMENT = 1,
172 if (
auto *
Arg = dyn_cast<Argument>(&V))
174 if (
auto *CB = dyn_cast<CallBase>(&V))
176 return IRPosition(const_cast<Value &>(V), IRP_FLOAT);
181 return IRPosition(const_cast<Function &>(
F), IRP_FUNCTION);
186 return IRPosition(const_cast<Function &>(F), IRP_RETURNED);
196 return IRPosition(const_cast<CallBase &>(CB), IRP_CALL_SITE);
201 return IRPosition(const_cast<CallBase &>(CB), IRP_CALL_SITE_RETURNED);
262 assert(KindOrArgNo != IRP_INVALID &&
263 "Invalid position does not have an anchor value!");
269 if (
auto *CB = dyn_cast<CallBase>(AnchorVal))
270 return CB->getCalledFunction();
271 assert(KindOrArgNo != IRP_INVALID &&
272 "Invalid position does not have an anchor scope!");
273 Value &V = getAnchorValue();
274 if (isa<Function>(V))
275 return &cast<Function>(V);
276 if (isa<Argument>(V))
277 return cast<Argument>(V).getParent();
278 if (isa<Instruction>(V))
284 Argument *getAssociatedArgument()
const;
289 switch (getPositionKind()) {
301 Value &V = getAnchorValue();
302 if (isa<Function>(V))
303 return &cast<Function>(V);
304 if (isa<Argument>(V))
305 return cast<Argument>(V).getParent();
306 if (isa<Instruction>(V))
313 Value &V = getAnchorValue();
314 if (
auto *
I = dyn_cast<Instruction>(&V))
316 if (
auto *
Arg = dyn_cast<Argument>(&V))
317 if (!
Arg->getParent()->isDeclaration())
318 return &
Arg->getParent()->getEntryBlock().front();
319 if (
auto *
F = dyn_cast<Function>(&V))
320 if (!
F->isDeclaration())
321 return &(
F->getEntryBlock().front());
327 assert(KindOrArgNo != IRP_INVALID &&
328 "Invalid position does not have an associated value!");
329 if (getArgNo() < 0 || isa<Argument>(AnchorVal))
331 assert(isa<CallBase>(AnchorVal) &&
"Expected a call base!");
332 return *cast<CallBase>(AnchorVal)->getArgOperand(getArgNo());
341 switch (getPositionKind()) {
356 "There is no attribute index for a floating or invalid position!");
361 if (getArgNo() >= 0) {
362 assert(((isa<Argument>(getAnchorValue()) &&
363 isa<Argument>(getAssociatedValue())) ||
364 isa<CallBase>(getAnchorValue())) &&
365 "Expected argument or call base due to argument number!");
366 if (isa<CallBase>(getAnchorValue()))
367 return IRP_CALL_SITE_ARGUMENT;
372 "Expected (call site) arguments to never reach this point!");
373 return Kind(KindOrArgNo);
385 bool IgnoreSubsumingPositions =
false)
const;
397 bool IgnoreSubsumingPositions =
false)
const;
401 if (getPositionKind() == IRP_INVALID || getPositionKind() == IRP_FLOAT)
417 if (getPositionKind() == IRP_INVALID || getPositionKind() == IRP_FLOAT)
434 getAssociatedFunction()->setAttributes(AttrList);
438 switch (getPositionKind()) {
458 : AnchorVal(0), KindOrArgNo(KindOrArgNo) {}
462 : AnchorVal(&AnchorVal), KindOrArgNo(PK) {
518 using iterator = decltype(IRPositions)::iterator;
523 iterator
end() {
return IRPositions.
end(); }
528 template <
typename Analysis>
538 template <
typename Analysis>
565 : DL(M.getDataLayout()), Explorer(
true), AG(AG) {
574 SccSize[
Node->getFunction()] = I->
size();
576 SccSizeOpt = std::move(SccSize);
585 return FuncInstOpcodeMap[&
F];
593 return FuncRWInstsMap[&
F];
612 template <
typename AP>
614 return AG.getAnalysis<AP>(
F);
619 if (!SccSizeOpt.hasValue())
621 return (SccSizeOpt.getValue())[&F];
695 : InfoCache(InfoCache), DepRecomputeInterval(DepRecomputeInterval),
696 Whitelist(Whitelist) {}
700 for (
auto &It : ArgumentReplacementMap)
732 template <
typename AAType>
734 const IRPosition &IRP,
bool TrackDependence =
true,
736 return getOrCreateAAFor<AAType>(IRP, &QueryingAA, TrackDependence,
762 static_assert(std::is_base_of<AbstractAttribute, AAType>::value,
763 "Cannot register an attribute with a type not derived from " 764 "'AbstractAttribute'!");
770 "Attribute already in map!");
772 AllAbstractAttributes.push_back(&AA);
789 void identifyDefaultAbstractAttributes(
Function &
F);
795 void initializeInformationCache(
Function &F);
803 "Only local linkage is assumed dead initially.");
805 identifyDefaultAbstractAttributes(const_cast<Function &>(F));
811 Value *&V = ToBeChangedUses[&U];
813 isa_and_nonnull<UndefValue>(V)))
815 assert((!V || V == &NV || isa<UndefValue>(NV)) &&
816 "Use was registered twice for replacement with different values!");
824 bool Changed =
false;
825 for (
auto &U : V.
uses())
826 Changed |= changeUseAfterManifest(U, NV);
835 bool AllowVolatile) {
836 if (
auto *LI = dyn_cast<LoadInst>(I)) {
837 if (!AllowVolatile && LI->isVolatile())
839 return LI->getPointerOperand();
842 if (
auto *
SI = dyn_cast<StoreInst>(I)) {
843 if (!AllowVolatile &&
SI->isVolatile())
845 return SI->getPointerOperand();
848 if (
auto *CXI = dyn_cast<AtomicCmpXchgInst>(I)) {
849 if (!AllowVolatile && CXI->isVolatile())
851 return CXI->getPointerOperand();
854 if (
auto *RMWI = dyn_cast<AtomicRMWInst>(I)) {
855 if (!AllowVolatile && RMWI->isVolatile())
857 return RMWI->getPointerOperand();
866 ToBeChangedToUnreachableInsts.insert(I);
873 InvokeWithDeadSuccessor.push_back(&II);
896 bool checkForAllUses(
const function_ref<
bool(
const Use &,
bool &)> &Pred,
937 return ReplacementTypes;
950 : A(A), ReplacedFn(*Arg.
getParent()), ReplacedArg(Arg),
951 ReplacementTypes(ReplacementTypes.
begin(), ReplacementTypes.
end()),
952 CalleeRepairCB(std::move(CalleeRepairCB)),
953 ACSRepairCB(std::move(ACSRepairCB)) {}
985 bool registerFunctionSignatureRewrite(
997 bool RequireAllCallSites);
1005 bool checkForAllReturnedValuesAndReturnInsts(
1031 return checkForAllInstructions(Pred, QueryingAA,
1033 (
unsigned)Instruction::CallBr,
1042 bool checkForAllReadWriteInstructions(
1056 const Function &Fn,
bool RequireAllCallSites,
1061 template <
typename AAType>
1062 const AAType &getOrCreateAAFor(
const IRPosition &IRP,
1064 bool TrackDependence =
false,
1066 if (
const AAType *AAPtr =
1067 lookupAAFor<AAType>(IRP, QueryingAA, TrackDependence))
1072 auto &AA = AAType::createForPosition(IRP, *
this);
1076 bool Invalidate = Whitelist && !Whitelist->count(&
AAType::ID);
1085 AA.getState().indicatePessimisticFixpoint();
1089 AA.initialize(*
this);
1092 if (TrackDependence && AA.getState().isValidState())
1093 recordDependence(AA, const_cast<AbstractAttribute &>(*QueryingAA),
1099 template <
typename AAType>
1100 const AAType *lookupAAFor(
const IRPosition &IRP,
1102 bool TrackDependence =
false,
1104 static_assert(std::is_base_of<AbstractAttribute, AAType>::value,
1105 "Cannot query an attribute with a type not derived from " 1106 "'AbstractAttribute'!");
1107 assert((QueryingAA || !TrackDependence) &&
1108 "Cannot track dependences without a QueryingAA!");
1113 if (AAType *AA = static_cast<AAType *>(
1116 if (TrackDependence && AA->getState().isValidState())
1117 recordDependence(*AA, const_cast<AbstractAttribute &>(*QueryingAA),
1147 struct QueryMapValueTy {
1162 ArgumentReplacementMap;
1168 bool QueriedNonFixAA;
1172 const unsigned DepRecomputeInterval;
1221 virtual bool isValidState()
const = 0;
1225 virtual bool isAtFixpoint()
const = 0;
1241 virtual ChangeStatus indicatePessimisticFixpoint() = 0;
1254 template <
typename base_ty, base_ty BestState, base_ty WorstState>
1292 return this->getAssumed() == R.
getAssumed() &&
1299 return !(*
this == R);
1319 virtual void handleNewAssumedValue(
base_t Value) = 0;
1322 virtual void handleNewKnownValue(
base_t Value) = 0;
1325 virtual void joinOR(
base_t AssumedValue,
base_t KnownValue) = 0;
1328 virtual void joinAND(
base_t AssumedValue,
base_t KnownValue) = 0;
1338 template <
typename base_ty =
uint32_t, base_ty BestState = ~base_ty(0),
1339 base_ty WorstState = 0>
1346 return (this->Known & BitsEncoding) == BitsEncoding;
1351 return (this->Assumed & BitsEncoding) == BitsEncoding;
1357 this->Assumed |=
Bits;
1358 this->Known |=
Bits;
1364 return intersectAssumedBits(~BitsEncoding);
1369 this->Known = (this->Known & ~BitsEncoding);
1376 this->Assumed = (this->Assumed & BitsEncoding) | this->Known;
1381 void handleNewAssumedValue(
base_t Value)
override {
1382 intersectAssumedBits(Value);
1384 void handleNewKnownValue(
base_t Value)
override { addKnownBits(Value); }
1385 void joinOR(
base_t AssumedValue,
base_t KnownValue)
override {
1386 this->Known |= KnownValue;
1387 this->Assumed |= AssumedValue;
1389 void joinAND(
base_t AssumedValue,
base_t KnownValue)
override {
1390 this->Known &= KnownValue;
1391 this->Assumed &= AssumedValue;
1397 template <
typename base_ty =
uint32_t, base_ty BestState = ~base_ty(0),
1398 base_ty WorstState = 0>
1406 this->Assumed =
std::max(std::min(this->Assumed, Value), this->Known);
1413 this->Assumed =
std::max(Value, this->Assumed);
1414 this->Known =
std::max(Value, this->Known);
1419 void handleNewAssumedValue(
base_t Value)
override {
1420 takeAssumedMinimum(Value);
1422 void handleNewKnownValue(
base_t Value)
override { takeKnownMaximum(Value); }
1423 void joinOR(
base_t AssumedValue,
base_t KnownValue)
override {
1424 this->Known =
std::max(this->Known, KnownValue);
1425 this->Assumed =
std::max(this->Assumed, AssumedValue);
1427 void joinAND(
base_t AssumedValue,
base_t KnownValue)
override {
1428 this->Known = std::min(this->Known, KnownValue);
1429 this->Assumed = std::min(this->Assumed, AssumedValue);
1435 template <
typename base_ty = u
int32_t>
1442 this->Assumed = std::min(
std::max(this->Assumed, Value), this->Known);
1449 this->Assumed = std::min(Value, this->Assumed);
1450 this->Known = std::min(Value, this->Known);
1455 void handleNewAssumedValue(
base_t Value)
override {
1456 takeAssumedMaximum(Value);
1458 void handleNewKnownValue(
base_t Value)
override { takeKnownMinimum(Value); }
1459 void joinOR(
base_t AssumedValue,
base_t KnownValue)
override {
1460 this->Assumed = std::min(this->Assumed, KnownValue);
1461 this->Assumed = std::min(this->Assumed, AssumedValue);
1463 void joinAND(
base_t AssumedValue,
base_t KnownValue)
override {
1464 this->Assumed =
std::max(this->Assumed, KnownValue);
1465 this->Assumed =
std::max(this->Assumed, AssumedValue);
1489 void handleNewAssumedValue(
base_t Value)
override {
1493 void handleNewKnownValue(
base_t Value)
override {
1495 Known = (Assumed =
Value);
1497 void joinOR(
base_t AssumedValue,
base_t KnownValue)
override {
1498 Known |= KnownValue;
1499 Assumed |= AssumedValue;
1501 void joinAND(
base_t AssumedValue,
base_t KnownValue)
override {
1502 Known &= KnownValue;
1503 Assumed &= AssumedValue;
1520 : BitWidth(BitWidth), Assumed(
ConstantRange::getEmpty(BitWidth)),
1525 return ConstantRange::getFull(BitWidth);
1530 return ConstantRange::getEmpty(BitWidth);
1538 return BitWidth > 0 && !Assumed.
isFullSet();
1625 template <
typename StateTy,
typename Base>
1638 template <Attribute::AttrKind AK,
typename Base>
1645 const IRPosition &IRP = this->getIRPosition();
1647 this->getState().indicateOptimisticFixpoint();
1661 this->getState().indicatePessimisticFixpoint();
1666 if (isa<UndefValue>(getIRPosition().getAssociatedValue()))
1669 getDeducedAttributes(getAnchorValue().getContext(), DeducedAttrs);
1747 virtual const StateType &getState()
const = 0;
1750 virtual const IRPosition &getIRPosition()
const = 0;
1758 virtual const std::string getAsStr()
const = 0;
1786 virtual void trackStatistics()
const = 0;
1806 template <
typename base_ty, base_ty BestState, base_ty WorstState>
1825 :
public IRAttribute<Attribute::Returned, AbstractAttribute> {
1841 virtual bool checkForAllReturnedValuesAndReturnInsts(
1852 virtual size_t getNumReturnValues()
const = 0;
1865 StateWrapper<BooleanState, AbstractAttribute>> {
1883 StateWrapper<BooleanState, AbstractAttribute>> {
1902 StateWrapper<BooleanState, AbstractAttribute>> {
1921 StateWrapper<BooleanState, AbstractAttribute>> {
1940 StateWrapper<BooleanState, AbstractAttribute>> {
1958 :
public StateWrapper<BooleanState, AbstractAttribute>,
1966 virtual bool isAssumedToCauseUB(
Instruction *
I)
const = 0;
1972 virtual bool isKnownToCauseUB(
Instruction *I)
const = 0;
2019 StateWrapper<BooleanState, AbstractAttribute>> {
2038 StateWrapper<BooleanState, AbstractAttribute>> {
2057 StateWrapper<BooleanState, AbstractAttribute>> {
2079 virtual bool isAssumedDead()
const = 0;
2082 virtual bool isAssumedDead(
const BasicBlock *BB)
const = 0;
2085 virtual bool isKnownDead(
const BasicBlock *BB)
const = 0;
2088 virtual bool isAssumedDead(
const Instruction *
I)
const = 0;
2091 virtual bool isKnownDead(
const Instruction *I)
const = 0;
2098 "Instruction must be in the same anchor scope function.");
2100 if (!isAssumedDead(I))
2150 void computeKnownDerefBytesFromAccessedMap() {
2151 int64_t KnownBytes = DerefBytesState.
getKnown();
2152 for (
auto &Access : AccessedBytesMap) {
2153 if (KnownBytes < Access.first)
2155 KnownBytes =
std::max(KnownBytes, Access.first + (int64_t)Access.second);
2165 bool isValidState()
const override {
return DerefBytesState.
isValidState(); }
2168 bool isAtFixpoint()
const override {
2169 return !isValidState() ||
2188 void takeKnownDerefBytesMaximum(uint64_t Bytes) {
2192 computeKnownDerefBytesFromAccessedMap();
2196 void takeAssumedDerefBytesMinimum(uint64_t Bytes) {
2201 void addAccessedBytes(int64_t
Offset, uint64_t
Size) {
2202 AccessedBytesMap[
Offset] =
std::max(AccessedBytesMap[Offset], Size);
2205 computeKnownDerefBytesFromAccessedMap();
2211 this->GlobalState == R.GlobalState;
2220 GlobalState ^= R.GlobalState;
2227 GlobalState &= R.GlobalState;
2234 GlobalState |= R.GlobalState;
2245 StateWrapper<DerefState, AbstractAttribute>> {
2250 return NonNullAA && NonNullAA->isAssumedNonNull();
2255 return NonNullAA && NonNullAA->isKnownNonNull();
2268 return DerefBytesState.getAssumed();
2273 return DerefBytesState.getKnown();
2288 Attribute::Alignment,
2289 StateWrapper<AAAlignmentStateType, AbstractAttribute>> {
2308 Attribute::NoCapture,
2309 StateWrapper<BitIntegerState<uint16_t, 7, 0>, AbstractAttribute>> {
2315 NOT_CAPTURED_IN_MEM = 1 << 0,
2316 NOT_CAPTURED_IN_INT = 1 << 1,
2317 NOT_CAPTURED_IN_RET = 1 << 2,
2321 NO_CAPTURE_MAYBE_RETURNED = NOT_CAPTURED_IN_MEM | NOT_CAPTURED_IN_INT,
2326 NOT_CAPTURED_IN_MEM | NOT_CAPTURED_IN_INT | NOT_CAPTURED_IN_RET,
2340 return isKnown(NO_CAPTURE_MAYBE_RETURNED);
2346 return isAssumed(NO_CAPTURE_MAYBE_RETURNED);
2400 Attribute::ReadNone,
2401 StateWrapper<BitIntegerState<uint8_t, 3>, AbstractAttribute>> {
2409 NO_ACCESSES = NO_READS | NO_WRITES,
2411 BEST_STATE = NO_ACCESSES,
2452 IRP.getAssociatedValue().
getType()->getIntegerBitWidth()),
2484 return cast<ConstantInt>(
2497 #endif // LLVM_TRANSFORMS_IPO_FUNCTIONATTRS_H An attribute for a call site return value.
Pass interface - Implemented by all 'passes'.
Instruction * getCtxI() const
Return the context instruction, if any.
std::map< int64_t, uint64_t > AccessedBytesMap
Map representing for accessed memory offsets and sizes.
static const char ID
Unique ID (due to the unique address)
void DeleteContainerPointers(Container &C)
For a container of pointers, deletes the pointers and then clears the container.
static ConstantRange getWorstState(uint32_t BitWidth)
Return the worst possible representable state.
Analysis::Result * getAnalysis(const Module &M)
This builds on the llvm/ADT/GraphTraits.h file to find the strongly connected components (SCCs) of a ...
A parsed version of the target data layout string in and methods for querying it. ...
const_iterator end(StringRef path)
Get end iterator over path.
reference emplace_back(ArgTypes &&... Args)
bool isKnownNoCaptureMaybeReturned() const
Return true if we know that the underlying value is not captured in its respective scope but we allow...
static IRPosition getEmptyKey()
iterator_range< use_iterator > uses()
uint32_t getKnownDereferenceableBytes() const
Return known dereferenceable bytes.
bool hasLocalLinkage() const
static const Value * getPointerOperand(const Instruction *I, bool AllowVolatile)
Get pointer operand of memory accessing instruction.
int getCallArgOperandNo(Argument &Arg) const
Return the operand index of the underlying instruction associated with Arg.
This class represents an incoming formal argument to a Function.
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
DiagnosticInfoOptimizationBase::Argument NV
bool isAssumed() const
Return true if the state is assumed to hold.
std::function< void(const ArgumentReplacementInfo &, Function &, Function::arg_iterator)> CalleeRepairCBTy
Callee repair callback type.
This class represents lattice values for constants.
bool isAssumedNoSync() const
Returns true if "nosync" is assumed.
bool isValidState() const override
See AbstractState::isValidState()
void setAttributes(AttributeList PAL)
Set the parameter attributes of the call.
A Module instance is used to store all the information related to an LLVM module. ...
bool isAssumedReadOnly() const
Return true if we assume that the underlying value is not accessed (=written) in its respective scope...
const APInt * getSingleElement() const
If this set contains a single element, return it, otherwise return null.
ChangeStatus
Simple enum classes that forces properties to be spelled out explicitly.
static IRPosition getTombstoneKey()
bool isKnown() const
Return true if the state is known to hold.
Specialization of the integer state for a bit-wise encoding.
A position that is not associated with a spot suitable for attributes.
AAReachability(const IRPosition &IRP)
Implements a dense probed hash-table based set.
static const char ID
Unique ID (due to the unique address)
static const char ID
Unique ID (due to the unique address)
bool isAnyCallSitePosition() const
AANoAlias(const IRPosition &IRP)
An abstract interface for all nocapture attributes.
ConstantRange getAssumed() const
Return the assumed state encoding.
Value & getAssociatedValue() const
Return the value this abstract attribute is associated with.
Abstract Attribute Classes
Helper struct necessary as the modular build fails if the virtual method IRAttribute::manifest is def...
An efficient, type-erasing, non-owning reference to a callable.
void setAssumed(bool Value)
Set the assumed value to Value but never below the known one.
static const char ID
Unique ID (due to the unique address)
An attribute for a call site argument.
bool isAssumedNoReturn() const
Return true if the underlying object is assumed to never return.
Function * getAnchorScope() const
Return the Function surrounding the anchor value.
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
bool isAssumedNoRecurse() const
Return true if "norecurse" is assumed.
An abstract attribute for willreturn.
APInt operator &(APInt a, const APInt &b)
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
MapVector< Value *, SmallSetVector< ReturnInst *, 4 > >::const_iterator const_iterator
const IRPosition & getIRPosition() const override
Return an IR position, see struct IRPosition.
block Block Frequency true
unsigned getKnownAlign() const
Return known alignment.
Helper to tie a abstract state implementation to an abstract attribute.
Kind
The positions we distinguish in the IR.
Wrapper for FunctoinAnalysisManager.
bool isAtFixpoint() const override
See AbstractState::isAtFixpoint()
A node in the call graph for a module.
AANoReturn(const IRPosition &IRP)
bool isAssumedHeapToStack() const
Returns true if HeapToStack conversion is assumed to be possible.
bool hasAttribute(unsigned Index, Attribute::AttrKind Kind) const
Return true if the attribute exists at the given index.
uint32_t BitWidth
Bitwidth of the associated value.
AAAlign(const IRPosition &IRP)
bool operator==(const IntegerRangeState &R) const
Equality for IntegerRangeState.
Attributor & getAttributor() const
Simple getters, see the corresponding members for details.
bool isValidState() const override
See AbstractState::isValidState() NOTE: For now we simply pretend that the worst possible state is in...
IntegerRangeState & getState() override
See AbstractAttribute::getState(...).
static const IRPosition function_scope(const IRPosition &IRP)
Create a position with function scope matching the "context" of IRP.
Specialization of the integer state for an increasing value, hence ~0u is the best state and 0 the wo...
BitIntegerState & removeAssumedBits(base_t BitsEncoding)
Remove the bits in BitsEncoding from the "assumed bits" if not known.
An AbstractAttribute for noreturn.
A visitor class for IR positions.
base_t getAssumed() const
Return the assumed state encoding.
bool isKnownNoReturn() const
Return true if the underlying object is known to never return.
static const char ID
Unique ID (due to the unique address)
static const IRPosition callsite_argument(AbstractCallSite ACS, unsigned ArgNo)
Create a position describing the argument of ACS at position ArgNo.
A Use represents the edge between a Value definition and its users.
const IRPosition & getIRPosition() const
Return an IR position, see struct IRPosition.
void intersectKnown(const IntegerRangeState &R)
See IntegerRangeState::intersectKnown(..).
bool isAssumedNoAlias() const
Return true if we assume that the underlying value is alias.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
An abstract attribute for norecurse.
bool isAssumedNoUnwind() const
Returns true if nounwind is assumed.
Contains a collection of routines for determining if a given instruction is guaranteed to execute if ...
IncIntegerState & takeKnownMaximum(base_t Value)
Take maximum of known and Value.
static const char ID
Unique ID (due to the unique address)
An abstract interface for all noalias attributes.
ConstantRange Assumed
State representing assumed range, initially set to empty.
scc_iterator< T > scc_begin(const T &G)
Construct the begin iterator for a deduced graph type T.
void operator &=(const IntegerStateBase< base_t, BestState, WorstState > &R)
An attribute for the function return value.
InstrTy * getInstruction() const
uint32_t getAssumedDereferenceableBytes() const
Return assumed dereferenceable bytes.
This file provides interfaces used to build and manipulate a call graph, which is a very useful tool ...
State for an integer range.
int getArgNo() const
Return the argument number of the associated value if it is an argument or call site argument...
void unionKnown(const IntegerRangeState &R)
See IntegerRangeState::unionKnown(..).
Attribute getAttr(Attribute::AttrKind AK) const
Return the attribute of kind AK existing in the IR at this position.
bool operator==(const IRPosition &RHS) const
AANoCapture(const IRPosition &IRP)
An abstract interface for liveness abstract attribute.
ConstantRange intersectWith(const ConstantRange &CR, PreferredRangeType Type=Smallest) const
Return the range that results from the intersection of this range with another range.
A CRTP mix-in to automatically provide informational APIs needed for passes.
bool isAssumedNoFree() const
Return true if "nofree" is assumed.
AAWillReturn(const IRPosition &IRP)
static const IRPosition callsite_returned(ImmutableCallSite ICS)
Create a position describing the returned value of ICS.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
bool isKnownWriteOnly() const
Return true if we know that the underlying value is not read in its respective scope.
bool operator!=(const IRPosition &RHS) const
bool isKnownNoUnwind() const
Returns true if nounwind is known.
An abstract interface for all nonnull attributes.
static Function * getFunction(Constant *C)
bool isKnown(base_t BitsEncoding) const
Return true if the bits set in BitsEncoding are "known bits".
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
E & operator^=(E &LHS, E RHS)
ChangeStatus manifest(Attributor &A) override
See AbstractAttribute::manifest(...).
void removeAttrs(ArrayRef< Attribute::AttrKind > AKs) const
Remove the attribute of kind AKs existing in the IR at this position.
bool isAssumedGlobal() const
Return true if we assume that underlying value is dereferenceable(_or_null) globally.
unsigned getAttrIdx() const
Return the index in the attribute list for this position.
AAHeapToStack(const IRPosition &IRP)
bool isKnownNoFree() const
Return true if "nofree" is known.
std::function< void(const ArgumentReplacementInfo &, AbstractCallSite, SmallVectorImpl< Value * > &)> ACSRepairCBTy
Abstract call site (ACS) repair callback type.
static const char ID
Unique ID (due to the unique address)
bool isKnownReadOnly() const
Return true if we know that the underlying value is not accessed (=written) in its respective scope...
AttributeSet getAttributes(unsigned Index) const
The attributes for the specified index are returned.
AAReturnedValues(const IRPosition &IRP)
ConstantRange Known
State representing known range, initially set to [-inf, inf].
static const IRPosition callsite_function(ImmutableCallSite ICS)
Create a position describing the function scope of ICS.
const IRPosition & getIRPosition() const override
Return an IR position, see struct IRPosition.
bool operator|=(SparseBitVector< ElementSize > &LHS, const SparseBitVector< ElementSize > *RHS)
MapVector< Value *, SmallSetVector< ReturnInst *, 4 > >::iterator iterator
static const char ID
Unique ID (due to the unique address)
AAUndefinedBehavior(const IRPosition &IRP)
A set of analyses that are preserved following a run of a transformation pass.
bool checkForAllCallLikeInstructions(const function_ref< bool(Instruction &)> &Pred, const AbstractAttribute &QueryingAA)
Check Pred on all call-like instructions (=CallBased derived).
static const char ID
Unique ID (due to the unique address)
bool isAssumedReachable(const Instruction *From, const Instruction *To) const
Returns true if 'From' instruction is assumed to reach, 'To' instruction.
LLVM Basic Block Representation.
Instruction * getInstruction() const
Return the underlying instruction.
This is an important class for using LLVM in a threaded context.
const Function & getReplacedFn() const
void unionKnown(const ConstantRange &R)
Unite known range with the passed state.
static const char ID
Unique ID (due to the unique address)
An abstract interface for all dereferenceable attribute.
AAType & registerAA(AAType &AA)
Introduce a new abstract attribute into the fixpoint analysis.
bool isKnownNoSync() const
Returns true if "nosync" is known.
IntegerStateBase::base_t base_t
void unionAssumed(const ConstantRange &R)
Unite assumed range with the passed state.
void unionAssumed(const IntegerRangeState &R)
See IntegerRangeState::unionAssumed(..).
void registerInvokeWithDeadSuccessor(InvokeInst &II)
Record that II has at least one dead successor block.
const Argument & getReplacedArg() const
bool operator==(const IntegerStateBase< base_t, BestState, WorstState > &R) const
Equality for IntegerStateBase.
AANoUnwind(const IRPosition &IRP)
AttributeList getAttributes() const
Get the parameter attributes of the call.
A manager for alias analyses.
bool isKnownNoCapture() const
Return true if we know that the underlying value is not captured in its respective scope...
void changeToUnreachableAfterManifest(Instruction *I)
Record that I is to be replaced with unreachable after information was manifested.
AADereferenceable(const IRPosition &IRP)
static const IRPosition returned(const Function &F)
Create a position describing the returned value of F.
const IRPosition & getIRPosition() const override
Return an IR position, see struct IRPosition.
An attribute for a function (scope).
virtual void initialize(Attributor &A)
Initialize the state with the information in the Attributor A.
static constexpr base_t getWorstState()
Return the worst possible representable state.
BitIntegerState & intersectAssumedBits(base_t BitsEncoding)
Keep only "assumed bits" also set in BitsEncoding but all known ones.
ConstantRange getKnown() const
Return the known state encoding.
static ChangeStatus manifestAttrs(Attributor &A, const IRPosition &IRP, const ArrayRef< Attribute > &DeducedAttrs)
AANoFree(const IRPosition &IRP)
bool isAssumedNoCaptureMaybeReturned() const
Return true if we assume that the underlying value is not captured in its respective scope but we all...
An attribute for a function argument.
bool isFnInterfaceKind() const
Return true if the position refers to a function interface, that is the function scope, the function return, or an argument.
bool isAssumedNonNull() const
Return true if we assume that the underlying value is nonnull.
The fixpoint analysis framework that orchestrates the attribute deduction.
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
bool isFullSet() const
Return true if this set contains all of the elements possible for this data-type. ...
void intersectKnown(const ConstantRange &R)
Intersect known range with the passed state.
BitIntegerState & addKnownBits(base_t Bits)
Add the bits in BitsEncoding to the "known bits".
const DataLayout & getDataLayout() const
Return the data layout associated with the anchor scope.
static unsigned getHashValue(const IRPosition &IRP)
const Function * getFunction() const
Return the function this instruction belongs to.
DecIntegerState & takeAssumedMaximum(base_t Value)
Take maximum of assumed and Value.
Simple state with integers encoding.
Attribute::AttrKind getAttrKind() const
Return the kind that identifies the abstract attribute implementation.
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
Attribute getAttribute(unsigned Index, Attribute::AttrKind Kind) const
Return the attribute object that exists at the given index.
IncIntegerState & takeAssumedMinimum(base_t Value)
Take minimum of assumed and Value.
Base struct for all "concrete attribute" deductions.
static wasm::ValType getType(const TargetRegisterClass *RC)
static const char ID
Unique ID (due to the unique address)
AAMemoryBehavior(const IRPosition &IRP)
unsigned getNumReplacementArgs() const
Value * AnchorVal
The value this position is anchored at.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static const char ID
Unique ID (due to the unique address)
bool verify(const TargetRegisterInfo &TRI) const
Check that information hold by this instance make sense for the given TRI.
StateType & getState() override
See AbstractAttribute::getState(...).
bool isKnownHeapToStack() const
Returns true if HeapToStack conversion is known to be possible.
Specialization of the integer state for a decreasing value, hence 0 is the best state and ~0u the wor...
ChangeStatus indicatePessimisticFixpoint() override
See AbstractState::indicatePessimisticFixpoint(...)
bool isAssumed(base_t BitsEncoding) const
Return true if the bits set in BitsEncoding are "assumed bits".
An abstract interface for all memory related attributes.
AAValueConstantRange(const IRPosition &IRP)
bool isAtFixpoint() const override
See AbstractState::isAtFixpoint()
bool isEmptySet() const
Return true if this set contains no members.
static constexpr base_t getBestState()
Return the best possible representable state.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
const AAType & getAAFor(const AbstractAttribute &QueryingAA, const IRPosition &IRP, bool TrackDependence=true, DepClassTy DepClass=DepClassTy::REQUIRED)
Lookup an abstract attribute of type AAType at position IRP.
void setKnown(bool Value)
Set the known and asssumed value to Value.
Attributor(InformationCache &InfoCache, unsigned DepRecomputeInterval, DenseSet< const char *> *Whitelist=nullptr)
Constructor.
bool isKnownNonNull() const
Return true if we know that the underlying value is nonnull.
static const char ID
Unique ID (due to the unique address)
An AbstractAttribute for nofree.
A SetVector that performs no allocations if smaller than a certain size.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
BlockVerifier::State From
AANoRecurse(const IRPosition &IRP)
const IRPosition & getIRPosition() const override
Return an IR position, see struct IRPosition.
Align max(MaybeAlign Lhs, Align Rhs)
An abstract attribute for undefined behavior.
bool isAssumedNoCapture() const
Return true if we assume that the underlying value is not captured in its respective scope...
void deleteAfterManifest(Instruction &I)
Record that I is deleted after information was manifested.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
bool isKnownReadNone() const
Return true if we know that the underlying value is not read or accessed in its respective scope...
Provides information about what library functions are available for the current target.
base_t getKnown() const
Return the known state encoding.
uint32_t getBitWidth() const
Return associated values' bit width.
This class represents a range of values.
void markLiveInternalFunction(const Function &F)
Mark the internal function F as live.
static const IRPosition callsite_argument(ImmutableCallSite ICS, unsigned ArgNo)
Create a position describing the argument of ICS at position ArgNo.
IRAttribute(const IRPosition &IRP)
static Constant * get(Type *Ty, uint64_t V, bool isSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
virtual void initialize(Attributor &A) override
See AbstractAttribute::initialize(...).
An abstract interface to determine reachability of point A to B.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Implements a dense probed hash-table based set with some number of buckets stored inline...
void operator^=(const IntegerStateBase< base_t, BestState, WorstState > &R)
"Clamp" this state with R.
static const IRPosition callsite_returned(const CallBase &CB)
Create a position describing the returned value of CB.
IntegerRangeState(uint32_t BitWidth)
A range adaptor for a pair of iterators.
Helper class that provides common functionality to manifest IR attributes.
static const char ID
Unique ID (due to the unique address)
void operator|=(const IntegerStateBase< base_t, BestState, WorstState > &R)
static const char ID
Unique ID (due to the unique address)
unsigned getArgNo() const
Return the index of this formal argument in its containing function.
const IRPosition & getIRPosition() const override
Return an IR position, see struct IRPosition.
static const char ID
Unique ID (due to the unique address)
static const IRPosition value(const Value &V)
Create a position describing the value of V.
const AbstractState & getState() const override
A "must be executed context" for a given program point PP is the set of instructions, potentially before and after PP, that are executed always when PP is reached.
ChangeStatus indicateOptimisticFixpoint() override
See AbstractState::indicateOptimisticFixpoint(...)
const SmallVectorImpl< Type * > & getReplacementTypes() const
static ConstantRange getBestState(uint32_t BitWidth)
Return the best possible representable state.
An interface to query the internal state of an abstract attribute.
void deleteAfterManifest(Function &F)
Record that F is deleted after information was manifested.
bool operator!=(uint64_t V1, const APInt &V2)
An analysis pass to compute the CallGraph for a Module.
IncIntegerState DerefBytesState
State representing for dereferenceable bytes.
An abstract interface for all align attributes.
The basic data container for the call graph of a Module of IR.
bool isAssumedWriteOnly() const
Return true if we assume that the underlying value is not read in its respective scope.
static const IRPosition argument(const Argument &Arg)
Create a position describing the argument Arg.
bool isAssumedToCauseUB() const
Return true if "undefined behavior" is assumed.
block Block Frequency Analysis
static bool isEqual(const IRPosition &LHS, const IRPosition &RHS)
Analysis::Result * getAnalysis(const Function &F)
const Function * getParent() const
bool changeValueAfterManifest(Value &V, Value &NV)
Helper function to replace all uses of V with NV.
ChangeStatus indicatePessimisticFixpoint() override
See AbstractState::indicatePessimisticFixpoint(...)
Pass * createAttributorLegacyPass()
Optional< ConstantInt * > getAssumedConstantInt(Attributor &A, const Instruction *CtxI=nullptr) const
Return an assumed constant for the assocaited value a program point CtxI.
InformationCache & getInfoCache()
Return the internal information cache.
bool isKnownToCauseUB() const
Return true if "undefined behavior" is known.
bool hasExactDefinition() const
Return true if this global has an exact defintion.
Establish a view to a call site for examination.
Helper struct used in the communication between an abstract attribute (AA) that wants to change the s...
LLVM_NODISCARD AttributeList removeAttribute(LLVMContext &C, unsigned Index, Attribute::AttrKind Kind) const
Remove the specified attribute at the specified index from this attribute list.
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static const char ID
Unique ID (due to the unique address)
An abstract interface for value simplify abstract attribute.
bool isKnownReachable(const Instruction *From, const Instruction *To) const
Returns true if 'From' instruction is known to reach, 'To' instruction.
virtual void getDeducedAttributes(LLVMContext &Ctx, SmallVectorImpl< Attribute > &Attrs) const
Return the deduced attributes in Attrs.
static const IRPosition callsite_function(const CallBase &CB)
Create a position describing the function scope of CB.
bool isLiveInstSet(T begin, T end) const
This method is used to check if at least one instruction in a collection of instructions is live...
static Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val=0)
Return a uniquified Attribute object.
An attribute for a call site (function scope).
static const char ID
Unique ID (due to the unique address)
Function * getAssociatedFunction() const
Return the associated function, if any.
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
An abstract interface for range value analysis.
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
ConstantRange unionWith(const ConstantRange &CR, PreferredRangeType Type=Smallest) const
Return the range that results from the union of this range with another range.
unsigned getAssumedAlign() const
Return assumed alignment.
bool isKnownGlobal() const
Return true if we know that underlying value is dereferenceable(_or_null) globally.
bool isKnownNoRecurse() const
Return true if "norecurse" is known.
AAValueSimplify(const IRPosition &IRP)
Analysis pass providing the TargetLibraryInfo.
AANonNull(const IRPosition &IRP)
static const IRPosition EmptyKey
Special DenseMap key values.
IntegerRangeState operator^=(const IntegerRangeState &R)
"Clamp" this state with R.
bool isKnownWillReturn() const
Return true if "willreturn" is known.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static const IRPosition TombstoneKey
const IRPosition & getIRPosition() const
Return an IR position, see struct IRPosition.
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
bool isKnownNonNull() const
Return true if we know that underlying value is nonnull.
E & operator &=(E &LHS, E RHS)
const AbstractState & getState() const override
See AbstractAttribute::getState(...).
virtual ChangeStatus manifest(Attributor &A)
Hook for the Attributor to trigger the manifestation of the information represented by the abstract a...
A vector that has set insertion semantics.
bool isAssumedWillReturn() const
Return true if "willreturn" is assumed.
static const char ID
Unique ID (due to the unique address)
virtual ~AbstractAttribute()
Virtual destructor.
bool isAssumedReadNone() const
Return true if we assume that the underlying value is not read or accessed in its respective scope...
This class implements an extremely fast bulk output stream that can only output to a stream...
State for dereferenceable attribute.
DecIntegerState & takeKnownMinimum(base_t Value)
Take minimum of known and Value.
print Print MemDeps of function
static const IRPosition callsite_argument(const CallBase &CB, unsigned ArgNo)
Create a position describing the argument of CB at position ArgNo.
bool isKnownNoAlias() const
Return true if we know that underlying value is noalias.
A container for analyses that lazily runs them and caches their results.
bool operator==(uint64_t V1, const APInt &V2)
APInt operator|(APInt a, const APInt &b)
AAIsDead(const IRPosition &IRP)
This header defines various interfaces for pass management in LLVM.
bool isAssumedNonNull() const
Return true if we assume that the underlying value is nonnull.
ChangeStatus indicateOptimisticFixpoint() override
See AbstractState::indicateOptimisticFixpoint(...)
AANoSync(const IRPosition &IRP)
bool changeUseAfterManifest(Use &U, Value &NV)
Record that U is to be replaces with NV after information was manifested.
int KindOrArgNo
The argument number, if non-negative, or the position "kind".
static const IRPosition function(const Function &F)
Create a position describing the function scope of F.
Value & getAnchorValue() const
Return the value this abstract attribute is anchored with.
IRPosition()
Default constructor available to create invalid positions implicitly.
Kind getPositionKind() const
Return the associated position kind.
BitIntegerState & removeKnownBits(base_t BitsEncoding)
Remove the bits in BitsEncoding from the "known bits".
void deleteAfterManifest(BasicBlock &BB)
Record that BB is deleted after information was manifested.
AnalysisGetter(ModuleAnalysisManager &MAM)
bool operator!=(const IntegerStateBase< base_t, BestState, WorstState > &R) const
Inequality for IntegerStateBase.
Enumerate the SCCs of a directed graph in reverse topological order of the SCC DAG.
Simple wrapper for a single bit (boolean) state.
AttrKind
This enumeration lists the attributes that can be associated with parameters, function results...
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...