mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-09-27 16:17:17 +00:00
Update various Loop optimization passes to cope with the possibility that
LoopSimplify form may not be available. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@86175 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -75,6 +75,10 @@ bool LoopExtractor::runOnLoop(Loop *L, LPPassManager &LPM) {
|
|||||||
if (L->getParentLoop())
|
if (L->getParentLoop())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
// If LoopSimplify form is not available, stay out of trouble.
|
||||||
|
if (!L->isLoopSimplifyForm())
|
||||||
|
return false;
|
||||||
|
|
||||||
DominatorTree &DT = getAnalysis<DominatorTree>();
|
DominatorTree &DT = getAnalysis<DominatorTree>();
|
||||||
bool Changed = false;
|
bool Changed = false;
|
||||||
|
|
||||||
|
@@ -536,8 +536,10 @@ void IndVarSimplify::SinkUnusedInvariants(Loop *L) {
|
|||||||
BasicBlock *ExitBlock = L->getExitBlock();
|
BasicBlock *ExitBlock = L->getExitBlock();
|
||||||
if (!ExitBlock) return;
|
if (!ExitBlock) return;
|
||||||
|
|
||||||
Instruction *InsertPt = ExitBlock->getFirstNonPHI();
|
|
||||||
BasicBlock *Preheader = L->getLoopPreheader();
|
BasicBlock *Preheader = L->getLoopPreheader();
|
||||||
|
if (!Preheader) return;
|
||||||
|
|
||||||
|
Instruction *InsertPt = ExitBlock->getFirstNonPHI();
|
||||||
BasicBlock::iterator I = Preheader->getTerminator();
|
BasicBlock::iterator I = Preheader->getTerminator();
|
||||||
while (I != Preheader->begin()) {
|
while (I != Preheader->begin()) {
|
||||||
--I;
|
--I;
|
||||||
|
@@ -263,7 +263,6 @@ bool LICM::runOnLoop(Loop *L, LPPassManager &LPM) {
|
|||||||
|
|
||||||
// Get the preheader block to move instructions into...
|
// Get the preheader block to move instructions into...
|
||||||
Preheader = L->getLoopPreheader();
|
Preheader = L->getLoopPreheader();
|
||||||
assert(Preheader&&"Preheader insertion pass guarantees we have a preheader!");
|
|
||||||
|
|
||||||
// Loop over the body of this loop, looking for calls, invokes, and stores.
|
// Loop over the body of this loop, looking for calls, invokes, and stores.
|
||||||
// Because subloops have already been incorporated into AST, we skip blocks in
|
// Because subloops have already been incorporated into AST, we skip blocks in
|
||||||
@@ -286,12 +285,14 @@ bool LICM::runOnLoop(Loop *L, LPPassManager &LPM) {
|
|||||||
// us to sink instructions in one pass, without iteration. After sinking
|
// us to sink instructions in one pass, without iteration. After sinking
|
||||||
// instructions, we perform another pass to hoist them out of the loop.
|
// instructions, we perform another pass to hoist them out of the loop.
|
||||||
//
|
//
|
||||||
SinkRegion(DT->getNode(L->getHeader()));
|
if (L->hasDedicatedExits())
|
||||||
HoistRegion(DT->getNode(L->getHeader()));
|
SinkRegion(DT->getNode(L->getHeader()));
|
||||||
|
if (Preheader)
|
||||||
|
HoistRegion(DT->getNode(L->getHeader()));
|
||||||
|
|
||||||
// Now that all loop invariants have been removed from the loop, promote any
|
// Now that all loop invariants have been removed from the loop, promote any
|
||||||
// memory references to scalars that we can...
|
// memory references to scalars that we can...
|
||||||
if (!DisablePromotion)
|
if (!DisablePromotion && Preheader && L->hasDedicatedExits())
|
||||||
PromoteValuesInLoop();
|
PromoteValuesInLoop();
|
||||||
|
|
||||||
// Clear out loops state information for the next iteration
|
// Clear out loops state information for the next iteration
|
||||||
|
@@ -209,6 +209,10 @@ bool LoopIndexSplit::runOnLoop(Loop *IncomingLoop, LPPassManager &LPM_Ref) {
|
|||||||
L = IncomingLoop;
|
L = IncomingLoop;
|
||||||
LPM = &LPM_Ref;
|
LPM = &LPM_Ref;
|
||||||
|
|
||||||
|
// If LoopSimplify form is not available, stay out of trouble.
|
||||||
|
if (!L->isLoopSimplifyForm())
|
||||||
|
return false;
|
||||||
|
|
||||||
// FIXME - Nested loops make dominator info updates tricky.
|
// FIXME - Nested loops make dominator info updates tricky.
|
||||||
if (!L->getSubLoops().empty())
|
if (!L->getSubLoops().empty())
|
||||||
return false;
|
return false;
|
||||||
|
@@ -104,17 +104,18 @@ bool LoopRotate::runOnLoop(Loop *Lp, LPPassManager &LPM) {
|
|||||||
bool LoopRotate::rotateLoop(Loop *Lp, LPPassManager &LPM) {
|
bool LoopRotate::rotateLoop(Loop *Lp, LPPassManager &LPM) {
|
||||||
L = Lp;
|
L = Lp;
|
||||||
|
|
||||||
OrigHeader = L->getHeader();
|
|
||||||
OrigPreHeader = L->getLoopPreheader();
|
OrigPreHeader = L->getLoopPreheader();
|
||||||
|
if (!OrigPreHeader) return false;
|
||||||
|
|
||||||
OrigLatch = L->getLoopLatch();
|
OrigLatch = L->getLoopLatch();
|
||||||
|
if (!OrigLatch) return false;
|
||||||
|
|
||||||
|
OrigHeader = L->getHeader();
|
||||||
|
|
||||||
// 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;
|
||||||
|
|
||||||
assert(OrigHeader && OrigLatch && OrigPreHeader &&
|
|
||||||
"Loop is not in canonical form");
|
|
||||||
|
|
||||||
// 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.
|
||||||
|
@@ -2528,6 +2528,10 @@ bool LoopStrengthReduce::runOnLoop(Loop *L, LPPassManager &LPM) {
|
|||||||
SE = &getAnalysis<ScalarEvolution>();
|
SE = &getAnalysis<ScalarEvolution>();
|
||||||
Changed = false;
|
Changed = false;
|
||||||
|
|
||||||
|
// If LoopSimplify form is not available, stay out of trouble.
|
||||||
|
if (!L->getLoopPreheader() || !L->getLoopLatch())
|
||||||
|
return false;
|
||||||
|
|
||||||
if (!IU->IVUsesByStride.empty()) {
|
if (!IU->IVUsesByStride.empty()) {
|
||||||
DEBUG(errs() << "\nLSR on \"" << L->getHeader()->getParent()->getName()
|
DEBUG(errs() << "\nLSR on \"" << L->getHeader()->getParent()->getName()
|
||||||
<< "\" ";
|
<< "\" ";
|
||||||
|
@@ -407,6 +407,10 @@ bool LoopUnswitch::UnswitchIfProfitable(Value *LoopCond, Constant *Val){
|
|||||||
initLoopData();
|
initLoopData();
|
||||||
Function *F = loopHeader->getParent();
|
Function *F = loopHeader->getParent();
|
||||||
|
|
||||||
|
// If LoopSimplify was unable to form a preheader, don't do any unswitching.
|
||||||
|
if (!loopPreheader)
|
||||||
|
return false;
|
||||||
|
|
||||||
// If the condition is trivial, always unswitch. There is no code growth for
|
// If the condition is trivial, always unswitch. There is no code growth for
|
||||||
// this case.
|
// this case.
|
||||||
if (!IsTrivialUnswitchCondition(LoopCond)) {
|
if (!IsTrivialUnswitchCondition(LoopCond)) {
|
||||||
|
Reference in New Issue
Block a user