clang 19.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
24class LLVM_LIBRARY_VISIBILITY SystemZTargetInfo : public TargetInfo {
25
26 static const char *const GCCRegNames[];
27 std::string CPU;
28 int ISARevision;
29 bool HasTransactionalExecution;
30 bool HasVector;
31 bool SoftFloat;
32 bool UnalignedSymbols;
33
34public:
35 SystemZTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
36 : TargetInfo(Triple), CPU("z10"), ISARevision(8),
37 HasTransactionalExecution(false), HasVector(false), SoftFloat(false),
38 UnalignedSymbols(false) {
39 IntMaxType = SignedLong;
40 Int64Type = SignedLong;
41 IntWidth = IntAlign = 32;
42 LongWidth = LongLongWidth = LongAlign = LongLongAlign = 64;
43 Int128Align = 64;
44 PointerWidth = PointerAlign = 64;
45 LongDoubleWidth = 128;
46 LongDoubleAlign = 64;
47 LongDoubleFormat = &llvm::APFloat::IEEEquad();
48 DefaultAlignForAttributeAligned = 64;
49 MinGlobalAlign = 16;
50 if (Triple.isOSzOS()) {
51 TLSSupported = false;
52 // All vector types are default aligned on an 8-byte boundary, even if the
53 // vector facility is not available. That is different from Linux.
54 MaxVectorAlign = 64;
55 // Compared to Linux/ELF, the data layout differs only in some details:
56 // - name mangling is GOFF.
57 // - 32 bit pointers, either as default or special address space
58 resetDataLayout("E-m:l-i1:8:16-i8:8:16-i64:64-f128:64-v128:64-"
59 "a:8:16-n32:64");
60 } else {
61 TLSSupported = true;
62 resetDataLayout("E-m:e-i1:8:16-i8:8:16-i64:64-f128:64"
63 "-v128:64-a:8:16-n32:64");
64 }
65 MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 128;
66 HasStrictFP = true;
67 }
68
69 unsigned getMinGlobalAlign(uint64_t Size, bool HasNonWeakDef) const override;
70
71 void getTargetDefines(const LangOptions &Opts,
72 MacroBuilder &Builder) const override;
73
74 ArrayRef<Builtin::Info> getTargetBuiltins() const override;
75
76 ArrayRef<const char *> getGCCRegNames() const override;
77
79 // No aliases.
80 return std::nullopt;
81 }
82
83 ArrayRef<TargetInfo::AddlRegName> getGCCAddlRegNames() const override;
84
85 bool isSPRegName(StringRef RegName) const override {
86 return RegName.equals("r15");
87 }
88
89 bool validateAsmConstraint(const char *&Name,
90 TargetInfo::ConstraintInfo &info) const override;
91
92 std::string convertConstraint(const char *&Constraint) const override {
93 switch (Constraint[0]) {
94 case 'p': // Keep 'p' constraint.
95 return std::string("p");
96 case 'Z':
97 switch (Constraint[1]) {
98 case 'Q': // Address with base and unsigned 12-bit displacement
99 case 'R': // Likewise, plus an index
100 case 'S': // Address with base and signed 20-bit displacement
101 case 'T': // Likewise, plus an index
102 // "^" hints llvm that this is a 2 letter constraint.
103 // "Constraint++" is used to promote the string iterator
104 // to the next constraint.
105 return std::string("^") + std::string(Constraint++, 2);
106 default:
107 break;
108 }
109 break;
110 default:
111 break;
112 }
113 return TargetInfo::convertConstraint(Constraint);
114 }
115
116 std::string_view getClobbers() const override {
117 // FIXME: Is this really right?
118 return "";
119 }
120
122 return TargetInfo::SystemZBuiltinVaList;
123 }
124
125 int getISARevision(StringRef Name) const;
126
127 bool isValidCPUName(StringRef Name) const override {
128 return getISARevision(Name) != -1;
129 }
130
131 void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
132
133 bool isValidTuneCPUName(StringRef Name) const override {
134 return isValidCPUName(Name);
135 }
136
138 fillValidCPUList(Values);
139 }
140
141 bool setCPU(const std::string &Name) override {
142 CPU = Name;
143 ISARevision = getISARevision(CPU);
144 return ISARevision != -1;
145 }
146
147 bool
148 initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
149 StringRef CPU,
150 const std::vector<std::string> &FeaturesVec) const override {
151 int ISARevision = getISARevision(CPU);
152 if (ISARevision >= 10)
153 Features["transactional-execution"] = true;
154 if (ISARevision >= 11)
155 Features["vector"] = true;
156 if (ISARevision >= 12)
157 Features["vector-enhancements-1"] = true;
158 if (ISARevision >= 13)
159 Features["vector-enhancements-2"] = true;
160 if (ISARevision >= 14)
161 Features["nnp-assist"] = true;
162 return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
163 }
164
165 bool handleTargetFeatures(std::vector<std::string> &Features,
166 DiagnosticsEngine &Diags) override {
167 HasTransactionalExecution = false;
168 HasVector = false;
169 SoftFloat = false;
170 UnalignedSymbols = false;
171 for (const auto &Feature : Features) {
172 if (Feature == "+transactional-execution")
173 HasTransactionalExecution = true;
174 else if (Feature == "+vector")
175 HasVector = true;
176 else if (Feature == "+soft-float")
177 SoftFloat = true;
178 else if (Feature == "+unaligned-symbols")
179 UnalignedSymbols = true;
180 }
181 HasVector &= !SoftFloat;
182
183 // If we use the vector ABI, vector types are 64-bit aligned. The
184 // DataLayout string is always set to this alignment as it is not a
185 // requirement that it follows the alignment emitted by the front end. It
186 // is assumed generally that the Datalayout should reflect only the
187 // target triple and not any specific feature.
188 if (HasVector && !getTriple().isOSzOS())
189 MaxVectorAlign = 64;
190
191 return true;
192 }
193
194 bool hasFeature(StringRef Feature) const override;
195
197 switch (CC) {
198 case CC_C:
199 case CC_Swift:
200 case CC_OpenCLKernel:
201 return CCCR_OK;
202 case CC_SwiftAsync:
203 return CCCR_Error;
204 default:
205 return CCCR_Warning;
206 }
207 }
208
209 StringRef getABI() const override {
210 if (HasVector)
211 return "vector";
212 return "";
213 }
214
215 const char *getLongDoubleMangling() const override { return "g"; }
216
217 bool hasBitIntType() const override { return true; }
218
219 int getEHDataRegisterNumber(unsigned RegNo) const override {
220 return RegNo < 4 ? 6 + RegNo : -1;
221 }
222};
223} // namespace targets
224} // namespace clang
225#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:449
Exposes information about the current target.
Definition: TargetInfo.h:213
BuiltinVaListKind
The different kinds of __builtin_va_list types defined by the target implementation.
Definition: TargetInfo.h:311
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:217
const char * getLongDoubleMangling() const override
Return the mangled code of long double.
Definition: SystemZ.h:215
bool isSPRegName(StringRef RegName) const override
Definition: SystemZ.h:85
std::string convertConstraint(const char *&Constraint) const override
Definition: SystemZ.h:92
bool isValidCPUName(StringRef Name) const override
Determine whether this TargetInfo supports the given CPU name.
Definition: SystemZ.h:127
ArrayRef< TargetInfo::GCCRegAlias > getGCCRegAliases() const override
Definition: SystemZ.h:78
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:165
CallingConvCheckResult checkCallingConvention(CallingConv CC) const override
Determines whether a given calling convention is valid for the target.
Definition: SystemZ.h:196
bool setCPU(const std::string &Name) override
Target the specified CPU.
Definition: SystemZ.h:141
void fillValidTuneCPUList(SmallVectorImpl< StringRef > &Values) const override
Fill a SmallVectorImpl with the valid values for tuning CPU.
Definition: SystemZ.h:137
BuiltinVaListKind getBuiltinVaListKind() const override
Returns the kind of __builtin_va_list type that should be used with this target.
Definition: SystemZ.h:121
int getEHDataRegisterNumber(unsigned RegNo) const override
Return the register number that __builtin_eh_return_regno would return with the specified argument.
Definition: SystemZ.h:219
std::string_view getClobbers() const override
Returns a string of target-specific clobbers, in LLVM format.
Definition: SystemZ.h:116
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:148
StringRef getABI() const override
Get the ABI currently in use.
Definition: SystemZ.h:209
bool isValidTuneCPUName(StringRef Name) const override
Determine whether this TargetInfo supports the given CPU name for tuning.
Definition: SystemZ.h:133
SystemZTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
Definition: SystemZ.h:35
Defines the clang::TargetInfo interface.
The JSON file list parser is used to communicate input to InstallAPI.
CallingConv
CallingConv - Specifies the calling convention that a function uses.
Definition: Specifiers.h:275
@ CC_Swift
Definition: Specifiers.h:290
@ CC_OpenCLKernel
Definition: Specifiers.h:289
@ CC_C
Definition: Specifiers.h:276
@ CC_SwiftAsync
Definition: Specifiers.h:291
#define false
Definition: stdbool.h:22