1 | //===- M68k.cpp -----------------------------------------------------------===// |
---|---|
2 | // |
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 |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #include "ABIInfoImpl.h" |
10 | #include "TargetInfo.h" |
11 | |
12 | using namespace clang; |
13 | using namespace clang::CodeGen; |
14 | |
15 | //===----------------------------------------------------------------------===// |
16 | // M68k ABI Implementation |
17 | //===----------------------------------------------------------------------===// |
18 | |
19 | namespace { |
20 | |
21 | class M68kTargetCodeGenInfo : public TargetCodeGenInfo { |
22 | public: |
23 | M68kTargetCodeGenInfo(CodeGenTypes &CGT) |
24 | : TargetCodeGenInfo(std::make_unique<DefaultABIInfo>(args&: CGT)) {} |
25 | void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV, |
26 | CodeGen::CodeGenModule &M) const override; |
27 | }; |
28 | |
29 | } // namespace |
30 | |
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>(Val: D)) { |
34 | if (const auto *attr = FD->getAttr<M68kInterruptAttr>()) { |
35 | // Handle 'interrupt' attribute: |
36 | llvm::Function *F = cast<llvm::Function>(Val: GV); |
37 | |
38 | // Step 1: Set ISR calling convention. |
39 | F->setCallingConv(llvm::CallingConv::M68k_INTR); |
40 | |
41 | // Step 2: Add attributes goodness. |
42 | F->addFnAttr(llvm::Attribute::NoInline); |
43 | |
44 | // Step 3: Emit ISR vector alias. |
45 | unsigned Num = attr->getNumber() / 2; |
46 | llvm::GlobalAlias::create(Linkage: llvm::Function::ExternalLinkage, |
47 | Name: "__isr_"+ Twine(Num), Aliasee: F); |
48 | } |
49 | } |
50 | } |
51 | |
52 | std::unique_ptr<TargetCodeGenInfo> |
53 | CodeGen::createM68kTargetCodeGenInfo(CodeGenModule &CGM) { |
54 | return std::make_unique<M68kTargetCodeGenInfo>(args&: CGM.getTypes()); |
55 | } |
56 |