[PATCH] [LV][BUG] Tiny fix for printing debug locations for absolute paths.

Zinovy Nis zinovy.nis at gmail.com
Mon May 5 08:16:28 PDT 2014


Slightly refactored to get rid of ugly format<..> calls.

http://reviews.llvm.org/D3513

Files:
  lib/Transforms/Vectorize/LoopVectorize.cpp

Index: lib/Transforms/Vectorize/LoopVectorize.cpp
===================================================================
--- lib/Transforms/Vectorize/LoopVectorize.cpp
+++ lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -84,6 +84,7 @@
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/Format.h"
+#include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Transforms/Scalar.h"
 #include "llvm/Transforms/Utils/BasicBlockUtils.h"
@@ -480,22 +481,32 @@
 #ifndef NDEBUG
 /// \return string containing a file name and a line # for the given
 /// instruction.
-static format_object3<const char *, const char *, unsigned>
-getDebugLocString(const Instruction *I) {
+static std::string getDebugLocString(const Instruction *I) {
   if (!I)
-    return format<const char *, const char *, unsigned>("", "", "", 0U);
+    return "";
+
   MDNode *N = I->getMetadata("dbg");
   if (!N) {
     const StringRef ModuleName =
         I->getParent()->getParent()->getParent()->getModuleIdentifier();
-    return format<const char *, const char *, unsigned>("%s", ModuleName.data(),
-                                                        "", 0U);
+    return ModuleName.data();
   }
   const DILocation Loc(N);
   const unsigned LineNo = Loc.getLineNumber();
-  const char *DirName = Loc.getDirectory().data();
   const char *FileName = Loc.getFilename().data();
-  return format("%s/%s:%u", DirName, FileName, LineNo);
+  // Absolute path doesn't need DirName.
+  std::string Result;
+  raw_string_ostream OS(Result);
+  if (sys::path::is_absolute(FileName))
+    OS << format("%s:%u", FileName, LineNo);
+  else {
+    const char *DirName = Loc.getDirectory().data();
+    SmallString<128> TDir;
+    sys::path::append(TDir, DirName, FileName);
+    OS << format("%s:%u", TDir.c_str(), LineNo);
+  }
+  OS.flush();
+  return Result;
 }
 #endif
 
@@ -1109,10 +1120,14 @@
 
   bool processLoop(Loop *L) {
     assert(L->empty() && "Only process inner loops.");
+
+#ifndef NDEBUG
+    auto DebugLocStr = getDebugLocString(L->getHeader()->getFirstNonPHIOrDbg());
+#endif /* NDEBUG */
+
     DEBUG(dbgs() << "\nLV: Checking a loop in \""
                  << L->getHeader()->getParent()->getName() << "\" from "
-                 << getDebugLocString(L->getHeader()->getFirstNonPHIOrDbg())
-                 << "\n");
+                 << DebugLocStr << "\n");
 
     LoopVectorizeHints Hints(L, DisableUnrolling);
 
@@ -1203,10 +1218,8 @@
     const unsigned UF =
         CM.selectUnrollFactor(OptForSize, Hints.getUnroll(), VF.Width, VF.Cost);
 
-    DEBUG(dbgs() << "LV: Found a vectorizable loop ("
-                 << VF.Width << ") in "
-                 << getDebugLocString(L->getHeader()->getFirstNonPHIOrDbg())
-                 << '\n');
+    DEBUG(dbgs() << "LV: Found a vectorizable loop (" << VF.Width << ") in "
+                 << DebugLocStr << '\n');
     DEBUG(dbgs() << "LV: Unroll Factor is " << UF << '\n');
 
     if (VF.Width == 1) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D3513.9077.patch
Type: text/x-patch
Size: 3009 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140505/ca939ee8/attachment.bin>


More information about the llvm-commits mailing list