clang 22.0.0git
MSP430.cpp
Go to the documentation of this file.
1//===- MSP430.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#include "llvm/ADT/StringExtras.h"
12
13using namespace clang;
14using namespace clang::CodeGen;
15
16//===----------------------------------------------------------------------===//
17// MSP430 ABI Implementation
18//===----------------------------------------------------------------------===//
19
20namespace {
21
22class MSP430ABIInfo : public DefaultABIInfo {
23 static ABIArgInfo complexArgInfo() {
24 ABIArgInfo Info = ABIArgInfo::getDirect();
25 Info.setCanBeFlattened(false);
26 return Info;
27 }
28
29public:
30 MSP430ABIInfo(CodeGenTypes &CGT) : DefaultABIInfo(CGT) {}
31
32 ABIArgInfo classifyReturnType(QualType RetTy) const {
33 if (RetTy->isAnyComplexType())
34 return complexArgInfo();
35
37 }
38
39 ABIArgInfo classifyArgumentType(QualType RetTy) const {
40 if (RetTy->isAnyComplexType())
41 return complexArgInfo();
42
44 }
45
46 // Just copy the original implementations because
47 // DefaultABIInfo::classify{Return,Argument}Type() are not virtual
48 void computeInfo(CGFunctionInfo &FI) const override {
49 if (!getCXXABI().classifyReturnType(FI))
51 for (auto &I : FI.arguments())
52 I.info = classifyArgumentType(I.type);
53 }
54
55 RValue EmitVAArg(CodeGenFunction &CGF, Address VAListAddr, QualType Ty,
56 AggValueSlot Slot) const override {
57 return CGF.EmitLoadOfAnyValue(
59 EmitVAArgInstr(CGF, VAListAddr, Ty, classifyArgumentType(Ty)), Ty),
60 Slot);
61 }
62};
63
64class MSP430TargetCodeGenInfo : public TargetCodeGenInfo {
65public:
66 MSP430TargetCodeGenInfo(CodeGenTypes &CGT)
67 : TargetCodeGenInfo(std::make_unique<MSP430ABIInfo>(CGT)) {}
68 void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
69 CodeGen::CodeGenModule &M) const override;
70};
71
72}
73
74void MSP430TargetCodeGenInfo::setTargetAttributes(
75 const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &M) const {
76 if (GV->isDeclaration())
77 return;
78 if (const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D)) {
79 const auto *InterruptAttr = FD->getAttr<MSP430InterruptAttr>();
80 if (!InterruptAttr)
81 return;
82
83 // Handle 'interrupt' attribute:
84 llvm::Function *F = cast<llvm::Function>(GV);
85
86 // Step 1: Set ISR calling convention.
87 F->setCallingConv(llvm::CallingConv::MSP430_INTR);
88
89 // Step 2: Add attributes goodness.
90 F->addFnAttr(llvm::Attribute::NoInline);
91 F->addFnAttr("interrupt", llvm::utostr(InterruptAttr->getNumber()));
92 }
93}
94
95std::unique_ptr<TargetCodeGenInfo>
97 return std::make_unique<MSP430TargetCodeGenInfo>(CGM.getTypes());
98}
static ABIArgInfo getDirect(llvm::Type *T=nullptr, unsigned Offset=0, llvm::Type *Padding=nullptr, bool CanBeFlattened=true, unsigned Align=0)
void setCanBeFlattened(bool Flatten)
CanQualType getReturnType() const
MutableArrayRef< ArgInfo > arguments()
RValue EmitLoadOfAnyValue(LValue V, AggValueSlot Slot=AggValueSlot::ignored(), SourceLocation Loc={})
Like EmitLoadOfLValue but also handles complex and aggregate types.
Definition CGExpr.cpp:2318
LValue MakeAddrLValue(Address Addr, QualType T, AlignmentSource Source=AlignmentSource::Type)
This class organizes the cross-function state that is used while generating LLVM code.
DefaultABIInfo - The default implementation for ABI specific details.
Definition ABIInfoImpl.h:21
ABIArgInfo classifyArgumentType(QualType RetTy) const
ABIArgInfo classifyReturnType(QualType RetTy) const
TargetCodeGenInfo - This class organizes various target-specific codegeneration issues,...
Definition TargetInfo.h:47
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
bool isAnyComplexType() const
Definition TypeBase.h:8657
ABIArgInfo classifyArgumentType(CodeGenModule &CGM, CanQualType type)
Classify the rules for how to pass a particular type.
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
Definition CGValue.h:145
std::unique_ptr< TargetCodeGenInfo > createMSP430TargetCodeGenInfo(CodeGenModule &CGM)
Definition MSP430.cpp:96
bool classifyReturnType(const CGCXXABI &CXXABI, CGFunctionInfo &FI, const ABIInfo &Info)
Address EmitVAArgInstr(CodeGenFunction &CGF, Address VAListAddr, QualType Ty, const ABIArgInfo &AI)
The JSON file list parser is used to communicate input to InstallAPI.
U cast(CodeGen::Address addr)
Definition Address.h:327