blob: 5ec1a06ffbc06c9dbf1e2a5ef3bcca46ded17a07 [file] [log] [blame]
Chris Lattner26dff502004-06-28 06:33:13 +00001//===- GlobalsModRef.cpp - Simple Mod/Ref Analysis for Globals ------------===//
Misha Brukman01808ca2005-04-21 21:13:18 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
Misha Brukman01808ca2005-04-21 21:13:18 +00006//
Chris Lattner26dff502004-06-28 06:33:13 +00007//===----------------------------------------------------------------------===//
8//
9// This simple pass provides alias and mod/ref information for global values
Chris Lattner3a353e82004-07-27 06:40:37 +000010// 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.
Chris Lattner26dff502004-06-28 06:33:13 +000013//
14//===----------------------------------------------------------------------===//
15
Chandler Carruth21dcff72015-08-14 03:48:20 +000016#include "llvm/Analysis/GlobalsModRef.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000017#include "llvm/ADT/SCCIterator.h"
Chandler Carruthf3af4af2015-07-22 11:47:54 +000018#include "llvm/ADT/SmallPtrSet.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000019#include "llvm/ADT/Statistic.h"
Victor Hernandezf390e042009-10-27 20:05:49 +000020#include "llvm/Analysis/MemoryBuiltins.h"
Chandler Carruth7b560d42015-09-09 17:55:00 +000021#include "llvm/Analysis/TargetLibraryInfo.h"
Dan Gohmana4fcd242010-12-15 20:02:24 +000022#include "llvm/Analysis/ValueTracking.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000023#include "llvm/IR/DerivedTypes.h"
Chandler Carruth83948572014-03-04 10:30:26 +000024#include "llvm/IR/InstIterator.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000025#include "llvm/IR/Instructions.h"
26#include "llvm/IR/IntrinsicInst.h"
27#include "llvm/IR/Module.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000028#include "llvm/Pass.h"
Reid Spencer7c16caa2004-09-01 22:55:40 +000029#include "llvm/Support/CommandLine.h"
Chris Lattner26dff502004-06-28 06:33:13 +000030using namespace llvm;
31
Chandler Carruthf1221bd2014-04-22 02:48:03 +000032#define DEBUG_TYPE "globalsmodref-aa"
33
Chris Lattner57ef9422006-12-19 22:30:33 +000034STATISTIC(NumNonAddrTakenGlobalVars,
35 "Number of global vars without address taken");
36STATISTIC(NumNonAddrTakenFunctions,"Number of functions without address taken");
37STATISTIC(NumNoMemFunctions, "Number of functions that do not access memory");
38STATISTIC(NumReadMemFunctions, "Number of functions that only read memory");
39STATISTIC(NumIndirectGlobalVars, "Number of indirect global objects");
40
Chandler Carruthf55803f2015-07-17 06:58:24 +000041// An option to enable unsafe alias results from the GlobalsModRef analysis.
42// When enabled, GlobalsModRef will provide no-alias results which in extremely
43// rare cases may not be conservatively correct. In particular, in the face of
44// transforms which cause assymetry between how effective GetUnderlyingObject
45// is for two pointers, it may produce incorrect results.
46//
47// These unsafe results have been returned by GMR for many years without
48// causing significant issues in the wild and so we provide a mechanism to
49// re-enable them for users of LLVM that have a particular performance
50// sensitivity and no known issues. The option also makes it easy to evaluate
51// the performance impact of these results.
52static cl::opt<bool> EnableUnsafeGlobalsModRefAliasResults(
53 "enable-unsafe-globalsmodref-alias-results", cl::init(false), cl::Hidden);
54
Chandler Carruth5657b732015-07-22 23:56:31 +000055/// The mod/ref information collected for a particular function.
56///
57/// We collect information about mod/ref behavior of a function here, both in
58/// general and as pertains to specific globals. We only have this detailed
59/// information when we know *something* useful about the behavior. If we
60/// saturate to fully general mod/ref, we remove the info for the function.
Chandler Carruth7b560d42015-09-09 17:55:00 +000061class GlobalsAAResult::FunctionInfo {
Chandler Carruth8e4357d2015-07-23 07:50:52 +000062 typedef SmallDenseMap<const GlobalValue *, ModRefInfo, 16> GlobalInfoMapType;
63
64 /// Build a wrapper struct that has 8-byte alignment. All heap allocations
65 /// should provide this much alignment at least, but this makes it clear we
66 /// specifically rely on this amount of alignment.
Fangrui Songa8301fce2018-07-27 05:38:14 +000067 struct alignas(8) AlignedMap {
Chandler Carruth8e4357d2015-07-23 07:50:52 +000068 AlignedMap() {}
69 AlignedMap(const AlignedMap &Arg) : Map(Arg.Map) {}
70 GlobalInfoMapType Map;
71 };
72
73 /// Pointer traits for our aligned map.
74 struct AlignedMapPointerTraits {
75 static inline void *getAsVoidPointer(AlignedMap *P) { return P; }
76 static inline AlignedMap *getFromVoidPointer(void *P) {
77 return (AlignedMap *)P;
78 }
79 enum { NumLowBitsAvailable = 3 };
Benjamin Kramerb2505002016-10-20 15:02:18 +000080 static_assert(alignof(AlignedMap) >= (1 << NumLowBitsAvailable),
Chandler Carruth8e4357d2015-07-23 07:50:52 +000081 "AlignedMap insufficiently aligned to have enough low bits.");
82 };
83
84 /// The bit that flags that this function may read any global. This is
85 /// chosen to mix together with ModRefInfo bits.
Alina Sbirlea63d22502017-12-05 20:12:23 +000086 /// FIXME: This assumes ModRefInfo lattice will remain 4 bits!
Alina Sbirlea50db8a22017-12-21 21:41:53 +000087 /// It overlaps with ModRefInfo::Must bit!
88 /// FunctionInfo.getModRefInfo() masks out everything except ModRef so
89 /// this remains correct, but the Must info is lost.
Chandler Carruth8e4357d2015-07-23 07:50:52 +000090 enum { MayReadAnyGlobal = 4 };
91
92 /// Checks to document the invariants of the bit packing here.
Alina Sbirlea50db8a22017-12-21 21:41:53 +000093 static_assert((MayReadAnyGlobal & static_cast<int>(ModRefInfo::MustModRef)) ==
94 0,
Chandler Carruth8e4357d2015-07-23 07:50:52 +000095 "ModRef and the MayReadAnyGlobal flag bits overlap.");
Alina Sbirlea50db8a22017-12-21 21:41:53 +000096 static_assert(((MayReadAnyGlobal |
97 static_cast<int>(ModRefInfo::MustModRef)) >>
Chandler Carruth8e4357d2015-07-23 07:50:52 +000098 AlignedMapPointerTraits::NumLowBitsAvailable) == 0,
99 "Insufficient low bits to store our flag and ModRef info.");
100
Chandler Carruth5657b732015-07-22 23:56:31 +0000101public:
Chandler Carruth8e4357d2015-07-23 07:50:52 +0000102 FunctionInfo() : Info() {}
103 ~FunctionInfo() {
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.
109 FunctionInfo(const FunctionInfo &Arg)
110 : Info(nullptr, Arg.Info.getInt()) {
111 if (const auto *ArgPtr = Arg.Info.getPointer())
112 Info.setPointer(new AlignedMap(*ArgPtr));
113 }
114 FunctionInfo(FunctionInfo &&Arg)
115 : Info(Arg.Info.getPointer(), Arg.Info.getInt()) {
116 Arg.Info.setPointerAndInt(nullptr, 0);
117 }
118 FunctionInfo &operator=(const FunctionInfo &RHS) {
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 }
125 FunctionInfo &operator=(FunctionInfo &&RHS) {
126 delete Info.getPointer();
127 Info.setPointerAndInt(RHS.Info.getPointer(), RHS.Info.getInt());
128 RHS.Info.setPointerAndInt(nullptr, 0);
129 return *this;
130 }
Chris Lattner3a353e82004-07-27 06:40:37 +0000131
Alina Sbirlea50db8a22017-12-21 21:41:53 +0000132 /// This method clears MayReadAnyGlobal bit added by GlobalsAAResult to return
133 /// the corresponding ModRefInfo. It must align in functionality with
134 /// clearMust().
135 ModRefInfo globalClearMayReadAnyGlobal(int I) const {
136 return ModRefInfo((I & static_cast<int>(ModRefInfo::ModRef)) |
137 static_cast<int>(ModRefInfo::NoModRef));
138 }
139
Chandler Carruth5657b732015-07-22 23:56:31 +0000140 /// Returns the \c ModRefInfo info for this function.
Chandler Carruth8e4357d2015-07-23 07:50:52 +0000141 ModRefInfo getModRefInfo() const {
Alina Sbirlea50db8a22017-12-21 21:41:53 +0000142 return globalClearMayReadAnyGlobal(Info.getInt());
Chandler Carruth8e4357d2015-07-23 07:50:52 +0000143 }
Duncan Sands06dbb122008-09-12 07:29:58 +0000144
Chandler Carruth5657b732015-07-22 23:56:31 +0000145 /// Adds new \c ModRefInfo for this function to its state.
Chandler Carruth8e4357d2015-07-23 07:50:52 +0000146 void addModRefInfo(ModRefInfo NewMRI) {
Alina Sbirlea50db8a22017-12-21 21:41:53 +0000147 Info.setInt(Info.getInt() | static_cast<int>(setMust(NewMRI)));
Chandler Carruth8e4357d2015-07-23 07:50:52 +0000148 }
Chandler Carruth5657b732015-07-22 23:56:31 +0000149
150 /// Returns whether this function may read any global variable, and we don't
151 /// know which global.
Chandler Carruth8e4357d2015-07-23 07:50:52 +0000152 bool mayReadAnyGlobal() const { return Info.getInt() & MayReadAnyGlobal; }
Chandler Carruth5657b732015-07-22 23:56:31 +0000153
154 /// Sets this function as potentially reading from any global.
Chandler Carruth8e4357d2015-07-23 07:50:52 +0000155 void setMayReadAnyGlobal() { Info.setInt(Info.getInt() | MayReadAnyGlobal); }
Chandler Carruth5657b732015-07-22 23:56:31 +0000156
157 /// Returns the \c ModRefInfo info for this function w.r.t. a particular
158 /// global, which may be more precise than the general information above.
159 ModRefInfo getModRefInfoForGlobal(const GlobalValue &GV) const {
Alina Sbirlea193429f2017-12-07 22:41:34 +0000160 ModRefInfo GlobalMRI =
161 mayReadAnyGlobal() ? ModRefInfo::Ref : ModRefInfo::NoModRef;
Chandler Carruth8e4357d2015-07-23 07:50:52 +0000162 if (AlignedMap *P = Info.getPointer()) {
163 auto I = P->Map.find(&GV);
164 if (I != P->Map.end())
Alina Sbirlead6037eb2017-12-07 00:43:19 +0000165 GlobalMRI = unionModRef(GlobalMRI, I->second);
Chandler Carruth8e4357d2015-07-23 07:50:52 +0000166 }
Chandler Carruth5657b732015-07-22 23:56:31 +0000167 return GlobalMRI;
Chandler Carruth466d7ad2015-07-14 08:42:39 +0000168 }
169
Chandler Carruthdbb46222015-07-23 00:12:32 +0000170 /// Add mod/ref info from another function into ours, saturating towards
Alina Sbirlea193429f2017-12-07 22:41:34 +0000171 /// ModRef.
Chandler Carruthdbb46222015-07-23 00:12:32 +0000172 void addFunctionInfo(const FunctionInfo &FI) {
173 addModRefInfo(FI.getModRefInfo());
174
175 if (FI.mayReadAnyGlobal())
176 setMayReadAnyGlobal();
177
Chandler Carruth8e4357d2015-07-23 07:50:52 +0000178 if (AlignedMap *P = FI.Info.getPointer())
179 for (const auto &G : P->Map)
180 addModRefInfoForGlobal(*G.first, G.second);
Chandler Carruth5657b732015-07-22 23:56:31 +0000181 }
Chandler Carruth466d7ad2015-07-14 08:42:39 +0000182
Chandler Carruth5657b732015-07-22 23:56:31 +0000183 void addModRefInfoForGlobal(const GlobalValue &GV, ModRefInfo NewMRI) {
Chandler Carruth8e4357d2015-07-23 07:50:52 +0000184 AlignedMap *P = Info.getPointer();
185 if (!P) {
186 P = new AlignedMap();
187 Info.setPointer(P);
188 }
189 auto &GlobalMRI = P->Map[&GV];
Alina Sbirlead6037eb2017-12-07 00:43:19 +0000190 GlobalMRI = unionModRef(GlobalMRI, NewMRI);
Chandler Carruth5657b732015-07-22 23:56:31 +0000191 }
192
Chandler Carruth786e6db2015-07-28 06:01:57 +0000193 /// Clear a global's ModRef info. Should be used when a global is being
194 /// deleted.
195 void eraseModRefInfoForGlobal(const GlobalValue &GV) {
196 if (AlignedMap *P = Info.getPointer())
197 P->Map.erase(&GV);
198 }
199
Chandler Carruth5657b732015-07-22 23:56:31 +0000200private:
Chandler Carruth8e4357d2015-07-23 07:50:52 +0000201 /// All of the information is encoded into a single pointer, with a three bit
202 /// integer in the low three bits. The high bit provides a flag for when this
203 /// function may read any global. The low two bits are the ModRefInfo. And
204 /// the pointer, when non-null, points to a map from GlobalValue to
205 /// ModRefInfo specific to that GlobalValue.
206 PointerIntPair<AlignedMap *, 3, unsigned, AlignedMapPointerTraits> Info;
Chandler Carruth466d7ad2015-07-14 08:42:39 +0000207};
208
Chandler Carruth7b560d42015-09-09 17:55:00 +0000209void GlobalsAAResult::DeletionCallbackHandle::deleted() {
Chandler Carruth21dcff72015-08-14 03:48:20 +0000210 Value *V = getValPtr();
211 if (auto *F = dyn_cast<Function>(V))
NAKAMURA Takumi98800d92015-09-14 06:16:44 +0000212 GAR->FunctionInfos.erase(F);
Chandler Carruth466d7ad2015-07-14 08:42:39 +0000213
Chandler Carruth21dcff72015-08-14 03:48:20 +0000214 if (GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
NAKAMURA Takumi98800d92015-09-14 06:16:44 +0000215 if (GAR->NonAddressTakenGlobals.erase(GV)) {
Chandler Carruth21dcff72015-08-14 03:48:20 +0000216 // This global might be an indirect global. If so, remove it and
217 // remove any AllocRelatedValues for it.
NAKAMURA Takumi98800d92015-09-14 06:16:44 +0000218 if (GAR->IndirectGlobals.erase(GV)) {
Chandler Carruth21dcff72015-08-14 03:48:20 +0000219 // Remove any entries in AllocsForIndirectGlobals for this global.
NAKAMURA Takumi98800d92015-09-14 06:16:44 +0000220 for (auto I = GAR->AllocsForIndirectGlobals.begin(),
221 E = GAR->AllocsForIndirectGlobals.end();
Chandler Carruth21dcff72015-08-14 03:48:20 +0000222 I != E; ++I)
223 if (I->second == GV)
NAKAMURA Takumi98800d92015-09-14 06:16:44 +0000224 GAR->AllocsForIndirectGlobals.erase(I);
Chandler Carruth8f1b63e2015-07-22 11:10:41 +0000225 }
226
Chandler Carruth21dcff72015-08-14 03:48:20 +0000227 // Scan the function info we have collected and remove this global
228 // from all of them.
NAKAMURA Takumi98800d92015-09-14 06:16:44 +0000229 for (auto &FIPair : GAR->FunctionInfos)
Chandler Carruth21dcff72015-08-14 03:48:20 +0000230 FIPair.second.eraseModRefInfoForGlobal(*GV);
Chandler Carruth8f1b63e2015-07-22 11:10:41 +0000231 }
Chandler Carruth466d7ad2015-07-14 08:42:39 +0000232 }
233
Chandler Carruth21dcff72015-08-14 03:48:20 +0000234 // If this is an allocation related to an indirect global, remove it.
NAKAMURA Takumi98800d92015-09-14 06:16:44 +0000235 GAR->AllocsForIndirectGlobals.erase(V);
Chandler Carruth466d7ad2015-07-14 08:42:39 +0000236
Chandler Carruth21dcff72015-08-14 03:48:20 +0000237 // And clear out the handle.
238 setValPtr(nullptr);
NAKAMURA Takumi98800d92015-09-14 06:16:44 +0000239 GAR->Handles.erase(I);
Chandler Carruth21dcff72015-08-14 03:48:20 +0000240 // This object is now destroyed!
Alexander Kornienkof00654e2015-06-23 09:49:53 +0000241}
Chris Lattner26dff502004-06-28 06:33:13 +0000242
Chandler Carruth7b560d42015-09-09 17:55:00 +0000243FunctionModRefBehavior GlobalsAAResult::getModRefBehavior(const Function *F) {
Chandler Carruth21dcff72015-08-14 03:48:20 +0000244 FunctionModRefBehavior Min = FMRB_UnknownModRefBehavior;
245
246 if (FunctionInfo *FI = getFunctionInfo(F)) {
Alina Sbirlea63d22502017-12-05 20:12:23 +0000247 if (!isModOrRefSet(FI->getModRefInfo()))
Chandler Carruth21dcff72015-08-14 03:48:20 +0000248 Min = FMRB_DoesNotAccessMemory;
Alina Sbirlea63d22502017-12-05 20:12:23 +0000249 else if (!isModSet(FI->getModRefInfo()))
Chandler Carruth21dcff72015-08-14 03:48:20 +0000250 Min = FMRB_OnlyReadsMemory;
251 }
252
Chandler Carruth7b560d42015-09-09 17:55:00 +0000253 return FunctionModRefBehavior(AAResultBase::getModRefBehavior(F) & Min);
Chandler Carruth21dcff72015-08-14 03:48:20 +0000254}
255
Chandler Carruth7b560d42015-09-09 17:55:00 +0000256FunctionModRefBehavior
Chandler Carruth363ac682019-01-07 05:42:51 +0000257GlobalsAAResult::getModRefBehavior(const CallBase *Call) {
Chandler Carruth21dcff72015-08-14 03:48:20 +0000258 FunctionModRefBehavior Min = FMRB_UnknownModRefBehavior;
259
Chandler Carruth363ac682019-01-07 05:42:51 +0000260 if (!Call->hasOperandBundles())
261 if (const Function *F = Call->getCalledFunction())
Sanjoy Dasca2edc72016-02-09 02:31:47 +0000262 if (FunctionInfo *FI = getFunctionInfo(F)) {
Alina Sbirlea63d22502017-12-05 20:12:23 +0000263 if (!isModOrRefSet(FI->getModRefInfo()))
Sanjoy Dasca2edc72016-02-09 02:31:47 +0000264 Min = FMRB_DoesNotAccessMemory;
Alina Sbirlea63d22502017-12-05 20:12:23 +0000265 else if (!isModSet(FI->getModRefInfo()))
Sanjoy Dasca2edc72016-02-09 02:31:47 +0000266 Min = FMRB_OnlyReadsMemory;
267 }
Chandler Carruth21dcff72015-08-14 03:48:20 +0000268
Chandler Carruth363ac682019-01-07 05:42:51 +0000269 return FunctionModRefBehavior(AAResultBase::getModRefBehavior(Call) & Min);
Chandler Carruth21dcff72015-08-14 03:48:20 +0000270}
271
272/// Returns the function info for the function, or null if we don't have
273/// anything useful to say about it.
Chandler Carruth7b560d42015-09-09 17:55:00 +0000274GlobalsAAResult::FunctionInfo *
275GlobalsAAResult::getFunctionInfo(const Function *F) {
Chandler Carruth21dcff72015-08-14 03:48:20 +0000276 auto I = FunctionInfos.find(F);
277 if (I != FunctionInfos.end())
278 return &I->second;
279 return nullptr;
280}
281
Chris Lattnerbfdd19b2006-10-01 22:36:45 +0000282/// AnalyzeGlobals - Scan through the users of all of the internal
Duncan Sands42c644e2008-09-03 12:55:42 +0000283/// GlobalValue's in the program. If none of them have their "address taken"
Chris Lattner26dff502004-06-28 06:33:13 +0000284/// (really, their address passed to something nontrivial), record this fact,
285/// and record the functions that they are used directly in.
Chandler Carruth7b560d42015-09-09 17:55:00 +0000286void GlobalsAAResult::AnalyzeGlobals(Module &M) {
Matthias Braunb30f2f512016-01-30 01:24:31 +0000287 SmallPtrSet<Function *, 32> TrackedFunctions;
Chandler Carrutha033bbb2015-07-15 08:09:23 +0000288 for (Function &F : M)
Chandler Carruth4cef26e2015-07-22 22:10:05 +0000289 if (F.hasLocalLinkage())
290 if (!AnalyzeUsesOfPointer(&F)) {
Chris Lattner3a353e82004-07-27 06:40:37 +0000291 // Remember that we are tracking this global.
Chandler Carrutha033bbb2015-07-15 08:09:23 +0000292 NonAddressTakenGlobals.insert(&F);
Chandler Carruth786e6db2015-07-28 06:01:57 +0000293 TrackedFunctions.insert(&F);
Chandler Carruthda7c1912015-07-22 09:27:58 +0000294 Handles.emplace_front(*this, &F);
295 Handles.front().I = Handles.begin();
Chris Lattner26dff502004-06-28 06:33:13 +0000296 ++NumNonAddrTakenFunctions;
297 }
Chris Lattner26dff502004-06-28 06:33:13 +0000298
Matthias Braunb30f2f512016-01-30 01:24:31 +0000299 SmallPtrSet<Function *, 16> Readers, Writers;
Chandler Carrutha033bbb2015-07-15 08:09:23 +0000300 for (GlobalVariable &GV : M.globals())
301 if (GV.hasLocalLinkage()) {
Chandler Carruth4cef26e2015-07-22 22:10:05 +0000302 if (!AnalyzeUsesOfPointer(&GV, &Readers,
303 GV.isConstant() ? nullptr : &Writers)) {
Chris Lattner26dff502004-06-28 06:33:13 +0000304 // Remember that we are tracking this global, and the mod/ref fns
Chandler Carrutha033bbb2015-07-15 08:09:23 +0000305 NonAddressTakenGlobals.insert(&GV);
Chandler Carruthda7c1912015-07-22 09:27:58 +0000306 Handles.emplace_front(*this, &GV);
307 Handles.front().I = Handles.begin();
Duncan Sands42c644e2008-09-03 12:55:42 +0000308
Chandler Carruth786e6db2015-07-28 06:01:57 +0000309 for (Function *Reader : Readers) {
310 if (TrackedFunctions.insert(Reader).second) {
311 Handles.emplace_front(*this, Reader);
312 Handles.front().I = Handles.begin();
313 }
Alina Sbirlea193429f2017-12-07 22:41:34 +0000314 FunctionInfos[Reader].addModRefInfoForGlobal(GV, ModRefInfo::Ref);
Chandler Carruth786e6db2015-07-28 06:01:57 +0000315 }
Chris Lattner3a353e82004-07-27 06:40:37 +0000316
Chandler Carrutha033bbb2015-07-15 08:09:23 +0000317 if (!GV.isConstant()) // No need to keep track of writers to constants
Chandler Carruth786e6db2015-07-28 06:01:57 +0000318 for (Function *Writer : Writers) {
319 if (TrackedFunctions.insert(Writer).second) {
320 Handles.emplace_front(*this, Writer);
321 Handles.front().I = Handles.begin();
322 }
Alina Sbirlea193429f2017-12-07 22:41:34 +0000323 FunctionInfos[Writer].addModRefInfoForGlobal(GV, ModRefInfo::Mod);
Chandler Carruth786e6db2015-07-28 06:01:57 +0000324 }
Chris Lattner26dff502004-06-28 06:33:13 +0000325 ++NumNonAddrTakenGlobalVars;
Duncan Sands42c644e2008-09-03 12:55:42 +0000326
Chris Lattnerbfdd19b2006-10-01 22:36:45 +0000327 // If this global holds a pointer type, see if it is an indirect global.
Manuel Jacob5f6eaac2016-01-16 20:30:46 +0000328 if (GV.getValueType()->isPointerTy() &&
Chandler Carrutha033bbb2015-07-15 08:09:23 +0000329 AnalyzeIndirectGlobalMemory(&GV))
Chris Lattnerbfdd19b2006-10-01 22:36:45 +0000330 ++NumIndirectGlobalVars;
Chris Lattner26dff502004-06-28 06:33:13 +0000331 }
Chandler Carruth466d7ad2015-07-14 08:42:39 +0000332 Readers.clear();
333 Writers.clear();
Chris Lattner26dff502004-06-28 06:33:13 +0000334 }
335}
336
Chris Lattnerbfdd19b2006-10-01 22:36:45 +0000337/// AnalyzeUsesOfPointer - Look at all of the users of the specified pointer.
338/// If this is used by anything complex (i.e., the address escapes), return
339/// true. Also, while we are at it, keep track of those functions that read and
340/// write to the value.
341///
342/// If OkayStoreDest is non-null, stores into this global are allowed.
Chandler Carruth7b560d42015-09-09 17:55:00 +0000343bool GlobalsAAResult::AnalyzeUsesOfPointer(Value *V,
344 SmallPtrSetImpl<Function *> *Readers,
345 SmallPtrSetImpl<Function *> *Writers,
346 GlobalValue *OkayStoreDest) {
Chandler Carruth466d7ad2015-07-14 08:42:39 +0000347 if (!V->getType()->isPointerTy())
348 return true;
Chris Lattner26dff502004-06-28 06:33:13 +0000349
Chandler Carruthcdf47882014-03-09 03:16:01 +0000350 for (Use &U : V->uses()) {
351 User *I = U.getUser();
352 if (LoadInst *LI = dyn_cast<LoadInst>(I)) {
Chandler Carruth4cef26e2015-07-22 22:10:05 +0000353 if (Readers)
354 Readers->insert(LI->getParent()->getParent());
Chandler Carruthcdf47882014-03-09 03:16:01 +0000355 } else if (StoreInst *SI = dyn_cast<StoreInst>(I)) {
Chris Lattnerbfdd19b2006-10-01 22:36:45 +0000356 if (V == SI->getOperand(1)) {
Chandler Carruth4cef26e2015-07-22 22:10:05 +0000357 if (Writers)
358 Writers->insert(SI->getParent()->getParent());
Chris Lattnerbfdd19b2006-10-01 22:36:45 +0000359 } else if (SI->getOperand(1) != OkayStoreDest) {
Chandler Carruth466d7ad2015-07-14 08:42:39 +0000360 return true; // Storing the pointer
Chris Lattnerbfdd19b2006-10-01 22:36:45 +0000361 }
Chandler Carruthcdf47882014-03-09 03:16:01 +0000362 } else if (Operator::getOpcode(I) == Instruction::GetElementPtr) {
363 if (AnalyzeUsesOfPointer(I, Readers, Writers))
Victor Hernandez537d8d92009-09-18 21:34:51 +0000364 return true;
Chandler Carruthcdf47882014-03-09 03:16:01 +0000365 } else if (Operator::getOpcode(I) == Instruction::BitCast) {
366 if (AnalyzeUsesOfPointer(I, Readers, Writers, OkayStoreDest))
Benjamin Kramerb8266d22014-02-10 14:17:30 +0000367 return true;
Chandler Carruth363ac682019-01-07 05:42:51 +0000368 } else if (auto *Call = dyn_cast<CallBase>(I)) {
Chris Lattner26dff502004-06-28 06:33:13 +0000369 // Make sure that this is just the function being called, not that it is
370 // passing into the function.
Chandler Carruth363ac682019-01-07 05:42:51 +0000371 if (Call->isDataOperand(&U)) {
Benjamin Kramerb8266d22014-02-10 14:17:30 +0000372 // Detect calls to free.
Chandler Carruth363ac682019-01-07 05:42:51 +0000373 if (Call->isArgOperand(&U) && isFreeCall(I, &TLI)) {
Chandler Carruth4cef26e2015-07-22 22:10:05 +0000374 if (Writers)
Chandler Carruth363ac682019-01-07 05:42:51 +0000375 Writers->insert(Call->getParent()->getParent());
Chandler Carruth4cef26e2015-07-22 22:10:05 +0000376 } else {
Benjamin Kramerb8266d22014-02-10 14:17:30 +0000377 return true; // Argument of an unknown call.
Chandler Carruth4cef26e2015-07-22 22:10:05 +0000378 }
Misha Brukman01808ca2005-04-21 21:13:18 +0000379 }
Chandler Carruthcdf47882014-03-09 03:16:01 +0000380 } else if (ICmpInst *ICI = dyn_cast<ICmpInst>(I)) {
Reid Spencer266e42b2006-12-23 06:05:41 +0000381 if (!isa<ConstantPointerNull>(ICI->getOperand(1)))
Chandler Carruth466d7ad2015-07-14 08:42:39 +0000382 return true; // Allow comparison against null.
Eli Friedman74bed9d72016-10-04 00:03:55 +0000383 } else if (Constant *C = dyn_cast<Constant>(I)) {
Eli Friedmanc5b72622016-10-24 21:47:44 +0000384 // Ignore constants which don't have any live uses.
385 if (isa<GlobalValue>(C) || C->isConstantUsed())
386 return true;
Chris Lattner26dff502004-06-28 06:33:13 +0000387 } else {
388 return true;
389 }
Gabor Greif070b9a22010-07-09 15:53:42 +0000390 }
391
Chris Lattner26dff502004-06-28 06:33:13 +0000392 return false;
393}
394
Chris Lattnerbfdd19b2006-10-01 22:36:45 +0000395/// AnalyzeIndirectGlobalMemory - We found an non-address-taken global variable
396/// which holds a pointer type. See if the global always points to non-aliased
397/// heap memory: that is, all initializers of the globals are allocations, and
398/// those allocations have no use other than initialization of the global.
399/// Further, all loads out of GV must directly use the memory, not store the
400/// pointer somewhere. If this is true, we consider the memory pointed to by
401/// GV to be owned by GV and can disambiguate other pointers from it.
James Molloyc67dec62015-10-28 10:41:29 +0000402bool GlobalsAAResult::AnalyzeIndirectGlobalMemory(GlobalVariable *GV) {
Chris Lattnerbfdd19b2006-10-01 22:36:45 +0000403 // Keep track of values related to the allocation of the memory, f.e. the
404 // value produced by the malloc call and any casts.
Chandler Carruth466d7ad2015-07-14 08:42:39 +0000405 std::vector<Value *> AllocRelatedValues;
Duncan Sands42c644e2008-09-03 12:55:42 +0000406
James Molloyc67dec62015-10-28 10:41:29 +0000407 // If the initializer is a valid pointer, bail.
408 if (Constant *C = GV->getInitializer())
409 if (!C->isNullValue())
410 return false;
Fangrui Songf78650a2018-07-30 19:41:25 +0000411
Chris Lattnerbfdd19b2006-10-01 22:36:45 +0000412 // Walk the user list of the global. If we find anything other than a direct
413 // load or store, bail out.
Chandler Carruthcdf47882014-03-09 03:16:01 +0000414 for (User *U : GV->users()) {
Gabor Greifaa389f52010-07-09 16:22:36 +0000415 if (LoadInst *LI = dyn_cast<LoadInst>(U)) {
Chris Lattnerbfdd19b2006-10-01 22:36:45 +0000416 // The pointer loaded from the global can only be used in simple ways:
417 // we allow addressing of it and loading storing to it. We do *not* allow
418 // storing the loaded pointer somewhere else or passing to a function.
Chandler Carruth4cef26e2015-07-22 22:10:05 +0000419 if (AnalyzeUsesOfPointer(LI))
Chandler Carruth466d7ad2015-07-14 08:42:39 +0000420 return false; // Loaded pointer escapes.
Chris Lattnerbfdd19b2006-10-01 22:36:45 +0000421 // TODO: Could try some IP mod/ref of the loaded pointer.
Gabor Greifaa389f52010-07-09 16:22:36 +0000422 } else if (StoreInst *SI = dyn_cast<StoreInst>(U)) {
Chris Lattnerbfdd19b2006-10-01 22:36:45 +0000423 // Storing the global itself.
Chandler Carruth466d7ad2015-07-14 08:42:39 +0000424 if (SI->getOperand(0) == GV)
425 return false;
Duncan Sands42c644e2008-09-03 12:55:42 +0000426
Chris Lattnerbfdd19b2006-10-01 22:36:45 +0000427 // If storing the null pointer, ignore it.
428 if (isa<ConstantPointerNull>(SI->getOperand(0)))
429 continue;
Duncan Sands42c644e2008-09-03 12:55:42 +0000430
Chris Lattnerbfdd19b2006-10-01 22:36:45 +0000431 // Check the value being stored.
Mehdi Aminia28d91d2015-03-10 02:37:25 +0000432 Value *Ptr = GetUnderlyingObject(SI->getOperand(0),
433 GV->getParent()->getDataLayout());
Chris Lattnerbfdd19b2006-10-01 22:36:45 +0000434
Chandler Carruth7b560d42015-09-09 17:55:00 +0000435 if (!isAllocLikeFn(Ptr, &TLI))
Chandler Carruth466d7ad2015-07-14 08:42:39 +0000436 return false; // Too hard to analyze.
Duncan Sands42c644e2008-09-03 12:55:42 +0000437
Chris Lattnerbfdd19b2006-10-01 22:36:45 +0000438 // Analyze all uses of the allocation. If any of them are used in a
439 // non-simple way (e.g. stored to another global) bail out.
Chandler Carruth4cef26e2015-07-22 22:10:05 +0000440 if (AnalyzeUsesOfPointer(Ptr, /*Readers*/ nullptr, /*Writers*/ nullptr,
441 GV))
Chandler Carruth466d7ad2015-07-14 08:42:39 +0000442 return false; // Loaded pointer escapes.
Chris Lattnerbfdd19b2006-10-01 22:36:45 +0000443
444 // Remember that this allocation is related to the indirect global.
445 AllocRelatedValues.push_back(Ptr);
446 } else {
447 // Something complex, bail out.
448 return false;
449 }
450 }
Duncan Sands42c644e2008-09-03 12:55:42 +0000451
Chris Lattnerbfdd19b2006-10-01 22:36:45 +0000452 // Okay, this is an indirect global. Remember all of the allocations for
453 // this global in AllocsForIndirectGlobals.
454 while (!AllocRelatedValues.empty()) {
455 AllocsForIndirectGlobals[AllocRelatedValues.back()] = GV;
Chandler Carruthda7c1912015-07-22 09:27:58 +0000456 Handles.emplace_front(*this, AllocRelatedValues.back());
457 Handles.front().I = Handles.begin();
Chris Lattnerbfdd19b2006-10-01 22:36:45 +0000458 AllocRelatedValues.pop_back();
459 }
460 IndirectGlobals.insert(GV);
Chandler Carruthda7c1912015-07-22 09:27:58 +0000461 Handles.emplace_front(*this, GV);
462 Handles.front().I = Handles.begin();
Chris Lattnerbfdd19b2006-10-01 22:36:45 +0000463 return true;
464}
465
Fangrui Songf78650a2018-07-30 19:41:25 +0000466void GlobalsAAResult::CollectSCCMembership(CallGraph &CG) {
James Molloyeb466412015-09-25 15:39:29 +0000467 // We do a bottom-up SCC traversal of the call graph. In other words, we
468 // visit all callees before callers (leaf-first).
469 unsigned SCCID = 0;
470 for (scc_iterator<CallGraph *> I = scc_begin(&CG); !I.isAtEnd(); ++I) {
471 const std::vector<CallGraphNode *> &SCC = *I;
472 assert(!SCC.empty() && "SCC with no functions?");
473
474 for (auto *CGN : SCC)
475 if (Function *F = CGN->getFunction())
476 FunctionToSCCMap[F] = SCCID;
477 ++SCCID;
478 }
479}
480
Chris Lattner26dff502004-06-28 06:33:13 +0000481/// AnalyzeCallGraph - At this point, we know the functions where globals are
482/// immediately stored to and read from. Propagate this information up the call
Chris Lattner3a353e82004-07-27 06:40:37 +0000483/// graph to all callers and compute the mod/ref info for all memory for each
Misha Brukman01808ca2005-04-21 21:13:18 +0000484/// function.
Chandler Carruth7b560d42015-09-09 17:55:00 +0000485void GlobalsAAResult::AnalyzeCallGraph(CallGraph &CG, Module &M) {
Chris Lattner26dff502004-06-28 06:33:13 +0000486 // We do a bottom-up SCC traversal of the call graph. In other words, we
487 // visit all callees before callers (leaf-first).
Chandler Carruth466d7ad2015-07-14 08:42:39 +0000488 for (scc_iterator<CallGraph *> I = scc_begin(&CG); !I.isAtEnd(); ++I) {
Duncan P. N. Exon Smithd2b2fac2014-04-25 18:24:50 +0000489 const std::vector<CallGraphNode *> &SCC = *I;
Duncan Sands21a57992008-09-04 19:16:20 +0000490 assert(!SCC.empty() && "SCC with no functions?");
Duncan Sands42c644e2008-09-03 12:55:42 +0000491
David Blaikiec662b502017-06-06 20:51:15 +0000492 Function *F = SCC[0]->getFunction();
493
David Blaikie7a9b7882017-06-07 21:37:39 +0000494 if (!F || !F->isDefinitionExact()) {
Sanjoy Das5ce32722016-04-08 00:48:30 +0000495 // Calls externally or not exact - can't say anything useful. Remove any
496 // existing function records (may have been created when scanning
497 // globals).
Chandler Carrutha033bbb2015-07-15 08:09:23 +0000498 for (auto *Node : SCC)
Chandler Carruth5657b732015-07-22 23:56:31 +0000499 FunctionInfos.erase(Node->getFunction());
Duncan Sands42c644e2008-09-03 12:55:42 +0000500 continue;
Duncan Sands21a57992008-09-04 19:16:20 +0000501 }
502
David Blaikiec662b502017-06-06 20:51:15 +0000503 FunctionInfo &FI = FunctionInfos[F];
Chandler Carruth196a9fa2018-03-16 23:51:33 +0000504 Handles.emplace_front(*this, F);
505 Handles.front().I = Handles.begin();
Duncan Sands42c644e2008-09-03 12:55:42 +0000506 bool KnowNothing = false;
Chris Lattner3a353e82004-07-27 06:40:37 +0000507
Duncan Sands42c644e2008-09-03 12:55:42 +0000508 // Collect the mod/ref properties due to called functions. We only compute
509 // one mod-ref set.
510 for (unsigned i = 0, e = SCC.size(); i != e && !KnowNothing; ++i) {
Duncan Sands42c644e2008-09-03 12:55:42 +0000511 if (!F) {
512 KnowNothing = true;
Chris Lattner3a353e82004-07-27 06:40:37 +0000513 break;
Chris Lattner26dff502004-06-28 06:33:13 +0000514 }
Chris Lattner3a353e82004-07-27 06:40:37 +0000515
David Blaikie7a9b7882017-06-07 21:37:39 +0000516 if (F->isDeclaration() || F->hasFnAttribute(Attribute::OptimizeNone)) {
Duncan Sands42c644e2008-09-03 12:55:42 +0000517 // Try to get mod/ref behaviour from function attributes.
Amaury Sechet457cc4d2016-01-06 13:23:52 +0000518 if (F->doesNotAccessMemory()) {
Duncan Sands0eca0572008-09-03 15:31:24 +0000519 // Can't do better than that!
520 } else if (F->onlyReadsMemory()) {
Alina Sbirlea193429f2017-12-07 22:41:34 +0000521 FI.addModRefInfo(ModRefInfo::Ref);
Tom Stellard1b5cf622016-07-14 15:50:27 +0000522 if (!F->isIntrinsic() && !F->onlyAccessesArgMemory())
Duncan Sandse30b36f2008-09-11 15:43:12 +0000523 // This function might call back into the module and read a global -
Duncan Sands06dbb122008-09-12 07:29:58 +0000524 // consider every global as possibly being read by this function.
Chandler Carruth5657b732015-07-22 23:56:31 +0000525 FI.setMayReadAnyGlobal();
Duncan Sands0eca0572008-09-03 15:31:24 +0000526 } else {
Alina Sbirlea193429f2017-12-07 22:41:34 +0000527 FI.addModRefInfo(ModRefInfo::ModRef);
Duncan Sandsd4133ac2008-09-11 19:35:55 +0000528 // Can't say anything useful unless it's an intrinsic - they don't
529 // read or write global variables of the kind considered here.
530 KnowNothing = !F->isIntrinsic();
Duncan Sands42c644e2008-09-03 12:55:42 +0000531 }
532 continue;
533 }
Misha Brukman01808ca2005-04-21 21:13:18 +0000534
Duncan Sands42c644e2008-09-03 12:55:42 +0000535 for (CallGraphNode::iterator CI = SCC[i]->begin(), E = SCC[i]->end();
Duncan Sands21a57992008-09-04 19:16:20 +0000536 CI != E && !KnowNothing; ++CI)
Duncan Sands42c644e2008-09-03 12:55:42 +0000537 if (Function *Callee = CI->second->getFunction()) {
Chandler Carruth5657b732015-07-22 23:56:31 +0000538 if (FunctionInfo *CalleeFI = getFunctionInfo(Callee)) {
Duncan Sands42c644e2008-09-03 12:55:42 +0000539 // Propagate function effect up.
Chandler Carruthdbb46222015-07-23 00:12:32 +0000540 FI.addFunctionInfo(*CalleeFI);
Duncan Sands42c644e2008-09-03 12:55:42 +0000541 } else {
542 // Can't say anything about it. However, if it is inside our SCC,
543 // then nothing needs to be done.
544 CallGraphNode *CalleeNode = CG[Callee];
David Majnemer0d955d02016-08-11 22:21:41 +0000545 if (!is_contained(SCC, CalleeNode))
Duncan Sands42c644e2008-09-03 12:55:42 +0000546 KnowNothing = true;
547 }
548 } else {
549 KnowNothing = true;
550 }
551 }
552
553 // If we can't say anything useful about this SCC, remove all SCC functions
Chandler Carruth5657b732015-07-22 23:56:31 +0000554 // from the FunctionInfos map.
Duncan Sands42c644e2008-09-03 12:55:42 +0000555 if (KnowNothing) {
Chandler Carrutha033bbb2015-07-15 08:09:23 +0000556 for (auto *Node : SCC)
Chandler Carruth5657b732015-07-22 23:56:31 +0000557 FunctionInfos.erase(Node->getFunction());
Duncan Sandse74d7502008-09-03 16:10:55 +0000558 continue;
Duncan Sands42c644e2008-09-03 12:55:42 +0000559 }
560
561 // Scan the function bodies for explicit loads or stores.
Chandler Carruth6af95d02015-07-15 08:53:29 +0000562 for (auto *Node : SCC) {
Alina Sbirlea63d22502017-12-05 20:12:23 +0000563 if (isModAndRefSet(FI.getModRefInfo()))
Chandler Carruth6af95d02015-07-15 08:53:29 +0000564 break; // The mod/ref lattice saturates here.
David Blaikiec662b502017-06-06 20:51:15 +0000565
566 // Don't prove any properties based on the implementation of an optnone
David Blaikie7a9b7882017-06-07 21:37:39 +0000567 // function. Function attributes were already used as a best approximation
568 // above.
569 if (Node->getFunction()->hasFnAttribute(Attribute::OptimizeNone))
David Blaikiec662b502017-06-06 20:51:15 +0000570 continue;
David Blaikiec662b502017-06-06 20:51:15 +0000571
Nico Rieck78199512015-08-06 19:10:45 +0000572 for (Instruction &I : instructions(Node->getFunction())) {
Alina Sbirlea63d22502017-12-05 20:12:23 +0000573 if (isModAndRefSet(FI.getModRefInfo()))
Chandler Carruth6af95d02015-07-15 08:53:29 +0000574 break; // The mod/ref lattice saturates here.
575
576 // We handle calls specially because the graph-relevant aspects are
577 // handled above.
Chandler Carruth363ac682019-01-07 05:42:51 +0000578 if (auto *Call = dyn_cast<CallBase>(&I)) {
579 if (isAllocationFn(Call, &TLI) || isFreeCall(Call, &TLI)) {
Chandler Carruth6af95d02015-07-15 08:53:29 +0000580 // FIXME: It is completely unclear why this is necessary and not
581 // handled by the above graph code.
Alina Sbirlea193429f2017-12-07 22:41:34 +0000582 FI.addModRefInfo(ModRefInfo::ModRef);
Chandler Carruth363ac682019-01-07 05:42:51 +0000583 } else if (Function *Callee = Call->getCalledFunction()) {
Chandler Carruth6af95d02015-07-15 08:53:29 +0000584 // The callgraph doesn't include intrinsic calls.
585 if (Callee->isIntrinsic()) {
Chandler Carruth363ac682019-01-07 05:42:51 +0000586 if (isa<DbgInfoIntrinsic>(Call))
Mikael Holmen4653b1a2018-01-15 07:05:51 +0000587 // Don't let dbg intrinsics affect alias info.
588 continue;
589
Chandler Carruth194f59c2015-07-22 23:15:57 +0000590 FunctionModRefBehavior Behaviour =
Chandler Carruth7b560d42015-09-09 17:55:00 +0000591 AAResultBase::getModRefBehavior(Callee);
Alina Sbirlead6037eb2017-12-07 00:43:19 +0000592 FI.addModRefInfo(createModRefInfo(Behaviour));
Chandler Carruth6af95d02015-07-15 08:53:29 +0000593 }
594 }
595 continue;
Duncan Sands9ddb3142008-09-13 12:45:50 +0000596 }
Duncan Sands42c644e2008-09-03 12:55:42 +0000597
Chandler Carruth6af95d02015-07-15 08:53:29 +0000598 // All non-call instructions we use the primary predicates for whether
599 // thay read or write memory.
600 if (I.mayReadFromMemory())
Alina Sbirlea193429f2017-12-07 22:41:34 +0000601 FI.addModRefInfo(ModRefInfo::Ref);
Chandler Carruth6af95d02015-07-15 08:53:29 +0000602 if (I.mayWriteToMemory())
Alina Sbirlea193429f2017-12-07 22:41:34 +0000603 FI.addModRefInfo(ModRefInfo::Mod);
Chandler Carruth6af95d02015-07-15 08:53:29 +0000604 }
605 }
606
Alina Sbirlea63d22502017-12-05 20:12:23 +0000607 if (!isModSet(FI.getModRefInfo()))
Duncan Sands42c644e2008-09-03 12:55:42 +0000608 ++NumReadMemFunctions;
Alina Sbirlea63d22502017-12-05 20:12:23 +0000609 if (!isModOrRefSet(FI.getModRefInfo()))
Duncan Sands42c644e2008-09-03 12:55:42 +0000610 ++NumNoMemFunctions;
Duncan Sands42c644e2008-09-03 12:55:42 +0000611
612 // Finally, now that we know the full effect on this SCC, clone the
613 // information to each function in the SCC.
James Molloy17379c42015-10-19 08:54:59 +0000614 // FI is a reference into FunctionInfos, so copy it now so that it doesn't
615 // get invalidated if DenseMap decides to re-hash.
616 FunctionInfo CachedFI = FI;
Duncan Sands42c644e2008-09-03 12:55:42 +0000617 for (unsigned i = 1, e = SCC.size(); i != e; ++i)
James Molloy17379c42015-10-19 08:54:59 +0000618 FunctionInfos[SCC[i]->getFunction()] = CachedFI;
Chris Lattner3a353e82004-07-27 06:40:37 +0000619 }
Chris Lattner26dff502004-06-28 06:33:13 +0000620}
621
James Molloy5b2a7322015-10-22 13:44:26 +0000622// GV is a non-escaping global. V is a pointer address that has been loaded from.
623// If we can prove that V must escape, we can conclude that a load from V cannot
624// alias GV.
625static bool isNonEscapingGlobalNoAliasWithLoad(const GlobalValue *GV,
626 const Value *V,
627 int &Depth,
628 const DataLayout &DL) {
629 SmallPtrSet<const Value *, 8> Visited;
630 SmallVector<const Value *, 8> Inputs;
631 Visited.insert(V);
632 Inputs.push_back(V);
633 do {
634 const Value *Input = Inputs.pop_back_val();
Fangrui Songf78650a2018-07-30 19:41:25 +0000635
James Molloy5b2a7322015-10-22 13:44:26 +0000636 if (isa<GlobalValue>(Input) || isa<Argument>(Input) || isa<CallInst>(Input) ||
637 isa<InvokeInst>(Input))
638 // Arguments to functions or returns from functions are inherently
639 // escaping, so we can immediately classify those as not aliasing any
640 // non-addr-taken globals.
641 //
642 // (Transitive) loads from a global are also safe - if this aliased
643 // another global, its address would escape, so no alias.
644 continue;
645
646 // Recurse through a limited number of selects, loads and PHIs. This is an
647 // arbitrary depth of 4, lower numbers could be used to fix compile time
648 // issues if needed, but this is generally expected to be only be important
649 // for small depths.
650 if (++Depth > 4)
651 return false;
652
653 if (auto *LI = dyn_cast<LoadInst>(Input)) {
654 Inputs.push_back(GetUnderlyingObject(LI->getPointerOperand(), DL));
655 continue;
Fangrui Songf78650a2018-07-30 19:41:25 +0000656 }
James Molloy5b2a7322015-10-22 13:44:26 +0000657 if (auto *SI = dyn_cast<SelectInst>(Input)) {
658 const Value *LHS = GetUnderlyingObject(SI->getTrueValue(), DL);
659 const Value *RHS = GetUnderlyingObject(SI->getFalseValue(), DL);
660 if (Visited.insert(LHS).second)
661 Inputs.push_back(LHS);
662 if (Visited.insert(RHS).second)
663 Inputs.push_back(RHS);
664 continue;
665 }
666 if (auto *PN = dyn_cast<PHINode>(Input)) {
667 for (const Value *Op : PN->incoming_values()) {
668 Op = GetUnderlyingObject(Op, DL);
669 if (Visited.insert(Op).second)
670 Inputs.push_back(Op);
671 }
672 continue;
673 }
Fangrui Songf78650a2018-07-30 19:41:25 +0000674
James Molloy5b2a7322015-10-22 13:44:26 +0000675 return false;
676 } while (!Inputs.empty());
677
678 // All inputs were known to be no-alias.
679 return true;
680}
681
Chandler Carruth405e4f92015-08-05 17:58:30 +0000682// There are particular cases where we can conclude no-alias between
683// a non-addr-taken global and some other underlying object. Specifically,
684// a non-addr-taken global is known to not be escaped from any function. It is
685// also incorrect for a transformation to introduce an escape of a global in
686// a way that is observable when it was not there previously. One function
687// being transformed to introduce an escape which could possibly be observed
688// (via loading from a global or the return value for example) within another
689// function is never safe. If the observation is made through non-atomic
690// operations on different threads, it is a data-race and UB. If the
691// observation is well defined, by being observed the transformation would have
692// changed program behavior by introducing the observed escape, making it an
693// invalid transform.
694//
695// This property does require that transformations which *temporarily* escape
696// a global that was not previously escaped, prior to restoring it, cannot rely
697// on the results of GMR::alias. This seems a reasonable restriction, although
698// currently there is no way to enforce it. There is also no realistic
699// optimization pass that would make this mistake. The closest example is
700// a transformation pass which does reg2mem of SSA values but stores them into
701// global variables temporarily before restoring the global variable's value.
702// This could be useful to expose "benign" races for example. However, it seems
703// reasonable to require that a pass which introduces escapes of global
704// variables in this way to either not trust AA results while the escape is
705// active, or to be forced to operate as a module pass that cannot co-exist
706// with an alias analysis such as GMR.
Chandler Carruth7b560d42015-09-09 17:55:00 +0000707bool GlobalsAAResult::isNonEscapingGlobalNoAlias(const GlobalValue *GV,
708 const Value *V) {
Chandler Carruth405e4f92015-08-05 17:58:30 +0000709 // In order to know that the underlying object cannot alias the
710 // non-addr-taken global, we must know that it would have to be an escape.
711 // Thus if the underlying object is a function argument, a load from
712 // a global, or the return of a function, it cannot alias. We can also
713 // recurse through PHI nodes and select nodes provided all of their inputs
714 // resolve to one of these known-escaping roots.
715 SmallPtrSet<const Value *, 8> Visited;
716 SmallVector<const Value *, 8> Inputs;
717 Visited.insert(V);
718 Inputs.push_back(V);
719 int Depth = 0;
720 do {
721 const Value *Input = Inputs.pop_back_val();
722
723 if (auto *InputGV = dyn_cast<GlobalValue>(Input)) {
724 // If one input is the very global we're querying against, then we can't
725 // conclude no-alias.
726 if (InputGV == GV)
727 return false;
728
Michael Kuperstein07f31d92015-08-11 08:06:44 +0000729 // Distinct GlobalVariables never alias, unless overriden or zero-sized.
730 // FIXME: The condition can be refined, but be conservative for now.
731 auto *GVar = dyn_cast<GlobalVariable>(GV);
732 auto *InputGVar = dyn_cast<GlobalVariable>(InputGV);
733 if (GVar && InputGVar &&
734 !GVar->isDeclaration() && !InputGVar->isDeclaration() &&
Sanjoy Das5ce32722016-04-08 00:48:30 +0000735 !GVar->isInterposable() && !InputGVar->isInterposable()) {
Michael Kuperstein07f31d92015-08-11 08:06:44 +0000736 Type *GVType = GVar->getInitializer()->getType();
737 Type *InputGVType = InputGVar->getInitializer()->getType();
738 if (GVType->isSized() && InputGVType->isSized() &&
Chandler Carruth7b560d42015-09-09 17:55:00 +0000739 (DL.getTypeAllocSize(GVType) > 0) &&
740 (DL.getTypeAllocSize(InputGVType) > 0))
Michael Kuperstein07f31d92015-08-11 08:06:44 +0000741 continue;
742 }
743
744 // Conservatively return false, even though we could be smarter
745 // (e.g. look through GlobalAliases).
Chandler Carruth405e4f92015-08-05 17:58:30 +0000746 return false;
747 }
748
749 if (isa<Argument>(Input) || isa<CallInst>(Input) ||
750 isa<InvokeInst>(Input)) {
751 // Arguments to functions or returns from functions are inherently
752 // escaping, so we can immediately classify those as not aliasing any
753 // non-addr-taken globals.
754 continue;
755 }
Fangrui Songf78650a2018-07-30 19:41:25 +0000756
James Molloy5b2a7322015-10-22 13:44:26 +0000757 // Recurse through a limited number of selects, loads and PHIs. This is an
Chandler Carruth405e4f92015-08-05 17:58:30 +0000758 // arbitrary depth of 4, lower numbers could be used to fix compile time
759 // issues if needed, but this is generally expected to be only be important
760 // for small depths.
761 if (++Depth > 4)
762 return false;
James Molloy5b2a7322015-10-22 13:44:26 +0000763
764 if (auto *LI = dyn_cast<LoadInst>(Input)) {
765 // A pointer loaded from a global would have been captured, and we know
766 // that the global is non-escaping, so no alias.
767 const Value *Ptr = GetUnderlyingObject(LI->getPointerOperand(), DL);
768 if (isNonEscapingGlobalNoAliasWithLoad(GV, Ptr, Depth, DL))
769 // The load does not alias with GV.
770 continue;
771 // Otherwise, a load could come from anywhere, so bail.
772 return false;
773 }
Chandler Carruth405e4f92015-08-05 17:58:30 +0000774 if (auto *SI = dyn_cast<SelectInst>(Input)) {
Chandler Carruth7b560d42015-09-09 17:55:00 +0000775 const Value *LHS = GetUnderlyingObject(SI->getTrueValue(), DL);
776 const Value *RHS = GetUnderlyingObject(SI->getFalseValue(), DL);
Chandler Carruth405e4f92015-08-05 17:58:30 +0000777 if (Visited.insert(LHS).second)
778 Inputs.push_back(LHS);
779 if (Visited.insert(RHS).second)
780 Inputs.push_back(RHS);
781 continue;
782 }
783 if (auto *PN = dyn_cast<PHINode>(Input)) {
784 for (const Value *Op : PN->incoming_values()) {
Chandler Carruth7b560d42015-09-09 17:55:00 +0000785 Op = GetUnderlyingObject(Op, DL);
Chandler Carruth405e4f92015-08-05 17:58:30 +0000786 if (Visited.insert(Op).second)
787 Inputs.push_back(Op);
788 }
789 continue;
790 }
791
Michael Kuperstein07f31d92015-08-11 08:06:44 +0000792 // FIXME: It would be good to handle other obvious no-alias cases here, but
793 // it isn't clear how to do so reasonbly without building a small version
Chandler Carruth7b560d42015-09-09 17:55:00 +0000794 // of BasicAA into this code. We could recurse into AAResultBase::alias
Michael Kuperstein07f31d92015-08-11 08:06:44 +0000795 // here but that seems likely to go poorly as we're inside the
796 // implementation of such a query. Until then, just conservatievly retun
797 // false.
Chandler Carruth405e4f92015-08-05 17:58:30 +0000798 return false;
799 } while (!Inputs.empty());
800
801 // If all the inputs to V were definitively no-alias, then V is no-alias.
802 return true;
803}
804
Chris Lattner26dff502004-06-28 06:33:13 +0000805/// alias - If one of the pointers is to a global that we are tracking, and the
806/// other is some random pointer, we know there cannot be an alias, because the
807/// address of the global isn't taken.
Chandler Carruth7b560d42015-09-09 17:55:00 +0000808AliasResult GlobalsAAResult::alias(const MemoryLocation &LocA,
809 const MemoryLocation &LocB) {
Chris Lattnerbfdd19b2006-10-01 22:36:45 +0000810 // Get the base object these pointers point to.
Chandler Carruth7b560d42015-09-09 17:55:00 +0000811 const Value *UV1 = GetUnderlyingObject(LocA.Ptr, DL);
812 const Value *UV2 = GetUnderlyingObject(LocB.Ptr, DL);
Duncan Sands42c644e2008-09-03 12:55:42 +0000813
Chris Lattnerbfdd19b2006-10-01 22:36:45 +0000814 // If either of the underlying values is a global, they may be non-addr-taken
815 // globals, which we can answer queries about.
Dan Gohman5442c712010-08-03 21:48:53 +0000816 const GlobalValue *GV1 = dyn_cast<GlobalValue>(UV1);
817 const GlobalValue *GV2 = dyn_cast<GlobalValue>(UV2);
Chris Lattnerbfdd19b2006-10-01 22:36:45 +0000818 if (GV1 || GV2) {
819 // If the global's address is taken, pretend we don't know it's a pointer to
820 // the global.
Chandler Carruth466d7ad2015-07-14 08:42:39 +0000821 if (GV1 && !NonAddressTakenGlobals.count(GV1))
822 GV1 = nullptr;
823 if (GV2 && !NonAddressTakenGlobals.count(GV2))
824 GV2 = nullptr;
Chris Lattner26dff502004-06-28 06:33:13 +0000825
Dan Gohman4a618822010-02-10 16:03:48 +0000826 // If the two pointers are derived from two different non-addr-taken
Chandler Carruthf55803f2015-07-17 06:58:24 +0000827 // globals we know these can't alias.
828 if (GV1 && GV2 && GV1 != GV2)
Chris Lattnerbfdd19b2006-10-01 22:36:45 +0000829 return NoAlias;
Chris Lattner26dff502004-06-28 06:33:13 +0000830
Chandler Carruthf55803f2015-07-17 06:58:24 +0000831 // If one is and the other isn't, it isn't strictly safe but we can fake
832 // this result if necessary for performance. This does not appear to be
833 // a common problem in practice.
834 if (EnableUnsafeGlobalsModRefAliasResults)
835 if ((GV1 || GV2) && GV1 != GV2)
836 return NoAlias;
837
Chandler Carruth405e4f92015-08-05 17:58:30 +0000838 // Check for a special case where a non-escaping global can be used to
839 // conclude no-alias.
Chandler Carruth99ad7bb2015-07-28 11:11:11 +0000840 if ((GV1 || GV2) && GV1 != GV2) {
Chandler Carruth405e4f92015-08-05 17:58:30 +0000841 const GlobalValue *GV = GV1 ? GV1 : GV2;
Chandler Carruth99ad7bb2015-07-28 11:11:11 +0000842 const Value *UV = GV1 ? UV2 : UV1;
Chandler Carruth405e4f92015-08-05 17:58:30 +0000843 if (isNonEscapingGlobalNoAlias(GV, UV))
Chandler Carruth99ad7bb2015-07-28 11:11:11 +0000844 return NoAlias;
Chandler Carruth99ad7bb2015-07-28 11:11:11 +0000845 }
846
Chris Lattnerbfdd19b2006-10-01 22:36:45 +0000847 // Otherwise if they are both derived from the same addr-taken global, we
848 // can't know the two accesses don't overlap.
849 }
Duncan Sands42c644e2008-09-03 12:55:42 +0000850
Chris Lattnerbfdd19b2006-10-01 22:36:45 +0000851 // These pointers may be based on the memory owned by an indirect global. If
852 // so, we may be able to handle this. First check to see if the base pointer
853 // is a direct load from an indirect global.
Craig Topper353eda42014-04-24 06:44:33 +0000854 GV1 = GV2 = nullptr;
Dan Gohman5442c712010-08-03 21:48:53 +0000855 if (const LoadInst *LI = dyn_cast<LoadInst>(UV1))
Chris Lattnerbfdd19b2006-10-01 22:36:45 +0000856 if (GlobalVariable *GV = dyn_cast<GlobalVariable>(LI->getOperand(0)))
857 if (IndirectGlobals.count(GV))
858 GV1 = GV;
Dan Gohman5442c712010-08-03 21:48:53 +0000859 if (const LoadInst *LI = dyn_cast<LoadInst>(UV2))
860 if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(LI->getOperand(0)))
Chris Lattnerbfdd19b2006-10-01 22:36:45 +0000861 if (IndirectGlobals.count(GV))
862 GV2 = GV;
Duncan Sands42c644e2008-09-03 12:55:42 +0000863
Chris Lattnerbfdd19b2006-10-01 22:36:45 +0000864 // These pointers may also be from an allocation for the indirect global. If
865 // so, also handle them.
Chandler Carruth56e2c622015-07-22 11:43:24 +0000866 if (!GV1)
867 GV1 = AllocsForIndirectGlobals.lookup(UV1);
868 if (!GV2)
869 GV2 = AllocsForIndirectGlobals.lookup(UV2);
Duncan Sands42c644e2008-09-03 12:55:42 +0000870
Chris Lattnerbfdd19b2006-10-01 22:36:45 +0000871 // Now that we know whether the two pointers are related to indirect globals,
Chandler Carruthf55803f2015-07-17 06:58:24 +0000872 // use this to disambiguate the pointers. If the pointers are based on
873 // different indirect globals they cannot alias.
874 if (GV1 && GV2 && GV1 != GV2)
Chris Lattner26dff502004-06-28 06:33:13 +0000875 return NoAlias;
Duncan Sands42c644e2008-09-03 12:55:42 +0000876
Chandler Carruthf55803f2015-07-17 06:58:24 +0000877 // If one is based on an indirect global and the other isn't, it isn't
878 // strictly safe but we can fake this result if necessary for performance.
879 // This does not appear to be a common problem in practice.
880 if (EnableUnsafeGlobalsModRefAliasResults)
881 if ((GV1 || GV2) && GV1 != GV2)
882 return NoAlias;
883
Chandler Carruth7b560d42015-09-09 17:55:00 +0000884 return AAResultBase::alias(LocA, LocB);
Chris Lattner26dff502004-06-28 06:33:13 +0000885}
886
Chandler Carruth363ac682019-01-07 05:42:51 +0000887ModRefInfo GlobalsAAResult::getModRefInfoForArgument(const CallBase *Call,
James Molloyeb466412015-09-25 15:39:29 +0000888 const GlobalValue *GV) {
Chandler Carruth363ac682019-01-07 05:42:51 +0000889 if (Call->doesNotAccessMemory())
Alina Sbirlea193429f2017-12-07 22:41:34 +0000890 return ModRefInfo::NoModRef;
891 ModRefInfo ConservativeResult =
Chandler Carruth363ac682019-01-07 05:42:51 +0000892 Call->onlyReadsMemory() ? ModRefInfo::Ref : ModRefInfo::ModRef;
David Majnemer0a16c222016-08-11 21:15:00 +0000893
James Molloyeb466412015-09-25 15:39:29 +0000894 // Iterate through all the arguments to the called function. If any argument
895 // is based on GV, return the conservative result.
Chandler Carruth363ac682019-01-07 05:42:51 +0000896 for (auto &A : Call->args()) {
James Molloyeb466412015-09-25 15:39:29 +0000897 SmallVector<Value*, 4> Objects;
898 GetUnderlyingObjects(A, Objects, DL);
David Majnemer0a16c222016-08-11 21:15:00 +0000899
James Molloyeb466412015-09-25 15:39:29 +0000900 // All objects must be identified.
David Majnemer0a16c222016-08-11 21:15:00 +0000901 if (!all_of(Objects, isIdentifiedObject) &&
Vaivaswatha Nagaraj68befd72016-01-14 08:46:45 +0000902 // Try ::alias to see if all objects are known not to alias GV.
David Majnemer0a16c222016-08-11 21:15:00 +0000903 !all_of(Objects, [&](Value *V) {
Vaivaswatha Nagaraj68befd72016-01-14 08:46:45 +0000904 return this->alias(MemoryLocation(V), MemoryLocation(GV)) == NoAlias;
David Majnemer0a16c222016-08-11 21:15:00 +0000905 }))
James Molloyeb466412015-09-25 15:39:29 +0000906 return ConservativeResult;
907
David Majnemer0a16c222016-08-11 21:15:00 +0000908 if (is_contained(Objects, GV))
James Molloyeb466412015-09-25 15:39:29 +0000909 return ConservativeResult;
910 }
911
912 // We identified all objects in the argument list, and none of them were GV.
Alina Sbirlea193429f2017-12-07 22:41:34 +0000913 return ModRefInfo::NoModRef;
James Molloyeb466412015-09-25 15:39:29 +0000914}
915
Chandler Carruth363ac682019-01-07 05:42:51 +0000916ModRefInfo GlobalsAAResult::getModRefInfo(const CallBase *Call,
Chandler Carruth7b560d42015-09-09 17:55:00 +0000917 const MemoryLocation &Loc) {
Alina Sbirlea193429f2017-12-07 22:41:34 +0000918 ModRefInfo Known = ModRefInfo::ModRef;
Chris Lattner26dff502004-06-28 06:33:13 +0000919
920 // If we are asking for mod/ref info of a direct call with a pointer to a
Chris Lattner3a353e82004-07-27 06:40:37 +0000921 // global we are tracking, return information if we have it.
Dan Gohman41f14cf2010-09-14 21:25:10 +0000922 if (const GlobalValue *GV =
Mehdi Aminia28d91d2015-03-10 02:37:25 +0000923 dyn_cast<GlobalValue>(GetUnderlyingObject(Loc.Ptr, DL)))
Rafael Espindola6de96a12009-01-15 20:18:42 +0000924 if (GV->hasLocalLinkage())
Chandler Carruth363ac682019-01-07 05:42:51 +0000925 if (const Function *F = Call->getCalledFunction())
Chris Lattner3a353e82004-07-27 06:40:37 +0000926 if (NonAddressTakenGlobals.count(GV))
Chandler Carruth5657b732015-07-22 23:56:31 +0000927 if (const FunctionInfo *FI = getFunctionInfo(F))
Alina Sbirlea63d22502017-12-05 20:12:23 +0000928 Known = unionModRef(FI->getModRefInfoForGlobal(*GV),
Chandler Carruth363ac682019-01-07 05:42:51 +0000929 getModRefInfoForArgument(Call, GV));
Chris Lattner26dff502004-06-28 06:33:13 +0000930
Alina Sbirlea63d22502017-12-05 20:12:23 +0000931 if (!isModOrRefSet(Known))
Alina Sbirlea193429f2017-12-07 22:41:34 +0000932 return ModRefInfo::NoModRef; // No need to query other mod/ref analyses
Chandler Carruth363ac682019-01-07 05:42:51 +0000933 return intersectModRef(Known, AAResultBase::getModRefInfo(Call, Loc));
Chandler Carruth7b560d42015-09-09 17:55:00 +0000934}
935
936GlobalsAAResult::GlobalsAAResult(const DataLayout &DL,
937 const TargetLibraryInfo &TLI)
Chandler Carruth12884f72016-03-02 15:56:53 +0000938 : AAResultBase(), DL(DL), TLI(TLI) {}
Chandler Carruth7b560d42015-09-09 17:55:00 +0000939
940GlobalsAAResult::GlobalsAAResult(GlobalsAAResult &&Arg)
Chandler Carruth12884f72016-03-02 15:56:53 +0000941 : AAResultBase(std::move(Arg)), DL(Arg.DL), TLI(Arg.TLI),
NAKAMURA Takumi1a296ec2015-09-10 07:16:42 +0000942 NonAddressTakenGlobals(std::move(Arg.NonAddressTakenGlobals)),
943 IndirectGlobals(std::move(Arg.IndirectGlobals)),
944 AllocsForIndirectGlobals(std::move(Arg.AllocsForIndirectGlobals)),
945 FunctionInfos(std::move(Arg.FunctionInfos)),
NAKAMURA Takumi98800d92015-09-14 06:16:44 +0000946 Handles(std::move(Arg.Handles)) {
947 // Update the parent for each DeletionCallbackHandle.
948 for (auto &H : Handles) {
949 assert(H.GAR == &Arg);
950 H.GAR = this;
951 }
952}
Chandler Carruth7b560d42015-09-09 17:55:00 +0000953
Chandler Carruth45a9c202016-03-11 09:15:11 +0000954GlobalsAAResult::~GlobalsAAResult() {}
955
Chandler Carruth7b560d42015-09-09 17:55:00 +0000956/*static*/ GlobalsAAResult
957GlobalsAAResult::analyzeModule(Module &M, const TargetLibraryInfo &TLI,
958 CallGraph &CG) {
959 GlobalsAAResult Result(M.getDataLayout(), TLI);
960
James Molloyeb466412015-09-25 15:39:29 +0000961 // Discover which functions aren't recursive, to feed into AnalyzeGlobals.
962 Result.CollectSCCMembership(CG);
963
Chandler Carruth7b560d42015-09-09 17:55:00 +0000964 // Find non-addr taken globals.
965 Result.AnalyzeGlobals(M);
966
967 // Propagate on CG.
968 Result.AnalyzeCallGraph(CG, M);
969
970 return Result;
971}
972
Chandler Carruthdab4eae2016-11-23 17:53:26 +0000973AnalysisKey GlobalsAA::Key;
Chandler Carruthb4faf132016-03-11 10:22:49 +0000974
Sean Silvafd03ac62016-08-09 00:28:38 +0000975GlobalsAAResult GlobalsAA::run(Module &M, ModuleAnalysisManager &AM) {
Chandler Carruth7b560d42015-09-09 17:55:00 +0000976 return GlobalsAAResult::analyzeModule(M,
Chandler Carruthb47f8012016-03-11 11:05:24 +0000977 AM.getResult<TargetLibraryAnalysis>(M),
978 AM.getResult<CallGraphAnalysis>(M));
Chandler Carruth7b560d42015-09-09 17:55:00 +0000979}
980
Chandler Carruth7b560d42015-09-09 17:55:00 +0000981char GlobalsAAWrapperPass::ID = 0;
982INITIALIZE_PASS_BEGIN(GlobalsAAWrapperPass, "globals-aa",
983 "Globals Alias Analysis", false, true)
984INITIALIZE_PASS_DEPENDENCY(CallGraphWrapperPass)
985INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
986INITIALIZE_PASS_END(GlobalsAAWrapperPass, "globals-aa",
987 "Globals Alias Analysis", false, true)
988
989ModulePass *llvm::createGlobalsAAWrapperPass() {
990 return new GlobalsAAWrapperPass();
991}
992
993GlobalsAAWrapperPass::GlobalsAAWrapperPass() : ModulePass(ID) {
994 initializeGlobalsAAWrapperPassPass(*PassRegistry::getPassRegistry());
995}
996
997bool GlobalsAAWrapperPass::runOnModule(Module &M) {
998 Result.reset(new GlobalsAAResult(GlobalsAAResult::analyzeModule(
999 M, getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(),
1000 getAnalysis<CallGraphWrapperPass>().getCallGraph())));
1001 return false;
1002}
1003
1004bool GlobalsAAWrapperPass::doFinalization(Module &M) {
1005 Result.reset();
1006 return false;
1007}
1008
1009void GlobalsAAWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const {
1010 AU.setPreservesAll();
1011 AU.addRequired<CallGraphWrapperPass>();
1012 AU.addRequired<TargetLibraryInfoWrapperPass>();
Chris Lattner26dff502004-06-28 06:33:13 +00001013}