clang 20.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
12using namespace clang;
13using namespace clang::CodeGen;
14
15//===----------------------------------------------------------------------===//
16// MSP430 ABI Implementation
17//===----------------------------------------------------------------------===//
18
19namespace {
20
21class MSP430ABIInfo : public DefaultABIInfo {
22 static ABIArgInfo complexArgInfo() {
24 Info.setCanBeFlattened(false);
25 return Info;
26 }
27
28public:
29 MSP430ABIInfo(CodeGenTypes &CGT) : DefaultABIInfo(CGT) {}
30
32 if (RetTy->isAnyComplexType())
33 return complexArgInfo();
34
36 }
37
39 if (RetTy->isAnyComplexType())
40 return complexArgInfo();
41
43 }
44
45 // Just copy the original implementations because
46 // DefaultABIInfo::classify{Return,Argument}Type() are not virtual
47 void computeInfo(CGFunctionInfo &FI) const override {
50 for (auto &I : FI.arguments())
51 I.info = classifyArgumentType(I.type);
52 }
53
54 RValue EmitVAArg(CodeGenFunction &CGF, Address VAListAddr, QualType Ty,
55 AggValueSlot Slot) const override {
56 return CGF.EmitLoadOfAnyValue(
58 EmitVAArgInstr(CGF, VAListAddr, Ty, classifyArgumentType(Ty)), Ty),
59 Slot);
60 }
61};
62
63class MSP430TargetCodeGenInfo : public TargetCodeGenInfo {
64public:
65 MSP430TargetCodeGenInfo(CodeGenTypes &CGT)
66 : TargetCodeGenInfo(std::make_unique<MSP430ABIInfo>(CGT)) {}
67 void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
68 CodeGen::CodeGenModule &M) const override;
69};
70
71}
72
73void MSP430TargetCodeGenInfo::setTargetAttributes(
74 const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &M) const {
75 if (GV->isDeclaration())
76 return;
77 if (const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D)) {
78 const auto *InterruptAttr = FD->getAttr<MSP430InterruptAttr>();
79 if (!InterruptAttr)
80 return;
81
82 // Handle 'interrupt' attribute:
83 llvm::Function *F = cast<llvm::Function>(GV);
84
85 // Step 1: Set ISR calling convention.
86 F->setCallingConv(llvm::CallingConv::MSP430_INTR);
87
88 // Step 2: Add attributes goodness.
89 F->addFnAttr(llvm::Attribute::NoInline);
90 F->addFnAttr("interrupt", llvm::utostr(InterruptAttr->getNumber()));
91 }
92}
93
94std::unique_ptr<TargetCodeGenInfo>
96 return std::make_unique<MSP430TargetCodeGenInfo>(CGM.getTypes());
97}
const Decl * D
ABIArgInfo - Helper class to encapsulate information about how a specific C type should be passed to ...
static ABIArgInfo getDirect(llvm::Type *T=nullptr, unsigned Offset=0, llvm::Type *Padding=nullptr, bool CanBeFlattened=true, unsigned Align=0)
void setCanBeFlattened(bool Flatten)
CodeGen::CGCXXABI & getCXXABI() const
Definition: ABIInfo.cpp:18
Like RawAddress, an abstract representation of an aligned address, but the pointer contained in this ...
Definition: Address.h:128
An aggregate value slot.
Definition: CGValue.h:504
CGFunctionInfo - Class to encapsulate the information about a function definition.
CanQualType getReturnType() const
MutableArrayRef< ArgInfo > arguments()
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
LValue MakeAddrLValue(Address Addr, QualType T, AlignmentSource Source=AlignmentSource::Type)
RValue EmitLoadOfAnyValue(LValue V, AggValueSlot Slot=AggValueSlot::ignored(), SourceLocation Loc={})
Like EmitLoadOfLValue but also handles complex and aggregate types.
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
ABIArgInfo classifyArgumentType(QualType RetTy) const
Definition: ABIInfoImpl.cpp:17
RValue EmitVAArg(CodeGenFunction &CGF, Address VAListAddr, QualType Ty, AggValueSlot Slot) const override
EmitVAArg - Emit the target dependent code to load a value of.
Definition: ABIInfoImpl.cpp:75
ABIArgInfo classifyReturnType(QualType RetTy) const
Definition: ABIInfoImpl.cpp:46
void computeInfo(CGFunctionInfo &FI) const override
Definition: ABIInfoImpl.cpp:68
RValue - This trivial value class is used to represent the result of an expression that is evaluated.
Definition: CGValue.h:42
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
Represents a function declaration or definition.
Definition: Decl.h:1935
A (possibly-)qualified type.
Definition: Type.h:929
bool isAnyComplexType() const
Definition: Type.h:8294
std::unique_ptr< TargetCodeGenInfo > createMSP430TargetCodeGenInfo(CodeGenModule &CGM)
Definition: MSP430.cpp:95
Address EmitVAArgInstr(CodeGenFunction &CGF, Address VAListAddr, QualType Ty, const ABIArgInfo &AI)
The JSON file list parser is used to communicate input to InstallAPI.