clang 17.0.0git
AVR.h
Go to the documentation of this file.
1//===--- AVR.h - Declare AVR target feature support -------------*- C++ -*-===//
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// This file declares AVR TargetInfo objects.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_LIB_BASIC_TARGETS_AVR_H
14#define LLVM_CLANG_LIB_BASIC_TARGETS_AVR_H
15
18#include "llvm/ADT/Triple.h"
19#include "llvm/Support/Compiler.h"
20
21namespace clang {
22namespace targets {
23
24// AVR Target
25class LLVM_LIBRARY_VISIBILITY AVRTargetInfo : public TargetInfo {
26public:
27 AVRTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
28 : TargetInfo(Triple) {
29 TLSSupported = false;
30 PointerWidth = 16;
31 PointerAlign = 8;
32 IntWidth = 16;
33 IntAlign = 8;
34 LongWidth = 32;
35 LongAlign = 8;
36 LongLongWidth = 64;
37 LongLongAlign = 8;
38 SuitableAlign = 8;
39 DefaultAlignForAttributeAligned = 8;
40 HalfWidth = 16;
41 HalfAlign = 8;
42 FloatWidth = 32;
43 FloatAlign = 8;
44 DoubleWidth = 32;
45 DoubleAlign = 8;
46 DoubleFormat = &llvm::APFloat::IEEEsingle();
47 LongDoubleWidth = 32;
48 LongDoubleAlign = 8;
49 LongDoubleFormat = &llvm::APFloat::IEEEsingle();
50 SizeType = UnsignedInt;
51 PtrDiffType = SignedInt;
52 IntPtrType = SignedInt;
53 Char16Type = UnsignedInt;
54 WIntType = SignedInt;
55 Int16Type = SignedInt;
56 Char32Type = UnsignedLong;
57 SigAtomicType = SignedChar;
58 resetDataLayout("e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8");
59 }
60
61 void getTargetDefines(const LangOptions &Opts,
62 MacroBuilder &Builder) const override;
63
65 return std::nullopt;
66 }
67
69 return TargetInfo::VoidPtrBuiltinVaList;
70 }
71
72 const char *getClobbers() const override { return ""; }
73
75 static const char *const GCCRegNames[] = {
76 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9",
77 "r10", "r11", "r12", "r13", "r14", "r15", "r16", "r17", "r18", "r19",
78 "r20", "r21", "r22", "r23", "r24", "r25", "X", "Y", "Z", "SP"};
79 return llvm::ArrayRef(GCCRegNames);
80 }
81
83 return std::nullopt;
84 }
85
87 static const TargetInfo::AddlRegName AddlRegNames[] = {
88 {{"r26", "r27"}, 26},
89 {{"r28", "r29"}, 27},
90 {{"r30", "r31"}, 28},
91 {{"SPL", "SPH"}, 29},
92 };
94 }
95
96 bool validateAsmConstraint(const char *&Name,
97 TargetInfo::ConstraintInfo &Info) const override {
98 // There aren't any multi-character AVR specific constraints.
99 if (StringRef(Name).size() > 1)
100 return false;
101
102 switch (*Name) {
103 default:
104 return false;
105 case 'a': // Simple upper registers
106 case 'b': // Base pointer registers pairs
107 case 'd': // Upper register
108 case 'l': // Lower registers
109 case 'e': // Pointer register pairs
110 case 'q': // Stack pointer register
111 case 'r': // Any register
112 case 'w': // Special upper register pairs
113 case 't': // Temporary register
114 case 'x':
115 case 'X': // Pointer register pair X
116 case 'y':
117 case 'Y': // Pointer register pair Y
118 case 'z':
119 case 'Z': // Pointer register pair Z
120 Info.setAllowsRegister();
121 return true;
122 case 'I': // 6-bit positive integer constant
123 Info.setRequiresImmediate(0, 63);
124 return true;
125 case 'J': // 6-bit negative integer constant
126 Info.setRequiresImmediate(-63, 0);
127 return true;
128 case 'K': // Integer constant (Range: 2)
129 Info.setRequiresImmediate(2);
130 return true;
131 case 'L': // Integer constant (Range: 0)
132 Info.setRequiresImmediate(0);
133 return true;
134 case 'M': // 8-bit integer constant
135 Info.setRequiresImmediate(0, 0xff);
136 return true;
137 case 'N': // Integer constant (Range: -1)
138 Info.setRequiresImmediate(-1);
139 return true;
140 case 'O': // Integer constant (Range: 8, 16, 24)
141 Info.setRequiresImmediate({8, 16, 24});
142 return true;
143 case 'P': // Integer constant (Range: 1)
144 Info.setRequiresImmediate(1);
145 return true;
146 case 'R': // Integer constant (Range: -6 to 5)
147 Info.setRequiresImmediate(-6, 5);
148 return true;
149 case 'G': // Floating point constant
150 case 'Q': // A memory address based on Y or Z pointer with displacement.
151 return true;
152 }
153
154 return false;
155 }
156
157 IntType getIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final {
158 // AVR prefers int for 16-bit integers.
159 return BitWidth == 16 ? (IsSigned ? SignedInt : UnsignedInt)
160 : TargetInfo::getIntTypeByWidth(BitWidth, IsSigned);
161 }
162
163 IntType getLeastIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final {
164 // AVR uses int for int_least16_t and int_fast16_t.
165 return BitWidth == 16
166 ? (IsSigned ? SignedInt : UnsignedInt)
167 : TargetInfo::getLeastIntTypeByWidth(BitWidth, IsSigned);
168 }
169
170 bool isValidCPUName(StringRef Name) const override;
171 void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
172 bool setCPU(const std::string &Name) override;
173 StringRef getABI() const override { return ABI; }
174
175protected:
176 std::string CPU;
177 StringRef ABI;
178 StringRef DefineName;
179 StringRef Arch;
180 int NumFlashBanks = 0;
181};
182
183} // namespace targets
184} // namespace clang
185
186#endif // LLVM_CLANG_LIB_BASIC_TARGETS_AVR_H
Defines the clang::TargetOptions class.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:82
Exposes information about the current target.
Definition: TargetInfo.h:206
BuiltinVaListKind
The different kinds of __builtin_va_list types defined by the target implementation.
Definition: TargetInfo.h:288
Options for controlling the target.
Definition: TargetOptions.h:26
bool validateAsmConstraint(const char *&Name, TargetInfo::ConstraintInfo &Info) const override
Definition: AVR.h:96
BuiltinVaListKind getBuiltinVaListKind() const override
Returns the kind of __builtin_va_list type that should be used with this target.
Definition: AVR.h:68
const char * getClobbers() const override
Returns a string of target-specific clobbers, in LLVM format.
Definition: AVR.h:72
ArrayRef< const char * > getGCCRegNames() const override
Definition: AVR.h:74
ArrayRef< TargetInfo::GCCRegAlias > getGCCRegAliases() const override
Definition: AVR.h:82
IntType getLeastIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final
Return the smallest integer type with at least the specified width.
Definition: AVR.h:163
ArrayRef< Builtin::Info > getTargetBuiltins() const override
Return information about target-specific builtins for the current primary target, and info about whic...
Definition: AVR.h:64
StringRef getABI() const override
Get the ABI currently in use.
Definition: AVR.h:173
ArrayRef< TargetInfo::AddlRegName > getGCCAddlRegNames() const override
Definition: AVR.h:86
IntType getIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final
Return integer type with specified width.
Definition: AVR.h:157
AVRTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
Definition: AVR.h:27
Defines the clang::TargetInfo interface.
const TargetInfo::AddlRegName AddlRegNames[]
Definition: X86.cpp:69
void setRequiresImmediate(int Min, int Max)
Definition: TargetInfo.h:1092
IntType
===-— Target Data Type Query Methods ----------------------------—===//
Definition: TargetInfo.h:135