clang  19.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 
12 using namespace clang;
13 using namespace clang::CodeGen;
14 
15 //===----------------------------------------------------------------------===//
16 // MSP430 ABI Implementation
17 //===----------------------------------------------------------------------===//
18 
19 namespace {
20 
21 class MSP430ABIInfo : public DefaultABIInfo {
22  static ABIArgInfo complexArgInfo() {
24  Info.setCanBeFlattened(false);
25  return Info;
26  }
27 
28 public:
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 {
48  if (!getCXXABI().classifyReturnType(FI))
50  for (auto &I : FI.arguments())
51  I.info = classifyArgumentType(I.type);
52  }
53 
54  Address EmitVAArg(CodeGenFunction &CGF, Address VAListAddr,
55  QualType Ty) const override {
56  return EmitVAArgInstr(CGF, VAListAddr, Ty, classifyArgumentType(Ty));
57  }
58 };
59 
60 class MSP430TargetCodeGenInfo : public TargetCodeGenInfo {
61 public:
62  MSP430TargetCodeGenInfo(CodeGenTypes &CGT)
63  : TargetCodeGenInfo(std::make_unique<MSP430ABIInfo>(CGT)) {}
64  void setTargetAttributes(const Decl *D, llvm::GlobalValue *GV,
65  CodeGen::CodeGenModule &M) const override;
66 };
67 
68 }
69 
70 void MSP430TargetCodeGenInfo::setTargetAttributes(
71  const Decl *D, llvm::GlobalValue *GV, CodeGen::CodeGenModule &M) const {
72  if (GV->isDeclaration())
73  return;
74  if (const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D)) {
75  const auto *InterruptAttr = FD->getAttr<MSP430InterruptAttr>();
76  if (!InterruptAttr)
77  return;
78 
79  // Handle 'interrupt' attribute:
80  llvm::Function *F = cast<llvm::Function>(GV);
81 
82  // Step 1: Set ISR calling convention.
83  F->setCallingConv(llvm::CallingConv::MSP430_INTR);
84 
85  // Step 2: Add attributes goodness.
86  F->addFnAttr(llvm::Attribute::NoInline);
87  F->addFnAttr("interrupt", llvm::utostr(InterruptAttr->getNumber()));
88  }
89 }
90 
91 std::unique_ptr<TargetCodeGenInfo>
93  return std::make_unique<MSP430TargetCodeGenInfo>(CGM.getTypes());
94 }
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)
Like RawAddress, an abstract representation of an aligned address, but the pointer contained in this ...
Definition: Address.h:111
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...
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
ABIArgInfo classifyReturnType(QualType RetTy) const
Definition: ABIInfoImpl.cpp:45
TargetCodeGenInfo - This class organizes various target-specific codegeneration issues,...
Definition: TargetInfo.h:46
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
Represents a function declaration or definition.
Definition: Decl.h:1972
A (possibly-)qualified type.
Definition: Type.h:940
bool isAnyComplexType() const
Definition: Type.h:7726
ABIArgInfo classifyArgumentType(CodeGenModule &CGM, CanQualType type)
Classify the rules for how to pass a particular type.
std::unique_ptr< TargetCodeGenInfo > createMSP430TargetCodeGenInfo(CodeGenModule &CGM)
Definition: MSP430.cpp:92
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.
Definition: Format.h:5433