1 //===--- AVR.h - Declare AVR target feature support -------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // This file declares AVR TargetInfo objects.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_CLANG_LIB_BASIC_TARGETS_AVR_H
14 #define LLVM_CLANG_LIB_BASIC_TARGETS_AVR_H
16 #include "clang/Basic/TargetInfo.h"
17 #include "clang/Basic/TargetOptions.h"
18 #include "llvm/Support/Compiler.h"
19 #include "llvm/TargetParser/Triple.h"
25 class LLVM_LIBRARY_VISIBILITY AVRTargetInfo
: public TargetInfo
{
27 AVRTargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&)
28 : TargetInfo(Triple
) {
41 DefaultAlignForAttributeAligned
= 8;
48 DoubleFormat
= &llvm::APFloat::IEEEsingle();
51 LongDoubleFormat
= &llvm::APFloat::IEEEsingle();
52 SizeType
= UnsignedInt
;
53 PtrDiffType
= SignedInt
;
54 IntPtrType
= SignedInt
;
55 Char16Type
= UnsignedInt
;
57 Int16Type
= SignedInt
;
58 Char32Type
= UnsignedLong
;
59 SigAtomicType
= SignedChar
;
60 resetDataLayout("e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8");
63 void getTargetDefines(const LangOptions
&Opts
,
64 MacroBuilder
&Builder
) const override
;
66 ArrayRef
<Builtin::Info
> getTargetBuiltins() const override
{ return {}; }
68 bool allowsLargerPreferedTypeAlignment() const override
{ return false; }
70 BuiltinVaListKind
getBuiltinVaListKind() const override
{
71 return TargetInfo::VoidPtrBuiltinVaList
;
74 std::string_view
getClobbers() const override
{ return ""; }
76 ArrayRef
<const char *> getGCCRegNames() const override
{
77 static const char *const GCCRegNames
[] = {
78 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9",
79 "r10", "r11", "r12", "r13", "r14", "r15", "r16", "r17", "r18", "r19",
80 "r20", "r21", "r22", "r23", "r24", "r25", "X", "Y", "Z", "SP"};
81 return llvm::ArrayRef(GCCRegNames
);
84 ArrayRef
<TargetInfo::GCCRegAlias
> getGCCRegAliases() const override
{
88 ArrayRef
<TargetInfo::AddlRegName
> getGCCAddlRegNames() const override
{
89 static const TargetInfo::AddlRegName AddlRegNames
[] = {
95 return llvm::ArrayRef(AddlRegNames
);
98 bool validateAsmConstraint(const char *&Name
,
99 TargetInfo::ConstraintInfo
&Info
) const override
{
100 // There aren't any multi-character AVR specific constraints.
101 if (StringRef(Name
).size() > 1)
107 case 'a': // Simple upper registers
108 case 'b': // Base pointer registers pairs
109 case 'd': // Upper register
110 case 'l': // Lower registers
111 case 'e': // Pointer register pairs
112 case 'q': // Stack pointer register
113 case 'r': // Any register
114 case 'w': // Special upper register pairs
115 case 't': // Temporary register
117 case 'X': // Pointer register pair X
119 case 'Y': // Pointer register pair Y
121 case 'Z': // Pointer register pair Z
122 Info
.setAllowsRegister();
124 case 'I': // 6-bit positive integer constant
125 Info
.setRequiresImmediate(0, 63);
127 case 'J': // 6-bit negative integer constant
128 Info
.setRequiresImmediate(-63, 0);
130 case 'K': // Integer constant (Range: 2)
131 Info
.setRequiresImmediate(2);
133 case 'L': // Integer constant (Range: 0)
134 Info
.setRequiresImmediate(0);
136 case 'M': // 8-bit integer constant
137 Info
.setRequiresImmediate(0, 0xff);
139 case 'N': // Integer constant (Range: -1)
140 Info
.setRequiresImmediate(-1);
142 case 'O': // Integer constant (Range: 8, 16, 24)
143 Info
.setRequiresImmediate({8, 16, 24});
145 case 'P': // Integer constant (Range: 1)
146 Info
.setRequiresImmediate(1);
148 case 'R': // Integer constant (Range: -6 to 5)
149 Info
.setRequiresImmediate(-6, 5);
151 case 'G': // Floating point constant 0.0
152 Info
.setRequiresImmediate(0);
154 case 'Q': // A memory address based on Y or Z pointer with displacement.
161 IntType
getIntTypeByWidth(unsigned BitWidth
, bool IsSigned
) const final
{
162 // AVR prefers int for 16-bit integers.
163 return BitWidth
== 16 ? (IsSigned
? SignedInt
: UnsignedInt
)
164 : TargetInfo::getIntTypeByWidth(BitWidth
, IsSigned
);
167 IntType
getLeastIntTypeByWidth(unsigned BitWidth
, bool IsSigned
) const final
{
168 // AVR uses int for int_least16_t and int_fast16_t.
169 return BitWidth
== 16
170 ? (IsSigned
? SignedInt
: UnsignedInt
)
171 : TargetInfo::getLeastIntTypeByWidth(BitWidth
, IsSigned
);
174 bool isValidCPUName(StringRef Name
) const override
;
175 void fillValidCPUList(SmallVectorImpl
<StringRef
> &Values
) const override
;
176 bool setCPU(const std::string
&Name
) override
;
177 std::optional
<std::string
> handleAsmEscapedChar(char EscChar
) const override
;
178 StringRef
getABI() const override
{ return ABI
; }
180 std::pair
<unsigned, unsigned> hardwareInterferenceSizes() const override
{
181 return std::make_pair(32, 32);
187 StringRef DefineName
;
189 int NumFlashBanks
= 0;
192 } // namespace targets
195 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_AVR_H