Initial commit of the machine code LICM pass. It successfully hoists this:
_foo:
li r2, 0
LBB1_1: ; bb
li r5, 0
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
to:
_foo:
li r2, 0
li r5, 0
LBB1_1: ; bb
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
ZOMG!! :-)
Moar to come...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44687 91177308-0d34-0410-b5e6-96231b3b80d8
2007-12-07 21:42:31 +00:00
|
|
|
//===-- MachineLICM.cpp - Machine Loop Invariant Code Motion 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.
|
Initial commit of the machine code LICM pass. It successfully hoists this:
_foo:
li r2, 0
LBB1_1: ; bb
li r5, 0
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
to:
_foo:
li r2, 0
li r5, 0
LBB1_1: ; bb
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
ZOMG!! :-)
Moar to come...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44687 91177308-0d34-0410-b5e6-96231b3b80d8
2007-12-07 21:42:31 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This pass performs loop invariant code motion on machine instructions. We
|
|
|
|
// attempt to remove as much code from the body of a loop as possible.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#define DEBUG_TYPE "machine-licm"
|
2008-01-04 06:41:45 +00:00
|
|
|
#include "llvm/CodeGen/Passes.h"
|
Initial commit of the machine code LICM pass. It successfully hoists this:
_foo:
li r2, 0
LBB1_1: ; bb
li r5, 0
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
to:
_foo:
li r2, 0
li r5, 0
LBB1_1: ; bb
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
ZOMG!! :-)
Moar to come...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44687 91177308-0d34-0410-b5e6-96231b3b80d8
2007-12-07 21:42:31 +00:00
|
|
|
#include "llvm/CodeGen/MachineDominators.h"
|
|
|
|
#include "llvm/CodeGen/MachineLoopInfo.h"
|
2008-01-02 19:32:43 +00:00
|
|
|
#include "llvm/CodeGen/MachineRegisterInfo.h"
|
Initial commit of the machine code LICM pass. It successfully hoists this:
_foo:
li r2, 0
LBB1_1: ; bb
li r5, 0
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
to:
_foo:
li r2, 0
li r5, 0
LBB1_1: ; bb
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
ZOMG!! :-)
Moar to come...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44687 91177308-0d34-0410-b5e6-96231b3b80d8
2007-12-07 21:42:31 +00:00
|
|
|
#include "llvm/Target/MRegisterInfo.h"
|
2007-12-11 23:27:51 +00:00
|
|
|
#include "llvm/Target/TargetInstrInfo.h"
|
Initial commit of the machine code LICM pass. It successfully hoists this:
_foo:
li r2, 0
LBB1_1: ; bb
li r5, 0
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
to:
_foo:
li r2, 0
li r5, 0
LBB1_1: ; bb
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
ZOMG!! :-)
Moar to come...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44687 91177308-0d34-0410-b5e6-96231b3b80d8
2007-12-07 21:42:31 +00:00
|
|
|
#include "llvm/Target/TargetMachine.h"
|
2008-01-04 06:41:45 +00:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
#include "llvm/ADT/Statistic.h"
|
|
|
|
#include "llvm/Support/CommandLine.h"
|
|
|
|
#include "llvm/Support/Compiler.h"
|
|
|
|
#include "llvm/Support/Debug.h"
|
Initial commit of the machine code LICM pass. It successfully hoists this:
_foo:
li r2, 0
LBB1_1: ; bb
li r5, 0
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
to:
_foo:
li r2, 0
li r5, 0
LBB1_1: ; bb
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
ZOMG!! :-)
Moar to come...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44687 91177308-0d34-0410-b5e6-96231b3b80d8
2007-12-07 21:42:31 +00:00
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2007-12-08 23:58:46 +00:00
|
|
|
STATISTIC(NumHoisted, "Number of machine instructions hoisted out of loops");
|
2007-12-08 01:47:01 +00:00
|
|
|
|
Initial commit of the machine code LICM pass. It successfully hoists this:
_foo:
li r2, 0
LBB1_1: ; bb
li r5, 0
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
to:
_foo:
li r2, 0
li r5, 0
LBB1_1: ; bb
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
ZOMG!! :-)
Moar to come...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44687 91177308-0d34-0410-b5e6-96231b3b80d8
2007-12-07 21:42:31 +00:00
|
|
|
namespace {
|
|
|
|
class VISIBILITY_HIDDEN MachineLICM : public MachineFunctionPass {
|
2008-01-02 19:32:43 +00:00
|
|
|
const TargetMachine *TM;
|
2007-12-11 23:27:51 +00:00
|
|
|
const TargetInstrInfo *TII;
|
|
|
|
MachineFunction *CurMF; // Current MachineFunction
|
2007-12-11 19:40:06 +00:00
|
|
|
|
Initial commit of the machine code LICM pass. It successfully hoists this:
_foo:
li r2, 0
LBB1_1: ; bb
li r5, 0
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
to:
_foo:
li r2, 0
li r5, 0
LBB1_1: ; bb
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
ZOMG!! :-)
Moar to come...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44687 91177308-0d34-0410-b5e6-96231b3b80d8
2007-12-07 21:42:31 +00:00
|
|
|
// Various analyses that we use...
|
|
|
|
MachineLoopInfo *LI; // Current MachineLoopInfo
|
|
|
|
MachineDominatorTree *DT; // Machine dominator tree for the current Loop
|
2008-01-02 19:32:43 +00:00
|
|
|
MachineRegisterInfo *RegInfo; // Machine register information
|
Initial commit of the machine code LICM pass. It successfully hoists this:
_foo:
li r2, 0
LBB1_1: ; bb
li r5, 0
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
to:
_foo:
li r2, 0
li r5, 0
LBB1_1: ; bb
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
ZOMG!! :-)
Moar to come...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44687 91177308-0d34-0410-b5e6-96231b3b80d8
2007-12-07 21:42:31 +00:00
|
|
|
|
|
|
|
// State that is updated as we process loops
|
|
|
|
bool Changed; // True if a loop is changed.
|
|
|
|
MachineLoop *CurLoop; // The current loop we are working on.
|
|
|
|
public:
|
|
|
|
static char ID; // Pass identification, replacement for typeid
|
|
|
|
MachineLICM() : MachineFunctionPass((intptr_t)&ID) {}
|
|
|
|
|
|
|
|
virtual bool runOnMachineFunction(MachineFunction &MF);
|
|
|
|
|
|
|
|
/// FIXME: Loop preheaders?
|
|
|
|
///
|
|
|
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
2008-01-04 07:50:05 +00:00
|
|
|
MachineFunctionPass::getAnalysisUsage(AU);
|
Initial commit of the machine code LICM pass. It successfully hoists this:
_foo:
li r2, 0
LBB1_1: ; bb
li r5, 0
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
to:
_foo:
li r2, 0
li r5, 0
LBB1_1: ; bb
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
ZOMG!! :-)
Moar to come...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44687 91177308-0d34-0410-b5e6-96231b3b80d8
2007-12-07 21:42:31 +00:00
|
|
|
AU.setPreservesCFG();
|
|
|
|
AU.addRequired<MachineLoopInfo>();
|
|
|
|
AU.addRequired<MachineDominatorTree>();
|
|
|
|
}
|
|
|
|
private:
|
2007-12-08 01:47:01 +00:00
|
|
|
/// VisitAllLoops - Visit all of the loops in depth first order and try to
|
|
|
|
/// hoist invariant instructions from them.
|
Initial commit of the machine code LICM pass. It successfully hoists this:
_foo:
li r2, 0
LBB1_1: ; bb
li r5, 0
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
to:
_foo:
li r2, 0
li r5, 0
LBB1_1: ; bb
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
ZOMG!! :-)
Moar to come...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44687 91177308-0d34-0410-b5e6-96231b3b80d8
2007-12-07 21:42:31 +00:00
|
|
|
///
|
2007-12-08 01:47:01 +00:00
|
|
|
void VisitAllLoops(MachineLoop *L) {
|
Initial commit of the machine code LICM pass. It successfully hoists this:
_foo:
li r2, 0
LBB1_1: ; bb
li r5, 0
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
to:
_foo:
li r2, 0
li r5, 0
LBB1_1: ; bb
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
ZOMG!! :-)
Moar to come...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44687 91177308-0d34-0410-b5e6-96231b3b80d8
2007-12-07 21:42:31 +00:00
|
|
|
const std::vector<MachineLoop*> &SubLoops = L->getSubLoops();
|
|
|
|
|
|
|
|
for (MachineLoop::iterator
|
2007-12-08 01:47:01 +00:00
|
|
|
I = SubLoops.begin(), E = SubLoops.end(); I != E; ++I) {
|
|
|
|
MachineLoop *ML = *I;
|
|
|
|
|
|
|
|
// Traverse the body of the loop in depth first order on the dominator
|
|
|
|
// tree so that we are guaranteed to see definitions before we see uses.
|
|
|
|
VisitAllLoops(ML);
|
|
|
|
HoistRegion(DT->getNode(ML->getHeader()));
|
|
|
|
}
|
Initial commit of the machine code LICM pass. It successfully hoists this:
_foo:
li r2, 0
LBB1_1: ; bb
li r5, 0
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
to:
_foo:
li r2, 0
li r5, 0
LBB1_1: ; bb
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
ZOMG!! :-)
Moar to come...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44687 91177308-0d34-0410-b5e6-96231b3b80d8
2007-12-07 21:42:31 +00:00
|
|
|
|
2007-12-08 01:47:01 +00:00
|
|
|
HoistRegion(DT->getNode(L->getHeader()));
|
Initial commit of the machine code LICM pass. It successfully hoists this:
_foo:
li r2, 0
LBB1_1: ; bb
li r5, 0
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
to:
_foo:
li r2, 0
li r5, 0
LBB1_1: ; bb
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
ZOMG!! :-)
Moar to come...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44687 91177308-0d34-0410-b5e6-96231b3b80d8
2007-12-07 21:42:31 +00:00
|
|
|
}
|
|
|
|
|
2007-12-08 23:58:46 +00:00
|
|
|
/// IsInSubLoop - A little predicate that returns true if the specified
|
Initial commit of the machine code LICM pass. It successfully hoists this:
_foo:
li r2, 0
LBB1_1: ; bb
li r5, 0
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
to:
_foo:
li r2, 0
li r5, 0
LBB1_1: ; bb
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
ZOMG!! :-)
Moar to come...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44687 91177308-0d34-0410-b5e6-96231b3b80d8
2007-12-07 21:42:31 +00:00
|
|
|
/// basic block is in a subloop of the current one, not the current one
|
|
|
|
/// itself.
|
|
|
|
///
|
2007-12-08 23:58:46 +00:00
|
|
|
bool IsInSubLoop(MachineBasicBlock *BB) {
|
Initial commit of the machine code LICM pass. It successfully hoists this:
_foo:
li r2, 0
LBB1_1: ; bb
li r5, 0
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
to:
_foo:
li r2, 0
li r5, 0
LBB1_1: ; bb
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
ZOMG!! :-)
Moar to come...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44687 91177308-0d34-0410-b5e6-96231b3b80d8
2007-12-07 21:42:31 +00:00
|
|
|
assert(CurLoop->contains(BB) && "Only valid if BB is IN the loop");
|
2007-12-11 18:45:11 +00:00
|
|
|
return LI->getLoopFor(BB) != CurLoop;
|
Initial commit of the machine code LICM pass. It successfully hoists this:
_foo:
li r2, 0
LBB1_1: ; bb
li r5, 0
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
to:
_foo:
li r2, 0
li r5, 0
LBB1_1: ; bb
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
ZOMG!! :-)
Moar to come...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44687 91177308-0d34-0410-b5e6-96231b3b80d8
2007-12-07 21:42:31 +00:00
|
|
|
}
|
|
|
|
|
2007-12-08 23:58:46 +00:00
|
|
|
/// IsLoopInvariantInst - Returns true if the instruction is loop
|
Initial commit of the machine code LICM pass. It successfully hoists this:
_foo:
li r2, 0
LBB1_1: ; bb
li r5, 0
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
to:
_foo:
li r2, 0
li r5, 0
LBB1_1: ; bb
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
ZOMG!! :-)
Moar to come...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44687 91177308-0d34-0410-b5e6-96231b3b80d8
2007-12-07 21:42:31 +00:00
|
|
|
/// invariant. I.e., all virtual register operands are defined outside of
|
|
|
|
/// the loop, physical registers aren't accessed (explicitly or implicitly),
|
|
|
|
/// and the instruction is hoistable.
|
|
|
|
///
|
2007-12-08 23:58:46 +00:00
|
|
|
bool IsLoopInvariantInst(MachineInstr &I);
|
Initial commit of the machine code LICM pass. It successfully hoists this:
_foo:
li r2, 0
LBB1_1: ; bb
li r5, 0
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
to:
_foo:
li r2, 0
li r5, 0
LBB1_1: ; bb
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
ZOMG!! :-)
Moar to come...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44687 91177308-0d34-0410-b5e6-96231b3b80d8
2007-12-07 21:42:31 +00:00
|
|
|
|
|
|
|
/// FindPredecessors - Get all of the predecessors of the loop that are not
|
|
|
|
/// back-edges.
|
|
|
|
///
|
2007-12-11 18:45:11 +00:00
|
|
|
void FindPredecessors(std::vector<MachineBasicBlock*> &Preds) {
|
Initial commit of the machine code LICM pass. It successfully hoists this:
_foo:
li r2, 0
LBB1_1: ; bb
li r5, 0
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
to:
_foo:
li r2, 0
li r5, 0
LBB1_1: ; bb
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
ZOMG!! :-)
Moar to come...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44687 91177308-0d34-0410-b5e6-96231b3b80d8
2007-12-07 21:42:31 +00:00
|
|
|
const MachineBasicBlock *Header = CurLoop->getHeader();
|
|
|
|
|
|
|
|
for (MachineBasicBlock::const_pred_iterator
|
|
|
|
I = Header->pred_begin(), E = Header->pred_end(); I != E; ++I)
|
|
|
|
if (!CurLoop->contains(*I))
|
|
|
|
Preds.push_back(*I);
|
|
|
|
}
|
|
|
|
|
2007-12-08 01:47:01 +00:00
|
|
|
/// MoveInstToEndOfBlock - Moves the machine instruction to the bottom of
|
|
|
|
/// the predecessor basic block (but before the terminator instructions).
|
Initial commit of the machine code LICM pass. It successfully hoists this:
_foo:
li r2, 0
LBB1_1: ; bb
li r5, 0
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
to:
_foo:
li r2, 0
li r5, 0
LBB1_1: ; bb
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
ZOMG!! :-)
Moar to come...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44687 91177308-0d34-0410-b5e6-96231b3b80d8
2007-12-07 21:42:31 +00:00
|
|
|
///
|
2008-01-02 19:32:43 +00:00
|
|
|
void MoveInstToEndOfBlock(MachineBasicBlock *ToMBB,
|
|
|
|
MachineBasicBlock *FromMBB,
|
|
|
|
MachineInstr *MI) {
|
2007-12-11 23:27:51 +00:00
|
|
|
DEBUG({
|
|
|
|
DOUT << "Hoisting " << *MI;
|
2008-01-02 19:32:43 +00:00
|
|
|
if (ToMBB->getBasicBlock())
|
2007-12-11 23:27:51 +00:00
|
|
|
DOUT << " to MachineBasicBlock "
|
2008-01-02 19:32:43 +00:00
|
|
|
<< ToMBB->getBasicBlock()->getName();
|
2007-12-11 23:27:51 +00:00
|
|
|
DOUT << "\n";
|
|
|
|
});
|
2008-01-02 19:32:43 +00:00
|
|
|
|
|
|
|
MachineBasicBlock::iterator WhereIter = ToMBB->getFirstTerminator();
|
|
|
|
MachineBasicBlock::iterator To, From = FromMBB->begin();
|
|
|
|
|
|
|
|
while (&*From != MI)
|
|
|
|
++From;
|
|
|
|
|
|
|
|
assert(From != FromMBB->end() && "Didn't find instr in BB!");
|
|
|
|
|
|
|
|
To = From;
|
|
|
|
ToMBB->splice(WhereIter, FromMBB, From, ++To);
|
2007-12-08 01:47:01 +00:00
|
|
|
++NumHoisted;
|
Initial commit of the machine code LICM pass. It successfully hoists this:
_foo:
li r2, 0
LBB1_1: ; bb
li r5, 0
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
to:
_foo:
li r2, 0
li r5, 0
LBB1_1: ; bb
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
ZOMG!! :-)
Moar to come...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44687 91177308-0d34-0410-b5e6-96231b3b80d8
2007-12-07 21:42:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// HoistRegion - Walk the specified region of the CFG (defined by all
|
|
|
|
/// blocks dominated by the specified block, and that are in the current
|
|
|
|
/// loop) in depth first order w.r.t the DominatorTree. This allows us to
|
|
|
|
/// visit definitions before uses, allowing us to hoist a loop body in one
|
|
|
|
/// pass without iteration.
|
|
|
|
///
|
|
|
|
void HoistRegion(MachineDomTreeNode *N);
|
|
|
|
|
|
|
|
/// Hoist - When an instruction is found to only use loop invariant operands
|
|
|
|
/// that is safe to hoist, this instruction is called to do the dirty work.
|
|
|
|
///
|
2007-12-08 01:47:01 +00:00
|
|
|
void Hoist(MachineInstr &MI);
|
Initial commit of the machine code LICM pass. It successfully hoists this:
_foo:
li r2, 0
LBB1_1: ; bb
li r5, 0
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
to:
_foo:
li r2, 0
li r5, 0
LBB1_1: ; bb
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
ZOMG!! :-)
Moar to come...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44687 91177308-0d34-0410-b5e6-96231b3b80d8
2007-12-07 21:42:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
char MachineLICM::ID = 0;
|
|
|
|
RegisterPass<MachineLICM> X("machine-licm",
|
|
|
|
"Machine Loop Invariant Code Motion");
|
|
|
|
} // end anonymous namespace
|
|
|
|
|
|
|
|
FunctionPass *llvm::createMachineLICMPass() { return new MachineLICM(); }
|
|
|
|
|
|
|
|
/// Hoist expressions out of the specified loop. Note, alias info for inner loop
|
|
|
|
/// is not preserved so it is not a good idea to run LICM multiple times on one
|
|
|
|
/// loop.
|
|
|
|
///
|
|
|
|
bool MachineLICM::runOnMachineFunction(MachineFunction &MF) {
|
2007-12-11 22:22:22 +00:00
|
|
|
DOUT << "******** Machine LICM ********\n";
|
|
|
|
|
Initial commit of the machine code LICM pass. It successfully hoists this:
_foo:
li r2, 0
LBB1_1: ; bb
li r5, 0
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
to:
_foo:
li r2, 0
li r5, 0
LBB1_1: ; bb
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
ZOMG!! :-)
Moar to come...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44687 91177308-0d34-0410-b5e6-96231b3b80d8
2007-12-07 21:42:31 +00:00
|
|
|
Changed = false;
|
2007-12-11 19:40:06 +00:00
|
|
|
CurMF = &MF;
|
2008-01-02 19:32:43 +00:00
|
|
|
TM = &CurMF->getTarget();
|
|
|
|
TII = TM->getInstrInfo();
|
2008-01-02 21:10:54 +00:00
|
|
|
RegInfo = &CurMF->getRegInfo();
|
Initial commit of the machine code LICM pass. It successfully hoists this:
_foo:
li r2, 0
LBB1_1: ; bb
li r5, 0
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
to:
_foo:
li r2, 0
li r5, 0
LBB1_1: ; bb
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
ZOMG!! :-)
Moar to come...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44687 91177308-0d34-0410-b5e6-96231b3b80d8
2007-12-07 21:42:31 +00:00
|
|
|
|
|
|
|
// Get our Loop information...
|
|
|
|
LI = &getAnalysis<MachineLoopInfo>();
|
|
|
|
DT = &getAnalysis<MachineDominatorTree>();
|
|
|
|
|
|
|
|
for (MachineLoopInfo::iterator
|
|
|
|
I = LI->begin(), E = LI->end(); I != E; ++I) {
|
2007-12-11 22:22:22 +00:00
|
|
|
CurLoop = *I;
|
Initial commit of the machine code LICM pass. It successfully hoists this:
_foo:
li r2, 0
LBB1_1: ; bb
li r5, 0
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
to:
_foo:
li r2, 0
li r5, 0
LBB1_1: ; bb
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
ZOMG!! :-)
Moar to come...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44687 91177308-0d34-0410-b5e6-96231b3b80d8
2007-12-07 21:42:31 +00:00
|
|
|
|
|
|
|
// Visit all of the instructions of the loop. We want to visit the subloops
|
|
|
|
// first, though, so that we can hoist their invariants first into their
|
|
|
|
// containing loop before we process that loop.
|
2007-12-11 22:22:22 +00:00
|
|
|
VisitAllLoops(CurLoop);
|
Initial commit of the machine code LICM pass. It successfully hoists this:
_foo:
li r2, 0
LBB1_1: ; bb
li r5, 0
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
to:
_foo:
li r2, 0
li r5, 0
LBB1_1: ; bb
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
ZOMG!! :-)
Moar to come...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44687 91177308-0d34-0410-b5e6-96231b3b80d8
2007-12-07 21:42:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return Changed;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// HoistRegion - Walk the specified region of the CFG (defined by all blocks
|
|
|
|
/// dominated by the specified block, and that are in the current loop) in depth
|
|
|
|
/// first order w.r.t the DominatorTree. This allows us to visit definitions
|
|
|
|
/// before uses, allowing us to hoist a loop body in one pass without iteration.
|
|
|
|
///
|
|
|
|
void MachineLICM::HoistRegion(MachineDomTreeNode *N) {
|
|
|
|
assert(N != 0 && "Null dominator tree node?");
|
|
|
|
MachineBasicBlock *BB = N->getBlock();
|
|
|
|
|
|
|
|
// If this subregion is not in the top level loop at all, exit.
|
|
|
|
if (!CurLoop->contains(BB)) return;
|
|
|
|
|
|
|
|
// Only need to process the contents of this block if it is not part of a
|
|
|
|
// subloop (which would already have been processed).
|
2007-12-08 23:58:46 +00:00
|
|
|
if (!IsInSubLoop(BB))
|
Initial commit of the machine code LICM pass. It successfully hoists this:
_foo:
li r2, 0
LBB1_1: ; bb
li r5, 0
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
to:
_foo:
li r2, 0
li r5, 0
LBB1_1: ; bb
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
ZOMG!! :-)
Moar to come...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44687 91177308-0d34-0410-b5e6-96231b3b80d8
2007-12-07 21:42:31 +00:00
|
|
|
for (MachineBasicBlock::iterator
|
|
|
|
I = BB->begin(), E = BB->end(); I != E; ) {
|
|
|
|
MachineInstr &MI = *I++;
|
|
|
|
|
|
|
|
// Try hoisting the instruction out of the loop. We can only do this if
|
|
|
|
// all of the operands of the instruction are loop invariant and if it is
|
|
|
|
// safe to hoist the instruction.
|
2007-12-08 01:47:01 +00:00
|
|
|
Hoist(MI);
|
Initial commit of the machine code LICM pass. It successfully hoists this:
_foo:
li r2, 0
LBB1_1: ; bb
li r5, 0
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
to:
_foo:
li r2, 0
li r5, 0
LBB1_1: ; bb
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
ZOMG!! :-)
Moar to come...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44687 91177308-0d34-0410-b5e6-96231b3b80d8
2007-12-07 21:42:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const std::vector<MachineDomTreeNode*> &Children = N->getChildren();
|
|
|
|
|
|
|
|
for (unsigned I = 0, E = Children.size(); I != E; ++I)
|
|
|
|
HoistRegion(Children[I]);
|
|
|
|
}
|
|
|
|
|
2007-12-08 23:58:46 +00:00
|
|
|
/// IsLoopInvariantInst - Returns true if the instruction is loop
|
Initial commit of the machine code LICM pass. It successfully hoists this:
_foo:
li r2, 0
LBB1_1: ; bb
li r5, 0
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
to:
_foo:
li r2, 0
li r5, 0
LBB1_1: ; bb
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
ZOMG!! :-)
Moar to come...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44687 91177308-0d34-0410-b5e6-96231b3b80d8
2007-12-07 21:42:31 +00:00
|
|
|
/// invariant. I.e., all virtual register operands are defined outside of the
|
2007-12-20 01:08:10 +00:00
|
|
|
/// loop, physical registers aren't accessed explicitly, and there are no side
|
|
|
|
/// effects that aren't captured by the operands or other flags.
|
Initial commit of the machine code LICM pass. It successfully hoists this:
_foo:
li r2, 0
LBB1_1: ; bb
li r5, 0
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
to:
_foo:
li r2, 0
li r5, 0
LBB1_1: ; bb
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
ZOMG!! :-)
Moar to come...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44687 91177308-0d34-0410-b5e6-96231b3b80d8
2007-12-07 21:42:31 +00:00
|
|
|
///
|
2007-12-08 23:58:46 +00:00
|
|
|
bool MachineLICM::IsLoopInvariantInst(MachineInstr &I) {
|
2007-12-18 21:38:04 +00:00
|
|
|
DEBUG({
|
|
|
|
DOUT << "--- Checking if we can hoist " << I;
|
|
|
|
if (I.getInstrDescriptor()->ImplicitUses) {
|
|
|
|
DOUT << " * Instruction has implicit uses:\n";
|
|
|
|
|
2008-01-02 19:32:43 +00:00
|
|
|
const MRegisterInfo *MRI = TM->getRegisterInfo();
|
2007-12-18 21:38:04 +00:00
|
|
|
const unsigned *ImpUses = I.getInstrDescriptor()->ImplicitUses;
|
|
|
|
|
|
|
|
for (; *ImpUses; ++ImpUses)
|
|
|
|
DOUT << " -> " << MRI->getName(*ImpUses) << "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (I.getInstrDescriptor()->ImplicitDefs) {
|
|
|
|
DOUT << " * Instruction has implicit defines:\n";
|
|
|
|
|
2008-01-02 19:32:43 +00:00
|
|
|
const MRegisterInfo *MRI = TM->getRegisterInfo();
|
2007-12-18 21:38:04 +00:00
|
|
|
const unsigned *ImpDefs = I.getInstrDescriptor()->ImplicitDefs;
|
|
|
|
|
|
|
|
for (; *ImpDefs; ++ImpDefs)
|
|
|
|
DOUT << " -> " << MRI->getName(*ImpDefs) << "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (TII->hasUnmodelledSideEffects(&I))
|
|
|
|
DOUT << " * Instruction has side effects.\n";
|
|
|
|
});
|
|
|
|
|
Initial commit of the machine code LICM pass. It successfully hoists this:
_foo:
li r2, 0
LBB1_1: ; bb
li r5, 0
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
to:
_foo:
li r2, 0
li r5, 0
LBB1_1: ; bb
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
ZOMG!! :-)
Moar to come...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44687 91177308-0d34-0410-b5e6-96231b3b80d8
2007-12-07 21:42:31 +00:00
|
|
|
// The instruction is loop invariant if all of its operands are loop-invariant
|
|
|
|
for (unsigned i = 0, e = I.getNumOperands(); i != e; ++i) {
|
|
|
|
const MachineOperand &MO = I.getOperand(i);
|
|
|
|
|
2007-12-18 21:38:04 +00:00
|
|
|
if (!(MO.isRegister() && MO.getReg() && MO.isUse()))
|
Initial commit of the machine code LICM pass. It successfully hoists this:
_foo:
li r2, 0
LBB1_1: ; bb
li r5, 0
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
to:
_foo:
li r2, 0
li r5, 0
LBB1_1: ; bb
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
ZOMG!! :-)
Moar to come...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44687 91177308-0d34-0410-b5e6-96231b3b80d8
2007-12-07 21:42:31 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
unsigned Reg = MO.getReg();
|
|
|
|
|
|
|
|
// Don't hoist instructions that access physical registers.
|
|
|
|
if (!MRegisterInfo::isVirtualRegister(Reg))
|
|
|
|
return false;
|
|
|
|
|
2008-01-02 19:32:43 +00:00
|
|
|
assert(RegInfo->getVRegDef(Reg)&&"Machine instr not mapped for this vreg?");
|
Initial commit of the machine code LICM pass. It successfully hoists this:
_foo:
li r2, 0
LBB1_1: ; bb
li r5, 0
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
to:
_foo:
li r2, 0
li r5, 0
LBB1_1: ; bb
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
ZOMG!! :-)
Moar to come...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44687 91177308-0d34-0410-b5e6-96231b3b80d8
2007-12-07 21:42:31 +00:00
|
|
|
|
|
|
|
// If the loop contains the definition of an operand, then the instruction
|
|
|
|
// isn't loop invariant.
|
2008-01-02 19:32:43 +00:00
|
|
|
if (CurLoop->contains(RegInfo->getVRegDef(Reg)->getParent()))
|
Initial commit of the machine code LICM pass. It successfully hoists this:
_foo:
li r2, 0
LBB1_1: ; bb
li r5, 0
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
to:
_foo:
li r2, 0
li r5, 0
LBB1_1: ; bb
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
ZOMG!! :-)
Moar to come...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44687 91177308-0d34-0410-b5e6-96231b3b80d8
2007-12-07 21:42:31 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-12-20 01:08:10 +00:00
|
|
|
// Don't hoist something that has unmodelled side effects.
|
2007-12-18 21:38:04 +00:00
|
|
|
if (TII->hasUnmodelledSideEffects(&I)) return false;
|
|
|
|
|
Initial commit of the machine code LICM pass. It successfully hoists this:
_foo:
li r2, 0
LBB1_1: ; bb
li r5, 0
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
to:
_foo:
li r2, 0
li r5, 0
LBB1_1: ; bb
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
ZOMG!! :-)
Moar to come...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44687 91177308-0d34-0410-b5e6-96231b3b80d8
2007-12-07 21:42:31 +00:00
|
|
|
// If we got this far, the instruction is loop invariant!
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Hoist - When an instruction is found to only use loop invariant operands
|
|
|
|
/// that is safe to hoist, this instruction is called to do the dirty work.
|
|
|
|
///
|
2007-12-08 01:47:01 +00:00
|
|
|
void MachineLICM::Hoist(MachineInstr &MI) {
|
2007-12-08 23:58:46 +00:00
|
|
|
if (!IsLoopInvariantInst(MI)) return;
|
Initial commit of the machine code LICM pass. It successfully hoists this:
_foo:
li r2, 0
LBB1_1: ; bb
li r5, 0
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
to:
_foo:
li r2, 0
li r5, 0
LBB1_1: ; bb
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
ZOMG!! :-)
Moar to come...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44687 91177308-0d34-0410-b5e6-96231b3b80d8
2007-12-07 21:42:31 +00:00
|
|
|
|
|
|
|
std::vector<MachineBasicBlock*> Preds;
|
|
|
|
|
|
|
|
// Non-back-edge predecessors.
|
|
|
|
FindPredecessors(Preds);
|
|
|
|
|
2007-12-08 01:47:01 +00:00
|
|
|
// Either we don't have any predecessors(?!) or we have more than one, which
|
|
|
|
// is forbidden.
|
|
|
|
if (Preds.empty() || Preds.size() != 1) return;
|
Initial commit of the machine code LICM pass. It successfully hoists this:
_foo:
li r2, 0
LBB1_1: ; bb
li r5, 0
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
to:
_foo:
li r2, 0
li r5, 0
LBB1_1: ; bb
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
ZOMG!! :-)
Moar to come...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44687 91177308-0d34-0410-b5e6-96231b3b80d8
2007-12-07 21:42:31 +00:00
|
|
|
|
2007-12-08 01:47:01 +00:00
|
|
|
// Check that the predecessor is qualified to take the hoisted
|
|
|
|
// instruction. I.e., there is only one edge from the predecessor, and it's to
|
|
|
|
// the loop header.
|
|
|
|
MachineBasicBlock *MBB = Preds.front();
|
|
|
|
|
2007-12-08 23:58:46 +00:00
|
|
|
// FIXME: We are assuming at first that the basic block coming into this loop
|
|
|
|
// has only one successor. This isn't the case in general because we haven't
|
|
|
|
// broken critical edges or added preheaders.
|
2007-12-08 01:47:01 +00:00
|
|
|
if (MBB->succ_size() != 1) return;
|
|
|
|
assert(*MBB->succ_begin() == CurLoop->getHeader() &&
|
|
|
|
"The predecessor doesn't feed directly into the loop header!");
|
|
|
|
|
|
|
|
// Now move the instructions to the predecessor.
|
2008-01-02 19:32:43 +00:00
|
|
|
MoveInstToEndOfBlock(MBB, MI.getParent(), &MI);
|
Initial commit of the machine code LICM pass. It successfully hoists this:
_foo:
li r2, 0
LBB1_1: ; bb
li r5, 0
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
to:
_foo:
li r2, 0
li r5, 0
LBB1_1: ; bb
stw r5, 0(r3)
addi r2, r2, 1
addi r3, r3, 4
cmplw cr0, r2, r4
bne cr0, LBB1_1 ; bb
LBB1_2: ; return
blr
ZOMG!! :-)
Moar to come...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@44687 91177308-0d34-0410-b5e6-96231b3b80d8
2007-12-07 21:42:31 +00:00
|
|
|
Changed = true;
|
|
|
|
}
|