58 using namespace llvm::cflaa;
60 #define DEBUG_TYPE "cfl-steens-aa"
87 std::numeric_limits<StratifiedIndex>::max();
97 if (
auto *Inst = dyn_cast<Instruction>(Val)) {
98 auto *Bb = Inst->getParent();
99 return Bb->getParent();
102 if (
auto *Arg = dyn_cast<Argument>(Val))
103 return Arg->getParent();
115 if (isa<Constant>(Val)) {
119 bool CanStoreMutableData = isa<GlobalValue>(Val) ||
120 isa<ConstantExpr>(Val) ||
121 isa<ConstantAggregate>(Val);
122 return !CanStoreMutableData;
131 : Sets(std::move(S)) {
146 auto AddToRetParamRelations = [&](
unsigned InterfaceIndex,
152 auto Itr = InterfaceMap.
find(SetIndex);
153 if (Itr != InterfaceMap.
end()) {
154 if (CurrValue != Itr->second)
155 Summary.RetParamRelations.push_back(
161 InterfaceMap.
insert(std::make_pair(SetIndex, CurrValue));
163 if (ExternalAttrs.any())
164 Summary.RetParamAttributes.push_back(
167 if (!
Link.hasBelow())
171 SetIndex =
Link.Below;
176 for (
auto *RetVal : RetVals) {
177 assert(RetVal !=
nullptr);
178 assert(RetVal->getType()->isPointerTy());
180 if (RetInfo.hasValue())
181 AddToRetParamRelations(0, RetInfo->Index);
186 for (
auto &Param : Fn.args()) {
187 if (Param.getType()->isPointerTy()) {
189 if (ParamInfo.hasValue())
190 AddToRetParamRelations(
I + 1, ParamInfo->Index);
202 auto &Graph = GraphBuilder.getCFLGraph();
203 for (
const auto &Mapping : Graph.value_mappings()) {
204 auto Val = Mapping.first;
213 for (
unsigned I = 0,
E =
ValueInfo.getNumLevels() - 1;
I <
E; ++
I) {
223 for (
const auto &Mapping : Graph.value_mappings()) {
224 auto Val = Mapping.first;
229 for (
unsigned I = 0, E =
ValueInfo.getNumLevels();
I <
E; ++
I) {
231 for (
auto &Edge :
ValueInfo.getNodeInfoAtLevel(
I).Edges)
232 SetBuilder.
addWith(Src, Edge.Other);
236 return FunctionInfo(*Fn, GraphBuilder.getReturnValues(), SetBuilder.
build());
242 assert(InsertPair.second &&
243 "Trying to scan a function that has already been cached");
248 auto FunInfo = buildSetsFrom(Fn);
249 Cache[Fn] = std::move(FunInfo);
251 Handles.push_front(FunctionHandle(Fn,
this));
260 auto Iter = Cache.find(Fn);
261 if (Iter == Cache.end()) {
263 Iter = Cache.find(Fn);
264 assert(Iter != Cache.end());
265 assert(Iter->second.hasValue());
272 if (FunInfo.hasValue())
273 return &FunInfo->getAliasSummary();
280 auto *ValA =
const_cast<Value *
>(LocA.
Ptr);
281 auto *ValB =
const_cast<Value *
>(LocB.
Ptr);
283 if (!ValA->getType()->isPointerTy() || !ValB->getType()->isPointerTy())
289 if (!MaybeFnA.hasValue() && !MaybeFnB.hasValue()) {
293 <<
"CFLSteensAA: could not extract parent function information.\n");
297 if (MaybeFnA.hasValue()) {
299 assert((!MaybeFnB.hasValue() || *MaybeFnB == *MaybeFnA) &&
300 "Interprocedural queries not supported");
307 assert(MaybeInfo.hasValue());
309 auto &Sets = MaybeInfo->getStratifiedSets();
311 if (!MaybeA.hasValue())
315 if (!MaybeB.hasValue())
320 auto AttrsA = Sets.getLink(SetA.Index).Attrs;
321 auto AttrsB = Sets.getLink(SetB.Index).Attrs;
333 if (SetA.Index == SetB.Index)
335 if (AttrsA.none() || AttrsB.none())
352 "Unification-Based CFL Alias Analysis",
false,
true)
363 auto &TLIWP = getAnalysis<TargetLibraryInfoWrapperPass>();
const cflaa::AliasSummary * getAliasSummary(Function &Fn)
Get the alias summary for the given function Return nullptr if the summary is not found or not availa...
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
const AliasSummary & getAliasSummary() const
We use ExternalRelation to describe an externally visible aliasing relations between parameters/retur...
StratifiedSets< T > build()
Builds a StratifiedSet from the information we've been given since either construction or the prior b...
This is the result of instantiating InterfaceValue at a particular callsite.
const Optional< FunctionInfo > & ensureCached(Function *Fn)
Ensures that the given function is available in the cache.
The two locations do not alias at all.
FunctionInfo(Function &Fn, const SmallVectorImpl< Value * > &RetVals, StratifiedSets< InstantiatedValue > S)
The two locations may or may not alias. This is the least precise result.
We use ExternalAttribute to describe an externally visible AliasAttrs for parameters/return value...
We use InterfaceValue to describe parameters/return value, as well as potential memory locations that...
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
AnalysisUsage & addRequired()
const StratifiedSets< InstantiatedValue > & getStratifiedSets() const
CFLSteensAAResult run(Function &F, FunctionAnalysisManager &AM)
bool addWith(const T &Main, const T &ToAdd)
A CRTP-driven "mixin" base class to help implement the function alias analysis results concept...
CFLSteensAAResult(const TargetLibraryInfo &)
Legacy wrapper pass to provide the CFLSteensAAResult object.
void scan(Function *Fn)
Inserts the given Function into the cache.
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
This is the interface for LLVM's unification-based alias analysis implemented with CFL graph reachabi...
void initializePass() override
initializePass - This method may be overriden by immutable passes to allow them to perform various in...
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs...ExtraArgs)
Get the result of an analysis pass for a given IR unit.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
AliasResult
The possible results of an alias query.
Represent the analysis usage information of a pass.
bool isGlobalOrArgAttr(AliasAttrs Attr)
AliasResult query(const MemoryLocation &LocA, const MemoryLocation &LocB)
Struct to hold value either by GUID or GlobalValue*.
const Value * Ptr
The address of the start of the location.
Representation for a specific memory location.
ImmutablePass class - This class is used to provide information that does not need to be run...
AliasAttrs getExternallyVisibleAttrs(AliasAttrs Attr)
Given an AliasAttrs, return a new AliasAttrs that only contains attributes meaningful to the caller...
A builder class used to create CFLGraph instance from a given function The CFL-AA that uses this buil...
Provides information about what library functions are available for the current target.
static bool canSkipAddingToSets(Value *Val)
Determines whether it would be pointless to add the given Value to our sets.
bool addBelow(const T &Main, const T &ToAdd)
Restructures the stratified sets as necessary to make "ToAdd" in a set below "Main".
const StratifiedLink & getLink(StratifiedIndex Index) const
Alias summary information.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Information we have about a function and would like to keep around.
void setPreservesAll()
Set by analyses that do not transform their input at all.
This file defines CFLGraph, an auxiliary data structure used by CFL-based alias analysis.
static const int64_t UnknownOffset
INITIALIZE_PASS(CFLSteensAAWrapperPass,"cfl-steens-aa","Unification-Based CFL Alias Analysis", false, true) ImmutablePass *llvm
bool hasUnknownOrCallerAttr(AliasAttrs Attr)
iterator find(const KeyT &Val)
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
ImmutablePass * createCFLSteensAAWrapperPass()
Analysis pass providing the TargetLibraryInfo.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void initializeCFLSteensAAWrapperPassPass(PassRegistry &)
Generic Builder class that produces StratifiedSets instances.
LLVM Value Representation.
static const unsigned MaxSupportedArgsInSummary
The maximum number of arguments we can put into a summary.
A container for analyses that lazily runs them and caches their results.
A special type used by analysis passes to provide an address that identifies that particular analysis...
void noteAttributes(const T &Main, AliasAttrs NewAttrs)
static Optional< Function * > parentFunctionOfValue(Value *)
Try to go from a Value* to a Function*. Never returns nullptr.