[PATCH] [LoopAccesses] Stash the report from the analysis rather than emitting it

Adam Nemet anemet at apple.com
Mon Feb 16 14:19:39 PST 2015


Hi hfinkel, aschwaighofer, nadav,

The transformation passes will query this and then emit them as part of
their own report.  The currently only user LV is modified to do just
that.

This is part of the patchset that converts LoopAccessAnalysis into an
actual analysis pass.

http://reviews.llvm.org/D7681

Files:
  include/llvm/Analysis/LoopAccessAnalysis.h
  lib/Analysis/LoopAccessAnalysis.cpp
  lib/Transforms/Vectorize/LoopVectorize.cpp

Index: include/llvm/Analysis/LoopAccessAnalysis.h
===================================================================
--- include/llvm/Analysis/LoopAccessAnalysis.h
+++ include/llvm/Analysis/LoopAccessAnalysis.h
@@ -16,6 +16,7 @@
 #define LLVM_ANALYSIS_LOOPACCESSANALYSIS_H
 
 #include "llvm/ADT/EquivalenceClasses.h"
+#include "llvm/ADT/Optional.h"
 #include "llvm/ADT/SetVector.h"
 #include "llvm/Analysis/AliasAnalysis.h"
 #include "llvm/Analysis/AliasSetTracker.h"
@@ -113,11 +114,11 @@
     SmallVector<unsigned, 2> AliasSetId;
   };
 
-  LoopAccessInfo(Function *F, Loop *L, ScalarEvolution *SE,
-                 const DataLayout *DL, const TargetLibraryInfo *TLI,
-                 AliasAnalysis *AA, DominatorTree *DT) :
-      TheFunction(F), TheLoop(L), SE(SE), DL(DL), TLI(TLI), AA(AA), DT(DT),
-      NumLoads(0), NumStores(0), MaxSafeDepDistBytes(-1U) {}
+  LoopAccessInfo(Loop *L, ScalarEvolution *SE, const DataLayout *DL,
+                 const TargetLibraryInfo *TLI, AliasAnalysis *AA,
+                 DominatorTree *DT) :
+      TheLoop(L), SE(SE), DL(DL), TLI(TLI), AA(AA), DT(DT), NumLoads(0),
+      NumStores(0), MaxSafeDepDistBytes(-1U) {}
 
   /// Return true we can analyze the memory accesses in the loop and there are
   /// no memory dependence cycles.  Replaces symbolic strides using Strides.
@@ -143,13 +144,16 @@
   /// second value is the final comparator value or NULL if no check is needed.
   std::pair<Instruction *, Instruction *> addRuntimeCheck(Instruction *Loc);
 
+  /// \brief The diagnostics report generated for the analysis.  E.g. why we
+  /// couldn't analyze the loop.
+  Optional<VectorizationReport> &getReport() { return Report; }
+
 private:
   void emitAnalysis(VectorizationReport &Message);
 
   /// We need to check that all of the pointers in this list are disjoint
   /// at runtime.
   RuntimePointerCheck PtrRtCheck;
-  Function *TheFunction;
   Loop *TheLoop;
   ScalarEvolution *SE;
   const DataLayout *DL;
@@ -161,6 +165,10 @@
   unsigned NumStores;
 
   unsigned MaxSafeDepDistBytes;
+
+  /// \brief The diagnostics report generated for the analysis.  E.g. why we
+  /// couldn't analyze the loop.
+  Optional<VectorizationReport> Report;
 };
 
 Value *stripIntegerCast(Value *V);
Index: lib/Analysis/LoopAccessAnalysis.cpp
===================================================================
--- lib/Analysis/LoopAccessAnalysis.cpp
+++ lib/Analysis/LoopAccessAnalysis.cpp
@@ -1077,7 +1077,8 @@
 }
 
 void LoopAccessInfo::emitAnalysis(VectorizationReport &Message) {
-  VectorizationReport::emitAnalysis(Message, TheFunction, TheLoop);
+  assert(!Report && "Multiple report generated");
+  Report = Message;
 }
 
 bool LoopAccessInfo::isUniform(Value *V) {
Index: lib/Transforms/Vectorize/LoopVectorize.cpp
===================================================================
--- lib/Transforms/Vectorize/LoopVectorize.cpp
+++ lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -556,7 +556,7 @@
       : NumPredStores(0), TheLoop(L), SE(SE), DL(DL),
         TLI(TLI), TheFunction(F), TTI(TTI), Induction(nullptr),
         WidestIndTy(nullptr),
-        LAI(F, L, SE, DL, TLI, AA, DT),
+        LAI(L, SE, DL, TLI, AA, DT),
         HasFunNoNaNAttr(false) {}
 
   /// This enum represents the kinds of reductions that we support.
@@ -3826,7 +3826,11 @@
 }
 
 bool LoopVectorizationLegality::canVectorizeMemory() {
-  return LAI.canVectorizeMemory(Strides);
+  bool Success = LAI.canVectorizeMemory(Strides);
+  auto &OptionalReport = LAI.getReport();
+  if (OptionalReport)
+    emitAnalysis(*OptionalReport);
+  return Success;
 }
 
 static bool hasMultipleUsesOf(Instruction *I,

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D7681.20050.patch
Type: text/x-patch
Size: 3646 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150216/7c1d283f/attachment.bin>


More information about the llvm-commits mailing list