Skip to content

Commit eb33db4

Browse files
committed
[AVR] Enable verifyInstructionPredicates for AVR
This patch fixes the failed test of verifyInstructionPredicates which is caused by verifyInstructionPredicates. verifyInstructionPredicates will add JMPk without checking the target predicate. Reviewed By: benshi001 Differential Revision: https://reviews.llvm.org/D155570
1 parent 16d5078 commit eb33db4

File tree

5 files changed

+17
-9
lines changed

5 files changed

+17
-9
lines changed

llvm/lib/Target/AVR/AVRAsmPrinter.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,8 @@ bool AVRAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
189189
}
190190

191191
void AVRAsmPrinter::emitInstruction(const MachineInstr *MI) {
192-
// FIXME: Enable feature predicate checks once all the test pass.
193-
// AVR_MC::verifyInstructionPredicates(MI->getOpcode(),
194-
// getSubtargetInfo().getFeatureBits());
192+
AVR_MC::verifyInstructionPredicates(MI->getOpcode(),
193+
getSubtargetInfo().getFeatureBits());
195194

196195
AVRMCInstLower MCInstLowering(OutContext, *this);
197196

llvm/lib/Target/AVR/AVRInstrInfo.cpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@
3535

3636
namespace llvm {
3737

38-
AVRInstrInfo::AVRInstrInfo()
39-
: AVRGenInstrInfo(AVR::ADJCALLSTACKDOWN, AVR::ADJCALLSTACKUP), RI() {}
38+
AVRInstrInfo::AVRInstrInfo(AVRSubtarget &STI)
39+
: AVRGenInstrInfo(AVR::ADJCALLSTACKDOWN, AVR::ADJCALLSTACKUP), RI(),
40+
STI(STI) {}
4041

4142
void AVRInstrInfo::copyPhysReg(MachineBasicBlock &MBB,
4243
MachineBasicBlock::iterator MI,
@@ -569,7 +570,10 @@ void AVRInstrInfo::insertIndirectBranch(MachineBasicBlock &MBB,
569570
// insertBranch or some hypothetical "insertDirectBranch".
570571
// See lib/CodeGen/RegisterRelaxation.cpp for details.
571572
// We end up here when a jump is too long for a RJMP instruction.
572-
BuildMI(&MBB, DL, get(AVR::JMPk)).addMBB(&NewDestBB);
573+
if (STI.hasJMPCALL())
574+
BuildMI(&MBB, DL, get(AVR::JMPk)).addMBB(&NewDestBB);
575+
else
576+
report_fatal_error("cannot create long jump without FeatureJMPCALL");
573577
}
574578

575579
} // end of namespace llvm

llvm/lib/Target/AVR/AVRInstrInfo.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
namespace llvm {
2525

26+
class AVRSubtarget;
27+
2628
namespace AVRCC {
2729

2830
/// AVR specific condition codes.
@@ -63,7 +65,7 @@ enum TOF {
6365
/// Utilities related to the AVR instruction set.
6466
class AVRInstrInfo : public AVRGenInstrInfo {
6567
public:
66-
explicit AVRInstrInfo();
68+
explicit AVRInstrInfo(AVRSubtarget &STI);
6769

6870
const AVRRegisterInfo &getRegisterInfo() const { return RI; }
6971
const MCInstrDesc &getBrCond(AVRCC::CondCodes CC) const;
@@ -116,6 +118,9 @@ class AVRInstrInfo : public AVRGenInstrInfo {
116118

117119
private:
118120
const AVRRegisterInfo RI;
121+
122+
protected:
123+
const AVRSubtarget &STI;
119124
};
120125

121126
} // end namespace llvm

llvm/lib/Target/AVR/AVRSubtarget.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace llvm {
2929

3030
AVRSubtarget::AVRSubtarget(const Triple &TT, const std::string &CPU,
3131
const std::string &FS, const AVRTargetMachine &TM)
32-
: AVRGenSubtargetInfo(TT, CPU, /*TuneCPU*/ CPU, FS),
32+
: AVRGenSubtargetInfo(TT, CPU, /*TuneCPU*/ CPU, FS), InstrInfo(*this),
3333
TLInfo(TM, initializeSubtargetDependencies(CPU, FS, TM)) {
3434
// Parse features string.
3535
ParseSubtargetFeatures(CPU, /*TuneCPU*/ CPU, FS);

llvm/test/CodeGen/AVR/branch-relaxation-long.ll

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
; RUN: llc < %s -march=avr | FileCheck %s
1+
; RUN: llc < %s -march=avr -mattr=avr3 | FileCheck %s
22

33
; CHECK-LABEL: relax_to_jmp:
44
; CHECK: cpi r{{[0-9]+}}, 0

0 commit comments

Comments
 (0)