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