@@ -43,6 +43,19 @@ static cl::opt<bool>
43
43
PrefetchWrites (" loop-prefetch-writes" , cl::Hidden, cl::init(false ),
44
44
cl::desc(" Prefetch write addresses" ));
45
45
46
+ static cl::opt<unsigned >
47
+ PrefetchDistance (" prefetch-distance" ,
48
+ cl::desc (" Number of instructions to prefetch ahead" ),
49
+ cl::Hidden);
50
+
51
+ static cl::opt<unsigned >
52
+ MinPrefetchStride (" min-prefetch-stride" ,
53
+ cl::desc (" Min stride to add prefetches" ), cl::Hidden);
54
+
55
+ static cl::opt<unsigned > MaxPrefetchIterationsAhead (
56
+ " max-prefetch-iters-ahead" ,
57
+ cl::desc (" Max number of iterations to prefetch ahead" ), cl::Hidden);
58
+
46
59
STATISTIC (NumPrefetches, " Number of prefetches inserted" );
47
60
48
61
namespace llvm {
@@ -79,6 +92,24 @@ namespace {
79
92
// / warrant a prefetch.
80
93
bool isStrideLargeEnough (const SCEVAddRecExpr *AR);
81
94
95
+ unsigned getMinPrefetchStride () {
96
+ if (MinPrefetchStride.getNumOccurrences () > 0 )
97
+ return MinPrefetchStride;
98
+ return TTI->getMinPrefetchStride ();
99
+ }
100
+
101
+ unsigned getPrefetchDistance () {
102
+ if (PrefetchDistance.getNumOccurrences () > 0 )
103
+ return PrefetchDistance;
104
+ return TTI->getPrefetchDistance ();
105
+ }
106
+
107
+ unsigned getMaxPrefetchIterationsAhead () {
108
+ if (MaxPrefetchIterationsAhead.getNumOccurrences () > 0 )
109
+ return MaxPrefetchIterationsAhead;
110
+ return TTI->getMaxPrefetchIterationsAhead ();
111
+ }
112
+
82
113
AssumptionCache *AC;
83
114
LoopInfo *LI;
84
115
ScalarEvolution *SE;
@@ -100,7 +131,7 @@ INITIALIZE_PASS_END(LoopDataPrefetch, "loop-data-prefetch",
100
131
FunctionPass *llvm::createLoopDataPrefetchPass() { return new LoopDataPrefetch (); }
101
132
102
133
bool LoopDataPrefetch::isStrideLargeEnough (const SCEVAddRecExpr *AR) {
103
- unsigned TargetMinStride = TTI-> getMinPrefetchStride ();
134
+ unsigned TargetMinStride = getMinPrefetchStride ();
104
135
// No need to check if any stride goes.
105
136
if (TargetMinStride <= 1 )
106
137
return true ;
@@ -125,7 +156,7 @@ bool LoopDataPrefetch::runOnFunction(Function &F) {
125
156
// If PrefetchDistance is not set, don't run the pass. This gives an
126
157
// opportunity for targets to run this pass for selected subtargets only
127
158
// (whose TTI sets PrefetchDistance).
128
- if (TTI-> getPrefetchDistance () == 0 )
159
+ if (getPrefetchDistance () == 0 )
129
160
return false ;
130
161
assert (TTI->getCacheLineSize () && " Cache line size is not set for target" );
131
162
@@ -168,11 +199,11 @@ bool LoopDataPrefetch::runOnLoop(Loop *L) {
168
199
if (!LoopSize)
169
200
LoopSize = 1 ;
170
201
171
- unsigned ItersAhead = TTI-> getPrefetchDistance () / LoopSize;
202
+ unsigned ItersAhead = getPrefetchDistance () / LoopSize;
172
203
if (!ItersAhead)
173
204
ItersAhead = 1 ;
174
205
175
- if (ItersAhead > TTI-> getMaxPrefetchIterationsAhead ())
206
+ if (ItersAhead > getMaxPrefetchIterationsAhead ())
176
207
return MadeChange;
177
208
178
209
DEBUG (dbgs () << " Prefetching " << ItersAhead
0 commit comments