1 //===- M68k.cpp -----------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "ABIInfoImpl.h"
10 #include "TargetInfo.h"
12 using namespace clang
;
13 using namespace clang::CodeGen
;
15 //===----------------------------------------------------------------------===//
16 // M68k ABI Implementation
17 //===----------------------------------------------------------------------===//
21 class M68kTargetCodeGenInfo
: public TargetCodeGenInfo
{
23 M68kTargetCodeGenInfo(CodeGenTypes
&CGT
)
24 : TargetCodeGenInfo(std::make_unique
<DefaultABIInfo
>(CGT
)) {}
25 void setTargetAttributes(const Decl
*D
, llvm::GlobalValue
*GV
,
26 CodeGen::CodeGenModule
&M
) const override
;
31 void M68kTargetCodeGenInfo::setTargetAttributes(
32 const Decl
*D
, llvm::GlobalValue
*GV
, CodeGen::CodeGenModule
&M
) const {
33 if (const auto *FD
= dyn_cast_or_null
<FunctionDecl
>(D
)) {
34 if (const auto *attr
= FD
->getAttr
<M68kInterruptAttr
>()) {
35 // Handle 'interrupt' attribute:
36 llvm::Function
*F
= cast
<llvm::Function
>(GV
);
38 // Step 1: Set ISR calling convention.
39 F
->setCallingConv(llvm::CallingConv::M68k_INTR
);
41 // Step 2: Add attributes goodness.
42 F
->addFnAttr(llvm::Attribute::NoInline
);
44 // Step 3: Emit ISR vector alias.
45 unsigned Num
= attr
->getNumber() / 2;
46 llvm::GlobalAlias::create(llvm::Function::ExternalLinkage
,
47 "__isr_" + Twine(Num
), F
);
52 std::unique_ptr
<TargetCodeGenInfo
>
53 CodeGen::createM68kTargetCodeGenInfo(CodeGenModule
&CGM
) {
54 return std::make_unique
<M68kTargetCodeGenInfo
>(CGM
.getTypes());