clang 24.0.0git
AVR.h
Go to the documentation of this file.
1//===--- AVR.h - Declare AVR target feature support -------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file declares AVR TargetInfo objects.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_LIB_BASIC_TARGETS_AVR_H
14#define LLVM_CLANG_LIB_BASIC_TARGETS_AVR_H
15
18#include "llvm/Support/Compiler.h"
19#include "llvm/TargetParser/Triple.h"
20
21namespace clang {
22namespace targets {
23
24// AVR Target
25class LLVM_LIBRARY_VISIBILITY AVRTargetInfo : public TargetInfo {
26public:
27 AVRTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
28 : TargetInfo(Triple) {
29 TLSSupported = false;
30 PointerWidth = 16;
31 PointerAlign = 8;
32 ShortWidth = 16;
33 ShortAlign = 8;
34 IntWidth = 16;
35 IntAlign = 8;
36 LongWidth = 32;
37 LongAlign = 8;
38 LongLongWidth = 64;
39 LongLongAlign = 8;
40 SuitableAlign = 8;
42 HalfWidth = 16;
43 HalfAlign = 8;
44 FloatWidth = 32;
45 FloatAlign = 8;
46 DoubleWidth = 32;
47 DoubleAlign = 8;
48 DoubleFormat = &llvm::APFloat::IEEEsingle();
49 LongDoubleWidth = 32;
51 LongDoubleFormat = &llvm::APFloat::IEEEsingle();
62 }
63
64 void getTargetDefines(const LangOptions &Opts,
65 MacroBuilder &Builder) const override;
66
67 llvm::SmallVector<Builtin::InfosShard> getTargetBuiltins() const override;
68
69 bool allowsLargerPreferedTypeAlignment() const override { return false; }
70
74
75 std::string_view getClobbers() const override { return ""; }
76
78 static const char *const GCCRegNames[] = {
79 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", "r8",
80 "r9", "r10", "r11", "r12", "r13", "r14", "r15", "r16", "r17",
81 "r18", "r19", "r20", "r21", "r22", "r23", "r24", "r25", "r26",
82 "r27", "r28", "r29", "r30", "r31", "__SP_L__", "__SP_H__"};
84 }
85
87 return {};
88 }
89
91 static const TargetInfo::AddlRegName AddlRegNames[] = {
92 {{"xl", "X"}, 26}, {{"xh"}, 27}, {{"yl", "Y"}, 28},
93 {{"yh"}, 29}, {{"zl", "Z"}, 30}, {{"zh"}, 31}};
95 }
96
97 bool validateAsmConstraint(const char *&Name,
98 TargetInfo::ConstraintInfo &Info) const override {
99 // There aren't any multi-character AVR specific constraints.
100 if (StringRef(Name).size() > 1)
101 return false;
102
103 switch (*Name) {
104 default:
105 return false;
106 case 'a': // Simple upper registers
107 case 'b': // Base pointer registers pairs
108 case 'd': // Upper register
109 case 'l': // Lower registers
110 case 'e': // Pointer register pairs
111 case 'q': // Stack pointer register
112 case 'r': // Any register
113 case 'w': // Special upper register pairs
114 case 't': // Temporary register
115 case 'x':
116 case 'X': // Pointer register pair X
117 case 'y':
118 case 'Y': // Pointer register pair Y
119 case 'z':
120 case 'Z': // Pointer register pair Z
121 Info.setAllowsRegister();
122 return true;
123 case 'I': // 6-bit positive integer constant
124 // Due to issue https://github.com/llvm/llvm-project/issues/51513, we
125 // allow value 64 in the frontend and let it be denied in the backend.
126 Info.setRequiresImmediate(0, 64);
127 return true;
128 case 'J': // 6-bit negative integer constant
129 Info.setRequiresImmediate(-63, 0);
130 return true;
131 case 'K': // Integer constant (Range: 2)
132 Info.setRequiresImmediate(2);
133 return true;
134 case 'L': // Integer constant (Range: 0)
135 Info.setRequiresImmediate(0);
136 return true;
137 case 'M': // 8-bit integer constant
138 Info.setRequiresImmediate(0, 0xff);
139 return true;
140 case 'N': // Integer constant (Range: -1)
141 Info.setRequiresImmediate(-1);
142 return true;
143 case 'O': // Integer constant (Range: 8, 16, 24)
144 Info.setRequiresImmediate({8, 16, 24});
145 return true;
146 case 'P': // Integer constant (Range: 1)
147 Info.setRequiresImmediate(1);
148 return true;
149 case 'R': // Integer constant (Range: -6 to 5)
150 Info.setRequiresImmediate(-6, 5);
151 return true;
152 case 'G': // Floating point constant 0.0
153 Info.setRequiresImmediate(0);
154 return true;
155 case 'Q': // A memory address based on Y or Z pointer with displacement.
156 return true;
157 }
158
159 return false;
160 }
161
162 IntType getIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final {
163 // AVR prefers int for 16-bit integers.
164 return BitWidth == 16 ? (IsSigned ? SignedInt : UnsignedInt)
165 : TargetInfo::getIntTypeByWidth(BitWidth, IsSigned);
166 }
167
168 IntType getLeastIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final {
169 // AVR uses int for int_least16_t and int_fast16_t.
170 return BitWidth == 16
171 ? (IsSigned ? SignedInt : UnsignedInt)
172 : TargetInfo::getLeastIntTypeByWidth(BitWidth, IsSigned);
173 }
174
175 bool isValidCPUName(StringRef Name) const override;
176 void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
177 bool setCPU(StringRef Name) override;
178 std::optional<std::string> handleAsmEscapedChar(char EscChar) const override;
179 StringRef getABI() const override { return ABI; }
180
181 std::pair<unsigned, unsigned> hardwareInterferenceSizes() const override {
182 return std::make_pair(32, 32);
183 }
184
185protected:
186 std::string CPU;
187 StringRef ABI;
188 StringRef DefineName;
189 StringRef Arch;
191};
192
193} // namespace targets
194} // namespace clang
195
196#endif // LLVM_CLANG_LIB_BASIC_TARGETS_AVR_H
Defines the clang::TargetOptions class.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
TargetInfo(const llvm::Triple &T)
virtual IntType getLeastIntTypeByWidth(unsigned BitWidth, bool IsSigned) const
Return the smallest integer type with at least the specified width.
BuiltinVaListKind
The different kinds of __builtin_va_list types defined by the target implementation.
Definition TargetInfo.h:341
@ VoidPtrBuiltinVaList
typedef void* __builtin_va_list;
Definition TargetInfo.h:346
virtual IntType getIntTypeByWidth(unsigned BitWidth, bool IsSigned) const
Return integer type with specified width.
void resetDataLayout(StringRef DL)
Set the data layout to the given string.
Options for controlling the target.
bool validateAsmConstraint(const char *&Name, TargetInfo::ConstraintInfo &Info) const override
Definition AVR.h:97
BuiltinVaListKind getBuiltinVaListKind() const override
Returns the kind of __builtin_va_list type that should be used with this target.
Definition AVR.h:71
std::string_view getClobbers() const override
Returns a string of target-specific clobbers, in LLVM format.
Definition AVR.h:75
ArrayRef< const char * > getGCCRegNames() const override
Definition AVR.h:77
ArrayRef< TargetInfo::GCCRegAlias > getGCCRegAliases() const override
Definition AVR.h:86
IntType getLeastIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final
Return the smallest integer type with at least the specified width.
Definition AVR.h:168
bool allowsLargerPreferedTypeAlignment() const override
Whether target allows to overalign ABI-specified preferred alignment.
Definition AVR.h:69
StringRef getABI() const override
Get the ABI currently in use.
Definition AVR.h:179
ArrayRef< TargetInfo::AddlRegName > getGCCAddlRegNames() const override
Definition AVR.h:90
std::pair< unsigned, unsigned > hardwareInterferenceSizes() const override
The first value in the pair is the minimum offset between two objects to avoid false sharing (destruc...
Definition AVR.h:181
IntType getIntTypeByWidth(unsigned BitWidth, bool IsSigned) const final
Return integer type with specified width.
Definition AVR.h:162
AVRTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
Definition AVR.h:27
Defines the clang::TargetInfo interface.
const TargetInfo::AddlRegName AddlRegNames[]
Definition X86.cpp:100
static const char *const GCCRegNames[]
Definition X86.cpp:73
Top level wrappers for InstallAPI frontend operations.
void setRequiresImmediate(int Min, int Max)
const llvm::fltSemantics * DoubleFormat
Definition TargetInfo.h:145
IntType
===-— Target Data Type Query Methods ----------------------------—===//
Definition TargetInfo.h:148
const llvm::fltSemantics * LongDoubleFormat
Definition TargetInfo.h:145
unsigned char DefaultAlignForAttributeAligned
Definition TargetInfo.h:135