mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-05-18 06:38:41 +00:00
In hexagon convertToHardwareLoop, don't deref end() iterator
In particular, check if MachineBasicBlock::iterator is end() before using it to call getDebugLoc(); See also this thread on llvm-commits: http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20121112/155914.html git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@169634 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
6cd738f339
commit
ade50dc6c7
@ -461,6 +461,9 @@ bool HexagonHardwareLoops::convertToHardwareLoop(MachineLoop *L) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
MachineBasicBlock::iterator LastI = LastMBB->getFirstTerminator();
|
MachineBasicBlock::iterator LastI = LastMBB->getFirstTerminator();
|
||||||
|
if (LastI == LastMBB->end()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Determine the loop start.
|
// Determine the loop start.
|
||||||
MachineBasicBlock *LoopStart = L->getTopBlock();
|
MachineBasicBlock *LoopStart = L->getTopBlock();
|
||||||
@ -478,6 +481,9 @@ bool HexagonHardwareLoops::convertToHardwareLoop(MachineLoop *L) {
|
|||||||
|
|
||||||
// Convert the loop to a hardware loop
|
// Convert the loop to a hardware loop
|
||||||
DEBUG(dbgs() << "Change to hardware loop at "; L->dump());
|
DEBUG(dbgs() << "Change to hardware loop at "; L->dump());
|
||||||
|
DebugLoc InsertPosDL;
|
||||||
|
if (InsertPos != Preheader->end())
|
||||||
|
InsertPosDL = InsertPos->getDebugLoc();
|
||||||
|
|
||||||
if (TripCount->isReg()) {
|
if (TripCount->isReg()) {
|
||||||
// Create a copy of the loop count register.
|
// Create a copy of the loop count register.
|
||||||
@ -485,23 +491,23 @@ bool HexagonHardwareLoops::convertToHardwareLoop(MachineLoop *L) {
|
|||||||
const TargetRegisterClass *RC =
|
const TargetRegisterClass *RC =
|
||||||
MF->getRegInfo().getRegClass(TripCount->getReg());
|
MF->getRegInfo().getRegClass(TripCount->getReg());
|
||||||
unsigned CountReg = MF->getRegInfo().createVirtualRegister(RC);
|
unsigned CountReg = MF->getRegInfo().createVirtualRegister(RC);
|
||||||
BuildMI(*Preheader, InsertPos, InsertPos->getDebugLoc(),
|
BuildMI(*Preheader, InsertPos, InsertPosDL,
|
||||||
TII->get(TargetOpcode::COPY), CountReg).addReg(TripCount->getReg());
|
TII->get(TargetOpcode::COPY), CountReg).addReg(TripCount->getReg());
|
||||||
if (TripCount->isNeg()) {
|
if (TripCount->isNeg()) {
|
||||||
unsigned CountReg1 = CountReg;
|
unsigned CountReg1 = CountReg;
|
||||||
CountReg = MF->getRegInfo().createVirtualRegister(RC);
|
CountReg = MF->getRegInfo().createVirtualRegister(RC);
|
||||||
BuildMI(*Preheader, InsertPos, InsertPos->getDebugLoc(),
|
BuildMI(*Preheader, InsertPos, InsertPosDL,
|
||||||
TII->get(Hexagon::NEG), CountReg).addReg(CountReg1);
|
TII->get(Hexagon::NEG), CountReg).addReg(CountReg1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the Loop instruction to the beginning of the loop.
|
// Add the Loop instruction to the beginning of the loop.
|
||||||
BuildMI(*Preheader, InsertPos, InsertPos->getDebugLoc(),
|
BuildMI(*Preheader, InsertPos, InsertPosDL,
|
||||||
TII->get(Hexagon::LOOP0_r)).addMBB(LoopStart).addReg(CountReg);
|
TII->get(Hexagon::LOOP0_r)).addMBB(LoopStart).addReg(CountReg);
|
||||||
} else {
|
} else {
|
||||||
assert(TripCount->isImm() && "Expecting immedate vaule for trip count");
|
assert(TripCount->isImm() && "Expecting immedate vaule for trip count");
|
||||||
// Add the Loop immediate instruction to the beginning of the loop.
|
// Add the Loop immediate instruction to the beginning of the loop.
|
||||||
int64_t CountImm = TripCount->getImm();
|
int64_t CountImm = TripCount->getImm();
|
||||||
BuildMI(*Preheader, InsertPos, InsertPos->getDebugLoc(),
|
BuildMI(*Preheader, InsertPos, InsertPosDL,
|
||||||
TII->get(Hexagon::LOOP0_i)).addMBB(LoopStart).addImm(CountImm);
|
TII->get(Hexagon::LOOP0_i)).addMBB(LoopStart).addImm(CountImm);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -514,8 +520,9 @@ bool HexagonHardwareLoops::convertToHardwareLoop(MachineLoop *L) {
|
|||||||
BlockAddress::get(const_cast<BasicBlock *>(LoopStart->getBasicBlock()));
|
BlockAddress::get(const_cast<BasicBlock *>(LoopStart->getBasicBlock()));
|
||||||
|
|
||||||
// Replace the loop branch with an endloop instruction.
|
// Replace the loop branch with an endloop instruction.
|
||||||
DebugLoc dl = LastI->getDebugLoc();
|
DebugLoc LastIDL = LastI->getDebugLoc();
|
||||||
BuildMI(*LastMBB, LastI, dl, TII->get(Hexagon::ENDLOOP0)).addMBB(LoopStart);
|
BuildMI(*LastMBB, LastI, LastIDL,
|
||||||
|
TII->get(Hexagon::ENDLOOP0)).addMBB(LoopStart);
|
||||||
|
|
||||||
// The loop ends with either:
|
// The loop ends with either:
|
||||||
// - a conditional branch followed by an unconditional branch, or
|
// - a conditional branch followed by an unconditional branch, or
|
||||||
@ -530,7 +537,7 @@ bool HexagonHardwareLoops::convertToHardwareLoop(MachineLoop *L) {
|
|||||||
TII->RemoveBranch(*LastMBB);
|
TII->RemoveBranch(*LastMBB);
|
||||||
}
|
}
|
||||||
SmallVector<MachineOperand, 0> Cond;
|
SmallVector<MachineOperand, 0> Cond;
|
||||||
TII->InsertBranch(*LastMBB, BranchTarget, 0, Cond, dl);
|
TII->InsertBranch(*LastMBB, BranchTarget, 0, Cond, LastIDL);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Conditional branch to loop start; just delete it.
|
// Conditional branch to loop start; just delete it.
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
; RUN: true || llc -march=hexagon -mcpu=hexagonv4 < %s | FileCheck %s
|
; RUN: llc -march=hexagon -mcpu=hexagonv4 < %s | FileCheck %s
|
||||||
|
|
||||||
; Check that post-increment load instructions are being generated.
|
; Check that post-increment load instructions are being generated.
|
||||||
; CHECK: r{{[0-9]+}}{{ *}}={{ *}}memw(r{{[0-9]+}}{{ *}}++{{ *}}#4{{ *}})
|
; CHECK: r{{[0-9]+}}{{ *}}={{ *}}memw(r{{[0-9]+}}{{ *}}++{{ *}}#4{{ *}})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user