Skip to content

Commit d7cdb43

Browse files
cr1901pftbest
authored andcommitted
[MSP430] Allow msp430_intrcc functions to not have interrupt attribute. (#37)
Summary: Useful in case you want to have control over interrupt vector generation. For example in Rust language we have an arrangement where all unhandled ISR vectors gets mapped to a single default handler function. Which is hard to implement when LLVM tries to generate vectors on its own. Reviewers: asl, krisb Subscribers: hiraditya, JDevlieghere, awygle, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D67313 llvm-svn: 372910 Co-authored-by: Vadzim Dambrouski <pftbest@gmail.com>
1 parent a56b846 commit d7cdb43

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

llvm/lib/Target/MSP430/MSP430AsmPrinter.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,9 @@ void MSP430AsmPrinter::EmitInstruction(const MachineInstr *MI) {
159159
void MSP430AsmPrinter::EmitInterruptVectorSection(MachineFunction &ISR) {
160160
MCSection *Cur = OutStreamer->getCurrentSectionOnly();
161161
const auto *F = &ISR.getFunction();
162-
assert(F->hasFnAttribute("interrupt") &&
163-
"Functions with MSP430_INTR CC should have 'interrupt' attribute");
162+
if (F->getCallingConv() != CallingConv::MSP430_INTR) {
163+
report_fatal_error("Functions with 'interrupt' attribute must have msp430_intrcc CC");
164+
}
164165
StringRef IVIdx = F->getFnAttribute("interrupt").getValueAsString();
165166
MCSection *IV = OutStreamer->getContext().getELFSection(
166167
"__interrupt_vector_" + IVIdx,
@@ -174,8 +175,9 @@ void MSP430AsmPrinter::EmitInterruptVectorSection(MachineFunction &ISR) {
174175

175176
bool MSP430AsmPrinter::runOnMachineFunction(MachineFunction &MF) {
176177
// Emit separate section for an interrupt vector if ISR
177-
if (MF.getFunction().getCallingConv() == CallingConv::MSP430_INTR)
178+
if (MF.getFunction().hasFnAttribute("interrupt")) {
178179
EmitInterruptVectorSection(MF);
180+
}
179181

180182
SetupMachineFunction(MF);
181183
EmitFunctionBody();

llvm/test/CodeGen/MSP430/interrupt.ll

+9
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,13 @@ entry:
5050
ret void
5151
}
5252

53+
; Functions without 'interrupt' attribute don't get a vector section.
54+
; CHECK-NOT: __interrupt_vector
55+
; CHECK-LABEL: NMI:
56+
; CHECK: reti
57+
define msp430_intrcc void @NMI() #1 {
58+
ret void
59+
}
60+
5361
attributes #0 = { noinline nounwind optnone "interrupt"="2" }
62+
attributes #1 = { noinline nounwind optnone }

0 commit comments

Comments
 (0)