clang 20.0.0git
SystemZ.h
Go to the documentation of this file.
1//===--- SystemZ.h - Declare SystemZ 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 SystemZ TargetInfo objects.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_LIB_BASIC_TARGETS_SYSTEMZ_H
14#define LLVM_CLANG_LIB_BASIC_TARGETS_SYSTEMZ_H
15
18#include "llvm/Support/Compiler.h"
19#include "llvm/TargetParser/Triple.h"
20
21namespace clang {
22namespace targets {
23
24static const unsigned ZOSAddressMap[] = {
25 0, // Default
26 0, // opencl_global
27 0, // opencl_local
28 0, // opencl_constant
29 0, // opencl_private
30 0, // opencl_generic
31 0, // opencl_global_device
32 0, // opencl_global_host
33 0, // cuda_device
34 0, // cuda_constant
35 0, // cuda_shared
36 0, // sycl_global
37 0, // sycl_global_device
38 0, // sycl_global_host
39 0, // sycl_local
40 0, // sycl_private
41 0, // ptr32_sptr
42 1, // ptr32_uptr
43 0, // ptr64
44 0, // hlsl_groupshared
45 0 // wasm_funcref
46};
47
48class LLVM_LIBRARY_VISIBILITY SystemZTargetInfo : public TargetInfo {
49
50 static const char *const GCCRegNames[];
51 std::string CPU;
52 int ISARevision;
53 bool HasTransactionalExecution;
54 bool HasVector;
55 bool SoftFloat;
56 bool UnalignedSymbols;
57 enum AddrSpace { ptr32 = 1 };
58
59public:
60 SystemZTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
61 : TargetInfo(Triple), CPU("z10"), ISARevision(8),
62 HasTransactionalExecution(false), HasVector(false), SoftFloat(false),
63 UnalignedSymbols(false) {
64 IntMaxType = SignedLong;
65 Int64Type = SignedLong;
66 IntWidth = IntAlign = 32;
67 LongWidth = LongLongWidth = LongAlign = LongLongAlign = 64;
68 Int128Align = 64;
69 PointerWidth = PointerAlign = 64;
70 LongDoubleWidth = 128;
71 LongDoubleAlign = 64;
72 LongDoubleFormat = &llvm::APFloat::IEEEquad();
73 DefaultAlignForAttributeAligned = 64;
74 MinGlobalAlign = 16;
75 HasUnalignedAccess = true;
76 if (Triple.isOSzOS()) {
77 if (Triple.isArch64Bit()) {
78 AddrSpaceMap = &ZOSAddressMap;
79 }
80 TLSSupported = false;
81 // All vector types are default aligned on an 8-byte boundary, even if the
82 // vector facility is not available. That is different from Linux.
83 MaxVectorAlign = 64;
84 // Compared to Linux/ELF, the data layout differs only in some details:
85 // - name mangling is GOFF.
86 // - 32 bit pointers, either as default or special address space
87 resetDataLayout("E-m:l-p1:32:32-i1:8:16-i8:8:16-i64:64-f128:64-v128:64-"
88 "a:8:16-n32:64");
89 } else {
90 TLSSupported = true;
91 resetDataLayout("E-m:e-i1:8:16-i8:8:16-i64:64-f128:64"
92 "-v128:64-a:8:16-n32:64");
93 }
94 MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 128;
95 HasStrictFP = true;
96 }
97
98 unsigned getMinGlobalAlign(uint64_t Size, bool HasNonWeakDef) const override;
99
100 void getTargetDefines(const LangOptions &Opts,
101 MacroBuilder &Builder) const override;
102
103 ArrayRef<Builtin::Info> getTargetBuiltins() const override;
104
105 ArrayRef<const char *> getGCCRegNames() const override;
106
108 // No aliases.
109 return std::nullopt;
110 }
111
112 ArrayRef<TargetInfo::AddlRegName> getGCCAddlRegNames() const override;
113
114 bool isSPRegName(StringRef RegName) const override {
115 return RegName == "r15";
116 }
117
118 bool validateAsmConstraint(const char *&Name,
119 TargetInfo::ConstraintInfo &info) const override;
120
121 std::string convertConstraint(const char *&Constraint) const override {
122 switch (Constraint[0]) {
123 case 'p': // Keep 'p' constraint.
124 return std::string("p");
125 case 'Z':
126 switch (Constraint[1]) {
127 case 'Q': // Address with base and unsigned 12-bit displacement
128 case 'R': // Likewise, plus an index
129 case 'S': // Address with base and signed 20-bit displacement
130 case 'T': // Likewise, plus an index
131 // "^" hints llvm that this is a 2 letter constraint.
132 // "Constraint++" is used to promote the string iterator
133 // to the next constraint.
134 return std::string("^") + std::string(Constraint++, 2);
135 default:
136 break;
137 }
138 break;
139 default:
140 break;
141 }
142 return TargetInfo::convertConstraint(Constraint);
143 }
144
145 std::string_view getClobbers() const override {
146 // FIXME: Is this really right?
147 return "";
148 }
149
151 return TargetInfo::SystemZBuiltinVaList;
152 }
153
154 int getISARevision(StringRef Name) const;
155
156 bool isValidCPUName(StringRef Name) const override {
157 return getISARevision(Name) != -1;
158 }
159
160 void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
161
162 bool isValidTuneCPUName(StringRef Name) const override {
163 return isValidCPUName(Name);
164 }
165
167 fillValidCPUList(Values);
168 }
169
170 bool setCPU(const std::string &Name) override {
171 CPU = Name;
172 ISARevision = getISARevision(CPU);
173 return ISARevision != -1;
174 }
175
176 bool
177 initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
178 StringRef CPU,
179 const std::vector<std::string> &FeaturesVec) const override {
180 int ISARevision = getISARevision(CPU);
181 if (ISARevision >= 10)
182 Features["transactional-execution"] = true;
183 if (ISARevision >= 11)
184 Features["vector"] = true;
185 if (ISARevision >= 12)
186 Features["vector-enhancements-1"] = true;
187 if (ISARevision >= 13)
188 Features["vector-enhancements-2"] = true;
189 if (ISARevision >= 14)
190 Features["nnp-assist"] = true;
191 return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
192 }
193
194 bool handleTargetFeatures(std::vector<std::string> &Features,
195 DiagnosticsEngine &Diags) override {
196 HasTransactionalExecution = false;
197 HasVector = false;
198 SoftFloat = false;
199 UnalignedSymbols = false;
200 for (const auto &Feature : Features) {
201 if (Feature == "+transactional-execution")
202 HasTransactionalExecution = true;
203 else if (Feature == "+vector")
204 HasVector = true;
205 else if (Feature == "+soft-float")
206 SoftFloat = true;
207 else if (Feature == "+unaligned-symbols")
208 UnalignedSymbols = true;
209 }
210 HasVector &= !SoftFloat;
211
212 // If we use the vector ABI, vector types are 64-bit aligned. The
213 // DataLayout string is always set to this alignment as it is not a
214 // requirement that it follows the alignment emitted by the front end. It
215 // is assumed generally that the Datalayout should reflect only the
216 // target triple and not any specific feature.
217 if (HasVector && !getTriple().isOSzOS())
218 MaxVectorAlign = 64;
219
220 return true;
221 }
222
223 bool hasFeature(StringRef Feature) const override;
224
226 switch (CC) {
227 case CC_C:
228 case CC_Swift:
229 case CC_OpenCLKernel:
230 return CCCR_OK;
231 case CC_SwiftAsync:
232 return CCCR_Error;
233 default:
234 return CCCR_Warning;
235 }
236 }
237
238 StringRef getABI() const override {
239 if (HasVector)
240 return "vector";
241 return "";
242 }
243
244 const char *getLongDoubleMangling() const override { return "g"; }
245
246 bool hasBitIntType() const override { return true; }
247
248 int getEHDataRegisterNumber(unsigned RegNo) const override {
249 return RegNo < 4 ? 6 + RegNo : -1;
250 }
251
252 std::pair<unsigned, unsigned> hardwareInterferenceSizes() const override {
253 return std::make_pair(256, 256);
254 }
255 uint64_t getPointerWidthV(LangAS AddrSpace) const override {
256 return (getTriple().isOSzOS() && getTriple().isArch64Bit() &&
257 getTargetAddressSpace(AddrSpace) == ptr32)
258 ? 32
259 : PointerWidth;
260 }
261
262 uint64_t getPointerAlignV(LangAS AddrSpace) const override {
263 return getPointerWidthV(AddrSpace);
264 }
265};
266} // namespace targets
267} // namespace clang
268#endif // LLVM_CLANG_LIB_BASIC_TARGETS_SYSTEMZ_H
static bool hasFeature(StringRef Feature, const LangOptions &LangOpts, const TargetInfo &Target)
Determine whether a translation unit built using the current language options has the given feature.
Definition: Module.cpp:100
Defines the clang::TargetOptions class.
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:192
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:461
Exposes information about the current target.
Definition: TargetInfo.h:218
BuiltinVaListKind
The different kinds of __builtin_va_list types defined by the target implementation.
Definition: TargetInfo.h:319
Options for controlling the target.
Definition: TargetOptions.h:26
bool hasBitIntType() const override
Determine whether the _BitInt type is supported on this target.
Definition: SystemZ.h:246
const char * getLongDoubleMangling() const override
Return the mangled code of long double.
Definition: SystemZ.h:244
uint64_t getPointerAlignV(LangAS AddrSpace) const override
Definition: SystemZ.h:262
bool isSPRegName(StringRef RegName) const override
Definition: SystemZ.h:114
std::string convertConstraint(const char *&Constraint) const override
Definition: SystemZ.h:121
bool isValidCPUName(StringRef Name) const override
Determine whether this TargetInfo supports the given CPU name.
Definition: SystemZ.h:156
ArrayRef< TargetInfo::GCCRegAlias > getGCCRegAliases() const override
Definition: SystemZ.h:107
bool handleTargetFeatures(std::vector< std::string > &Features, DiagnosticsEngine &Diags) override
Perform initialization based on the user configured set of features (e.g., +sse4).
Definition: SystemZ.h:194
CallingConvCheckResult checkCallingConvention(CallingConv CC) const override
Determines whether a given calling convention is valid for the target.
Definition: SystemZ.h:225
bool setCPU(const std::string &Name) override
Target the specified CPU.
Definition: SystemZ.h:170
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: SystemZ.h:252
void fillValidTuneCPUList(SmallVectorImpl< StringRef > &Values) const override
Fill a SmallVectorImpl with the valid values for tuning CPU.
Definition: SystemZ.h:166
BuiltinVaListKind getBuiltinVaListKind() const override
Returns the kind of __builtin_va_list type that should be used with this target.
Definition: SystemZ.h:150
uint64_t getPointerWidthV(LangAS AddrSpace) const override
Definition: SystemZ.h:255
int getEHDataRegisterNumber(unsigned RegNo) const override
Return the register number that __builtin_eh_return_regno would return with the specified argument.
Definition: SystemZ.h:248
std::string_view getClobbers() const override
Returns a string of target-specific clobbers, in LLVM format.
Definition: SystemZ.h:145
bool initFeatureMap(llvm::StringMap< bool > &Features, DiagnosticsEngine &Diags, StringRef CPU, const std::vector< std::string > &FeaturesVec) const override
Initialize the map with the default set of target features for the CPU this should include all legal ...
Definition: SystemZ.h:177
StringRef getABI() const override
Get the ABI currently in use.
Definition: SystemZ.h:238
bool isValidTuneCPUName(StringRef Name) const override
Determine whether this TargetInfo supports the given CPU name for tuning.
Definition: SystemZ.h:162
SystemZTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
Definition: SystemZ.h:60
Defines the clang::TargetInfo interface.
static const unsigned ZOSAddressMap[]
Definition: SystemZ.h:24
The JSON file list parser is used to communicate input to InstallAPI.
LangAS
Defines the address space values used by the address space qualifier of QualType.
Definition: AddressSpaces.h:25
CallingConv
CallingConv - Specifies the calling convention that a function uses.
Definition: Specifiers.h:278
@ CC_Swift
Definition: Specifiers.h:293
@ CC_OpenCLKernel
Definition: Specifiers.h:292
@ CC_C
Definition: Specifiers.h:279
@ CC_SwiftAsync
Definition: Specifiers.h:294
#define false
Definition: stdbool.h:26