blob: 7da2cf22f408306f908b0be7b5cd32b890878d52 [file] [log] [blame]
George Burgess IVbfa401e2016-07-06 00:26:41 +00001//- CFLSteensAliasAnalysis.cpp - Unification-based Alias Analysis ---*- C++-*-//
Hal Finkel7529c552014-09-02 21:43:13 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
George Burgess IVbfa401e2016-07-06 00:26:41 +000010// This file implements a CFL-base, summary-based alias analysis algorithm. It
11// does not depend on types. The algorithm is a mixture of the one described in
12// "Demand-driven alias analysis for C" by Xin Zheng and Radu Rugina, and "Fast
13// algorithms for Dyck-CFL-reachability with applications to Alias Analysis" by
14// Zhang Q, Lyu M R, Yuan H, and Su Z. -- to summarize the papers, we build a
15// graph of the uses of a variable, where each node is a memory location, and
16// each edge is an action that happened on that memory location. The "actions"
17// can be one of Dereference, Reference, or Assign. The precision of this
18// analysis is roughly the same as that of an one level context-sensitive
19// Steensgaard's algorithm.
Hal Finkel7529c552014-09-02 21:43:13 +000020//
21// Two variables are considered as aliasing iff you can reach one value's node
22// from the other value's node and the language formed by concatenating all of
23// the edge labels (actions) conforms to a context-free grammar.
24//
25// Because this algorithm requires a graph search on each query, we execute the
26// algorithm outlined in "Fast algorithms..." (mentioned above)
27// in order to transform the graph into sets of variables that may alias in
George Burgess IV77351ba32016-01-28 00:54:01 +000028// ~nlogn time (n = number of variables), which makes queries take constant
Hal Finkel7529c552014-09-02 21:43:13 +000029// time.
30//===----------------------------------------------------------------------===//
31
George Burgess IV77351ba32016-01-28 00:54:01 +000032// N.B. AliasAnalysis as a whole is phrased as a FunctionPass at the moment, and
George Burgess IVbfa401e2016-07-06 00:26:41 +000033// CFLSteensAA is interprocedural. This is *technically* A Bad Thing, because
George Burgess IV77351ba32016-01-28 00:54:01 +000034// FunctionPasses are only allowed to inspect the Function that they're being
35// run on. Realistically, this likely isn't a problem until we allow
36// FunctionPasses to run concurrently.
37
George Burgess IVbfa401e2016-07-06 00:26:41 +000038#include "llvm/Analysis/CFLSteensAliasAnalysis.h"
Hal Finkel7529c552014-09-02 21:43:13 +000039#include "StratifiedSets.h"
Hal Finkel7529c552014-09-02 21:43:13 +000040#include "llvm/ADT/DenseMap.h"
Hal Finkel7529c552014-09-02 21:43:13 +000041#include "llvm/ADT/None.h"
Chandler Carruthd9903882015-01-14 11:23:27 +000042#include "llvm/ADT/Optional.h"
George Burgess IV18b83fe2016-06-01 18:39:54 +000043#include "llvm/Analysis/MemoryBuiltins.h"
44#include "llvm/Analysis/TargetLibraryInfo.h"
Hal Finkel7529c552014-09-02 21:43:13 +000045#include "llvm/IR/Constants.h"
46#include "llvm/IR/Function.h"
Hal Finkel7529c552014-09-02 21:43:13 +000047#include "llvm/IR/InstVisitor.h"
Chandler Carruthd9903882015-01-14 11:23:27 +000048#include "llvm/IR/Instructions.h"
Hal Finkel7529c552014-09-02 21:43:13 +000049#include "llvm/Pass.h"
Hal Finkel7d7087c2014-09-02 22:13:00 +000050#include "llvm/Support/Compiler.h"
George Burgess IV33305e72015-02-12 03:07:07 +000051#include "llvm/Support/Debug.h"
Hal Finkel7529c552014-09-02 21:43:13 +000052#include "llvm/Support/ErrorHandling.h"
Benjamin Kramer799003b2015-03-23 19:32:43 +000053#include "llvm/Support/raw_ostream.h"
Hal Finkel7529c552014-09-02 21:43:13 +000054#include <algorithm>
55#include <cassert>
Benjamin Kramer799003b2015-03-23 19:32:43 +000056#include <memory>
Hal Finkel7529c552014-09-02 21:43:13 +000057#include <tuple>
58
59using namespace llvm;
60
George Burgess IVbfa401e2016-07-06 00:26:41 +000061#define DEBUG_TYPE "cfl-steens-aa"
George Burgess IV33305e72015-02-12 03:07:07 +000062
George Burgess IVbfa401e2016-07-06 00:26:41 +000063CFLSteensAAResult::CFLSteensAAResult(const TargetLibraryInfo &TLI)
George Burgess IV18b83fe2016-06-01 18:39:54 +000064 : AAResultBase(), TLI(TLI) {}
George Burgess IVbfa401e2016-07-06 00:26:41 +000065CFLSteensAAResult::CFLSteensAAResult(CFLSteensAAResult &&Arg)
George Burgess IV18b83fe2016-06-01 18:39:54 +000066 : AAResultBase(std::move(Arg)), TLI(Arg.TLI) {}
George Burgess IVbfa401e2016-07-06 00:26:41 +000067CFLSteensAAResult::~CFLSteensAAResult() {}
Chandler Carruth8b046a42015-08-14 02:42:20 +000068
George Burgess IV1f99da52016-06-23 18:55:23 +000069/// We use InterfaceValue to describe parameters/return value, as well as
70/// potential memory locations that are pointed to by parameters/return value,
71/// of a function.
72/// Index is an integer which represents a single parameter or a return value.
73/// When the index is 0, it refers to the return value. Non-zero index i refers
74/// to the i-th parameter.
75/// DerefLevel indicates the number of dereferences one must perform on the
76/// parameter/return value to get this InterfaceValue.
77struct InterfaceValue {
78 unsigned Index;
79 unsigned DerefLevel;
80};
81
82bool operator==(InterfaceValue lhs, InterfaceValue rhs) {
83 return lhs.Index == rhs.Index && lhs.DerefLevel == rhs.DerefLevel;
84}
85bool operator!=(InterfaceValue lhs, InterfaceValue rhs) {
86 return !(lhs == rhs);
87}
88
89/// We use ExternalRelation to describe an externally visible aliasing relations
George Burgess IV87b2e412016-06-20 23:10:56 +000090/// between parameters/return value of a function.
George Burgess IV87b2e412016-06-20 23:10:56 +000091struct ExternalRelation {
George Burgess IV1f99da52016-06-23 18:55:23 +000092 InterfaceValue From, To;
George Burgess IV87b2e412016-06-20 23:10:56 +000093};
Chandler Carruth8b046a42015-08-14 02:42:20 +000094
George Burgess IVa3d62be2016-06-24 01:00:03 +000095/// We use ExternalAttribute to describe an externally visible StratifiedAttrs
96/// for parameters/return value.
97struct ExternalAttribute {
98 InterfaceValue IValue;
99 StratifiedAttrs Attr;
100};
101
George Burgess IV87b2e412016-06-20 23:10:56 +0000102/// Information we have about a function and would like to keep around.
George Burgess IVbfa401e2016-07-06 00:26:41 +0000103class CFLSteensAAResult::FunctionInfo {
George Burgess IV87b2e412016-06-20 23:10:56 +0000104 StratifiedSets<Value *> Sets;
105
106 // RetParamRelations is a collection of ExternalRelations.
107 SmallVector<ExternalRelation, 8> RetParamRelations;
108
George Burgess IVa3d62be2016-06-24 01:00:03 +0000109 // RetParamAttributes is a collection of ExternalAttributes.
110 SmallVector<ExternalAttribute, 8> RetParamAttributes;
111
George Burgess IV87b2e412016-06-20 23:10:56 +0000112public:
113 FunctionInfo(Function &Fn, const SmallVectorImpl<Value *> &RetVals,
114 StratifiedSets<Value *> S);
115
116 const StratifiedSets<Value *> &getStratifiedSets() const { return Sets; }
117 const SmallVectorImpl<ExternalRelation> &getRetParamRelations() const {
118 return RetParamRelations;
119 }
George Burgess IVa3d62be2016-06-24 01:00:03 +0000120 const SmallVectorImpl<ExternalAttribute> &getRetParamAttributes() const {
121 return RetParamAttributes;
122 }
Chandler Carruth8b046a42015-08-14 02:42:20 +0000123};
124
George Burgess IVcae581d2016-04-13 23:27:37 +0000125/// Try to go from a Value* to a Function*. Never returns nullptr.
Hal Finkel7529c552014-09-02 21:43:13 +0000126static Optional<Function *> parentFunctionOfValue(Value *);
127
George Burgess IVcae581d2016-04-13 23:27:37 +0000128/// Returns possible functions called by the Inst* into the given
129/// SmallVectorImpl. Returns true if targets found, false otherwise. This is
130/// templated so we can use it with CallInsts and InvokeInsts.
George Burgess IV24eb0da2016-06-14 18:12:28 +0000131static bool getPossibleTargets(CallSite, SmallVectorImpl<Function *> &);
Hal Finkel7529c552014-09-02 21:43:13 +0000132
Hal Finkel1ae325f2014-09-02 23:50:01 +0000133const StratifiedIndex StratifiedLink::SetSentinel =
George Burgess IV11d509d2015-03-15 00:52:21 +0000134 std::numeric_limits<StratifiedIndex>::max();
Hal Finkel1ae325f2014-09-02 23:50:01 +0000135
Hal Finkel7529c552014-09-02 21:43:13 +0000136namespace {
George Burgess IVcae581d2016-04-13 23:27:37 +0000137/// StratifiedInfo Attribute things.
Hal Finkel7d7087c2014-09-02 22:13:00 +0000138LLVM_CONSTEXPR unsigned MaxStratifiedAttrIndex = NumStratifiedAttrs;
George Burgess IVa1f9a2d2016-06-07 18:35:37 +0000139LLVM_CONSTEXPR unsigned AttrEscapedIndex = 0;
140LLVM_CONSTEXPR unsigned AttrUnknownIndex = 1;
141LLVM_CONSTEXPR unsigned AttrGlobalIndex = 2;
George Burgess IVa3d62be2016-06-24 01:00:03 +0000142LLVM_CONSTEXPR unsigned AttrCallerIndex = 3;
143LLVM_CONSTEXPR unsigned AttrFirstArgIndex = 4;
Hal Finkel7d7087c2014-09-02 22:13:00 +0000144LLVM_CONSTEXPR unsigned AttrLastArgIndex = MaxStratifiedAttrIndex;
145LLVM_CONSTEXPR unsigned AttrMaxNumArgs = AttrLastArgIndex - AttrFirstArgIndex;
Hal Finkel7529c552014-09-02 21:43:13 +0000146
George Burgess IVd9c39fc2016-06-24 01:41:29 +0000147// NOTE: These aren't StratifiedAttrs because bitsets don't have a constexpr
148// ctor for some versions of MSVC that we support. We could maybe refactor,
149// but...
150using StratifiedAttr = unsigned;
151LLVM_CONSTEXPR StratifiedAttr AttrNone = 0;
152LLVM_CONSTEXPR StratifiedAttr AttrEscaped = 1 << AttrEscapedIndex;
153LLVM_CONSTEXPR StratifiedAttr AttrUnknown = 1 << AttrUnknownIndex;
154LLVM_CONSTEXPR StratifiedAttr AttrGlobal = 1 << AttrGlobalIndex;
155LLVM_CONSTEXPR StratifiedAttr AttrCaller = 1 << AttrCallerIndex;
156LLVM_CONSTEXPR StratifiedAttr ExternalAttrMask =
157 AttrEscaped | AttrUnknown | AttrGlobal;
Hal Finkel7529c552014-09-02 21:43:13 +0000158
George Burgess IV87b2e412016-06-20 23:10:56 +0000159/// The maximum number of arguments we can put into a summary.
160LLVM_CONSTEXPR unsigned MaxSupportedArgsInSummary = 50;
161
George Burgess IVcae581d2016-04-13 23:27:37 +0000162/// StratifiedSets call for knowledge of "direction", so this is how we
163/// represent that locally.
Hal Finkel7529c552014-09-02 21:43:13 +0000164enum class Level { Same, Above, Below };
165
George Burgess IVcae581d2016-04-13 23:27:37 +0000166/// Edges can be one of four "weights" -- each weight must have an inverse
167/// weight (Assign has Assign; Reference has Dereference).
Hal Finkel7529c552014-09-02 21:43:13 +0000168enum class EdgeType {
George Burgess IVcae581d2016-04-13 23:27:37 +0000169 /// The weight assigned when assigning from or to a value. For example, in:
170 /// %b = getelementptr %a, 0
171 /// ...The relationships are %b assign %a, and %a assign %b. This used to be
172 /// two edges, but having a distinction bought us nothing.
Hal Finkel7529c552014-09-02 21:43:13 +0000173 Assign,
174
George Burgess IVcae581d2016-04-13 23:27:37 +0000175 /// The edge used when we have an edge going from some handle to a Value.
176 /// Examples of this include:
177 /// %b = load %a (%b Dereference %a)
178 /// %b = extractelement %a, 0 (%a Dereference %b)
Hal Finkel7529c552014-09-02 21:43:13 +0000179 Dereference,
180
George Burgess IVcae581d2016-04-13 23:27:37 +0000181 /// The edge used when our edge goes from a value to a handle that may have
182 /// contained it at some point. Examples:
183 /// %b = load %a (%a Reference %b)
184 /// %b = extractelement %a, 0 (%b Reference %a)
Hal Finkel7529c552014-09-02 21:43:13 +0000185 Reference
186};
187
George Burgess IV24eb0da2016-06-14 18:12:28 +0000188/// The Program Expression Graph (PEG) of CFL analysis
189class CFLGraph {
190 typedef Value *Node;
Hal Finkel7529c552014-09-02 21:43:13 +0000191
George Burgess IV24eb0da2016-06-14 18:12:28 +0000192 struct Edge {
George Burgess IV24eb0da2016-06-14 18:12:28 +0000193 EdgeType Type;
194 Node Other;
195 };
Hal Finkel7529c552014-09-02 21:43:13 +0000196
George Burgess IV24eb0da2016-06-14 18:12:28 +0000197 typedef std::vector<Edge> EdgeList;
George Burgess IV259d9012016-06-15 20:43:41 +0000198
199 struct NodeInfo {
200 EdgeList Edges;
201 StratifiedAttrs Attr;
202 };
203
204 typedef DenseMap<Node, NodeInfo> NodeMap;
George Burgess IV24eb0da2016-06-14 18:12:28 +0000205 NodeMap NodeImpls;
Hal Finkel7529c552014-09-02 21:43:13 +0000206
George Burgess IV24eb0da2016-06-14 18:12:28 +0000207 // Gets the inverse of a given EdgeType.
208 static EdgeType flipWeight(EdgeType Initial) {
209 switch (Initial) {
210 case EdgeType::Assign:
211 return EdgeType::Assign;
212 case EdgeType::Dereference:
213 return EdgeType::Reference;
214 case EdgeType::Reference:
215 return EdgeType::Dereference;
216 }
217 llvm_unreachable("Incomplete coverage of EdgeType enum");
218 }
Hal Finkel7529c552014-09-02 21:43:13 +0000219
George Burgess IV259d9012016-06-15 20:43:41 +0000220 const NodeInfo *getNode(Node N) const {
George Burgess IV24eb0da2016-06-14 18:12:28 +0000221 auto Itr = NodeImpls.find(N);
222 if (Itr == NodeImpls.end())
223 return nullptr;
224 return &Itr->second;
225 }
George Burgess IV259d9012016-06-15 20:43:41 +0000226 NodeInfo *getNode(Node N) {
George Burgess IV24eb0da2016-06-14 18:12:28 +0000227 auto Itr = NodeImpls.find(N);
228 if (Itr == NodeImpls.end())
229 return nullptr;
230 return &Itr->second;
231 }
232
233 static Node nodeDeref(const NodeMap::value_type &P) { return P.first; }
234 typedef std::pointer_to_unary_function<const NodeMap::value_type &, Node>
235 NodeDerefFun;
236
237public:
238 typedef EdgeList::const_iterator const_edge_iterator;
239 typedef mapped_iterator<NodeMap::const_iterator, NodeDerefFun>
240 const_node_iterator;
241
242 bool addNode(Node N) {
George Burgess IV259d9012016-06-15 20:43:41 +0000243 return NodeImpls.insert(std::make_pair(N, NodeInfo{EdgeList(), AttrNone}))
244 .second;
George Burgess IV24eb0da2016-06-14 18:12:28 +0000245 }
246
George Burgess IV259d9012016-06-15 20:43:41 +0000247 void addAttr(Node N, StratifiedAttrs Attr) {
248 auto *Info = getNode(N);
249 assert(Info != nullptr);
250 Info->Attr |= Attr;
251 }
George Burgess IV24eb0da2016-06-14 18:12:28 +0000252
George Burgess IV259d9012016-06-15 20:43:41 +0000253 void addEdge(Node From, Node To, EdgeType Type) {
254 auto *FromInfo = getNode(From);
255 assert(FromInfo != nullptr);
256 auto *ToInfo = getNode(To);
257 assert(ToInfo != nullptr);
258
259 FromInfo->Edges.push_back(Edge{Type, To});
260 ToInfo->Edges.push_back(Edge{flipWeight(Type), From});
261 }
262
263 StratifiedAttrs attrFor(Node N) const {
264 auto *Info = getNode(N);
265 assert(Info != nullptr);
266 return Info->Attr;
George Burgess IV24eb0da2016-06-14 18:12:28 +0000267 }
268
269 iterator_range<const_edge_iterator> edgesFor(Node N) const {
George Burgess IV259d9012016-06-15 20:43:41 +0000270 auto *Info = getNode(N);
271 assert(Info != nullptr);
272 auto &Edges = Info->Edges;
273 return make_range(Edges.begin(), Edges.end());
George Burgess IV24eb0da2016-06-14 18:12:28 +0000274 }
275
276 iterator_range<const_node_iterator> nodes() const {
277 return make_range<const_node_iterator>(
278 map_iterator(NodeImpls.begin(), NodeDerefFun(nodeDeref)),
279 map_iterator(NodeImpls.end(), NodeDerefFun(nodeDeref)));
280 }
281
282 bool empty() const { return NodeImpls.empty(); }
283 std::size_t size() const { return NodeImpls.size(); }
Hal Finkel7529c552014-09-02 21:43:13 +0000284};
285
George Burgess IVa3d62be2016-06-24 01:00:03 +0000286// This is the result of instantiating InterfaceValue at a particular callsite
287struct InterprocNode {
288 Value *Val;
289 unsigned DerefLevel;
290};
291
George Burgess IV1f99da52016-06-23 18:55:23 +0000292// Interprocedural assignment edges that CFLGraph may not easily model
293struct InterprocEdge {
George Burgess IVa3d62be2016-06-24 01:00:03 +0000294 InterprocNode From, To;
295};
George Burgess IV1f99da52016-06-23 18:55:23 +0000296
George Burgess IVa3d62be2016-06-24 01:00:03 +0000297// Interprocedural attribute tagging that CFLGraph may not easily model
298struct InterprocAttr {
299 InterprocNode Node;
300 StratifiedAttrs Attr;
George Burgess IV1f99da52016-06-23 18:55:23 +0000301};
302
George Burgess IVcae581d2016-04-13 23:27:37 +0000303/// Gets the edges our graph should have, based on an Instruction*
Hal Finkel7529c552014-09-02 21:43:13 +0000304class GetEdgesVisitor : public InstVisitor<GetEdgesVisitor, void> {
George Burgess IVbfa401e2016-07-06 00:26:41 +0000305 CFLSteensAAResult &AA;
George Burgess IV18b83fe2016-06-01 18:39:54 +0000306 const TargetLibraryInfo &TLI;
Hal Finkel7529c552014-09-02 21:43:13 +0000307
George Burgess IV24eb0da2016-06-14 18:12:28 +0000308 CFLGraph &Graph;
George Burgess IVa3d62be2016-06-24 01:00:03 +0000309 SmallVectorImpl<Value *> &ReturnValues;
George Burgess IV24eb0da2016-06-14 18:12:28 +0000310 SmallPtrSetImpl<Value *> &Externals;
311 SmallPtrSetImpl<Value *> &Escapes;
George Burgess IV1f99da52016-06-23 18:55:23 +0000312 SmallVectorImpl<InterprocEdge> &InterprocEdges;
George Burgess IVa3d62be2016-06-24 01:00:03 +0000313 SmallVectorImpl<InterprocAttr> &InterprocAttrs;
George Burgess IV24eb0da2016-06-14 18:12:28 +0000314
315 static bool hasUsefulEdges(ConstantExpr *CE) {
316 // ConstantExpr doesn't have terminators, invokes, or fences, so only needs
317 // to check for compares.
318 return CE->getOpcode() != Instruction::ICmp &&
319 CE->getOpcode() != Instruction::FCmp;
320 }
321
322 void addNode(Value *Val) {
323 if (!Graph.addNode(Val))
324 return;
325
326 if (isa<GlobalValue>(Val))
327 Externals.insert(Val);
328 else if (auto CExpr = dyn_cast<ConstantExpr>(Val))
329 if (hasUsefulEdges(CExpr))
330 visitConstantExpr(CExpr);
331 }
332
George Burgess IV259d9012016-06-15 20:43:41 +0000333 void addNodeWithAttr(Value *Val, StratifiedAttrs Attr) {
334 addNode(Val);
335 Graph.addAttr(Val, Attr);
336 }
337
338 void addEdge(Value *From, Value *To, EdgeType Type) {
339 if (!From->getType()->isPointerTy() || !To->getType()->isPointerTy())
340 return;
George Burgess IV24eb0da2016-06-14 18:12:28 +0000341 addNode(From);
342 if (To != From)
343 addNode(To);
George Burgess IV259d9012016-06-15 20:43:41 +0000344 Graph.addEdge(From, To, Type);
George Burgess IV24eb0da2016-06-14 18:12:28 +0000345 }
346
Hal Finkel7529c552014-09-02 21:43:13 +0000347public:
George Burgess IVbfa401e2016-07-06 00:26:41 +0000348 GetEdgesVisitor(CFLSteensAAResult &AA, const TargetLibraryInfo &TLI,
George Burgess IVa3d62be2016-06-24 01:00:03 +0000349 CFLGraph &Graph, SmallVectorImpl<Value *> &ReturnValues,
350 SmallPtrSetImpl<Value *> &Externals,
George Burgess IV1f99da52016-06-23 18:55:23 +0000351 SmallPtrSetImpl<Value *> &Escapes,
George Burgess IVa3d62be2016-06-24 01:00:03 +0000352 SmallVectorImpl<InterprocEdge> &InterprocEdges,
353 SmallVectorImpl<InterprocAttr> &InterprocAttrs)
354 : AA(AA), TLI(TLI), Graph(Graph), ReturnValues(ReturnValues),
355 Externals(Externals), Escapes(Escapes), InterprocEdges(InterprocEdges),
356 InterprocAttrs(InterprocAttrs) {}
Hal Finkel7529c552014-09-02 21:43:13 +0000357
358 void visitInstruction(Instruction &) {
359 llvm_unreachable("Unsupported instruction encountered");
360 }
361
George Burgess IVa3d62be2016-06-24 01:00:03 +0000362 void visitReturnInst(ReturnInst &Inst) {
363 if (auto RetVal = Inst.getReturnValue()) {
364 if (RetVal->getType()->isPointerTy()) {
365 addNode(RetVal);
366 ReturnValues.push_back(RetVal);
367 }
368 }
369 }
370
George Burgess IVb54a8d622015-03-10 02:40:06 +0000371 void visitPtrToIntInst(PtrToIntInst &Inst) {
372 auto *Ptr = Inst.getOperand(0);
George Burgess IV259d9012016-06-15 20:43:41 +0000373 addNodeWithAttr(Ptr, AttrEscaped);
George Burgess IVb54a8d622015-03-10 02:40:06 +0000374 }
375
376 void visitIntToPtrInst(IntToPtrInst &Inst) {
377 auto *Ptr = &Inst;
George Burgess IV259d9012016-06-15 20:43:41 +0000378 addNodeWithAttr(Ptr, AttrUnknown);
George Burgess IVb54a8d622015-03-10 02:40:06 +0000379 }
380
Hal Finkel7529c552014-09-02 21:43:13 +0000381 void visitCastInst(CastInst &Inst) {
George Burgess IV24eb0da2016-06-14 18:12:28 +0000382 auto *Src = Inst.getOperand(0);
George Burgess IV259d9012016-06-15 20:43:41 +0000383 addEdge(Src, &Inst, EdgeType::Assign);
Hal Finkel7529c552014-09-02 21:43:13 +0000384 }
385
386 void visitBinaryOperator(BinaryOperator &Inst) {
387 auto *Op1 = Inst.getOperand(0);
388 auto *Op2 = Inst.getOperand(1);
George Burgess IV259d9012016-06-15 20:43:41 +0000389 addEdge(Op1, &Inst, EdgeType::Assign);
390 addEdge(Op2, &Inst, EdgeType::Assign);
Hal Finkel7529c552014-09-02 21:43:13 +0000391 }
392
393 void visitAtomicCmpXchgInst(AtomicCmpXchgInst &Inst) {
394 auto *Ptr = Inst.getPointerOperand();
395 auto *Val = Inst.getNewValOperand();
George Burgess IV259d9012016-06-15 20:43:41 +0000396 addEdge(Ptr, Val, EdgeType::Dereference);
Hal Finkel7529c552014-09-02 21:43:13 +0000397 }
398
399 void visitAtomicRMWInst(AtomicRMWInst &Inst) {
400 auto *Ptr = Inst.getPointerOperand();
401 auto *Val = Inst.getValOperand();
George Burgess IV259d9012016-06-15 20:43:41 +0000402 addEdge(Ptr, Val, EdgeType::Dereference);
Hal Finkel7529c552014-09-02 21:43:13 +0000403 }
404
405 void visitPHINode(PHINode &Inst) {
George Burgess IV77351ba32016-01-28 00:54:01 +0000406 for (Value *Val : Inst.incoming_values())
George Burgess IV259d9012016-06-15 20:43:41 +0000407 addEdge(Val, &Inst, EdgeType::Assign);
Hal Finkel7529c552014-09-02 21:43:13 +0000408 }
409
410 void visitGetElementPtrInst(GetElementPtrInst &Inst) {
411 auto *Op = Inst.getPointerOperand();
George Burgess IV259d9012016-06-15 20:43:41 +0000412 addEdge(Op, &Inst, EdgeType::Assign);
Hal Finkel7529c552014-09-02 21:43:13 +0000413 }
414
415 void visitSelectInst(SelectInst &Inst) {
Daniel Berlin16f7a522015-01-26 17:31:17 +0000416 // Condition is not processed here (The actual statement producing
417 // the condition result is processed elsewhere). For select, the
418 // condition is evaluated, but not loaded, stored, or assigned
419 // simply as a result of being the condition of a select.
420
Hal Finkel7529c552014-09-02 21:43:13 +0000421 auto *TrueVal = Inst.getTrueValue();
Hal Finkel7529c552014-09-02 21:43:13 +0000422 auto *FalseVal = Inst.getFalseValue();
George Burgess IV259d9012016-06-15 20:43:41 +0000423 addEdge(TrueVal, &Inst, EdgeType::Assign);
424 addEdge(FalseVal, &Inst, EdgeType::Assign);
Hal Finkel7529c552014-09-02 21:43:13 +0000425 }
426
George Burgess IV24eb0da2016-06-14 18:12:28 +0000427 void visitAllocaInst(AllocaInst &Inst) { Graph.addNode(&Inst); }
Hal Finkel7529c552014-09-02 21:43:13 +0000428
429 void visitLoadInst(LoadInst &Inst) {
430 auto *Ptr = Inst.getPointerOperand();
431 auto *Val = &Inst;
George Burgess IV259d9012016-06-15 20:43:41 +0000432 addEdge(Val, Ptr, EdgeType::Reference);
Hal Finkel7529c552014-09-02 21:43:13 +0000433 }
434
435 void visitStoreInst(StoreInst &Inst) {
436 auto *Ptr = Inst.getPointerOperand();
437 auto *Val = Inst.getValueOperand();
George Burgess IV259d9012016-06-15 20:43:41 +0000438 addEdge(Ptr, Val, EdgeType::Dereference);
Hal Finkel7529c552014-09-02 21:43:13 +0000439 }
440
Hal Finkeldb5f86a2014-10-14 20:51:26 +0000441 void visitVAArgInst(VAArgInst &Inst) {
442 // We can't fully model va_arg here. For *Ptr = Inst.getOperand(0), it does
443 // two things:
444 // 1. Loads a value from *((T*)*Ptr).
445 // 2. Increments (stores to) *Ptr by some target-specific amount.
446 // For now, we'll handle this like a landingpad instruction (by placing the
447 // result in its own group, and having that group alias externals).
George Burgess IV259d9012016-06-15 20:43:41 +0000448 addNodeWithAttr(&Inst, AttrUnknown);
Hal Finkeldb5f86a2014-10-14 20:51:26 +0000449 }
450
Hal Finkel7529c552014-09-02 21:43:13 +0000451 static bool isFunctionExternal(Function *Fn) {
George Burgess IV9fdbfe12016-06-21 01:42:47 +0000452 return !Fn->hasExactDefinition();
Hal Finkel7529c552014-09-02 21:43:13 +0000453 }
454
George Burgess IV87b2e412016-06-20 23:10:56 +0000455 bool tryInterproceduralAnalysis(CallSite CS,
456 const SmallVectorImpl<Function *> &Fns) {
Hal Finkel7529c552014-09-02 21:43:13 +0000457 assert(Fns.size() > 0);
458
George Burgess IV87b2e412016-06-20 23:10:56 +0000459 if (CS.arg_size() > MaxSupportedArgsInSummary)
Hal Finkel7529c552014-09-02 21:43:13 +0000460 return false;
461
462 // Exit early if we'll fail anyway
463 for (auto *Fn : Fns) {
464 if (isFunctionExternal(Fn) || Fn->isVarArg())
465 return false;
George Burgess IV87b2e412016-06-20 23:10:56 +0000466 // Fail if the caller does not provide enough arguments
467 assert(Fn->arg_size() <= CS.arg_size());
Hal Finkel7529c552014-09-02 21:43:13 +0000468 auto &MaybeInfo = AA.ensureCached(Fn);
469 if (!MaybeInfo.hasValue())
470 return false;
471 }
472
George Burgess IVa3d62be2016-06-24 01:00:03 +0000473 auto InstantiateInterfaceIndex = [&CS](unsigned Index) {
474 auto Value =
475 (Index == 0) ? CS.getInstruction() : CS.getArgument(Index - 1);
476 return Value->getType()->isPointerTy() ? Value : nullptr;
477 };
478
Hal Finkel7529c552014-09-02 21:43:13 +0000479 for (auto *Fn : Fns) {
George Burgess IV87b2e412016-06-20 23:10:56 +0000480 auto &FnInfo = AA.ensureCached(Fn);
481 assert(FnInfo.hasValue());
Hal Finkel7529c552014-09-02 21:43:13 +0000482
George Burgess IV87b2e412016-06-20 23:10:56 +0000483 auto &RetParamRelations = FnInfo->getRetParamRelations();
484 for (auto &Relation : RetParamRelations) {
George Burgess IVa3d62be2016-06-24 01:00:03 +0000485 auto FromVal = InstantiateInterfaceIndex(Relation.From.Index);
486 auto ToVal = InstantiateInterfaceIndex(Relation.To.Index);
487 if (FromVal && ToVal) {
George Burgess IV1f99da52016-06-23 18:55:23 +0000488 auto FromLevel = Relation.From.DerefLevel;
489 auto ToLevel = Relation.To.DerefLevel;
490 InterprocEdges.push_back(
George Burgess IVa3d62be2016-06-24 01:00:03 +0000491 InterprocEdge{InterprocNode{FromVal, FromLevel},
492 InterprocNode{ToVal, ToLevel}});
493 }
494 }
495
496 auto &RetParamAttributes = FnInfo->getRetParamAttributes();
497 for (auto &Attribute : RetParamAttributes) {
498 if (auto Val = InstantiateInterfaceIndex(Attribute.IValue.Index)) {
499 InterprocAttrs.push_back(InterprocAttr{
500 InterprocNode{Val, Attribute.IValue.DerefLevel}, Attribute.Attr});
George Burgess IV1f99da52016-06-23 18:55:23 +0000501 }
Hal Finkel7529c552014-09-02 21:43:13 +0000502 }
George Burgess IV259d9012016-06-15 20:43:41 +0000503 }
George Burgess IV24eb0da2016-06-14 18:12:28 +0000504
Hal Finkel7529c552014-09-02 21:43:13 +0000505 return true;
506 }
507
George Burgess IV24eb0da2016-06-14 18:12:28 +0000508 void visitCallSite(CallSite CS) {
509 auto Inst = CS.getInstruction();
510
511 // Make sure all arguments and return value are added to the graph first
512 for (Value *V : CS.args())
513 addNode(V);
George Burgess IV87b2e412016-06-20 23:10:56 +0000514 if (Inst->getType()->isPointerTy())
George Burgess IV24eb0da2016-06-14 18:12:28 +0000515 addNode(Inst);
516
George Burgess IV18b83fe2016-06-01 18:39:54 +0000517 // Check if Inst is a call to a library function that allocates/deallocates
518 // on the heap. Those kinds of functions do not introduce any aliases.
519 // TODO: address other common library functions such as realloc(), strdup(),
520 // etc.
George Burgess IV24eb0da2016-06-14 18:12:28 +0000521 if (isMallocLikeFn(Inst, &TLI) || isCallocLikeFn(Inst, &TLI) ||
522 isFreeCall(Inst, &TLI))
George Burgess IV18b83fe2016-06-01 18:39:54 +0000523 return;
George Burgess IV18b83fe2016-06-01 18:39:54 +0000524
George Burgess IV68b36e02015-08-28 00:16:18 +0000525 // TODO: Add support for noalias args/all the other fun function attributes
526 // that we can tack on.
Hal Finkel7529c552014-09-02 21:43:13 +0000527 SmallVector<Function *, 4> Targets;
George Burgess IV24eb0da2016-06-14 18:12:28 +0000528 if (getPossibleTargets(CS, Targets))
George Burgess IV87b2e412016-06-20 23:10:56 +0000529 if (tryInterproceduralAnalysis(CS, Targets))
Hal Finkel7529c552014-09-02 21:43:13 +0000530 return;
Hal Finkel7529c552014-09-02 21:43:13 +0000531
George Burgess IV68b36e02015-08-28 00:16:18 +0000532 // Because the function is opaque, we need to note that anything
George Burgess IV24eb0da2016-06-14 18:12:28 +0000533 // could have happened to the arguments (unless the function is marked
534 // readonly or readnone), and that the result could alias just about
535 // anything, too (unless the result is marked noalias).
536 if (!CS.onlyReadsMemory())
537 for (Value *V : CS.args()) {
George Burgess IV259d9012016-06-15 20:43:41 +0000538 if (V->getType()->isPointerTy())
539 Escapes.insert(V);
George Burgess IV24eb0da2016-06-14 18:12:28 +0000540 }
541
George Burgess IV87b2e412016-06-20 23:10:56 +0000542 if (Inst->getType()->isPointerTy()) {
George Burgess IV24eb0da2016-06-14 18:12:28 +0000543 auto *Fn = CS.getCalledFunction();
544 if (Fn == nullptr || !Fn->doesNotAlias(0))
George Burgess IV259d9012016-06-15 20:43:41 +0000545 Graph.addAttr(Inst, AttrUnknown);
George Burgess IV24eb0da2016-06-14 18:12:28 +0000546 }
Hal Finkel7529c552014-09-02 21:43:13 +0000547 }
548
George Burgess IVcae581d2016-04-13 23:27:37 +0000549 /// Because vectors/aggregates are immutable and unaddressable, there's
550 /// nothing we can do to coax a value out of them, other than calling
551 /// Extract{Element,Value}. We can effectively treat them as pointers to
552 /// arbitrary memory locations we can store in and load from.
Hal Finkel7529c552014-09-02 21:43:13 +0000553 void visitExtractElementInst(ExtractElementInst &Inst) {
554 auto *Ptr = Inst.getVectorOperand();
555 auto *Val = &Inst;
George Burgess IV259d9012016-06-15 20:43:41 +0000556 addEdge(Val, Ptr, EdgeType::Reference);
Hal Finkel7529c552014-09-02 21:43:13 +0000557 }
558
559 void visitInsertElementInst(InsertElementInst &Inst) {
560 auto *Vec = Inst.getOperand(0);
561 auto *Val = Inst.getOperand(1);
George Burgess IV259d9012016-06-15 20:43:41 +0000562 addEdge(Vec, &Inst, EdgeType::Assign);
563 addEdge(&Inst, Val, EdgeType::Dereference);
Hal Finkel7529c552014-09-02 21:43:13 +0000564 }
565
566 void visitLandingPadInst(LandingPadInst &Inst) {
567 // Exceptions come from "nowhere", from our analysis' perspective.
568 // So we place the instruction its own group, noting that said group may
569 // alias externals
George Burgess IV259d9012016-06-15 20:43:41 +0000570 addNodeWithAttr(&Inst, AttrUnknown);
Hal Finkel7529c552014-09-02 21:43:13 +0000571 }
572
573 void visitInsertValueInst(InsertValueInst &Inst) {
574 auto *Agg = Inst.getOperand(0);
575 auto *Val = Inst.getOperand(1);
George Burgess IV259d9012016-06-15 20:43:41 +0000576 addEdge(Agg, &Inst, EdgeType::Assign);
577 addEdge(&Inst, Val, EdgeType::Dereference);
Hal Finkel7529c552014-09-02 21:43:13 +0000578 }
579
580 void visitExtractValueInst(ExtractValueInst &Inst) {
581 auto *Ptr = Inst.getAggregateOperand();
George Burgess IV259d9012016-06-15 20:43:41 +0000582 addEdge(&Inst, Ptr, EdgeType::Reference);
Hal Finkel7529c552014-09-02 21:43:13 +0000583 }
584
585 void visitShuffleVectorInst(ShuffleVectorInst &Inst) {
586 auto *From1 = Inst.getOperand(0);
587 auto *From2 = Inst.getOperand(1);
George Burgess IV259d9012016-06-15 20:43:41 +0000588 addEdge(From1, &Inst, EdgeType::Assign);
589 addEdge(From2, &Inst, EdgeType::Assign);
Hal Finkel7529c552014-09-02 21:43:13 +0000590 }
Pete Cooper36642532015-06-12 16:13:54 +0000591
592 void visitConstantExpr(ConstantExpr *CE) {
593 switch (CE->getOpcode()) {
594 default:
595 llvm_unreachable("Unknown instruction type encountered!");
596// Build the switch statement using the Instruction.def file.
597#define HANDLE_INST(NUM, OPCODE, CLASS) \
598 case Instruction::OPCODE: \
599 visit##OPCODE(*(CLASS *)CE); \
600 break;
601#include "llvm/IR/Instruction.def"
602 }
603 }
Hal Finkel7529c552014-09-02 21:43:13 +0000604};
605
George Burgess IVe17756e2016-06-14 18:02:27 +0000606class CFLGraphBuilder {
607 // Input of the builder
George Burgess IVbfa401e2016-07-06 00:26:41 +0000608 CFLSteensAAResult &Analysis;
George Burgess IVe17756e2016-06-14 18:02:27 +0000609 const TargetLibraryInfo &TLI;
610
611 // Output of the builder
612 CFLGraph Graph;
613 SmallVector<Value *, 4> ReturnedValues;
614
615 // Auxiliary structures used by the builder
George Burgess IV24eb0da2016-06-14 18:12:28 +0000616 SmallPtrSet<Value *, 8> ExternalValues;
617 SmallPtrSet<Value *, 8> EscapedValues;
George Burgess IV1f99da52016-06-23 18:55:23 +0000618 SmallVector<InterprocEdge, 8> InterprocEdges;
George Burgess IVa3d62be2016-06-24 01:00:03 +0000619 SmallVector<InterprocAttr, 8> InterprocAttrs;
George Burgess IVe17756e2016-06-14 18:02:27 +0000620
621 // Helper functions
622
623 // Determines whether or not we an instruction is useless to us (e.g.
624 // FenceInst)
625 static bool hasUsefulEdges(Instruction *Inst) {
George Burgess IVa3d62be2016-06-24 01:00:03 +0000626 bool IsNonInvokeRetTerminator = isa<TerminatorInst>(Inst) &&
627 !isa<InvokeInst>(Inst) &&
628 !isa<ReturnInst>(Inst);
George Burgess IVe17756e2016-06-14 18:02:27 +0000629 return !isa<CmpInst>(Inst) && !isa<FenceInst>(Inst) &&
George Burgess IVa3d62be2016-06-24 01:00:03 +0000630 !IsNonInvokeRetTerminator;
George Burgess IVe17756e2016-06-14 18:02:27 +0000631 }
632
George Burgess IV24eb0da2016-06-14 18:12:28 +0000633 void addArgumentToGraph(Argument &Arg) {
George Burgess IV259d9012016-06-15 20:43:41 +0000634 if (Arg.getType()->isPointerTy()) {
635 Graph.addNode(&Arg);
636 ExternalValues.insert(&Arg);
637 }
George Burgess IVe17756e2016-06-14 18:02:27 +0000638 }
639
640 // Given an Instruction, this will add it to the graph, along with any
641 // Instructions that are potentially only available from said Instruction
642 // For example, given the following line:
643 // %0 = load i16* getelementptr ([1 x i16]* @a, 0, 0), align 2
644 // addInstructionToGraph would add both the `load` and `getelementptr`
645 // instructions to the graph appropriately.
646 void addInstructionToGraph(Instruction &Inst) {
George Burgess IVe17756e2016-06-14 18:02:27 +0000647 if (!hasUsefulEdges(&Inst))
648 return;
649
George Burgess IVa3d62be2016-06-24 01:00:03 +0000650 GetEdgesVisitor(Analysis, TLI, Graph, ReturnedValues, ExternalValues,
651 EscapedValues, InterprocEdges, InterprocAttrs)
George Burgess IV24eb0da2016-06-14 18:12:28 +0000652 .visit(Inst);
653 }
George Burgess IVe17756e2016-06-14 18:02:27 +0000654
George Burgess IV24eb0da2016-06-14 18:12:28 +0000655 // Builds the graph needed for constructing the StratifiedSets for the given
656 // function
657 void buildGraphFrom(Function &Fn) {
658 for (auto &Bb : Fn.getBasicBlockList())
659 for (auto &Inst : Bb.getInstList())
660 addInstructionToGraph(Inst);
George Burgess IVe17756e2016-06-14 18:02:27 +0000661
George Burgess IV24eb0da2016-06-14 18:12:28 +0000662 for (auto &Arg : Fn.args())
663 addArgumentToGraph(Arg);
George Burgess IVe17756e2016-06-14 18:02:27 +0000664 }
665
666public:
George Burgess IVbfa401e2016-07-06 00:26:41 +0000667 CFLGraphBuilder(CFLSteensAAResult &Analysis, const TargetLibraryInfo &TLI,
George Burgess IVe17756e2016-06-14 18:02:27 +0000668 Function &Fn)
669 : Analysis(Analysis), TLI(TLI) {
670 buildGraphFrom(Fn);
671 }
672
George Burgess IV87b2e412016-06-20 23:10:56 +0000673 const CFLGraph &getCFLGraph() const { return Graph; }
674 const SmallVector<Value *, 4> &getReturnValues() const {
675 return ReturnedValues;
George Burgess IVe17756e2016-06-14 18:02:27 +0000676 }
George Burgess IV87b2e412016-06-20 23:10:56 +0000677 const SmallPtrSet<Value *, 8> &getExternalValues() const {
678 return ExternalValues;
679 }
680 const SmallPtrSet<Value *, 8> &getEscapedValues() const {
681 return EscapedValues;
682 }
George Burgess IV1f99da52016-06-23 18:55:23 +0000683 const SmallVector<InterprocEdge, 8> &getInterprocEdges() const {
684 return InterprocEdges;
685 }
George Burgess IVa3d62be2016-06-24 01:00:03 +0000686 const SmallVector<InterprocAttr, 8> &getInterprocAttrs() const {
687 return InterprocAttrs;
688 }
George Burgess IVe17756e2016-06-14 18:02:27 +0000689};
Alexander Kornienkof00654e2015-06-23 09:49:53 +0000690}
Hal Finkel7529c552014-09-02 21:43:13 +0000691
Hal Finkel7529c552014-09-02 21:43:13 +0000692//===----------------------------------------------------------------------===//
693// Function declarations that require types defined in the namespace above
694//===----------------------------------------------------------------------===//
695
George Burgess IVa1f9a2d2016-06-07 18:35:37 +0000696/// Given a StratifiedAttrs, returns true if it marks the corresponding values
697/// as globals or arguments
698static bool isGlobalOrArgAttr(StratifiedAttrs Attr);
Hal Finkel7529c552014-09-02 21:43:13 +0000699
George Burgess IV652ec4f2016-06-09 23:15:04 +0000700/// Given a StratifiedAttrs, returns true if the corresponding values come from
701/// an unknown source (such as opaque memory or an integer cast)
702static bool isUnknownAttr(StratifiedAttrs Attr);
703
George Burgess IVa1f9a2d2016-06-07 18:35:37 +0000704/// Given an argument number, returns the appropriate StratifiedAttr to set.
George Burgess IVa3d62be2016-06-24 01:00:03 +0000705static StratifiedAttrs argNumberToAttr(unsigned ArgNum);
George Burgess IVa1f9a2d2016-06-07 18:35:37 +0000706
707/// Given a Value, potentially return which StratifiedAttr it maps to.
George Burgess IVa3d62be2016-06-24 01:00:03 +0000708static Optional<StratifiedAttrs> valueToAttr(Value *Val);
Hal Finkel7529c552014-09-02 21:43:13 +0000709
George Burgess IVcae581d2016-04-13 23:27:37 +0000710/// Gets the "Level" that one should travel in StratifiedSets
711/// given an EdgeType.
Hal Finkel7529c552014-09-02 21:43:13 +0000712static Level directionOfEdgeType(EdgeType);
713
George Burgess IVcae581d2016-04-13 23:27:37 +0000714/// Determines whether it would be pointless to add the given Value to our sets.
George Burgess IVab03af22015-03-10 02:58:15 +0000715static bool canSkipAddingToSets(Value *Val);
716
Hal Finkel7529c552014-09-02 21:43:13 +0000717static Optional<Function *> parentFunctionOfValue(Value *Val) {
718 if (auto *Inst = dyn_cast<Instruction>(Val)) {
719 auto *Bb = Inst->getParent();
720 return Bb->getParent();
721 }
722
723 if (auto *Arg = dyn_cast<Argument>(Val))
724 return Arg->getParent();
George Burgess IV77351ba32016-01-28 00:54:01 +0000725 return None;
Hal Finkel7529c552014-09-02 21:43:13 +0000726}
727
George Burgess IV24eb0da2016-06-14 18:12:28 +0000728static bool getPossibleTargets(CallSite CS,
Hal Finkel7529c552014-09-02 21:43:13 +0000729 SmallVectorImpl<Function *> &Output) {
George Burgess IV24eb0da2016-06-14 18:12:28 +0000730 if (auto *Fn = CS.getCalledFunction()) {
Hal Finkel7529c552014-09-02 21:43:13 +0000731 Output.push_back(Fn);
732 return true;
733 }
734
735 // TODO: If the call is indirect, we might be able to enumerate all potential
736 // targets of the call and return them, rather than just failing.
737 return false;
738}
739
George Burgess IVa1f9a2d2016-06-07 18:35:37 +0000740static bool isGlobalOrArgAttr(StratifiedAttrs Attr) {
George Burgess IVa3d62be2016-06-24 01:00:03 +0000741 return Attr.reset(AttrEscapedIndex)
742 .reset(AttrUnknownIndex)
743 .reset(AttrCallerIndex)
744 .any();
George Burgess IVa1f9a2d2016-06-07 18:35:37 +0000745}
746
George Burgess IV652ec4f2016-06-09 23:15:04 +0000747static bool isUnknownAttr(StratifiedAttrs Attr) {
George Burgess IVa3d62be2016-06-24 01:00:03 +0000748 return Attr.test(AttrUnknownIndex) || Attr.test(AttrCallerIndex);
George Burgess IV652ec4f2016-06-09 23:15:04 +0000749}
750
George Burgess IVa3d62be2016-06-24 01:00:03 +0000751static Optional<StratifiedAttrs> valueToAttr(Value *Val) {
Hal Finkel7529c552014-09-02 21:43:13 +0000752 if (isa<GlobalValue>(Val))
George Burgess IVd9c39fc2016-06-24 01:41:29 +0000753 return StratifiedAttrs(AttrGlobal);
Hal Finkel7529c552014-09-02 21:43:13 +0000754
755 if (auto *Arg = dyn_cast<Argument>(Val))
Daniel Berlin16f7a522015-01-26 17:31:17 +0000756 // Only pointer arguments should have the argument attribute,
757 // because things can't escape through scalars without us seeing a
758 // cast, and thus, interaction with them doesn't matter.
759 if (!Arg->hasNoAliasAttr() && Arg->getType()->isPointerTy())
George Burgess IVa1f9a2d2016-06-07 18:35:37 +0000760 return argNumberToAttr(Arg->getArgNo());
George Burgess IV77351ba32016-01-28 00:54:01 +0000761 return None;
Hal Finkel7529c552014-09-02 21:43:13 +0000762}
763
George Burgess IVa3d62be2016-06-24 01:00:03 +0000764static StratifiedAttrs argNumberToAttr(unsigned ArgNum) {
George Burgess IV3c898c22015-01-21 16:37:21 +0000765 if (ArgNum >= AttrMaxNumArgs)
George Burgess IVa1f9a2d2016-06-07 18:35:37 +0000766 return AttrUnknown;
George Burgess IVf10c7fc2016-06-27 22:50:01 +0000767 // N.B. MSVC complains if we use `1U` here, since StratifiedAttrs' ctor takes
768 // an unsigned long long.
769 return StratifiedAttrs(1ULL << (ArgNum + AttrFirstArgIndex));
Hal Finkel7529c552014-09-02 21:43:13 +0000770}
771
Hal Finkel7529c552014-09-02 21:43:13 +0000772static Level directionOfEdgeType(EdgeType Weight) {
773 switch (Weight) {
774 case EdgeType::Reference:
775 return Level::Above;
776 case EdgeType::Dereference:
777 return Level::Below;
778 case EdgeType::Assign:
779 return Level::Same;
780 }
781 llvm_unreachable("Incomplete switch coverage");
782}
783
George Burgess IVab03af22015-03-10 02:58:15 +0000784static bool canSkipAddingToSets(Value *Val) {
785 // Constants can share instances, which may falsely unify multiple
786 // sets, e.g. in
787 // store i32* null, i32** %ptr1
788 // store i32* null, i32** %ptr2
789 // clearly ptr1 and ptr2 should not be unified into the same set, so
790 // we should filter out the (potentially shared) instance to
791 // i32* null.
792 if (isa<Constant>(Val)) {
George Burgess IVab03af22015-03-10 02:58:15 +0000793 // TODO: Because all of these things are constant, we can determine whether
794 // the data is *actually* mutable at graph building time. This will probably
795 // come for free/cheap with offset awareness.
Duncan P. N. Exon Smith1de3c7e2016-04-05 21:10:45 +0000796 bool CanStoreMutableData = isa<GlobalValue>(Val) ||
797 isa<ConstantExpr>(Val) ||
798 isa<ConstantAggregate>(Val);
George Burgess IVab03af22015-03-10 02:58:15 +0000799 return !CanStoreMutableData;
800 }
801
802 return false;
Hal Finkel7529c552014-09-02 21:43:13 +0000803}
804
George Burgess IVbfa401e2016-07-06 00:26:41 +0000805CFLSteensAAResult::FunctionInfo::FunctionInfo(
806 Function &Fn, const SmallVectorImpl<Value *> &RetVals,
807 StratifiedSets<Value *> S)
George Burgess IV87b2e412016-06-20 23:10:56 +0000808 : Sets(std::move(S)) {
George Burgess IV1f99da52016-06-23 18:55:23 +0000809 // Historically, an arbitrary upper-bound of 50 args was selected. We may want
810 // to remove this if it doesn't really matter in practice.
811 if (Fn.arg_size() > MaxSupportedArgsInSummary)
812 return;
George Burgess IV87b2e412016-06-20 23:10:56 +0000813
George Burgess IV1f99da52016-06-23 18:55:23 +0000814 DenseMap<StratifiedIndex, InterfaceValue> InterfaceMap;
George Burgess IV87b2e412016-06-20 23:10:56 +0000815
George Burgess IV1f99da52016-06-23 18:55:23 +0000816 // Our intention here is to record all InterfaceValues that share the same
817 // StratifiedIndex in RetParamRelations. For each valid InterfaceValue, we
818 // have its StratifiedIndex scanned here and check if the index is presented
819 // in InterfaceMap: if it is not, we add the correspondence to the map;
820 // otherwise, an aliasing relation is found and we add it to
821 // RetParamRelations.
George Burgess IVa3d62be2016-06-24 01:00:03 +0000822
George Burgess IVd14d05a2016-06-23 20:59:13 +0000823 auto AddToRetParamRelations = [&](unsigned InterfaceIndex,
824 StratifiedIndex SetIndex) {
George Burgess IV1f99da52016-06-23 18:55:23 +0000825 unsigned Level = 0;
826 while (true) {
827 InterfaceValue CurrValue{InterfaceIndex, Level};
George Burgess IV87b2e412016-06-20 23:10:56 +0000828
George Burgess IV1f99da52016-06-23 18:55:23 +0000829 auto Itr = InterfaceMap.find(SetIndex);
830 if (Itr != InterfaceMap.end()) {
831 if (CurrValue != Itr->second)
832 RetParamRelations.push_back(ExternalRelation{CurrValue, Itr->second});
833 break;
George Burgess IVa3d62be2016-06-24 01:00:03 +0000834 }
George Burgess IV87b2e412016-06-20 23:10:56 +0000835
George Burgess IV1f99da52016-06-23 18:55:23 +0000836 auto &Link = Sets.getLink(SetIndex);
George Burgess IVa3d62be2016-06-24 01:00:03 +0000837 InterfaceMap.insert(std::make_pair(SetIndex, CurrValue));
George Burgess IVd9c39fc2016-06-24 01:41:29 +0000838 auto ExternalAttrs = Link.Attrs & StratifiedAttrs(ExternalAttrMask);
George Burgess IVa3d62be2016-06-24 01:00:03 +0000839 if (ExternalAttrs.any())
840 RetParamAttributes.push_back(
841 ExternalAttribute{CurrValue, ExternalAttrs});
842
George Burgess IV1f99da52016-06-23 18:55:23 +0000843 if (!Link.hasBelow())
844 break;
George Burgess IV87b2e412016-06-20 23:10:56 +0000845
George Burgess IV1f99da52016-06-23 18:55:23 +0000846 ++Level;
847 SetIndex = Link.Below;
George Burgess IV87b2e412016-06-20 23:10:56 +0000848 }
George Burgess IV1f99da52016-06-23 18:55:23 +0000849 };
850
851 // Populate RetParamRelations for return values
852 for (auto *RetVal : RetVals) {
George Burgess IVa3d62be2016-06-24 01:00:03 +0000853 assert(RetVal != nullptr);
854 assert(RetVal->getType()->isPointerTy());
George Burgess IV1f99da52016-06-23 18:55:23 +0000855 auto RetInfo = Sets.find(RetVal);
856 if (RetInfo.hasValue())
857 AddToRetParamRelations(0, RetInfo->Index);
858 }
859
860 // Populate RetParamRelations for parameters
861 unsigned I = 0;
862 for (auto &Param : Fn.args()) {
863 if (Param.getType()->isPointerTy()) {
864 auto ParamInfo = Sets.find(&Param);
865 if (ParamInfo.hasValue())
866 AddToRetParamRelations(I + 1, ParamInfo->Index);
867 }
868 ++I;
George Burgess IV87b2e412016-06-20 23:10:56 +0000869 }
870}
871
Chandler Carruth8b046a42015-08-14 02:42:20 +0000872// Builds the graph + StratifiedSets for a function.
George Burgess IVbfa401e2016-07-06 00:26:41 +0000873CFLSteensAAResult::FunctionInfo CFLSteensAAResult::buildSetsFrom(Function *Fn) {
George Burgess IVe17756e2016-06-14 18:02:27 +0000874 CFLGraphBuilder GraphBuilder(*this, TLI, *Fn);
875 StratifiedSetsBuilder<Value *> SetBuilder;
Hal Finkel7529c552014-09-02 21:43:13 +0000876
George Burgess IVe17756e2016-06-14 18:02:27 +0000877 auto &Graph = GraphBuilder.getCFLGraph();
George Burgess IVdc96feb2016-06-13 19:21:18 +0000878 SmallVector<Value *, 16> Worklist;
George Burgess IVdc96feb2016-06-13 19:21:18 +0000879 for (auto Node : Graph.nodes())
880 Worklist.push_back(Node);
881
882 while (!Worklist.empty()) {
883 auto *CurValue = Worklist.pop_back_val();
George Burgess IVe17756e2016-06-14 18:02:27 +0000884 SetBuilder.add(CurValue);
George Burgess IVdc96feb2016-06-13 19:21:18 +0000885 if (canSkipAddingToSets(CurValue))
886 continue;
887
George Burgess IV259d9012016-06-15 20:43:41 +0000888 auto Attr = Graph.attrFor(CurValue);
889 SetBuilder.noteAttributes(CurValue, Attr);
890
George Burgess IVdc96feb2016-06-13 19:21:18 +0000891 for (const auto &Edge : Graph.edgesFor(CurValue)) {
892 auto Label = Edge.Type;
893 auto *OtherValue = Edge.Other;
894
895 if (canSkipAddingToSets(OtherValue))
Hal Finkel7529c552014-09-02 21:43:13 +0000896 continue;
897
George Burgess IVdc96feb2016-06-13 19:21:18 +0000898 bool Added;
899 switch (directionOfEdgeType(Label)) {
900 case Level::Above:
George Burgess IVe17756e2016-06-14 18:02:27 +0000901 Added = SetBuilder.addAbove(CurValue, OtherValue);
George Burgess IVdc96feb2016-06-13 19:21:18 +0000902 break;
903 case Level::Below:
George Burgess IVe17756e2016-06-14 18:02:27 +0000904 Added = SetBuilder.addBelow(CurValue, OtherValue);
George Burgess IVdc96feb2016-06-13 19:21:18 +0000905 break;
906 case Level::Same:
George Burgess IVe17756e2016-06-14 18:02:27 +0000907 Added = SetBuilder.addWith(CurValue, OtherValue);
George Burgess IVdc96feb2016-06-13 19:21:18 +0000908 break;
Hal Finkel7529c552014-09-02 21:43:13 +0000909 }
George Burgess IVdc96feb2016-06-13 19:21:18 +0000910
George Burgess IVdc96feb2016-06-13 19:21:18 +0000911 if (Added)
912 Worklist.push_back(OtherValue);
Hal Finkel7529c552014-09-02 21:43:13 +0000913 }
914 }
915
George Burgess IV652ec4f2016-06-09 23:15:04 +0000916 // Special handling for globals and arguments
George Burgess IV24eb0da2016-06-14 18:12:28 +0000917 for (auto *External : GraphBuilder.getExternalValues()) {
918 SetBuilder.add(External);
919 auto Attr = valueToAttr(External);
George Burgess IV652ec4f2016-06-09 23:15:04 +0000920 if (Attr.hasValue()) {
George Burgess IV24eb0da2016-06-14 18:12:28 +0000921 SetBuilder.noteAttributes(External, *Attr);
George Burgess IVa3d62be2016-06-24 01:00:03 +0000922 if (*Attr == AttrGlobal)
923 SetBuilder.addAttributesBelow(External, 1, AttrUnknown);
924 else
925 SetBuilder.addAttributesBelow(External, 1, AttrCaller);
George Burgess IV652ec4f2016-06-09 23:15:04 +0000926 }
George Burgess IV24eb0da2016-06-14 18:12:28 +0000927 }
George Burgess IVab03af22015-03-10 02:58:15 +0000928
George Burgess IV1f99da52016-06-23 18:55:23 +0000929 // Special handling for interprocedural aliases
930 for (auto &Edge : GraphBuilder.getInterprocEdges()) {
George Burgess IVfe1397b2016-06-23 19:16:04 +0000931 auto FromVal = Edge.From.Val;
932 auto ToVal = Edge.To.Val;
George Burgess IV1f99da52016-06-23 18:55:23 +0000933 SetBuilder.add(FromVal);
934 SetBuilder.add(ToVal);
935 SetBuilder.addBelowWith(FromVal, Edge.From.DerefLevel, ToVal,
936 Edge.To.DerefLevel);
937 }
938
George Burgess IVa3d62be2016-06-24 01:00:03 +0000939 // Special handling for interprocedural attributes
940 for (auto &IPAttr : GraphBuilder.getInterprocAttrs()) {
941 auto Val = IPAttr.Node.Val;
942 SetBuilder.add(Val);
943 SetBuilder.addAttributesBelow(Val, IPAttr.Node.DerefLevel, IPAttr.Attr);
944 }
945
George Burgess IV1f99da52016-06-23 18:55:23 +0000946 // Special handling for opaque external functions
George Burgess IV24eb0da2016-06-14 18:12:28 +0000947 for (auto *Escape : GraphBuilder.getEscapedValues()) {
948 SetBuilder.add(Escape);
949 SetBuilder.noteAttributes(Escape, AttrEscaped);
George Burgess IVa3d62be2016-06-24 01:00:03 +0000950 SetBuilder.addAttributesBelow(Escape, 1, AttrUnknown);
George Burgess IV24eb0da2016-06-14 18:12:28 +0000951 }
Hal Finkel7529c552014-09-02 21:43:13 +0000952
George Burgess IV87b2e412016-06-20 23:10:56 +0000953 return FunctionInfo(*Fn, GraphBuilder.getReturnValues(), SetBuilder.build());
Hal Finkel7529c552014-09-02 21:43:13 +0000954}
955
George Burgess IVbfa401e2016-07-06 00:26:41 +0000956void CFLSteensAAResult::scan(Function *Fn) {
Hal Finkel8d1590d2014-09-02 22:52:30 +0000957 auto InsertPair = Cache.insert(std::make_pair(Fn, Optional<FunctionInfo>()));
Hal Finkel7529c552014-09-02 21:43:13 +0000958 (void)InsertPair;
959 assert(InsertPair.second &&
960 "Trying to scan a function that has already been cached");
961
George Burgess IV6edb8912016-05-02 18:09:19 +0000962 // Note that we can't do Cache[Fn] = buildSetsFrom(Fn) here: the function call
963 // may get evaluated after operator[], potentially triggering a DenseMap
964 // resize and invalidating the reference returned by operator[]
965 auto FunInfo = buildSetsFrom(Fn);
966 Cache[Fn] = std::move(FunInfo);
967
Hal Finkel7529c552014-09-02 21:43:13 +0000968 Handles.push_front(FunctionHandle(Fn, this));
969}
970
George Burgess IVbfa401e2016-07-06 00:26:41 +0000971void CFLSteensAAResult::evict(Function *Fn) { Cache.erase(Fn); }
Chandler Carruth8b046a42015-08-14 02:42:20 +0000972
George Burgess IVcae581d2016-04-13 23:27:37 +0000973/// Ensures that the given function is available in the cache, and returns the
974/// entry.
George Burgess IVbfa401e2016-07-06 00:26:41 +0000975const Optional<CFLSteensAAResult::FunctionInfo> &
976CFLSteensAAResult::ensureCached(Function *Fn) {
Chandler Carruth8b046a42015-08-14 02:42:20 +0000977 auto Iter = Cache.find(Fn);
978 if (Iter == Cache.end()) {
979 scan(Fn);
980 Iter = Cache.find(Fn);
981 assert(Iter != Cache.end());
982 assert(Iter->second.hasValue());
983 }
984 return Iter->second;
985}
986
George Burgess IVbfa401e2016-07-06 00:26:41 +0000987AliasResult CFLSteensAAResult::query(const MemoryLocation &LocA,
988 const MemoryLocation &LocB) {
Hal Finkel7529c552014-09-02 21:43:13 +0000989 auto *ValA = const_cast<Value *>(LocA.Ptr);
990 auto *ValB = const_cast<Value *>(LocB.Ptr);
991
George Burgess IV259d9012016-06-15 20:43:41 +0000992 if (!ValA->getType()->isPointerTy() || !ValB->getType()->isPointerTy())
993 return NoAlias;
994
Hal Finkel7529c552014-09-02 21:43:13 +0000995 Function *Fn = nullptr;
996 auto MaybeFnA = parentFunctionOfValue(ValA);
997 auto MaybeFnB = parentFunctionOfValue(ValB);
998 if (!MaybeFnA.hasValue() && !MaybeFnB.hasValue()) {
George Burgess IVcae581d2016-04-13 23:27:37 +0000999 // The only times this is known to happen are when globals + InlineAsm are
1000 // involved
George Burgess IVbfa401e2016-07-06 00:26:41 +00001001 DEBUG(dbgs()
1002 << "CFLSteensAA: could not extract parent function information.\n");
Chandler Carruthc3f49eb2015-06-22 02:16:51 +00001003 return MayAlias;
Hal Finkel7529c552014-09-02 21:43:13 +00001004 }
1005
1006 if (MaybeFnA.hasValue()) {
1007 Fn = *MaybeFnA;
1008 assert((!MaybeFnB.hasValue() || *MaybeFnB == *MaybeFnA) &&
1009 "Interprocedural queries not supported");
1010 } else {
1011 Fn = *MaybeFnB;
1012 }
1013
1014 assert(Fn != nullptr);
1015 auto &MaybeInfo = ensureCached(Fn);
1016 assert(MaybeInfo.hasValue());
1017
George Burgess IV87b2e412016-06-20 23:10:56 +00001018 auto &Sets = MaybeInfo->getStratifiedSets();
Hal Finkel7529c552014-09-02 21:43:13 +00001019 auto MaybeA = Sets.find(ValA);
1020 if (!MaybeA.hasValue())
Chandler Carruthc3f49eb2015-06-22 02:16:51 +00001021 return MayAlias;
Hal Finkel7529c552014-09-02 21:43:13 +00001022
1023 auto MaybeB = Sets.find(ValB);
1024 if (!MaybeB.hasValue())
Chandler Carruthc3f49eb2015-06-22 02:16:51 +00001025 return MayAlias;
Hal Finkel7529c552014-09-02 21:43:13 +00001026
1027 auto SetA = *MaybeA;
1028 auto SetB = *MaybeB;
Hal Finkel7529c552014-09-02 21:43:13 +00001029 auto AttrsA = Sets.getLink(SetA.Index).Attrs;
1030 auto AttrsB = Sets.getLink(SetB.Index).Attrs;
George Burgess IV33305e72015-02-12 03:07:07 +00001031
George Burgess IVa1f9a2d2016-06-07 18:35:37 +00001032 // If both values are local (meaning the corresponding set has attribute
George Burgess IVbfa401e2016-07-06 00:26:41 +00001033 // AttrNone or AttrEscaped), then we know that CFLSteensAA fully models them:
1034 // they may-alias each other if and only if they are in the same set.
George Burgess IVa1f9a2d2016-06-07 18:35:37 +00001035 // If at least one value is non-local (meaning it either is global/argument or
1036 // it comes from unknown sources like integer cast), the situation becomes a
1037 // bit more interesting. We follow three general rules described below:
1038 // - Non-local values may alias each other
1039 // - AttrNone values do not alias any non-local values
George Burgess IV652ec4f2016-06-09 23:15:04 +00001040 // - AttrEscaped do not alias globals/arguments, but they may alias
George Burgess IVa1f9a2d2016-06-07 18:35:37 +00001041 // AttrUnknown values
1042 if (SetA.Index == SetB.Index)
Chandler Carruthc3f49eb2015-06-22 02:16:51 +00001043 return MayAlias;
George Burgess IVa1f9a2d2016-06-07 18:35:37 +00001044 if (AttrsA.none() || AttrsB.none())
1045 return NoAlias;
George Burgess IV652ec4f2016-06-09 23:15:04 +00001046 if (isUnknownAttr(AttrsA) || isUnknownAttr(AttrsB))
George Burgess IVa1f9a2d2016-06-07 18:35:37 +00001047 return MayAlias;
1048 if (isGlobalOrArgAttr(AttrsA) && isGlobalOrArgAttr(AttrsB))
1049 return MayAlias;
1050 return NoAlias;
Hal Finkel7529c552014-09-02 21:43:13 +00001051}
Mehdi Amini46a43552015-03-04 18:43:29 +00001052
George Burgess IVbfa401e2016-07-06 00:26:41 +00001053ModRefInfo CFLSteensAAResult::getArgModRefInfo(ImmutableCallSite CS,
1054 unsigned ArgIdx) {
George Burgess IVd86e38e2016-06-30 02:11:26 +00001055 if (auto CalledFunc = CS.getCalledFunction()) {
1056 auto &MaybeInfo = ensureCached(const_cast<Function *>(CalledFunc));
1057 if (!MaybeInfo.hasValue())
1058 return MRI_ModRef;
1059 auto &RetParamAttributes = MaybeInfo->getRetParamAttributes();
1060 auto &RetParamRelations = MaybeInfo->getRetParamRelations();
1061
1062 bool ArgAttributeIsWritten =
1063 std::any_of(RetParamAttributes.begin(), RetParamAttributes.end(),
1064 [ArgIdx](const ExternalAttribute &ExtAttr) {
1065 return ExtAttr.IValue.Index == ArgIdx + 1;
1066 });
1067 bool ArgIsAccessed =
1068 std::any_of(RetParamRelations.begin(), RetParamRelations.end(),
1069 [ArgIdx](const ExternalRelation &ExtRelation) {
1070 return ExtRelation.To.Index == ArgIdx + 1 ||
1071 ExtRelation.From.Index == ArgIdx + 1;
1072 });
1073
1074 return (!ArgIsAccessed && !ArgAttributeIsWritten) ? MRI_NoModRef
1075 : MRI_ModRef;
1076 }
1077
1078 return MRI_ModRef;
1079}
1080
George Burgess IVbfa401e2016-07-06 00:26:41 +00001081FunctionModRefBehavior
1082CFLSteensAAResult::getModRefBehavior(ImmutableCallSite CS) {
George Burgess IVd86e38e2016-06-30 02:11:26 +00001083 // If we know the callee, try analyzing it
1084 if (auto CalledFunc = CS.getCalledFunction())
1085 return getModRefBehavior(CalledFunc);
1086
1087 // Otherwise, be conservative
1088 return FMRB_UnknownModRefBehavior;
1089}
1090
George Burgess IVbfa401e2016-07-06 00:26:41 +00001091FunctionModRefBehavior CFLSteensAAResult::getModRefBehavior(const Function *F) {
George Burgess IVd86e38e2016-06-30 02:11:26 +00001092 assert(F != nullptr);
1093
1094 // TODO: Remove the const_cast
1095 auto &MaybeInfo = ensureCached(const_cast<Function *>(F));
1096 if (!MaybeInfo.hasValue())
1097 return FMRB_UnknownModRefBehavior;
1098 auto &RetParamAttributes = MaybeInfo->getRetParamAttributes();
1099 auto &RetParamRelations = MaybeInfo->getRetParamRelations();
1100
1101 // First, if any argument is marked Escpaed, Unknown or Global, anything may
1102 // happen to them and thus we can't draw any conclusion.
1103 if (!RetParamAttributes.empty())
1104 return FMRB_UnknownModRefBehavior;
1105
1106 // Currently we don't (and can't) distinguish reads from writes in
1107 // RetParamRelations. All we can say is whether there may be memory access or
1108 // not.
1109 if (RetParamRelations.empty())
1110 return FMRB_DoesNotAccessMemory;
1111
1112 // Check if something beyond argmem gets touched.
1113 bool AccessArgMemoryOnly =
1114 std::all_of(RetParamRelations.begin(), RetParamRelations.end(),
1115 [](const ExternalRelation &ExtRelation) {
1116 // Both DerefLevels has to be 0, since we don't know which
1117 // one is a read and which is a write.
1118 return ExtRelation.From.DerefLevel == 0 &&
1119 ExtRelation.To.DerefLevel == 0;
1120 });
1121 return AccessArgMemoryOnly ? FMRB_OnlyAccessesArgumentPointees
1122 : FMRB_UnknownModRefBehavior;
1123}
1124
George Burgess IVbfa401e2016-07-06 00:26:41 +00001125char CFLSteensAA::PassID;
Chandler Carruthb4faf132016-03-11 10:22:49 +00001126
George Burgess IVbfa401e2016-07-06 00:26:41 +00001127CFLSteensAAResult CFLSteensAA::run(Function &F, AnalysisManager<Function> &AM) {
1128 return CFLSteensAAResult(AM.getResult<TargetLibraryAnalysis>(F));
Chandler Carruth7b560d42015-09-09 17:55:00 +00001129}
1130
George Burgess IVbfa401e2016-07-06 00:26:41 +00001131char CFLSteensAAWrapperPass::ID = 0;
1132INITIALIZE_PASS(CFLSteensAAWrapperPass, "cfl-steens-aa",
1133 "Unification-Based CFL Alias Analysis", false, true)
Chandler Carruth7b560d42015-09-09 17:55:00 +00001134
George Burgess IVbfa401e2016-07-06 00:26:41 +00001135ImmutablePass *llvm::createCFLSteensAAWrapperPass() {
1136 return new CFLSteensAAWrapperPass();
Chandler Carruth7b560d42015-09-09 17:55:00 +00001137}
1138
George Burgess IVbfa401e2016-07-06 00:26:41 +00001139CFLSteensAAWrapperPass::CFLSteensAAWrapperPass() : ImmutablePass(ID) {
1140 initializeCFLSteensAAWrapperPassPass(*PassRegistry::getPassRegistry());
1141}
1142
1143void CFLSteensAAWrapperPass::initializePass() {
George Burgess IV18b83fe2016-06-01 18:39:54 +00001144 auto &TLIWP = getAnalysis<TargetLibraryInfoWrapperPass>();
George Burgess IVbfa401e2016-07-06 00:26:41 +00001145 Result.reset(new CFLSteensAAResult(TLIWP.getTLI()));
Chandler Carruth7b560d42015-09-09 17:55:00 +00001146}
1147
George Burgess IVbfa401e2016-07-06 00:26:41 +00001148void CFLSteensAAWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const {
Chandler Carruth7b560d42015-09-09 17:55:00 +00001149 AU.setPreservesAll();
George Burgess IV18b83fe2016-06-01 18:39:54 +00001150 AU.addRequired<TargetLibraryInfoWrapperPass>();
Mehdi Amini46a43552015-03-04 18:43:29 +00001151}