xref: /freebsd/contrib/llvm-project/clang/lib/Basic/Targets/AVR.h (revision fe6060f10f634930ff71b7c50291ddc610da2475)
10b57cec5SDimitry Andric //===--- AVR.h - Declare AVR target feature support -------------*- C++ -*-===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric // This file declares AVR TargetInfo objects.
100b57cec5SDimitry Andric //
110b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
120b57cec5SDimitry Andric 
130b57cec5SDimitry Andric #ifndef LLVM_CLANG_LIB_BASIC_TARGETS_AVR_H
140b57cec5SDimitry Andric #define LLVM_CLANG_LIB_BASIC_TARGETS_AVR_H
150b57cec5SDimitry Andric 
160b57cec5SDimitry Andric #include "clang/Basic/TargetInfo.h"
170b57cec5SDimitry Andric #include "clang/Basic/TargetOptions.h"
180b57cec5SDimitry Andric #include "llvm/ADT/Triple.h"
190b57cec5SDimitry Andric #include "llvm/Support/Compiler.h"
200b57cec5SDimitry Andric 
210b57cec5SDimitry Andric namespace clang {
220b57cec5SDimitry Andric namespace targets {
230b57cec5SDimitry Andric 
240b57cec5SDimitry Andric // AVR Target
250b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY AVRTargetInfo : public TargetInfo {
260b57cec5SDimitry Andric public:
270b57cec5SDimitry Andric   AVRTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
280b57cec5SDimitry Andric       : TargetInfo(Triple) {
290b57cec5SDimitry Andric     TLSSupported = false;
300b57cec5SDimitry Andric     PointerWidth = 16;
310b57cec5SDimitry Andric     PointerAlign = 8;
320b57cec5SDimitry Andric     IntWidth = 16;
330b57cec5SDimitry Andric     IntAlign = 8;
340b57cec5SDimitry Andric     LongWidth = 32;
350b57cec5SDimitry Andric     LongAlign = 8;
360b57cec5SDimitry Andric     LongLongWidth = 64;
370b57cec5SDimitry Andric     LongLongAlign = 8;
380b57cec5SDimitry Andric     SuitableAlign = 8;
390b57cec5SDimitry Andric     DefaultAlignForAttributeAligned = 8;
400b57cec5SDimitry Andric     HalfWidth = 16;
410b57cec5SDimitry Andric     HalfAlign = 8;
420b57cec5SDimitry Andric     FloatWidth = 32;
430b57cec5SDimitry Andric     FloatAlign = 8;
440b57cec5SDimitry Andric     DoubleWidth = 32;
450b57cec5SDimitry Andric     DoubleAlign = 8;
460b57cec5SDimitry Andric     DoubleFormat = &llvm::APFloat::IEEEsingle();
470b57cec5SDimitry Andric     LongDoubleWidth = 32;
480b57cec5SDimitry Andric     LongDoubleAlign = 8;
490b57cec5SDimitry Andric     LongDoubleFormat = &llvm::APFloat::IEEEsingle();
500b57cec5SDimitry Andric     SizeType = UnsignedInt;
510b57cec5SDimitry Andric     PtrDiffType = SignedInt;
520b57cec5SDimitry Andric     IntPtrType = SignedInt;
530b57cec5SDimitry Andric     Char16Type = UnsignedInt;
540b57cec5SDimitry Andric     WIntType = SignedInt;
55*fe6060f1SDimitry Andric     Int16Type = SignedInt;
560b57cec5SDimitry Andric     Char32Type = UnsignedLong;
570b57cec5SDimitry Andric     SigAtomicType = SignedChar;
580b57cec5SDimitry Andric     resetDataLayout("e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8");
590b57cec5SDimitry Andric   }
600b57cec5SDimitry Andric 
610b57cec5SDimitry Andric   void getTargetDefines(const LangOptions &Opts,
620b57cec5SDimitry Andric                         MacroBuilder &Builder) const override;
630b57cec5SDimitry Andric 
640b57cec5SDimitry Andric   ArrayRef<Builtin::Info> getTargetBuiltins() const override { return None; }
650b57cec5SDimitry Andric 
660b57cec5SDimitry Andric   BuiltinVaListKind getBuiltinVaListKind() const override {
670b57cec5SDimitry Andric     return TargetInfo::VoidPtrBuiltinVaList;
680b57cec5SDimitry Andric   }
690b57cec5SDimitry Andric 
700b57cec5SDimitry Andric   const char *getClobbers() const override { return ""; }
710b57cec5SDimitry Andric 
720b57cec5SDimitry Andric   ArrayRef<const char *> getGCCRegNames() const override {
730b57cec5SDimitry Andric     static const char *const GCCRegNames[] = {
740b57cec5SDimitry Andric         "r0",  "r1",  "r2",  "r3",  "r4",  "r5",  "r6",  "r7",  "r8",  "r9",
750b57cec5SDimitry Andric         "r10", "r11", "r12", "r13", "r14", "r15", "r16", "r17", "r18", "r19",
760b57cec5SDimitry Andric         "r20", "r21", "r22", "r23", "r24", "r25", "X",   "Y",   "Z",   "SP"
770b57cec5SDimitry Andric     };
780b57cec5SDimitry Andric     return llvm::makeArrayRef(GCCRegNames);
790b57cec5SDimitry Andric   }
800b57cec5SDimitry Andric 
810b57cec5SDimitry Andric   ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override {
820b57cec5SDimitry Andric     return None;
830b57cec5SDimitry Andric   }
840b57cec5SDimitry Andric 
850b57cec5SDimitry Andric   ArrayRef<TargetInfo::AddlRegName> getGCCAddlRegNames() const override {
860b57cec5SDimitry Andric     static const TargetInfo::AddlRegName AddlRegNames[] = {
870b57cec5SDimitry Andric         {{"r26", "r27"}, 26},
880b57cec5SDimitry Andric         {{"r28", "r29"}, 27},
890b57cec5SDimitry Andric         {{"r30", "r31"}, 28},
900b57cec5SDimitry Andric         {{"SPL", "SPH"}, 29},
910b57cec5SDimitry Andric     };
920b57cec5SDimitry Andric     return llvm::makeArrayRef(AddlRegNames);
930b57cec5SDimitry Andric   }
940b57cec5SDimitry Andric 
950b57cec5SDimitry Andric   bool validateAsmConstraint(const char *&Name,
960b57cec5SDimitry Andric                              TargetInfo::ConstraintInfo &Info) const override {
970b57cec5SDimitry Andric     // There aren't any multi-character AVR specific constraints.
980b57cec5SDimitry Andric     if (StringRef(Name).size() > 1)
990b57cec5SDimitry Andric       return false;
1000b57cec5SDimitry Andric 
1010b57cec5SDimitry Andric     switch (*Name) {
1020b57cec5SDimitry Andric     default:
1030b57cec5SDimitry Andric       return false;
1040b57cec5SDimitry Andric     case 'a': // Simple upper registers
1050b57cec5SDimitry Andric     case 'b': // Base pointer registers pairs
1060b57cec5SDimitry Andric     case 'd': // Upper register
1070b57cec5SDimitry Andric     case 'l': // Lower registers
1080b57cec5SDimitry Andric     case 'e': // Pointer register pairs
1090b57cec5SDimitry Andric     case 'q': // Stack pointer register
1100b57cec5SDimitry Andric     case 'r': // Any register
1110b57cec5SDimitry Andric     case 'w': // Special upper register pairs
1120b57cec5SDimitry Andric     case 't': // Temporary register
1130b57cec5SDimitry Andric     case 'x':
1140b57cec5SDimitry Andric     case 'X': // Pointer register pair X
1150b57cec5SDimitry Andric     case 'y':
1160b57cec5SDimitry Andric     case 'Y': // Pointer register pair Y
1170b57cec5SDimitry Andric     case 'z':
1180b57cec5SDimitry Andric     case 'Z': // Pointer register pair Z
1190b57cec5SDimitry Andric       Info.setAllowsRegister();
1200b57cec5SDimitry Andric       return true;
1210b57cec5SDimitry Andric     case 'I': // 6-bit positive integer constant
1220b57cec5SDimitry Andric       Info.setRequiresImmediate(0, 63);
1230b57cec5SDimitry Andric       return true;
1240b57cec5SDimitry Andric     case 'J': // 6-bit negative integer constant
1250b57cec5SDimitry Andric       Info.setRequiresImmediate(-63, 0);
1260b57cec5SDimitry Andric       return true;
1270b57cec5SDimitry Andric     case 'K': // Integer constant (Range: 2)
1280b57cec5SDimitry Andric       Info.setRequiresImmediate(2);
1290b57cec5SDimitry Andric       return true;
1300b57cec5SDimitry Andric     case 'L': // Integer constant (Range: 0)
1310b57cec5SDimitry Andric       Info.setRequiresImmediate(0);
1320b57cec5SDimitry Andric       return true;
1330b57cec5SDimitry Andric     case 'M': // 8-bit integer constant
1340b57cec5SDimitry Andric       Info.setRequiresImmediate(0, 0xff);
1350b57cec5SDimitry Andric       return true;
1360b57cec5SDimitry Andric     case 'N': // Integer constant (Range: -1)
1370b57cec5SDimitry Andric       Info.setRequiresImmediate(-1);
1380b57cec5SDimitry Andric       return true;
1390b57cec5SDimitry Andric     case 'O': // Integer constant (Range: 8, 16, 24)
1400b57cec5SDimitry Andric       Info.setRequiresImmediate({8, 16, 24});
1410b57cec5SDimitry Andric       return true;
1420b57cec5SDimitry Andric     case 'P': // Integer constant (Range: 1)
1430b57cec5SDimitry Andric       Info.setRequiresImmediate(1);
1440b57cec5SDimitry Andric       return true;
1450b57cec5SDimitry Andric     case 'R': // Integer constant (Range: -6 to 5)
1460b57cec5SDimitry Andric       Info.setRequiresImmediate(-6, 5);
1470b57cec5SDimitry Andric       return true;
1480b57cec5SDimitry Andric     case 'G': // Floating point constant
1490b57cec5SDimitry Andric     case 'Q': // A memory address based on Y or Z pointer with displacement.
1500b57cec5SDimitry Andric       return true;
1510b57cec5SDimitry Andric     }
1520b57cec5SDimitry Andric 
1530b57cec5SDimitry Andric     return false;
1540b57cec5SDimitry Andric   }
1550b57cec5SDimitry Andric 
1560b57cec5SDimitry Andric   IntType getIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final {
1570b57cec5SDimitry Andric     // AVR prefers int for 16-bit integers.
1580b57cec5SDimitry Andric     return BitWidth == 16 ? (IsSigned ? SignedInt : UnsignedInt)
1590b57cec5SDimitry Andric                           : TargetInfo::getIntTypeByWidth(BitWidth, IsSigned);
1600b57cec5SDimitry Andric   }
1610b57cec5SDimitry Andric 
1620b57cec5SDimitry Andric   IntType getLeastIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final {
1630b57cec5SDimitry Andric     // AVR uses int for int_least16_t and int_fast16_t.
1640b57cec5SDimitry Andric     return BitWidth == 16
1650b57cec5SDimitry Andric                ? (IsSigned ? SignedInt : UnsignedInt)
1660b57cec5SDimitry Andric                : TargetInfo::getLeastIntTypeByWidth(BitWidth, IsSigned);
1670b57cec5SDimitry Andric   }
1680b57cec5SDimitry Andric 
1690b57cec5SDimitry Andric   bool isValidCPUName(StringRef Name) const override;
1700b57cec5SDimitry Andric   void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
1710b57cec5SDimitry Andric   bool setCPU(const std::string &Name) override {
1720b57cec5SDimitry Andric     bool isValid = isValidCPUName(Name);
1730b57cec5SDimitry Andric     if (isValid)
1740b57cec5SDimitry Andric       CPU = Name;
1750b57cec5SDimitry Andric     return isValid;
1760b57cec5SDimitry Andric   }
1770b57cec5SDimitry Andric 
1780b57cec5SDimitry Andric protected:
1790b57cec5SDimitry Andric   std::string CPU;
1800b57cec5SDimitry Andric };
1810b57cec5SDimitry Andric 
1820b57cec5SDimitry Andric } // namespace targets
1830b57cec5SDimitry Andric } // namespace clang
1840b57cec5SDimitry Andric 
1850b57cec5SDimitry Andric #endif // LLVM_CLANG_LIB_BASIC_TARGETS_AVR_H
186