From 3638fa36f31459b520b44ec1081651b333f16d61 Mon Sep 17 00:00:00 2001 From: Vadzim Dambrouski Date: Wed, 25 Sep 2019 18:58:07 +0000 Subject: [PATCH] [MSP430] Allow msp430_intrcc functions to not have interrupt attribute. 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 --- llvm/lib/Target/MSP430/MSP430AsmPrinter.cpp | 8 +++++--- llvm/test/CodeGen/MSP430/interrupt.ll | 9 +++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/llvm/lib/Target/MSP430/MSP430AsmPrinter.cpp b/llvm/lib/Target/MSP430/MSP430AsmPrinter.cpp index 3a71a084d1afb..a3b91acdc6d02 100644 --- a/llvm/lib/Target/MSP430/MSP430AsmPrinter.cpp +++ b/llvm/lib/Target/MSP430/MSP430AsmPrinter.cpp @@ -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, @@ -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(); diff --git a/llvm/test/CodeGen/MSP430/interrupt.ll b/llvm/test/CodeGen/MSP430/interrupt.ll index 94fb3bc457a35..dac3e14321d70 100644 --- a/llvm/test/CodeGen/MSP430/interrupt.ll +++ b/llvm/test/CodeGen/MSP430/interrupt.ll @@ -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 }