LLVM  9.0.0svn
AliasAnalysisSummary.cpp
Go to the documentation of this file.
1 #include "AliasAnalysisSummary.h"
2 #include "llvm/IR/Argument.h"
3 #include "llvm/IR/Type.h"
5 
6 namespace llvm {
7 namespace cflaa {
8 
9 namespace {
10 const unsigned AttrEscapedIndex = 0;
11 const unsigned AttrUnknownIndex = 1;
12 const unsigned AttrGlobalIndex = 2;
13 const unsigned AttrCallerIndex = 3;
14 const unsigned AttrFirstArgIndex = 4;
15 const unsigned AttrLastArgIndex = NumAliasAttrs;
16 const unsigned AttrMaxNumArgs = AttrLastArgIndex - AttrFirstArgIndex;
17 
18 // It would be *slightly* prettier if we changed these to AliasAttrs, but it
19 // seems that both GCC and MSVC emit dynamic initializers for const bitsets.
20 using AliasAttr = unsigned;
21 const AliasAttr AttrNone = 0;
22 const AliasAttr AttrEscaped = 1 << AttrEscapedIndex;
23 const AliasAttr AttrUnknown = 1 << AttrUnknownIndex;
24 const AliasAttr AttrGlobal = 1 << AttrGlobalIndex;
25 const AliasAttr AttrCaller = 1 << AttrCallerIndex;
26 const AliasAttr ExternalAttrMask = AttrEscaped | AttrUnknown | AttrGlobal;
27 }
28 
29 AliasAttrs getAttrNone() { return AttrNone; }
30 
31 AliasAttrs getAttrUnknown() { return AttrUnknown; }
32 bool hasUnknownAttr(AliasAttrs Attr) { return Attr.test(AttrUnknownIndex); }
33 
34 AliasAttrs getAttrCaller() { return AttrCaller; }
35 bool hasCallerAttr(AliasAttrs Attr) { return Attr.test(AttrCaller); }
37  return Attr.test(AttrUnknownIndex) || Attr.test(AttrCallerIndex);
38 }
39 
40 AliasAttrs getAttrEscaped() { return AttrEscaped; }
41 bool hasEscapedAttr(AliasAttrs Attr) { return Attr.test(AttrEscapedIndex); }
42 
43 static AliasAttr argNumberToAttr(unsigned ArgNum) {
44  if (ArgNum >= AttrMaxNumArgs)
45  return AttrUnknown;
46  // N.B. MSVC complains if we use `1U` here, since AliasAttr' ctor takes
47  // an unsigned long long.
48  return AliasAttr(1ULL << (ArgNum + AttrFirstArgIndex));
49 }
50 
52  if (isa<GlobalValue>(Val))
53  return AttrGlobal;
54 
55  if (auto *Arg = dyn_cast<Argument>(&Val))
56  // Only pointer arguments should have the argument attribute,
57  // because things can't escape through scalars without us seeing a
58  // cast, and thus, interaction with them doesn't matter.
59  if (!Arg->hasNoAliasAttr() && Arg->getType()->isPointerTy())
60  return argNumberToAttr(Arg->getArgNo());
61  return AttrNone;
62 }
63 
65  return Attr.reset(AttrEscapedIndex)
66  .reset(AttrUnknownIndex)
67  .reset(AttrCallerIndex)
68  .any();
69 }
70 
72  return Attr & AliasAttrs(ExternalAttrMask);
73 }
74 
76  CallBase &Call) {
77  auto Index = IValue.Index;
78  auto *V = (Index == 0) ? &Call : Call.getArgOperand(Index - 1);
79  if (V->getType()->isPointerTy())
80  return InstantiatedValue{V, IValue.DerefLevel};
81  return None;
82 }
83 
86  auto From = instantiateInterfaceValue(ERelation.From, Call);
87  if (!From)
88  return None;
89  auto To = instantiateInterfaceValue(ERelation.To, Call);
90  if (!To)
91  return None;
92  return InstantiatedRelation{*From, *To, ERelation.Offset};
93 }
94 
96  CallBase &Call) {
97  auto Value = instantiateInterfaceValue(EAttr.IValue, Call);
98  if (!Value)
99  return None;
100  return InstantiatedAttr{*Value, EAttr.Attr};
101 }
102 }
103 }
const NoneType None
Definition: None.h:23
static const unsigned NumAliasAttrs
The number of attributes that AliasAttr should contain.
This class represents lattice values for constants.
Definition: AllocatorList.h:23
We use ExternalRelation to describe an externally visible aliasing relations between parameters/retur...
This is the result of instantiating InterfaceValue at a particular call.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition: InstrTypes.h:1100
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...
Value * getArgOperand(unsigned i) const
Definition: InstrTypes.h:1241
Optional< InstantiatedAttr > instantiateExternalAttribute(ExternalAttribute EAttr, CallBase &Call)
Optional< InstantiatedValue > instantiateInterfaceValue(InterfaceValue IValue, CallBase &Call)
Optional< InstantiatedRelation > instantiateExternalRelation(ExternalRelation ERelation, CallBase &Call)
static AliasAttr argNumberToAttr(unsigned ArgNum)
AliasAttrs getAttrEscaped()
AttrEscaped represent whether the said pointer comes from a known source but escapes to the unknown w...
bool hasUnknownAttr(AliasAttrs Attr)
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
bool isGlobalOrArgAttr(AliasAttrs Attr)
AliasAttrs getAttrUnknown()
AttrUnknown represent whether the said pointer comes from a source not known to alias analyses (such ...
BlockVerifier::State From
AliasAttrs getExternallyVisibleAttrs(AliasAttrs Attr)
Given an AliasAttrs, return a new AliasAttrs that only contains attributes meaningful to the caller...
This file defines various utility types and functions useful to summary-based alias analysis...
AliasAttrs getGlobalOrArgAttrFromValue(const Value &Val)
AttrGlobal represent whether the said pointer is a global value.
bool hasUnknownOrCallerAttr(AliasAttrs Attr)
std::bitset< NumAliasAttrs > AliasAttrs
These are attributes that an alias analysis can use to mark certain special properties of a given poi...
bool hasCallerAttr(AliasAttrs Attr)
AliasAttrs getAttrCaller()
AttrCaller represent whether the said pointer comes from a source not known to the current function b...
This is the result of instantiating ExternalRelation at a particular callsite.
bool hasEscapedAttr(AliasAttrs Attr)
LLVM Value Representation.
Definition: Value.h:72
AliasAttrs getAttrNone()
Attr represent whether the said pointer comes from an unknown source (such as opaque memory or an int...
This is the result of instantiating ExternalAttribute at a particular callsite.