2007-04-07 01:25:15 +00:00
|
|
|
//===- LoopRotation.cpp - Loop Rotation Pass ------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:36:04 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-04-07 01:25:15 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements Loop Rotation Pass.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2007-04-09 16:11:48 +00:00
|
|
|
#define DEBUG_TYPE "loop-rotate"
|
2007-04-07 01:25:15 +00:00
|
|
|
#include "llvm/Transforms/Scalar.h"
|
|
|
|
#include "llvm/Function.h"
|
2011-01-02 07:35:53 +00:00
|
|
|
#include "llvm/Analysis/CodeMetrics.h"
|
2011-01-08 08:24:46 +00:00
|
|
|
#include "llvm/Analysis/LoopPass.h"
|
|
|
|
#include "llvm/Analysis/InstructionSimplify.h"
|
2007-07-11 23:47:28 +00:00
|
|
|
#include "llvm/Analysis/ScalarEvolution.h"
|
2007-04-07 01:25:15 +00:00
|
|
|
#include "llvm/Transforms/Utils/Local.h"
|
2007-07-11 23:47:28 +00:00
|
|
|
#include "llvm/Transforms/Utils/BasicBlockUtils.h"
|
2009-10-24 23:19:52 +00:00
|
|
|
#include "llvm/Transforms/Utils/SSAUpdater.h"
|
2011-01-08 07:21:31 +00:00
|
|
|
#include "llvm/Transforms/Utils/ValueMapper.h"
|
2007-04-07 01:25:15 +00:00
|
|
|
#include "llvm/Support/Debug.h"
|
|
|
|
#include "llvm/ADT/Statistic.h"
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
#define MAX_HEADER_SIZE 16
|
|
|
|
|
|
|
|
STATISTIC(NumRotated, "Number of loops rotated");
|
|
|
|
namespace {
|
|
|
|
|
2009-09-02 06:11:42 +00:00
|
|
|
class LoopRotate : public LoopPass {
|
2007-04-07 01:25:15 +00:00
|
|
|
public:
|
2007-05-03 01:11:54 +00:00
|
|
|
static char ID; // Pass ID, replacement for typeid
|
2010-10-19 17:21:58 +00:00
|
|
|
LoopRotate() : LoopPass(ID) {
|
|
|
|
initializeLoopRotatePass(*PassRegistry::getPassRegistry());
|
|
|
|
}
|
2007-05-01 21:15:47 +00:00
|
|
|
|
2007-04-09 16:11:48 +00:00
|
|
|
// Rotate Loop L as many times as possible. Return true if
|
|
|
|
// loop is rotated at least once.
|
2007-04-07 01:25:15 +00:00
|
|
|
bool runOnLoop(Loop *L, LPPassManager &LPM);
|
2007-04-09 16:11:48 +00:00
|
|
|
|
|
|
|
// LCSSA form makes instruction renaming easier.
|
2007-04-07 01:25:15 +00:00
|
|
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
2010-07-16 17:58:45 +00:00
|
|
|
AU.addPreserved<DominatorTree>();
|
|
|
|
AU.addRequired<LoopInfo>();
|
|
|
|
AU.addPreserved<LoopInfo>();
|
2008-02-15 01:24:49 +00:00
|
|
|
AU.addRequiredID(LoopSimplifyID);
|
|
|
|
AU.addPreservedID(LoopSimplifyID);
|
2007-04-07 01:25:15 +00:00
|
|
|
AU.addRequiredID(LCSSAID);
|
|
|
|
AU.addPreservedID(LCSSAID);
|
2007-07-11 23:47:28 +00:00
|
|
|
AU.addPreserved<ScalarEvolution>();
|
2007-04-07 01:25:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Helper functions
|
|
|
|
|
|
|
|
/// Do actual work
|
2011-01-08 17:48:33 +00:00
|
|
|
bool rotateLoop(Loop *L);
|
2007-04-07 01:25:15 +00:00
|
|
|
|
2007-04-09 20:19:46 +00:00
|
|
|
/// After loop rotation, loop pre-header has multiple sucessors.
|
|
|
|
/// Insert one forwarding basic block to ensure that loop pre-header
|
|
|
|
/// has only one successor.
|
2011-01-08 17:48:33 +00:00
|
|
|
void preserveCanonicalLoopForm(Loop *L, BasicBlock *OrigHeader,
|
|
|
|
BasicBlock *OrigPreHeader,
|
|
|
|
BasicBlock *OrigLatch, BasicBlock *NewHeader,
|
|
|
|
BasicBlock *Exit);
|
2007-04-09 20:19:46 +00:00
|
|
|
|
2007-04-07 01:25:15 +00:00
|
|
|
private:
|
2011-01-08 17:38:45 +00:00
|
|
|
LoopInfo *LI;
|
2007-04-07 01:25:15 +00:00
|
|
|
};
|
|
|
|
}
|
2008-05-13 00:00:25 +00:00
|
|
|
|
|
|
|
char LoopRotate::ID = 0;
|
2010-10-12 19:48:12 +00:00
|
|
|
INITIALIZE_PASS_BEGIN(LoopRotate, "loop-rotate", "Rotate Loops", false, false)
|
|
|
|
INITIALIZE_PASS_DEPENDENCY(LoopInfo)
|
|
|
|
INITIALIZE_PASS_DEPENDENCY(LoopSimplify)
|
|
|
|
INITIALIZE_PASS_DEPENDENCY(LCSSA)
|
|
|
|
INITIALIZE_PASS_END(LoopRotate, "loop-rotate", "Rotate Loops", false, false)
|
2007-04-07 01:25:15 +00:00
|
|
|
|
2008-10-22 23:32:42 +00:00
|
|
|
Pass *llvm::createLoopRotatePass() { return new LoopRotate(); }
|
2007-04-07 01:25:15 +00:00
|
|
|
|
2007-04-09 16:11:48 +00:00
|
|
|
/// Rotate Loop L as many times as possible. Return true if
|
2009-06-25 00:22:44 +00:00
|
|
|
/// the loop is rotated at least once.
|
2011-01-08 17:48:33 +00:00
|
|
|
bool LoopRotate::runOnLoop(Loop *L, LPPassManager &LPM) {
|
2011-01-08 17:38:45 +00:00
|
|
|
LI = &getAnalysis<LoopInfo>();
|
2007-07-11 23:47:28 +00:00
|
|
|
|
2007-04-07 01:25:15 +00:00
|
|
|
// One loop can be rotated multiple times.
|
2011-01-08 17:38:45 +00:00
|
|
|
bool MadeChange = false;
|
2011-01-08 17:48:33 +00:00
|
|
|
while (rotateLoop(L))
|
2011-01-08 17:38:45 +00:00
|
|
|
MadeChange = true;
|
2007-04-07 01:25:15 +00:00
|
|
|
|
2011-01-08 17:38:45 +00:00
|
|
|
return MadeChange;
|
2007-04-07 01:25:15 +00:00
|
|
|
}
|
|
|
|
|
2007-05-11 21:10:54 +00:00
|
|
|
/// Rotate loop LP. Return true if the loop is rotated.
|
2011-01-08 17:48:33 +00:00
|
|
|
bool LoopRotate::rotateLoop(Loop *L) {
|
2009-06-25 00:22:44 +00:00
|
|
|
// If the loop has only one block then there is not much to rotate.
|
2007-04-09 16:11:48 +00:00
|
|
|
if (L->getBlocks().size() == 1)
|
2007-04-07 01:25:15 +00:00
|
|
|
return false;
|
2011-01-08 18:06:22 +00:00
|
|
|
|
|
|
|
BasicBlock *OrigHeader = L->getHeader();
|
|
|
|
|
|
|
|
BranchInst *BI = dyn_cast<BranchInst>(OrigHeader->getTerminator());
|
|
|
|
if (BI == 0 || BI->isUnconditional())
|
|
|
|
return false;
|
|
|
|
|
2009-06-25 00:22:44 +00:00
|
|
|
// If the loop header is not one of the loop exiting blocks then
|
|
|
|
// either this loop is already rotated or it is not
|
2007-04-07 01:25:15 +00:00
|
|
|
// suitable for loop rotation transformations.
|
2009-10-24 23:34:26 +00:00
|
|
|
if (!L->isLoopExiting(OrigHeader))
|
2007-04-07 01:25:15 +00:00
|
|
|
return false;
|
|
|
|
|
2007-04-09 16:11:48 +00:00
|
|
|
// Updating PHInodes in loops with multiple exits adds complexity.
|
|
|
|
// Keep it simple, and restrict loop rotation to loops with one exit only.
|
|
|
|
// In future, lift this restriction and support for multiple exits if
|
|
|
|
// required.
|
2007-08-21 00:31:24 +00:00
|
|
|
SmallVector<BasicBlock*, 8> ExitBlocks;
|
2007-04-07 01:25:15 +00:00
|
|
|
L->getExitBlocks(ExitBlocks);
|
|
|
|
if (ExitBlocks.size() > 1)
|
|
|
|
return false;
|
|
|
|
|
2011-01-02 07:35:53 +00:00
|
|
|
// Check size of original header and reject loop if it is very big.
|
|
|
|
{
|
|
|
|
CodeMetrics Metrics;
|
|
|
|
Metrics.analyzeBasicBlock(OrigHeader);
|
|
|
|
if (Metrics.NumInsts > MAX_HEADER_SIZE)
|
|
|
|
return false;
|
2009-03-06 03:51:30 +00:00
|
|
|
}
|
|
|
|
|
2007-07-11 23:47:28 +00:00
|
|
|
// Now, this loop is suitable for rotation.
|
2011-01-08 18:06:22 +00:00
|
|
|
BasicBlock *OrigPreHeader = L->getLoopPreheader();
|
|
|
|
BasicBlock *OrigLatch = L->getLoopLatch();
|
|
|
|
assert(OrigPreHeader && OrigLatch && "Loop not in canonical form?");
|
2007-07-11 23:47:28 +00:00
|
|
|
|
2009-09-27 15:37:03 +00:00
|
|
|
// Anything ScalarEvolution may know about this loop or the PHI nodes
|
|
|
|
// in its header will soon be invalidated.
|
|
|
|
if (ScalarEvolution *SE = getAnalysisIfAvailable<ScalarEvolution>())
|
2009-10-31 15:04:55 +00:00
|
|
|
SE->forgetLoop(L);
|
2009-09-27 15:37:03 +00:00
|
|
|
|
2007-04-07 01:25:15 +00:00
|
|
|
// Find new Loop header. NewHeader is a Header's one and only successor
|
2009-01-26 01:57:01 +00:00
|
|
|
// that is inside loop. Header's other successor is outside the
|
|
|
|
// loop. Otherwise loop is not suitable for rotation.
|
2011-01-08 17:48:33 +00:00
|
|
|
BasicBlock *Exit = BI->getSuccessor(0);
|
|
|
|
BasicBlock *NewHeader = BI->getSuccessor(1);
|
2007-04-09 16:11:48 +00:00
|
|
|
if (L->contains(Exit))
|
|
|
|
std::swap(Exit, NewHeader);
|
2009-01-26 01:38:24 +00:00
|
|
|
assert(NewHeader && "Unable to determine new loop header");
|
2007-04-09 16:11:48 +00:00
|
|
|
assert(L->contains(NewHeader) && !L->contains(Exit) &&
|
|
|
|
"Unable to determine loop header and exit blocks");
|
2009-01-26 02:11:30 +00:00
|
|
|
|
2009-06-25 00:22:44 +00:00
|
|
|
// This code assumes that the new header has exactly one predecessor.
|
|
|
|
// Remove any single-entry PHI nodes in it.
|
2009-01-26 02:11:30 +00:00
|
|
|
assert(NewHeader->getSinglePredecessor() &&
|
|
|
|
"New header doesn't have one pred!");
|
|
|
|
FoldSingleEntryPHINodes(NewHeader);
|
2007-04-07 01:25:15 +00:00
|
|
|
|
2009-10-24 23:19:52 +00:00
|
|
|
// Begin by walking OrigHeader and populating ValueMap with an entry for
|
|
|
|
// each Instruction.
|
2007-04-09 16:11:48 +00:00
|
|
|
BasicBlock::iterator I = OrigHeader->begin(), E = OrigHeader->end();
|
2011-01-08 07:21:31 +00:00
|
|
|
ValueToValueMapTy ValueMap;
|
2007-04-09 16:11:48 +00:00
|
|
|
|
2009-10-24 23:19:52 +00:00
|
|
|
// For PHI nodes, the value available in OldPreHeader is just the
|
|
|
|
// incoming value from OldPreHeader.
|
|
|
|
for (; PHINode *PN = dyn_cast<PHINode>(I); ++I)
|
|
|
|
ValueMap[PN] = PN->getIncomingValue(PN->getBasicBlockIndex(OrigPreHeader));
|
2007-04-09 19:04:21 +00:00
|
|
|
|
2010-09-06 01:10:22 +00:00
|
|
|
// For the rest of the instructions, either hoist to the OrigPreheader if
|
|
|
|
// possible or create a clone in the OldPreHeader if not.
|
2009-10-24 23:19:52 +00:00
|
|
|
TerminatorInst *LoopEntryBranch = OrigPreHeader->getTerminator();
|
2010-09-06 01:10:22 +00:00
|
|
|
while (I != E) {
|
|
|
|
Instruction *Inst = I++;
|
|
|
|
|
|
|
|
// 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
|
|
|
|
// execution in the preheader, but does prevent the instruction from
|
|
|
|
// executing in each iteration of the loop. This means it is safe to hoist
|
|
|
|
// something that might trap, but isn't safe to hoist something that reads
|
|
|
|
// memory (without proving that the loop doesn't write).
|
|
|
|
if (L->hasLoopInvariantOperands(Inst) &&
|
|
|
|
!Inst->mayReadFromMemory() && !Inst->mayWriteToMemory() &&
|
|
|
|
!isa<TerminatorInst>(Inst)) {
|
|
|
|
Inst->moveBefore(LoopEntryBranch);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, create a duplicate of the instruction.
|
|
|
|
Instruction *C = Inst->clone();
|
2011-01-08 08:15:20 +00:00
|
|
|
|
2011-01-08 08:24:46 +00:00
|
|
|
// Eagerly remap the operands of the instruction.
|
|
|
|
RemapInstruction(C, ValueMap,
|
|
|
|
RF_NoModuleLevelChanges|RF_IgnoreMissingEntries);
|
|
|
|
|
|
|
|
// With the operands remapped, see if the instruction constant folds or is
|
|
|
|
// otherwise simplifyable. This commonly occurs because the entry from PHI
|
|
|
|
// nodes allows icmps and other instructions to fold.
|
2011-01-08 17:38:45 +00:00
|
|
|
Value *V = SimplifyInstruction(C);
|
|
|
|
if (V && LI->replacementPreservesLCSSAForm(C, V)) {
|
2011-01-08 08:24:46 +00:00
|
|
|
// If so, then delete the temporary instruction and stick the folded value
|
|
|
|
// in the map.
|
|
|
|
delete C;
|
|
|
|
ValueMap[Inst] = V;
|
|
|
|
} else {
|
|
|
|
// Otherwise, stick the new instruction into the new block!
|
|
|
|
C->setName(Inst->getName());
|
|
|
|
C->insertBefore(LoopEntryBranch);
|
|
|
|
ValueMap[Inst] = C;
|
|
|
|
}
|
2007-04-07 01:25:15 +00:00
|
|
|
}
|
|
|
|
|
2009-10-24 23:19:52 +00:00
|
|
|
// Along with all the other instructions, we just cloned OrigHeader's
|
|
|
|
// terminator into OrigPreHeader. Fix up the PHI nodes in each of OrigHeader's
|
|
|
|
// successors by duplicating their incoming values for OrigHeader.
|
|
|
|
TerminatorInst *TI = OrigHeader->getTerminator();
|
|
|
|
for (unsigned i = 0, e = TI->getNumSuccessors(); i != e; ++i)
|
|
|
|
for (BasicBlock::iterator BI = TI->getSuccessor(i)->begin();
|
|
|
|
PHINode *PN = dyn_cast<PHINode>(BI); ++BI)
|
|
|
|
PN->addIncoming(PN->getIncomingValueForBlock(OrigHeader), OrigPreHeader);
|
|
|
|
|
|
|
|
// Now that OrigPreHeader has a clone of OrigHeader's terminator, remove
|
|
|
|
// OrigPreHeader's old terminator (the original branch into the loop), and
|
|
|
|
// remove the corresponding incoming values from the PHI nodes in OrigHeader.
|
|
|
|
LoopEntryBranch->eraseFromParent();
|
|
|
|
for (I = OrigHeader->begin(); PHINode *PN = dyn_cast<PHINode>(I); ++I)
|
|
|
|
PN->removeIncomingValue(PN->getBasicBlockIndex(OrigPreHeader));
|
|
|
|
|
2009-10-26 15:55:24 +00:00
|
|
|
// Now fix up users of the instructions in OrigHeader, inserting PHI nodes
|
2009-10-24 23:19:52 +00:00
|
|
|
// as necessary.
|
|
|
|
SSAUpdater SSA;
|
|
|
|
for (I = OrigHeader->begin(); I != E; ++I) {
|
|
|
|
Value *OrigHeaderVal = I;
|
|
|
|
Value *OrigPreHeaderVal = ValueMap[OrigHeaderVal];
|
|
|
|
|
2011-01-08 07:21:31 +00:00
|
|
|
// If there are no uses of the value (e.g. because it returns void), there
|
|
|
|
// is nothing to rewrite.
|
|
|
|
if (OrigHeaderVal->use_empty() && OrigPreHeaderVal->use_empty())
|
|
|
|
continue;
|
|
|
|
|
2009-10-24 23:19:52 +00:00
|
|
|
// The value now exits in two versions: the initial value in the preheader
|
|
|
|
// and the loop "next" value in the original header.
|
2010-09-02 08:14:03 +00:00
|
|
|
SSA.Initialize(OrigHeaderVal->getType(), OrigHeaderVal->getName());
|
2009-10-24 23:19:52 +00:00
|
|
|
SSA.AddAvailableValue(OrigHeader, OrigHeaderVal);
|
|
|
|
SSA.AddAvailableValue(OrigPreHeader, OrigPreHeaderVal);
|
|
|
|
|
|
|
|
// Visit each use of the OrigHeader instruction.
|
|
|
|
for (Value::use_iterator UI = OrigHeaderVal->use_begin(),
|
|
|
|
UE = OrigHeaderVal->use_end(); UI != UE; ) {
|
|
|
|
// Grab the use before incrementing the iterator.
|
|
|
|
Use &U = UI.getUse();
|
|
|
|
|
|
|
|
// Increment the iterator before removing the use from the list.
|
|
|
|
++UI;
|
|
|
|
|
|
|
|
// SSAUpdater can't handle a non-PHI use in the same block as an
|
|
|
|
// earlier def. We can easily handle those cases manually.
|
|
|
|
Instruction *UserInst = cast<Instruction>(U.getUser());
|
|
|
|
if (!isa<PHINode>(UserInst)) {
|
|
|
|
BasicBlock *UserBB = UserInst->getParent();
|
|
|
|
|
|
|
|
// The original users in the OrigHeader are already using the
|
|
|
|
// original definitions.
|
|
|
|
if (UserBB == OrigHeader)
|
2007-04-09 16:21:29 +00:00
|
|
|
continue;
|
|
|
|
|
2009-10-24 23:19:52 +00:00
|
|
|
// Users in the OrigPreHeader need to use the value to which the
|
|
|
|
// original definitions are mapped.
|
|
|
|
if (UserBB == OrigPreHeader) {
|
|
|
|
U = OrigPreHeaderVal;
|
2007-04-07 01:25:15 +00:00
|
|
|
continue;
|
2009-10-24 23:19:52 +00:00
|
|
|
}
|
2007-04-07 01:25:15 +00:00
|
|
|
}
|
|
|
|
|
2009-10-24 23:19:52 +00:00
|
|
|
// Anything else can be handled by SSAUpdater.
|
|
|
|
SSA.RewriteUse(U);
|
2007-04-07 01:25:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-24 23:19:52 +00:00
|
|
|
// NewHeader is now the header of the loop.
|
2007-04-07 01:25:15 +00:00
|
|
|
L->moveToHeader(NewHeader);
|
|
|
|
|
2010-08-17 17:39:21 +00:00
|
|
|
// Move the original header to the bottom of the loop, where it now more
|
|
|
|
// naturally belongs. This isn't necessary for correctness, and CodeGen can
|
|
|
|
// usually reorder blocks on its own to fix things like this up, but it's
|
|
|
|
// still nice to keep the IR readable.
|
|
|
|
//
|
|
|
|
// The original header should have only one predecessor at this point, since
|
|
|
|
// we checked that the loop had a proper preheader and unique backedge before
|
|
|
|
// we started.
|
|
|
|
assert(OrigHeader->getSinglePredecessor() &&
|
|
|
|
"Original loop header has too many predecessors after loop rotation!");
|
|
|
|
OrigHeader->moveAfter(OrigHeader->getSinglePredecessor());
|
|
|
|
|
|
|
|
// Also, since this original header only has one predecessor, zap its
|
|
|
|
// PHI nodes, which are now trivial.
|
|
|
|
FoldSingleEntryPHINodes(OrigHeader);
|
2011-01-08 18:52:51 +00:00
|
|
|
|
2010-08-17 17:39:21 +00:00
|
|
|
// TODO: We could just go ahead and merge OrigHeader into its predecessor
|
|
|
|
// at this point, if we don't mind updating dominator info.
|
|
|
|
|
|
|
|
// Establish a new preheader, update dominators, etc.
|
2011-01-08 17:48:33 +00:00
|
|
|
preserveCanonicalLoopForm(L, OrigHeader, OrigPreHeader, OrigLatch,
|
|
|
|
NewHeader, Exit);
|
2007-04-09 20:19:46 +00:00
|
|
|
|
2010-06-22 15:08:57 +00:00
|
|
|
++NumRotated;
|
2007-04-07 01:25:15 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-04-09 20:19:46 +00:00
|
|
|
|
2011-01-08 18:52:51 +00:00
|
|
|
/// Update LoopInfo, DominatorTree, and DomFrontiers to reflect the CFG change
|
|
|
|
/// we just made. Then split edges as necessary to preserve LoopSimplify form.
|
2011-01-08 17:48:33 +00:00
|
|
|
void LoopRotate::preserveCanonicalLoopForm(Loop *L, BasicBlock *OrigHeader,
|
|
|
|
BasicBlock *OrigPreHeader,
|
|
|
|
BasicBlock *OrigLatch,
|
|
|
|
BasicBlock *NewHeader,
|
|
|
|
BasicBlock *Exit) {
|
2011-01-08 18:52:51 +00:00
|
|
|
assert(L->getHeader() == NewHeader && "Latch block is our new header");
|
2007-04-09 20:19:46 +00:00
|
|
|
|
2009-01-28 13:14:17 +00:00
|
|
|
if (DominatorTree *DT = getAnalysisIfAvailable<DominatorTree>()) {
|
2011-01-08 18:52:51 +00:00
|
|
|
// Since OrigPreheader now has the conditional branch to Exit block, it is
|
|
|
|
// the dominator of Exit.
|
2007-07-11 23:47:28 +00:00
|
|
|
DT->changeImmediateDominator(Exit, OrigPreHeader);
|
2011-01-08 18:52:51 +00:00
|
|
|
DT->changeImmediateDominator(NewHeader, OrigPreHeader);
|
|
|
|
|
|
|
|
// Update OrigHeader to be dominated by the new header block.
|
2007-07-11 23:47:28 +00:00
|
|
|
DT->changeImmediateDominator(OrigHeader, OrigLatch);
|
|
|
|
}
|
2011-01-08 18:52:51 +00:00
|
|
|
|
|
|
|
// Right now OrigPreHeader has two successors, NewHeader and ExitBlock, and
|
|
|
|
// thus is not a preheader anymore. Split the edge to form a real preheader.
|
|
|
|
BasicBlock *NewPH = SplitCriticalEdge(OrigPreHeader, NewHeader, this);
|
|
|
|
NewPH->setName(NewHeader->getName() + ".lr.ph");
|
|
|
|
|
|
|
|
// Preserve canonical loop form, which means Exit block should have only one
|
|
|
|
// predecessor.
|
|
|
|
SplitCriticalEdge(L->getLoopLatch(), Exit, this);
|
2007-07-11 23:47:28 +00:00
|
|
|
|
2009-01-26 01:38:24 +00:00
|
|
|
assert(NewHeader && L->getHeader() == NewHeader &&
|
|
|
|
"Invalid loop header after loop rotation");
|
2011-01-08 18:52:51 +00:00
|
|
|
assert(L->getLoopPreheader() == NewPH &&
|
2009-01-26 01:38:24 +00:00
|
|
|
"Invalid loop preheader after loop rotation");
|
2011-01-08 18:52:51 +00:00
|
|
|
assert(L->getLoopLatch() && "Invalid loop latch after loop rotation");
|
2007-04-09 20:19:46 +00:00
|
|
|
}
|