25 using namespace llvm::PatternMatch;
27 void AssumptionCache::scanFunction() {
28 assert(!Scanned &&
"Tried to scan the function twice!");
29 assert(AssumeHandles.empty() &&
"Already have assumes when scanning!");
35 if (
match(&II, m_Intrinsic<Intrinsic::assume>()))
36 AssumeHandles.push_back(&II);
43 assert(
match(CI, m_Intrinsic<Intrinsic::assume>()) &&
44 "Registered call does not call @llvm.assume");
51 AssumeHandles.push_back(CI);
55 "Cannot register @llvm.assume call not in a basic block");
57 "Cannot register @llvm.assume call not in this function");
63 for (
auto &VH : AssumeHandles) {
68 "Cached assumption not inside this function!");
69 assert(
match(cast<CallInst>(VH), m_Intrinsic<Intrinsic::assume>()) &&
70 "Cached something other than a call to @llvm.assume!");
71 assert(AssumptionSet.insert(VH).second &&
72 "Cache contains multiple copies of a call!");
77 char AssumptionAnalysis::PassID;
83 OS <<
"Cached assumptions for function: " << F.
getName() <<
"\n";
86 OS <<
" " << *cast<CallInst>(VH)->getArgOperand(0) <<
"\n";
91 void AssumptionCacheTracker::FunctionCallbackVH::deleted() {
92 auto I = ACT->AssumptionCaches.find_as(cast<Function>(getValPtr()));
93 if (
I != ACT->AssumptionCaches.end())
94 ACT->AssumptionCaches.erase(
I);
103 auto I = AssumptionCaches.find_as(&F);
104 if (
I != AssumptionCaches.end())
109 auto IP = AssumptionCaches.insert(std::make_pair(
110 FunctionCallbackVH(&F,
this), llvm::make_unique<AssumptionCache>(F)));
111 assert(
IP.second &&
"Scanning function already in the map?");
112 return *
IP.first->second;
118 for (
const auto &
I : AssumptionCaches) {
119 for (
auto &VH :
I.second->assumptions())
121 AssumptionSet.
insert(cast<CallInst>(VH));
123 for (
const BasicBlock &B : cast<Function>(*
I.first))
125 if (
match(&II, m_Intrinsic<Intrinsic::assume>()))
126 assert(AssumptionSet.
count(cast<CallInst>(&II)) &&
127 "Assumption in scanned function not in cache");
139 "Assumption Cache Tracker",
false,
true)
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
CallInst - This class represents a function call, abstracting a target machine's calling convention...
size_type count(PtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
An immutable pass that tracks lazily created AssumptionCache objects.
A cache of .assume calls within a function.
const Function * getParent() const
Return the enclosing method, or null if none.
StringRef getName() const
Return a constant reference to the value's name.
bool match(Val *V, const Pattern &P)
An abstract set of preserved analyses following a transformation pass run.
LLVM Basic Block Representation.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
MutableArrayRef< WeakVH > assumptions()
Access the list of assumption handles currently tracked for this fuction.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
A function analysis which provides an AssumptionCache.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
ImmutablePass class - This class is used to provide information that does not need to be run...
~AssumptionCacheTracker() override
PassT::Result & getResult(IRUnitT &IR)
Get the result of an analysis pass for this module.
void registerAssumption(CallInst *CI)
Add an .assume intrinsic to this function's cache.
PreservedAnalyses run(Function &F, AnalysisManager< Function > *AM)
static const Function * getParent(const Value *V)
AssumptionCache & getAssumptionCache(Function &F)
Get the cached assumptions for a function.
A generic analysis pass manager with lazy running and caching of results.
void initializeAssumptionCacheTrackerPass(PassRegistry &)
void verifyAnalysis() const override
verifyAnalysis() - This member can be implemented by a analysis pass to check state of analysis infor...
This header defines various interfaces for pass management in LLVM.
const BasicBlock * getParent() const