mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-13 20:32:21 +00:00
Re-apply 85799. It turns out my code isn't buggy.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@85947 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
60faaf64b4
commit
777c6b7caa
@ -56,12 +56,12 @@ namespace {
|
|||||||
|
|
||||||
// State that is updated as we process loops
|
// State that is updated as we process loops
|
||||||
bool Changed; // True if a loop is changed.
|
bool Changed; // True if a loop is changed.
|
||||||
|
bool FirstInLoop; // True if it's the first LICM in the loop.
|
||||||
MachineLoop *CurLoop; // The current loop we are working on.
|
MachineLoop *CurLoop; // The current loop we are working on.
|
||||||
MachineBasicBlock *CurPreheader; // The preheader for CurLoop.
|
MachineBasicBlock *CurPreheader; // The preheader for CurLoop.
|
||||||
|
|
||||||
// For each BB and opcode pair, keep a list of hoisted instructions.
|
// For each opcode, keep a list of potentail CSE instructions.
|
||||||
DenseMap<std::pair<unsigned, unsigned>,
|
DenseMap<unsigned, std::vector<const MachineInstr*> > CSEMap;
|
||||||
std::vector<const MachineInstr*> > CSEMap;
|
|
||||||
public:
|
public:
|
||||||
static char ID; // Pass identification, replacement for typeid
|
static char ID; // Pass identification, replacement for typeid
|
||||||
MachineLICM() : MachineFunctionPass(&ID) {}
|
MachineLICM() : MachineFunctionPass(&ID) {}
|
||||||
@ -115,6 +115,11 @@ namespace {
|
|||||||
/// that is safe to hoist, this instruction is called to do the dirty work.
|
/// that is safe to hoist, this instruction is called to do the dirty work.
|
||||||
///
|
///
|
||||||
void Hoist(MachineInstr *MI);
|
void Hoist(MachineInstr *MI);
|
||||||
|
|
||||||
|
/// InitCSEMap - Initialize the CSE map with instructions that are in the
|
||||||
|
/// current loop preheader that may become duplicates of instructions that
|
||||||
|
/// are hoisted out of the loop.
|
||||||
|
void InitCSEMap(MachineBasicBlock *BB);
|
||||||
};
|
};
|
||||||
} // end anonymous namespace
|
} // end anonymous namespace
|
||||||
|
|
||||||
@ -140,7 +145,7 @@ static bool LoopIsOuterMostWithPreheader(MachineLoop *CurLoop) {
|
|||||||
bool MachineLICM::runOnMachineFunction(MachineFunction &MF) {
|
bool MachineLICM::runOnMachineFunction(MachineFunction &MF) {
|
||||||
DEBUG(errs() << "******** Machine LICM ********\n");
|
DEBUG(errs() << "******** Machine LICM ********\n");
|
||||||
|
|
||||||
Changed = false;
|
Changed = FirstInLoop = false;
|
||||||
TM = &MF.getTarget();
|
TM = &MF.getTarget();
|
||||||
TII = TM->getInstrInfo();
|
TII = TM->getInstrInfo();
|
||||||
TRI = TM->getRegisterInfo();
|
TRI = TM->getRegisterInfo();
|
||||||
@ -152,8 +157,7 @@ bool MachineLICM::runOnMachineFunction(MachineFunction &MF) {
|
|||||||
DT = &getAnalysis<MachineDominatorTree>();
|
DT = &getAnalysis<MachineDominatorTree>();
|
||||||
AA = &getAnalysis<AliasAnalysis>();
|
AA = &getAnalysis<AliasAnalysis>();
|
||||||
|
|
||||||
for (MachineLoopInfo::iterator
|
for (MachineLoopInfo::iterator I = LI->begin(), E = LI->end(); I != E; ++I) {
|
||||||
I = LI->begin(), E = LI->end(); I != E; ++I) {
|
|
||||||
CurLoop = *I;
|
CurLoop = *I;
|
||||||
|
|
||||||
// Only visit outer-most preheader-sporting loops.
|
// Only visit outer-most preheader-sporting loops.
|
||||||
@ -170,7 +174,11 @@ bool MachineLICM::runOnMachineFunction(MachineFunction &MF) {
|
|||||||
if (!CurPreheader)
|
if (!CurPreheader)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
// CSEMap is initialized for loop header when the first instruction is
|
||||||
|
// being hoisted.
|
||||||
|
FirstInLoop = true;
|
||||||
HoistRegion(DT->getNode(CurLoop->getHeader()));
|
HoistRegion(DT->getNode(CurLoop->getHeader()));
|
||||||
|
CSEMap.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
return Changed;
|
return Changed;
|
||||||
@ -191,10 +199,7 @@ void MachineLICM::HoistRegion(MachineDomTreeNode *N) {
|
|||||||
for (MachineBasicBlock::iterator
|
for (MachineBasicBlock::iterator
|
||||||
MII = BB->begin(), E = BB->end(); MII != E; ) {
|
MII = BB->begin(), E = BB->end(); MII != E; ) {
|
||||||
MachineBasicBlock::iterator NextMII = MII; ++NextMII;
|
MachineBasicBlock::iterator NextMII = MII; ++NextMII;
|
||||||
MachineInstr &MI = *MII;
|
Hoist(&*MII);
|
||||||
|
|
||||||
Hoist(&MI);
|
|
||||||
|
|
||||||
MII = NextMII;
|
MII = NextMII;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -430,6 +435,27 @@ MachineInstr *MachineLICM::ExtractHoistableLoad(MachineInstr *MI) {
|
|||||||
return NewMIs[0];
|
return NewMIs[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MachineLICM::InitCSEMap(MachineBasicBlock *BB) {
|
||||||
|
for (MachineBasicBlock::iterator I = BB->begin(),E = BB->end(); I != E; ++I) {
|
||||||
|
const MachineInstr *MI = &*I;
|
||||||
|
// FIXME: For now, only hoist re-materilizable instructions. LICM will
|
||||||
|
// increase register pressure. We want to make sure it doesn't increase
|
||||||
|
// spilling.
|
||||||
|
if (TII->isTriviallyReMaterializable(MI, AA)) {
|
||||||
|
unsigned Opcode = MI->getOpcode();
|
||||||
|
DenseMap<unsigned, std::vector<const MachineInstr*> >::iterator
|
||||||
|
CI = CSEMap.find(Opcode);
|
||||||
|
if (CI != CSEMap.end())
|
||||||
|
CI->second.push_back(MI);
|
||||||
|
else {
|
||||||
|
std::vector<const MachineInstr*> CSEMIs;
|
||||||
|
CSEMIs.push_back(MI);
|
||||||
|
CSEMap.insert(std::make_pair(Opcode, CSEMIs));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Hoist - When an instruction is found to use only loop invariant operands
|
/// Hoist - When an instruction is found to use only loop invariant operands
|
||||||
/// that are safe to hoist, this instruction is called to do the dirty work.
|
/// that are safe to hoist, this instruction is called to do the dirty work.
|
||||||
///
|
///
|
||||||
@ -454,11 +480,14 @@ void MachineLICM::Hoist(MachineInstr *MI) {
|
|||||||
errs() << "\n";
|
errs() << "\n";
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// If this is the first instruction being hoisted to the preheader,
|
||||||
|
// initialize the CSE map with potential common expressions.
|
||||||
|
InitCSEMap(CurPreheader);
|
||||||
|
|
||||||
// Look for opportunity to CSE the hoisted instruction.
|
// Look for opportunity to CSE the hoisted instruction.
|
||||||
std::pair<unsigned, unsigned> BBOpcPair =
|
unsigned Opcode = MI->getOpcode();
|
||||||
std::make_pair(CurPreheader->getNumber(), MI->getOpcode());
|
DenseMap<unsigned, std::vector<const MachineInstr*> >::iterator
|
||||||
DenseMap<std::pair<unsigned, unsigned>,
|
CI = CSEMap.find(Opcode);
|
||||||
std::vector<const MachineInstr*> >::iterator CI = CSEMap.find(BBOpcPair);
|
|
||||||
bool DoneCSE = false;
|
bool DoneCSE = false;
|
||||||
if (CI != CSEMap.end()) {
|
if (CI != CSEMap.end()) {
|
||||||
const MachineInstr *Dup = LookForDuplicate(MI, CI->second, RegInfo);
|
const MachineInstr *Dup = LookForDuplicate(MI, CI->second, RegInfo);
|
||||||
@ -477,15 +506,15 @@ void MachineLICM::Hoist(MachineInstr *MI) {
|
|||||||
|
|
||||||
// Otherwise, splice the instruction to the preheader.
|
// Otherwise, splice the instruction to the preheader.
|
||||||
if (!DoneCSE) {
|
if (!DoneCSE) {
|
||||||
CurPreheader->splice(CurPreheader->getFirstTerminator(),
|
CurPreheader->splice(CurPreheader->getFirstTerminator(),MI->getParent(),MI);
|
||||||
MI->getParent(), MI);
|
|
||||||
// Add to the CSE map.
|
// Add to the CSE map.
|
||||||
if (CI != CSEMap.end())
|
if (CI != CSEMap.end())
|
||||||
CI->second.push_back(MI);
|
CI->second.push_back(MI);
|
||||||
else {
|
else {
|
||||||
std::vector<const MachineInstr*> CSEMIs;
|
std::vector<const MachineInstr*> CSEMIs;
|
||||||
CSEMIs.push_back(MI);
|
CSEMIs.push_back(MI);
|
||||||
CSEMap.insert(std::make_pair(BBOpcPair, CSEMIs));
|
CSEMap.insert(std::make_pair(Opcode, CSEMIs));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
; RUN: llc < %s -mtriple=arm-apple-darwin
|
; RUN: llc < %s -mtriple=arm-apple-darwin
|
||||||
; RUN: llc < %s -mtriple=arm-apple-darwin -stats -info-output-file - | grep "Number of re-materialization" | grep 4
|
; RUN: llc < %s -mtriple=arm-apple-darwin -stats -info-output-file - | grep "Number of re-materialization" | grep 5
|
||||||
|
|
||||||
%struct.CONTENTBOX = type { i32, i32, i32, i32, i32 }
|
%struct.CONTENTBOX = type { i32, i32, i32, i32, i32 }
|
||||||
%struct.LOCBOX = type { i32, i32, i32, i32 }
|
%struct.LOCBOX = type { i32, i32, i32, i32 }
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
; RUN: llc < %s -march=x86 -mattr=+sse2 -stats |& \
|
; RUN: llc < %s -march=x86 -mattr=+sse2 | FileCheck %s
|
||||||
; RUN: grep {1 .*folded into instructions}
|
; Increment in loop bb.i28.i adjusted to 2, to prevent loop reversal from
|
||||||
; Increment in loop bb.128.i adjusted to 2, to prevent loop reversal from
|
|
||||||
; kicking in.
|
; kicking in.
|
||||||
|
|
||||||
declare fastcc void @rdft(i32, i32, double*, i32*, double*)
|
declare fastcc void @rdft(i32, i32, double*, i32*, double*)
|
||||||
@ -34,6 +33,9 @@ cond_next36.i: ; preds = %cond_next.i
|
|||||||
br label %bb.i28.i
|
br label %bb.i28.i
|
||||||
|
|
||||||
bb.i28.i: ; preds = %bb.i28.i, %cond_next36.i
|
bb.i28.i: ; preds = %bb.i28.i, %cond_next36.i
|
||||||
|
; CHECK: %bb.i28.i
|
||||||
|
; CHECK: addl $2
|
||||||
|
; CHECK: addl $2
|
||||||
%j.0.reg2mem.0.i16.i = phi i32 [ 0, %cond_next36.i ], [ %indvar.next39.i, %bb.i28.i ] ; <i32> [#uses=2]
|
%j.0.reg2mem.0.i16.i = phi i32 [ 0, %cond_next36.i ], [ %indvar.next39.i, %bb.i28.i ] ; <i32> [#uses=2]
|
||||||
%din_addr.1.reg2mem.0.i17.i = phi double [ 0.000000e+00, %cond_next36.i ], [ %tmp16.i25.i, %bb.i28.i ] ; <double> [#uses=1]
|
%din_addr.1.reg2mem.0.i17.i = phi double [ 0.000000e+00, %cond_next36.i ], [ %tmp16.i25.i, %bb.i28.i ] ; <double> [#uses=1]
|
||||||
%tmp1.i18.i = fptosi double %din_addr.1.reg2mem.0.i17.i to i32 ; <i32> [#uses=2]
|
%tmp1.i18.i = fptosi double %din_addr.1.reg2mem.0.i17.i to i32 ; <i32> [#uses=2]
|
||||||
|
Loading…
Reference in New Issue
Block a user