[polly] r187102 - ScopDetect: Only track detection failures if actually needed.

Tobias Grosser tobias at grosser.es
Wed Jul 24 20:02:30 PDT 2013


Author: grosser
Date: Wed Jul 24 22:02:29 2013
New Revision: 187102

URL: http://llvm.org/viewvc/llvm-project?rev=187102&view=rev
Log:
ScopDetect: Only track detection failures if actually needed.

String operations resulted by raw_string_ostream in the INVALID macro can lead
to significant compile-time overhead when compiling large size source code.
This is because raw_string_ostream relies on TypeFinder class, whose
compile-time cost increases as the size of the module increases. This patch
targets to ensure that it only track detection failures if actually needed.
In this way, we can avoid expensive string operations in normal execution.

With this patch file, the relative compile-time cost of Polly-detect pass does
not increase even when compiling very large size source code.

Contributed-by:   Star Tan <tanmx_star at yeah.net>

Modified:
    polly/trunk/include/polly/ScopDetection.h
    polly/trunk/lib/Analysis/ScopDetection.cpp
    polly/trunk/lib/RegisterPasses.cpp

Modified: polly/trunk/include/polly/ScopDetection.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/ScopDetection.h?rev=187102&r1=187101&r2=187102&view=diff
==============================================================================
--- polly/trunk/include/polly/ScopDetection.h (original)
+++ polly/trunk/include/polly/ScopDetection.h Wed Jul 24 22:02:29 2013
@@ -72,6 +72,8 @@ class Value;
 namespace polly {
 typedef std::set<const SCEV *> ParamSetType;
 
+extern bool PollyTrackFailures;
+
 //===----------------------------------------------------------------------===//
 /// @brief Pass to detect the maximal static control parts (Scops) of a
 /// function.
@@ -145,6 +147,13 @@ class ScopDetection : public FunctionPas
   /// @return True if the call instruction is valid, false otherwise.
   static bool isValidCallInst(CallInst &CI);
 
+  /// @brief Format the invalid alias message.
+  ///
+  /// @param AS The alias set.
+  ///
+  /// @return The failure message why the alias is invalid.
+  std::string formatInvalidAlias(AliasSet &AS) const;
+
   /// @brief Check if a memory access can be part of a Scop.
   ///
   /// @param Inst The instruction accessing the memory.

Modified: polly/trunk/lib/Analysis/ScopDetection.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/Analysis/ScopDetection.cpp?rev=187102&r1=187101&r2=187102&view=diff
==============================================================================
--- polly/trunk/lib/Analysis/ScopDetection.cpp (original)
+++ polly/trunk/lib/Analysis/ScopDetection.cpp Wed Jul 24 22:02:29 2013
@@ -98,6 +98,14 @@ AllowNonAffine("polly-allow-nonaffine",
                cl::desc("Allow non affine access functions in arrays"),
                cl::Hidden, cl::init(false), cl::cat(PollyCategory));
 
+static cl::opt<bool, true>
+TrackFailures("polly-detect-track-failures",
+              cl::desc("Track failure strings in detecting scop regions"),
+              cl::location(PollyTrackFailures), cl::Hidden, cl::init(false),
+              cl::cat(PollyCategory));
+
+bool polly::PollyTrackFailures = false;
+
 //===----------------------------------------------------------------------===//
 // Statistics.
 
@@ -108,11 +116,13 @@ STATISTIC(ValidRegion, "Number of region
 
 #define INVALID(NAME, MESSAGE)                                                 \
   do {                                                                         \
-    std::string Buf;                                                           \
-    raw_string_ostream fmt(Buf);                                               \
-    fmt << MESSAGE;                                                            \
-    fmt.flush();                                                               \
-    LastFailure = Buf;                                                         \
+    if (PollyTrackFailures) {                                                  \
+      std::string Buf;                                                         \
+      raw_string_ostream fmt(Buf);                                             \
+      fmt << MESSAGE;                                                          \
+      fmt.flush();                                                             \
+      LastFailure = Buf;                                                       \
+    }                                                                          \
     DEBUG(dbgs() << MESSAGE);                                                  \
     DEBUG(dbgs() << "\n");                                                     \
     assert(!Context.Verifying &&#NAME);                                        \
@@ -122,11 +132,13 @@ STATISTIC(ValidRegion, "Number of region
 
 #define INVALID_NOVERIFY(NAME, MESSAGE)                                        \
   do {                                                                         \
-    std::string Buf;                                                           \
-    raw_string_ostream fmt(Buf);                                               \
-    fmt << MESSAGE;                                                            \
-    fmt.flush();                                                               \
-    LastFailure = Buf;                                                         \
+    if (PollyTrackFailures) {                                                  \
+      std::string Buf;                                                         \
+      raw_string_ostream fmt(Buf);                                             \
+      fmt << MESSAGE;                                                          \
+      fmt.flush();                                                             \
+      LastFailure = Buf;                                                       \
+    }                                                                          \
     DEBUG(dbgs() << MESSAGE);                                                  \
     DEBUG(dbgs() << "\n");                                                     \
     /* DISABLED: assert(!Context.Verifying && #NAME); */                       \
@@ -256,6 +268,40 @@ bool ScopDetection::isValidCallInst(Call
   return false;
 }
 
+std::string ScopDetection::formatInvalidAlias(AliasSet &AS) const {
+  std::string Message;
+  raw_string_ostream OS(Message);
+
+  OS << "Possible aliasing: ";
+
+  std::vector<Value *> Pointers;
+
+  for (AliasSet::iterator AI = AS.begin(), AE = AS.end(); AI != AE; ++AI)
+    Pointers.push_back(AI.getPointer());
+
+  std::sort(Pointers.begin(), Pointers.end());
+
+  for (std::vector<Value *>::iterator PI = Pointers.begin(),
+                                      PE = Pointers.end();
+       ;) {
+    Value *V = *PI;
+
+    if (V->getName().size() == 0)
+      OS << "\"" << *V << "\"";
+    else
+      OS << "\"" << V->getName() << "\"";
+
+    ++PI;
+
+    if (PI != PE)
+      OS << ", ";
+    else
+      break;
+  }
+
+  return OS.str();
+}
+
 bool ScopDetection::isValidMemoryAccess(Instruction &Inst,
                                         DetectionContext &Context) const {
   Value *Ptr = getPointerOperand(Inst);
@@ -310,37 +356,7 @@ bool ScopDetection::isValidMemoryAccess(
   // not proof this without -basicaa we would fail. We disable this check to
   // not cause irrelevant verification failures.
   if (!AS.isMustAlias()) {
-    std::string Message;
-    raw_string_ostream OS(Message);
-
-    OS << "Possible aliasing: ";
-
-    std::vector<Value *> Pointers;
-
-    for (AliasSet::iterator AI = AS.begin(), AE = AS.end(); AI != AE; ++AI)
-      Pointers.push_back(AI.getPointer());
-
-    std::sort(Pointers.begin(), Pointers.end());
-
-    for (std::vector<Value *>::iterator PI = Pointers.begin(),
-                                        PE = Pointers.end();
-         ;) {
-      Value *V = *PI;
-
-      if (V->getName().size() == 0)
-        OS << "\"" << *V << "\"";
-      else
-        OS << "\"" << V->getName() << "\"";
-
-      ++PI;
-
-      if (PI != PE)
-        OS << ", ";
-      else
-        break;
-    }
-
-    INVALID_NOVERIFY(Alias, OS.str());
+    INVALID_NOVERIFY(Alias, formatInvalidAlias(AS));
     return false;
   }
 

Modified: polly/trunk/lib/RegisterPasses.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/RegisterPasses.cpp?rev=187102&r1=187101&r2=187102&view=diff
==============================================================================
--- polly/trunk/lib/RegisterPasses.cpp (original)
+++ polly/trunk/lib/RegisterPasses.cpp Wed Jul 24 22:02:29 2013
@@ -317,6 +317,9 @@ registerPollyEarlyAsPossiblePasses(const
   if (Builder.OptLevel == 0)
     return;
 
+  if (PollyOnlyPrinter || PollyPrinter || PollyOnlyViewer || PollyViewer)
+    PollyTrackFailures = true;
+
   if (PollyOnlyPrinter || PollyPrinter || PollyOnlyViewer || PollyViewer ||
       ExportJScop || ImportJScop)
     PollyEnabled = true;





More information about the llvm-commits mailing list