[BUG][REFACTOR]

1) Fix for printing debug locations for absolute paths.
2) Location printing is moved into public method DebugLoc::print() to avoid re-inventing the wheel.

Differential Revision: http://reviews.llvm.org/D3513

llvm-svn: 208177
This commit is contained in:
Zinovy Nis 2014-05-07 09:51:22 +00:00
parent 79dffb4128
commit da925c0d7c
4 changed files with 48 additions and 42 deletions

View File

@ -21,6 +21,7 @@ namespace llvm {
template <typename T> struct DenseMapInfo; template <typename T> struct DenseMapInfo;
class MDNode; class MDNode;
class LLVMContext; class LLVMContext;
class raw_ostream;
/// DebugLoc - Debug location id. This is carried by Instruction, SDNode, /// DebugLoc - Debug location id. This is carried by Instruction, SDNode,
/// and MachineInstr to compactly encode file/line/scope information for an /// and MachineInstr to compactly encode file/line/scope information for an
@ -106,6 +107,8 @@ namespace llvm {
bool operator!=(const DebugLoc &DL) const { return !(*this == DL); } bool operator!=(const DebugLoc &DL) const { return !(*this == DL); }
void dump(const LLVMContext &Ctx) const; void dump(const LLVMContext &Ctx) const;
/// \brief prints source location /path/to/file.exe:line:col @[inlined at]
void print(const LLVMContext &Ctx, raw_ostream &OS) const;
}; };
template <> template <>

View File

