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

Nadav Rotem nrotem at apple.com
Mon May 5 09:13:22 PDT 2014


Zinovy, 

Why is getDebugLocString defined in LoopVectorize.cpp?  I am expecting other passes to also need this utility. Please refactor this function and put this function in a place where other passes would be able to use it. 

Nadav  

On May 5, 2014, at 8:16 AM, Zinovy Nis <zinovy.nis at gmail.com> wrote:

> 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) {
> <D3513.9077.patch>




More information about the llvm-commits mailing list