[OptTable] Fix typo VALUE => VALUES (NFCI) (#121523)
[llvm-project.git] / clang / lib / CodeGen / Targets / MSP430.cpp
blob8ce70e2111ccfa828984b7cfda513f21cc896648
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 //===----------------------------------------------------------------------===//
9 #include "ABIInfoImpl.h"
10 #include "TargetInfo.h"
12 using namespace clang;
13 using namespace clang::CodeGen;
15 //===----------------------------------------------------------------------===//
16 // MSP430 ABI Implementation
17 //===----------------------------------------------------------------------===//
19 namespace {
21 class MSP430ABIInfo : public DefaultABIInfo {
22 static ABIArgInfo complexArgInfo() {
23 ABIArgInfo Info = ABIArgInfo::getDirect();
24 Info.setCanBeFlattened(false);
25 return Info;
28 public:
29 MSP430ABIInfo(CodeGenTypes &CGT) : DefaultABIInfo(CGT) {}
31 ABIArgInfo classifyReturnType(QualType RetTy) const {
32 if (RetTy->isAnyComplexType())
33 return complexArgInfo();
35 return DefaultABIInfo::classifyReturnType(RetTy);
38 ABIArgInfo classifyArgumentType(QualType RetTy) const {
39 if (RetTy->isAnyComplexType())
40 return complexArgInfo();
42 return DefaultABIInfo::classifyArgumentType(RetTy);
45 // Just copy the original implementations because
46 // DefaultABIInfo::classify{Return,Argument}Type() are not virtual
47 void computeInfo(CGFunctionInfo &FI) const override {
48 if (!getCXXABI().classifyReturnType(FI))
49 FI.getReturnInfo() = classifyReturnType(FI.getReturnType());
50 for (auto &I : FI.arguments())
51 I.info = classifyArgumentType(I.type);
54 RValue EmitVAArg(CodeGenFunction &CGF, Address VAListAddr, QualType Ty,
55 AggValueSlot Slot) const override {
56 return CGF.EmitLoadOfAnyValue(
57 CGF.MakeAddrLValue(
58 EmitVAArgInstr(CGF, VAListAddr, Ty, classifyArgumentType(Ty)), Ty),
59 Slot);
63 class MSP430TargetCodeGenInfo : public TargetCodeGenInfo {
64 public:
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;
73 void 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;
82 // Handle 'interrupt' attribute:
83 llvm::Function *F = cast<llvm::Function>(GV);
85 // Step 1: Set ISR calling convention.
86 F->setCallingConv(llvm::CallingConv::MSP430_INTR);
88 // Step 2: Add attributes goodness.
89 F->addFnAttr(llvm::Attribute::NoInline);
90 F->addFnAttr("interrupt", llvm::utostr(InterruptAttr->getNumber()));
94 std::unique_ptr<TargetCodeGenInfo>
95 CodeGen::createMSP430TargetCodeGenInfo(CodeGenModule &CGM) {
96 return std::make_unique<MSP430TargetCodeGenInfo>(CGM.getTypes());