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