Skip to content

Commit

Permalink
[MSP430] Allow msp430_intrcc functions to not have interrupt attribut…
Browse files Browse the repository at this point in the history
…e. (llvm#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>
  • Loading branch information
2 people authored and alexcrichton committed Jan 26, 2020
1 parent a56b846 commit d7cdb43
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
8 changes: 5 additions & 3 deletions llvm/lib/Target/MSP430/MSP430AsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,9 @@ void MSP430AsmPrinter::EmitInstruction(const MachineInstr *MI) {
void MSP430AsmPrinter::EmitInterruptVectorSection(MachineFunction &ISR) {
MCSection *Cur = OutStreamer->getCurrentSectionOnly();
const auto *F = &ISR.getFunction();
assert(F->hasFnAttribute("interrupt") &&
"Functions with MSP430_INTR CC should have 'interrupt' attribute");
if (F->getCallingConv() != CallingConv::MSP430_INTR) {
report_fatal_error("Functions with 'interrupt' attribute must have msp430_intrcc CC");
}
StringRef IVIdx = F->getFnAttribute("interrupt").getValueAsString();
MCSection *IV = OutStreamer->getContext().getELFSection(
"__interrupt_vector_" + IVIdx,
Expand All @@ -174,8 +175,9 @@ void MSP430AsmPrinter::EmitInterruptVectorSection(MachineFunction &ISR) {

bool MSP430AsmPrinter::runOnMachineFunction(MachineFunction &MF) {
// Emit separate section for an interrupt vector if ISR
if (MF.getFunction().getCallingConv() == CallingConv::MSP430_INTR)
if (MF.getFunction().hasFnAttribute("interrupt")) {
EmitInterruptVectorSection(MF);
}

SetupMachineFunction(MF);
EmitFunctionBody();
Expand Down
9 changes: 9 additions & 0 deletions llvm/test/CodeGen/MSP430/interrupt.ll
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,13 @@ entry:
ret void
}

; Functions without 'interrupt' attribute don't get a vector section.
; CHECK-NOT: __interrupt_vector
; CHECK-LABEL: NMI:
; CHECK: reti
define msp430_intrcc void @NMI() #1 {
ret void
}

attributes #0 = { noinline nounwind optnone "interrupt"="2" }
attributes #1 = { noinline nounwind optnone }

0 comments on commit d7cdb43

Please sign in to comment.