|
17 | 17 | #include "llvm/ADT/SmallVector.h"
|
18 | 18 | #include "llvm/ADT/Statistic.h"
|
19 | 19 | #include "llvm/ADT/StringRef.h"
|
| 20 | +#include "llvm/ADT/StringSet.h" |
20 | 21 | #include "llvm/Analysis/DependenceAnalysis.h"
|
21 | 22 | #include "llvm/Analysis/LoopCacheAnalysis.h"
|
22 | 23 | #include "llvm/Analysis/LoopInfo.h"
|
@@ -71,7 +72,7 @@ static const unsigned MaxMemInstrCount = 100;
|
71 | 72 | // Maximum loop depth supported.
|
72 | 73 | static const unsigned MaxLoopNestDepth = 10;
|
73 | 74 |
|
74 |
| -#ifdef DUMP_DEP_MATRICIES |
| 75 | +#ifndef NDEBUG |
75 | 76 | static void printDepMatrix(CharMatrix &DepMatrix) {
|
76 | 77 | for (auto &Row : DepMatrix) {
|
77 | 78 | for (auto D : Row)
|
@@ -110,6 +111,7 @@ static bool populateDependencyMatrix(CharMatrix &DepMatrix, unsigned Level,
|
110 | 111 | << " Loads and Stores to analyze\n");
|
111 | 112 |
|
112 | 113 | ValueVector::iterator I, IE, J, JE;
|
| 114 | + StringSet<> Seen; |
113 | 115 |
|
114 | 116 | for (I = MemInstr.begin(), IE = MemInstr.end(); I != IE; ++I) {
|
115 | 117 | for (J = I, JE = MemInstr.end(); J != JE; ++J) {
|
@@ -156,7 +158,10 @@ static bool populateDependencyMatrix(CharMatrix &DepMatrix, unsigned Level,
|
156 | 158 | Dep.push_back('I');
|
157 | 159 | }
|
158 | 160 |
|
159 |
| - DepMatrix.push_back(Dep); |
| 161 | + // Make sure we only add unique entries to the dependency matrix. |
| 162 | + if (Seen.insert(StringRef(Dep.data(), Dep.size())).second) |
| 163 | + DepMatrix.push_back(Dep); |
| 164 | + |
160 | 165 | if (DepMatrix.size() > MaxMemInstrCount) {
|
161 | 166 | LLVM_DEBUG(dbgs() << "Cannot handle more than " << MaxMemInstrCount
|
162 | 167 | << " dependencies inside loop\n");
|
@@ -449,10 +454,9 @@ struct LoopInterchange {
|
449 | 454 | LLVM_DEBUG(dbgs() << "Populating dependency matrix failed\n");
|
450 | 455 | return false;
|
451 | 456 | }
|
452 |
| -#ifdef DUMP_DEP_MATRICIES |
453 |
| - LLVM_DEBUG(dbgs() << "Dependence before interchange\n"); |
454 |
| - printDepMatrix(DependencyMatrix); |
455 |
| -#endif |
| 457 | + |
| 458 | + LLVM_DEBUG(dbgs() << "Dependency matrix before interchange:\n"; |
| 459 | + printDepMatrix(DependencyMatrix)); |
456 | 460 |
|
457 | 461 | // Get the Outermost loop exit.
|
458 | 462 | BasicBlock *LoopNestExit = OuterMostLoop->getExitBlock();
|
@@ -492,10 +496,10 @@ struct LoopInterchange {
|
492 | 496 | std::swap(LoopList[i - 1], LoopList[i]);
|
493 | 497 | // Update the DependencyMatrix
|
494 | 498 | interChangeDependencies(DependencyMatrix, i, i - 1);
|
495 |
| -#ifdef DUMP_DEP_MATRICIES |
496 |
| - LLVM_DEBUG(dbgs() << "Dependence after interchange\n"); |
497 |
| - printDepMatrix(DependencyMatrix); |
498 |
| -#endif |
| 499 | + |
| 500 | + LLVM_DEBUG(dbgs() << "Dependency matrix after interchange:\n"; |
| 501 | + printDepMatrix(DependencyMatrix)); |
| 502 | + |
499 | 503 | ChangedPerIter |= Interchanged;
|
500 | 504 | Changed |= Interchanged;
|
501 | 505 | }
|
|
0 commit comments