Skip to content

Commit 385f2ec

Browse files
committed
some cleanups: remove dead arguments and eliminate ivars
that are just passed to one function. llvm-svn: 123067
1 parent 25ba40a commit 385f2ec

File tree

1 file changed

+36
-55
lines changed

1 file changed

+36
-55
lines changed

llvm/lib/Transforms/Scalar/LoopRotation.cpp

Lines changed: 36 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -59,25 +59,18 @@ namespace {
5959
// Helper functions
6060

6161
/// Do actual work
62-
bool rotateLoop(Loop *L, LPPassManager &LPM);
62+
bool rotateLoop(Loop *L);
6363

64-
/// Initialize local data
65-
void initialize();
66-
6764
/// After loop rotation, loop pre-header has multiple sucessors.
6865
/// Insert one forwarding basic block to ensure that loop pre-header
6966
/// has only one successor.
70-
void preserveCanonicalLoopForm(LPPassManager &LPM);
67+
void preserveCanonicalLoopForm(Loop *L, BasicBlock *OrigHeader,
68+
BasicBlock *OrigPreHeader,
69+
BasicBlock *OrigLatch, BasicBlock *NewHeader,
70+
BasicBlock *Exit);
7171

7272
private:
7373
LoopInfo *LI;
74-
Loop *L;
75-
BasicBlock *OrigHeader;
76-
BasicBlock *OrigPreHeader;
77-
BasicBlock *OrigLatch;
78-
BasicBlock *NewHeader;
79-
BasicBlock *Exit;
80-
LPPassManager *LPM_Ptr;
8174
};
8275
}
8376

@@ -90,44 +83,28 @@ INITIALIZE_PASS_END(LoopRotate, "loop-rotate", "Rotate Loops", false, false)
9083

9184
Pass *llvm::createLoopRotatePass() { return new LoopRotate(); }
9285

