blob: a87cf458a8470b472994ee961c7ff1cb169e9991 [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"
George Burgess IV1ca8aff2016-07-06 00:36:12 +000039#include "CFLGraph.h"
George Burgess IVe1919962016-07-06 00:47:21 +000040#include "StratifiedSets.h"
Hal Finkel7529c552014-09-02 21:43:13 +000041#include "llvm/ADT/DenseMap.h"
Hal Finkel7529c552014-09-02 21:43:13 +000042#include "llvm/ADT/None.h"
Chandler Carruthd9903882015-01-14 11:23:27 +000043#include "llvm/ADT/Optional.h"
George Burgess IV18b83fe2016-06-01 18:39:54 +000044#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/Pass.h"
Hal Finkel7d7087c2014-09-02 22:13:00 +000048#include "llvm/Support/Compiler.h"
George Burgess IV33305e72015-02-12 03:07:07 +000049#include "llvm/Support/Debug.h"
Hal Finkel7529c552014-09-02 21:43:13 +000050#include "llvm/Support/ErrorHandling.h"
Benjamin Kramer799003b2015-03-23 19:32:43 +000051#include "llvm/Support/raw_ostream.h"
Hal Finkel7529c552014-09-02 21:43:13 +000052#include <algorithm>
53#include <cassert>
Benjamin Kramer799003b2015-03-23 19:32:43 +000054#include <memory>
Hal Finkel7529c552014-09-02 21:43:13 +000055#include <tuple>
56
57using namespace llvm;
George Burgess IV1ca8aff2016-07-06 00:36:12 +000058using namespace llvm::cflaa;
Hal Finkel7529c552014-09-02 21:43:13 +000059
George Burgess IVbfa401e2016-07-06 00:26:41 +000060#define DEBUG_TYPE "cfl-steens-aa"
George Burgess IV33305e72015-02-12 03:07:07 +000061
George Burgess IVbfa401e2016-07-06 00:26:41 +000062CFLSteensAAResult::CFLSteensAAResult(const TargetLibraryInfo &TLI)
George Burgess IV18b83fe2016-06-01 18:39:54 +000063 : AAResultBase(), TLI(TLI) {}
George Burgess IVbfa401e2016-07-06 00:26:41 +000064CFLSteensAAResult::CFLSteensAAResult(CFLSteensAAResult &&Arg)
George Burgess IV18b83fe2016-06-01 18:39:54 +000065 : AAResultBase(std::move(Arg)), TLI(Arg.TLI) {}
George Burgess IVbfa401e2016-07-06 00:26:41 +000066CFLSteensAAResult::~CFLSteensAAResult() {}
Chandler Carruth8b046a42015-08-14 02:42:20 +000067
George Burgess IV87b2e412016-06-20 23:10:56 +000068/// Information we have about a function and would like to keep around.
George Burgess IVbfa401e2016-07-06 00:26:41 +000069class CFLSteensAAResult::FunctionInfo {
George Burgess IVde1be712016-07-11 22:59:09 +000070 StratifiedSets<InstantiatedValue> Sets;
George Burgess IVc294d0d2016-07-09 02:54:42 +000071 AliasSummary Summary;
George Burgess IVa3d62be2016-06-24 01:00:03 +000072
George Burgess IV87b2e412016-06-20 23:10:56 +000073public:
74 FunctionInfo(Function &Fn, const SmallVectorImpl<Value *> &RetVals,
George Burgess IVde1be712016-07-11 22:59:09 +000075 StratifiedSets<InstantiatedValue> S);
George Burgess IV87b2e412016-06-20 23:10:56 +000076
George Burgess IVde1be712016-07-11 22:59:09 +000077 const StratifiedSets<InstantiatedValue> &getStratifiedSets() const {
78 return Sets;
79 }
George Burgess IVc294d0d2016-07-09 02:54:42 +000080 const AliasSummary &getAliasSummary() const { return Summary; }
Chandler Carruth8b046a42015-08-14 02:42:20 +000081};
82
Hal Finkel1ae325f2014-09-02 23:50:01 +000083const StratifiedIndex StratifiedLink::SetSentinel =
George Burgess IV11d509d2015-03-15 00:52:21 +000084 std::numeric_limits<StratifiedIndex>::max();
Hal Finkel1ae325f2014-09-02 23:50:01 +000085
Hal Finkel7529c552014-09-02 21:43:13 +000086//===----------------------------------------------------------------------===//
87// Function declarations that require types defined in the namespace above
88//===----------------------------------------------------------------------===//
89
George Burgess IVcae581d2016-04-13 23:27:37 +000090/// Determines whether it would be pointless to add the given Value to our sets.
George Burgess IVab03af22015-03-10 02:58:15 +000091static bool canSkipAddingToSets(Value *Val);
92
George Burgess IVab03af22015-03-10 02:58:15 +000093static bool canSkipAddingToSets(Value *Val) {
94 // Constants can share instances, which may falsely unify multiple
95 // sets, e.g. in
96 // store i32* null, i32** %ptr1
97 // store i32* null, i32** %ptr2
98 // clearly ptr1 and ptr2 should not be unified into the same set, so
99 // we should filter out the (potentially shared) instance to
100 // i32* null.
101 if (isa<Constant>(Val)) {
George Burgess IVab03af22015-03-10 02:58:15 +0000102 // TODO: Because all of these things are constant, we can determine whether
103 // the data is *actually* mutable at graph building time. This will probably
104 // come for free/cheap with offset awareness.
Duncan P. N. Exon Smith1de3c7e2016-04-05 21:10:45 +0000105 bool CanStoreMutableData = isa<GlobalValue>(Val) ||
106 isa<ConstantExpr>(Val) ||
107 isa<ConstantAggregate>(Val);
George Burgess IVab03af22015-03-10 02:58:15 +0000108 return !CanStoreMutableData;
109 }
110
111 return false;
Hal Finkel7529c552014-09-02 21:43:13 +0000112}
113
George Burgess IVbfa401e2016-07-06 00:26:41 +0000114CFLSteensAAResult::FunctionInfo::FunctionInfo(
115 Function &Fn, const SmallVectorImpl<Value *> &RetVals,
George Burgess IVde1be712016-07-11 22:59:09 +0000116 StratifiedSets<InstantiatedValue> S)
George Burgess IV87b2e412016-06-20 23:10:56 +0000117 : Sets(std::move(S)) {
George Burgess IV1f99da52016-06-23 18:55:23 +0000118 // Historically, an arbitrary upper-bound of 50 args was selected. We may want
119 // to remove this if it doesn't really matter in practice.
120 if (Fn.arg_size() > MaxSupportedArgsInSummary)
121 return;
George Burgess IV87b2e412016-06-20 23:10:56 +0000122
George Burgess IV1f99da52016-06-23 18:55:23 +0000123 DenseMap<StratifiedIndex, InterfaceValue> InterfaceMap;
George Burgess IV87b2e412016-06-20 23:10:56 +0000124
George Burgess IV1f99da52016-06-23 18:55:23 +0000125 // Our intention here is to record all InterfaceValues that share the same
126 // StratifiedIndex in RetParamRelations. For each valid InterfaceValue, we
127 // have its StratifiedIndex scanned here and check if the index is presented
128 // in InterfaceMap: if it is not, we add the correspondence to the map;
129 // otherwise, an aliasing relation is found and we add it to
130 // RetParamRelations.
George Burgess IVa3d62be2016-06-24 01:00:03 +0000131
George Burgess IVd14d05a2016-06-23 20:59:13 +0000132 auto AddToRetParamRelations = [&](unsigned InterfaceIndex,
133 StratifiedIndex SetIndex) {
George Burgess IV1f99da52016-06-23 18:55:23 +0000134 unsigned Level = 0;
135 while (true) {
136 InterfaceValue CurrValue{InterfaceIndex, Level};
George Burgess IV87b2e412016-06-20 23:10:56 +0000137
George Burgess IV1f99da52016-06-23 18:55:23 +0000138 auto Itr = InterfaceMap.find(SetIndex);
139 if (Itr != InterfaceMap.end()) {
140 if (CurrValue != Itr->second)
George Burgess IVc294d0d2016-07-09 02:54:42 +0000141 Summary.RetParamRelations.push_back(
George Burgess IV4ec17532016-07-22 22:30:48 +0000142 ExternalRelation{CurrValue, Itr->second, UnknownOffset});
George Burgess IV1f99da52016-06-23 18:55:23 +0000143 break;
George Burgess IVa3d62be2016-06-24 01:00:03 +0000144 }
George Burgess IV87b2e412016-06-20 23:10:56 +0000145
George Burgess IV1f99da52016-06-23 18:55:23 +0000146 auto &Link = Sets.getLink(SetIndex);
George Burgess IVa3d62be2016-06-24 01:00:03 +0000147 InterfaceMap.insert(std::make_pair(SetIndex, CurrValue));
George Burgess IVe1919962016-07-06 00:47:21 +0000148 auto ExternalAttrs = getExternallyVisibleAttrs(Link.Attrs);
George Burgess IVa3d62be2016-06-24 01:00:03 +0000149 if (ExternalAttrs.any())
George Burgess IVc294d0d2016-07-09 02:54:42 +0000150 Summary.RetParamAttributes.push_back(
George Burgess IVa3d62be2016-06-24 01:00:03 +0000151 ExternalAttribute{CurrValue, ExternalAttrs});
152
George Burgess IV1f99da52016-06-23 18:55:23 +0000153 if (!Link.hasBelow())
154 break;
George Burgess IV87b2e412016-06-20 23:10:56 +0000155
George Burgess IV1f99da52016-06-23 18:55:23 +0000156 ++Level;
157 SetIndex = Link.Below;
George Burgess IV87b2e412016-06-20 23:10:56 +0000158 }
George Burgess IV1f99da52016-06-23 18:55:23 +0000159 };
160
161 // Populate RetParamRelations for return values
162 for (auto *RetVal : RetVals) {
George Burgess IVa3d62be2016-06-24 01:00:03 +0000163 assert(RetVal != nullptr);
164 assert(RetVal->getType()->isPointerTy());
George Burgess IVde1be712016-07-11 22:59:09 +0000165 auto RetInfo = Sets.find(InstantiatedValue{RetVal, 0});
George Burgess IV1f99da52016-06-23 18:55:23 +0000166 if (RetInfo.hasValue())
167 AddToRetParamRelations(0, RetInfo->Index);
168 }
169
170 // Populate RetParamRelations for parameters
171 unsigned I = 0;
172 for (auto &Param : Fn.args()) {
173 if (Param.getType()->isPointerTy()) {
George Burgess IVde1be712016-07-11 22:59:09 +0000174 auto ParamInfo = Sets.find(InstantiatedValue{&Param, 0});
George Burgess IV1f99da52016-06-23 18:55:23 +0000175 if (ParamInfo.hasValue())
176 AddToRetParamRelations(I + 1, ParamInfo->Index);
177 }
178 ++I;
George Burgess IV87b2e412016-06-20 23:10:56 +0000179 }
180}
181
Chandler Carruth8b046a42015-08-14 02:42:20 +0000182// Builds the graph + StratifiedSets for a function.
George Burgess IVbfa401e2016-07-06 00:26:41 +0000183CFLSteensAAResult::FunctionInfo CFLSteensAAResult::buildSetsFrom(Function *Fn) {
George Burgess IVc294d0d2016-07-09 02:54:42 +0000184 CFLGraphBuilder<CFLSteensAAResult> GraphBuilder(*this, TLI, *Fn);
George Burgess IVde1be712016-07-11 22:59:09 +0000185 StratifiedSetsBuilder<InstantiatedValue> SetBuilder;
Hal Finkel7529c552014-09-02 21:43:13 +0000186
George Burgess IVde1be712016-07-11 22:59:09 +0000187 // Add all CFLGraph nodes and all Dereference edges to StratifiedSets
George Burgess IVe17756e2016-06-14 18:02:27 +0000188 auto &Graph = GraphBuilder.getCFLGraph();
George Burgess IVde1be712016-07-11 22:59:09 +0000189 for (const auto &Mapping : Graph.value_mappings()) {
190 auto Val = Mapping.first;
191 if (canSkipAddingToSets(Val))
George Burgess IVdc96feb2016-06-13 19:21:18 +0000192 continue;
George Burgess IVde1be712016-07-11 22:59:09 +0000193 auto &ValueInfo = Mapping.second;
George Burgess IVdc96feb2016-06-13 19:21:18 +0000194
George Burgess IVde1be712016-07-11 22:59:09 +0000195 assert(ValueInfo.getNumLevels() > 0);
196 SetBuilder.add(InstantiatedValue{Val, 0});
197 SetBuilder.noteAttributes(InstantiatedValue{Val, 0},
198 ValueInfo.getNodeInfoAtLevel(0).Attr);
199 for (unsigned I = 0, E = ValueInfo.getNumLevels() - 1; I < E; ++I) {
200 SetBuilder.add(InstantiatedValue{Val, I + 1});
201 SetBuilder.noteAttributes(InstantiatedValue{Val, I + 1},
202 ValueInfo.getNodeInfoAtLevel(I + 1).Attr);
203 SetBuilder.addBelow(InstantiatedValue{Val, I},
204 InstantiatedValue{Val, I + 1});
Hal Finkel7529c552014-09-02 21:43:13 +0000205 }
206 }
207
George Burgess IVde1be712016-07-11 22:59:09 +0000208 // Add all assign edges to StratifiedSets
209 for (const auto &Mapping : Graph.value_mappings()) {
210 auto Val = Mapping.first;
211 if (canSkipAddingToSets(Val))
212 continue;
213 auto &ValueInfo = Mapping.second;
George Burgess IV1f99da52016-06-23 18:55:23 +0000214
George Burgess IVde1be712016-07-11 22:59:09 +0000215 for (unsigned I = 0, E = ValueInfo.getNumLevels(); I < E; ++I) {
216 auto Src = InstantiatedValue{Val, I};
217 for (auto &Edge : ValueInfo.getNodeInfoAtLevel(I).Edges)
218 SetBuilder.addWith(Src, Edge.Other);
219 }
George Burgess IVa3d62be2016-06-24 01:00:03 +0000220 }
221
George Burgess IV87b2e412016-06-20 23:10:56 +0000222 return FunctionInfo(*Fn, GraphBuilder.getReturnValues(), SetBuilder.build());
Hal Finkel7529c552014-09-02 21:43:13 +0000223}
224
George Burgess IVbfa401e2016-07-06 00:26:41 +0000225void CFLSteensAAResult::scan(Function *Fn) {
Hal Finkel8d1590d2014-09-02 22:52:30 +0000226 auto InsertPair = Cache.insert(std::make_pair(Fn, Optional<FunctionInfo>()));
Hal Finkel7529c552014-09-02 21:43:13 +0000227 (void)InsertPair;
228 assert(InsertPair.second &&
229 "Trying to scan a function that has already been cached");
230
George Burgess IV6edb8912016-05-02 18:09:19 +0000231 // Note that we can't do Cache[Fn] = buildSetsFrom(Fn) here: the function call
232 // may get evaluated after operator[], potentially triggering a DenseMap
233 // resize and invalidating the reference returned by operator[]
234 auto FunInfo = buildSetsFrom(Fn);
235 Cache[Fn] = std::move(FunInfo);
236
Davide Italianoe34a8062017-06-26 23:59:14 +0000237 Handles.emplace_front(Fn, this);
Hal Finkel7529c552014-09-02 21:43:13 +0000238}
239
George Burgess IVbfa401e2016-07-06 00:26:41 +0000240void CFLSteensAAResult::evict(Function *Fn) { Cache.erase(Fn); }
Chandler Carruth8b046a42015-08-14 02:42:20 +0000241
George Burgess IVcae581d2016-04-13 23:27:37 +0000242/// Ensures that the given function is available in the cache, and returns the
243/// entry.
George Burgess IVbfa401e2016-07-06 00:26:41 +0000244const Optional<CFLSteensAAResult::FunctionInfo> &
245CFLSteensAAResult::ensureCached(Function *Fn) {
Chandler Carruth8b046a42015-08-14 02:42:20 +0000246 auto Iter = Cache.find(Fn);
247 if (Iter == Cache.end()) {
248 scan(Fn);
249 Iter = Cache.find(Fn);
250 assert(Iter != Cache.end());
251 assert(Iter->second.hasValue());
252 }
253 return Iter->second;
254}
255
George Burgess IVc294d0d2016-07-09 02:54:42 +0000256const AliasSummary *CFLSteensAAResult::getAliasSummary(Function &Fn) {
257 auto &FunInfo = ensureCached(&Fn);
258 if (FunInfo.hasValue())
259 return &FunInfo->getAliasSummary();
260 else
261 return nullptr;
262}
263
George Burgess IVbfa401e2016-07-06 00:26:41 +0000264AliasResult CFLSteensAAResult::query(const MemoryLocation &LocA,
265 const MemoryLocation &LocB) {
Hal Finkel7529c552014-09-02 21:43:13 +0000266 auto *ValA = const_cast<Value *>(LocA.Ptr);
267 auto *ValB = const_cast<Value *>(LocB.Ptr);
268
George Burgess IV259d9012016-06-15 20:43:41 +0000269 if (!ValA->getType()->isPointerTy() || !ValB->getType()->isPointerTy())
270 return NoAlias;
271
Hal Finkel7529c552014-09-02 21:43:13 +0000272 Function *Fn = nullptr;
Davide Italiano31d4c1b2017-06-27 02:25:06 +0000273 Function *MaybeFnA = const_cast<Function *>(parentFunctionOfValue(ValA));
274 Function *MaybeFnB = const_cast<Function *>(parentFunctionOfValue(ValB));
Davide Italiano604c0032017-06-27 00:33:37 +0000275 if (!MaybeFnA && !MaybeFnB) {
George Burgess IVcae581d2016-04-13 23:27:37 +0000276 // The only times this is known to happen are when globals + InlineAsm are
277 // involved
George Burgess IVbfa401e2016-07-06 00:26:41 +0000278 DEBUG(dbgs()
279 << "CFLSteensAA: could not extract parent function information.\n");
Chandler Carruthc3f49eb2015-06-22 02:16:51 +0000280 return MayAlias;
Hal Finkel7529c552014-09-02 21:43:13 +0000281 }
282
Davide Italiano604c0032017-06-27 00:33:37 +0000283 if (MaybeFnA) {
284 Fn = MaybeFnA;
285 assert((!MaybeFnB || MaybeFnB == MaybeFnA) &&
Hal Finkel7529c552014-09-02 21:43:13 +0000286 "Interprocedural queries not supported");
287 } else {
Davide Italiano604c0032017-06-27 00:33:37 +0000288 Fn = MaybeFnB;
Hal Finkel7529c552014-09-02 21:43:13 +0000289 }
290
291 assert(Fn != nullptr);
292 auto &MaybeInfo = ensureCached(Fn);
293 assert(MaybeInfo.hasValue());
294
George Burgess IV87b2e412016-06-20 23:10:56 +0000295 auto &Sets = MaybeInfo->getStratifiedSets();
George Burgess IVde1be712016-07-11 22:59:09 +0000296 auto MaybeA = Sets.find(InstantiatedValue{ValA, 0});
Hal Finkel7529c552014-09-02 21:43:13 +0000297 if (!MaybeA.hasValue())
Chandler Carruthc3f49eb2015-06-22 02:16:51 +0000298 return MayAlias;
Hal Finkel7529c552014-09-02 21:43:13 +0000299
George Burgess IVde1be712016-07-11 22:59:09 +0000300 auto MaybeB = Sets.find(InstantiatedValue{ValB, 0});
Hal Finkel7529c552014-09-02 21:43:13 +0000301 if (!MaybeB.hasValue())
Chandler Carruthc3f49eb2015-06-22 02:16:51 +0000302 return MayAlias;
Hal Finkel7529c552014-09-02 21:43:13 +0000303
304 auto SetA = *MaybeA;
305 auto SetB = *MaybeB;
Hal Finkel7529c552014-09-02 21:43:13 +0000306 auto AttrsA = Sets.getLink(SetA.Index).Attrs;
307 auto AttrsB = Sets.getLink(SetB.Index).Attrs;
George Burgess IV33305e72015-02-12 03:07:07 +0000308
George Burgess IVa1f9a2d2016-06-07 18:35:37 +0000309 // If both values are local (meaning the corresponding set has attribute
George Burgess IVbfa401e2016-07-06 00:26:41 +0000310 // AttrNone or AttrEscaped), then we know that CFLSteensAA fully models them:
311 // they may-alias each other if and only if they are in the same set.
George Burgess IVa1f9a2d2016-06-07 18:35:37 +0000312 // If at least one value is non-local (meaning it either is global/argument or
313 // it comes from unknown sources like integer cast), the situation becomes a
314 // bit more interesting. We follow three general rules described below:
315 // - Non-local values may alias each other
316 // - AttrNone values do not alias any non-local values
George Burgess IV652ec4f2016-06-09 23:15:04 +0000317 // - AttrEscaped do not alias globals/arguments, but they may alias
George Burgess IVa1f9a2d2016-06-07 18:35:37 +0000318 // AttrUnknown values
319 if (SetA.Index == SetB.Index)
Chandler Carruthc3f49eb2015-06-22 02:16:51 +0000320 return MayAlias;
George Burgess IVa1f9a2d2016-06-07 18:35:37 +0000321 if (AttrsA.none() || AttrsB.none())
322 return NoAlias;
George Burgess IVe1919962016-07-06 00:47:21 +0000323 if (hasUnknownOrCallerAttr(AttrsA) || hasUnknownOrCallerAttr(AttrsB))
George Burgess IVa1f9a2d2016-06-07 18:35:37 +0000324 return MayAlias;
325 if (isGlobalOrArgAttr(AttrsA) && isGlobalOrArgAttr(AttrsB))
326 return MayAlias;
327 return NoAlias;
Hal Finkel7529c552014-09-02 21:43:13 +0000328}
Mehdi Amini46a43552015-03-04 18:43:29 +0000329
Chandler Carruthdab4eae2016-11-23 17:53:26 +0000330AnalysisKey CFLSteensAA::Key;
Chandler Carruthb4faf132016-03-11 10:22:49 +0000331
Sean Silva36e0d012016-08-09 00:28:15 +0000332CFLSteensAAResult CFLSteensAA::run(Function &F, FunctionAnalysisManager &AM) {
George Burgess IVbfa401e2016-07-06 00:26:41 +0000333 return CFLSteensAAResult(AM.getResult<TargetLibraryAnalysis>(F));
Chandler Carruth7b560d42015-09-09 17:55:00 +0000334}
335
George Burgess IVbfa401e2016-07-06 00:26:41 +0000336char CFLSteensAAWrapperPass::ID = 0;
337INITIALIZE_PASS(CFLSteensAAWrapperPass, "cfl-steens-aa",
338 "Unification-Based CFL Alias Analysis", false, true)
Chandler Carruth7b560d42015-09-09 17:55:00 +0000339
George Burgess IVbfa401e2016-07-06 00:26:41 +0000340ImmutablePass *llvm::createCFLSteensAAWrapperPass() {
341 return new CFLSteensAAWrapperPass();
Chandler Carruth7b560d42015-09-09 17:55:00 +0000342}
343
George Burgess IVbfa401e2016-07-06 00:26:41 +0000344CFLSteensAAWrapperPass::CFLSteensAAWrapperPass() : ImmutablePass(ID) {
345 initializeCFLSteensAAWrapperPassPass(*PassRegistry::getPassRegistry());
346}
347
348void CFLSteensAAWrapperPass::initializePass() {
George Burgess IV18b83fe2016-06-01 18:39:54 +0000349 auto &TLIWP = getAnalysis<TargetLibraryInfoWrapperPass>();
George Burgess IVbfa401e2016-07-06 00:26:41 +0000350 Result.reset(new CFLSteensAAResult(TLIWP.getTLI()));
Chandler Carruth7b560d42015-09-09 17:55:00 +0000351}
352
George Burgess IVbfa401e2016-07-06 00:26:41 +0000353void CFLSteensAAWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const {
Chandler Carruth7b560d42015-09-09 17:55:00 +0000354 AU.setPreservesAll();
George Burgess IV18b83fe2016-06-01 18:39:54 +0000355 AU.addRequired<TargetLibraryInfoWrapperPass>();
Mehdi Amini46a43552015-03-04 18:43:29 +0000356}