43 cl::desc(
"Enable verification of assumption cache"),
47AssumptionCache::getOrInsertAffectedValues(
Value *V) {
50 auto AVI = AffectedValues.find_as(V);
51 if (AVI != AffectedValues.end())
54 return AffectedValues[AffectedValueCallbackVH(V,
this)];
59 auto AddAffectedVal = [&](
Value *V) {
64 if (Bundle.
getTagName() ==
"separate_storage") {
65 assert(Bundle.
Inputs.size() == 2 &&
"separate_storage must have two args");
79 auto InsertAffected = [&Affected](
Value *V) {
83 auto AddAffectedVal = [&Affected](
Value *V,
unsigned Idx) {
92 [&](
Value *V) { Affected.push_back({V, Idx}); });
100 std::tie(Ptr, AS) =
TTI->getPredicatedAddrSpace(
Cond);
111 for (
auto &AV : Affected) {
112 auto &AVV = getOrInsertAffectedValues(AV.Assume);
114 return Elem.
Assume == CI && Elem.
Index == AV.Index;
116 AVV.push_back({CI, AV.Index});
120void AssumptionCache::removeAffectedValues(
AssumeInst *CI) {
138 for (
auto &AV : Affected)
139 if (Seen.
insert({AV.Assume, AV.Index}).second &&
140 AffectedValues.find_as(AV.Assume) != AffectedValues.end())
141 ExpectedMatches[AV.Assume]++;
144 for (
auto &AV : Affected) {
145 auto AVI = AffectedValues.find_as(AV.Assume);
146 if (AVI == AffectedValues.end())
149 bool HasNonnull =
false;
150 for (ResultElem &Elem : AVI->second) {
151 if (Elem.Assume == CI) {
153 Elem.Assume =
nullptr;
156 ExpectedMatches[AV.Assume]--;
158 assert(ExpectedMatches[AV.Assume] >= 0);
163 HasNonnull |= !!Elem.Assume;
164 if (HasNonnull && Found)
168 assert(ExpectedMatches[AV.Assume] == 0 ||
169 Found &&
"already unregistered or incorrect cache state");
172 AffectedValues.erase(AVI);
176 none_of(Affected, [&](
auto &AV) {
return ExpectedMatches[AV.Assume]; }) &&
177 "already unregistered or incorrect cache state");
181 removeAffectedValues(CI);
196void AssumptionCache::transferAffectedValuesInCache(
Value *OV,
Value *NV) {
197 auto &NAVV = getOrInsertAffectedValues(NV);
198 auto AVI = AffectedValues.find(OV);
199 if (AVI == AffectedValues.end())
202 for (
auto &
A : AVI->second)
205 AffectedValues.erase(OV);
208void AssumptionCache::AffectedValueCallbackVH::allUsesReplacedWith(
Value *NV) {
214 AC->transferAffectedValuesInCache(getValPtr(), NV);
220void AssumptionCache::scanFunction() {
221 assert(!Scanned &&
"Tried to scan the function twice!");
222 assert(AssumeHandles.empty() &&
"Already have assumes when scanning!");
226 for (BasicBlock &
B : F)
227 for (Instruction &
I :
B)
229 AssumeHandles.push_back(&
I);
235 for (
auto &
A : AssumeHandles)
245 AssumeHandles.push_back(CI);
249 "Cannot register @llvm.assume call not in a basic block");
251 "Cannot register @llvm.assume call not in this function");
257 for (
auto &VH : AssumeHandles) {
262 "Cached assumption not inside this function!");
264 "Cached something other than a call to @llvm.assume!");
266 "Cache contains multiple copies of a call!");
285 OS <<
"Cached assumptions for function: " <<
F.getName() <<
"\n";
291 if (!Assume->hasOperandBundles()) {
292 OS <<
" " << *Assume->getArgOperand(0) <<
"\n";
297 "assume must have trivial cond");
301 OS << LS <<
'"' << BU.getTagName() <<
"\"(";
303 [&](
const Use &
Input) { Input->printAsOperand(OS); });
314 if (
I != ACT->AssumptionCaches.end())
315 ACT->AssumptionCaches.erase(
I);
324 auto I = AssumptionCaches.find_as(&
F);
325 if (
I != AssumptionCaches.end())
329 auto *
TTI = TTIWP ? &TTIWP->getTTI(
F) :
nullptr;
333 auto IP = AssumptionCaches.insert(std::make_pair(
334 FunctionCallbackVH(&
F,
this), std::make_unique<AssumptionCache>(
F,
TTI)));
335 assert(IP.second &&
"Scanning function already in the map?");
336 return *IP.first->second;
340 auto I = AssumptionCaches.find_as(&
F);
341 if (
I != AssumptionCaches.end())
342 return I->second.get();
355 for (
const auto &
I : AssumptionCaches) {
356 for (
auto &VH :
I.second->assumptions())
375 "Assumption Cache Tracker",
false,
true)
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static void findAffectedValues(CallBase *CI, TargetTransformInfo *TTI, SmallVectorImpl< AssumptionCache::ResultElem > &Affected)
static cl::opt< bool > VerifyAssumptionCache("verify-assumption-cache", cl::Hidden, cl::desc("Enable verification of assumption cache"), cl::init(false))
static const Function * getParent(const Value *V)
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This file defines the DenseSet and SmallDenseSet classes.
This header defines various interfaces for pass management in LLVM.
uint64_t IntrinsicInst * II
FunctionAnalysisManager FAM
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
const SmallVectorImpl< MachineOperand > & Cond
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
This represents the llvm.assume intrinsic.
A function analysis which provides an AssumptionCache.
LLVM_ABI AssumptionCache run(Function &F, FunctionAnalysisManager &)
An immutable pass that tracks lazily created AssumptionCache objects.
~AssumptionCacheTracker() override
AssumptionCache * lookupAssumptionCache(Function &F)
Return the cached assumptions for a function if it has already been scanned.
void verifyAnalysis() const override
verifyAnalysis() - This member can be implemented by a analysis pass to check state of analysis infor...
AssumptionCache & getAssumptionCache(Function &F)
Get the cached assumptions for a function.
A cache of @llvm.assume calls within a function.
static LLVM_ABI void findValuesAffectedByOperandBundle(OperandBundleUse Bundle, function_ref< void(Value *)> InsertAffected)
Determine which values are affected by this assume operand bundle.
LLVM_ABI void registerAssumption(AssumeInst *CI)
Add an @llvm.assume intrinsic to this function's cache.
LLVM_ABI void replaceAssumption(WeakVH &Handle, AssumeInst *New)
Replace the assumption referenced by Handle (must be a valid handle for a registered assumption) with...
LLVM_ABI void updateAffectedValues(AssumeInst *CI)
Update the cache of values being affected by this assumption (i.e.
MutableArrayRef< WeakVH > assumptions()
Access the list of assumption handles currently tracked for this function.
LLVM_ABI void unregisterAssumption(AssumeInst *CI)
Remove an @llvm.assume intrinsic from this function's cache if it has been added to the cache earlier...
AssumptionCache(Function &F, TargetTransformInfo *TTI=nullptr)
Construct an AssumptionCache from a function by scanning all of its instructions.
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
LLVM Basic Block Representation.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
OperandBundleUse getOperandBundleAt(unsigned Index) const
Return the operand bundle at a specific index.
unsigned getNumOperandBundles() const
Return the number of operand bundles associated with this User.
virtual void deleted()
Callback for Value destruction.
A helper class to return the specified delimiter string after the first invocation of operator String...
AnalysisType * getAnalysisIfAvailable() const
getAnalysisIfAvailable<AnalysisType>() - Subclasses use this function to get analysis information tha...
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Implements a dense probed hash-table based set with some number of buckets stored inline.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Analysis pass providing the TargetTransformInfo.
A Use represents the edge between a Value definition and its users.
Value * getValPtr() const
LLVM Value Representation.
LLVM_ABI const Value * stripInBoundsOffsets(function_ref< void(const Value *)> Func=[](const Value *) {}) const
Strip off pointer casts and inbounds GEPs.
A nullable Value handle that is nullable.
std::pair< iterator, bool > insert(const ValueT &V)
An efficient, type-erasing, non-owning reference to a callable.
const ParentTy * getParent() const
bool match(Val *V, const Pattern &P)
cst_pred_ty< is_one > m_One()
Match an integer 1 or a vector with all elements equal to 1.
auto m_Intrinsic(const Ts &...Ops)
Match intrinsic calls like this: m_Intrinsic<Intrinsic::fabs>(m_Value(X))
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
constexpr StringRef IgnoreBundleTag
Tag in operand bundle indicating that this bundle should be ignored.
void interleaveComma(const Container &c, StreamT &os, UnaryFunctor each_fn)
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
void erase(Container &C, ValueType V)
Wrapper function to remove a value from a container:
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
LLVM_ABI const Value * getUnderlyingObject(const Value *V, unsigned MaxLookup=MaxLookupSearchDepth)
This method strips off any GEP address adjustments, pointer casts or llvm.threadlocal....
LLVM_ABI void findValuesAffectedByCondition(Value *Cond, bool IsAssume, function_ref< void(Value *)> InsertAffected)
Call InsertAffected on all Values whose known bits / value may be affected by the condition Cond.
A special type used by analysis passes to provide an address that identifies that particular analysis...
unsigned Index
contains either ExprResultIdx or the index of the operand bundle containing the knowledge.
A lightweight accessor for an operand bundle meant to be passed around by value.
StringRef getTagName() const
Return the tag of this operand bundle as a string.