@ -1453,25 +1453,7 @@ void MachineInstr::dump() const {
static void printDebugLoc(DebugLoc DL, const MachineFunction *MF, static void printDebugLoc(DebugLoc DL, const MachineFunction *MF,
raw_ostream &CommentOS) { raw_ostream &CommentOS) {
const LLVMContext &Ctx = MF->getFunction()->getContext(); const LLVMContext &Ctx = MF->getFunction()->getContext();
if (!DL.isUnknown()) { // Print source line info. DL.print(Ctx, CommentOS);
DIScope Scope(DL.getScope(Ctx));
assert((!Scope || Scope.isScope()) &&
"Scope of a DebugLoc should be null or a DIScope.");
// Omit the directory, because it's likely to be long and uninteresting.
if (Scope)
CommentOS << Scope.getFilename();
else
CommentOS << "<unknown>";
CommentOS << ':' << DL.getLine();
if (DL.getCol() != 0)
CommentOS << ':' << DL.getCol();
DebugLoc InlinedAtDL = DebugLoc::getFromDILocation(DL.getInlinedAt(Ctx));
if (!InlinedAtDL.isUnknown()) {
CommentOS << " @[ ";
printDebugLoc(InlinedAtDL, MF, CommentOS);
CommentOS << " ]";
}
}
} }
void MachineInstr::print(raw_ostream &OS, const TargetMachine *TM, void MachineInstr::print(raw_ostream &OS, const TargetMachine *TM,
@ -1684,7 +1666,7 @@ void MachineInstr::print(raw_ostream &OS, const TargetMachine *TM,
OS << " line no:" << DV.getLineNumber(); OS << " line no:" << DV.getLineNumber();
if (MDNode *InlinedAt = DV.getInlinedAt()) { if (MDNode *InlinedAt = DV.getInlinedAt()) {
DebugLoc InlinedAtDL = DebugLoc::getFromDILocation(InlinedAt); DebugLoc InlinedAtDL = DebugLoc::getFromDILocation(InlinedAt);
if (!InlinedAtDL.isUnknown()) { if (!InlinedAtDL.isUnknown() && MF) {
OS << " inlined @[ "; OS << " inlined @[ ";
printDebugLoc(InlinedAtDL, MF, OS); printDebugLoc(InlinedAtDL, MF, OS);
OS << " ]"; OS << " ]";

View File

@ -167,6 +167,28 @@ void DebugLoc::dump(const LLVMContext &Ctx) const {
#endif #endif
} }
void DebugLoc::print(const LLVMContext &Ctx, raw_ostream &OS) const {
if (!isUnknown()) {
// Print source line info.
DIScope Scope(getScope(Ctx));
assert((!Scope || Scope.isScope()) &&
"Scope of a DebugLoc should be null or a DIScope.");
if (Scope)
OS << Scope.getFilename();
else
OS << "<unknown>";
OS << ':' << getLine();
if (getCol() != 0)
OS << ':' << getCol();
DebugLoc InlinedAtDL = DebugLoc::getFromDILocation(getInlinedAt(Ctx));
if (!InlinedAtDL.isUnknown()) {
OS << " @[ ";
InlinedAtDL.print(Ctx, OS);
OS << " ]";
}
}
}
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
// DenseMap specialization // DenseMap specialization
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//

View File

@ -83,7 +83,6 @@
#include "llvm/Support/BranchProbability.h" #include "llvm/Support/BranchProbability.h"
#include "llvm/Support/CommandLine.h" #include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h" #include "llvm/Support/Debug.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/raw_ostream.h" #include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Scalar.h" #include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h" #include "llvm/Transforms/Utils/BasicBlockUtils.h"
@ -480,22 +479,19 @@ static void setDebugLocFromInst(IRBuilder<> &B, const Value *Ptr) {
#ifndef NDEBUG #ifndef NDEBUG
/// \return string containing a file name and a line # for the given /// \return string containing a file name and a line # for the given
/// instruction. /// instruction.
static format_object3<const char *, const char *, unsigned> static std::string getDebugLocString(const Instruction *I) {
getDebugLocString(const Instruction *I) { std::string Result;
if (!I) if (I) {
return format<const char *, const char *, unsigned>("", "", "", 0U); raw_string_ostream OS(Result);
MDNode *N = I->getMetadata("dbg"); const DebugLoc &InstrDebugLoc = I->getDebugLoc();
if (!N) { if (!InstrDebugLoc.isUnknown())
const StringRef ModuleName = InstrDebugLoc.print(I->getContext(), OS);
I->getParent()->getParent()->getParent()->getModuleIdentifier(); else
return format<const char *, const char *, unsigned>("%s", ModuleName.data(), // Just print the module name.
"", 0U); OS << I->getParent()->getParent()->getParent()->getModuleIdentifier();
OS.flush();
} }
const DILocation Loc(N); return Result;
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);
} }
#endif #endif
@ -1109,10 +1105,15 @@ struct LoopVectorize : public FunctionPass {
bool processLoop(Loop *L) { bool processLoop(Loop *L) {
assert(L->empty() && "Only process inner loops."); assert(L->empty() && "Only process inner loops.");
#ifndef NDEBUG
const std::string DebugLocStr =
getDebugLocString(L->getHeader()->getFirstNonPHIOrDbgOrLifetime());
#endif /* NDEBUG */
DEBUG(dbgs() << "\nLV: Checking a loop in \"" DEBUG(dbgs() << "\nLV: Checking a loop in \""
<< L->getHeader()->getParent()->getName() << "\" from " << L->getHeader()->getParent()->getName() << "\" from "
<< getDebugLocString(L->getHeader()->getFirstNonPHIOrDbg()) << DebugLocStr << "\n");
<< "\n");
LoopVectorizeHints Hints(L, DisableUnrolling); LoopVectorizeHints Hints(L, DisableUnrolling);
@ -1203,10 +1204,8 @@ struct LoopVectorize : public FunctionPass {
const unsigned UF = const unsigned UF =
CM.selectUnrollFactor(OptForSize, Hints.getUnroll(), VF.Width, VF.Cost); CM.selectUnrollFactor(OptForSize, Hints.getUnroll(), VF.Width, VF.Cost);
DEBUG(dbgs() << "LV: Found a vectorizable loop (" DEBUG(dbgs() << "LV: Found a vectorizable loop (" << VF.Width << ") in "
<< VF.Width << ") in " << DebugLocStr << '\n');
<< getDebugLocString(L->getHeader()->getFirstNonPHIOrDbg())
<< '\n');
DEBUG(dbgs() << "LV: Unroll Factor is " << UF << '\n'); DEBUG(dbgs() << "LV: Unroll Factor is " << UF << '\n');
if (VF.Width == 1) { if (VF.Width == 1) {