clang 20.0.0git
M68k.cpp
Go to the documentation of this file.
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
12using namespace clang;
13using namespace clang::CodeGen;
14
15//===----------------------------------------------------------------------===//
16// M68k ABI Implementation
17//===----------------------------------------------------------------------===//
18
19namespace {
20
21class M68kTargetCodeGenInfo : public TargetCodeGenInfo {
22public:
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;
27};
28
29} // namespace
30
31void 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);
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(llvm::Function::ExternalLinkage,
47 "__isr_" + Twine(Num), F);
48 }
49 }
50}
51
52std::unique_ptr<TargetCodeGenInfo>
54 return std::make_unique<M68kTargetCodeGenInfo>(CGM.getTypes());
55}
const Decl * D
This class organizes the cross-function state that is used while generating LLVM code.
This class organizes the cross-module state that is used while lowering AST types to LLVM types.
Definition: CodeGenTypes.h:54
DefaultABIInfo - The default implementation for ABI specific details.
Definition: ABIInfoImpl.h:21
TargetCodeGenInfo - This class organizes various target-specific codegeneration issues,...
Definition: TargetInfo.h:47
virtual void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &M) const
setTargetAttributes - Provides a convenient hook to handle extra target-specific attributes for the g...
Definition: TargetInfo.h:76
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
std::unique_ptr< TargetCodeGenInfo > createM68kTargetCodeGenInfo(CodeGenModule &CGM)
Definition: M68k.cpp:53
const internal::VariadicAllOfMatcher< Attr > attr
Matches attributes.
The JSON file list parser is used to communicate input to InstallAPI.