/src/llvm-project/clang/lib/CodeGen/Targets/M68k.cpp
Line | Count | Source (jump to first uncovered line) |
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 | 0 | : TargetCodeGenInfo(std::make_unique<DefaultABIInfo>(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 | 0 | const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &M) const { |
33 | 0 | if (const auto *FD = dyn_cast_or_null<FunctionDecl>(D)) { |
34 | 0 | if (const auto *attr = FD->getAttr<M68kInterruptAttr>()) { |
35 | | // Handle 'interrupt' attribute: |
36 | 0 | llvm::Function *F = cast<llvm::Function>(GV); |
37 | | |
38 | | // Step 1: Set ISR calling convention. |
39 | 0 | F->setCallingConv(llvm::CallingConv::M68k_INTR); |
40 | | |
41 | | // Step 2: Add attributes goodness. |
42 | 0 | F->addFnAttr(llvm::Attribute::NoInline); |
43 | | |
44 | | // Step 3: Emit ISR vector alias. |
45 | 0 | unsigned Num = attr->getNumber() / 2; |
46 | 0 | llvm::GlobalAlias::create(llvm::Function::ExternalLinkage, |
47 | 0 | "__isr_" + Twine(Num), F); |
48 | 0 | } |
49 | 0 | } |
50 | 0 | } |
51 | | |
52 | | std::unique_ptr<TargetCodeGenInfo> |
53 | 0 | CodeGen::createM68kTargetCodeGenInfo(CodeGenModule &CGM) { |
54 | 0 | return std::make_unique<M68kTargetCodeGenInfo>(CGM.getTypes()); |
55 | 0 | } |