Skip to content

Commit 1f11ce6

Browse files
committed
Merging r314891:
------------------------------------------------------------------------ r314891 | dylanmckay | 2017-10-04 22:51:28 +1300 (Wed, 04 Oct 2017) | 8 lines [AVR] Insert JMP for long branches Previously, on long branches (relative jumps of >4 kB), an assertion failure was hit, as AVRInstrInfo::insertIndirectBranch was not implemented. Despite its name, it is called by the branch relaxator for *all* unconditional jumps. Patch by Thomas Backman. ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_50@315833 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 1fc9dfd commit 1f11ce6

File tree

3 files changed

+4159
-2
lines changed

3 files changed

+4159
-2
lines changed

lib/Target/AVR/AVRInstrInfo.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,8 +537,7 @@ bool AVRInstrInfo::isBranchOffsetInRange(unsigned BranchOp,
537537
llvm_unreachable("unexpected opcode!");
538538
case AVR::JMPk:
539539
case AVR::CALLk:
540-
assert(BrOffset >= 0 && "offset must be absolute address");
541-
return isUIntN(16, BrOffset);
540+
return true;
542541
case AVR::RCALLk:
543542
case AVR::RJMPk:
544543
return isIntN(13, BrOffset);
@@ -556,5 +555,20 @@ bool AVRInstrInfo::isBranchOffsetInRange(unsigned BranchOp,
556555
}
557556
}
558557

558+
unsigned AVRInstrInfo::insertIndirectBranch(MachineBasicBlock &MBB,
559+
MachineBasicBlock &NewDestBB,
560+
const DebugLoc &DL,
561+
int64_t BrOffset,
562+
RegScavenger *RS) const {
563+
// This method inserts a *direct* branch (JMP), despite its name.
564+
// LLVM calls this method to fixup unconditional branches; it never calls
565+
// insertBranch or some hypothetical "insertDirectBranch".
566+
// See lib/CodeGen/RegisterRelaxation.cpp for details.
567+
// We end up here when a jump is too long for a RJMP instruction.
568+
auto &MI = *BuildMI(&MBB, DL, get(AVR::JMPk)).addMBB(&NewDestBB);
569+
570+
return getInstSizeInBytes(MI);
571+
}
572+
559573
} // end of namespace llvm
560574

lib/Target/AVR/AVRInstrInfo.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ class AVRInstrInfo : public AVRGenInstrInfo {
107107

108108
bool isBranchOffsetInRange(unsigned BranchOpc,
109109
int64_t BrOffset) const override;
110+
111+
unsigned insertIndirectBranch(MachineBasicBlock &MBB,
112+
MachineBasicBlock &NewDestBB,
113+
const DebugLoc &DL,
114+
int64_t BrOffset,
115+
RegScavenger *RS) const override;
110116
private:
111117
const AVRRegisterInfo RI;
112118
};

0 commit comments

Comments
 (0)