1
- // ===----------- LoopVersioningLICM.cpp - LICM Loop Versioning ------------===//
1
+ // ===- LoopVersioningLICM.cpp - LICM Loop Versioning ---------- ------------===//
2
2
//
3
3
// The LLVM Compiler Infrastructure
4
4
//
60
60
//
61
61
// ===----------------------------------------------------------------------===//
62
62
63
- #include " llvm/ADT/MapVector.h"
64
- #include " llvm/ADT/SmallPtrSet.h"
65
- #include " llvm/ADT/Statistic.h"
66
- #include " llvm/ADT/StringExtras.h"
63
+ #include " llvm/ADT/SmallVector.h"
64
+ #include " llvm/ADT/StringRef.h"
67
65
#include " llvm/Analysis/AliasAnalysis.h"
68
66
#include " llvm/Analysis/AliasSetTracker.h"
69
- #include " llvm/Analysis/ConstantFolding.h"
70
67
#include " llvm/Analysis/GlobalsModRef.h"
71
68
#include " llvm/Analysis/LoopAccessAnalysis.h"
72
69
#include " llvm/Analysis/LoopInfo.h"
73
70
#include " llvm/Analysis/LoopPass.h"
74
71
#include " llvm/Analysis/ScalarEvolution.h"
75
- #include " llvm/Analysis/ScalarEvolutionExpander.h"
76
- #include " llvm/Analysis/TargetLibraryInfo.h"
77
- #include " llvm/Analysis/ValueTracking.h"
78
- #include " llvm/Analysis/VectorUtils.h"
72
+ #include " llvm/IR/CallSite.h"
73
+ #include " llvm/IR/Constants.h"
79
74
#include " llvm/IR/Dominators.h"
80
- #include " llvm/IR/IntrinsicInst.h"
75
+ #include " llvm/IR/Instruction.h"
76
+ #include " llvm/IR/Instructions.h"
77
+ #include " llvm/IR/LLVMContext.h"
81
78
#include " llvm/IR/MDBuilder.h"
82
- #include " llvm/IR/PatternMatch.h"
83
- #include " llvm/IR/PredIteratorCache.h"
79
+ #include " llvm/IR/Metadata.h"
84
80
#include " llvm/IR/Type.h"
81
+ #include " llvm/IR/Value.h"
82
+ #include " llvm/Pass.h"
83
+ #include " llvm/Support/Casting.h"
84
+ #include " llvm/Support/CommandLine.h"
85
85
#include " llvm/Support/Debug.h"
86
86
#include " llvm/Support/raw_ostream.h"
87
87
#include " llvm/Transforms/Scalar.h"
88
- #include " llvm/Transforms/Utils/BasicBlockUtils.h"
89
- #include " llvm/Transforms/Utils/Cloning.h"
90
88
#include " llvm/Transforms/Utils/LoopUtils.h"
91
89
#include " llvm/Transforms/Utils/LoopVersioning.h"
92
- #include " llvm/Transforms/Utils/ValueMapper.h"
90
+ #include < cassert>
91
+ #include < memory>
92
+
93
+ using namespace llvm ;
93
94
94
95
#define DEBUG_TYPE " loop-versioning-licm"
95
- static const char *LICMVersioningMetaData = " llvm.loop.licm_versioning.disable" ;
96
96
97
- using namespace llvm ;
97
+ static const char *LICMVersioningMetaData = " llvm.loop.licm_versioning.disable " ;
98
98
99
99
// / Threshold minimum allowed percentage for possible
100
100
// / invariant instructions in a loop.
@@ -143,9 +143,16 @@ void llvm::addStringMetadataToLoop(Loop *TheLoop, const char *MDString,
143
143
}
144
144
145
145
namespace {
146
+
146
147
struct LoopVersioningLICM : public LoopPass {
147
148
static char ID;
148
149
150
+ LoopVersioningLICM ()
151
+ : LoopPass(ID), LoopDepthThreshold(LVLoopDepthThreshold),
152
+ InvariantThreshold (LVInvarThreshold) {
153
+ initializeLoopVersioningLICMPass (*PassRegistry::getPassRegistry ());
154
+ }
155
+
149
156
bool runOnLoop (Loop *L, LPPassManager &LPM) override ;
150
157
151
158
void getAnalysisUsage (AnalysisUsage &AU) const override {
@@ -161,13 +168,6 @@ struct LoopVersioningLICM : public LoopPass {
161
168
AU.addPreserved <GlobalsAAWrapperPass>();
162
169
}
163
170
164
- LoopVersioningLICM ()
165
- : LoopPass(ID), AA(nullptr ), SE(nullptr ), LAA(nullptr ), LAI(nullptr ),
166
- CurLoop (nullptr ), LoopDepthThreshold(LVLoopDepthThreshold),
167
- InvariantThreshold(LVInvarThreshold), LoadAndStoreCounter(0 ),
168
- InvariantCounter(0 ), IsReadOnlyLoop(true ) {
169
- initializeLoopVersioningLICMPass (*PassRegistry::getPassRegistry ());
170
- }
171
171
StringRef getPassName () const override { return " Loop Versioning for LICM" ; }
172
172
173
173
void reset () {
@@ -191,30 +191,49 @@ struct LoopVersioningLICM : public LoopPass {
191
191
};
192
192
193
193
private:
194
- AliasAnalysis *AA; // Current AliasAnalysis information
195
- ScalarEvolution *SE; // Current ScalarEvolution
196
- LoopAccessLegacyAnalysis *LAA; // Current LoopAccessAnalysis
197
- const LoopAccessInfo *LAI; // Current Loop's LoopAccessInfo
194
+ // Current AliasAnalysis information
195
+ AliasAnalysis *AA = nullptr ;
196
+
197
+ // Current ScalarEvolution
198
+ ScalarEvolution *SE = nullptr ;
199
+
200
+ // Current LoopAccessAnalysis
201
+ LoopAccessLegacyAnalysis *LAA = nullptr ;
202
+
203
+ // Current Loop's LoopAccessInfo
204
+ const LoopAccessInfo *LAI = nullptr ;
205
+
206
+ // The current loop we are working on.
207
+ Loop *CurLoop = nullptr ;
208
+
209
+ // AliasSet information for the current loop.
210
+ std::unique_ptr<AliasSetTracker> CurAST;
198
211
199
- Loop *CurLoop; // The current loop we are working on.
200
- std::unique_ptr<AliasSetTracker>
201
- CurAST; // AliasSet information for the current loop.
212
+ // Maximum loop nest threshold
213
+ unsigned LoopDepthThreshold;
202
214
203
- unsigned LoopDepthThreshold; // Maximum loop nest threshold
204
- float InvariantThreshold; // Minimum invariant threshold
205
- unsigned LoadAndStoreCounter; // Counter to track num of load & store
206
- unsigned InvariantCounter; // Counter to track num of invariant
207
- bool IsReadOnlyLoop; // Read only loop marker.
215
+ // Minimum invariant threshold
216
+ float InvariantThreshold;
217
+
218
+ // Counter to track num of load & store
219
+ unsigned LoadAndStoreCounter = 0 ;
220
+
221
+ // Counter to track num of invariant
222
+ unsigned InvariantCounter = 0 ;
223
+
224
+ // Read only loop marker.
225
+ bool IsReadOnlyLoop = true ;
208
226
209
227
bool isLegalForVersioning ();
210
228
bool legalLoopStructure ();
211
229
bool legalLoopInstructions ();
212
230
bool legalLoopMemoryAccesses ();
213
231
bool isLoopAlreadyVisited ();
214
- void setNoAliasToLoop (Loop *);
215
- bool instructionSafeForVersioning (Instruction *);
232
+ void setNoAliasToLoop (Loop *VerLoop );
233
+ bool instructionSafeForVersioning (Instruction *I );
216
234
};
217
- }
235
+
236
+ } // end anonymous namespace
218
237
219
238
// / \brief Check loop structure and confirms it's good for LoopVersioningLICM.
220
239
bool LoopVersioningLICM::legalLoopStructure () {
@@ -225,7 +244,7 @@ bool LoopVersioningLICM::legalLoopStructure() {
225
244
return false ;
226
245
}
227
246
// Loop should be innermost loop, if not return false.
228
- if (CurLoop->getSubLoops ().size ()) {
247
+ if (! CurLoop->getSubLoops ().empty ()) {
229
248
DEBUG (dbgs () << " loop is not innermost\n " );
230
249
return false ;
231
250
}
@@ -562,6 +581,7 @@ bool LoopVersioningLICM::runOnLoop(Loop *L, LPPassManager &LPM) {
562
581
}
563
582
564
583
char LoopVersioningLICM::ID = 0 ;
584
+
565
585
INITIALIZE_PASS_BEGIN (LoopVersioningLICM, " loop-versioning-licm" ,
566
586
" Loop Versioning For LICM" , false , false )
567
587
INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass)
0 commit comments