static void printDebugLoc(DebugLoc DL, const MachineFunction *MF,
raw_ostream &CommentOS) {
const LLVMContext &Ctx = MF->getFunction()->getContext();
- if (!DL.isUnknown()) { // Print source line info.
- 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 << " ]";
- }
- }
+ DL.print(Ctx, CommentOS);
}
void MachineInstr::print(raw_ostream &OS, const TargetMachine *TM,
OS << " line no:" << DV.getLineNumber();
if (MDNode *InlinedAt = DV.getInlinedAt()) {
DebugLoc InlinedAtDL = DebugLoc::getFromDILocation(InlinedAt);
- if (!InlinedAtDL.isUnknown()) {
+ if (!InlinedAtDL.isUnknown() && MF) {
OS << " inlined @[ ";
printDebugLoc(InlinedAtDL, MF, OS);
OS << " ]";
#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
//===----------------------------------------------------------------------===//
#include "llvm/Support/BranchProbability.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
-#include "llvm/Support/Format.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#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) {
- if (!I)
- return format<const char *, const char *, unsigned>("", "", "", 0U);
- 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);
- }
- 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);
+static std::string getDebugLocString(const Instruction *I) {
+ std::string Result;
+ if (I) {
+ raw_string_ostream OS(Result);
+ const DebugLoc &InstrDebugLoc = I->getDebugLoc();
+ if (!InstrDebugLoc.isUnknown())
+ InstrDebugLoc.print(I->getContext(), OS);
+ else
+ // Just print the module name.
+ OS << I->getParent()->getParent()->getParent()->getModuleIdentifier();
+ OS.flush();
+ }
+ return Result;
}
#endif
bool processLoop(Loop *L) {
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 \""
<< L->getHeader()->getParent()->getName() << "\" from "
- << getDebugLocString(L->getHeader()->getFirstNonPHIOrDbg())
- << "\n");
+ << DebugLocStr << "\n");
LoopVectorizeHints Hints(L, DisableUnrolling);
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) {