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