17
17
#include " llvm/ADT/DenseSet.h"
18
18
#include " llvm/ADT/STLExtras.h"
19
19
#include " llvm/ADT/Statistic.h"
20
+ #include " llvm/Analysis/AliasAnalysis.h"
20
21
#include " llvm/Analysis/GlobalsModRef.h"
21
22
#include " llvm/Analysis/CFG.h"
22
23
#include " llvm/Analysis/BlockFrequencyInfoImpl.h"
@@ -91,6 +92,7 @@ namespace {
91
92
bool runOnFunction (Function &F) override ;
92
93
93
94
void getAnalysisUsage (AnalysisUsage &AU) const override {
95
+ AU.addRequired <AAResultsWrapperPass>();
94
96
AU.addRequired <LazyValueInfoWrapperPass>();
95
97
AU.addPreserved <LazyValueInfoWrapperPass>();
96
98
AU.addPreserved <GlobalsAAWrapperPass>();
@@ -106,6 +108,7 @@ INITIALIZE_PASS_BEGIN(JumpThreading, "jump-threading",
106
108
" Jump Threading" , false , false )
107
109
INITIALIZE_PASS_DEPENDENCY(LazyValueInfoWrapperPass)
108
110
INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
111
+ INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass)
109
112
INITIALIZE_PASS_END(JumpThreading, " jump-threading" ,
110
113
" Jump Threading" , false , false )
111
114
@@ -123,6 +126,7 @@ bool JumpThreading::runOnFunction(Function &F) {
123
126
return false ;
124
127
auto TLI = &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI ();
125
128
auto LVI = &getAnalysis<LazyValueInfoWrapperPass>().getLVI ();
129
+ auto AA = &getAnalysis<AAResultsWrapperPass>().getAAResults ();
126
130
std::unique_ptr<BlockFrequencyInfo> BFI;
127
131
std::unique_ptr<BranchProbabilityInfo> BPI;
128
132
bool HasProfileData = F.getEntryCount ().hasValue ();
@@ -131,7 +135,8 @@ bool JumpThreading::runOnFunction(Function &F) {
131
135
BPI.reset (new BranchProbabilityInfo (F, LI));
132
136
BFI.reset (new BlockFrequencyInfo (F, *BPI, LI));
133
137
}
134
- return Impl.runImpl (F, TLI, LVI, HasProfileData, std::move (BFI),
138
+
139
+ return Impl.runImpl (F, TLI, LVI, AA, HasProfileData, std::move (BFI),
135
140
std::move (BPI));
136
141
}
137
142
@@ -140,6 +145,8 @@ PreservedAnalyses JumpThreadingPass::run(Function &F,
140
145
141
146
auto &TLI = AM.getResult <TargetLibraryAnalysis>(F);
142
147
auto &LVI = AM.getResult <LazyValueAnalysis>(F);
148
+ auto &AA = AM.getResult <AAManager>(F);
149
+
143
150
std::unique_ptr<BlockFrequencyInfo> BFI;
144
151
std::unique_ptr<BranchProbabilityInfo> BPI;
145
152
bool HasProfileData = F.getEntryCount ().hasValue ();
@@ -148,8 +155,9 @@ PreservedAnalyses JumpThreadingPass::run(Function &F,
148
155
BPI.reset (new BranchProbabilityInfo (F, LI));
149
156
BFI.reset (new BlockFrequencyInfo (F, *BPI, LI));
150
157
}
151
- bool Changed =
152
- runImpl (F, &TLI, &LVI, HasProfileData, std::move (BFI), std::move (BPI));
158
+
159
+ bool Changed = runImpl (F, &TLI, &LVI, &AA, HasProfileData, std::move (BFI),
160
+ std::move (BPI));
153
161
154
162
if (!Changed)
155
163
return PreservedAnalyses::all ();
@@ -159,13 +167,15 @@ PreservedAnalyses JumpThreadingPass::run(Function &F,
159
167
}
160
168
161
169
bool JumpThreadingPass::runImpl (Function &F, TargetLibraryInfo *TLI_,
162
- LazyValueInfo *LVI_, bool HasProfileData_,
170
+ LazyValueInfo *LVI_, AliasAnalysis *AA_,
171
+ bool HasProfileData_,
163
172
std::unique_ptr<BlockFrequencyInfo> BFI_,
164
173
std::unique_ptr<BranchProbabilityInfo> BPI_) {
165
174
166
175
DEBUG (dbgs () << " Jump threading on function '" << F.getName () << " '\n " );
167
176
TLI = TLI_;
168
177
LVI = LVI_;
178
+ AA = AA_;
169
179
BFI.reset ();
170
180
BPI.reset ();
171
181
// When profile data is available, we need to update edge weights after
@@ -953,8 +963,8 @@ bool JumpThreadingPass::SimplifyPartiallyRedundantLoad(LoadInst *LI) {
953
963
// the entry to its block.
954
964
BasicBlock::iterator BBIt (LI);
955
965
bool IsLoadCSE;
956
- if (Value *AvailableVal =
957
- FindAvailableLoadedValue ( LI, LoadBB, BBIt, DefMaxInstsToScan, nullptr , &IsLoadCSE)) {
966
+ if (Value *AvailableVal = FindAvailableLoadedValue (
967
+ LI, LoadBB, BBIt, DefMaxInstsToScan, AA , &IsLoadCSE)) {
958
968
// If the value of the load is locally available within the block, just use
959
969
// it. This frequently occurs for reg2mem'd allocas.
960
970
@@ -1001,9 +1011,8 @@ bool JumpThreadingPass::SimplifyPartiallyRedundantLoad(LoadInst *LI) {
1001
1011
// Scan the predecessor to see if the value is available in the pred.
1002
1012
BBIt = PredBB->end ();
1003
1013
unsigned NumScanedInst = 0 ;
1004
- Value *PredAvailable =
1005
- FindAvailableLoadedValue (LI, PredBB, BBIt, DefMaxInstsToScan, nullptr ,
1006
- &IsLoadCSE, &NumScanedInst);
1014
+ Value *PredAvailable = FindAvailableLoadedValue (
1015
+ LI, PredBB, BBIt, DefMaxInstsToScan, AA, &IsLoadCSE, &NumScanedInst);
1007
1016
1008
1017
// If PredBB has a single predecessor, continue scanning through the single
1009
1018
// predecessor.
@@ -1014,8 +1023,8 @@ bool JumpThreadingPass::SimplifyPartiallyRedundantLoad(LoadInst *LI) {
1014
1023
if (SinglePredBB) {
1015
1024
BBIt = SinglePredBB->end ();
1016
1025
PredAvailable = FindAvailableLoadedValue (
1017
- LI, SinglePredBB, BBIt, (DefMaxInstsToScan - NumScanedInst),
1018
- nullptr , &IsLoadCSE, &NumScanedInst);
1026
+ LI, SinglePredBB, BBIt, (DefMaxInstsToScan - NumScanedInst), AA,
1027
+ &IsLoadCSE, &NumScanedInst);
1019
1028
}
1020
1029
}
1021
1030
0 commit comments