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