mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-14 11:32:34 +00:00
whitespace
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@150438 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
bdf9db6f49
commit
c3a825b76c
@ -53,12 +53,12 @@ namespace {
|
|||||||
|
|
||||||
bool runOnLoop(Loop *L, LPPassManager &LPM);
|
bool runOnLoop(Loop *L, LPPassManager &LPM);
|
||||||
bool rotateLoop(Loop *L);
|
bool rotateLoop(Loop *L);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
LoopInfo *LI;
|
LoopInfo *LI;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
char LoopRotate::ID = 0;
|
char LoopRotate::ID = 0;
|
||||||
INITIALIZE_PASS_BEGIN(LoopRotate, "loop-rotate", "Rotate Loops", false, false)
|
INITIALIZE_PASS_BEGIN(LoopRotate, "loop-rotate", "Rotate Loops", false, false)
|
||||||
INITIALIZE_PASS_DEPENDENCY(LoopInfo)
|
INITIALIZE_PASS_DEPENDENCY(LoopInfo)
|
||||||
@ -92,18 +92,18 @@ static void RewriteUsesOfClonedInstructions(BasicBlock *OrigHeader,
|
|||||||
BasicBlock::iterator I, E = OrigHeader->end();
|
BasicBlock::iterator I, E = OrigHeader->end();
|
||||||
for (I = OrigHeader->begin(); PHINode *PN = dyn_cast<PHINode>(I); ++I)
|
for (I = OrigHeader->begin(); PHINode *PN = dyn_cast<PHINode>(I); ++I)
|
||||||
PN->removeIncomingValue(PN->getBasicBlockIndex(OrigPreheader));
|
PN->removeIncomingValue(PN->getBasicBlockIndex(OrigPreheader));
|
||||||
|
|
||||||
// Now fix up users of the instructions in OrigHeader, inserting PHI nodes
|
// Now fix up users of the instructions in OrigHeader, inserting PHI nodes
|
||||||
// as necessary.
|
// as necessary.
|
||||||
SSAUpdater SSA;
|
SSAUpdater SSA;
|
||||||
for (I = OrigHeader->begin(); I != E; ++I) {
|
for (I = OrigHeader->begin(); I != E; ++I) {
|
||||||
Value *OrigHeaderVal = I;
|
Value *OrigHeaderVal = I;
|
||||||
|
|
||||||
// If there are no uses of the value (e.g. because it returns void), there
|
// If there are no uses of the value (e.g. because it returns void), there
|
||||||
// is nothing to rewrite.
|
// is nothing to rewrite.
|
||||||
if (OrigHeaderVal->use_empty())
|
if (OrigHeaderVal->use_empty())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Value *OrigPreHeaderVal = ValueMap[OrigHeaderVal];
|
Value *OrigPreHeaderVal = ValueMap[OrigHeaderVal];
|
||||||
|
|
||||||
// The value now exits in two versions: the initial value in the preheader
|
// The value now exits in two versions: the initial value in the preheader
|
||||||
@ -111,27 +111,27 @@ static void RewriteUsesOfClonedInstructions(BasicBlock *OrigHeader,
|
|||||||
SSA.Initialize(OrigHeaderVal->getType(), OrigHeaderVal->getName());
|
SSA.Initialize(OrigHeaderVal->getType(), OrigHeaderVal->getName());
|
||||||
SSA.AddAvailableValue(OrigHeader, OrigHeaderVal);
|
SSA.AddAvailableValue(OrigHeader, OrigHeaderVal);
|
||||||
SSA.AddAvailableValue(OrigPreheader, OrigPreHeaderVal);
|
SSA.AddAvailableValue(OrigPreheader, OrigPreHeaderVal);
|
||||||
|
|
||||||
// Visit each use of the OrigHeader instruction.
|
// Visit each use of the OrigHeader instruction.
|
||||||
for (Value::use_iterator UI = OrigHeaderVal->use_begin(),
|
for (Value::use_iterator UI = OrigHeaderVal->use_begin(),
|
||||||
UE = OrigHeaderVal->use_end(); UI != UE; ) {
|
UE = OrigHeaderVal->use_end(); UI != UE; ) {
|
||||||
// Grab the use before incrementing the iterator.
|
// Grab the use before incrementing the iterator.
|
||||||
Use &U = UI.getUse();
|
Use &U = UI.getUse();
|
||||||
|
|
||||||
// Increment the iterator before removing the use from the list.
|
// Increment the iterator before removing the use from the list.
|
||||||
++UI;
|
++UI;
|
||||||
|
|
||||||
// SSAUpdater can't handle a non-PHI use in the same block as an
|
// SSAUpdater can't handle a non-PHI use in the same block as an
|
||||||
// earlier def. We can easily handle those cases manually.
|
// earlier def. We can easily handle those cases manually.
|
||||||
Instruction *UserInst = cast<Instruction>(U.getUser());
|
Instruction *UserInst = cast<Instruction>(U.getUser());
|
||||||
if (!isa<PHINode>(UserInst)) {
|
if (!isa<PHINode>(UserInst)) {
|
||||||
BasicBlock *UserBB = UserInst->getParent();
|
BasicBlock *UserBB = UserInst->getParent();
|
||||||
|
|
||||||
// The original users in the OrigHeader are already using the
|
// The original users in the OrigHeader are already using the
|
||||||
// original definitions.
|
// original definitions.
|
||||||
if (UserBB == OrigHeader)
|
if (UserBB == OrigHeader)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Users in the OrigPreHeader need to use the value to which the
|
// Users in the OrigPreHeader need to use the value to which the
|
||||||
// original definitions are mapped.
|
// original definitions are mapped.
|
||||||
if (UserBB == OrigPreheader) {
|
if (UserBB == OrigPreheader) {
|
||||||
@ -139,32 +139,32 @@ static void RewriteUsesOfClonedInstructions(BasicBlock *OrigHeader,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Anything else can be handled by SSAUpdater.
|
// Anything else can be handled by SSAUpdater.
|
||||||
SSA.RewriteUse(U);
|
SSA.RewriteUse(U);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Rotate loop LP. Return true if the loop is rotated.
|
/// Rotate loop LP. Return true if the loop is rotated.
|
||||||
bool LoopRotate::rotateLoop(Loop *L) {
|
bool LoopRotate::rotateLoop(Loop *L) {
|
||||||
// If the loop has only one block then there is not much to rotate.
|
// If the loop has only one block then there is not much to rotate.
|
||||||
if (L->getBlocks().size() == 1)
|
if (L->getBlocks().size() == 1)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
BasicBlock *OrigHeader = L->getHeader();
|
BasicBlock *OrigHeader = L->getHeader();
|
||||||
|
|
||||||
BranchInst *BI = dyn_cast<BranchInst>(OrigHeader->getTerminator());
|
BranchInst *BI = dyn_cast<BranchInst>(OrigHeader->getTerminator());
|
||||||
if (BI == 0 || BI->isUnconditional())
|
if (BI == 0 || BI->isUnconditional())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// If the loop header is not one of the loop exiting blocks then
|
// If the loop header is not one of the loop exiting blocks then
|
||||||
// either this loop is already rotated or it is not
|
// either this loop is already rotated or it is not
|
||||||
// suitable for loop rotation transformations.
|
// suitable for loop rotation transformations.
|
||||||
if (!L->isLoopExiting(OrigHeader))
|
if (!L->isLoopExiting(OrigHeader))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Updating PHInodes in loops with multiple exits adds complexity.
|
// Updating PHInodes in loops with multiple exits adds complexity.
|
||||||
// Keep it simple, and restrict loop rotation to loops with one exit only.
|
// Keep it simple, and restrict loop rotation to loops with one exit only.
|
||||||
// In future, lift this restriction and support for multiple exits if
|
// In future, lift this restriction and support for multiple exits if
|
||||||
// required.
|
// required.
|
||||||
@ -184,7 +184,7 @@ bool LoopRotate::rotateLoop(Loop *L) {
|
|||||||
// Now, this loop is suitable for rotation.
|
// Now, this loop is suitable for rotation.
|
||||||
BasicBlock *OrigPreheader = L->getLoopPreheader();
|
BasicBlock *OrigPreheader = L->getLoopPreheader();
|
||||||
BasicBlock *OrigLatch = L->getLoopLatch();
|
BasicBlock *OrigLatch = L->getLoopLatch();
|
||||||
|
|
||||||
// If the loop could not be converted to canonical form, it must have an
|
// If the loop could not be converted to canonical form, it must have an
|
||||||
// indirectbr in it, just give up.
|
// indirectbr in it, just give up.
|
||||||
if (OrigPreheader == 0 || OrigLatch == 0)
|
if (OrigPreheader == 0 || OrigLatch == 0)
|
||||||
@ -203,9 +203,9 @@ bool LoopRotate::rotateLoop(Loop *L) {
|
|||||||
if (L->contains(Exit))
|
if (L->contains(Exit))
|
||||||
std::swap(Exit, NewHeader);
|
std::swap(Exit, NewHeader);
|
||||||
assert(NewHeader && "Unable to determine new loop header");
|
assert(NewHeader && "Unable to determine new loop header");
|
||||||
assert(L->contains(NewHeader) && !L->contains(Exit) &&
|
assert(L->contains(NewHeader) && !L->contains(Exit) &&
|
||||||
"Unable to determine loop header and exit blocks");
|
"Unable to determine loop header and exit blocks");
|
||||||
|
|
||||||
// This code assumes that the new header has exactly one predecessor.
|
// This code assumes that the new header has exactly one predecessor.
|
||||||
// Remove any single-entry PHI nodes in it.
|
// Remove any single-entry PHI nodes in it.
|
||||||
assert(NewHeader->getSinglePredecessor() &&
|
assert(NewHeader->getSinglePredecessor() &&
|
||||||
@ -227,7 +227,7 @@ bool LoopRotate::rotateLoop(Loop *L) {
|
|||||||
TerminatorInst *LoopEntryBranch = OrigPreheader->getTerminator();
|
TerminatorInst *LoopEntryBranch = OrigPreheader->getTerminator();
|
||||||
while (I != E) {
|
while (I != E) {
|
||||||
Instruction *Inst = I++;
|
Instruction *Inst = I++;
|
||||||
|
|
||||||
// If the instruction's operands are invariant and it doesn't read or write
|
// If the instruction's operands are invariant and it doesn't read or write
|
||||||
// memory, then it is safe to hoist. Doing this doesn't change the order of
|
// memory, then it is safe to hoist. Doing this doesn't change the order of
|
||||||
// execution in the preheader, but does prevent the instruction from
|
// execution in the preheader, but does prevent the instruction from
|
||||||
@ -240,14 +240,14 @@ bool LoopRotate::rotateLoop(Loop *L) {
|
|||||||
Inst->moveBefore(LoopEntryBranch);
|
Inst->moveBefore(LoopEntryBranch);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, create a duplicate of the instruction.
|
// Otherwise, create a duplicate of the instruction.
|
||||||
Instruction *C = Inst->clone();
|
Instruction *C = Inst->clone();
|
||||||
|
|
||||||
// Eagerly remap the operands of the instruction.
|
// Eagerly remap the operands of the instruction.
|
||||||
RemapInstruction(C, ValueMap,
|
RemapInstruction(C, ValueMap,
|
||||||
RF_NoModuleLevelChanges|RF_IgnoreMissingEntries);
|
RF_NoModuleLevelChanges|RF_IgnoreMissingEntries);
|
||||||
|
|
||||||
// With the operands remapped, see if the instruction constant folds or is
|
// With the operands remapped, see if the instruction constant folds or is
|
||||||
// otherwise simplifyable. This commonly occurs because the entry from PHI
|
// otherwise simplifyable. This commonly occurs because the entry from PHI
|
||||||
// nodes allows icmps and other instructions to fold.
|
// nodes allows icmps and other instructions to fold.
|
||||||
@ -287,7 +287,7 @@ bool LoopRotate::rotateLoop(Loop *L) {
|
|||||||
L->moveToHeader(NewHeader);
|
L->moveToHeader(NewHeader);
|
||||||
assert(L->getHeader() == NewHeader && "Latch block is our new header");
|
assert(L->getHeader() == NewHeader && "Latch block is our new header");
|
||||||
|
|
||||||
|
|
||||||
// At this point, we've finished our major CFG changes. As part of cloning
|
// At this point, we've finished our major CFG changes. As part of cloning
|
||||||
// the loop into the preheader we've simplified instructions and the
|
// the loop into the preheader we've simplified instructions and the
|
||||||
// duplicated conditional branch may now be branching on a constant. If it is
|
// duplicated conditional branch may now be branching on a constant. If it is
|
||||||
@ -308,16 +308,16 @@ bool LoopRotate::rotateLoop(Loop *L) {
|
|||||||
// the dominator of Exit.
|
// the dominator of Exit.
|
||||||
DT->changeImmediateDominator(Exit, OrigPreheader);
|
DT->changeImmediateDominator(Exit, OrigPreheader);
|
||||||
DT->changeImmediateDominator(NewHeader, OrigPreheader);
|
DT->changeImmediateDominator(NewHeader, OrigPreheader);
|
||||||
|
|
||||||
// Update OrigHeader to be dominated by the new header block.
|
// Update OrigHeader to be dominated by the new header block.
|
||||||
DT->changeImmediateDominator(OrigHeader, OrigLatch);
|
DT->changeImmediateDominator(OrigHeader, OrigLatch);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Right now OrigPreHeader has two successors, NewHeader and ExitBlock, and
|
// Right now OrigPreHeader has two successors, NewHeader and ExitBlock, and
|
||||||
// thus is not a preheader anymore. Split the edge to form a real preheader.
|
// thus is not a preheader anymore. Split the edge to form a real preheader.
|
||||||
BasicBlock *NewPH = SplitCriticalEdge(OrigPreheader, NewHeader, this);
|
BasicBlock *NewPH = SplitCriticalEdge(OrigPreheader, NewHeader, this);
|
||||||
NewPH->setName(NewHeader->getName() + ".lr.ph");
|
NewPH->setName(NewHeader->getName() + ".lr.ph");
|
||||||
|
|
||||||
// Preserve canonical loop form, which means that 'Exit' should have only one
|
// Preserve canonical loop form, which means that 'Exit' should have only one
|
||||||
// predecessor.
|
// predecessor.
|
||||||
BasicBlock *ExitSplit = SplitCriticalEdge(L->getLoopLatch(), Exit, this);
|
BasicBlock *ExitSplit = SplitCriticalEdge(L->getLoopLatch(), Exit, this);
|
||||||
@ -329,7 +329,7 @@ bool LoopRotate::rotateLoop(Loop *L) {
|
|||||||
BranchInst *NewBI = BranchInst::Create(NewHeader, PHBI);
|
BranchInst *NewBI = BranchInst::Create(NewHeader, PHBI);
|
||||||
NewBI->setDebugLoc(PHBI->getDebugLoc());
|
NewBI->setDebugLoc(PHBI->getDebugLoc());
|
||||||
PHBI->eraseFromParent();
|
PHBI->eraseFromParent();
|
||||||
|
|
||||||
// With our CFG finalized, update DomTree if it is available.
|
// With our CFG finalized, update DomTree if it is available.
|
||||||
if (DominatorTree *DT = getAnalysisIfAvailable<DominatorTree>()) {
|
if (DominatorTree *DT = getAnalysisIfAvailable<DominatorTree>()) {
|
||||||
// Update OrigHeader to be dominated by the new header block.
|
// Update OrigHeader to be dominated by the new header block.
|
||||||
@ -337,7 +337,7 @@ bool LoopRotate::rotateLoop(Loop *L) {
|
|||||||
DT->changeImmediateDominator(OrigHeader, OrigLatch);
|
DT->changeImmediateDominator(OrigHeader, OrigLatch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(L->getLoopPreheader() && "Invalid loop preheader after loop rotation");
|
assert(L->getLoopPreheader() && "Invalid loop preheader after loop rotation");
|
||||||
assert(L->getLoopLatch() && "Invalid loop latch after loop rotation");
|
assert(L->getLoopLatch() && "Invalid loop latch after loop rotation");
|
||||||
|
|
||||||
@ -346,7 +346,7 @@ bool LoopRotate::rotateLoop(Loop *L) {
|
|||||||
// connected by an unconditional branch. This is just a cleanup so the
|
// connected by an unconditional branch. This is just a cleanup so the
|
||||||
// emitted code isn't too gross in this common case.
|
// emitted code isn't too gross in this common case.
|
||||||
MergeBlockIntoPredecessor(OrigHeader, this);
|
MergeBlockIntoPredecessor(OrigHeader, this);
|
||||||
|
|
||||||
++NumRotated;
|
++NumRotated;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user