LLVM 24.0.0git
GlobalsModRef.cpp
Go to the documentation of this file.
1//===- GlobalsModRef.cpp - Simple Mod/Ref Analysis for Globals ------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This simple pass provides alias and mod/ref information for global values
10// that do not have their address taken, and keeps track of whether functions
11// read or write memory (are "pure"). For this simple (but very common) case,
12// we can provide pretty accurate and useful information.
13//
14//===----------------------------------------------------------------------===//
15
17#include "AnalysisOptions.h"
20#include "llvm/ADT/Statistic.h"
24#include "llvm/IR/Constants.h"
27#include "llvm/IR/Module.h"
28#include "llvm/IR/PassManager.h"
30#include "llvm/Pass.h"
31
32using namespace llvm;
33
34#define DEBUG_TYPE "globalsmodref-aa"
35
36STATISTIC(NumNonAddrTakenGlobalVars,
37 "Number of global vars without address taken");
38STATISTIC(NumNonAddrTakenFunctions,"Number of functions without address taken");
39STATISTIC(NumNoMemFunctions, "Number of functions that do not access memory");
40STATISTIC(NumReadMemFunctions, "Number of functions that only read memory");
41STATISTIC(NumIndirectGlobalVars, "Number of indirect global objects");
42
43/// The mod/ref information collected for a particular function.
44///
45/// We collect information about mod/ref behavior of a function here, both in
46/// general and as pertains to specific globals. We only have this detailed
47/// information when we know *something* useful about the behavior. If we
48/// saturate to fully general mod/ref, we remove the info for the function.
51
52 /// Build a wrapper struct that has 8-byte alignment. All heap allocations
53 /// should provide this much alignment at least, but this makes it clear we
54 /// specifically rely on this amount of alignment.
55 struct alignas(8) AlignedMap {
56 AlignedMap() = default;
57 AlignedMap(const AlignedMap &Arg) = default;
58 GlobalInfoMapType Map;
59 };
60
61 /// Pointer traits for our aligned map.
62 struct AlignedMapPointerTraits {
63 static inline void *getAsVoidPointer(AlignedMap *P) { return P; }
64 static inline AlignedMap *getFromVoidPointer(void *P) {
65 return (AlignedMap *)P;
66 }
67 static constexpr int NumLowBitsAvailable = 3;
68 static_assert(alignof(AlignedMap) >= (1 << NumLowBitsAvailable),
69 "AlignedMap insufficiently aligned to have enough low bits.");
70 };
71
72 /// The bit that flags that this function may read any global. This is
73 /// chosen to mix together with ModRefInfo bits.
74 /// FIXME: This assumes ModRefInfo lattice will remain 4 bits!
75 /// FunctionInfo.getModRefInfo() masks out everything except ModRef so
76 /// this remains correct.
77 enum { MayReadAnyGlobal = 4 };
78
79 /// Checks to document the invariants of the bit packing here.
80 static_assert((MayReadAnyGlobal & static_cast<int>(ModRefInfo::ModRef)) == 0,
81 "ModRef and the MayReadAnyGlobal flag bits overlap.");
82 static_assert(((MayReadAnyGlobal | static_cast<int>(ModRefInfo::ModRef)) >>
83 AlignedMapPointerTraits::NumLowBitsAvailable) == 0,
84 "Insufficient low bits to store our flag and ModRef info.");
85
86public:
87 FunctionInfo() = default;
89 delete Info.getPointer();
90 }
91 // Spell out the copy ond move constructors and assignment operators to get
92 // deep copy semantics and correct move semantics in the face of the
93 // pointer-int pair.
95 : Info(nullptr, Arg.Info.getInt()) {
96 if (const auto *ArgPtr = Arg.Info.getPointer())
97 Info.setPointer(new AlignedMap(*ArgPtr));
98 }
100 : Info(Arg.Info.getPointer(), Arg.Info.getInt()) {
101 Arg.Info.setPointerAndInt(nullptr, 0);
102 }
104 delete Info.getPointer();
105 Info.setPointerAndInt(nullptr, RHS.Info.getInt());
106 if (const auto *RHSPtr = RHS.Info.getPointer())
107 Info.setPointer(new AlignedMap(*RHSPtr));
108 return *this;
109 }
111 delete Info.getPointer();
112 Info.setPointerAndInt(RHS.Info.getPointer(), RHS.Info.getInt());
113 RHS.Info.setPointerAndInt(nullptr, 0);
114 return *this;
115 }
116
117 /// This method clears MayReadAnyGlobal bit added by GlobalsAAResult to return
118 /// the corresponding ModRefInfo.
120 return ModRefInfo(I & static_cast<int>(ModRefInfo::ModRef));
121 }
122
123 /// Returns the \c ModRefInfo info for this function.
125 return globalClearMayReadAnyGlobal(Info.getInt());
126 }
127
128 /// Adds new \c ModRefInfo for this function to its state.
130 Info.setInt(Info.getInt() | static_cast<int>(NewMRI));
131 }
132
133 /// Returns whether this function may read any global variable, and we don't
134 /// know which global.
135 bool mayReadAnyGlobal() const { return Info.getInt() & MayReadAnyGlobal; }
136
137 /// Sets this function as potentially reading from any global.
138 void setMayReadAnyGlobal() { Info.setInt(Info.getInt() | MayReadAnyGlobal); }
139
140 /// Returns the \c ModRefInfo info for this function w.r.t. a particular
141 /// global, which may be more precise than the general information above.
143 ModRefInfo GlobalMRI =
145 if (AlignedMap *P = Info.getPointer()) {
146 auto I = P->Map.find(&GV);
147 if (I != P->Map.end())
148 GlobalMRI |= I->second;
149 }
150 return GlobalMRI;
151 }
152
153 /// Add mod/ref info from another function into ours, saturating towards
154 /// ModRef.
157
158 if (FI.mayReadAnyGlobal())
160
161 if (AlignedMap *P = FI.Info.getPointer())
162 for (const auto &G : P->Map)
163 addModRefInfoForGlobal(*G.first, G.second);
164 }
165
167 AlignedMap *P = Info.getPointer();
168 if (!P) {
169 P = new AlignedMap();
170 Info.setPointer(P);
171 }
172 auto &GlobalMRI = P->Map[&GV];
173 GlobalMRI |= NewMRI;
174 }
175
176 /// Clear a global's ModRef info. Should be used when a global is being
177 /// deleted.
179 if (AlignedMap *P = Info.getPointer())
180 P->Map.erase(&GV);
181 }
182
183private:
184 /// All of the information is encoded into a single pointer, with a three bit
185 /// integer in the low three bits. The high bit provides a flag for when this
186 /// function may read any global. The low two bits are the ModRefInfo. And
187 /// the pointer, when non-null, points to a map from GlobalValue to
188 /// ModRefInfo specific to that GlobalValue.
190};
191
192void GlobalsAAResult::DeletionCallbackHandle::deleted() {
193 Value *V = getValPtr();
194 if (auto *F = dyn_cast<Function>(V))
195 GAR->FunctionInfos.erase(F);
196
197 if (GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
198 if (GAR->NonAddressTakenGlobals.erase(GV)) {
199 // This global might be an indirect global. If so, remove it and
200 // remove any AllocRelatedValues for it.
201 if (GAR->IndirectGlobals.erase(GV)) {
202 // Remove any entries in AllocsForIndirectGlobals for this global.
203 GAR->AllocsForIndirectGlobals.remove_if(
204 [GV](const auto &Entry) { return Entry.second == GV; });
205 }
206
207 // Scan the function info we have collected and remove this global
208 // from all of them.
209 for (auto &FIPair : GAR->FunctionInfos)
210 FIPair.second.eraseModRefInfoForGlobal(*GV);
211 }
212 }
213
214 // If this is an allocation related to an indirect global, remove it.
215 GAR->AllocsForIndirectGlobals.erase(V);
216
217 // And clear out the handle.
218 setValPtr(nullptr);
219 GAR->Handles.erase(I);
220 // This object is now destroyed!
221}
222
224 if (FunctionInfo *FI = getFunctionInfo(F))
225 return MemoryEffects(FI->getModRefInfo());
226
227 return MemoryEffects::unknown();
228}
229
230/// Returns the function info for the function, or null if we don't have
231/// anything useful to say about it.
233GlobalsAAResult::getFunctionInfo(const Function *F) {
234 auto I = FunctionInfos.find(F);
235 if (I != FunctionInfos.end())
236 return &I->second;
237 return nullptr;
238}
239
240/// AnalyzeGlobals - Scan through the users of all of the internal
241/// GlobalValue's in the program. If none of them have their "address taken"
242/// (really, their address passed to something nontrivial), record this fact,
243/// and record the functions that they are used directly in.
244void GlobalsAAResult::AnalyzeGlobals(Module &M) {
245 SmallPtrSet<Function *, 32> TrackedFunctions;
246 for (Function &F : M)
247 if (F.hasLocalLinkage()) {
248 if (!AnalyzeUsesOfPointer(&F)) {
249 // Remember that we are tracking this global.
250 NonAddressTakenGlobals.insert(&F);
251 TrackedFunctions.insert(&F);
252 Handles.emplace_front(*this, &F);
253 Handles.front().I = Handles.begin();
254 ++NumNonAddrTakenFunctions;
255 } else
256 UnknownFunctionsWithLocalLinkage = true;
257 }
258
259 SmallPtrSet<Function *, 16> Readers, Writers;
260 for (GlobalVariable &GV : M.globals())
261 if (GV.hasLocalLinkage()) {
262 if (!AnalyzeUsesOfPointer(&GV, &Readers,
263 GV.isConstant() ? nullptr : &Writers)) {
264 // Remember that we are tracking this global, and the mod/ref fns
265 NonAddressTakenGlobals.insert(&GV);
266 Handles.emplace_front(*this, &GV);
267 Handles.front().I = Handles.begin();
268
269 for (Function *Reader : Readers) {
270 if (TrackedFunctions.insert(Reader).second) {
271 Handles.emplace_front(*this, Reader);
272 Handles.front().I = Handles.begin();
273 }
274 FunctionInfos[Reader].addModRefInfoForGlobal(GV, ModRefInfo::Ref);
275 }
276
277 if (!GV.isConstant()) // No need to keep track of writers to constants
278 for (Function *Writer : Writers) {
279 if (TrackedFunctions.insert(Writer).second) {
280 Handles.emplace_front(*this, Writer);
281 Handles.front().I = Handles.begin();
282 }
283 FunctionInfos[Writer].addModRefInfoForGlobal(GV, ModRefInfo::Mod);
284 }
285 ++NumNonAddrTakenGlobalVars;
286
287 // If this global holds a pointer type, see if it is an indirect global.
288 if (GV.getValueType()->isPointerTy() &&
289 AnalyzeIndirectGlobalMemory(&GV))
290 ++NumIndirectGlobalVars;
291 }
292 Readers.clear();
293 Writers.clear();
294 }
295}
296
297/// AnalyzeUsesOfPointer - Look at all of the users of the specified pointer.
298/// If this is used by anything complex (i.e., the address escapes), return
299/// true. Also, while we are at it, keep track of those functions that read and
300/// write to the value.
301///
302/// If OkayStoreDest is non-null, stores into this global are allowed.
303bool GlobalsAAResult::AnalyzeUsesOfPointer(Value *V,
304 SmallPtrSetImpl<Function *> *Readers,
305 SmallPtrSetImpl<Function *> *Writers,
306 GlobalValue *OkayStoreDest) {
307 if (!V->getType()->isPointerTy())
308 return true;
309
310 for (Use &U : V->uses()) {
311 User *I = U.getUser();
312 if (LoadInst *LI = dyn_cast<LoadInst>(I)) {
313 if (Readers)
314 Readers->insert(LI->getParent()->getParent());
315 } else if (StoreInst *SI = dyn_cast<StoreInst>(I)) {
316 // Check the pointer operand use of the store.
317 if (&U == &SI->getOperandUse(1)) {
318 if (Writers)
319 Writers->insert(SI->getParent()->getParent());
320 } else if (SI->getOperand(1) != OkayStoreDest) {
321 return true; // Storing the pointer
322 }
323 } else if (Operator::getOpcode(I) == Instruction::GetElementPtr) {
324 if (AnalyzeUsesOfPointer(I, Readers, Writers))
325 return true;
326 } else if (Operator::getOpcode(I) == Instruction::BitCast ||
327 Operator::getOpcode(I) == Instruction::AddrSpaceCast) {
328 if (AnalyzeUsesOfPointer(I, Readers, Writers, OkayStoreDest))
329 return true;
330 } else if (auto *Call = dyn_cast<CallBase>(I)) {
331 if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(I)) {
332 if (II->getIntrinsicID() == Intrinsic::threadlocal_address &&
333 V == II->getArgOperand(0)) {
334 if (AnalyzeUsesOfPointer(II, Readers, Writers))
335 return true;
336 continue;
337 }
338 }
339 // Make sure that this is just the function being called, not that it is
340 // passing into the function.
341 if (Call->isDataOperand(&U)) {
342 // Detect calls to free.
343 if (Call->isArgOperand(&U) && getFreedOperand(Call) == U) {
344 if (Writers)
345 Writers->insert(Call->getParent()->getParent());
346 } else {
347 // In general, we return true for unknown calls, but there are
348 // some simple checks that we can do for functions that
349 // will never call back into the module.
350 auto *F = Call->getCalledFunction();
351 // TODO: we should be able to remove isDeclaration() check
352 // and let the function body analysis check for captures,
353 // and collect the mod-ref effects. This information will
354 // be later propagated via the call graph.
355 if (!F || !F->isDeclaration())
356 return true;
357 // Note that the NoCallback check here is a little bit too
358 // conservative. If there are no captures of the global
359 // in the module, then this call may not be a capture even
360 // if it does not have NoCallback.
361 if (!Call->hasFnAttr(Attribute::NoCallback) ||
362 !Call->isArgOperand(&U) ||
364 return true;
365
366 // Conservatively, assume the call reads and writes the global.
367 // We could use memory attributes to make it more precise.
368 if (Readers)
369 Readers->insert(Call->getParent()->getParent());
370 if (Writers)
371 Writers->insert(Call->getParent()->getParent());
372 }
373 }
374 } else if (ICmpInst *ICI = dyn_cast<ICmpInst>(I)) {
375 if (!isa<ConstantPointerNull>(ICI->getOperand(1)))
376 return true; // Allow comparison against null.
377 } else if (Constant *C = dyn_cast<Constant>(I)) {
378 // Ignore constants which don't have any live uses.
379 if (isa<GlobalValue>(C) || C->isConstantUsed())
380 return true;
381 } else {
382 return true;
383 }
384 }
385
386 return false;
387}
388
389/// AnalyzeIndirectGlobalMemory - We found an non-address-taken global variable
390/// which holds a pointer type. See if the global always points to non-aliased
391/// heap memory: that is, all initializers of the globals store a value known
392/// to be obtained via a noalias return function call which have no other use.
393/// Further, all loads out of GV must directly use the memory, not store the
394/// pointer somewhere. If this is true, we consider the memory pointed to by
395/// GV to be owned by GV and can disambiguate other pointers from it.
396bool GlobalsAAResult::AnalyzeIndirectGlobalMemory(GlobalVariable *GV) {
397 // Keep track of values related to the allocation of the memory, f.e. the
398 // value produced by the noalias call and any casts.
399 std::vector<Value *> AllocRelatedValues;
400
401 // If the initializer is a non-null pointer, bail.
402 if (Constant *C = GV->getInitializer())
404 return false;
405
406 // Walk the user list of the global. If we find anything other than a direct
407 // load or store, bail out.
408 for (User *U : GV->users()) {
409 if (LoadInst *LI = dyn_cast<LoadInst>(U)) {
410 // The pointer loaded from the global can only be used in simple ways:
411 // we allow addressing of it and loading storing to it. We do *not* allow
412 // storing the loaded pointer somewhere else or passing to a function.
413 if (AnalyzeUsesOfPointer(LI))
414 return false; // Loaded pointer escapes.
415 // TODO: Could try some IP mod/ref of the loaded pointer.
416 } else if (StoreInst *SI = dyn_cast<StoreInst>(U)) {
417 // Storing the global itself.
418 if (SI->getOperand(0) == GV)
419 return false;
420
421 // If storing the null pointer, ignore it.
422 if (isa<ConstantPointerNull>(SI->getOperand(0)))
423 continue;
424
425 // Check the value being stored.
426 Value *Ptr = getUnderlyingObject(SI->getOperand(0));
427
428 if (!isNoAliasCall(Ptr))
429 return false; // Too hard to analyze.
430
431 // Analyze all uses of the allocation. If any of them are used in a
432 // non-simple way (e.g. stored to another global) bail out.
433 if (AnalyzeUsesOfPointer(Ptr, /*Readers*/ nullptr, /*Writers*/ nullptr,
434 GV))
435 return false; // Loaded pointer escapes.
436
437 // Remember that this allocation is related to the indirect global.
438 AllocRelatedValues.push_back(Ptr);
439 } else {
440 // Something complex, bail out.
441 return false;
442 }
443 }
444
445 // Okay, this is an indirect global. Remember all of the allocations for
446 // this global in AllocsForIndirectGlobals.
447 while (!AllocRelatedValues.empty()) {
448 AllocsForIndirectGlobals[AllocRelatedValues.back()] = GV;
449 Handles.emplace_front(*this, AllocRelatedValues.back());
450 Handles.front().I = Handles.begin();
451 AllocRelatedValues.pop_back();
452 }
453 IndirectGlobals.insert(GV);
454 Handles.emplace_front(*this, GV);
455 Handles.front().I = Handles.begin();
456 return true;
457}
458
459void GlobalsAAResult::CollectSCCMembership(CallGraph &CG) {
460 // We do a bottom-up SCC traversal of the call graph. In other words, we
461 // visit all callees before callers (leaf-first).
462 unsigned SCCID = 0;
463 for (scc_iterator<CallGraph *> I = scc_begin(&CG); !I.isAtEnd(); ++I) {
464 const std::vector<CallGraphNode *> &SCC = *I;
465 assert(!SCC.empty() && "SCC with no functions?");
466
467 for (auto *CGN : SCC)
468 if (Function *F = CGN->getFunction())
469 FunctionToSCCMap[F] = SCCID;
470 ++SCCID;
471 }
472}
473
474/// AnalyzeCallGraph - At this point, we know the functions where globals are
475/// immediately stored to and read from. Propagate this information up the call
476/// graph to all callers and compute the mod/ref info for all memory for each
477/// function.
478void GlobalsAAResult::AnalyzeCallGraph(CallGraph &CG, Module &M) {
479 // We do a bottom-up SCC traversal of the call graph. In other words, we
480 // visit all callees before callers (leaf-first).
481 for (scc_iterator<CallGraph *> I = scc_begin(&CG); !I.isAtEnd(); ++I) {
482 const std::vector<CallGraphNode *> &SCC = *I;
483 assert(!SCC.empty() && "SCC with no functions?");
484
485 if (any_of(SCC, [](CallGraphNode *Node) { return !Node->getFunction(); })) {
486 // Calls externally - can't say anything useful. Remove any existing
487 // function records (may have been created when scanning globals).
488 for (auto *Node : SCC)
489 FunctionInfos.erase(Node->getFunction());
490 continue;
491 }
492
493 Function *FirstF = SCC[0]->getFunction();
494 FunctionInfo &FI = FunctionInfos[FirstF];
495 Handles.emplace_front(*this, FirstF);
496 Handles.front().I = Handles.begin();
497 bool KnowNothing = false;
498
499 // Only the attributes of declarations, functions without an exact
500 // definition (which may be replaced at link time), and optnone functions
501 // can be relied on, not their bodies.
502 auto UseAttributesOnly = [](const Function &F) {
503 return F.isDeclaration() || !F.isDefinitionExact() || F.hasOptNone();
504 };
505
506 // Intrinsics, like any other synchronizing function, can make effects
507 // of other threads visible. Without nosync we know nothing really.
508 // Similarly, if `nocallback` is missing the function, or intrinsic,
509 // can call into the module arbitrarily. If both are set the function
510 // has an effect but will not interact with accesses of internal
511 // globals inside the module. We are conservative here for definitions
512 // (optnone or non-exact), might not be necessary.
513 auto MaySyncOrCallIntoModule = [](const Function &F) {
514 return !F.isDeclaration() || !F.hasNoSync() ||
515 !F.hasFnAttribute(Attribute::NoCallback);
516 };
517
518 // Collect the mod/ref properties due to called functions. We only compute
519 // one mod-ref set.
520 for (unsigned i = 0, e = SCC.size(); i != e && !KnowNothing; ++i) {
521 Function *F = SCC[i]->getFunction();
522 if (!F) {
523 KnowNothing = true;
524 break;
525 }
526
527 if (UseAttributesOnly(*F)) {
528 // Try to get mod/ref behaviour from function attributes.
529 if (F->doesNotAccessMemory()) {
530 // Can't do better than that!
531 } else if (F->onlyReadsMemory()) {
532 FI.addModRefInfo(ModRefInfo::Ref);
533 if (!F->onlyAccessesArgMemory() && MaySyncOrCallIntoModule(*F))
534 // This function might call back into the module and read a global -
535 // consider every global as possibly being read by this function.
536 FI.setMayReadAnyGlobal();
537 } else {
538 FI.addModRefInfo(ModRefInfo::ModRef);
539 if (!F->onlyAccessesArgMemory())
540 FI.setMayReadAnyGlobal();
541 if (MaySyncOrCallIntoModule(*F)) {
542 KnowNothing = true;
543 break;
544 }
545 }
546 continue;
547 }
548
549 for (CallGraphNode::iterator CI = SCC[i]->begin(), E = SCC[i]->end();
550 CI != E && !KnowNothing; ++CI)
551 if (Function *Callee = CI->second->getFunction()) {
552 if (FunctionInfo *CalleeFI = getFunctionInfo(Callee)) {
553 // Propagate function effect up.
554 FI.addFunctionInfo(*CalleeFI);
555 } else {
556 // Can't say anything about it. However, if it is inside our SCC,
557 // then nothing needs to be done.
558 CallGraphNode *CalleeNode = CG[Callee];
559 if (!is_contained(SCC, CalleeNode))
560 KnowNothing = true;
561 }
562 } else {
563 KnowNothing = true;
564 }
565 }
566
567 // If we can't say anything useful about this SCC, remove all SCC functions
568 // from the FunctionInfos map.
569 if (KnowNothing) {
570 for (auto *Node : SCC)
571 FunctionInfos.erase(Node->getFunction());
572 continue;
573 }
574
575 // Scan the function bodies for explicit loads or stores.
576 for (auto *Node : SCC) {
577 if (isModAndRefSet(FI.getModRefInfo()))
578 break; // The mod/ref lattice saturates here.
579
580 // Don't prove any properties based on the body of a function whose body
581 // can't be relied on. Function attributes were already used as a best
582 // approximation above.
583 if (UseAttributesOnly(*Node->getFunction()))
584 continue;
585
586 for (Instruction &I : instructions(Node->getFunction())) {
587 if (isModAndRefSet(FI.getModRefInfo()))
588 break; // The mod/ref lattice saturates here.
589
590 // We handle calls specially because the graph-relevant aspects are
591 // handled above.
592 if (isa<CallBase>(&I))
593 continue;
594
595 // All non-call instructions we use the primary predicates for whether
596 // they read or write memory.
597 if (I.mayReadFromMemory())
598 FI.addModRefInfo(ModRefInfo::Ref);
599 if (I.mayWriteToMemory())
600 FI.addModRefInfo(ModRefInfo::Mod);
601 }
602 }
603
604 if (!isModSet(FI.getModRefInfo()))
605 ++NumReadMemFunctions;
606 if (!isModOrRefSet(FI.getModRefInfo()))
607 ++NumNoMemFunctions;
608
609 // Finally, now that we know the full effect on this SCC, clone the
610 // information to each function in the SCC.
611 // FI is a reference into FunctionInfos, so copy it now so that it doesn't
612 // get invalidated if DenseMap decides to re-hash.
613 FunctionInfo CachedFI = FI;
614 for (unsigned i = 1, e = SCC.size(); i != e; ++i)
615 FunctionInfos[SCC[i]->getFunction()] = CachedFI;
616 }
617}
618
619// GV is a non-escaping global. V is a pointer address that has been loaded from.
620// If we can prove that V must escape, we can conclude that a load from V cannot
621// alias GV.
623 const Value *V,
624 int &Depth,
625 const DataLayout &DL) {
628 Visited.insert(V);
629 Inputs.push_back(V);
630 do {
631 const Value *Input = Inputs.pop_back_val();
632
635 // Arguments to functions or returns from functions are inherently
636 // escaping, so we can immediately classify those as not aliasing any
637 // non-addr-taken globals.
638 //
639 // (Transitive) loads from a global are also safe - if this aliased
640 // another global, its address would escape, so no alias.
641 continue;
642
643 // Recurse through a limited number of selects, loads and PHIs. This is an
644 // arbitrary depth of 4, lower numbers could be used to fix compile time
645 // issues if needed, but this is generally expected to be only be important
646 // for small depths.
647 if (++Depth > 4)
648 return false;
649
650 if (auto *LI = dyn_cast<LoadInst>(Input)) {
651 Inputs.push_back(getUnderlyingObject(LI->getPointerOperand()));
652 continue;
653 }
654 if (auto *SI = dyn_cast<SelectInst>(Input)) {
655 const Value *LHS = getUnderlyingObject(SI->getTrueValue());
656 const Value *RHS = getUnderlyingObject(SI->getFalseValue());
657 if (Visited.insert(LHS).second)
658 Inputs.push_back(LHS);
659 if (Visited.insert(RHS).second)
660 Inputs.push_back(RHS);
661 continue;
662 }
663 if (auto *PN = dyn_cast<PHINode>(Input)) {
664 for (const Value *Op : PN->incoming_values()) {
666 if (Visited.insert(Op).second)
667 Inputs.push_back(Op);
668 }
669 continue;
670 }
671
672 return false;
673 } while (!Inputs.empty());
674
675 // All inputs were known to be no-alias.
676 return true;
677}
678
679// There are particular cases where we can conclude no-alias between
680// a non-addr-taken global and some other underlying object. Specifically,
681// a non-addr-taken global is known to not be escaped from any function. It is
682// also incorrect for a transformation to introduce an escape of a global in
683// a way that is observable when it was not there previously. One function
684// being transformed to introduce an escape which could possibly be observed
685// (via loading from a global or the return value for example) within another
686// function is never safe. If the observation is made through non-atomic
687// operations on different threads, it is a data-race and UB. If the
688// observation is well defined, by being observed the transformation would have
689// changed program behavior by introducing the observed escape, making it an
690// invalid transform.
691//
692// This property does require that transformations which *temporarily* escape
693// a global that was not previously escaped, prior to restoring it, cannot rely
694// on the results of GMR::alias. This seems a reasonable restriction, although
695// currently there is no way to enforce it. There is also no realistic
696// optimization pass that would make this mistake. The closest example is
697// a transformation pass which does reg2mem of SSA values but stores them into
698// global variables temporarily before restoring the global variable's value.
699// This could be useful to expose "benign" races for example. However, it seems
700// reasonable to require that a pass which introduces escapes of global
701// variables in this way to either not trust AA results while the escape is
702// active, or to be forced to operate as a module pass that cannot co-exist
703// with an alias analysis such as GMR.
704bool GlobalsAAResult::isNonEscapingGlobalNoAlias(const GlobalValue *GV,
705 const Value *V,
706 const Instruction *CtxI) {
707 // In order to know that the underlying object cannot alias the
708 // non-addr-taken global, we must know that it would have to be an escape.
709 // Thus if the underlying object is a function argument, a load from
710 // a global, or the return of a function, it cannot alias. We can also
711 // recurse through PHI nodes and select nodes provided all of their inputs
712 // resolve to one of these known-escaping roots.
713
714 // A non-addr-taken global cannot alias with any non-pointer value.
715 // Check this early and exit.
716 if (!V->getType()->isPointerTy())
717 return true;
718
719 SmallPtrSet<const Value *, 8> Visited;
720 SmallVector<const Value *, 8> Inputs;
721 Visited.insert(V);
722 Inputs.push_back(V);
723 int Depth = 0;
724 do {
725 const Value *Input = Inputs.pop_back_val();
726
727 if (auto *InputGV = dyn_cast<GlobalValue>(Input)) {
728 // If one input is the very global we're querying against, then we can't
729 // conclude no-alias.
730 if (InputGV == GV)
731 return false;
732
733 // Distinct GlobalVariables never alias, unless overriden or zero-sized.
734 // FIXME: The condition can be refined, but be conservative for now.
735 auto *GVar = dyn_cast<GlobalVariable>(GV);
736 auto *InputGVar = dyn_cast<GlobalVariable>(InputGV);
737 if (GVar && InputGVar &&
738 !GVar->isDeclaration() && !InputGVar->isDeclaration() &&
739 !GVar->isInterposable() && !InputGVar->isInterposable()) {
740 Type *GVType = GVar->getInitializer()->getType();
741 Type *InputGVType = InputGVar->getInitializer()->getType();
742 if (GVType->isSized() && InputGVType->isSized() &&
743 (DL.getTypeAllocSize(GVType) > 0) &&
744 (DL.getTypeAllocSize(InputGVType) > 0))
745 continue;
746 }
747
748 // Conservatively return false, even though we could be smarter
749 // (e.g. look through GlobalAliases).
750 return false;
751 }
752
753 if (isa<Argument>(Input) || isa<CallInst>(Input) ||
754 isa<InvokeInst>(Input)) {
755 // Arguments to functions or returns from functions are inherently
756 // escaping, so we can immediately classify those as not aliasing any
757 // non-addr-taken globals.
758 continue;
759 }
760
761 if (CtxI)
762 if (auto *CPN = dyn_cast<ConstantPointerNull>(Input)) {
763 // Null pointer cannot alias with a non-addr-taken global.
764 const Function *F = CtxI->getFunction();
765 if (!NullPointerIsDefined(F, CPN->getPointerType()->getAddressSpace()))
766 continue;
767 }
768
769 // Recurse through a limited number of selects, loads and PHIs. This is an
770 // arbitrary depth of 4, lower numbers could be used to fix compile time
771 // issues if needed, but this is generally expected to be only be important
772 // for small depths.
773 if (++Depth > 4)
774 return false;
775
776 if (auto *LI = dyn_cast<LoadInst>(Input)) {
777 // A pointer loaded from a global would have been captured, and we know
778 // that the global is non-escaping, so no alias.
779 const Value *Ptr = getUnderlyingObject(LI->getPointerOperand());
781 // The load does not alias with GV.
782 continue;
783 // Otherwise, a load could come from anywhere, so bail.
784 return false;
785 }
786 if (auto *SI = dyn_cast<SelectInst>(Input)) {
787 const Value *LHS = getUnderlyingObject(SI->getTrueValue());
788 const Value *RHS = getUnderlyingObject(SI->getFalseValue());
789 if (Visited.insert(LHS).second)
790 Inputs.push_back(LHS);
791 if (Visited.insert(RHS).second)
792 Inputs.push_back(RHS);
793 continue;
794 }
795 if (auto *PN = dyn_cast<PHINode>(Input)) {
796 for (const Value *Op : PN->incoming_values()) {
798 if (Visited.insert(Op).second)
799 Inputs.push_back(Op);
800 }
801 continue;
802 }
803
804 // FIXME: It would be good to handle other obvious no-alias cases here, but
805 // it isn't clear how to do so reasonably without building a small version
806 // of BasicAA into this code.
807 return false;
808 } while (!Inputs.empty());
809
810 // If all the inputs to V were definitively no-alias, then V is no-alias.
811 return true;
812}
813
815 ModuleAnalysisManager::Invalidator &) {
816 // Check whether the analysis has been explicitly invalidated. Otherwise, it's
817 // stateless and remains preserved.
818 auto PAC = PA.getChecker<GlobalsAA>();
819 return !PAC.preservedWhenStateless();
820}
821
822/// alias - If one of the pointers is to a global that we are tracking, and the
823/// other is some random pointer, we know there cannot be an alias, because the
824/// address of the global isn't taken.
826 const MemoryLocation &LocB,
827 AAQueryInfo &AAQI, const Instruction *CtxI) {
828 // Get the base object these pointers point to.
829 const Value *UV1 =
831 const Value *UV2 =
833
834 // If either of the underlying values is a global, they may be non-addr-taken
835 // globals, which we can answer queries about.
836 const GlobalValue *GV1 = dyn_cast<GlobalValue>(UV1);
837 const GlobalValue *GV2 = dyn_cast<GlobalValue>(UV2);
838 if (GV1 || GV2) {
839 // If the global's address is taken, pretend we don't know it's a pointer to
840 // the global.
841 if (GV1 && !NonAddressTakenGlobals.count(GV1))
842 GV1 = nullptr;
843 if (GV2 && !NonAddressTakenGlobals.count(GV2))
844 GV2 = nullptr;
845
846 // If the two pointers are derived from two different non-addr-taken
847 // globals we know these can't alias.
848 if (GV1 && GV2 && GV1 != GV2)
850
851 // If one is and the other isn't, it isn't strictly safe but we can fake
852 // this result if necessary for performance. This does not appear to be
853 // a common problem in practice.
854 if ((GV1 || GV2) && GV1 != GV2 &&
855 Opts.enable_unsafe_globalsmodref_alias_results)
857
858 // Check for a special case where a non-escaping global can be used to
859 // conclude no-alias.
860 if ((GV1 || GV2) && GV1 != GV2) {
861 const GlobalValue *GV = GV1 ? GV1 : GV2;
862 const Value *UV = GV1 ? UV2 : UV1;
863 if (isNonEscapingGlobalNoAlias(GV, UV, CtxI))
865 }
866
867 // Otherwise if they are both derived from the same addr-taken global, we
868 // can't know the two accesses don't overlap.
869 }
870
871 // These pointers may be based on the memory owned by an indirect global. If
872 // so, we may be able to handle this. First check to see if the base pointer
873 // is a direct load from an indirect global.
874 GV1 = GV2 = nullptr;
875 if (const LoadInst *LI = dyn_cast<LoadInst>(UV1))
876 if (GlobalVariable *GV = dyn_cast<GlobalVariable>(LI->getOperand(0)))
877 if (IndirectGlobals.count(GV))
878 GV1 = GV;
879 if (const LoadInst *LI = dyn_cast<LoadInst>(UV2))
880 if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(LI->getOperand(0)))
881 if (IndirectGlobals.count(GV))
882 GV2 = GV;
883
884 // These pointers may also be from an allocation for the indirect global. If
885 // so, also handle them.
886 if (!GV1)
887 GV1 = AllocsForIndirectGlobals.lookup(UV1);
888 if (!GV2)
889 GV2 = AllocsForIndirectGlobals.lookup(UV2);
890
891 // Now that we know whether the two pointers are related to indirect globals,
892 // use this to disambiguate the pointers. If the pointers are based on
893 // different indirect globals they cannot alias.
894 if (GV1 && GV2 && GV1 != GV2)
896
897 // If one is based on an indirect global and the other isn't, it isn't
898 // strictly safe but we can fake this result if necessary for performance.
899 // This does not appear to be a common problem in practice.
900 if ((GV1 || GV2) && GV1 != GV2 &&
901 Opts.enable_unsafe_globalsmodref_alias_results)
903
905}
906
907ModRefInfo GlobalsAAResult::getModRefInfoForArgument(const CallBase *Call,
908 const GlobalValue *GV,
909 AAQueryInfo &AAQI) {
910 if (Call->doesNotAccessMemory())
912 ModRefInfo ConservativeResult =
913 Call->onlyReadsMemory() ? ModRefInfo::Ref : ModRefInfo::ModRef;
914
915 // Iterate through all the arguments to the called function. If any argument
916 // is based on GV, return the conservative result.
917 for (const auto &A : Call->args()) {
919 getUnderlyingObjects(A, Objects);
920
921 // All objects must be identified.
922 if (!all_of(Objects, isIdentifiedObject) &&
923 // Try ::alias to see if all objects are known not to alias GV.
924 !all_of(Objects, [&](const Value *V) {
928 }))
929 return ConservativeResult;
930
931 if (is_contained(Objects, GV))
932 return ConservativeResult;
933 }
934
935 // We identified all objects in the argument list, and none of them were GV.
937}
938
940 const MemoryLocation &Loc,
941 AAQueryInfo &AAQI) {
943
944 // If we are asking for mod/ref info of a direct call with a pointer to a
945 // global we are tracking, return information if we have it.
946 if (const GlobalValue *GV =
948 // If GV is internal to this IR and there is no function with local linkage
949 // that has had their address taken, keep looking for a tighter ModRefInfo.
950 if (GV->hasLocalLinkage() && !UnknownFunctionsWithLocalLinkage)
951 if (const Function *F = Call->getCalledFunction())
952 if (NonAddressTakenGlobals.count(GV))
953 if (const FunctionInfo *FI = getFunctionInfo(F))
954 Known = FI->getModRefInfoForGlobal(*GV) |
955 getModRefInfoForArgument(Call, GV, AAQI);
956
957 return Known;
958}
959
960GlobalsAAResult::GlobalsAAResult(const AnalysisOptions &Opts,
961 const DataLayout &DL)
962 : Opts(Opts), DL(DL) {}
963
964GlobalsAAResult::GlobalsAAResult(GlobalsAAResult &&Arg)
965 : AAResultBase(std::move(Arg)), Opts(Arg.Opts), DL(Arg.DL),
966 NonAddressTakenGlobals(std::move(Arg.NonAddressTakenGlobals)),
967 IndirectGlobals(std::move(Arg.IndirectGlobals)),
968 AllocsForIndirectGlobals(std::move(Arg.AllocsForIndirectGlobals)),
969 FunctionInfos(std::move(Arg.FunctionInfos)),
970 Handles(std::move(Arg.Handles)) {
971 // Update the parent for each DeletionCallbackHandle.
972 for (auto &H : Handles) {
973 assert(H.GAR == &Arg);
974 H.GAR = this;
975 }
976}
977
979
980/*static*/ GlobalsAAResult GlobalsAAResult::analyzeModule(Module &M,
981 CallGraph &CG) {
982 GlobalsAAResult Result(getAnalysisOptions(M), M.getDataLayout());
983
984 // Discover which functions aren't recursive, to feed into AnalyzeGlobals.
985 Result.CollectSCCMembership(CG);
986
987 // Find non-addr taken globals.
988 Result.AnalyzeGlobals(M);
989
990 // Propagate on CG.
991 Result.AnalyzeCallGraph(CG, M);
992
993 return Result;
994}
995
996AnalysisKey GlobalsAA::Key;
997
1001
1004 if (auto *G = AM.getCachedResult<GlobalsAA>(M)) {
1005 auto &CG = AM.getResult<CallGraphAnalysis>(M);
1006 G->NonAddressTakenGlobals.clear();
1007 G->UnknownFunctionsWithLocalLinkage = false;
1008 G->IndirectGlobals.clear();
1009 G->AllocsForIndirectGlobals.clear();
1010 G->FunctionInfos.clear();
1011 G->FunctionToSCCMap.clear();
1012 G->Handles.clear();
1013 G->CollectSCCMembership(CG);
1014 G->AnalyzeGlobals(M);
1015 G->AnalyzeCallGraph(CG, M);
1016 }
1017 return PreservedAnalyses::all();
1018}
1019
1022 "Globals Alias Analysis", false, true)
1025 "Globals Alias Analysis", false, true)
1026
1030
1032
1035 M, getAnalysis<CallGraphWrapperPass>().getCallGraph())));
1036 return false;
1037}
1038
1040 Result.reset();
1041 return false;
1042}
1043
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Expand Atomic instructions
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file provides interfaces used to build and manipulate a call graph, which is a very useful tool ...
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static bool isNonEscapingGlobalNoAliasWithLoad(const GlobalValue *GV, const Value *V, int &Depth, const DataLayout &DL)
This is the interface for a simple mod/ref and alias analysis over globals.
Value * getPointer(Value *Ptr)
Module.h This file contains the declarations for the Module class.
This header defines various interfaces for pass management in LLVM.
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
#define G(x, y, z)
Definition MD5.cpp:55
#define H(x, y, z)
Definition MD5.cpp:56
uint64_t IntrinsicInst * II
#define P(N)
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition PassSupport.h:42
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition PassSupport.h:44
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
Definition PassSupport.h:39
This builds on the llvm/ADT/GraphTraits.h file to find the strongly connected components (SCCs) of a ...
This file defines the SmallPtrSet class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
Definition Statistic.h:170
Value * RHS
Value * LHS
The mod/ref information collected for a particular function.
FunctionInfo & operator=(FunctionInfo &&RHS)
void eraseModRefInfoForGlobal(const GlobalValue &GV)
Clear a global's ModRef info.
void setMayReadAnyGlobal()
Sets this function as potentially reading from any global.
void addModRefInfo(ModRefInfo NewMRI)
Adds new ModRefInfo for this function to its state.
void addFunctionInfo(const FunctionInfo &FI)
Add mod/ref info from another function into ours, saturating towards ModRef.
ModRefInfo getModRefInfo() const
Returns the ModRefInfo info for this function.
FunctionInfo()=default
Checks to document the invariants of the bit packing here.
FunctionInfo & operator=(const FunctionInfo &RHS)
void addModRefInfoForGlobal(const GlobalValue &GV, ModRefInfo NewMRI)
ModRefInfo globalClearMayReadAnyGlobal(int I) const
This method clears MayReadAnyGlobal bit added by GlobalsAAResult to return the corresponding ModRefIn...
bool mayReadAnyGlobal() const
Returns whether this function may read any global variable, and we don't know which global.
FunctionInfo(const FunctionInfo &Arg)
ModRefInfo getModRefInfoForGlobal(const GlobalValue &GV) const
Returns the ModRefInfo info for this function w.r.t.
The Input class is used to parse a yaml document into in-memory structs and vectors.
This class stores info we want to provide to or retain within an alias query.
AAResultBase()=default
The possible results of an alias query.
@ MayAlias
The two locations may or may not alias.
@ NoAlias
The two locations do not alias at all.
PassT::Result * getCachedResult(IRUnitT &IR) const
Get the cached result of an analysis pass for a given IR unit.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
void setPreservesAll()
Set by analyses that do not transform their input at all.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
bool doesNotCapture(unsigned OpNo) const
Determine whether this data operand is not captured.
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation or the function signa...
bool hasFnAttr(Attribute::AttrKind Kind) const
Determine whether this call has the given attribute.
unsigned getArgOperandNo(const Use *U) const
Given a use for a arg operand, get the arg operand number that corresponds to it.
bool isArgOperand(const Use *U) const
bool isDataOperand(const Use *U) const
An analysis pass to compute the CallGraph for a Module.
Definition CallGraph.h:270
std::vector< CallRecord >::iterator iterator
Definition CallGraph.h:189
The ModulePass which wraps up a CallGraph and the logic to build it.
Definition CallGraph.h:314
The basic data container for the call graph of a Module of IR.
Definition CallGraph.h:72
void setValPtr(Value *P)
A parsed version of the target data layout string in and methods for querying it.
Definition DataLayout.h:63
bool hasLocalLinkage() const
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
An alias analysis result set for globals.
static LLVM_ABI GlobalsAAResult analyzeModule(Module &M, CallGraph &CG)
LLVM_ABI ~GlobalsAAResult()
LLVM_ABI ModRefInfo getModRefInfo(const CallBase *Call, const MemoryLocation &Loc, AAQueryInfo &AAQI)
LLVM_ABI bool invalidate(Module &M, const PreservedAnalyses &PA, ModuleAnalysisManager::Invalidator &)
LLVM_ABI MemoryEffects getMemoryEffects(const Function *F)
getMemoryEffects - Return the behavior of the specified function if called from the specified call si...
LLVM_ABI AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB, AAQueryInfo &AAQI, const Instruction *CtxI)
alias - If one of the pointers is to a global that we are tracking, and the other is some random poin...
Legacy wrapper pass to provide the GlobalsAAResult object.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
bool runOnModule(Module &M) override
runOnModule - Virtual method overriden by subclasses to process the module being operated on.
bool doFinalization(Module &M) override
doFinalization - Virtual method overriden by subclasses to do any necessary clean up after all passes...
Analysis pass providing a never-invalidated alias analysis result.
LLVM_ABI GlobalsAAResult run(Module &M, ModuleAnalysisManager &AM)
LLVM_ABI const Function * getFunction() const
Return the function this instruction belongs to.
An instruction for reading from memory.
static MemoryEffectsBase unknown()
Definition ModRef.h:123
Representation for a specific memory location.
static MemoryLocation getBeforeOrAfter(const Value *Ptr, const AAMDNodes &AATags=AAMDNodes())
Return a location that may access any location before or after Ptr, while remaining within the underl...
const Value * Ptr
The address of the start of the location.
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
Definition Pass.h:253
ModulePass(char &pid)
Definition Pass.h:255
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:68
unsigned getOpcode() const
Return the opcode for this Instruction or ConstantExpr.
Definition Operator.h:43
AnalysisType & getAnalysis() const
getAnalysis<AnalysisType>() - This function is used by subclasses to get to the analysis information ...
PointerIntPair - This class implements a pair of a pointer and small integer.
void setPointerAndInt(PointerTy PtrVal, IntType IntVal) &
PointerTy getPointer() const
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
PreservedAnalysisChecker getChecker() const
Build a checker for this PreservedAnalyses and the specified analysis type.
Definition Analysis.h:275
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.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
bool isSized() const
Return true if it makes sense to take the size of this type.
Definition Type.h:321
Value * getValPtr() const
LLVM Value Representation.
Definition Value.h:75
iterator_range< user_iterator > users()
Definition Value.h:428
LLVM_ABI const Value * stripPointerCastsForAliasAnalysis() const
Strip off pointer casts, all-zero GEPs, single-argument phi nodes and invariant group info.
Definition Value.cpp:723
const ParentTy * getParent() const
Definition ilist_node.h:34
CallInst * Call
@ User
could "use" a pointer
NodeAddr< NodeBase * > Node
Definition RDFGraph.h:381
iterator end() const
Definition BasicBlock.h:89
LLVM_ABI iterator begin() const
This is an optimization pass for GlobalISel generic memory operations.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1755
@ Known
Known to have no common set bits.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
scc_iterator< T > scc_begin(const T &G)
Construct the begin iterator for a deduced graph type T.
LLVM_ABI bool isNoAliasCall(const Value *V)
Return true if this pointer is returned by a noalias function.
MemoryEffectsBase< IRMemLocation > MemoryEffects
Summary of how a function affects memory in the program.
Definition ModRef.h:356
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
Definition InstrProf.h:143
const AnalysisOptions & getAnalysisOptions(const LLVMContext &C)
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1762
LLVM_ABI ModulePass * createGlobalsAAWrapperPass()
bool isModSet(const ModRefInfo MRI)
Definition ModRef.h:49
LLVM_ABI bool NullPointerIsDefined(const Function *F, unsigned AS=0)
Check whether null pointer dereferencing is considered undefined behavior for a given function or an ...
bool isModOrRefSet(const ModRefInfo MRI)
Definition ModRef.h:43
LLVM_ABI const Value * getUnderlyingObject(const Value *V, unsigned MaxLookup=MaxLookupSearchDepth, bool MustPreserveProvenance=false)
This method strips off any GEP address adjustments, pointer casts or llvm.threadlocal....
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...
Definition Casting.h:547
ModRefInfo
Flags indicating whether a memory access modifies or references memory.
Definition ModRef.h:28
@ Ref
The access may reference the value stored in memory.
Definition ModRef.h:32
@ ModRef
The access may reference and may modify the value stored in memory.
Definition ModRef.h:36
@ Mod
The access may modify the value stored in memory.
Definition ModRef.h:34
@ NoModRef
The access neither references nor modifies the value stored in memory.
Definition ModRef.h:30
DWARFExpression::Operation Op
bool isModAndRefSet(const ModRefInfo MRI)
Definition ModRef.h:46
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1933
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition STLExtras.h:1963
LLVM_ABI Value * getFreedOperand(const CallBase *CB)
If this if a call to a free function, return the freed operand.
LLVM_ABI void getUnderlyingObjects(const Value *V, SmallVectorImpl< const Value * > &Objects, const LoopInfo *LI=nullptr, unsigned MaxLookup=MaxLookupSearchDepth)
This method is similar to getUnderlyingObject except that it can look through phi and select instruct...
LLVM_ABI bool isIdentifiedObject(const Value *V)
Return true if this pointer refers to a distinct and identifiable object.
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
Definition MIRParser.h:39
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:879
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition Analysis.h:29
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)