clang 23.0.0git
SystemZ.cpp
Go to the documentation of this file.
1//===--- SystemZ.cpp - Implement SystemZ 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 SystemZ TargetInfo objects.
10//
11//===----------------------------------------------------------------------===//
12
13#include "SystemZ.h"
18#include "llvm/ADT/StringExtras.h"
19#include "llvm/ADT/StringSwitch.h"
20
21using namespace clang;
22using namespace clang::targets;
23
24static constexpr int NumBuiltins =
26static constexpr int NumBuiltinsZOS =
28
29#define GET_BUILTIN_STR_TABLE
30#include "clang/Basic/BuiltinsSystemZ.inc"
31#undef GET_BUILTIN_STR_TABLE
32
33static constexpr Builtin::Info BuiltinInfos[] = {
34#define GET_BUILTIN_INFOS
35#include "clang/Basic/BuiltinsSystemZ.inc"
36#undef GET_BUILTIN_INFOS
37};
38
39static constexpr Builtin::Info PrefixedBuiltinInfos[] = {
40#define GET_BUILTIN_PREFIXED_INFOS
41#include "clang/Basic/BuiltinsSystemZ.inc"
42#undef GET_BUILTIN_PREFIXED_INFOS
43};
44static_assert((std::size(BuiltinInfos) + std::size(PrefixedBuiltinInfos)) ==
46namespace clang {
47namespace ZOS {
48#define GET_BUILTIN_STR_TABLE
49#include "clang/Basic/BuiltinsZOS.inc"
50#undef GET_BUILTIN_STR_TABLE
51
52static constexpr Builtin::Info BuiltinInfos[] = {
53#define GET_BUILTIN_INFOS
54#include "clang/Basic/BuiltinsZOS.inc"
55#undef GET_BUILTIN_INFOS
56};
57static_assert((std::size(BuiltinInfos)) == NumBuiltinsZOS);
58} // namespace ZOS
59} // namespace clang
60
61const char *const SystemZTargetInfo::GCCRegNames[] = {
62 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
63 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
64 "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7",
65 "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15",
66 /*ap*/"", "cc", /*fp*/"", /*rp*/"", "a0", "a1",
67 "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23",
68 "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31"
69};
70
72 {{"v0"}, 16}, {{"v2"}, 17}, {{"v4"}, 18}, {{"v6"}, 19},
73 {{"v1"}, 20}, {{"v3"}, 21}, {{"v5"}, 22}, {{"v7"}, 23},
74 {{"v8"}, 24}, {{"v10"}, 25}, {{"v12"}, 26}, {{"v14"}, 27},
75 {{"v9"}, 28}, {{"v11"}, 29}, {{"v13"}, 30}, {{"v15"}, 31}
76};
77
81
85
87 const char *&Name, TargetInfo::ConstraintInfo &Info) const {
88 switch (*Name) {
89 default:
90 return false;
91
92 case 'Z':
93 switch (Name[1]) {
94 default:
95 return false;
96 case 'Q': // Address with base and unsigned 12-bit displacement
97 case 'R': // Likewise, plus an index
98 case 'S': // Address with base and signed 20-bit displacement
99 case 'T': // Likewise, plus an index
100 break;
101 }
102 [[fallthrough]];
103 case 'a': // Address register
104 case 'd': // Data register (equivalent to 'r')
105 case 'f': // Floating-point register
106 case 'v': // Vector register
107 Info.setAllowsRegister();
108 return true;
109
110 case 'I': // Unsigned 8-bit constant
111 case 'J': // Unsigned 12-bit constant
112 case 'K': // Signed 16-bit constant
113 case 'L': // Signed 20-bit displacement (on all targets we support)
114 case 'M': // 0x7fffffff
115 return true;
116
117 case 'Q': // Memory with base and unsigned 12-bit displacement
118 case 'R': // Likewise, plus an index
119 case 'S': // Memory with base and signed 20-bit displacement
120 case 'T': // Likewise, plus an index
121 Info.setAllowsMemory();
122 return true;
123 case '@':
124 // CC condition changes.
125 if (StringRef(Name) == "@cc") {
126 Name += 2;
127 Info.setAllowsRegister();
128 // SystemZ has 2-bits CC, and hence Interval [0, 4).
129 Info.setOutputOperandBounds(0, 4);
130 return true;
131 }
132 return false;
133 }
134}
135
137 llvm::StringLiteral Name;
139};
140static constexpr ISANameRevision ISARevisions[] = {
141 {{"arch8"}, 8}, {{"z10"}, 8},
142 {{"arch9"}, 9}, {{"z196"}, 9},
143 {{"arch10"}, 10}, {{"zEC12"}, 10},
144 {{"arch11"}, 11}, {{"z13"}, 11},
145 {{"arch12"}, 12}, {{"z14"}, 12},
146 {{"arch13"}, 13}, {{"z15"}, 13},
147 {{"arch14"}, 14}, {{"z16"}, 14},
148 {{"arch15"}, 15}, {{"z17"}, 15},
149};
150
151int SystemZTargetInfo::getISARevision(StringRef Name) const {
152 const auto Rev =
153 llvm::find_if(ISARevisions, [Name](const ISANameRevision &CR) {
154 return CR.Name == Name;
155 });
156 if (Rev == std::end(ISARevisions))
157 return -1;
158 return Rev->ISARevisionID;
159}
160
162 SmallVectorImpl<StringRef> &Values) const {
163 for (const ISANameRevision &Rev : ISARevisions)
164 Values.push_back(Rev.Name);
165}
166
168 return llvm::StringSwitch<bool>(Feature)
169 .Case("systemz", true)
170 .Case("arch8", ISARevision >= 8)
171 .Case("arch9", ISARevision >= 9)
172 .Case("arch10", ISARevision >= 10)
173 .Case("arch11", ISARevision >= 11)
174 .Case("arch12", ISARevision >= 12)
175 .Case("arch13", ISARevision >= 13)
176 .Case("arch14", ISARevision >= 14)
177 .Case("arch15", ISARevision >= 15)
178 .Case("htm", HasTransactionalExecution)
179 .Case("vx", HasVector)
180 .Default(false);
181}
182
184 bool HasNonWeakDef) const {
185 // Don't enforce the minimum alignment on an external or weak symbol if
186 // -munaligned-symbols is passed.
187 if (UnalignedSymbols && !HasNonWeakDef)
188 return 0;
189
190 return MinGlobalAlign;
191}
192
194 MacroBuilder &Builder) const {
195 // Inline assembly supports SystemZ flag outputs.
196 Builder.defineMacro("__GCC_ASM_FLAG_OUTPUTS__");
197
198 Builder.defineMacro("__s390__");
199 Builder.defineMacro("__s390x__");
200 Builder.defineMacro("__zarch__");
201 Builder.defineMacro("__LONG_DOUBLE_128__");
202
203 Builder.defineMacro("__ARCH__", Twine(ISARevision));
204
205 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
206 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
207 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4");
208 Builder.defineMacro("__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8");
209
210 if (HasTransactionalExecution)
211 Builder.defineMacro("__HTM__");
212 if (HasVector)
213 Builder.defineMacro("__VX__");
214 if (Opts.ZVector)
215 Builder.defineMacro("__VEC__", "10305");
216
217 /* Set __TARGET_LIB__ only if a value was given. If no value was given */
218 /* we rely on the LE headers to define __TARGET_LIB__. */
219 if (!getTriple().getOSVersion().empty()) {
220 llvm::VersionTuple V = getTriple().getOSVersion();
221 // Create string with form: 0xPVRRMMMM, where P=4
222 std::string Str("0x");
223 unsigned int Librel = 0x40000000;
224 Librel |= V.getMajor() << 24;
225 Librel |= V.getMinor().value_or(1) << 16;
226 Librel |= V.getSubminor().value_or(0);
227 Str += llvm::utohexstr(Librel);
228
229 Builder.defineMacro("__TARGET_LIB__", Str);
230 }
231}
232
235 if (getTriple().isOSzOS())
236 return {{&BuiltinStrings, BuiltinInfos},
237 {&BuiltinStrings, PrefixedBuiltinInfos, "__builtin_s390_"},
238 {&ZOS::BuiltinStrings, ZOS::BuiltinInfos}};
239 return {{&BuiltinStrings, BuiltinInfos},
240 {&BuiltinStrings, PrefixedBuiltinInfos, "__builtin_s390_"}};
241}
#define V(N, I)
static constexpr llvm::StringTable BuiltinStrings
Definition ARM.cpp:1115
static constexpr Builtin::Info PrefixedBuiltinInfos[]
Definition Hexagon.cpp:235
const TargetInfo::AddlRegName GCCAddlRegNames[]
Definition PPC.cpp:801
static constexpr int NumBuiltinsZOS
Definition SystemZ.cpp:26
static constexpr ISANameRevision ISARevisions[]
Definition SystemZ.cpp:140
static constexpr Builtin::Info BuiltinInfos[]
Definition Builtins.cpp:39
static constexpr unsigned NumBuiltins
Definition Builtins.cpp:33
Defines enum values for all the target-independent builtin functions.
Defines the clang::LangOptions interface.
Defines the clang::MacroBuilder utility class.
Enumerates target-specific builtins in their own namespaces within namespace clang.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
void getTargetDefines(const LangOptions &Opts, MacroBuilder &Builder) const override
===-— Other target property query methods -----------------------—===//
Definition SystemZ.cpp:193
bool validateAsmConstraint(const char *&Name, TargetInfo::ConstraintInfo &info) const override
Definition SystemZ.cpp:86
unsigned getMinGlobalAlign(uint64_t Size, bool HasNonWeakDef) const override
getMinGlobalAlign - Return the minimum alignment of a global variable, unless its alignment is explic...
Definition SystemZ.cpp:183
llvm::SmallVector< Builtin::InfosShard > getTargetBuiltins() const override
Return information about target-specific builtins for the current primary target, and info about whic...
Definition SystemZ.cpp:234
ArrayRef< TargetInfo::AddlRegName > getGCCAddlRegNames() const override
Definition SystemZ.cpp:82
ArrayRef< const char * > getGCCRegNames() const override
Definition SystemZ.cpp:78
bool hasFeature(StringRef Feature) const override
Determine whether the given target has the given feature.
Definition SystemZ.cpp:167
int getISARevision(StringRef Name) const
Definition SystemZ.cpp:151
void fillValidCPUList(SmallVectorImpl< StringRef > &Values) const override
Fill a SmallVectorImpl with the valid values to setCPU.
Definition SystemZ.cpp:161
static constexpr Builtin::Info BuiltinInfos[]
Definition SystemZ.cpp:52
The JSON file list parser is used to communicate input to InstallAPI.
llvm::StringLiteral Name
Definition SystemZ.cpp:137
The info used to represent each builtin.
Definition Builtins.h:80
void setOutputOperandBounds(unsigned Min, unsigned Max)