Index: clang/lib/Basic/Targets/AVR.h =================================================================== --- clang/lib/Basic/Targets/AVR.h +++ clang/lib/Basic/Targets/AVR.h @@ -18,6 +18,8 @@ #include "llvm/ADT/Triple.h" #include "llvm/Support/Compiler.h" +#include "llvm/Support/AVRTargetParser.h" + namespace clang { namespace targets { @@ -165,10 +167,9 @@ : TargetInfo::getLeastIntTypeByWidth(BitWidth, IsSigned); } - bool isValidCPUName(StringRef Name) const override; void fillValidCPUList(SmallVectorImpl &Values) const override; bool setCPU(const std::string &Name) override { - bool isValid = isValidCPUName(Name); + bool isValid = llvm::AVR::isValidCPUName(Name); if (isValid) CPU = Name; return isValid; Index: clang/lib/Basic/Targets/AVR.cpp =================================================================== --- clang/lib/Basic/Targets/AVR.cpp +++ clang/lib/Basic/Targets/AVR.cpp @@ -12,7 +12,6 @@ #include "AVR.h" #include "clang/Basic/MacroBuilder.h" -#include "llvm/ADT/StringSwitch.h" using namespace clang; using namespace clang::targets; @@ -20,279 +19,8 @@ namespace clang { namespace targets { -/// Information about a specific microcontroller. -struct LLVM_LIBRARY_VISIBILITY MCUInfo { - const char *Name; - const char *DefineName; -}; - -// This list should be kept up-to-date with AVRDevices.td in LLVM. -static MCUInfo AVRMcus[] = { - {"at90s1200", "__AVR_AT90S1200__"}, - {"attiny11", "__AVR_ATtiny11__"}, - {"attiny12", "__AVR_ATtiny12__"}, - {"attiny15", "__AVR_ATtiny15__"}, - {"attiny28", "__AVR_ATtiny28__"}, - {"at90s2313", "__AVR_AT90S2313__"}, - {"at90s2323", "__AVR_AT90S2323__"}, - {"at90s2333", "__AVR_AT90S2333__"}, - {"at90s2343", "__AVR_AT90S2343__"}, - {"attiny22", "__AVR_ATtiny22__"}, - {"attiny26", "__AVR_ATtiny26__"}, - {"at86rf401", "__AVR_AT86RF401__"}, - {"at90s4414", "__AVR_AT90S4414__"}, - {"at90s4433", "__AVR_AT90S4433__"}, - {"at90s4434", "__AVR_AT90S4434__"}, - {"at90s8515", "__AVR_AT90S8515__"}, - {"at90c8534", "__AVR_AT90c8534__"}, - {"at90s8535", "__AVR_AT90S8535__"}, - {"ata5272", "__AVR_ATA5272__"}, - {"attiny13", "__AVR_ATtiny13__"}, - {"attiny13a", "__AVR_ATtiny13A__"}, - {"attiny2313", "__AVR_ATtiny2313__"}, - {"attiny2313a", "__AVR_ATtiny2313A__"}, - {"attiny24", "__AVR_ATtiny24__"}, - {"attiny24a", "__AVR_ATtiny24A__"}, - {"attiny4313", "__AVR_ATtiny4313__"}, - {"attiny44", "__AVR_ATtiny44__"}, - {"attiny44a", "__AVR_ATtiny44A__"}, - {"attiny84", "__AVR_ATtiny84__"}, - {"attiny84a", "__AVR_ATtiny84A__"}, - {"attiny25", "__AVR_ATtiny25__"}, - {"attiny45", "__AVR_ATtiny45__"}, - {"attiny85", "__AVR_ATtiny85__"}, - {"attiny261", "__AVR_ATtiny261__"}, - {"attiny261a", "__AVR_ATtiny261A__"}, - {"attiny461", "__AVR_ATtiny461__"}, - {"attiny461a", "__AVR_ATtiny461A__"}, - {"attiny861", "__AVR_ATtiny861__"}, - {"attiny861a", "__AVR_ATtiny861A__"}, - {"attiny87", "__AVR_ATtiny87__"}, - {"attiny43u", "__AVR_ATtiny43U__"}, - {"attiny48", "__AVR_ATtiny48__"}, - {"attiny88", "__AVR_ATtiny88__"}, - {"attiny828", "__AVR_ATtiny828__"}, - {"at43usb355", "__AVR_AT43USB355__"}, - {"at76c711", "__AVR_AT76C711__"}, - {"atmega103", "__AVR_ATmega103__"}, - {"at43usb320", "__AVR_AT43USB320__"}, - {"attiny167", "__AVR_ATtiny167__"}, - {"at90usb82", "__AVR_AT90USB82__"}, - {"at90usb162", "__AVR_AT90USB162__"}, - {"ata5505", "__AVR_ATA5505__"}, - {"atmega8u2", "__AVR_ATmega8U2__"}, - {"atmega16u2", "__AVR_ATmega16U2__"}, - {"atmega32u2", "__AVR_ATmega32U2__"}, - {"attiny1634", "__AVR_ATtiny1634__"}, - {"atmega8", "__AVR_ATmega8__"}, - {"ata6289", "__AVR_ATA6289__"}, - {"atmega8a", "__AVR_ATmega8A__"}, - {"ata6285", "__AVR_ATA6285__"}, - {"ata6286", "__AVR_ATA6286__"}, - {"atmega48", "__AVR_ATmega48__"}, - {"atmega48a", "__AVR_ATmega48A__"}, - {"atmega48pa", "__AVR_ATmega48PA__"}, - {"atmega48p", "__AVR_ATmega48P__"}, - {"atmega88", "__AVR_ATmega88__"}, - {"atmega88a", "__AVR_ATmega88A__"}, - {"atmega88p", "__AVR_ATmega88P__"}, - {"atmega88pa", "__AVR_ATmega88PA__"}, - {"atmega8515", "__AVR_ATmega8515__"}, - {"atmega8535", "__AVR_ATmega8535__"}, - {"atmega8hva", "__AVR_ATmega8HVA__"}, - {"at90pwm1", "__AVR_AT90PWM1__"}, - {"at90pwm2", "__AVR_AT90PWM2__"}, - {"at90pwm2b", "__AVR_AT90PWM2B__"}, - {"at90pwm3", "__AVR_AT90PWM3__"}, - {"at90pwm3b", "__AVR_AT90PWM3B__"}, - {"at90pwm81", "__AVR_AT90PWM81__"}, - {"ata5790", "__AVR_ATA5790__"}, - {"ata5795", "__AVR_ATA5795__"}, - {"atmega16", "__AVR_ATmega16__"}, - {"atmega16a", "__AVR_ATmega16A__"}, - {"atmega161", "__AVR_ATmega161__"}, - {"atmega162", "__AVR_ATmega162__"}, - {"atmega163", "__AVR_ATmega163__"}, - {"atmega164a", "__AVR_ATmega164A__"}, - {"atmega164p", "__AVR_ATmega164P__"}, - {"atmega164pa", "__AVR_ATmega164PA__"}, - {"atmega165", "__AVR_ATmega165__"}, - {"atmega165a", "__AVR_ATmega165A__"}, - {"atmega165p", "__AVR_ATmega165P__"}, - {"atmega165pa", "__AVR_ATmega165PA__"}, - {"atmega168", "__AVR_ATmega168__"}, - {"atmega168a", "__AVR_ATmega168A__"}, - {"atmega168p", "__AVR_ATmega168P__"}, - {"atmega168pa", "__AVR_ATmega168PA__"}, - {"atmega169", "__AVR_ATmega169__"}, - {"atmega169a", "__AVR_ATmega169A__"}, - {"atmega169p", "__AVR_ATmega169P__"}, - {"atmega169pa", "__AVR_ATmega169PA__"}, - {"atmega32", "__AVR_ATmega32__"}, - {"atmega32a", "__AVR_ATmega32A__"}, - {"atmega323", "__AVR_ATmega323__"}, - {"atmega324a", "__AVR_ATmega324A__"}, - {"atmega324p", "__AVR_ATmega324P__"}, - {"atmega324pa", "__AVR_ATmega324PA__"}, - {"atmega325", "__AVR_ATmega325__"}, - {"atmega325a", "__AVR_ATmega325A__"}, - {"atmega325p", "__AVR_ATmega325P__"}, - {"atmega325pa", "__AVR_ATmega325PA__"}, - {"atmega3250", "__AVR_ATmega3250__"}, - {"atmega3250a", "__AVR_ATmega3250A__"}, - {"atmega3250p", "__AVR_ATmega3250P__"}, - {"atmega3250pa", "__AVR_ATmega3250PA__"}, - {"atmega328", "__AVR_ATmega328__"}, - {"atmega328p", "__AVR_ATmega328P__"}, - {"atmega329", "__AVR_ATmega329__"}, - {"atmega329a", "__AVR_ATmega329A__"}, - {"atmega329p", "__AVR_ATmega329P__"}, - {"atmega329pa", "__AVR_ATmega329PA__"}, - {"atmega3290", "__AVR_ATmega3290__"}, - {"atmega3290a", "__AVR_ATmega3290A__"}, - {"atmega3290p", "__AVR_ATmega3290P__"}, - {"atmega3290pa", "__AVR_ATmega3290PA__"}, - {"atmega406", "__AVR_ATmega406__"}, - {"atmega64", "__AVR_ATmega64__"}, - {"atmega64a", "__AVR_ATmega64A__"}, - {"atmega640", "__AVR_ATmega640__"}, - {"atmega644", "__AVR_ATmega644__"}, - {"atmega644a", "__AVR_ATmega644A__"}, - {"atmega644p", "__AVR_ATmega644P__"}, - {"atmega644pa", "__AVR_ATmega644PA__"}, - {"atmega645", "__AVR_ATmega645__"}, - {"atmega645a", "__AVR_ATmega645A__"}, - {"atmega645p", "__AVR_ATmega645P__"}, - {"atmega649", "__AVR_ATmega649__"}, - {"atmega649a", "__AVR_ATmega649A__"}, - {"atmega649p", "__AVR_ATmega649P__"}, - {"atmega6450", "__AVR_ATmega6450__"}, - {"atmega6450a", "__AVR_ATmega6450A__"}, - {"atmega6450p", "__AVR_ATmega6450P__"}, - {"atmega6490", "__AVR_ATmega6490__"}, - {"atmega6490a", "__AVR_ATmega6490A__"}, - {"atmega6490p", "__AVR_ATmega6490P__"}, - {"atmega64rfr2", "__AVR_ATmega64RFR2__"}, - {"atmega644rfr2", "__AVR_ATmega644RFR2__"}, - {"atmega16hva", "__AVR_ATmega16HVA__"}, - {"atmega16hva2", "__AVR_ATmega16HVA2__"}, - {"atmega16hvb", "__AVR_ATmega16HVB__"}, - {"atmega16hvbrevb", "__AVR_ATmega16HVBREVB__"}, - {"atmega32hvb", "__AVR_ATmega32HVB__"}, - {"atmega32hvbrevb", "__AVR_ATmega32HVBREVB__"}, - {"atmega64hve", "__AVR_ATmega64HVE__"}, - {"at90can32", "__AVR_AT90CAN32__"}, - {"at90can64", "__AVR_AT90CAN64__"}, - {"at90pwm161", "__AVR_AT90PWM161__"}, - {"at90pwm216", "__AVR_AT90PWM216__"}, - {"at90pwm316", "__AVR_AT90PWM316__"}, - {"atmega32c1", "__AVR_ATmega32C1__"}, - {"atmega64c1", "__AVR_ATmega64C1__"}, - {"atmega16m1", "__AVR_ATmega16M1__"}, - {"atmega32m1", "__AVR_ATmega32M1__"}, - {"atmega64m1", "__AVR_ATmega64M1__"}, - {"atmega16u4", "__AVR_ATmega16U4__"}, - {"atmega32u4", "__AVR_ATmega32U4__"}, - {"atmega32u6", "__AVR_ATmega32U6__"}, - {"at90usb646", "__AVR_AT90USB646__"}, - {"at90usb647", "__AVR_AT90USB647__"}, - {"at90scr100", "__AVR_AT90SCR100__"}, - {"at94k", "__AVR_AT94K__"}, - {"m3000", "__AVR_AT000__"}, - {"atmega128", "__AVR_ATmega128__"}, - {"atmega128a", "__AVR_ATmega128A__"}, - {"atmega1280", "__AVR_ATmega1280__"}, - {"atmega1281", "__AVR_ATmega1281__"}, - {"atmega1284", "__AVR_ATmega1284__"}, - {"atmega1284p", "__AVR_ATmega1284P__"}, - {"atmega128rfa1", "__AVR_ATmega128RFA1__"}, - {"atmega128rfr2", "__AVR_ATmega128RFR2__"}, - {"atmega1284rfr2", "__AVR_ATmega1284RFR2__"}, - {"at90can128", "__AVR_AT90CAN128__"}, - {"at90usb1286", "__AVR_AT90USB1286__"}, - {"at90usb1287", "__AVR_AT90USB1287__"}, - {"atmega2560", "__AVR_ATmega2560__"}, - {"atmega2561", "__AVR_ATmega2561__"}, - {"atmega256rfr2", "__AVR_ATmega256RFR2__"}, - {"atmega2564rfr2", "__AVR_ATmega2564RFR2__"}, - {"atxmega16a4", "__AVR_ATxmega16A4__"}, - {"atxmega16a4u", "__AVR_ATxmega16a4U__"}, - {"atxmega16c4", "__AVR_ATxmega16C4__"}, - {"atxmega16d4", "__AVR_ATxmega16D4__"}, - {"atxmega32a4", "__AVR_ATxmega32A4__"}, - {"atxmega32a4u", "__AVR_ATxmega32A4U__"}, - {"atxmega32c4", "__AVR_ATxmega32C4__"}, - {"atxmega32d4", "__AVR_ATxmega32D4__"}, - {"atxmega32e5", "__AVR_ATxmega32E5__"}, - {"atxmega16e5", "__AVR_ATxmega16E5__"}, - {"atxmega8e5", "__AVR_ATxmega8E5__"}, - {"atxmega32x1", "__AVR_ATxmega32X1__"}, - {"atxmega64a3", "__AVR_ATxmega64A3__"}, - {"atxmega64a3u", "__AVR_ATxmega64A3U__"}, - {"atxmega64a4u", "__AVR_ATxmega64A4U__"}, - {"atxmega64b1", "__AVR_ATxmega64B1__"}, - {"atxmega64b3", "__AVR_ATxmega64B3__"}, - {"atxmega64c3", "__AVR_ATxmega64C3__"}, - {"atxmega64d3", "__AVR_ATxmega64D3__"}, - {"atxmega64d4", "__AVR_ATxmega64D4__"}, - {"atxmega64a1", "__AVR_ATxmega64A1__"}, - {"atxmega64a1u", "__AVR_ATxmega64A1U__"}, - {"atxmega128a3", "__AVR_ATxmega128A3__"}, - {"atxmega128a3u", "__AVR_ATxmega128A3U__"}, - {"atxmega128b1", "__AVR_ATxmega128B1__"}, - {"atxmega128b3", "__AVR_ATxmega128B3__"}, - {"atxmega128c3", "__AVR_ATxmega128C3__"}, - {"atxmega128d3", "__AVR_ATxmega128D3__"}, - {"atxmega128d4", "__AVR_ATxmega128D4__"}, - {"atxmega192a3", "__AVR_ATxmega192A3__"}, - {"atxmega192a3u", "__AVR_ATxmega192A3U__"}, - {"atxmega192c3", "__AVR_ATxmega192C3__"}, - {"atxmega192d3", "__AVR_ATxmega192D3__"}, - {"atxmega256a3", "__AVR_ATxmega256A3__"}, - {"atxmega256a3u", "__AVR_ATxmega256A3U__"}, - {"atxmega256a3b", "__AVR_ATxmega256A3B__"}, - {"atxmega256a3bu", "__AVR_ATxmega256A3BU__"}, - {"atxmega256c3", "__AVR_ATxmega256C3__"}, - {"atxmega256d3", "__AVR_ATxmega256D3__"}, - {"atxmega384c3", "__AVR_ATxmega384C3__"}, - {"atxmega384d3", "__AVR_ATxmega384D3__"}, - {"atxmega128a1", "__AVR_ATxmega128A1__"}, - {"atxmega128a1u", "__AVR_ATxmega128A1U__"}, - {"atxmega128a4u", "__AVR_ATxmega128a4U__"}, - {"attiny4", "__AVR_ATtiny4__"}, - {"attiny5", "__AVR_ATtiny5__"}, - {"attiny9", "__AVR_ATtiny9__"}, - {"attiny10", "__AVR_ATtiny10__"}, - {"attiny20", "__AVR_ATtiny20__"}, - {"attiny40", "__AVR_ATtiny40__"}, - {"attiny102", "__AVR_ATtiny102__"}, - {"attiny104", "__AVR_ATtiny104__"}, -}; - -} // namespace targets -} // namespace clang - -static constexpr llvm::StringLiteral ValidFamilyNames[] = { - "avr1", "avr2", "avr25", "avr3", "avr31", - "avr35", "avr4", "avr5", "avr51", "avr6", - "avrxmega1", "avrxmega2", "avrxmega3", "avrxmega4", "avrxmega5", - "avrxmega6", "avrxmega7", "avrtiny"}; - -bool AVRTargetInfo::isValidCPUName(StringRef Name) const { - bool IsFamily = - llvm::find(ValidFamilyNames, Name) != std::end(ValidFamilyNames); - - bool IsMCU = - llvm::find_if(AVRMcus, [&](const MCUInfo &Info) { - return Info.Name == Name; - }) != std::end(AVRMcus); - return IsFamily || IsMCU; -} - void AVRTargetInfo::fillValidCPUList(SmallVectorImpl &Values) const { - Values.append(std::begin(ValidFamilyNames), std::end(ValidFamilyNames)); - for (const MCUInfo &Info : AVRMcus) - Values.push_back(Info.Name); + llvm::AVR::fillValidCPUList(Values); } void AVRTargetInfo::getTargetDefines(const LangOptions &Opts, @@ -301,11 +29,17 @@ Builder.defineMacro("__AVR"); Builder.defineMacro("__AVR__"); - if (!this->CPU.empty()) { - auto It = llvm::find_if( - AVRMcus, [&](const MCUInfo &Info) { return Info.Name == this->CPU; }); + auto Family = llvm::AVR::getFamilyName(CPU); + if (Family.hasValue()) { + auto FamilyInfo = llvm::AVR::getFamilyInfo(Family.getValue()); + Builder.defineMacro("__AVR_ARCH__", Twine(FamilyInfo.Number)); + } - if (It != std::end(AVRMcus)) - Builder.defineMacro(It->DefineName); + auto MCUDefine = llvm::AVR::getMCUDefine(CPU); + if (MCUDefine.hasValue()) { + Builder.defineMacro(MCUDefine.getValue()); } } + +} // namespace targets +} // namespace clang Index: clang/lib/Driver/ToolChains/AVR.cpp =================================================================== --- clang/lib/Driver/ToolChains/AVR.cpp +++ clang/lib/Driver/ToolChains/AVR.cpp @@ -17,6 +17,7 @@ #include "llvm/MC/MCSubtargetInfo.h" #include "llvm/MC/SubtargetFeature.h" #include "llvm/Option/ArgList.h" +#include "llvm/Support/AVRTargetParser.h" #include "llvm/Support/FileSystem.h" using namespace clang::driver; @@ -27,15 +28,6 @@ namespace { -// TODO: Consider merging this into the AVR device table -// array in Targets/AVR.cpp. -llvm::Optional GetMcuFamilyName(StringRef MCU) { - return llvm::StringSwitch>(MCU) - .Case("atmega328", Optional("avr5")) - .Case("atmega328p", Optional("avr5")) - .Default(Optional()); -} - const StringRef PossibleAVRLibcLocations[] = { "/usr/avr", "/usr/lib/avr", @@ -59,7 +51,7 @@ // We cannot link any standard libraries without an MCU specified. D.Diag(diag::warn_drv_avr_mcu_not_specified); } else { - Optional FamilyName = GetMcuFamilyName(CPU); + Optional FamilyName = llvm::AVR::getFamilyName(CPU); Optional AVRLibcRoot = findAVRLibcInstallation(); if (!FamilyName.hasValue()) { @@ -104,7 +96,7 @@ const char *LinkingOutput) const { // Compute information about the target AVR. std::string CPU = getCPUName(Args, getToolChain().getTriple()); - llvm::Optional FamilyName = GetMcuFamilyName(CPU); + llvm::Optional FamilyName = llvm::AVR::getFamilyName(CPU); std::string Linker = getToolChain().GetProgramPath(getShortName()); ArgStringList CmdArgs; Index: llvm/include/llvm/Support/AVRTargetParser.h =================================================================== --- /dev/null +++ llvm/include/llvm/Support/AVRTargetParser.h @@ -0,0 +1,38 @@ +//===-- AVRTargetParser - Parser for AVR target features --------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file implements a target parser to recognise AVR CPUs +// +//===----------------------------------------------------------------------===// + +#include "llvm/ADT/StringRef.h" + +namespace llvm { +namespace AVR { + +struct MCUInfo { + const char *Family; + const char *Name; + const char *DefineName; +}; + +struct FamilyInfo { + const char *Name; + int Number; +}; + +Optional getMCUDefine(StringRef CPU); + +Optional getFamilyName(StringRef CPU); +FamilyInfo getFamilyInfo(StringRef Family); + +bool isValidCPUName(StringRef CPU); + +void fillValidCPUList(SmallVectorImpl &Values); +} // namespace AVR +} // namespace llvm Index: llvm/lib/Support/AVRTargetParser.cpp =================================================================== --- /dev/null +++ llvm/lib/Support/AVRTargetParser.cpp @@ -0,0 +1,317 @@ +//===-- AVRTargetParser - Parser for AVR target features --------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This file implements a target parser to recognise AVR CPUs +// +//===----------------------------------------------------------------------===// + +#include "llvm/Support/AVRTargetParser.h" + +#include "llvm/ADT/SmallVector.h" + +using namespace llvm; + +// This list should be kept up-to-date with AVRDevices.td in LLVM. +static constexpr AVR::MCUInfo AVRMcus[] = { + {"avr1", "at90s1200", "__AVR_AT90S1200__"}, + {"avr1", "attiny11", "__AVR_ATtiny11__"}, + {"avr1", "attiny12", "__AVR_ATtiny12__"}, + {"avr1", "attiny15", "__AVR_ATtiny15__"}, + {"avr1", "attiny28", "__AVR_ATtiny28__"}, + {"avr2", "at90s2313", "__AVR_AT90S2313__"}, + {"avr2", "at90s2323", "__AVR_AT90S2323__"}, + {"avr2", "at90s2333", "__AVR_AT90S2333__"}, + {"avr2", "at90s2343", "__AVR_AT90S2343__"}, + {"avr2", "attiny22", "__AVR_ATtiny22__"}, + {"avr2", "attiny26", "__AVR_ATtiny26__"}, + {"avr25", "at86rf401", "__AVR_AT86RF401__"}, + {"avr2", "at90s4414", "__AVR_AT90S4414__"}, + {"avr2", "at90s4433", "__AVR_AT90S4433__"}, + {"avr2", "at90s4434", "__AVR_AT90S4434__"}, + {"avr2", "at90s8515", "__AVR_AT90S8515__"}, + {"avr2", "at90c8534", "__AVR_AT90c8534__"}, + {"avr2", "at90s8535", "__AVR_AT90S8535__"}, + {"avr25", "ata5272", "__AVR_ATA5272__"}, + {"avr25", "attiny13", "__AVR_ATtiny13__"}, + {"avr25", "attiny13a", "__AVR_ATtiny13A__"}, + {"avr25", "attiny2313", "__AVR_ATtiny2313__"}, + {"avr25", "attiny2313a", "__AVR_ATtiny2313A__"}, + {"avr25", "attiny24", "__AVR_ATtiny24__"}, + {"avr25", "attiny24a", "__AVR_ATtiny24A__"}, + {"avr25", "attiny4313", "__AVR_ATtiny4313__"}, + {"avr25", "attiny44", "__AVR_ATtiny44__"}, + {"avr25", "attiny44a", "__AVR_ATtiny44A__"}, + {"avr25", "attiny84", "__AVR_ATtiny84__"}, + {"avr25", "attiny84a", "__AVR_ATtiny84A__"}, + {"avr25", "attiny25", "__AVR_ATtiny25__"}, + {"avr25", "attiny45", "__AVR_ATtiny45__"}, + {"avr25", "attiny85", "__AVR_ATtiny85__"}, + {"avr25", "attiny261", "__AVR_ATtiny261__"}, + {"avr25", "attiny261a", "__AVR_ATtiny261A__"}, + {"avr25", "attiny461", "__AVR_ATtiny461__"}, + {"avr25", "attiny461a", "__AVR_ATtiny461A__"}, + {"avr25", "attiny861", "__AVR_ATtiny861__"}, + {"avr25", "attiny861a", "__AVR_ATtiny861A__"}, + {"avr25", "attiny87", "__AVR_ATtiny87__"}, + {"avr25", "attiny43u", "__AVR_ATtiny43U__"}, + {"avr25", "attiny48", "__AVR_ATtiny48__"}, + {"avr25", "attiny88", "__AVR_ATtiny88__"}, + {"avr25", "attiny828", "__AVR_ATtiny828__"}, + {"avr3", "at43usb355", "__AVR_AT43USB355__"}, + {"avr3", "at76c711", "__AVR_AT76C711__"}, + {"avr31", "atmega103", "__AVR_ATmega103__"}, + {"avr31", "at43usb320", "__AVR_AT43USB320__"}, + {"avr35", "attiny167", "__AVR_ATtiny167__"}, + {"avr35", "at90usb82", "__AVR_AT90USB82__"}, + {"avr35", "at90usb162", "__AVR_AT90USB162__"}, + {"avr35", "ata5505", "__AVR_ATA5505__"}, + {"avr35", "atmega8u2", "__AVR_ATmega8U2__"}, + {"avr35", "atmega16u2", "__AVR_ATmega16U2__"}, + {"avr35", "atmega32u2", "__AVR_ATmega32U2__"}, + {"avr35", "attiny1634", "__AVR_ATtiny1634__"}, + {"avr4", "atmega8", "__AVR_ATmega8__"}, + {"avr4", "ata6289", "__AVR_ATA6289__"}, + {"avr4", "atmega8a", "__AVR_ATmega8A__"}, + {"avr4", "ata6285", "__AVR_ATA6285__"}, + {"avr4", "ata6286", "__AVR_ATA6286__"}, + {"avr4", "atmega48", "__AVR_ATmega48__"}, + {"avr4", "atmega48a", "__AVR_ATmega48A__"}, + {"avr4", "atmega48pa", "__AVR_ATmega48PA__"}, + {"avr4", "atmega48p", "__AVR_ATmega48P__"}, + {"avr4", "atmega88", "__AVR_ATmega88__"}, + {"avr4", "atmega88a", "__AVR_ATmega88A__"}, + {"avr4", "atmega88p", "__AVR_ATmega88P__"}, + {"avr4", "atmega88pa", "__AVR_ATmega88PA__"}, + {"avr4", "atmega8515", "__AVR_ATmega8515__"}, + {"avr4", "atmega8535", "__AVR_ATmega8535__"}, + {"avr4", "atmega8hva", "__AVR_ATmega8HVA__"}, + {"avr4", "at90pwm1", "__AVR_AT90PWM1__"}, + {"avr4", "at90pwm2", "__AVR_AT90PWM2__"}, + {"avr4", "at90pwm2b", "__AVR_AT90PWM2B__"}, + {"avr4", "at90pwm3", "__AVR_AT90PWM3__"}, + {"avr4", "at90pwm3b", "__AVR_AT90PWM3B__"}, + {"avr4", "at90pwm81", "__AVR_AT90PWM81__"}, + {"avr5", "ata5790", "__AVR_ATA5790__"}, + {"avr5", "ata5795", "__AVR_ATA5795__"}, + {"avr5", "atmega16", "__AVR_ATmega16__"}, + {"avr5", "atmega16a", "__AVR_ATmega16A__"}, + {"avr5", "atmega161", "__AVR_ATmega161__"}, + {"avr5", "atmega162", "__AVR_ATmega162__"}, + {"avr5", "atmega163", "__AVR_ATmega163__"}, + {"avr5", "atmega164a", "__AVR_ATmega164A__"}, + {"avr5", "atmega164p", "__AVR_ATmega164P__"}, + {"avr5", "atmega164pa", "__AVR_ATmega164PA__"}, + {"avr5", "atmega165", "__AVR_ATmega165__"}, + {"avr5", "atmega165a", "__AVR_ATmega165A__"}, + {"avr5", "atmega165p", "__AVR_ATmega165P__"}, + {"avr5", "atmega165pa", "__AVR_ATmega165PA__"}, + {"avr5", "atmega168", "__AVR_ATmega168__"}, + {"avr5", "atmega168a", "__AVR_ATmega168A__"}, + {"avr5", "atmega168p", "__AVR_ATmega168P__"}, + {"avr5", "atmega168pa", "__AVR_ATmega168PA__"}, + {"avr5", "atmega169", "__AVR_ATmega169__"}, + {"avr5", "atmega169a", "__AVR_ATmega169A__"}, + {"avr5", "atmega169p", "__AVR_ATmega169P__"}, + {"avr5", "atmega169pa", "__AVR_ATmega169PA__"}, + {"avr5", "atmega32", "__AVR_ATmega32__"}, + {"avr5", "atmega32a", "__AVR_ATmega32A__"}, + {"avr5", "atmega323", "__AVR_ATmega323__"}, + {"avr5", "atmega324a", "__AVR_ATmega324A__"}, + {"avr5", "atmega324p", "__AVR_ATmega324P__"}, + {"avr5", "atmega324pa", "__AVR_ATmega324PA__"}, + {"avr5", "atmega325", "__AVR_ATmega325__"}, + {"avr5", "atmega325a", "__AVR_ATmega325A__"}, + {"avr5", "atmega325p", "__AVR_ATmega325P__"}, + {"avr5", "atmega325pa", "__AVR_ATmega325PA__"}, + {"avr5", "atmega3250", "__AVR_ATmega3250__"}, + {"avr5", "atmega3250a", "__AVR_ATmega3250A__"}, + {"avr5", "atmega3250p", "__AVR_ATmega3250P__"}, + {"avr5", "atmega3250pa", "__AVR_ATmega3250PA__"}, + {"avr5", "atmega328", "__AVR_ATmega328__"}, + {"avr5", "atmega328p", "__AVR_ATmega328P__"}, + {"avr5", "atmega329", "__AVR_ATmega329__"}, + {"avr5", "atmega329a", "__AVR_ATmega329A__"}, + {"avr5", "atmega329p", "__AVR_ATmega329P__"}, + {"avr5", "atmega329pa", "__AVR_ATmega329PA__"}, + {"avr5", "atmega3290", "__AVR_ATmega3290__"}, + {"avr5", "atmega3290a", "__AVR_ATmega3290A__"}, + {"avr5", "atmega3290p", "__AVR_ATmega3290P__"}, + {"avr5", "atmega3290pa", "__AVR_ATmega3290PA__"}, + {"avr5", "atmega406", "__AVR_ATmega406__"}, + {"avr5", "atmega64", "__AVR_ATmega64__"}, + {"avr5", "atmega64a", "__AVR_ATmega64A__"}, + {"avr5", "atmega640", "__AVR_ATmega640__"}, + {"avr5", "atmega644", "__AVR_ATmega644__"}, + {"avr5", "atmega644a", "__AVR_ATmega644A__"}, + {"avr5", "atmega644p", "__AVR_ATmega644P__"}, + {"avr5", "atmega644pa", "__AVR_ATmega644PA__"}, + {"avr5", "atmega645", "__AVR_ATmega645__"}, + {"avr5", "atmega645a", "__AVR_ATmega645A__"}, + {"avr5", "atmega645p", "__AVR_ATmega645P__"}, + {"avr5", "atmega649", "__AVR_ATmega649__"}, + {"avr5", "atmega649a", "__AVR_ATmega649A__"}, + {"avr5", "atmega649p", "__AVR_ATmega649P__"}, + {"avr5", "atmega6450", "__AVR_ATmega6450__"}, + {"avr5", "atmega6450a", "__AVR_ATmega6450A__"}, + {"avr5", "atmega6450p", "__AVR_ATmega6450P__"}, + {"avr5", "atmega6490", "__AVR_ATmega6490__"}, + {"avr5", "atmega6490a", "__AVR_ATmega6490A__"}, + {"avr5", "atmega6490p", "__AVR_ATmega6490P__"}, + {"avr5", "atmega64rfr2", "__AVR_ATmega64RFR2__"}, + {"avr5", "atmega644rfr2", "__AVR_ATmega644RFR2__"}, + {"avr5", "atmega16hva", "__AVR_ATmega16HVA__"}, + {"avr5", "atmega16hva2", "__AVR_ATmega16HVA2__"}, + {"avr5", "atmega16hvb", "__AVR_ATmega16HVB__"}, + {"avr5", "atmega16hvbrevb", "__AVR_ATmega16HVBREVB__"}, + {"avr5", "atmega32hvb", "__AVR_ATmega32HVB__"}, + {"avr5", "atmega32hvbrevb", "__AVR_ATmega32HVBREVB__"}, + {"avr5", "atmega64hve", "__AVR_ATmega64HVE__"}, + {"avr5", "at90can32", "__AVR_AT90CAN32__"}, + {"avr5", "at90can64", "__AVR_AT90CAN64__"}, + {"avr5", "at90pwm161", "__AVR_AT90PWM161__"}, + {"avr5", "at90pwm216", "__AVR_AT90PWM216__"}, + {"avr5", "at90pwm316", "__AVR_AT90PWM316__"}, + {"avr5", "atmega32c1", "__AVR_ATmega32C1__"}, + {"avr5", "atmega64c1", "__AVR_ATmega64C1__"}, + {"avr5", "atmega16m1", "__AVR_ATmega16M1__"}, + {"avr5", "atmega32m1", "__AVR_ATmega32M1__"}, + {"avr5", "atmega64m1", "__AVR_ATmega64M1__"}, + {"avr5", "atmega16u4", "__AVR_ATmega16U4__"}, + {"avr5", "atmega32u4", "__AVR_ATmega32U4__"}, + {"avr5", "atmega32u6", "__AVR_ATmega32U6__"}, + {"avr5", "at90usb646", "__AVR_AT90USB646__"}, + {"avr5", "at90usb647", "__AVR_AT90USB647__"}, + {"avr5", "at90scr100", "__AVR_AT90SCR100__"}, + {"avr5", "at94k", "__AVR_AT94K__"}, + {"avr5", "m3000", "__AVR_AT000__"}, + {"avr51", "atmega128", "__AVR_ATmega128__"}, + {"avr51", "atmega128a", "__AVR_ATmega128A__"}, + {"avr51", "atmega1280", "__AVR_ATmega1280__"}, + {"avr51", "atmega1281", "__AVR_ATmega1281__"}, + {"avr51", "atmega1284", "__AVR_ATmega1284__"}, + {"avr51", "atmega1284p", "__AVR_ATmega1284P__"}, + {"avr51", "atmega128rfa1", "__AVR_ATmega128RFA1__"}, + {"avr51", "atmega128rfr2", "__AVR_ATmega128RFR2__"}, + {"avr51", "atmega1284rfr2", "__AVR_ATmega1284RFR2__"}, + {"avr51", "at90can128", "__AVR_AT90CAN128__"}, + {"avr51", "at90usb1286", "__AVR_AT90USB1286__"}, + {"avr51", "at90usb1287", "__AVR_AT90USB1287__"}, + {"avr6", "atmega2560", "__AVR_ATmega2560__"}, + {"avr6", "atmega2561", "__AVR_ATmega2561__"}, + {"avr6", "atmega256rfr2", "__AVR_ATmega256RFR2__"}, + {"avr6", "atmega2564rfr2", "__AVR_ATmega2564RFR2__"}, + {"avrxmega2", "atxmega16a4", "__AVR_ATxmega16A4__"}, + {"avrxmega2", "atxmega16a4u", "__AVR_ATxmega16A4U__"}, + {"avrxmega2", "atxmega16c4", "__AVR_ATxmega16C4__"}, + {"avrxmega2", "atxmega16d4", "__AVR_ATxmega16D4__"}, + {"avrxmega2", "atxmega32a4", "__AVR_ATxmega32A4__"}, + {"avrxmega2", "atxmega32a4u", "__AVR_ATxmega32A4U__"}, + {"avrxmega2", "atxmega32c4", "__AVR_ATxmega32C4__"}, + {"avrxmega2", "atxmega32d4", "__AVR_ATxmega32D4__"}, + {"avrxmega2", "atxmega32e5", "__AVR_ATxmega32E5__"}, + {"avrxmega2", "atxmega16e5", "__AVR_ATxmega16E5__"}, + {"avrxmega2", "atxmega8e5", "__AVR_ATxmega8E5__"}, + {"avrxmega2", "atxmega32x1", "__AVR_ATxmega32X1__"}, + {"avrxmega4", "atxmega64a3", "__AVR_ATxmega64A3__"}, + {"avrxmega4", "atxmega64a3u", "__AVR_ATxmega64A3U__"}, + {"avrxmega4", "atxmega64a4u", "__AVR_ATxmega64A4U__"}, + {"avrxmega4", "atxmega64b1", "__AVR_ATxmega64B1__"}, + {"avrxmega4", "atxmega64b3", "__AVR_ATxmega64B3__"}, + {"avrxmega4", "atxmega64c3", "__AVR_ATxmega64C3__"}, + {"avrxmega4", "atxmega64d3", "__AVR_ATxmega64D3__"}, + {"avrxmega4", "atxmega64d4", "__AVR_ATxmega64D4__"}, + {"avrxmega5", "atxmega64a1", "__AVR_ATxmega64A1__"}, + {"avrxmega5", "atxmega64a1u", "__AVR_ATxmega64A1U__"}, + {"avrxmega6", "atxmega128a3", "__AVR_ATxmega128A3__"}, + {"avrxmega6", "atxmega128a3u", "__AVR_ATxmega128A3U__"}, + {"avrxmega6", "atxmega128b1", "__AVR_ATxmega128B1__"}, + {"avrxmega6", "atxmega128b3", "__AVR_ATxmega128B3__"}, + {"avrxmega6", "atxmega128c3", "__AVR_ATxmega128C3__"}, + {"avrxmega6", "atxmega128d3", "__AVR_ATxmega128D3__"}, + {"avrxmega6", "atxmega128d4", "__AVR_ATxmega128D4__"}, + {"avrxmega6", "atxmega192a3", "__AVR_ATxmega192A3__"}, + {"avrxmega6", "atxmega192a3u", "__AVR_ATxmega192A3U__"}, + {"avrxmega6", "atxmega192c3", "__AVR_ATxmega192C3__"}, + {"avrxmega6", "atxmega192d3", "__AVR_ATxmega192D3__"}, + {"avrxmega6", "atxmega256a3", "__AVR_ATxmega256A3__"}, + {"avrxmega6", "atxmega256a3u", "__AVR_ATxmega256A3U__"}, + {"avrxmega6", "atxmega256a3b", "__AVR_ATxmega256A3B__"}, + {"avrxmega6", "atxmega256a3bu", "__AVR_ATxmega256A3BU__"}, + {"avrxmega6", "atxmega256c3", "__AVR_ATxmega256C3__"}, + {"avrxmega6", "atxmega256d3", "__AVR_ATxmega256D3__"}, + {"avrxmega6", "atxmega384c3", "__AVR_ATxmega384C3__"}, + {"avrxmega6", "atxmega384d3", "__AVR_ATxmega384D3__"}, + {"avrxmega7", "atxmega128a1", "__AVR_ATxmega128A1__"}, + {"avrxmega7", "atxmega128a1u", "__AVR_ATxmega128A1U__"}, + {"avrxmega7", "atxmega128a4u", "__AVR_ATxmega128A4U__"}, + {"avrtiny", "attiny4", "__AVR_ATtiny4__"}, + {"avrtiny", "attiny5", "__AVR_ATtiny5__"}, + {"avrtiny", "attiny9", "__AVR_ATtiny9__"}, + {"avrtiny", "attiny10", "__AVR_ATtiny10__"}, + {"avrtiny", "attiny20", "__AVR_ATtiny20__"}, + {"avrtiny", "attiny40", "__AVR_ATtiny40__"}, + {"avrtiny", "attiny102", "__AVR_ATtiny102__"}, + {"avrtiny", "attiny104", "__AVR_ATtiny104__"}, +}; + +static constexpr AVR::FamilyInfo AVRFamilies[] = { + {"avr1", 1}, {"avr2", 2}, {"avr25", 25}, + {"avr3", 3}, {"avr31", 31}, {"avr35", 35}, + {"avr4", 4}, {"avr5", 5}, {"avr51", 51}, + {"avr6", 6}, {"avrtiny", 100}, {"avrxmega1", 101}, + {"avrxmega2", 102}, {"avrxmega3", 103}, {"avrxmega4", 104}, + {"avrxmega5", 105}, {"avrxmega6", 106}, {"avrxmega7", 107}}; + +Optional AVR::getMCUDefine(StringRef CPU) { + auto It = llvm::find_if(AVRMcus, + [&](const auto &Info) { return Info.Name == CPU; }); + + if (It != std::end(AVRMcus)) + return StringRef(It->DefineName); + + return {}; +} + +Optional AVR::getFamilyName(StringRef CPU) { + auto It = llvm::find_if(AVRMcus, + [&](const auto &Info) { return Info.Name == CPU; }); + + if (It != std::end(AVRMcus)) + return StringRef(It->Family); + + return {}; +} + +AVR::FamilyInfo AVR::getFamilyInfo(StringRef Family) { + auto It = llvm::find_if( + AVRFamilies, [&](const auto &Info) { return Info.Name == Family; }); + + if (It != std::end(AVRFamilies)) + return *It; + + return {}; +} + +bool AVR::isValidCPUName(StringRef CPU) { + bool IsFamily = llvm::find_if(AVRFamilies, [&](const FamilyInfo &Info) { + return Info.Name == CPU; + }) != std::end(AVRFamilies); + + bool IsMCU = llvm::find_if(AVRMcus, [&](const MCUInfo &Info) { + return Info.Name == CPU; + }) != std::end(AVRMcus); + return IsFamily || IsMCU; +} + +void AVR::fillValidCPUList(SmallVectorImpl &Values) { + for (const FamilyInfo &Info : AVRFamilies) + Values.push_back(Info.Name); + + for (const MCUInfo &Info : AVRMcus) + Values.push_back(Info.Name); +} Index: llvm/lib/Support/CMakeLists.txt =================================================================== --- llvm/lib/Support/CMakeLists.txt +++ llvm/lib/Support/CMakeLists.txt @@ -54,6 +54,7 @@ add_llvm_component_library(LLVMSupport AArch64TargetParser.cpp ABIBreak.cpp + AVRTargetParser.cpp ARMTargetParser.cpp AMDGPUMetadata.cpp APFloat.cpp