<p dir="ltr">Nifty. </p>
<div class="gmail_quote">On Apr 4, 2014 6:41 AM, "Zinovy Nis" <<a href="mailto:zinovy.nis@gmail.com">zinovy.nis@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi nadav, chandlerc, hfinkel, rengolin,<br>
<br>
Hi.<br>
<br>
The patch makes LoopVectorizer print in debug console not only a function name or a module name where analyzing loop was found, but also a line in the source code where the loop resides:<br>
<br>
LV: Checking a loop in "bar" from /some/path/foo.c:42<br>
...<br>
LV: Found a vectorizable loop (4) in /some/path/foo.c:42<br>
...<br>
<br>
It can be useful when debugging loop vectorizer issues.<br>
<br>
<a href="http://llvm-reviews.chandlerc.com/D3288" target="_blank">http://llvm-reviews.chandlerc.com/D3288</a><br>
<br>
Files:<br>
lib/Transforms/Vectorize/LoopVectorize.cpp<br>
<br>
Index: lib/Transforms/Vectorize/LoopVectorize.cpp<br>
===================================================================<br>
--- lib/Transforms/Vectorize/LoopVectorize.cpp<br>
+++ lib/Transforms/Vectorize/LoopVectorize.cpp<br>
@@ -67,6 +67,7 @@<br>
#include "llvm/Analysis/ValueTracking.h"<br>
#include "llvm/IR/Constants.h"<br>
#include "llvm/IR/DataLayout.h"<br>
+#include "llvm/IR/DebugInfo.h"<br>
#include "llvm/IR/DerivedTypes.h"<br>
#include "llvm/IR/Dominators.h"<br>
#include "llvm/IR/Function.h"<br>
@@ -84,6 +85,7 @@<br>
#include "llvm/Support/BranchProbability.h"<br>
#include "llvm/Support/CommandLine.h"<br>
#include "llvm/Support/Debug.h"<br>
+#include "llvm/Support/Format.h"<br>
#include "llvm/Support/raw_ostream.h"<br>
#include "llvm/Target/TargetLibraryInfo.h"<br>
#include "llvm/Transforms/Scalar.h"<br>
@@ -468,7 +470,25 @@<br>
else<br>
B.SetCurrentDebugLocation(DebugLoc());<br>
}<br>
-<br>
+/// \return string containing a file name and a line # for the given<br>
+/// instruction.<br>
+static format_object3<const char *, const char *, unsigned><br>
+getDebugLocString(const Instruction *I) {<br>
+ if (!I)<br>
+ return format<const char *, const char *, unsigned>("", "", "", 0U);<br>
+ MDNode *N = I->getMetadata("dbg");<br>
+ if (!N) {<br>
+ const StringRef ModuleName =<br>
+ I->getParent()->getParent()->getParent()->getModuleIdentifier();<br>
+ return format<const char *, const char *, unsigned>("%s", ModuleName.data(),<br>
+ "", 0U);<br>
+ }<br>
+ const DILocation Loc(N);<br>
+ const unsigned LineNo = Loc.getLineNumber();<br>
+ const char *DirName = Loc.getDirectory().data();<br>
+ const char *FileName = Loc.getFilename().data();<br>
+ return format("%s/%s:%u", DirName, FileName, LineNo);<br>
+}<br>
/// LoopVectorizationLegality checks if it is legal to vectorize a loop, and<br>
/// to what vectorization factor.<br>
/// This class does not look at the profitability of vectorization, only the<br>
@@ -1065,8 +1085,10 @@<br>
<br>
bool processLoop(Loop *L) {<br>
assert(L->empty() && "Only process inner loops.");<br>
- DEBUG(dbgs() << "LV: Checking a loop in \"" <<<br>
- L->getHeader()->getParent()->getName() << "\"\n");<br>
+ DEBUG(dbgs() << "LV: Checking a loop in \""<br>
+ << L->getHeader()->getParent()->getName() << "\" from "<br>
+ << getDebugLocString(L->getHeader()->getFirstNonPHIOrDbg())<br>
+ << "\n");<br>
<br>
LoopVectorizeHints Hints(L, DisableUnrolling);<br>
<br>
@@ -1129,8 +1151,10 @@<br>
unsigned UF = CM.selectUnrollFactor(OptForSize, Hints.Unroll, VF.Width,<br>
VF.Cost);<br>
<br>
- DEBUG(dbgs() << "LV: Found a vectorizable loop ("<< VF.Width << ") in "<<<br>
- F->getParent()->getModuleIdentifier() << '\n');<br>
+ DEBUG(dbgs() << "LV: Found a vectorizable loop ("<br>
+ << VF.Width << ") in "<br>
+ << getDebugLocString(L->getHeader()->getFirstNonPHIOrDbg())<br>
+ << '\n');<br>
DEBUG(dbgs() << "LV: Unroll Factor is " << UF << '\n');<br>
<br>
if (VF.Width == 1) {<br>
<br>_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
<br></blockquote></div>