[llvm] r264806 - [LoopDataPrefetch] Centralize the tuning cl::opts under the pass

Adam Nemet via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 29 16:45:53 PDT 2016


Author: anemet
Date: Tue Mar 29 18:45:52 2016
New Revision: 264806

URL: http://llvm.org/viewvc/llvm-project?rev=264806&view=rev
Log:
[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.

Modified:
    llvm/trunk/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
    llvm/trunk/lib/Transforms/Scalar/LoopDataPrefetch.cpp
    llvm/trunk/test/Transforms/LoopDataPrefetch/AArch64/large-stride.ll

Modified: llvm/trunk/lib/Target/AArch64/AArch64TargetTransformInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AArch64/AArch64TargetTransformInfo.cpp?rev=264806&r1=264805&r2=264806&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AArch64/AArch64TargetTransformInfo.cpp (original)
+++ llvm/trunk/lib/Target/AArch64/AArch64TargetTransformInfo.cpp Tue Mar 29 18:45:52 2016
@@ -20,24 +20,6 @@ using namespace llvm;
 
 #define DEBUG_TYPE "aarch64tti"
 
-static cl::opt<unsigned> CyclonePrefetchDistance(
-    "cyclone-prefetch-distance",
-    cl::desc("Number of instructions to prefetch ahead for Cyclone"),
-    cl::init(280), cl::Hidden);
-
-// The HW prefetcher handles accesses with strides up to 2KB.
-static cl::opt<unsigned> CycloneMinPrefetchStride(
-    "cyclone-min-prefetch-stride",
-    cl::desc("Min stride to add prefetches for Cyclone"),
-    cl::init(2048), cl::Hidden);
-
-// Be conservative for now and don't prefetch ahead too much since the loop
-// may terminate early.
-static cl::opt<unsigned> CycloneMaxPrefetchIterationsAhead(
-    "cyclone-max-prefetch-iters-ahead",
-    cl::desc("Max number of iterations to prefetch ahead on Cyclone"),
-    cl::init(3), cl::Hidden);
-
 /// \brief Calculate the cost of materializing a 64-bit value. This helper
 /// method might only calculate a fraction of a larger immediate. Therefore it
 /// is valid to return a cost of ZERO.
@@ -600,18 +582,21 @@ unsigned AArch64TTIImpl::getCacheLineSiz
 
 unsigned AArch64TTIImpl::getPrefetchDistance() {
   if (ST->isCyclone())
-    return CyclonePrefetchDistance;
+    return 280;
   return BaseT::getPrefetchDistance();
 }
 
 unsigned AArch64TTIImpl::getMinPrefetchStride() {
   if (ST->isCyclone())
-    return CycloneMinPrefetchStride;
+    // The HW prefetcher handles accesses with strides up to 2KB.
+    return 2048;
   return BaseT::getMinPrefetchStride();
 }
 
 unsigned AArch64TTIImpl::getMaxPrefetchIterationsAhead() {
   if (ST->isCyclone())
-    return CycloneMaxPrefetchIterationsAhead;
+    // Be conservative for now and don't prefetch ahead too much since the loop
+    // may terminate early.
+    return 3;
   return BaseT::getMaxPrefetchIterationsAhead();
 }

Modified: llvm/trunk/lib/Transforms/Scalar/LoopDataPrefetch.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopDataPrefetch.cpp?rev=264806&r1=264805&r2=264806&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LoopDataPrefetch.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LoopDataPrefetch.cpp Tue Mar 29 18:45:52 2016
@@ -43,6 +43,19 @@ static cl::opt<bool>
 PrefetchWrites("loop-prefetch-writes", cl::Hidden, cl::init(false),
                cl::desc("Prefetch write addresses"));
 
+static cl::opt<unsigned>
+    PrefetchDistance("prefetch-distance",
+                     cl::desc("Number of instructions to prefetch ahead"),
+                     cl::Hidden);
+
+static cl::opt<unsigned>
+    MinPrefetchStride("min-prefetch-stride",
+                      cl::desc("Min stride to add prefetches"), cl::Hidden);
+
+static cl::opt<unsigned> MaxPrefetchIterationsAhead(
+    "max-prefetch-iters-ahead",
+    cl::desc("Max number of iterations to prefetch ahead"), cl::Hidden);
+
 STATISTIC(NumPrefetches, "Number of prefetches inserted");
 
 namespace llvm {
@@ -79,6 +92,24 @@ namespace {
     /// warrant a prefetch.
     bool isStrideLargeEnough(const SCEVAddRecExpr *AR);
 
+    unsigned getMinPrefetchStride() {
+      if (MinPrefetchStride.getNumOccurrences() > 0)
+        return MinPrefetchStride;
+      return TTI->getMinPrefetchStride();
+    }
+
+    unsigned getPrefetchDistance() {
+      if (PrefetchDistance.getNumOccurrences() > 0)
+        return PrefetchDistance;
+      return TTI->getPrefetchDistance();
+    }
+
+    unsigned getMaxPrefetchIterationsAhead() {
+      if (MaxPrefetchIterationsAhead.getNumOccurrences() > 0)
+        return MaxPrefetchIterationsAhead;
+      return TTI->getMaxPrefetchIterationsAhead();
+    }
+
     AssumptionCache *AC;
     LoopInfo *LI;
     ScalarEvolution *SE;
@@ -100,7 +131,7 @@ INITIALIZE_PASS_END(LoopDataPrefetch, "l
 FunctionPass *llvm::createLoopDataPrefetchPass() { return new LoopDataPrefetch(); }
 
 bool LoopDataPrefetch::isStrideLargeEnough(const SCEVAddRecExpr *AR) {
-  unsigned TargetMinStride = TTI->getMinPrefetchStride();
+  unsigned TargetMinStride = getMinPrefetchStride();
   // No need to check if any stride goes.
   if (TargetMinStride <= 1)
     return true;
@@ -125,7 +156,7 @@ bool LoopDataPrefetch::runOnFunction(Fun
   // If PrefetchDistance is not set, don't run the pass.  This gives an
   // opportunity for targets to run this pass for selected subtargets only
   // (whose TTI sets PrefetchDistance).
-  if (TTI->getPrefetchDistance() == 0)
+  if (getPrefetchDistance() == 0)
     return false;
   assert(TTI->getCacheLineSize() && "Cache line size is not set for target");
 
@@ -168,11 +199,11 @@ bool LoopDataPrefetch::runOnLoop(Loop *L
   if (!LoopSize)
     LoopSize = 1;
 
-  unsigned ItersAhead = TTI->getPrefetchDistance() / LoopSize;
+  unsigned ItersAhead = getPrefetchDistance() / LoopSize;
   if (!ItersAhead)
     ItersAhead = 1;
 
-  if (ItersAhead > TTI->getMaxPrefetchIterationsAhead())
+  if (ItersAhead > getMaxPrefetchIterationsAhead())
     return MadeChange;
 
   DEBUG(dbgs() << "Prefetching " << ItersAhead

Modified: llvm/trunk/test/Transforms/LoopDataPrefetch/AArch64/large-stride.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LoopDataPrefetch/AArch64/large-stride.ll?rev=264806&r1=264805&r2=264806&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/LoopDataPrefetch/AArch64/large-stride.ll (original)
+++ llvm/trunk/test/Transforms/LoopDataPrefetch/AArch64/large-stride.ll Tue Mar 29 18:45:52 2016
@@ -1,4 +1,4 @@
-; 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
+; 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
 ; RUN: opt -mcpu=cyclone -mtriple=arm64-apple-ios -loop-data-prefetch -S < %s | FileCheck %s --check-prefix=NO_LARGE_PREFETCH --check-prefix=ALL
 ; RUN: opt -mcpu=generic -mtriple=arm64-apple-ios -loop-data-prefetch -S < %s | FileCheck %s --check-prefix=NO_LARGE_PREFETCH --check-prefix=ALL
 




More information about the llvm-commits mailing list