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/ADT/Triple.h"
19 #include "llvm/Support/Compiler.h"
25 class LLVM_LIBRARY_VISIBILITY AVRTargetInfo
: public TargetInfo
{
27 AVRTargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&)
28 : TargetInfo(Triple
) {
39 DefaultAlignForAttributeAligned
= 8;
46 DoubleFormat
= &llvm::APFloat::IEEEsingle();
49 LongDoubleFormat
= &llvm::APFloat::IEEEsingle();
50 SizeType
= UnsignedInt
;
51 PtrDiffType
= SignedInt
;
52 IntPtrType
= SignedInt
;
53 Char16Type
= UnsignedInt
;
55 Int16Type
= SignedInt
;
56 Char32Type
= UnsignedLong
;
57 SigAtomicType
= SignedChar
;
59 resetDataLayout("e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8");
62 void getTargetDefines(const LangOptions
&Opts
,
63 MacroBuilder
&Builder
) const override
;
65 ArrayRef
<Builtin::Info
> getTargetBuiltins() const override
{ return None
; }
67 BuiltinVaListKind
getBuiltinVaListKind() const override
{
68 return TargetInfo::VoidPtrBuiltinVaList
;
71 const char *getClobbers() const override
{ return ""; }
73 ArrayRef
<const char *> getGCCRegNames() const override
{
74 static const char *const GCCRegNames
[] = {
75 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9",
76 "r10", "r11", "r12", "r13", "r14", "r15", "r16", "r17", "r18", "r19",
77 "r20", "r21", "r22", "r23", "r24", "r25", "X", "Y", "Z", "SP"};
78 return llvm::makeArrayRef(GCCRegNames
);
81 ArrayRef
<TargetInfo::GCCRegAlias
> getGCCRegAliases() const override
{
85 ArrayRef
<TargetInfo::AddlRegName
> getGCCAddlRegNames() const override
{
86 static const TargetInfo::AddlRegName AddlRegNames
[] = {
92 return llvm::makeArrayRef(AddlRegNames
);
95 bool validateAsmConstraint(const char *&Name
,
96 TargetInfo::ConstraintInfo
&Info
) const override
{
97 // There aren't any multi-character AVR specific constraints.
98 if (StringRef(Name
).size() > 1)
104 case 'a': // Simple upper registers
105 case 'b': // Base pointer registers pairs
106 case 'd': // Upper register
107 case 'l': // Lower registers
108 case 'e': // Pointer register pairs
109 case 'q': // Stack pointer register
110 case 'r': // Any register
111 case 'w': // Special upper register pairs
112 case 't': // Temporary register
114 case 'X': // Pointer register pair X
116 case 'Y': // Pointer register pair Y
118 case 'Z': // Pointer register pair Z
119 Info
.setAllowsRegister();
121 case 'I': // 6-bit positive integer constant
122 Info
.setRequiresImmediate(0, 63);
124 case 'J': // 6-bit negative integer constant
125 Info
.setRequiresImmediate(-63, 0);
127 case 'K': // Integer constant (Range: 2)
128 Info
.setRequiresImmediate(2);
130 case 'L': // Integer constant (Range: 0)
131 Info
.setRequiresImmediate(0);
133 case 'M': // 8-bit integer constant
134 Info
.setRequiresImmediate(0, 0xff);
136 case 'N': // Integer constant (Range: -1)
137 Info
.setRequiresImmediate(-1);
139 case 'O': // Integer constant (Range: 8, 16, 24)
140 Info
.setRequiresImmediate({8, 16, 24});
142 case 'P': // Integer constant (Range: 1)
143 Info
.setRequiresImmediate(1);
145 case 'R': // Integer constant (Range: -6 to 5)
146 Info
.setRequiresImmediate(-6, 5);
148 case 'G': // Floating point constant
149 case 'Q': // A memory address based on Y or Z pointer with displacement.
156 IntType
getIntTypeByWidth(unsigned BitWidth
, bool IsSigned
) const final
{
157 // AVR prefers int for 16-bit integers.
158 return BitWidth
== 16 ? (IsSigned
? SignedInt
: UnsignedInt
)
159 : TargetInfo::getIntTypeByWidth(BitWidth
, IsSigned
);
162 IntType
getLeastIntTypeByWidth(unsigned BitWidth
, bool IsSigned
) const final
{
163 // AVR uses int for int_least16_t and int_fast16_t.
164 return BitWidth
== 16
165 ? (IsSigned
? SignedInt
: UnsignedInt
)
166 : TargetInfo::getLeastIntTypeByWidth(BitWidth
, IsSigned
);
169 bool isValidCPUName(StringRef Name
) const override
;
170 void fillValidCPUList(SmallVectorImpl
<StringRef
> &Values
) const override
;
171 bool setCPU(const std::string
&Name
) override
;
172 StringRef
getABI() const override
{ return ABI
; }
179 } // namespace targets
182 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_AVR_H