clang 24.0.0git
M68k.cpp
Go to the documentation of this file.
1//===--- M68k.cpp - Implement M68k targets 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 M68k TargetInfo objects.
10//
11//===----------------------------------------------------------------------===//
12
13#include "M68k.h"
16#include "llvm/ADT/StringRef.h"
17#include "llvm/ADT/StringSwitch.h"
18#include "llvm/TargetParser/TargetParser.h"
19#include <cstdint>
20#include <cstring>
21#include <limits>
22#include <optional>
23
24namespace clang {
25namespace targets {
26
27// Linux/m68k ("old") uses the ABI from Sun Microsystems a.out
28// for m68k, and uses 16-bit alignments for int/long/pointers.
29//
30// NetBSD/m68k uses the ABI from SVR4 for m68k,
31// which uses 32-bit alignments for int/long/pointers.
32//
33// Ref. https://github.com/M680x0/issues/issues/13 and
34// https://github.com/llvm/llvm-project/issues/199826
35//
36// Arguably this ought to respect -malign-int, as suggested
37// above, this code doesn't so far.
38
39M68kTargetInfo::M68kTargetInfo(const llvm::Triple &Triple,
40 const TargetOptions &Opts)
41 : TargetInfo(Triple), TargetOpts(Opts) {
43
47 if (getTriple().isOSNetBSD()) {
49 } else {
51 }
52}
53
54bool M68kTargetInfo::setCPU(StringRef Name) {
55 CPU = llvm::StringSwitch<CPUKind>(Name)
56 .Case("generic", CK_68000)
57 .Case("M68000", CK_68000)
58 .Case("M68010", CK_68010)
59 .Case("M68020", CK_68020)
60 .Case("M68030", CK_68030)
61 .Case("M68040", CK_68040)
62 .Case("M68060", CK_68060)
63 .Default(CK_Unknown);
64 return CPU != CK_Unknown;
65}
66
68 SmallVectorImpl<StringRef> &Values) const {
69 Values.append(
70 {"generic", "M68000", "M68010", "M68020", "M68030", "M68040", "M68060"});
71}
72
74 MacroBuilder &Builder) const {
75 using llvm::Twine;
76
77 Builder.defineMacro("__m68k__");
78
79 DefineStd(Builder, "mc68000", Opts);
80
81 // For sub-architecture
82 switch (CPU) {
83 case CK_68010:
84 DefineStd(Builder, "mc68010", Opts);
85 break;
86 case CK_68020:
87 DefineStd(Builder, "mc68020", Opts);
88 break;
89 case CK_68030:
90 DefineStd(Builder, "mc68030", Opts);
91 break;
92 case CK_68040:
93 DefineStd(Builder, "mc68040", Opts);
94 break;
95 case CK_68060:
96 DefineStd(Builder, "mc68060", Opts);
97 break;
98 default:
99 break;
100 }
101
102 if (CPU >= CK_68020) {
103 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
104 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
105 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4");
106 }
107
108 // Floating point
109 if (TargetOpts.FeatureMap.lookup("isa-68881") ||
110 TargetOpts.FeatureMap.lookup("isa-68882"))
111 Builder.defineMacro("__HAVE_68881__");
112}
113
116 // FIXME: Implement.
117 return {};
118}
119
120bool M68kTargetInfo::hasFeature(StringRef Feature) const {
121 // FIXME elaborate moar
122 return Feature == "M68000";
123}
124
125const char *const M68kTargetInfo::GCCRegNames[] = {
126 "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7",
127 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "sp",
128 "pc"};
129
133
134const TargetInfo::GCCRegAlias M68kTargetInfo::GCCRegAliases[] = {
135 {{"bp"}, "a5"},
136 {{"fp"}, "a6"},
137 {{"usp", "ssp", "isp", "a7"}, "sp"},
138};
139
143
145 const char *&Name, TargetInfo::ConstraintInfo &info) const {
146 switch (*Name) {
147 case 'a': // address register
148 case 'd': // data register
149 info.setAllowsRegister();
150 return true;
151 case 'I': // constant integer in the range [1,8]
152 info.setRequiresImmediate(1, 8);
153 return true;
154 case 'J': // constant signed 16-bit integer
155 info.setRequiresImmediate(std::numeric_limits<int16_t>::min(),
156 std::numeric_limits<int16_t>::max());
157 return true;
158 case 'K': // constant that is NOT in the range of [-0x80, 0x80)
159 info.setRequiresImmediate();
160 return true;
161 case 'L': // constant integer in the range [-8,-1]
162 info.setRequiresImmediate(-8, -1);
163 return true;
164 case 'M': // constant that is NOT in the range of [-0x100, 0x100]
165 info.setRequiresImmediate();
166 return true;
167 case 'N': // constant integer in the range [24,31]
168 info.setRequiresImmediate(24, 31);
169 return true;
170 case 'O': // constant integer 16
171 info.setRequiresImmediate(16);
172 return true;
173 case 'P': // constant integer in the range [8,15]
174 info.setRequiresImmediate(8, 15);
175 return true;
176 case 'C':
177 ++Name;
178 switch (*Name) {
179 case '0': // constant integer 0
180 info.setRequiresImmediate(0);
181 return true;
182 case 'i': // constant integer
183 case 'j': // integer constant that doesn't fit in 16 bits
184 info.setRequiresImmediate();
185 return true;
186 default:
187 break;
188 }
189 break;
190 case 'Q': // address register indirect addressing
191 case 'U': // address register indirect w/ constant offset addressing
192 // TODO: Handle 'S' (basically 'm' when pc-rel is enforced) when
193 // '-mpcrel' flag is properly handled by the driver.
194 info.setAllowsMemory();
195 return true;
196 default:
197 break;
198 }
199 return false;
200}
201
202std::optional<std::string>
204 char C;
205 switch (EscChar) {
206 case '.':
207 case '#':
208 C = EscChar;
209 break;
210 case '/':
211 C = '%';
212 break;
213 case '$':
214 C = 's';
215 break;
216 case '&':
217 C = 'd';
218 break;
219 default:
220 return std::nullopt;
221 }
222
223 return std::string(1, C);
224}
225
226std::string M68kTargetInfo::convertConstraint(const char *&Constraint) const {
227 if (*Constraint == 'C')
228 // Two-character constraint; add "^" hint for later parsing
229 return std::string("^") + std::string(Constraint++, 2);
230
231 return std::string(1, *Constraint);
232}
233
234std::string_view M68kTargetInfo::getClobbers() const {
235 // FIXME: Is this really right?
236 return "";
237}
238
242
245 switch (CC) {
246 case CC_C:
247 case CC_M68kRTD:
248 return CCCR_OK;
249 default:
251 }
252}
253} // namespace targets
254} // namespace clang
Defines the Diagnostic-related interfaces.
Defines enum values for all the target-independent builtin functions.
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)
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
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 CallingConvCheckResult checkCallingConvention(CallingConv CC) const
Determines whether a given calling convention is valid for the target.
void resetDataLayout()
Set the data layout based on current triple and ABI.
Options for controlling the target.
void fillValidCPUList(SmallVectorImpl< StringRef > &Values) const override
Fill a SmallVectorImpl with the valid values to setCPU.
Definition M68k.cpp:67
std::string convertConstraint(const char *&Constraint) const override
Definition M68k.cpp:226
bool hasFeature(StringRef Feature) const override
Determine whether the given target has the given feature.
Definition M68k.cpp:120
std::optional< std::string > handleAsmEscapedChar(char EscChar) const override
Replace some escaped characters with another string based on target-specific rules.
Definition M68k.cpp:203
BuiltinVaListKind getBuiltinVaListKind() const override
Returns the kind of __builtin_va_list type that should be used with this target.
Definition M68k.cpp:239
M68kTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
Definition M68k.cpp:39
CallingConvCheckResult checkCallingConvention(CallingConv CC) const override
Determines whether a given calling convention is valid for the target.
Definition M68k.cpp:244
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
===-— Other target property query methods -----------------------—===//
Definition M68k.cpp:73
bool setCPU(StringRef Name) override
Target the specified CPU.
Definition M68k.cpp:54
std::string_view getClobbers() const override
Returns a string of target-specific clobbers, in LLVM format.
Definition M68k.cpp:234
ArrayRef< TargetInfo::GCCRegAlias > getGCCRegAliases() const override
Definition M68k.cpp:140
ArrayRef< const char * > getGCCRegNames() const override
Definition M68k.cpp:130
bool validateAsmConstraint(const char *&Name, TargetInfo::ConstraintInfo &info) const override
Definition M68k.cpp:144
llvm::SmallVector< Builtin::InfosShard > getTargetBuiltins() const override
Return information about target-specific builtins for the current primary target, and info about whic...
Definition M68k.cpp:115
LLVM_LIBRARY_VISIBILITY void DefineStd(clang::MacroBuilder &Builder, llvm::StringRef MacroName, const clang::LangOptions &Opts)
Define a macro name and standard variants.
Top level wrappers for InstallAPI frontend operations.
CallingConv
CallingConv - Specifies the calling convention that a function uses.
Definition Specifiers.h:282
@ CC_M68kRTD
Definition Specifiers.h:302