Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 515ab47

Browse files
committed
[LoopDataPrefetch] Centralize the tuning cl::opts under the pass
This is effectively NFC, minus the renaming of the options (-cyclone-prefetch-distance -> -prefetch-distance). The change was requested by Tim in D17943. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@264806 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 0a20d99 commit 515ab47

File tree

3 files changed

+42
-26
lines changed

3 files changed

+42
-26
lines changed

lib/Target/AArch64/AArch64TargetTransformInfo.cpp

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,6 @@ using namespace llvm;
2020

2121
#define DEBUG_TYPE "aarch64tti"
2222

23-
static cl::opt<unsigned> CyclonePrefetchDistance(
24-
"cyclone-prefetch-distance",
25-
cl::desc("Number of instructions to prefetch ahead for Cyclone"),
26-
cl::init(280), cl::Hidden);
27-
28-
// The HW prefetcher handles accesses with strides up to 2KB.
29-
static cl::opt<unsigned> CycloneMinPrefetchStride(
30-
"cyclone-min-prefetch-stride",
31-
cl::desc("Min stride to add prefetches for Cyclone"),
32-
cl::init(2048), cl::Hidden);
33-
34-
// Be conservative for now and don't prefetch ahead too much since the loop
35-
// may terminate early.
36-
static cl::opt<unsigned> CycloneMaxPrefetchIterationsAhead(
37-
"cyclone-max-prefetch-iters-ahead",
38-
cl::desc("Max number of iterations to prefetch ahead on Cyclone"),
39-
cl::init(3), cl::Hidden);
40-
4123
/// \brief Calculate the cost of materializing a 64-bit value. This helper
4224
/// method might only calculate a fraction of a larger immediate. Therefore it
4325
/// is valid to return a cost of ZERO.
@@ -600,18 +582,21 @@ unsigned AArch64TTIImpl::getCacheLineSize() {
600582

601583
unsigned AArch64TTIImpl::getPrefetchDistance() {
602584
if (ST->isCyclone())
603-
return CyclonePrefetchDistance;
585+
return 280;
604586
return BaseT::getPrefetchDistance();
605587
}
606588

607589
unsigned AArch64TTIImpl::getMinPrefetchStride() {
608590
if (ST->isCyclone())
609-
return CycloneMinPrefetchStride;
591+
// The HW prefetcher handles accesses with strides up to 2KB.
592+
return 2048;
610593
return BaseT::getMinPrefetchStride();
611594
}
612595

613596
unsigned AArch64TTIImpl::getMaxPrefetchIterationsAhead() {
614597
if (ST->isCyclone())
615-
return CycloneMaxPrefetchIterationsAhead;
598+
// Be conservative for now and don't prefetch ahead too much since the loop
599+
// may terminate early.
600+
return 3;
616601
return BaseT::getMaxPrefetchIterationsAhead();
617602
}

lib/Transforms/Scalar/LoopDataPrefetch.cpp

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,19 @@ static cl::opt<bool>
4343
PrefetchWrites("loop-prefetch-writes", cl::Hidden, cl::init(false),
4444
cl::desc("Prefetch write addresses"));
4545

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+
4659
STATISTIC(NumPrefetches, "Number of prefetches inserted");
4760

4861
namespace llvm {
@@ -79,6 +92,24 @@ namespace {
7992
/// warrant a prefetch.
8093
bool isStrideLargeEnough(const SCEVAddRecExpr *AR);
8194

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+
82113
AssumptionCache *AC;
83114
LoopInfo *LI;
84115
ScalarEvolution *SE;
@@ -100,7 +131,7 @@ INITIALIZE_PASS_END(LoopDataPrefetch, "loop-data-prefetch",
100131
FunctionPass *llvm::createLoopDataPrefetchPass() { return new LoopDataPrefetch(); }
101132

102133
bool LoopDataPrefetch::isStrideLargeEnough(const SCEVAddRecExpr *AR) {
103-
unsigned TargetMinStride = TTI->getMinPrefetchStride();
134+
unsigned TargetMinStride = getMinPrefetchStride();
104135
// No need to check if any stride goes.
105136
if (TargetMinStride <= 1)
106137
return true;
@@ -125,7 +156,7 @@ bool LoopDataPrefetch::runOnFunction(Function &F) {
125156
// If PrefetchDistance is not set, don't run the pass. This gives an
126157
// opportunity for targets to run this pass for selected subtargets only
127158
// (whose TTI sets PrefetchDistance).
128-
if (TTI->getPrefetchDistance() == 0)
159+
if (getPrefetchDistance() == 0)
129160
return false;
130161
assert(TTI->getCacheLineSize() && "Cache line size is not set for target");
131162

@@ -168,11 +199,11 @@ bool LoopDataPrefetch::runOnLoop(Loop *L) {
168199
if (!LoopSize)
169200
LoopSize = 1;
170201

171-
unsigned ItersAhead = TTI->getPrefetchDistance() / LoopSize;
202+
unsigned ItersAhead = getPrefetchDistance() / LoopSize;
172203
if (!ItersAhead)
173204
ItersAhead = 1;
174205

175-
if (ItersAhead > TTI->getMaxPrefetchIterationsAhead())
206+
if (ItersAhead > getMaxPrefetchIterationsAhead())
176207
return MadeChange;
177208

178209
DEBUG(dbgs() << "Prefetching " << ItersAhead

test/Transforms/LoopDataPrefetch/AArch64/large-stride.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; RUN: opt -mcpu=cyclone -mtriple=arm64-apple-ios -loop-data-prefetch -cyclone-max-prefetch-iters-ahead=100 -S < %s | FileCheck %s --check-prefix=LARGE_PREFETCH --check-prefix=ALL
1+
; RUN: opt -mcpu=cyclone -mtriple=arm64-apple-ios -loop-data-prefetch -max-prefetch-iters-ahead=100 -S < %s | FileCheck %s --check-prefix=LARGE_PREFETCH --check-prefix=ALL
22
; RUN: opt -mcpu=cyclone -mtriple=arm64-apple-ios -loop-data-prefetch -S < %s | FileCheck %s --check-prefix=NO_LARGE_PREFETCH --check-prefix=ALL
33
; RUN: opt -mcpu=generic -mtriple=arm64-apple-ios -loop-data-prefetch -S < %s | FileCheck %s --check-prefix=NO_LARGE_PREFETCH --check-prefix=ALL
44

0 commit comments

Comments
 (0)