annotate lib/Analysis/AliasAnalysis.cpp @ 128:c347d3398279 default tip

fix
author mir3636
date Wed, 06 Dec 2017 14:37:17 +0900
parents 803732b1fca8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
1 //==- AliasAnalysis.cpp - Generic Alias Analysis Interface Implementation --==//
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 //
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 // The LLVM Compiler Infrastructure
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 //
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 // This file is distributed under the University of Illinois Open Source
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 // License. See LICENSE.TXT for details.
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 //
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 //===----------------------------------------------------------------------===//
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 //
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 // This file implements the generic AliasAnalysis interface which is used as the
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 // common interface used by all clients and implementations of alias analysis.
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 //
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 // This file also implements the default version of the AliasAnalysis interface
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 // that is to be used when no other implementation is specified. This does some
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 // simple tests that detect obvious cases: two different global pointers cannot
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 // alias, a global cannot alias a malloc, two different mallocs cannot alias,
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 // etc.
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 //
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 // This alias analysis implementation really isn't very good for anything, but
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 // it is very fast, and makes a nice clean default implementation. Because it
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 // handles lots of little corner cases, other, more complex, alias analysis
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 // implementations may choose to rely on this pass to resolve these simple and
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 // easy cases.
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 //
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 //===----------------------------------------------------------------------===//
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 #include "llvm/Analysis/AliasAnalysis.h"
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
28 #include "llvm/Analysis/BasicAliasAnalysis.h"
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
29 #include "llvm/Analysis/CFLAndersAliasAnalysis.h"
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
30 #include "llvm/Analysis/CFLSteensAliasAnalysis.h"
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 #include "llvm/Analysis/CaptureTracking.h"
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
32 #include "llvm/Analysis/GlobalsModRef.h"
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
33 #include "llvm/Analysis/MemoryLocation.h"
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
34 #include "llvm/Analysis/ObjCARCAliasAnalysis.h"
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
35 #include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h"
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
36 #include "llvm/Analysis/ScopedNoAliasAA.h"
83
60c9769439b8 LLVM 3.7
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 77
diff changeset
37 #include "llvm/Analysis/TargetLibraryInfo.h"
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
38 #include "llvm/Analysis/TypeBasedAliasAnalysis.h"
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 #include "llvm/Analysis/ValueTracking.h"
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
40 #include "llvm/IR/Argument.h"
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
41 #include "llvm/IR/Attributes.h"
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 #include "llvm/IR/BasicBlock.h"
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
43 #include "llvm/IR/CallSite.h"
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
44 #include "llvm/IR/Instruction.h"
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 #include "llvm/IR/Instructions.h"
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
46 #include "llvm/IR/Module.h"
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 #include "llvm/IR/Type.h"
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
48 #include "llvm/IR/Value.h"
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 #include "llvm/Pass.h"
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
50 #include "llvm/Support/AtomicOrdering.h"
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
51 #include "llvm/Support/Casting.h"
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
52 #include "llvm/Support/CommandLine.h"
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
53 #include <algorithm>
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
54 #include <cassert>
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
55 #include <functional>
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
56 #include <iterator>
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
57
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 using namespace llvm;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
59
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
60 /// Allow disabling BasicAA from the AA results. This is particularly useful
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
61 /// when testing to isolate a single AA implementation.
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
62 static cl::opt<bool> DisableBasicAA("disable-basicaa", cl::Hidden,
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
63 cl::init(false));
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
64
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
65 AAResults::AAResults(AAResults &&Arg)
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
66 : TLI(Arg.TLI), AAs(std::move(Arg.AAs)), AADeps(std::move(Arg.AADeps)) {
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
67 for (auto &AA : AAs)
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
68 AA->setAAResults(this);
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
69 }
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
70
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
71 AAResults::~AAResults() {
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
72 // FIXME; It would be nice to at least clear out the pointers back to this
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
73 // aggregation here, but we end up with non-nesting lifetimes in the legacy
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
74 // pass manager that prevent this from working. In the legacy pass manager
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
75 // we'll end up with dangling references here in some cases.
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
76 #if 0
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
77 for (auto &AA : AAs)
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
78 AA->setAAResults(nullptr);
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
79 #endif
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
80 }
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
81
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
82 bool AAResults::invalidate(Function &F, const PreservedAnalyses &PA,
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
83 FunctionAnalysisManager::Invalidator &Inv) {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
84 // Check if the AA manager itself has been invalidated.
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
85 auto PAC = PA.getChecker<AAManager>();
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
86 if (!PAC.preserved() && !PAC.preservedSet<AllAnalysesOn<Function>>())
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
87 return true; // The manager needs to be blown away, clear everything.
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
88
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
89 // Check all of the dependencies registered.
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
90 for (AnalysisKey *ID : AADeps)
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
91 if (Inv.invalidate(ID, F, PA))
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
92 return true;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
93
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
94 // Everything we depend on is still fine, so are we. Nothing to invalidate.
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
95 return false;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
96 }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
97
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
98 //===----------------------------------------------------------------------===//
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
99 // Default chaining methods
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
100 //===----------------------------------------------------------------------===//
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
101
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
102 AliasResult AAResults::alias(const MemoryLocation &LocA,
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
103 const MemoryLocation &LocB) {
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
104 for (const auto &AA : AAs) {
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
105 auto Result = AA->alias(LocA, LocB);
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
106 if (Result != MayAlias)
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
107 return Result;
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
108 }
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
109 return MayAlias;
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
110 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
111
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
112 bool AAResults::pointsToConstantMemory(const MemoryLocation &Loc,
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
113 bool OrLocal) {
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
114 for (const auto &AA : AAs)
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
115 if (AA->pointsToConstantMemory(Loc, OrLocal))
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
116 return true;
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
117
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
118 return false;
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
119 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
120
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
121 ModRefInfo AAResults::getArgModRefInfo(ImmutableCallSite CS, unsigned ArgIdx) {
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
122 ModRefInfo Result = MRI_ModRef;
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
123
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
124 for (const auto &AA : AAs) {
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
125 Result = ModRefInfo(Result & AA->getArgModRefInfo(CS, ArgIdx));
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
126
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
127 // Early-exit the moment we reach the bottom of the lattice.
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
128 if (Result == MRI_NoModRef)
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
129 return Result;
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
130 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
131
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
132 return Result;
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
133 }
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
134
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
135 ModRefInfo AAResults::getModRefInfo(Instruction *I, ImmutableCallSite Call) {
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
136 // We may have two calls
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
137 if (auto CS = ImmutableCallSite(I)) {
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
138 // Check if the two calls modify the same memory
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
139 return getModRefInfo(CS, Call);
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
140 } else if (I->isFenceLike()) {
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
141 // If this is a fence, just return MRI_ModRef.
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
142 return MRI_ModRef;
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
143 } else {
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
144 // Otherwise, check if the call modifies or references the
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
145 // location this memory access defines. The best we can say
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
146 // is that if the call references what this instruction
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
147 // defines, it must be clobbered by this location.
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
148 const MemoryLocation DefLoc = MemoryLocation::get(I);
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
149 if (getModRefInfo(Call, DefLoc) != MRI_NoModRef)
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
150 return MRI_ModRef;
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
151 }
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
152 return MRI_NoModRef;
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
153 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
154
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
155 ModRefInfo AAResults::getModRefInfo(ImmutableCallSite CS,
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
156 const MemoryLocation &Loc) {
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
157 ModRefInfo Result = MRI_ModRef;
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
158
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
159 for (const auto &AA : AAs) {
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
160 Result = ModRefInfo(Result & AA->getModRefInfo(CS, Loc));
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
161
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
162 // Early-exit the moment we reach the bottom of the lattice.
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
163 if (Result == MRI_NoModRef)
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
164 return Result;
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
165 }
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
166
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
167 // Try to refine the mod-ref info further using other API entry points to the
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
168 // aggregate set of AA results.
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
169 auto MRB = getModRefBehavior(CS);
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
170 if (MRB == FMRB_DoesNotAccessMemory ||
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
171 MRB == FMRB_OnlyAccessesInaccessibleMem)
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
172 return MRI_NoModRef;
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
173
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
174 if (onlyReadsMemory(MRB))
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
175 Result = ModRefInfo(Result & MRI_Ref);
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
176 else if (doesNotReadMemory(MRB))
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
177 Result = ModRefInfo(Result & MRI_Mod);
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
178
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
179 if (onlyAccessesArgPointees(MRB) || onlyAccessesInaccessibleOrArgMem(MRB)) {
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
180 bool DoesAlias = false;
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
181 ModRefInfo AllArgsMask = MRI_NoModRef;
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
182 if (doesAccessArgPointees(MRB)) {
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
183 for (auto AI = CS.arg_begin(), AE = CS.arg_end(); AI != AE; ++AI) {
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
184 const Value *Arg = *AI;
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
185 if (!Arg->getType()->isPointerTy())
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
186 continue;
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
187 unsigned ArgIdx = std::distance(CS.arg_begin(), AI);
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
188 MemoryLocation ArgLoc = MemoryLocation::getForArgument(CS, ArgIdx, TLI);
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
189 AliasResult ArgAlias = alias(ArgLoc, Loc);
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
190 if (ArgAlias != NoAlias) {
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
191 ModRefInfo ArgMask = getArgModRefInfo(CS, ArgIdx);
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
192 DoesAlias = true;
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
193 AllArgsMask = ModRefInfo(AllArgsMask | ArgMask);
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
194 }
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
195 }
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
196 }
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
197 if (!DoesAlias)
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
198 return MRI_NoModRef;
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
199 Result = ModRefInfo(Result & AllArgsMask);
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
200 }
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
201
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
202 // If Loc is a constant memory location, the call definitely could not
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
203 // modify the memory location.
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
204 if ((Result & MRI_Mod) &&
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
205 pointsToConstantMemory(Loc, /*OrLocal*/ false))
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
206 Result = ModRefInfo(Result & ~MRI_Mod);
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
207
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
208 return Result;
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
209 }
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
210
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
211 ModRefInfo AAResults::getModRefInfo(ImmutableCallSite CS1,
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
212 ImmutableCallSite CS2) {
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
213 ModRefInfo Result = MRI_ModRef;
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
214
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
215 for (const auto &AA : AAs) {
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
216 Result = ModRefInfo(Result & AA->getModRefInfo(CS1, CS2));
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
217
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
218 // Early-exit the moment we reach the bottom of the lattice.
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
219 if (Result == MRI_NoModRef)
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
220 return Result;
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
221 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
222
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
223 // Try to refine the mod-ref info further using other API entry points to the
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
224 // aggregate set of AA results.
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
225
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
226 // If CS1 or CS2 are readnone, they don't interact.
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
227 auto CS1B = getModRefBehavior(CS1);
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
228 if (CS1B == FMRB_DoesNotAccessMemory)
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
229 return MRI_NoModRef;
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
230
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
231 auto CS2B = getModRefBehavior(CS2);
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
232 if (CS2B == FMRB_DoesNotAccessMemory)
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
233 return MRI_NoModRef;
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
234
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
235 // If they both only read from memory, there is no dependence.
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
236 if (onlyReadsMemory(CS1B) && onlyReadsMemory(CS2B))
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
237 return MRI_NoModRef;
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
238
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
239 // If CS1 only reads memory, the only dependence on CS2 can be
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
240 // from CS1 reading memory written by CS2.
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
241 if (onlyReadsMemory(CS1B))
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
242 Result = ModRefInfo(Result & MRI_Ref);
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
243 else if (doesNotReadMemory(CS1B))
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
244 Result = ModRefInfo(Result & MRI_Mod);
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
245
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
246 // If CS2 only access memory through arguments, accumulate the mod/ref
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
247 // information from CS1's references to the memory referenced by
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
248 // CS2's arguments.
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
249 if (onlyAccessesArgPointees(CS2B)) {
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
250 ModRefInfo R = MRI_NoModRef;
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
251 if (doesAccessArgPointees(CS2B)) {
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
252 for (auto I = CS2.arg_begin(), E = CS2.arg_end(); I != E; ++I) {
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
253 const Value *Arg = *I;
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
254 if (!Arg->getType()->isPointerTy())
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
255 continue;
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
256 unsigned CS2ArgIdx = std::distance(CS2.arg_begin(), I);
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
257 auto CS2ArgLoc = MemoryLocation::getForArgument(CS2, CS2ArgIdx, TLI);
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
258
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
259 // ArgMask indicates what CS2 might do to CS2ArgLoc, and the dependence
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
260 // of CS1 on that location is the inverse.
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
261 ModRefInfo ArgMask = getArgModRefInfo(CS2, CS2ArgIdx);
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
262 if (ArgMask == MRI_Mod)
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
263 ArgMask = MRI_ModRef;
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
264 else if (ArgMask == MRI_Ref)
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
265 ArgMask = MRI_Mod;
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
266
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
267 ArgMask = ModRefInfo(ArgMask & getModRefInfo(CS1, CS2ArgLoc));
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
268
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
269 R = ModRefInfo((R | ArgMask) & Result);
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
270 if (R == Result)
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
271 break;
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
272 }
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
273 }
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
274 return R;
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
275 }
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
276
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
277 // If CS1 only accesses memory through arguments, check if CS2 references
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
278 // any of the memory referenced by CS1's arguments. If not, return NoModRef.
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
279 if (onlyAccessesArgPointees(CS1B)) {
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
280 ModRefInfo R = MRI_NoModRef;
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
281 if (doesAccessArgPointees(CS1B)) {
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
282 for (auto I = CS1.arg_begin(), E = CS1.arg_end(); I != E; ++I) {
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
283 const Value *Arg = *I;
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
284 if (!Arg->getType()->isPointerTy())
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
285 continue;
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
286 unsigned CS1ArgIdx = std::distance(CS1.arg_begin(), I);
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
287 auto CS1ArgLoc = MemoryLocation::getForArgument(CS1, CS1ArgIdx, TLI);
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
288
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
289 // ArgMask indicates what CS1 might do to CS1ArgLoc; if CS1 might Mod
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
290 // CS1ArgLoc, then we care about either a Mod or a Ref by CS2. If CS1
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
291 // might Ref, then we care only about a Mod by CS2.
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
292 ModRefInfo ArgMask = getArgModRefInfo(CS1, CS1ArgIdx);
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
293 ModRefInfo ArgR = getModRefInfo(CS2, CS1ArgLoc);
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
294 if (((ArgMask & MRI_Mod) != MRI_NoModRef &&
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
295 (ArgR & MRI_ModRef) != MRI_NoModRef) ||
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
296 ((ArgMask & MRI_Ref) != MRI_NoModRef &&
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
297 (ArgR & MRI_Mod) != MRI_NoModRef))
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
298 R = ModRefInfo((R | ArgMask) & Result);
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
299
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
300 if (R == Result)
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
301 break;
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
302 }
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
303 }
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
304 return R;
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
305 }
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
306
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
307 return Result;
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
308 }
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
309
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
310 FunctionModRefBehavior AAResults::getModRefBehavior(ImmutableCallSite CS) {
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
311 FunctionModRefBehavior Result = FMRB_UnknownModRefBehavior;
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
312
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
313 for (const auto &AA : AAs) {
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
314 Result = FunctionModRefBehavior(Result & AA->getModRefBehavior(CS));
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
315
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
316 // Early-exit the moment we reach the bottom of the lattice.
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
317 if (Result == FMRB_DoesNotAccessMemory)
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
318 return Result;
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
319 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
320
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
321 return Result;
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
322 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
323
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
324 FunctionModRefBehavior AAResults::getModRefBehavior(const Function *F) {
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
325 FunctionModRefBehavior Result = FMRB_UnknownModRefBehavior;
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
326
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
327 for (const auto &AA : AAs) {
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
328 Result = FunctionModRefBehavior(Result & AA->getModRefBehavior(F));
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
329
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
330 // Early-exit the moment we reach the bottom of the lattice.
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
331 if (Result == FMRB_DoesNotAccessMemory)
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
332 return Result;
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
333 }
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
334
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
335 return Result;
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
336 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
337
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
338 //===----------------------------------------------------------------------===//
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
339 // Helper method implementation
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
340 //===----------------------------------------------------------------------===//
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
341
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
342 ModRefInfo AAResults::getModRefInfo(const LoadInst *L,
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
343 const MemoryLocation &Loc) {
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
344 // Be conservative in the face of atomic.
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
345 if (isStrongerThan(L->getOrdering(), AtomicOrdering::Unordered))
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
346 return MRI_ModRef;
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
347
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
348 // If the load address doesn't alias the given address, it doesn't read
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
349 // or write the specified memory.
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
350 if (Loc.Ptr && !alias(MemoryLocation::get(L), Loc))
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
351 return MRI_NoModRef;
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
352
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
353 // Otherwise, a load just reads.
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
354 return MRI_Ref;
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
355 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
356
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
357 ModRefInfo AAResults::getModRefInfo(const StoreInst *S,
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
358 const MemoryLocation &Loc) {
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
359 // Be conservative in the face of atomic.
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
360 if (isStrongerThan(S->getOrdering(), AtomicOrdering::Unordered))
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
361 return MRI_ModRef;
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
362
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
363 if (Loc.Ptr) {
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
364 // If the store address cannot alias the pointer in question, then the
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
365 // specified memory cannot be modified by the store.
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
366 if (!alias(MemoryLocation::get(S), Loc))
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
367 return MRI_NoModRef;
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
368
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
369 // If the pointer is a pointer to constant memory, then it could not have
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
370 // been modified by this store.
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
371 if (pointsToConstantMemory(Loc))
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
372 return MRI_NoModRef;
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
373 }
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
374
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
375 // Otherwise, a store just writes.
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
376 return MRI_Mod;
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
377 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
378
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
379 ModRefInfo AAResults::getModRefInfo(const FenceInst *S, const MemoryLocation &Loc) {
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
380 // If we know that the location is a constant memory location, the fence
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
381 // cannot modify this location.
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
382 if (Loc.Ptr && pointsToConstantMemory(Loc))
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
383 return MRI_Ref;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
384 return MRI_ModRef;
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
385 }
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
386
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
387 ModRefInfo AAResults::getModRefInfo(const VAArgInst *V,
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
388 const MemoryLocation &Loc) {
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
389 if (Loc.Ptr) {
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
390 // If the va_arg address cannot alias the pointer in question, then the
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
391 // specified memory cannot be accessed by the va_arg.
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
392 if (!alias(MemoryLocation::get(V), Loc))
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
393 return MRI_NoModRef;
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
394
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
395 // If the pointer is a pointer to constant memory, then it could not have
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
396 // been modified by this va_arg.
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
397 if (pointsToConstantMemory(Loc))
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
398 return MRI_NoModRef;
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
399 }
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
400
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
401 // Otherwise, a va_arg reads and writes.
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
402 return MRI_ModRef;
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
403 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
404
100
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
405 ModRefInfo AAResults::getModRefInfo(const CatchPadInst *CatchPad,
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
406 const MemoryLocation &Loc) {
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
407 if (Loc.Ptr) {
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
408 // If the pointer is a pointer to constant memory,
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
409 // then it could not have been modified by this catchpad.
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
410 if (pointsToConstantMemory(Loc))
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
411 return MRI_NoModRef;
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
412 }
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
413
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
414 // Otherwise, a catchpad reads and writes.
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
415 return MRI_ModRef;
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
416 }
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
417
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
418 ModRefInfo AAResults::getModRefInfo(const CatchReturnInst *CatchRet,
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
419 const MemoryLocation &Loc) {
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
420 if (Loc.Ptr) {
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
421 // If the pointer is a pointer to constant memory,
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
422 // then it could not have been modified by this catchpad.
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
423 if (pointsToConstantMemory(Loc))
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
424 return MRI_NoModRef;
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
425 }
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
426
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
427 // Otherwise, a catchret reads and writes.
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
428 return MRI_ModRef;
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
429 }
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
430
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
431 ModRefInfo AAResults::getModRefInfo(const AtomicCmpXchgInst *CX,
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
432 const MemoryLocation &Loc) {
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
433 // Acquire/Release cmpxchg has properties that matter for arbitrary addresses.
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
434 if (isStrongerThanMonotonic(CX->getSuccessOrdering()))
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
435 return MRI_ModRef;
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
436
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
437 // If the cmpxchg address does not alias the location, it does not access it.
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
438 if (Loc.Ptr && !alias(MemoryLocation::get(CX), Loc))
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
439 return MRI_NoModRef;
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
440
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
441 return MRI_ModRef;
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
442 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
443
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
444 ModRefInfo AAResults::getModRefInfo(const AtomicRMWInst *RMW,
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
445 const MemoryLocation &Loc) {
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
446 // Acquire/Release atomicrmw has properties that matter for arbitrary addresses.
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
447 if (isStrongerThanMonotonic(RMW->getOrdering()))
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
448 return MRI_ModRef;
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
449
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
450 // If the atomicrmw address does not alias the location, it does not access it.
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
451 if (Loc.Ptr && !alias(MemoryLocation::get(RMW), Loc))
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
452 return MRI_NoModRef;
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
453
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
454 return MRI_ModRef;
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
455 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
456
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
457 /// \brief Return information about whether a particular call site modifies
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
458 /// or reads the specified memory location \p MemLoc before instruction \p I
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
459 /// in a BasicBlock. A ordered basic block \p OBB can be used to speed up
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
460 /// instruction-ordering queries inside the BasicBlock containing \p I.
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
461 /// FIXME: this is really just shoring-up a deficiency in alias analysis.
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
462 /// BasicAA isn't willing to spend linear time determining whether an alloca
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
463 /// was captured before or after this particular call, while we are. However,
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
464 /// with a smarter AA in place, this test is just wasting compile time.
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
465 ModRefInfo AAResults::callCapturesBefore(const Instruction *I,
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
466 const MemoryLocation &MemLoc,
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
467 DominatorTree *DT,
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
468 OrderedBasicBlock *OBB) {
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
469 if (!DT)
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
470 return MRI_ModRef;
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
471
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
472 const Value *Object =
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
473 GetUnderlyingObject(MemLoc.Ptr, I->getModule()->getDataLayout());
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
474 if (!isIdentifiedObject(Object) || isa<GlobalValue>(Object) ||
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
475 isa<Constant>(Object))
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
476 return MRI_ModRef;
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
477
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
478 ImmutableCallSite CS(I);
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
479 if (!CS.getInstruction() || CS.getInstruction() == Object)
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
480 return MRI_ModRef;
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
481
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
482 if (PointerMayBeCapturedBefore(Object, /* ReturnCaptures */ true,
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
483 /* StoreCaptures */ true, I, DT,
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
484 /* include Object */ true,
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
485 /* OrderedBasicBlock */ OBB))
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
486 return MRI_ModRef;
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
487
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
488 unsigned ArgNo = 0;
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
489 ModRefInfo R = MRI_NoModRef;
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
490 for (auto CI = CS.data_operands_begin(), CE = CS.data_operands_end();
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
491 CI != CE; ++CI, ++ArgNo) {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
492 // Only look at the no-capture or byval pointer arguments. If this
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
493 // pointer were passed to arguments that were neither of these, then it
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
494 // couldn't be no-capture.
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
495 if (!(*CI)->getType()->isPointerTy() ||
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
496 (!CS.doesNotCapture(ArgNo) &&
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
497 ArgNo < CS.getNumArgOperands() && !CS.isByValArgument(ArgNo)))
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
498 continue;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
499
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
500 // If this is a no-capture pointer argument, see if we can tell that it
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
501 // is impossible to alias the pointer we're checking. If not, we have to
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
502 // assume that the call could touch the pointer, even though it doesn't
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
503 // escape.
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
504 if (isNoAlias(MemoryLocation(*CI), MemoryLocation(Object)))
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
505 continue;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
506 if (CS.doesNotAccessMemory(ArgNo))
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
507 continue;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
508 if (CS.onlyReadsMemory(ArgNo)) {
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
509 R = MRI_Ref;
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
510 continue;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
511 }
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
512 return MRI_ModRef;
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
513 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
514 return R;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
515 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
516
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
517 /// canBasicBlockModify - Return true if it is possible for execution of the
83
60c9769439b8 LLVM 3.7
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 77
diff changeset
518 /// specified basic block to modify the location Loc.
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
519 ///
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
520 bool AAResults::canBasicBlockModify(const BasicBlock &BB,
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
521 const MemoryLocation &Loc) {
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
522 return canInstructionRangeModRef(BB.front(), BB.back(), Loc, MRI_Mod);
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
523 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
524
83
60c9769439b8 LLVM 3.7
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 77
diff changeset
525 /// canInstructionRangeModRef - Return true if it is possible for the
60c9769439b8 LLVM 3.7
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 77
diff changeset
526 /// execution of the specified instructions to mod\ref (according to the
60c9769439b8 LLVM 3.7
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 77
diff changeset
527 /// mode) the location Loc. The instructions to consider are all
60c9769439b8 LLVM 3.7
Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp>
parents: 77
diff changeset
528 /// of the instructions in the range of [I1,I2] INCLUSIVE.
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
529 /// I1 and I2 must be in the same basic block.
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
530 bool AAResults::canInstructionRangeModRef(const Instruction &I1,
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
531 const Instruction &I2,
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
532 const MemoryLocation &Loc,
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
533 const ModRefInfo Mode) {
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
534 assert(I1.getParent() == I2.getParent() &&
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
535 "Instructions not in same basic block!");
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
536 BasicBlock::const_iterator I = I1.getIterator();
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
537 BasicBlock::const_iterator E = I2.getIterator();
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
538 ++E; // Convert from inclusive to exclusive range.
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
539
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
540 for (; I != E; ++I) // Check every instruction in range
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
541 if (getModRefInfo(&*I, Loc) & Mode)
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
542 return true;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
543 return false;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
544 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
545
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
546 // Provide a definition for the root virtual destructor.
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
547 AAResults::Concept::~Concept() = default;
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
548
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
549 // Provide a definition for the static object used to identify passes.
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
550 AnalysisKey AAManager::Key;
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
551
100
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
552 namespace {
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
553
100
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
554 /// A wrapper pass for external alias analyses. This just squirrels away the
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
555 /// callback used to run any analyses and register their results.
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
556 struct ExternalAAWrapperPass : ImmutablePass {
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
557 using CallbackT = std::function<void(Pass &, Function &, AAResults &)>;
100
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
558
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
559 CallbackT CB;
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
560
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
561 static char ID;
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
562
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
563 ExternalAAWrapperPass() : ImmutablePass(ID) {
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
564 initializeExternalAAWrapperPassPass(*PassRegistry::getPassRegistry());
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
565 }
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
566
100
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
567 explicit ExternalAAWrapperPass(CallbackT CB)
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
568 : ImmutablePass(ID), CB(std::move(CB)) {
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
569 initializeExternalAAWrapperPassPass(*PassRegistry::getPassRegistry());
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
570 }
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
571
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
572 void getAnalysisUsage(AnalysisUsage &AU) const override {
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
573 AU.setPreservesAll();
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
574 }
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
575 };
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
576
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
577 } // end anonymous namespace
100
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
578
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
579 char ExternalAAWrapperPass::ID = 0;
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
580
100
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
581 INITIALIZE_PASS(ExternalAAWrapperPass, "external-aa", "External Alias Analysis",
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
582 false, true)
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
583
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
584 ImmutablePass *
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
585 llvm::createExternalAAWrapperPass(ExternalAAWrapperPass::CallbackT Callback) {
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
586 return new ExternalAAWrapperPass(std::move(Callback));
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
587 }
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
588
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
589 AAResultsWrapperPass::AAResultsWrapperPass() : FunctionPass(ID) {
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
590 initializeAAResultsWrapperPassPass(*PassRegistry::getPassRegistry());
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
591 }
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
592
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
593 char AAResultsWrapperPass::ID = 0;
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
594
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
595 INITIALIZE_PASS_BEGIN(AAResultsWrapperPass, "aa",
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
596 "Function Alias Analysis Results", false, true)
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
597 INITIALIZE_PASS_DEPENDENCY(BasicAAWrapperPass)
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
598 INITIALIZE_PASS_DEPENDENCY(CFLAndersAAWrapperPass)
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
599 INITIALIZE_PASS_DEPENDENCY(CFLSteensAAWrapperPass)
100
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
600 INITIALIZE_PASS_DEPENDENCY(ExternalAAWrapperPass)
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
601 INITIALIZE_PASS_DEPENDENCY(GlobalsAAWrapperPass)
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
602 INITIALIZE_PASS_DEPENDENCY(ObjCARCAAWrapperPass)
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
603 INITIALIZE_PASS_DEPENDENCY(SCEVAAWrapperPass)
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
604 INITIALIZE_PASS_DEPENDENCY(ScopedNoAliasAAWrapperPass)
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
605 INITIALIZE_PASS_DEPENDENCY(TypeBasedAAWrapperPass)
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
606 INITIALIZE_PASS_END(AAResultsWrapperPass, "aa",
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
607 "Function Alias Analysis Results", false, true)
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
608
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
609 FunctionPass *llvm::createAAResultsWrapperPass() {
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
610 return new AAResultsWrapperPass();
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
611 }
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
612
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
613 /// Run the wrapper pass to rebuild an aggregation over known AA passes.
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
614 ///
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
615 /// This is the legacy pass manager's interface to the new-style AA results
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
616 /// aggregation object. Because this is somewhat shoe-horned into the legacy
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
617 /// pass manager, we hard code all the specific alias analyses available into
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
618 /// it. While the particular set enabled is configured via commandline flags,
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
619 /// adding a new alias analysis to LLVM will require adding support for it to
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
620 /// this list.
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
621 bool AAResultsWrapperPass::runOnFunction(Function &F) {
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
622 // NB! This *must* be reset before adding new AA results to the new
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
623 // AAResults object because in the legacy pass manager, each instance
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
624 // of these will refer to the *same* immutable analyses, registering and
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
625 // unregistering themselves with them. We need to carefully tear down the
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
626 // previous object first, in this case replacing it with an empty one, before
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
627 // registering new results.
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
628 AAR.reset(
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
629 new AAResults(getAnalysis<TargetLibraryInfoWrapperPass>().getTLI()));
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
630
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
631 // BasicAA is always available for function analyses. Also, we add it first
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
632 // so that it can trump TBAA results when it proves MustAlias.
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
633 // FIXME: TBAA should have an explicit mode to support this and then we
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
634 // should reconsider the ordering here.
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
635 if (!DisableBasicAA)
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
636 AAR->addAAResult(getAnalysis<BasicAAWrapperPass>().getResult());
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
637
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
638 // Populate the results with the currently available AAs.
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
639 if (auto *WrapperPass = getAnalysisIfAvailable<ScopedNoAliasAAWrapperPass>())
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
640 AAR->addAAResult(WrapperPass->getResult());
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
641 if (auto *WrapperPass = getAnalysisIfAvailable<TypeBasedAAWrapperPass>())
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
642 AAR->addAAResult(WrapperPass->getResult());
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
643 if (auto *WrapperPass =
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
644 getAnalysisIfAvailable<objcarc::ObjCARCAAWrapperPass>())
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
645 AAR->addAAResult(WrapperPass->getResult());
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
646 if (auto *WrapperPass = getAnalysisIfAvailable<GlobalsAAWrapperPass>())
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
647 AAR->addAAResult(WrapperPass->getResult());
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
648 if (auto *WrapperPass = getAnalysisIfAvailable<SCEVAAWrapperPass>())
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
649 AAR->addAAResult(WrapperPass->getResult());
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
650 if (auto *WrapperPass = getAnalysisIfAvailable<CFLAndersAAWrapperPass>())
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
651 AAR->addAAResult(WrapperPass->getResult());
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
652 if (auto *WrapperPass = getAnalysisIfAvailable<CFLSteensAAWrapperPass>())
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
653 AAR->addAAResult(WrapperPass->getResult());
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
654
100
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
655 // If available, run an external AA providing callback over the results as
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
656 // well.
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
657 if (auto *WrapperPass = getAnalysisIfAvailable<ExternalAAWrapperPass>())
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
658 if (WrapperPass->CB)
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
659 WrapperPass->CB(*this, F, *AAR);
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
660
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
661 // Analyses don't mutate the IR, so return false.
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
662 return false;
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
663 }
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
664
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
665 void AAResultsWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const {
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
666 AU.setPreservesAll();
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
667 AU.addRequired<BasicAAWrapperPass>();
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
668 AU.addRequired<TargetLibraryInfoWrapperPass>();
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
669
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
670 // We also need to mark all the alias analysis passes we will potentially
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
671 // probe in runOnFunction as used here to ensure the legacy pass manager
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
672 // preserves them. This hard coding of lists of alias analyses is specific to
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
673 // the legacy pass manager.
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
674 AU.addUsedIfAvailable<ScopedNoAliasAAWrapperPass>();
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
675 AU.addUsedIfAvailable<TypeBasedAAWrapperPass>();
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
676 AU.addUsedIfAvailable<objcarc::ObjCARCAAWrapperPass>();
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
677 AU.addUsedIfAvailable<GlobalsAAWrapperPass>();
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
678 AU.addUsedIfAvailable<SCEVAAWrapperPass>();
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
679 AU.addUsedIfAvailable<CFLAndersAAWrapperPass>();
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
680 AU.addUsedIfAvailable<CFLSteensAAWrapperPass>();
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
681 }
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
682
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
683 AAResults llvm::createLegacyPMAAResults(Pass &P, Function &F,
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
684 BasicAAResult &BAR) {
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
685 AAResults AAR(P.getAnalysis<TargetLibraryInfoWrapperPass>().getTLI());
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
686
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
687 // Add in our explicitly constructed BasicAA results.
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
688 if (!DisableBasicAA)
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
689 AAR.addAAResult(BAR);
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
690
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
691 // Populate the results with the other currently available AAs.
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
692 if (auto *WrapperPass =
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
693 P.getAnalysisIfAvailable<ScopedNoAliasAAWrapperPass>())
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
694 AAR.addAAResult(WrapperPass->getResult());
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
695 if (auto *WrapperPass = P.getAnalysisIfAvailable<TypeBasedAAWrapperPass>())
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
696 AAR.addAAResult(WrapperPass->getResult());
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
697 if (auto *WrapperPass =
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
698 P.getAnalysisIfAvailable<objcarc::ObjCARCAAWrapperPass>())
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
699 AAR.addAAResult(WrapperPass->getResult());
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
700 if (auto *WrapperPass = P.getAnalysisIfAvailable<GlobalsAAWrapperPass>())
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
701 AAR.addAAResult(WrapperPass->getResult());
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
702 if (auto *WrapperPass = P.getAnalysisIfAvailable<CFLAndersAAWrapperPass>())
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
703 AAR.addAAResult(WrapperPass->getResult());
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
704 if (auto *WrapperPass = P.getAnalysisIfAvailable<CFLSteensAAWrapperPass>())
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
705 AAR.addAAResult(WrapperPass->getResult());
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
706
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
707 return AAR;
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
708 }
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
709
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
710 bool llvm::isNoAliasCall(const Value *V) {
95
afa8332a0e37 LLVM 3.8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
711 if (auto CS = ImmutableCallSite(V))
121
803732b1fca8 LLVM 5.0
kono
parents: 120
diff changeset
712 return CS.hasRetAttr(Attribute::NoAlias);
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
713 return false;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
714 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
715
100
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
716 bool llvm::isNoAliasArgument(const Value *V) {
0
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
717 if (const Argument *A = dyn_cast<Argument>(V))
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
718 return A->hasNoAliasAttr();
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
719 return false;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
720 }
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
721
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
722 bool llvm::isIdentifiedObject(const Value *V) {
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
723 if (isa<AllocaInst>(V))
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
724 return true;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
725 if (isa<GlobalValue>(V) && !isa<GlobalAlias>(V))
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
726 return true;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
727 if (isNoAliasCall(V))
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
728 return true;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
729 if (const Argument *A = dyn_cast<Argument>(V))
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
730 return A->hasNoAliasAttr() || A->hasByValAttr();
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
731 return false;
95c75e76d11b LLVM 3.4
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
732 }
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
733
100
7d135dc70f03 LLVM 3.9
Miyagi Mitsuki <e135756@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
734 bool llvm::isIdentifiedFunctionLocal(const Value *V) {
77
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
735 return isa<AllocaInst>(V) || isNoAliasCall(V) || isNoAliasArgument(V);
54457678186b LLVM 3.6
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
736 }
120
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
737
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
738 void llvm::getAAResultsAnalysisUsage(AnalysisUsage &AU) {
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
739 // This function needs to be in sync with llvm::createLegacyPMAAResults -- if
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
740 // more alias analyses are added to llvm::createLegacyPMAAResults, they need
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
741 // to be added here also.
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
742 AU.addRequired<TargetLibraryInfoWrapperPass>();
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
743 AU.addUsedIfAvailable<ScopedNoAliasAAWrapperPass>();
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
744 AU.addUsedIfAvailable<TypeBasedAAWrapperPass>();
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
745 AU.addUsedIfAvailable<objcarc::ObjCARCAAWrapperPass>();
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
746 AU.addUsedIfAvailable<GlobalsAAWrapperPass>();
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
747 AU.addUsedIfAvailable<CFLAndersAAWrapperPass>();
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
748 AU.addUsedIfAvailable<CFLSteensAAWrapperPass>();
1172e4bd9c6f update 4.0.0
mir3636
parents: 100
diff changeset
749 }