clang 24.0.0git
AVR.cpp
Go to the documentation of this file.
1//===--- AVR.cpp - Implement AVR target feature support -------------------===//
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 implements AVR TargetInfo objects.
10//
11//===----------------------------------------------------------------------===//
12
13#include "AVR.h"
17#include "llvm/ADT/StringSwitch.h"
18
19using namespace clang;
20using namespace clang::targets;
21
23
24#define GET_BUILTIN_STR_TABLE
25#include "clang/Basic/BuiltinsAVR.inc"
26#undef GET_BUILTIN_STR_TABLE
27
28static constexpr Builtin::Info BuiltinInfos[] = {
29#define GET_BUILTIN_INFOS
30#include "clang/Basic/BuiltinsAVR.inc"
31#undef GET_BUILTIN_INFOS
32};
33static_assert(std::size(BuiltinInfos) == NumBuiltins);
34
35namespace clang {
36namespace targets {
37
38/// Information about a specific microcontroller.
39struct LLVM_LIBRARY_VISIBILITY MCUInfo {
40 const char *Name;
41 const char *DefineName;
42 StringRef Arch; // The __AVR_ARCH__ value.
43 const int NumFlashBanks; // Set to 0 for the devices do not support LPM/ELPM.
44};
45
46// NOTE: This list has been synchronized with gcc-avr 5.4.0 and avr-libc 2.0.0.
47static const MCUInfo AVRMcus[] = {
48 {"avr1", nullptr, "1", 0},
49 {"at90s1200", "__AVR_AT90S1200__", "1", 0},
50 {"attiny11", "__AVR_ATtiny11__", "1", 0},
51 {"attiny12", "__AVR_ATtiny12__", "1", 0},
52 {"attiny15", "__AVR_ATtiny15__", "1", 0},
53 {"attiny28", "__AVR_ATtiny28__", "1", 0},
54 {"avr2", nullptr, "2", 1},
55 {"at90s2313", "__AVR_AT90S2313__", "2", 1},
56 {"at90s2323", "__AVR_AT90S2323__", "2", 1},
57 {"at90s2333", "__AVR_AT90S2333__", "2", 1},
58 {"at90s2343", "__AVR_AT90S2343__", "2", 1},
59 {"attiny22", "__AVR_ATtiny22__", "2", 1},
60 {"attiny26", "__AVR_ATtiny26__", "2", 1},
61 {"at86rf401", "__AVR_AT86RF401__", "25", 1},
62 {"at90s4414", "__AVR_AT90S4414__", "2", 1},
63 {"at90s4433", "__AVR_AT90S4433__", "2", 1},
64 {"at90s4434", "__AVR_AT90S4434__", "2", 1},
65 {"at90s8515", "__AVR_AT90S8515__", "2", 1},
66 {"at90c8534", "__AVR_AT90c8534__", "2", 1},
67 {"at90s8535", "__AVR_AT90S8535__", "2", 1},
68 {"avr25", nullptr, "25", 1},
69 {"ata5272", "__AVR_ATA5272__", "25", 1},
70 {"ata6616c", "__AVR_ATA6616c__", "25", 1},
71 {"attiny13", "__AVR_ATtiny13__", "25", 1},
72 {"attiny13a", "__AVR_ATtiny13A__", "25", 1},
73 {"attiny2313", "__AVR_ATtiny2313__", "25", 1},
74 {"attiny2313a", "__AVR_ATtiny2313A__", "25", 1},
75 {"attiny24", "__AVR_ATtiny24__", "25", 1},
76 {"attiny24a", "__AVR_ATtiny24A__", "25", 1},
77 {"attiny4313", "__AVR_ATtiny4313__", "25", 1},
78 {"attiny44", "__AVR_ATtiny44__", "25", 1},
79 {"attiny44a", "__AVR_ATtiny44A__", "25", 1},
80 {"attiny84", "__AVR_ATtiny84__", "25", 1},
81 {"attiny84a", "__AVR_ATtiny84A__", "25", 1},
82 {"attiny25", "__AVR_ATtiny25__", "25", 1},
83 {"attiny45", "__AVR_ATtiny45__", "25", 1},
84 {"attiny85", "__AVR_ATtiny85__", "25", 1},
85 {"attiny261", "__AVR_ATtiny261__", "25", 1},
86 {"attiny261a", "__AVR_ATtiny261A__", "25", 1},
87 {"attiny441", "__AVR_ATtiny441__", "25", 1},
88 {"attiny461", "__AVR_ATtiny461__", "25", 1},
89 {"attiny461a", "__AVR_ATtiny461A__", "25", 1},
90 {"attiny841", "__AVR_ATtiny841__", "25", 1},
91 {"attiny861", "__AVR_ATtiny861__", "25", 1},
92 {"attiny861a", "__AVR_ATtiny861A__", "25", 1},
93 {"attiny87", "__AVR_ATtiny87__", "25", 1},
94 {"attiny43u", "__AVR_ATtiny43U__", "25", 1},
95 {"attiny48", "__AVR_ATtiny48__", "25", 1},
96 {"attiny88", "__AVR_ATtiny88__", "25", 1},
97 {"attiny828", "__AVR_ATtiny828__", "25", 1},
98 {"avr3", nullptr, "3", 1},
99 {"at43usb355", "__AVR_AT43USB355__", "3", 1},
100 {"at76c711", "__AVR_AT76C711__", "3", 1},
101 {"avr31", nullptr, "31", 1},
102 {"atmega103", "__AVR_ATmega103__", "31", 1},
103 {"at43usb320", "__AVR_AT43USB320__", "31", 1},
104 {"avr35", nullptr, "35", 1},
105 {"attiny167", "__AVR_ATtiny167__", "35", 1},
106 {"at90usb82", "__AVR_AT90USB82__", "35", 1},
107 {"at90usb162", "__AVR_AT90USB162__", "35", 1},
108 {"ata5505", "__AVR_ATA5505__", "35", 1},
109 {"ata6617c", "__AVR_ATA6617C__", "35", 1},
110 {"ata664251", "__AVR_ATA664251__", "35", 1},
111 {"atmega8u2", "__AVR_ATmega8U2__", "35", 1},
112 {"atmega16u2", "__AVR_ATmega16U2__", "35", 1},
113 {"atmega32u2", "__AVR_ATmega32U2__", "35", 1},
114 {"attiny1634", "__AVR_ATtiny1634__", "35", 1},
115 {"avr4", nullptr, "4", 1},
116 {"atmega8", "__AVR_ATmega8__", "4", 1},
117 {"ata6289", "__AVR_ATA6289__", "4", 1},
118 {"atmega8a", "__AVR_ATmega8A__", "4", 1},
119 {"ata6285", "__AVR_ATA6285__", "4", 1},
120 {"ata6286", "__AVR_ATA6286__", "4", 1},
121 {"ata6612c", "__AVR_ATA6612C__", "4", 1},
122 {"atmega48", "__AVR_ATmega48__", "4", 1},
123 {"atmega48a", "__AVR_ATmega48A__", "4", 1},
124 {"atmega48pa", "__AVR_ATmega48PA__", "4", 1},
125 {"atmega48pb", "__AVR_ATmega48PB__", "4", 1},
126 {"atmega48p", "__AVR_ATmega48P__", "4", 1},
127 {"atmega88", "__AVR_ATmega88__", "4", 1},
128 {"atmega88a", "__AVR_ATmega88A__", "4", 1},
129 {"atmega88p", "__AVR_ATmega88P__", "4", 1},
130 {"atmega88pa", "__AVR_ATmega88PA__", "4", 1},
131 {"atmega88pb", "__AVR_ATmega88PB__", "4", 1},
132 {"atmega8515", "__AVR_ATmega8515__", "4", 1},
133 {"atmega8535", "__AVR_ATmega8535__", "4", 1},
134 {"atmega8hva", "__AVR_ATmega8HVA__", "4", 1},
135 {"at90pwm1", "__AVR_AT90PWM1__", "4", 1},
136 {"at90pwm2", "__AVR_AT90PWM2__", "4", 1},
137 {"at90pwm2b", "__AVR_AT90PWM2B__", "4", 1},
138 {"at90pwm3", "__AVR_AT90PWM3__", "4", 1},
139 {"at90pwm3b", "__AVR_AT90PWM3B__", "4", 1},
140 {"at90pwm81", "__AVR_AT90PWM81__", "4", 1},
141 {"avr5", nullptr, "5", 1},
142 {"ata5702m322", "__AVR_ATA5702M322__", "5", 1},
143 {"ata5782", "__AVR_ATA5782__", "5", 1},
144 {"ata5790", "__AVR_ATA5790__", "5", 1},
145 {"ata5790n", "__AVR_ATA5790N__", "5", 1},
146 {"ata5791", "__AVR_ATA5791__", "5", 1},
147 {"ata5795", "__AVR_ATA5795__", "5", 1},
148 {"ata5831", "__AVR_ATA5831__", "5", 1},
149 {"ata6613c", "__AVR_ATA6613C__", "5", 1},
150 {"ata6614q", "__AVR_ATA6614Q__", "5", 1},
151 {"ata8210", "__AVR_ATA8210__", "5", 1},
152 {"ata8510", "__AVR_ATA8510__", "5", 1},
153 {"atmega16", "__AVR_ATmega16__", "5", 1},
154 {"atmega16a", "__AVR_ATmega16A__", "5", 1},
155 {"atmega161", "__AVR_ATmega161__", "5", 1},
156 {"atmega162", "__AVR_ATmega162__", "5", 1},
157 {"atmega163", "__AVR_ATmega163__", "5", 1},
158 {"atmega164a", "__AVR_ATmega164A__", "5", 1},
159 {"atmega164p", "__AVR_ATmega164P__", "5", 1},
160 {"atmega164pa", "__AVR_ATmega164PA__", "5", 1},
161 {"atmega165", "__AVR_ATmega165__", "5", 1},
162 {"atmega165a", "__AVR_ATmega165A__", "5", 1},
163 {"atmega165p", "__AVR_ATmega165P__", "5", 1},
164 {"atmega165pa", "__AVR_ATmega165PA__", "5", 1},
165 {"atmega168", "__AVR_ATmega168__", "5", 1},
166 {"atmega168a", "__AVR_ATmega168A__", "5", 1},
167 {"atmega168p", "__AVR_ATmega168P__", "5", 1},
168 {"atmega168pa", "__AVR_ATmega168PA__", "5", 1},
169 {"atmega168pb", "__AVR_ATmega168PB__", "5", 1},
170 {"atmega169", "__AVR_ATmega169__", "5", 1},
171 {"atmega169a", "__AVR_ATmega169A__", "5", 1},
172 {"atmega169p", "__AVR_ATmega169P__", "5", 1},
173 {"atmega169pa", "__AVR_ATmega169PA__", "5", 1},
174 {"atmega32", "__AVR_ATmega32__", "5", 1},
175 {"atmega32a", "__AVR_ATmega32A__", "5", 1},
176 {"atmega323", "__AVR_ATmega323__", "5", 1},
177 {"atmega324a", "__AVR_ATmega324A__", "5", 1},
178 {"atmega324p", "__AVR_ATmega324P__", "5", 1},
179 {"atmega324pa", "__AVR_ATmega324PA__", "5", 1},
180 {"atmega324pb", "__AVR_ATmega324PB__", "5", 1},
181 {"atmega325", "__AVR_ATmega325__", "5", 1},
182 {"atmega325a", "__AVR_ATmega325A__", "5", 1},
183 {"atmega325p", "__AVR_ATmega325P__", "5", 1},
184 {"atmega325pa", "__AVR_ATmega325PA__", "5", 1},
185 {"atmega3250", "__AVR_ATmega3250__", "5", 1},
186 {"atmega3250a", "__AVR_ATmega3250A__", "5", 1},
187 {"atmega3250p", "__AVR_ATmega3250P__", "5", 1},
188 {"atmega3250pa", "__AVR_ATmega3250PA__", "5", 1},
189 {"atmega328", "__AVR_ATmega328__", "5", 1},
190 {"atmega328p", "__AVR_ATmega328P__", "5", 1},
191 {"atmega328pb", "__AVR_ATmega328PB__", "5", 1},
192 {"atmega329", "__AVR_ATmega329__", "5", 1},
193 {"atmega329a", "__AVR_ATmega329A__", "5", 1},
194 {"atmega329p", "__AVR_ATmega329P__", "5", 1},
195 {"atmega329pa", "__AVR_ATmega329PA__", "5", 1},
196 {"atmega3290", "__AVR_ATmega3290__", "5", 1},
197 {"atmega3290a", "__AVR_ATmega3290A__", "5", 1},
198 {"atmega3290p", "__AVR_ATmega3290P__", "5", 1},
199 {"atmega3290pa", "__AVR_ATmega3290PA__", "5", 1},
200 {"atmega406", "__AVR_ATmega406__", "5", 1},
201 {"atmega64", "__AVR_ATmega64__", "5", 1},
202 {"atmega64a", "__AVR_ATmega64A__", "5", 1},
203 {"atmega640", "__AVR_ATmega640__", "5", 1},
204 {"atmega644", "__AVR_ATmega644__", "5", 1},
205 {"atmega644a", "__AVR_ATmega644A__", "5", 1},
206 {"atmega644p", "__AVR_ATmega644P__", "5", 1},
207 {"atmega644pa", "__AVR_ATmega644PA__", "5", 1},
208 {"atmega645", "__AVR_ATmega645__", "5", 1},
209 {"atmega645a", "__AVR_ATmega645A__", "5", 1},
210 {"atmega645p", "__AVR_ATmega645P__", "5", 1},
211 {"atmega649", "__AVR_ATmega649__", "5", 1},
212 {"atmega649a", "__AVR_ATmega649A__", "5", 1},
213 {"atmega649p", "__AVR_ATmega649P__", "5", 1},
214 {"atmega6450", "__AVR_ATmega6450__", "5", 1},
215 {"atmega6450a", "__AVR_ATmega6450A__", "5", 1},
216 {"atmega6450p", "__AVR_ATmega6450P__", "5", 1},
217 {"atmega6490", "__AVR_ATmega6490__", "5", 1},
218 {"atmega6490a", "__AVR_ATmega6490A__", "5", 1},
219 {"atmega6490p", "__AVR_ATmega6490P__", "5", 1},
220 {"atmega64rfr2", "__AVR_ATmega64RFR2__", "5", 1},
221 {"atmega644rfr2", "__AVR_ATmega644RFR2__", "5", 1},
222 {"atmega16hva", "__AVR_ATmega16HVA__", "5", 1},
223 {"atmega16hva2", "__AVR_ATmega16HVA2__", "5", 1},
224 {"atmega16hvb", "__AVR_ATmega16HVB__", "5", 1},
225 {"atmega16hvbrevb", "__AVR_ATmega16HVBREVB__", "5", 1},
226 {"atmega32hvb", "__AVR_ATmega32HVB__", "5", 1},
227 {"atmega32hvbrevb", "__AVR_ATmega32HVBREVB__", "5", 1},
228 {"atmega64hve", "__AVR_ATmega64HVE__", "5", 1},
229 {"atmega64hve2", "__AVR_ATmega64HVE2__", "5", 1},
230 {"at90can32", "__AVR_AT90CAN32__", "5", 1},
231 {"at90can64", "__AVR_AT90CAN64__", "5", 1},
232 {"at90pwm161", "__AVR_AT90PWM161__", "5", 1},
233 {"at90pwm216", "__AVR_AT90PWM216__", "5", 1},
234 {"at90pwm316", "__AVR_AT90PWM316__", "5", 1},
235 {"atmega32c1", "__AVR_ATmega32C1__", "5", 1},
236 {"atmega64c1", "__AVR_ATmega64C1__", "5", 1},
237 {"atmega16m1", "__AVR_ATmega16M1__", "5", 1},
238 {"atmega32m1", "__AVR_ATmega32M1__", "5", 1},
239 {"atmega64m1", "__AVR_ATmega64M1__", "5", 1},
240 {"atmega16u4", "__AVR_ATmega16U4__", "5", 1},
241 {"atmega32u4", "__AVR_ATmega32U4__", "5", 1},
242 {"atmega32u6", "__AVR_ATmega32U6__", "5", 1},
243 {"at90usb646", "__AVR_AT90USB646__", "5", 1},
244 {"at90usb647", "__AVR_AT90USB647__", "5", 1},
245 {"at90scr100", "__AVR_AT90SCR100__", "5", 1},
246 {"at94k", "__AVR_AT94K__", "5", 1},
247 {"m3000", "__AVR_AT000__", "5", 1},
248 {"avr51", nullptr, "51", 2},
249 {"atmega128", "__AVR_ATmega128__", "51", 2},
250 {"atmega128a", "__AVR_ATmega128A__", "51", 2},
251 {"atmega1280", "__AVR_ATmega1280__", "51", 2},
252 {"atmega1281", "__AVR_ATmega1281__", "51", 2},
253 {"atmega1284", "__AVR_ATmega1284__", "51", 2},
254 {"atmega1284p", "__AVR_ATmega1284P__", "51", 2},
255 {"atmega128rfa1", "__AVR_ATmega128RFA1__", "51", 2},
256 {"atmega128rfr2", "__AVR_ATmega128RFR2__", "51", 2},
257 {"atmega1284rfr2", "__AVR_ATmega1284RFR2__", "51", 2},
258 {"at90can128", "__AVR_AT90CAN128__", "51", 2},
259 {"at90usb1286", "__AVR_AT90USB1286__", "51", 2},
260 {"at90usb1287", "__AVR_AT90USB1287__", "51", 2},
261 {"avr6", nullptr, "6", 4},
262 {"atmega2560", "__AVR_ATmega2560__", "6", 4},
263 {"atmega2561", "__AVR_ATmega2561__", "6", 4},
264 {"atmega256rfr2", "__AVR_ATmega256RFR2__", "6", 4},
265 {"atmega2564rfr2", "__AVR_ATmega2564RFR2__", "6", 4},
266 {"avrxmega2", nullptr, "102", 1},
267 {"atxmega16a4", "__AVR_ATxmega16A4__", "102", 1},
268 {"atxmega16a4u", "__AVR_ATxmega16A4U__", "102", 1},
269 {"atxmega16c4", "__AVR_ATxmega16C4__", "102", 1},
270 {"atxmega16d4", "__AVR_ATxmega16D4__", "102", 1},
271 {"atxmega32a4", "__AVR_ATxmega32A4__", "102", 1},
272 {"atxmega32a4u", "__AVR_ATxmega32A4U__", "102", 1},
273 {"atxmega32c3", "__AVR_ATxmega32C3__", "102", 1},
274 {"atxmega32c4", "__AVR_ATxmega32C4__", "102", 1},
275 {"atxmega32d3", "__AVR_ATxmega32D3__", "102", 1},
276 {"atxmega32d4", "__AVR_ATxmega32D4__", "102", 1},
277 {"atxmega32e5", "__AVR_ATxmega32E5__", "102", 1},
278 {"atxmega16e5", "__AVR_ATxmega16E5__", "102", 1},
279 {"atxmega8e5", "__AVR_ATxmega8E5__", "102", 1},
280 {"avrxmega4", nullptr, "104", 1},
281 {"atxmega64a3", "__AVR_ATxmega64A3__", "104", 1},
282 {"atxmega64a3u", "__AVR_ATxmega64A3U__", "104", 1},
283 {"atxmega64a4u", "__AVR_ATxmega64A4U__", "104", 1},
284 {"atxmega64b1", "__AVR_ATxmega64B1__", "104", 1},
285 {"atxmega64b3", "__AVR_ATxmega64B3__", "104", 1},
286 {"atxmega64c3", "__AVR_ATxmega64C3__", "104", 1},
287 {"atxmega64d3", "__AVR_ATxmega64D3__", "104", 1},
288 {"atxmega64d4", "__AVR_ATxmega64D4__", "104", 1},
289 {"avrxmega5", nullptr, "105", 1},
290 {"atxmega64a1", "__AVR_ATxmega64A1__", "105", 1},
291 {"atxmega64a1u", "__AVR_ATxmega64A1U__", "105", 1},
292 {"avrxmega6", nullptr, "106", 6},
293 {"atxmega128a3", "__AVR_ATxmega128A3__", "106", 2},
294 {"atxmega128a3u", "__AVR_ATxmega128A3U__", "106", 2},
295 {"atxmega128b1", "__AVR_ATxmega128B1__", "106", 2},
296 {"atxmega128b3", "__AVR_ATxmega128B3__", "106", 2},
297 {"atxmega128c3", "__AVR_ATxmega128C3__", "106", 2},
298 {"atxmega128d3", "__AVR_ATxmega128D3__", "106", 2},
299 {"atxmega128d4", "__AVR_ATxmega128D4__", "106", 2},
300 {"atxmega192a3", "__AVR_ATxmega192A3__", "106", 3},
301 {"atxmega192a3u", "__AVR_ATxmega192A3U__", "106", 3},
302 {"atxmega192c3", "__AVR_ATxmega192C3__", "106", 3},
303 {"atxmega192d3", "__AVR_ATxmega192D3__", "106", 3},
304 {"atxmega256a3", "__AVR_ATxmega256A3__", "106", 4},
305 {"atxmega256a3u", "__AVR_ATxmega256A3U__", "106", 4},
306 {"atxmega256a3b", "__AVR_ATxmega256A3B__", "106", 4},
307 {"atxmega256a3bu", "__AVR_ATxmega256A3BU__", "106", 4},
308 {"atxmega256c3", "__AVR_ATxmega256C3__", "106", 4},
309 {"atxmega256d3", "__AVR_ATxmega256D3__", "106", 4},
310 {"atxmega384c3", "__AVR_ATxmega384C3__", "106", 6},
311 {"atxmega384d3", "__AVR_ATxmega384D3__", "106", 6},
312 {"avrxmega7", nullptr, "107", 2},
313 {"atxmega128a1", "__AVR_ATxmega128A1__", "107", 2},
314 {"atxmega128a1u", "__AVR_ATxmega128A1U__", "107", 2},
315 {"atxmega128a4u", "__AVR_ATxmega128A4U__", "107", 2},
316 {"avrtiny", nullptr, "100", 0},
317 {"attiny4", "__AVR_ATtiny4__", "100", 0},
318 {"attiny5", "__AVR_ATtiny5__", "100", 0},
319 {"attiny9", "__AVR_ATtiny9__", "100", 0},
320 {"attiny10", "__AVR_ATtiny10__", "100", 0},
321 {"attiny20", "__AVR_ATtiny20__", "100", 0},
322 {"attiny40", "__AVR_ATtiny40__", "100", 0},
323 {"attiny102", "__AVR_ATtiny102__", "100", 0},
324 {"attiny104", "__AVR_ATtiny104__", "100", 0},
325 {"avrxmega3", nullptr, "103", 1},
326 {"attiny202", "__AVR_ATtiny202__", "103", 1},
327 {"attiny402", "__AVR_ATtiny402__", "103", 1},
328 {"attiny204", "__AVR_ATtiny204__", "103", 1},
329 {"attiny404", "__AVR_ATtiny404__", "103", 1},
330 {"attiny804", "__AVR_ATtiny804__", "103", 1},
331 {"attiny1604", "__AVR_ATtiny1604__", "103", 1},
332 {"attiny406", "__AVR_ATtiny406__", "103", 1},
333 {"attiny806", "__AVR_ATtiny806__", "103", 1},
334 {"attiny1606", "__AVR_ATtiny1606__", "103", 1},
335 {"attiny807", "__AVR_ATtiny807__", "103", 1},
336 {"attiny1607", "__AVR_ATtiny1607__", "103", 1},
337 {"attiny212", "__AVR_ATtiny212__", "103", 1},
338 {"attiny412", "__AVR_ATtiny412__", "103", 1},
339 {"attiny214", "__AVR_ATtiny214__", "103", 1},
340 {"attiny414", "__AVR_ATtiny414__", "103", 1},
341 {"attiny814", "__AVR_ATtiny814__", "103", 1},
342 {"attiny1614", "__AVR_ATtiny1614__", "103", 1},
343 {"attiny416", "__AVR_ATtiny416__", "103", 1},
344 {"attiny816", "__AVR_ATtiny816__", "103", 1},
345 {"attiny1616", "__AVR_ATtiny1616__", "103", 1},
346 {"attiny3216", "__AVR_ATtiny3216__", "103", 1},
347 {"attiny417", "__AVR_ATtiny417__", "103", 1},
348 {"attiny817", "__AVR_ATtiny817__", "103", 1},
349 {"attiny1617", "__AVR_ATtiny1617__", "103", 1},
350 {"attiny3217", "__AVR_ATtiny3217__", "103", 1},
351 {"attiny1624", "__AVR_ATtiny1624__", "103", 1},
352 {"attiny1626", "__AVR_ATtiny1626__", "103", 1},
353 {"attiny1627", "__AVR_ATtiny1627__", "103", 1},
354 {"attiny3224", "__AVR_ATtiny3224__", "103", 1},
355 {"attiny3226", "__AVR_ATtiny3226__", "103", 1},
356 {"attiny3227", "__AVR_ATtiny3227__", "103", 1},
357 {"atmega808", "__AVR_ATmega808__", "103", 1},
358 {"atmega809", "__AVR_ATmega809__", "103", 1},
359 {"atmega1608", "__AVR_ATmega1608__", "103", 1},
360 {"atmega1609", "__AVR_ATmega1609__", "103", 1},
361 {"atmega3208", "__AVR_ATmega3208__", "103", 1},
362 {"atmega3209", "__AVR_ATmega3209__", "103", 1},
363 {"atmega4808", "__AVR_ATmega4808__", "103", 1},
364 {"atmega4809", "__AVR_ATmega4809__", "103", 1},
365
366 // gcc 14 additions:
367
368 {"avr64da28", "__AVR_AVR64DA28__", "102", 1},
369 {"avr64da32", "__AVR_AVR64DA32__", "102", 1},
370 {"avr64da48", "__AVR_AVR64DA48__", "102", 1},
371 {"avr64da64", "__AVR_AVR64DA64__", "102", 1},
372 {"avr64db28", "__AVR_AVR64DB28__", "102", 1},
373 {"avr64db32", "__AVR_AVR64DB32__", "102", 1},
374 {"avr64db48", "__AVR_AVR64DB48__", "102", 1},
375 {"avr64db64", "__AVR_AVR64DB64__", "102", 1},
376 {"avr64dd14", "__AVR_AVR64DD14__", "102", 1},
377 {"avr64dd20", "__AVR_AVR64DD20__", "102", 1},
378 {"avr64dd28", "__AVR_AVR64DD28__", "102", 1},
379 {"avr64dd32", "__AVR_AVR64DD32__", "102", 1},
380 {"avr64du28", "__AVR_AVR64DU28__", "102", 1},
381 {"avr64du32", "__AVR_AVR64DU32__", "102", 1},
382 {"avr64ea28", "__AVR_AVR64EA28__", "102", 1},
383 {"avr64ea32", "__AVR_AVR64EA32__", "102", 1},
384 {"avr64ea48", "__AVR_AVR64EA48__", "102", 1},
385 {"avr64sd28", "__AVR_AVR64SD28__", "102", 1},
386 {"avr64sd32", "__AVR_AVR64SD32__", "102", 1},
387 {"avr64sd48", "__AVR_AVR64SD48__", "102", 1},
388
389 {"avr16dd20", "__AVR_AVR16DD20__", "103", 1},
390 {"avr16dd28", "__AVR_AVR16DD28__", "103", 1},
391 {"avr16dd32", "__AVR_AVR16DD32__", "103", 1},
392 {"avr16du14", "__AVR_AVR16DU14__", "103", 1},
393 {"avr16du20", "__AVR_AVR16DU20__", "103", 1},
394 {"avr16du28", "__AVR_AVR16DU28__", "103", 1},
395 {"avr16du32", "__AVR_AVR16DU32__", "103", 1},
396 {"avr32da28", "__AVR_AVR32DA28__", "103", 1},
397 {"avr32da32", "__AVR_AVR32DA32__", "103", 1},
398 {"avr32da48", "__AVR_AVR32DA48__", "103", 1},
399 {"avr32db28", "__AVR_AVR32DB28__", "103", 1},
400 {"avr32db32", "__AVR_AVR32DB32__", "103", 1},
401 {"avr32db48", "__AVR_AVR32DB48__", "103", 1},
402 {"avr32dd14", "__AVR_AVR32DD14__", "103", 1},
403 {"avr32dd20", "__AVR_AVR32DD20__", "103", 1},
404 {"avr32dd28", "__AVR_AVR32DD28__", "103", 1},
405 {"avr32dd32", "__AVR_AVR32DD32__", "103", 1},
406 {"avr32du14", "__AVR_AVR32DU14__", "103", 1},
407 {"avr32du20", "__AVR_AVR32DU20__", "103", 1},
408 {"avr32du28", "__AVR_AVR32DU28__", "103", 1},
409 {"avr32du32", "__AVR_AVR32DU32__", "103", 1},
410 {"avr16eb14", "__AVR_AVR16EB14__", "103", 1},
411 {"avr16eb20", "__AVR_AVR16EB20__", "103", 1},
412 {"avr16eb28", "__AVR_AVR16EB28__", "103", 1},
413 {"avr16eb32", "__AVR_AVR16EB32__", "103", 1},
414 {"avr16ea28", "__AVR_AVR16EA28__", "103", 1},
415 {"avr16ea32", "__AVR_AVR16EA32__", "103", 1},
416 {"avr16ea48", "__AVR_AVR16EA48__", "103", 1},
417 {"avr32ea28", "__AVR_AVR32EA28__", "103", 1},
418 {"avr32ea32", "__AVR_AVR32EA32__", "103", 1},
419 {"avr32ea48", "__AVR_AVR32EA48__", "103", 1},
420 {"avr32sd20", "__AVR_AVR32SD20__", "103", 1},
421 {"avr32sd28", "__AVR_AVR32SD28__", "103", 1},
422 {"avr32sd32", "__AVR_AVR32SD32__", "103", 1},
423 {"avr128da28", "__AVR_AVR128DA28__", "104", 2},
424 {"avr128da32", "__AVR_AVR128DA32__", "104", 2},
425 {"avr128da48", "__AVR_AVR128DA48__", "104", 2},
426 {"avr128da64", "__AVR_AVR128DA64__", "104", 2},
427 {"avr128db28", "__AVR_AVR128DB28__", "104", 2},
428 {"avr128db32", "__AVR_AVR128DB32__", "104", 2},
429 {"avr128db48", "__AVR_AVR128DB48__", "104", 2},
430 {"avr128db64", "__AVR_AVR128DB64__", "104", 2},
431};
432
433} // namespace targets
434} // namespace clang
435
436static bool ArchHasELPM(StringRef Arch) {
437 return llvm::StringSwitch<bool>(Arch)
438 .Cases({"31", "51", "6"}, true)
439 .Cases({"102", "104", "105", "106", "107"}, true)
440 .Default(false);
441}
442
443static bool ArchHasELPMX(StringRef Arch) {
444 return llvm::StringSwitch<bool>(Arch)
445 .Cases({"51", "6"}, true)
446 .Cases({"102", "104", "105", "106", "107"}, true)
447 .Default(false);
448}
449
450static bool ArchHasMOVW(StringRef Arch) {
451 return llvm::StringSwitch<bool>(Arch)
452 .Cases({"25", "35", "4", "5", "51", "6"}, true)
453 .Cases({"102", "103", "104", "105", "106", "107"}, true)
454 .Default(false);
455}
456
457static bool ArchHasLPMX(StringRef Arch) {
458 return ArchHasMOVW(Arch); // same architectures
459}
460
461static bool ArchHasMUL(StringRef Arch) {
462 return llvm::StringSwitch<bool>(Arch)
463 .Cases({"4", "5", "51", "6"}, true)
464 .Cases({"102", "103", "104", "105", "106", "107"}, true)
465 .Default(false);
466}
467
468static bool ArchHasJMPCALL(StringRef Arch) {
469 return llvm::StringSwitch<bool>(Arch)
470 .Cases({"3", "31", "35", "5", "51", "6"}, true)
471 .Cases({"102", "103", "104", "105", "106", "107"}, true)
472 .Default(false);
473}
474
475static bool ArchHas3BytePC(StringRef Arch) {
476 // These devices have more than 128kB of program memory.
477 // Note:
478 // - Not fully correct for arch 106: only about half the chips have more
479 // than 128kB program memory and therefore a 3 byte PC.
480 // - Doesn't match GCC entirely: avr-gcc thinks arch 107 goes beyond 128kB
481 // but in fact it doesn't.
482 return llvm::StringSwitch<bool>(Arch)
483 .Case("6", true)
484 .Case("106", true)
485 .Default(false);
486}
487
488bool AVRTargetInfo::isValidCPUName(StringRef Name) const {
489 return llvm::any_of(AVRMcus,
490 [&](const MCUInfo &Info) { return Info.Name == Name; });
491}
492
497
499 for (const MCUInfo &Info : AVRMcus)
500 Values.push_back(Info.Name);
501}
502
503bool AVRTargetInfo::setCPU(StringRef Name) {
504 // Set the ABI field based on the device or family name.
505 auto It = llvm::find_if(
506 AVRMcus, [&](const MCUInfo &Info) { return Info.Name == Name; });
507 if (It != std::end(AVRMcus)) {
508 CPU = Name;
509 ABI = (It->Arch == "100") ? "avrtiny" : "avr";
510 DefineName = It->DefineName;
511 Arch = It->Arch;
512 NumFlashBanks = It->NumFlashBanks;
513 return true;
514 }
515
516 // Parameter Name is neither valid family name nor valid device name.
517 return false;
518}
519
520std::optional<std::string>
522 switch (EscChar) {
523 // "%~" represents for 'r' depends on the device has long jump/call.
524 case '~':
525 return ArchHasJMPCALL(Arch) ? std::string("") : std::string(1, 'r');
526
527 // "%!" represents for 'e' depends on the PC register size.
528 case '!':
529 return ArchHas3BytePC(Arch) ? std::string(1, 'e') : std::string("");
530
531 // This is an invalid escape character for AVR.
532 default:
533 return std::nullopt;
534 }
535}
536
538 MacroBuilder &Builder) const {
539 Builder.defineMacro("AVR");
540 Builder.defineMacro("__AVR");
541 Builder.defineMacro("__AVR__");
542
543 if (ABI == "avrtiny")
544 Builder.defineMacro("__AVR_TINY__", "1");
545
546 if (DefineName.size() != 0)
547 Builder.defineMacro(DefineName);
548
549 Builder.defineMacro("__AVR_ARCH__", Arch);
550
551 // TODO: perhaps we should use the information from AVRDevices.td instead?
552 if (ArchHasELPM(Arch))
553 Builder.defineMacro("__AVR_HAVE_ELPM__");
554 if (ArchHasELPMX(Arch))
555 Builder.defineMacro("__AVR_HAVE_ELPMX__");
556 if (ArchHasMOVW(Arch))
557 Builder.defineMacro("__AVR_HAVE_MOVW__");
558 if (ArchHasLPMX(Arch))
559 Builder.defineMacro("__AVR_HAVE_LPMX__");
560 if (ArchHasMUL(Arch))
561 Builder.defineMacro("__AVR_HAVE_MUL__");
562 if (ArchHasJMPCALL(Arch))
563 Builder.defineMacro("__AVR_HAVE_JMP_CALL__");
564 if (ArchHas3BytePC(Arch)) {
565 // Note: some devices do support eijmp/eicall even though this macro isn't
566 // set. This is the case if they have less than 128kB flash and so
567 // eijmp/eicall isn't very useful anyway. (This matches gcc, although it's
568 // debatable whether we should be bug-compatible in this case).
569 Builder.defineMacro("__AVR_HAVE_EIJMP_EICALL__");
570 Builder.defineMacro("__AVR_3_BYTE_PC__");
571 } else {
572 Builder.defineMacro("__AVR_2_BYTE_PC__");
573 }
574
575 if (NumFlashBanks >= 1)
576 Builder.defineMacro("__flash", "__attribute__((__address_space__(1)))");
577 if (NumFlashBanks >= 2)
578 Builder.defineMacro("__flash1", "__attribute__((__address_space__(2)))");
579 if (NumFlashBanks >= 3)
580 Builder.defineMacro("__flash2", "__attribute__((__address_space__(3)))");
581 if (NumFlashBanks >= 4)
582 Builder.defineMacro("__flash3", "__attribute__((__address_space__(4)))");
583 if (NumFlashBanks >= 5)
584 Builder.defineMacro("__flash4", "__attribute__((__address_space__(5)))");
585 if (NumFlashBanks >= 6)
586 Builder.defineMacro("__flash5", "__attribute__((__address_space__(6)))");
587
588 // Define macros for builtins
589 Builder.defineMacro("__BUILTIN_AVR_NOP", "1");
590 Builder.defineMacro("__BUILTIN_AVR_SEI", "1");
591 Builder.defineMacro("__BUILTIN_AVR_CLI", "1");
592 Builder.defineMacro("__BUILTIN_AVR_WDR", "1");
593 Builder.defineMacro("__BUILTIN_AVR_SLEEP", "1");
594 Builder.defineMacro("__BUILTIN_AVR_SWAP", "1");
595}
static bool ArchHasMOVW(StringRef Arch)
Definition AVR.cpp:450
static bool ArchHas3BytePC(StringRef Arch)
Definition AVR.cpp:475
static bool ArchHasJMPCALL(StringRef Arch)
Definition AVR.cpp:468
static bool ArchHasELPMX(StringRef Arch)
Definition AVR.cpp:443
static bool ArchHasLPMX(StringRef Arch)
Definition AVR.cpp:457
static bool ArchHasELPM(StringRef Arch)
Definition AVR.cpp:436
static bool ArchHasMUL(StringRef Arch)
Definition AVR.cpp:461
static constexpr llvm::StringTable BuiltinStrings
Definition Mips.cpp:25
static constexpr Builtin::Info BuiltinInfos[]
Definition Builtins.cpp:39
static constexpr unsigned NumBuiltins
Definition Builtins.cpp:33
Defines enum values for all the target-independent builtin functions.
Defines the clang::MacroBuilder utility class.
Enumerates target-specific builtins in their own namespaces within namespace clang.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
std::optional< std::string > handleAsmEscapedChar(char EscChar) const override
Replace some escaped characters with another string based on target-specific rules.
Definition AVR.cpp:521
void fillValidCPUList(SmallVectorImpl< StringRef > &Values) const override
Fill a SmallVectorImpl with the valid values to setCPU.
Definition AVR.cpp:498
bool isValidCPUName(StringRef Name) const override
Determine whether this TargetInfo supports the given CPU name.
Definition AVR.cpp:488
llvm::SmallVector< Builtin::InfosShard > getTargetBuiltins() const override
Return information about target-specific builtins for the current primary target, and info about whic...
Definition AVR.cpp:494
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
===-— Other target property query methods -----------------------—===//
Definition AVR.cpp:537
bool setCPU(StringRef Name) override
Target the specified CPU.
Definition AVR.cpp:503
static const MCUInfo AVRMcus[]
Definition AVR.cpp:47
Top level wrappers for InstallAPI frontend operations.
@ Default
Set to the current date and time.
The info used to represent each builtin.
Definition Builtins.h:82
Information about a specific microcontroller.
Definition AVR.cpp:39
const char * DefineName
Definition AVR.cpp:41
const int NumFlashBanks
Definition AVR.cpp:43
const char * Name
Definition AVR.cpp:40