Skip to content

Commit 661c26f

Browse files
committed
Replace Levels parameter by DV.size()
1 parent 514bd66 commit 661c26f

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

llvm/lib/Transforms/Scalar/LoopInterchange.cpp

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,8 @@ static void printDepMatrix(CharMatrix &DepMatrix) {
8282
}
8383
#endif
8484

85-
static bool isDirectionNegative(std::vector<Dependence::DVEntry> &DV,
86-
unsigned Levels) {
87-
for (unsigned Level = 1; Level <= Levels; ++Level) {
85+
static bool isDirectionNegative(std::vector<Dependence::DVEntry> &DV) {
86+
for (unsigned Level = 1; Level <= DV.size(); ++Level) {
8887
unsigned char Direction = DV[Level - 1].Direction;
8988
if (Direction == Dependence::DVEntry::EQ)
9089
continue;
@@ -96,10 +95,10 @@ static bool isDirectionNegative(std::vector<Dependence::DVEntry> &DV,
9695
return false;
9796
}
9897

99-
static void dumpDirection(raw_ostream &OS, std::vector<Dependence::DVEntry> &DV,
100-
unsigned Levels) {
98+
static void dumpDirection(raw_ostream &OS,
99+
std::vector<Dependence::DVEntry> &DV) {
101100
OS << " [";
102-
for (unsigned II = 1; II <= Levels; ++II) {
101+
for (unsigned II = 1; II <= DV.size(); ++II) {
103102
unsigned Direction = DV[II - 1].Direction;
104103
if (Direction == Dependence::DVEntry::ALL)
105104
OS << "*";
@@ -111,7 +110,7 @@ static void dumpDirection(raw_ostream &OS, std::vector<Dependence::DVEntry> &DV,
111110
if (Direction & Dependence::DVEntry::GT)
112111
OS << ">";
113112
}
114-
if (II < Levels)
113+
if (II < DV.size())
115114
OS << " ";
116115
}
117116
OS << "]\n";
@@ -134,16 +133,16 @@ static void getAffectedLoop(const SCEV *Expr, SmallBitVector &Loops,
134133
// Update the Direction of undistributed loop to EQ.
135134
static void
136135
updateUndistributedLoopDirection(std::vector<Dependence::DVEntry> &DV,
137-
unsigned Levels, ScalarEvolution *SE,
138-
Instruction *Src, Instruction *Dst) {
139-
SmallBitVector DistributedLoops(Levels + 1);
136+
ScalarEvolution *SE, Instruction *Src,
137+
Instruction *Dst) {
138+
SmallBitVector DistributedLoops(DV.size() + 1);
140139
Value *SrcPtr = getLoadStorePointerOperand(Src);
141140
Value *DstPtr = getLoadStorePointerOperand(Dst);
142141
const SCEV *SrcSCEV = SE->getSCEV(SrcPtr);
143142
const SCEV *DstSCEV = SE->getSCEV(DstPtr);
144143
getAffectedLoop(SrcSCEV, DistributedLoops, SE);
145144
getAffectedLoop(DstSCEV, DistributedLoops, SE);
146-
for (unsigned II = 1; II < Levels; ++II)
145+
for (unsigned II = 1; II <= DV.size(); ++II)
147146
// Set the direction of the loop to EQ if the loop won't affect the
148147
// SCEV of Src and Dst.
149148
if (!DistributedLoops.test(II)) {
@@ -152,16 +151,16 @@ updateUndistributedLoopDirection(std::vector<Dependence::DVEntry> &DV,
152151
}
153152
}
154153

155-
static bool normalize(std::vector<Dependence::DVEntry> &DV, unsigned Levels,
156-
ScalarEvolution *SE, Instruction *Src, Instruction *Dst) {
157-
updateUndistributedLoopDirection(DV, Levels, SE, Src, Dst);
154+
static bool normalize(std::vector<Dependence::DVEntry> &DV, ScalarEvolution *SE,
155+
Instruction *Src, Instruction *Dst) {
156+
updateUndistributedLoopDirection(DV, SE, Src, Dst);
158157

159-
if (!isDirectionNegative(DV, Levels))
158+
if (!isDirectionNegative(DV))
160159
return false;
161160

162161
LLVM_DEBUG(dbgs() << "Before normalizing negative direction vectors:\n";
163-
dumpDirection(dbgs(), DV, Levels););
164-
for (unsigned Level = 1; Level <= Levels; ++Level) {
162+
dumpDirection(dbgs(), DV););
163+
for (unsigned Level = 1; Level <= DV.size(); ++Level) {
165164
unsigned char Direction = DV[Level - 1].Direction;
166165
// Reverse the direction vector, this means LT becomes GT
167166
// and GT becomes LT.
@@ -174,7 +173,7 @@ static bool normalize(std::vector<Dependence::DVEntry> &DV, unsigned Levels,
174173
}
175174

176175
LLVM_DEBUG(dbgs() << "After normalizing negative direction vectors:\n";
177-
dumpDirection(dbgs(), DV, Levels););
176+
dumpDirection(dbgs(), DV););
178177
return true;
179178
}
180179

@@ -226,7 +225,7 @@ static bool populateDependencyMatrix(CharMatrix &DepMatrix, unsigned Level,
226225
DV[II - 1].Direction = D->getDirection(II);
227226
// If the direction vector is negative, normalize it to
228227
// make it non-negative.
229-
if (normalize(DV, Levels, SE, Src, Dst))
228+
if (normalize(DV, SE, Src, Dst))
230229
LLVM_DEBUG(dbgs() << "Negative dependence vector normalized.\n");
231230
LLVM_DEBUG(StringRef DepType = D->isFlow() ? "flow"
232231
: D->isAnti() ? "anti"

0 commit comments

Comments
 (0)