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 -getDebugLocString(const Instruction *I) { +static std::string getDebugLocString(const Instruction *I) { if (!I) - return format("", "", "", 0U); + return ""; + MDNode *N = I->getMetadata("dbg"); if (!N) { const StringRef ModuleName = I->getParent()->getParent()->getParent()->getModuleIdentifier(); - return format("%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) {