93-
/// Initialize local data
94-
void LoopRotate::initialize() {
95-
L = NULL;
96-
OrigHeader = NULL;
97-
OrigPreHeader = NULL;
98-
NewHeader = NULL;
99-
Exit = NULL;
100-
}
101-
10286
/// Rotate Loop L as many times as possible. Return true if
10387
/// the loop is rotated at least once.
104-
bool LoopRotate::runOnLoop(Loop *Lp, LPPassManager &LPM) {
88+
bool LoopRotate::runOnLoop(Loop *L, LPPassManager &LPM) {
10589
LI = &getAnalysis<LoopInfo>();
10690

107-
initialize();
108-
LPM_Ptr = &LPM;
109-
11091
// One loop can be rotated multiple times.
11192
bool MadeChange = false;
112-
while (rotateLoop(Lp,LPM)) {
93+
while (rotateLoop(L))
11394
MadeChange = true;
114-
initialize();
115-
}
11695

11796
return MadeChange;
11897
}
11998

12099
/// Rotate loop LP. Return true if the loop is rotated.
121-
bool LoopRotate::rotateLoop(Loop *Lp, LPPassManager &LPM) {
122-
L = Lp;
123-
124-
OrigPreHeader = L->getLoopPreheader();
100+
bool LoopRotate::rotateLoop(Loop *L) {
101+
BasicBlock *OrigPreHeader = L->getLoopPreheader();
125102
if (!OrigPreHeader) return false;
126103

127-
OrigLatch = L->getLoopLatch();
104+
BasicBlock *OrigLatch = L->getLoopLatch();
128105
if (!OrigLatch) return false;
129106

130-
OrigHeader = L->getHeader();
107+
BasicBlock *OrigHeader = L->getHeader();
131108

132109
// If the loop has only one block then there is not much to rotate.
133110
if (L->getBlocks().size() == 1)
@@ -171,8 +148,8 @@ bool LoopRotate::rotateLoop(Loop *Lp, LPPassManager &LPM) {
171148
// Find new Loop header. NewHeader is a Header's one and only successor
172149
// that is inside loop. Header's other successor is outside the
173150
// loop. Otherwise loop is not suitable for rotation.
174-
Exit = BI->getSuccessor(0);
175-
NewHeader = BI->getSuccessor(1);
151+
BasicBlock *Exit = BI->getSuccessor(0);
152+
BasicBlock *NewHeader = BI->getSuccessor(1);
176153
if (L->contains(Exit))
177154
std::swap(Exit, NewHeader);
178155
assert(NewHeader && "Unable to determine new loop header");
@@ -328,7 +305,8 @@ bool LoopRotate::rotateLoop(Loop *Lp, LPPassManager &LPM) {
328305
// at this point, if we don't mind updating dominator info.
329306

330307
// Establish a new preheader, update dominators, etc.
331-
preserveCanonicalLoopForm(LPM);
308+
preserveCanonicalLoopForm(L, OrigHeader, OrigPreHeader, OrigLatch,
309+
NewHeader, Exit);
332310

333311
++NumRotated;
334312
return true;
@@ -338,15 +316,18 @@ bool LoopRotate::rotateLoop(Loop *Lp, LPPassManager &LPM) {
338316
/// After loop rotation, loop pre-header has multiple sucessors.
339317
/// Insert one forwarding basic block to ensure that loop pre-header
340318
/// has only one successor.
341-
void LoopRotate::preserveCanonicalLoopForm(LPPassManager &LPM) {
319+
void LoopRotate::preserveCanonicalLoopForm(Loop *L, BasicBlock *OrigHeader,
320+
BasicBlock *OrigPreHeader,
321+
BasicBlock *OrigLatch,
322+
BasicBlock *NewHeader,
323+
BasicBlock *Exit) {
342324

343325
// Right now original pre-header has two successors, new header and
344326
// exit block. Insert new block between original pre-header and
345327
// new header such that loop's new pre-header has only one successor.
346-
BasicBlock *NewPreHeader = BasicBlock::Create(OrigHeader->getContext(),
347-
"bb.nph",
348-
OrigHeader->getParent(),
349-
NewHeader);
328+
BasicBlock *NewPreHeader =
329+
BasicBlock::Create(OrigHeader->getContext(), "bb.nph",
330+
OrigHeader->getParent(), NewHeader);
350331
LoopInfo &LI = getAnalysis<LoopInfo>();
351332
if (Loop *PL = LI.getLoopFor(OrigPreHeader))
352333
PL->addBasicBlockToLoop(NewPreHeader, LI.getBase());
@@ -431,19 +412,19 @@ void LoopRotate::preserveCanonicalLoopForm(LPPassManager &LPM) {
431412
for (Loop::block_iterator BI = L->block_begin(), BE = L->block_end();
432413
BI != BE; ++BI) {
433414
BasicBlock *B = *BI;
434-
if (DT->dominates(B, NewLatch)) {
435-
DominanceFrontier::iterator BDFI = DF->find(B);
436-
if (BDFI != DF->end()) {
437-
DominanceFrontier::DomSetType &BSet = BDFI->second;
438-
BSet.erase(NewLatch);
439-
BSet.insert(L->getHeader());
440-
BSet.insert(Exit);
441-
} else {
442-
DominanceFrontier::DomSetType BSet;
443-
BSet.insert(L->getHeader());
444-
BSet.insert(Exit);
445-
DF->addBasicBlock(B, BSet);
446-
}
415+
if (!DT->dominates(B, NewLatch)) continue;
416+
417+
DominanceFrontier::iterator BDFI = DF->find(B);
418+
if (BDFI != DF->end()) {
419+
DominanceFrontier::DomSetType &BSet = BDFI->second;
420+
BSet.erase(NewLatch);
421+
BSet.insert(L->getHeader());
422+
BSet.insert(Exit);
423+
} else {
424+
DominanceFrontier::DomSetType BSet;
425+
BSet.insert(L->getHeader());
426+
BSet.insert(Exit);
427+
DF->addBasicBlock(B, BSet);
447428
}
448429
}
449430
}

0 commit comments

Comments
 (0)