LLVM 23.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
19#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"
32
33using namespace llvm;
34
35#define DEBUG_TYPE "globalsmodref-aa"
36
37STATISTIC(NumNonAddrTakenGlobalVars,
38 "Number of global vars without address taken");
39STATISTIC(NumNonAddrTakenFunctions,"Number of functions without address taken");
40STATISTIC(NumNoMemFunctions, "Number of functions that do not access memory");
41STATISTIC(NumReadMemFunctions, "Number of functions that only read memory");
42STATISTIC(NumIndirectGlobalVars, "Number of indirect global objects");
43
44// An option to enable unsafe alias results from the GlobalsModRef analysis.
45// When enabled, GlobalsModRef will provide no-alias results which in extremely
46// rare cases may not be conservatively correct. In particular, in the face of
47// transforms which cause asymmetry between how effective getUnderlyingObject
48// is for two pointers, it may produce incorrect results.
49//
50// These unsafe results have been returned by GMR for many years without
51// causing significant issues in the wild and so we provide a mechanism to
52// re-enable them for users of LLVM that have a particular performance
53// sensitivity and no known issues. The option also makes it easy to evaluate
54// the performance impact of these results.
56 "enable-unsafe-globalsmodref-alias-results", cl::init(false), cl::Hidden);
57
58/// The mod/ref information collected for a particular function.
59///
60/// We collect information about mod/ref behavior of a function here, both in
61/// general and as pertains to specific globals. We only have this detailed
62/// information when we know *something* useful about the behavior. If we
63/// saturate to fully general mod/ref, we remove the info for the function.
66
67 /// Build a wrapper struct that has 8-byte alignment. All heap allocations
68 /// should provide this much alignment at least, but this makes it clear we
69 /// specifically rely on this amount of alignment.
70 struct alignas(8) AlignedMap {
71 AlignedMap() = default;
72 AlignedMap(const AlignedMap &Arg) = default;
73 GlobalInfoMapType Map;
74 };
75
76 /// Pointer traits for our aligned map.
77 struct AlignedMapPointerTraits {
78 static inline void *getAsVoidPointer(AlignedMap *P) { return P; }
79 static inline AlignedMap *getFromVoidPointer(void *P) {
80 return (AlignedMap *)P;
81 }
82 static constexpr int NumLowBitsAvailable = 3;
83 static_assert(alignof(AlignedMap) >= (1 << NumLowBitsAvailable),
84 "AlignedMap insufficiently aligned to have enough low bits.");
85 };
86
87 /// The bit that flags that this function may read any global. This is
88 /// chosen to mix together with ModRefInfo bits.
89 /// FIXME: This assumes ModRefInfo lattice will remain 4 bits!
90 /// FunctionInfo.getModRefInfo() masks out everything except ModRef so
91 /// this remains correct.
92 enum { MayReadAnyGlobal = 4 };
93
94 /// Checks to document the invariants of the bit packing here.
95 static_assert((MayReadAnyGlobal & static_cast<int>(ModRefInfo::ModRef)) == 0,
96 "ModRef and the MayReadAnyGlobal flag bits overlap.");
97 static_assert(((MayReadAnyGlobal | static_cast<int>(ModRefInfo::ModRef)) >>
98 AlignedMapPointerTraits::NumLowBitsAvailable) == 0,
99 "Insufficient low bits to store our flag and ModRef info.");
100
101public:
102 FunctionInfo() = default;
104 delete Info.getPointer();
105 }
106 // Spell out the copy ond move constructors and assignment operators to get
107 // deep copy semantics and correct move semantics in the face of the
108 // pointer-int pair.
110 : Info(nullptr, Arg.Info.getInt()) {
111 if (const auto *ArgPtr = Arg.Info.getPointer())
112 Info.setPointer(new AlignedMap(*ArgPtr));
113 }
115 : Info(Arg.Info.getPointer(), Arg.Info.getInt()) {
116 Arg.Info.setPointerAndInt(nullptr, 0);
117 }
119 delete Info.getPointer();
120 Info.setPointerAndInt(nullptr, RHS.Info.getInt());
121 if (const auto *RHSPtr = RHS.Info.getPointer())
122 Info.setPointer(new AlignedMap(*RHSPtr));
123 return *this;
124 }
126 delete Info.getPointer();
127 Info.setPointerAndInt(RHS.Info.getPointer(), RHS.Info.getInt());
128 RHS.Info.setPointerAndInt(nullptr, 0);
129 return *this;
130 }
131
132 /// This method clears MayReadAnyGlobal bit added by GlobalsAAResult to return
133 /// the corresponding ModRefInfo.
135 return ModRefInfo(I & static_cast<int>(ModRefInfo::ModRef));
136 }
137
138 /// Returns the \c ModRefInfo info for this function.
140 return globalClearMayReadAnyGlobal(Info.getInt());
141 }
142
143 /// Adds new \c ModRefInfo for this function to its state.
145 Info.setInt(Info.getInt() | static_cast<int>(NewMRI));
146 }
147
148 /// Returns whether this function may read any global variable, and we don't
149 /// know which global.
150 bool mayReadAnyGlobal() const { return Info.getInt() & MayReadAnyGlobal; }
151
152 /// Sets this function as potentially reading from any global.
153 void setMayReadAnyGlobal() { Info.setInt(Info.getInt() | MayReadAnyGlobal); }
154
155 /// Returns the \c ModRefInfo info for this function w.r.t. a particular
156 /// global, which may be more precise than the general information above.
158 ModRefInfo GlobalMRI =
160 if (AlignedMap *P = Info.getPointer()) {
161 auto I = P->Map.find(&GV);
162 if (I != P->Map.end())
163 GlobalMRI |= I->second;
164 }
165 return GlobalMRI;
166 }
167
168 /// Add mod/ref info from another function into ours, saturating towards
169 /// ModRef.
172
173 if (FI.mayReadAnyGlobal())
175
176 if (AlignedMap *P = FI.Info.getPointer())
177 for (const auto &G : P->Map)
178 addModRefInfoForGlobal(*G.first, G.second);
179 }
180
182 AlignedMap *P = Info.getPointer();
183 if (!P) {
184 P = new AlignedMap();
185 Info.setPointer(P);
186 }
187 auto &GlobalMRI = P->Map[&GV];
188 GlobalMRI |= NewMRI;
189 }
190
191 /// Clear a global's ModRef info. Should be used when a global is being
192 /// deleted.
194 if (AlignedMap *P = Info.getPointer())
195 P->Map.erase(&GV);
196 }
197
198private:
199 /// All of the information is encoded into a single pointer, with a three bit
200 /// integer in the low three bits. The high bit provides a flag for when this
201 /// function may read any global. The low two bits are the ModRefInfo. And
202 /// the pointer, when non-null, points to a map from GlobalValue to
203 /// ModRefInfo specific to that GlobalValue.
205};
206
207void GlobalsAAResult::DeletionCallbackHandle::deleted() {
208 Value *V = getValPtr();
209 if (auto *F = dyn_cast<Function>(V))
210 GAR->FunctionInfos.erase(F);
211
212 if (GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
213 if (GAR->NonAddressTakenGlobals.erase(GV)) {
214 // This global might be an indirect global. If so, remove it and
215 // remove any AllocRelatedValues for it.
216 if (GAR->IndirectGlobals.erase(GV)) {
217 // Remove any entries in AllocsForIndirectGlobals for this global.
218 for (auto I = GAR->AllocsForIndirectGlobals.begin(),
219 E = GAR->AllocsForIndirectGlobals.end();
220 I != E; ++I)
221 if (I->second == GV)
222 GAR->AllocsForIndirectGlobals.erase(I);
223 }
224
225 // Scan the function info we have collected and remove this global
226 // from all of them.
227 for (auto &FIPair : GAR->FunctionInfos)
228 FIPair.second.eraseModRefInfoForGlobal(*GV);
229 }
230 }
231
232 // If this is an allocation related to an indirect global, remove it.
233 GAR->AllocsForIndirectGlobals.erase(V);
234
235 // And clear out the handle.
236 setValPtr(nullptr);
237 GAR->Handles.erase(I);
238 // This object is now destroyed!
239}
240
242 if (FunctionInfo *FI = getFunctionInfo(F))
243 return MemoryEffects(FI->getModRefInfo());
244
245 return MemoryEffects::unknown();
246}
247
248/// Returns the function info for the function, or null if we don't have
249/// anything useful to say about it.
251GlobalsAAResult::getFunctionInfo(const Function *F) {
252 auto I = FunctionInfos.find(F);
253 if (I != FunctionInfos.end())
254 return &I->second;
255 return nullptr;
256}
257
258/// AnalyzeGlobals - Scan through the users of all of the internal
259/// GlobalValue's in the program. If none of them have their "address taken"
260/// (really, their address passed to something nontrivial), record this fact,
261/// and record the functions that they are used directly in.
262void GlobalsAAResult::AnalyzeGlobals(Module &M) {
263 SmallPtrSet<Function *, 32> TrackedFunctions;
264 for (Function &F : M)
265 if (F.hasLocalLinkage()) {
266 if (!AnalyzeUsesOfPointer(&F)) {
267 // Remember that we are tracking this global.
268 NonAddressTakenGlobals.insert(&F);
269 TrackedFunctions.insert(&F);
270 Handles.emplace_front(*this, &F);
271 Handles.front().I = Handles.begin();
272 ++NumNonAddrTakenFunctions;
273 } else
274 UnknownFunctionsWithLocalLinkage = true;
275 }
276
277 SmallPtrSet<Function *, 16> Readers, Writers;
278 for (GlobalVariable &GV : M.globals())
279 if (GV.hasLocalLinkage()) {
280 if (!AnalyzeUsesOfPointer(&GV, &Readers,
281 GV.isConstant() ? nullptr : &Writers)) {
282 // Remember that we are tracking this global, and the mod/ref fns
283 NonAddressTakenGlobals.insert(&GV);
284 Handles.emplace_front(*this, &GV);
285 Handles.front().I = Handles.begin();
286
287 for (Function *Reader : Readers) {
288 if (TrackedFunctions.insert(Reader).second) {
289 Handles.emplace_front(*this, Reader);
290 Handles.front().I = Handles.begin();
291 }
292 FunctionInfos[Reader].addModRefInfoForGlobal(GV, ModRefInfo::Ref);
293 }
294
295 if (!GV.isConstant()) // No need to keep track of writers to constants
296 for (Function *Writer : Writers) {
297 if (TrackedFunctions.insert(Writer).second) {
298 Handles.emplace_front(*this, Writer);
299 Handles.front().I = Handles.begin();
300 }
301 FunctionInfos[Writer].addModRefInfoForGlobal(GV, ModRefInfo::Mod);
302 }
303 ++NumNonAddrTakenGlobalVars;
304
305 // If this global holds a pointer type, see if it is an indirect global.
306 if (GV.getValueType()->isPointerTy() &&
307 AnalyzeIndirectGlobalMemory(&GV))
308 ++NumIndirectGlobalVars;
309 }
310 Readers.clear();
311 Writers.clear();
312 }
313}
314
315/// AnalyzeUsesOfPointer - Look at all of the users of the specified pointer.
316/// If this is used by anything complex (i.e., the address escapes), return
317/// true. Also, while we are at it, keep track of those functions that read and
318/// write to the value.
319///
320/// If OkayStoreDest is non-null, stores into this global are allowed.
321bool GlobalsAAResult::AnalyzeUsesOfPointer(Value *V,
322 SmallPtrSetImpl<Function *> *Readers,
323 SmallPtrSetImpl<Function *> *Writers,
324 GlobalValue *OkayStoreDest) {
325 if (!V->getType()->isPointerTy())
326 return true;
327
328 for (Use &U : V->uses()) {
329 User *I = U.getUser();
330 if (LoadInst *LI = dyn_cast<LoadInst>(I)) {
331 if (Readers)
332 Readers->insert(LI->getParent()->getParent());
333 } else if (StoreInst *SI = dyn_cast<StoreInst>(I)) {
334 if (V == SI->getOperand(1)) {
335 if (Writers)
336 Writers->insert(SI->getParent()->getParent());
337 } else if (SI->getOperand(1) != OkayStoreDest) {
338 return true; // Storing the pointer
339 }
340 } else if (Operator::getOpcode(I) == Instruction::GetElementPtr) {
341 if (AnalyzeUsesOfPointer(I, Readers, Writers))
342 return true;
343 } else if (Operator::getOpcode(I) == Instruction::BitCast ||
344 Operator::getOpcode(I) == Instruction::AddrSpaceCast) {
345 if (AnalyzeUsesOfPointer(I, Readers, Writers, OkayStoreDest))
346 return true;
347 } else if (auto *Call = dyn_cast<CallBase>(I)) {
348 if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(I)) {
349 if (II->getIntrinsicID() == Intrinsic::threadlocal_address &&
350 V == II->getArgOperand(0)) {
351 if (AnalyzeUsesOfPointer(II, Readers, Writers))
352 return true;
353 continue;
354 }
355 }
356 // Make sure that this is just the function being called, not that it is
357 // passing into the function.
358 if (Call->isDataOperand(&U)) {
359 // Detect calls to free.
360 if (Call->isArgOperand(&U) &&
361 getFreedOperand(Call, &GetTLI(*Call->getFunction())) == U) {
362 if (Writers)
363 Writers->insert(Call->getParent()->getParent());
364 } else {
365 // In general, we return true for unknown calls, but there are
366 // some simple checks that we can do for functions that
367 // will never call back into the module.
368 auto *F = Call->getCalledFunction();
369 // TODO: we should be able to remove isDeclaration() check
370 // and let the function body analysis check for captures,
371 // and collect the mod-ref effects. This information will
372 // be later propagated via the call graph.
373 if (!F || !F->isDeclaration())
374 return true;
375 // Note that the NoCallback check here is a little bit too
376 // conservative. If there are no captures of the global
377 // in the module, then this call may not be a capture even
378 // if it does not have NoCallback.
379 if (!Call->hasFnAttr(Attribute::NoCallback) ||
380 !Call->isArgOperand(&U) ||
382 return true;
383
384 // Conservatively, assume the call reads and writes the global.
385 // We could use memory attributes to make it more precise.
386 if (Readers)
387 Readers->insert(Call->getParent()->getParent());
388 if (Writers)
389 Writers->insert(Call->getParent()->getParent());
390 }
391 }
392 } else if (ICmpInst *ICI = dyn_cast<ICmpInst>(I)) {
393 if (!isa<ConstantPointerNull>(ICI->getOperand(1)))
394 return true; // Allow comparison against null.
395 } else if (Constant *C = dyn_cast<Constant>(I)) {
396 // Ignore constants which don't have any live uses.
397 if (isa<GlobalValue>(C) || C->isConstantUsed())
398 return true;
399 } else {
400 return true;
401 }
402 }
403
404 return false;
405}
406
407/// AnalyzeIndirectGlobalMemory - We found an non-address-taken global variable
408/// which holds a pointer type. See if the global always points to non-aliased
409/// heap memory: that is, all initializers of the globals store a value known
410/// to be obtained via a noalias return function call which have no other use.
411/// Further, all loads out of GV must directly use the memory, not store the
412/// pointer somewhere. If this is true, we consider the memory pointed to by
413/// GV to be owned by GV and can disambiguate other pointers from it.
414bool GlobalsAAResult::AnalyzeIndirectGlobalMemory(GlobalVariable *GV) {
415 // Keep track of values related to the allocation of the memory, f.e. the
416 // value produced by the noalias call and any casts.
417 std::vector<Value *> AllocRelatedValues;
418
419 // If the initializer is a non-null pointer, bail.
420 if (Constant *C = GV->getInitializer())
422 return false;
423
424 // Walk the user list of the global. If we find anything other than a direct
425 // load or store, bail out.
426 for (User *U : GV->users()) {
427 if (LoadInst *LI = dyn_cast<LoadInst>(U)) {
428 // The pointer loaded from the global can only be used in simple ways:
429 // we allow addressing of it and loading storing to it. We do *not* allow
430 // storing the loaded pointer somewhere else or passing to a function.
431 if (AnalyzeUsesOfPointer(LI))
432 return false; // Loaded pointer escapes.
433 // TODO: Could try some IP mod/ref of the loaded pointer.
434 } else if (StoreInst *SI = dyn_cast<StoreInst>(U)) {
435 // Storing the global itself.
436 if (SI->getOperand(0) == GV)
437 return false;
438
439 // If storing the null pointer, ignore it.
440 if (isa<ConstantPointerNull>(SI->getOperand(0)))
441 continue;
442
443 // Check the value being stored.
444 Value *Ptr = getUnderlyingObject(SI->getOperand(0));
445
446 if (!isNoAliasCall(Ptr))
447 return false; // Too hard to analyze.
448
449 // Analyze all uses of the allocation. If any of them are used in a
450 // non-simple way (e.g. stored to another global) bail out.
451 if (AnalyzeUsesOfPointer(Ptr, /*Readers*/ nullptr, /*Writers*/ nullptr,
452 GV))
453 return false; // Loaded pointer escapes.
454
455 // Remember that this allocation is related to the indirect global.
456 AllocRelatedValues.push_back(Ptr);
457 } else {
458 // Something complex, bail out.
459 return false;
460 }
461 }
462
463 // Okay, this is an indirect global. Remember all of the allocations for
464 // this global in AllocsForIndirectGlobals.
465 while (!AllocRelatedValues.empty()) {
466 AllocsForIndirectGlobals[AllocRelatedValues.back()] = GV;
467 Handles.emplace_front(*this, AllocRelatedValues.back());
468 Handles.front().I = Handles.begin();
469 AllocRelatedValues.pop_back();
470 }
471 IndirectGlobals.insert(GV);
472 Handles.emplace_front(*this, GV);
473 Handles.front().I = Handles.begin();
474 return true;
475}
476
477void GlobalsAAResult::CollectSCCMembership(CallGraph &CG) {
478 // We do a bottom-up SCC traversal of the call graph. In other words, we
479 // visit all callees before callers (leaf-first).
480 unsigned SCCID = 0;
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 for (auto *CGN : SCC)
486 if (Function *F = CGN->getFunction())
487 FunctionToSCCMap[F] = SCCID;
488 ++SCCID;
489 }
490}
491
492/// AnalyzeCallGraph - At this point, we know the functions where globals are
493/// immediately stored to and read from. Propagate this information up the call
494/// graph to all callers and compute the mod/ref info for all memory for each
495/// function.
496void GlobalsAAResult::AnalyzeCallGraph(CallGraph &CG, Module &M) {
497 // We do a bottom-up SCC traversal of the call graph. In other words, we
498 // visit all callees before callers (leaf-first).
499 for (scc_iterator<CallGraph *> I = scc_begin(&CG); !I.isAtEnd(); ++I) {
500 const std::vector<CallGraphNode *> &SCC = *I;
501 assert(!SCC.empty() && "SCC with no functions?");
502
503 Function *F = SCC[0]->getFunction();
504
505 if (!F || !F->isDefinitionExact()) {
506 // Calls externally or not exact - can't say anything useful. Remove any
507 // existing function records (may have been created when scanning
508 // globals).
509 for (auto *Node : SCC)
510 FunctionInfos.erase(Node->getFunction());
511 continue;
512 }
513
514 FunctionInfo &FI = FunctionInfos[F];
515 Handles.emplace_front(*this, F);
516 Handles.front().I = Handles.begin();
517 bool KnowNothing = false;
518
519 // Intrinsics, like any other synchronizing function, can make effects
520 // of other threads visible. Without nosync we know nothing really.
521 // Similarly, if `nocallback` is missing the function, or intrinsic,
522 // can call into the module arbitrarily. If both are set the function
523 // has an effect but will not interact with accesses of internal
524 // globals inside the module. We are conservative here for optnone
525 // functions, might not be necessary.
526 auto MaySyncOrCallIntoModule = [](const Function &F) {
527 return !F.isDeclaration() || !F.hasNoSync() ||
528 !F.hasFnAttribute(Attribute::NoCallback);
529 };
530
531 // Collect the mod/ref properties due to called functions. We only compute
532 // one mod-ref set.
533 for (unsigned i = 0, e = SCC.size(); i != e && !KnowNothing; ++i) {
534 if (!F) {
535 KnowNothing = true;
536 break;
537 }
538
539 if (F->isDeclaration() || F->hasOptNone()) {
540 // Try to get mod/ref behaviour from function attributes.
541 if (F->doesNotAccessMemory()) {
542 // Can't do better than that!
543 } else if (F->onlyReadsMemory()) {
544 FI.addModRefInfo(ModRefInfo::Ref);
545 if (!F->onlyAccessesArgMemory() && MaySyncOrCallIntoModule(*F))
546 // This function might call back into the module and read a global -
547 // consider every global as possibly being read by this function.
548 FI.setMayReadAnyGlobal();
549 } else {
550 FI.addModRefInfo(ModRefInfo::ModRef);
551 if (!F->onlyAccessesArgMemory())
552 FI.setMayReadAnyGlobal();
553 if (MaySyncOrCallIntoModule(*F)) {
554 KnowNothing = true;
555 break;
556 }
557 }
558 continue;
559 }
560
561 for (CallGraphNode::iterator CI = SCC[i]->begin(), E = SCC[i]->end();
562 CI != E && !KnowNothing; ++CI)
563 if (Function *Callee = CI->second->getFunction()) {
564 if (FunctionInfo *CalleeFI = getFunctionInfo(Callee)) {
565 // Propagate function effect up.
566 FI.addFunctionInfo(*CalleeFI);
567 } else {
568 // Can't say anything about it. However, if it is inside our SCC,
569 // then nothing needs to be done.
570 CallGraphNode *CalleeNode = CG[Callee];
571 if (!is_contained(SCC, CalleeNode))
572 KnowNothing = true;
573 }
574 } else {
575 KnowNothing = true;
576 }
577 }
578
579 // If we can't say anything useful about this SCC, remove all SCC functions
580 // from the FunctionInfos map.
581 if (KnowNothing) {
582 for (auto *Node : SCC)
583 FunctionInfos.erase(Node->getFunction());
584 continue;
585 }
586
587 // Scan the function bodies for explicit loads or stores.
588 for (auto *Node : SCC) {
589 if (isModAndRefSet(FI.getModRefInfo()))
590 break; // The mod/ref lattice saturates here.
591
592 // Don't prove any properties based on the implementation of an optnone
593 // function. Function attributes were already used as a best approximation
594 // above.
595 if (Node->getFunction()->hasOptNone())
596 continue;
597
598 for (Instruction &I : instructions(Node->getFunction())) {
599 if (isModAndRefSet(FI.getModRefInfo()))
600 break; // The mod/ref lattice saturates here.
601
602 // We handle calls specially because the graph-relevant aspects are
603 // handled above.
604 if (isa<CallBase>(&I))
605 continue;
606
607 // All non-call instructions we use the primary predicates for whether
608 // they read or write memory.
609 if (I.mayReadFromMemory())
610 FI.addModRefInfo(ModRefInfo::Ref);
611 if (I.mayWriteToMemory())
612 FI.addModRefInfo(ModRefInfo::Mod);
613 }
614 }
615
616 if (!isModSet(FI.getModRefInfo()))
617 ++NumReadMemFunctions;
618 if (!isModOrRefSet(FI.getModRefInfo()))
619 ++NumNoMemFunctions;
620
621 // Finally, now that we know the full effect on this SCC, clone the
622 // information to each function in the SCC.
623 // FI is a reference into FunctionInfos, so copy it now so that it doesn't
624 // get invalidated if DenseMap decides to re-hash.
625 FunctionInfo CachedFI = FI;
626 for (unsigned i = 1, e = SCC.size(); i != e; ++i)
627 FunctionInfos[SCC[i]->getFunction()] = CachedFI;
628 }
629}
630
631// GV is a non-escaping global. V is a pointer address that has been loaded from.
632// If we can prove that V must escape, we can conclude that a load from V cannot
633// alias GV.
635 const Value *V,
636 int &Depth,
637 const DataLayout &DL) {
640 Visited.insert(V);
641 Inputs.push_back(V);
642 do {
643 const Value *Input = Inputs.pop_back_val();
644
647 // Arguments to functions or returns from functions are inherently
648 // escaping, so we can immediately classify those as not aliasing any
649 // non-addr-taken globals.
650 //
651 // (Transitive) loads from a global are also safe - if this aliased
652 // another global, its address would escape, so no alias.
653 continue;
654
655 // Recurse through a limited number of selects, loads and PHIs. This is an
656 // arbitrary depth of 4, lower numbers could be used to fix compile time
657 // issues if needed, but this is generally expected to be only be important
658 // for small depths.
659 if (++Depth > 4)
660 return false;
661
662 if (auto *LI = dyn_cast<LoadInst>(Input)) {
663 Inputs.push_back(getUnderlyingObject(LI->getPointerOperand()));
664 continue;
665 }
666 if (auto *SI = dyn_cast<SelectInst>(Input)) {
667 const Value *LHS = getUnderlyingObject(SI->getTrueValue());
668 const Value *RHS = getUnderlyingObject(SI->getFalseValue());
669 if (Visited.insert(LHS).second)
670 Inputs.push_back(LHS);
671 if (Visited.insert(RHS).second)
672 Inputs.push_back(RHS);
673 continue;
674 }
675 if (auto *PN = dyn_cast<PHINode>(Input)) {
676 for (const Value *Op : PN->incoming_values()) {
678 if (Visited.insert(Op).second)
679 Inputs.push_back(Op);
680 }
681 continue;
682 }
683
684 return false;
685 } while (!Inputs.empty());
686
687 // All inputs were known to be no-alias.
688 return true;
689}
690
691// There are particular cases where we can conclude no-alias between
692// a non-addr-taken global and some other underlying object. Specifically,
693// a non-addr-taken global is known to not be escaped from any function. It is
694// also incorrect for a transformation to introduce an escape of a global in
695// a way that is observable when it was not there previously. One function
696// being transformed to introduce an escape which could possibly be observed
697// (via loading from a global or the return value for example) within another
698// function is never safe. If the observation is made through non-atomic
699// operations on different threads, it is a data-race and UB. If the
700// observation is well defined, by being observed the transformation would have
701// changed program behavior by introducing the observed escape, making it an
702// invalid transform.
703//
704// This property does require that transformations which *temporarily* escape
705// a global that was not previously escaped, prior to restoring it, cannot rely
706// on the results of GMR::alias. This seems a reasonable restriction, although
707// currently there is no way to enforce it. There is also no realistic
708// optimization pass that would make this mistake. The closest example is
709// a transformation pass which does reg2mem of SSA values but stores them into
710// global variables temporarily before restoring the global variable's value.
711// This could be useful to expose "benign" races for example. However, it seems
712// reasonable to require that a pass which introduces escapes of global
713// variables in this way to either not trust AA results while the escape is
714// active, or to be forced to operate as a module pass that cannot co-exist
715// with an alias analysis such as GMR.
716bool GlobalsAAResult::isNonEscapingGlobalNoAlias(const GlobalValue *GV,
717 const Value *V,
718 const Instruction *CtxI) {
719 // In order to know that the underlying object cannot alias the
720 // non-addr-taken global, we must know that it would have to be an escape.
721 // Thus if the underlying object is a function argument, a load from
722 // a global, or the return of a function, it cannot alias. We can also
723 // recurse through PHI nodes and select nodes provided all of their inputs
724 // resolve to one of these known-escaping roots.
725
726 // A non-addr-taken global cannot alias with any non-pointer value.
727 // Check this early and exit.
728 if (!V->getType()->isPointerTy())
729 return true;
730
731 SmallPtrSet<const Value *, 8> Visited;
732 SmallVector<const Value *, 8> Inputs;
733 Visited.insert(V);
734 Inputs.push_back(V);
735 int Depth = 0;
736 do {
737 const Value *Input = Inputs.pop_back_val();
738
739 if (auto *InputGV = dyn_cast<GlobalValue>(Input)) {
740 // If one input is the very global we're querying against, then we can't
741 // conclude no-alias.
742 if (InputGV == GV)
743 return false;
744
745 // Distinct GlobalVariables never alias, unless overriden or zero-sized.
746 // FIXME: The condition can be refined, but be conservative for now.
747 auto *GVar = dyn_cast<GlobalVariable>(GV);
748 auto *InputGVar = dyn_cast<GlobalVariable>(InputGV);
749 if (GVar && InputGVar &&
750 !GVar->isDeclaration() && !InputGVar->isDeclaration() &&
751 !GVar->isInterposable() && !InputGVar->isInterposable()) {
752 Type *GVType = GVar->getInitializer()->getType();
753 Type *InputGVType = InputGVar->getInitializer()->getType();
754 if (GVType->isSized() && InputGVType->isSized() &&
755 (DL.getTypeAllocSize(GVType) > 0) &&
756 (DL.getTypeAllocSize(InputGVType) > 0))
757 continue;
758 }
759
760 // Conservatively return false, even though we could be smarter
761 // (e.g. look through GlobalAliases).
762 return false;
763 }
764
765 if (isa<Argument>(Input) || isa<CallInst>(Input) ||
766 isa<InvokeInst>(Input)) {
767 // Arguments to functions or returns from functions are inherently
768 // escaping, so we can immediately classify those as not aliasing any
769 // non-addr-taken globals.
770 continue;
771 }
772
773 if (CtxI)
774 if (auto *CPN = dyn_cast<ConstantPointerNull>(Input)) {
775 // Null pointer cannot alias with a non-addr-taken global.
776 const Function *F = CtxI->getFunction();
777 if (!NullPointerIsDefined(F, CPN->getPointerType()->getAddressSpace()))
778 continue;
779 }
780
781 // Recurse through a limited number of selects, loads and PHIs. This is an
782 // arbitrary depth of 4, lower numbers could be used to fix compile time
783 // issues if needed, but this is generally expected to be only be important
784 // for small depths.
785 if (++Depth > 4)
786 return false;
787
788 if (auto *LI = dyn_cast<LoadInst>(Input)) {
789 // A pointer loaded from a global would have been captured, and we know
790 // that the global is non-escaping, so no alias.
791 const Value *Ptr = getUnderlyingObject(LI->getPointerOperand());
793 // The load does not alias with GV.
794 continue;
795 // Otherwise, a load could come from anywhere, so bail.
796 return false;
797 }
798 if (auto *SI = dyn_cast<SelectInst>(Input)) {
799 const Value *LHS = getUnderlyingObject(SI->getTrueValue());
800 const Value *RHS = getUnderlyingObject(SI->getFalseValue());
801 if (Visited.insert(LHS).second)
802 Inputs.push_back(LHS);
803 if (Visited.insert(RHS).second)
804 Inputs.push_back(RHS);
805 continue;
806 }
807 if (auto *PN = dyn_cast<PHINode>(Input)) {
808 for (const Value *Op : PN->incoming_values()) {
810 if (Visited.insert(Op).second)
811 Inputs.push_back(Op);
812 }
813 continue;
814 }
815
816 // FIXME: It would be good to handle other obvious no-alias cases here, but
817 // it isn't clear how to do so reasonably without building a small version
818 // of BasicAA into this code.
819 return false;
820 } while (!Inputs.empty());
821
822 // If all the inputs to V were definitively no-alias, then V is no-alias.
823 return true;
824}
825
827 ModuleAnalysisManager::Invalidator &) {
828 // Check whether the analysis has been explicitly invalidated. Otherwise, it's
829 // stateless and remains preserved.
830 auto PAC = PA.getChecker<GlobalsAA>();
831 return !PAC.preservedWhenStateless();
832}
833
834/// alias - If one of the pointers is to a global that we are tracking, and the
835/// other is some random pointer, we know there cannot be an alias, because the
836/// address of the global isn't taken.
838 const MemoryLocation &LocB,
839 AAQueryInfo &AAQI, const Instruction *CtxI) {
840 // Get the base object these pointers point to.
841 const Value *UV1 =
843 const Value *UV2 =
845
846 // If either of the underlying values is a global, they may be non-addr-taken
847 // globals, which we can answer queries about.
848 const GlobalValue *GV1 = dyn_cast<GlobalValue>(UV1);
849 const GlobalValue *GV2 = dyn_cast<GlobalValue>(UV2);
850 if (GV1 || GV2) {
851 // If the global's address is taken, pretend we don't know it's a pointer to
852 // the global.
853 if (GV1 && !NonAddressTakenGlobals.count(GV1))
854 GV1 = nullptr;
855 if (GV2 && !NonAddressTakenGlobals.count(GV2))
856 GV2 = nullptr;
857
858 // If the two pointers are derived from two different non-addr-taken
859 // globals we know these can't alias.
860 if (GV1 && GV2 && GV1 != GV2)
862
863 // If one is and the other isn't, it isn't strictly safe but we can fake
864 // this result if necessary for performance. This does not appear to be
865 // a common problem in practice.
867 if ((GV1 || GV2) && GV1 != GV2)
869
870 // Check for a special case where a non-escaping global can be used to
871 // conclude no-alias.
872 if ((GV1 || GV2) && GV1 != GV2) {
873 const GlobalValue *GV = GV1 ? GV1 : GV2;
874 const Value *UV = GV1 ? UV2 : UV1;
875 if (isNonEscapingGlobalNoAlias(GV, UV, CtxI))
877 }
878
879 // Otherwise if they are both derived from the same addr-taken global, we
880 // can't know the two accesses don't overlap.
881 }
882
883 // These pointers may be based on the memory owned by an indirect global. If
884 // so, we may be able to handle this. First check to see if the base pointer
885 // is a direct load from an indirect global.
886 GV1 = GV2 = nullptr;
887 if (const LoadInst *LI = dyn_cast<LoadInst>(UV1))
888 if (GlobalVariable *GV = dyn_cast<GlobalVariable>(LI->getOperand(0)))
889 if (IndirectGlobals.count(GV))
890 GV1 = GV;
891 if (const LoadInst *LI = dyn_cast<LoadInst>(UV2))
892 if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(LI->getOperand(0)))
893 if (IndirectGlobals.count(GV))
894 GV2 = GV;
895
896 // These pointers may also be from an allocation for the indirect global. If
897 // so, also handle them.
898 if (!GV1)
899 GV1 = AllocsForIndirectGlobals.lookup(UV1);
900 if (!GV2)
901 GV2 = AllocsForIndirectGlobals.lookup(UV2);
902
903 // Now that we know whether the two pointers are related to indirect globals,
904 // use this to disambiguate the pointers. If the pointers are based on
905 // different indirect globals they cannot alias.
906 if (GV1 && GV2 && GV1 != GV2)
908
909 // If one is based on an indirect global and the other isn't, it isn't
910 // strictly safe but we can fake this result if necessary for performance.
911 // This does not appear to be a common problem in practice.
913 if ((GV1 || GV2) && GV1 != GV2)
915
917}
918
919ModRefInfo GlobalsAAResult::getModRefInfoForArgument(const CallBase *Call,
920 const GlobalValue *GV,
921 AAQueryInfo &AAQI) {
922 if (Call->doesNotAccessMemory())
924 ModRefInfo ConservativeResult =
925 Call->onlyReadsMemory() ? ModRefInfo::Ref : ModRefInfo::ModRef;
926
927 // Iterate through all the arguments to the called function. If any argument
928 // is based on GV, return the conservative result.
929 for (const auto &A : Call->args()) {
931 getUnderlyingObjects(A, Objects);
932
933 // All objects must be identified.
934 if (!all_of(Objects, isIdentifiedObject) &&
935 // Try ::alias to see if all objects are known not to alias GV.
936 !all_of(Objects, [&](const Value *V) {
940 }))
941 return ConservativeResult;
942
943 if (is_contained(Objects, GV))
944 return ConservativeResult;
945 }
946
947 // We identified all objects in the argument list, and none of them were GV.
949}
950
952 const MemoryLocation &Loc,
953 AAQueryInfo &AAQI) {
955
956 // If we are asking for mod/ref info of a direct call with a pointer to a
957 // global we are tracking, return information if we have it.
958 if (const GlobalValue *GV =
960 // If GV is internal to this IR and there is no function with local linkage
961 // that has had their address taken, keep looking for a tighter ModRefInfo.
962 if (GV->hasLocalLinkage() && !UnknownFunctionsWithLocalLinkage)
963 if (const Function *F = Call->getCalledFunction())
964 if (NonAddressTakenGlobals.count(GV))
965 if (const FunctionInfo *FI = getFunctionInfo(F))
966 Known = FI->getModRefInfoForGlobal(*GV) |
967 getModRefInfoForArgument(Call, GV, AAQI);
968
969 return Known;
970}
971
972GlobalsAAResult::GlobalsAAResult(
973 const DataLayout &DL,
974 std::function<const TargetLibraryInfo &(Function &F)> GetTLI)
975 : DL(DL), GetTLI(std::move(GetTLI)) {}
976
977GlobalsAAResult::GlobalsAAResult(GlobalsAAResult &&Arg)
978 : AAResultBase(std::move(Arg)), DL(Arg.DL), GetTLI(std::move(Arg.GetTLI)),
979 NonAddressTakenGlobals(std::move(Arg.NonAddressTakenGlobals)),
980 IndirectGlobals(std::move(Arg.IndirectGlobals)),
981 AllocsForIndirectGlobals(std::move(Arg.AllocsForIndirectGlobals)),
982 FunctionInfos(std::move(Arg.FunctionInfos)),
983 Handles(std::move(Arg.Handles)) {
984 // Update the parent for each DeletionCallbackHandle.
985 for (auto &H : Handles) {
986 assert(H.GAR == &Arg);
987 H.GAR = this;
988 }
989}
990
992
993/*static*/ GlobalsAAResult GlobalsAAResult::analyzeModule(
994 Module &M, std::function<const TargetLibraryInfo &(Function &F)> GetTLI,
995 CallGraph &CG) {
996 GlobalsAAResult Result(M.getDataLayout(), GetTLI);
997
998 // Discover which functions aren't recursive, to feed into AnalyzeGlobals.
999 Result.CollectSCCMembership(CG);
1000
1001 // Find non-addr taken globals.
1002 Result.AnalyzeGlobals(M);
1003
1004 // Propagate on CG.
1005 Result.AnalyzeCallGraph(CG, M);
1006
1007 return Result;
1008}
1009
1010AnalysisKey GlobalsAA::Key;
1011
1015 auto GetTLI = [&FAM](Function &F) -> TargetLibraryInfo & {
1016 return FAM.getResult<TargetLibraryAnalysis>(F);
1017 };
1018 return GlobalsAAResult::analyzeModule(M, GetTLI,
1020}
1021
1024 if (auto *G = AM.getCachedResult<GlobalsAA>(M)) {
1025 auto &CG = AM.getResult<CallGraphAnalysis>(M);
1026 G->NonAddressTakenGlobals.clear();
1027 G->UnknownFunctionsWithLocalLinkage = false;
1028 G->IndirectGlobals.clear();
1029 G->AllocsForIndirectGlobals.clear();
1030 G->FunctionInfos.clear();
1031 G->FunctionToSCCMap.clear();
1032 G->Handles.clear();
1033 G->CollectSCCMembership(CG);
1034 G->AnalyzeGlobals(M);
1035 G->AnalyzeCallGraph(CG, M);
1036 }
1037 return PreservedAnalyses::all();
1038}
1039
1042 "Globals Alias Analysis", false, true)
1046 "Globals Alias Analysis", false, true)
1047
1051
1053
1055 auto GetTLI = [this](Function &F) -> TargetLibraryInfo & {
1056 return this->getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(F);
1057 };
1059 M, GetTLI, getAnalysis<CallGraphWrapperPass>().getCallGraph())));
1060 return false;
1061}
1062
1064 Result.reset();
1065 return false;
1066}
1067
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Expand Atomic instructions
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 cl::opt< bool > EnableUnsafeGlobalsModRefAliasResults("enable-unsafe-globalsmodref-alias-results", cl::init(false), cl::Hidden)
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
Machine Check Debug Module
uint64_t IntrinsicInst * II
#define P(N)
FunctionAnalysisManager FAM
#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:171
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:286
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:330
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:64
bool hasLocalLinkage() const
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
An alias analysis result set for globals.
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 &)
static LLVM_ABI GlobalsAAResult analyzeModule(Module &M, std::function< const TargetLibraryInfo &(Function &F)> GetTLI, CallGraph &CG)
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:255
ModulePass(char &pid)
Definition Pass.h:257
A Module instance is used to store all the information related to an LLVM module.
Definition Module.h:67
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.
Analysis pass providing the TargetLibraryInfo.
Provides information about what library functions are available for the current target.
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
Definition Type.h:328
Value * getValPtr() const
LLVM Value Representation.
Definition Value.h:75
iterator_range< user_iterator > users()
Definition Value.h:426
LLVM_ABI const Value * stripPointerCastsForAliasAnalysis() const
Strip off pointer casts, all-zero GEPs, single-argument phi nodes and invariant group info.
Definition Value.cpp:725
const ParentTy * getParent() const
Definition ilist_node.h:34
CallInst * Call
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
initializer< Ty > init(const Ty &Val)
@ 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.
FunctionAddr VTableAddr Value
Definition InstrProf.h:137
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:1738
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.
InnerAnalysisManagerProxy< FunctionAnalysisManager, Module > FunctionAnalysisManagerModuleProxy
Provide the FunctionAnalysisManager to Module proxy.
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
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
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
LLVM_ABI Value * getFreedOperand(const CallBase *CB, const TargetLibraryInfo *TLI)
If this if a call to a free function, return the freed operand.
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:1916
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
Definition STLExtras.h:1946
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 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:874
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)