1 //===--- SystemZ.h - Declare SystemZ target feature support -----*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // This file declares SystemZ TargetInfo objects.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_CLANG_LIB_BASIC_TARGETS_SYSTEMZ_H
14 #define LLVM_CLANG_LIB_BASIC_TARGETS_SYSTEMZ_H
16 #include "clang/Basic/TargetInfo.h"
17 #include "clang/Basic/TargetOptions.h"
18 #include "llvm/Support/Compiler.h"
19 #include "llvm/TargetParser/Triple.h"
24 static const unsigned ZOSAddressMap
[] = {
31 0, // opencl_global_device
32 0, // opencl_global_host
37 0, // sycl_global_device
38 0, // sycl_global_host
44 0, // hlsl_groupshared
48 class LLVM_LIBRARY_VISIBILITY SystemZTargetInfo
: public TargetInfo
{
50 static const char *const GCCRegNames
[];
52 bool HasTransactionalExecution
;
55 bool UnalignedSymbols
;
56 enum AddrSpace
{ ptr32
= 1 };
59 SystemZTargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&)
60 : TargetInfo(Triple
), ISARevision(getISARevision("z10")),
61 HasTransactionalExecution(false), HasVector(false), SoftFloat(false),
62 UnalignedSymbols(false) {
63 IntMaxType
= SignedLong
;
64 Int64Type
= SignedLong
;
65 IntWidth
= IntAlign
= 32;
66 LongWidth
= LongLongWidth
= LongAlign
= LongLongAlign
= 64;
68 PointerWidth
= PointerAlign
= 64;
69 LongDoubleWidth
= 128;
71 LongDoubleFormat
= &llvm::APFloat::IEEEquad();
72 DefaultAlignForAttributeAligned
= 64;
74 HasUnalignedAccess
= true;
75 if (Triple
.isOSzOS()) {
76 if (Triple
.isArch64Bit()) {
77 AddrSpaceMap
= &ZOSAddressMap
;
80 // All vector types are default aligned on an 8-byte boundary, even if the
81 // vector facility is not available. That is different from Linux.
83 // Compared to Linux/ELF, the data layout differs only in some details:
84 // - name mangling is GOFF.
85 // - 32 bit pointers, either as default or special address space
86 resetDataLayout("E-m:l-p1:32:32-i1:8:16-i8:8:16-i64:64-f128:64-v128:64-"
90 resetDataLayout("E-m:e-i1:8:16-i8:8:16-i64:64-f128:64"
91 "-v128:64-a:8:16-n32:64");
93 MaxAtomicPromoteWidth
= MaxAtomicInlineWidth
= 128;
97 unsigned getMinGlobalAlign(uint64_t Size
, bool HasNonWeakDef
) const override
;
99 void getTargetDefines(const LangOptions
&Opts
,
100 MacroBuilder
&Builder
) const override
;
102 ArrayRef
<Builtin::Info
> getTargetBuiltins() const override
;
104 ArrayRef
<const char *> getGCCRegNames() const override
;
106 ArrayRef
<TargetInfo::GCCRegAlias
> getGCCRegAliases() const override
{
111 ArrayRef
<TargetInfo::AddlRegName
> getGCCAddlRegNames() const override
;
113 bool isSPRegName(StringRef RegName
) const override
{
114 return RegName
== "r15";
117 bool validateAsmConstraint(const char *&Name
,
118 TargetInfo::ConstraintInfo
&info
) const override
;
120 std::string
convertConstraint(const char *&Constraint
) const override
{
121 switch (Constraint
[0]) {
122 case 'p': // Keep 'p' constraint.
123 return std::string("p");
125 switch (Constraint
[1]) {
126 case 'Q': // Address with base and unsigned 12-bit displacement
127 case 'R': // Likewise, plus an index
128 case 'S': // Address with base and signed 20-bit displacement
129 case 'T': // Likewise, plus an index
130 // "^" hints llvm that this is a 2 letter constraint.
131 // "Constraint++" is used to promote the string iterator
132 // to the next constraint.
133 return std::string("^") + std::string(Constraint
++, 2);
141 return TargetInfo::convertConstraint(Constraint
);
144 std::string_view
getClobbers() const override
{
145 // FIXME: Is this really right?
149 BuiltinVaListKind
getBuiltinVaListKind() const override
{
150 return TargetInfo::SystemZBuiltinVaList
;
153 int getISARevision(StringRef Name
) const;
155 bool isValidCPUName(StringRef Name
) const override
{
156 return getISARevision(Name
) != -1;
159 void fillValidCPUList(SmallVectorImpl
<StringRef
> &Values
) const override
;
161 bool isValidTuneCPUName(StringRef Name
) const override
{
162 return isValidCPUName(Name
);
165 void fillValidTuneCPUList(SmallVectorImpl
<StringRef
> &Values
) const override
{
166 fillValidCPUList(Values
);
169 bool setCPU(const std::string
&Name
) override
{
170 ISARevision
= getISARevision(Name
);
171 return ISARevision
!= -1;
175 initFeatureMap(llvm::StringMap
<bool> &Features
, DiagnosticsEngine
&Diags
,
177 const std::vector
<std::string
> &FeaturesVec
) const override
{
178 int ISARevision
= getISARevision(CPU
);
179 if (ISARevision
>= 10)
180 Features
["transactional-execution"] = true;
181 if (ISARevision
>= 11)
182 Features
["vector"] = true;
183 if (ISARevision
>= 12)
184 Features
["vector-enhancements-1"] = true;
185 if (ISARevision
>= 13)
186 Features
["vector-enhancements-2"] = true;
187 if (ISARevision
>= 14)
188 Features
["nnp-assist"] = true;
189 return TargetInfo::initFeatureMap(Features
, Diags
, CPU
, FeaturesVec
);
192 bool handleTargetFeatures(std::vector
<std::string
> &Features
,
193 DiagnosticsEngine
&Diags
) override
{
194 HasTransactionalExecution
= false;
197 UnalignedSymbols
= false;
198 for (const auto &Feature
: Features
) {
199 if (Feature
== "+transactional-execution")
200 HasTransactionalExecution
= true;
201 else if (Feature
== "+vector")
203 else if (Feature
== "+soft-float")
205 else if (Feature
== "+unaligned-symbols")
206 UnalignedSymbols
= true;
208 HasVector
&= !SoftFloat
;
210 // If we use the vector ABI, vector types are 64-bit aligned. The
211 // DataLayout string is always set to this alignment as it is not a
212 // requirement that it follows the alignment emitted by the front end. It
213 // is assumed generally that the Datalayout should reflect only the
214 // target triple and not any specific feature.
215 if (HasVector
&& !getTriple().isOSzOS())
221 bool hasFeature(StringRef Feature
) const override
;
223 CallingConvCheckResult
checkCallingConvention(CallingConv CC
) const override
{
227 case CC_OpenCLKernel
:
236 StringRef
getABI() const override
{
242 const char *getLongDoubleMangling() const override
{ return "g"; }
244 bool hasBitIntType() const override
{ return true; }
246 int getEHDataRegisterNumber(unsigned RegNo
) const override
{
247 return RegNo
< 4 ? 6 + RegNo
: -1;
250 std::pair
<unsigned, unsigned> hardwareInterferenceSizes() const override
{
251 return std::make_pair(256, 256);
253 uint64_t getPointerWidthV(LangAS AddrSpace
) const override
{
254 return (getTriple().isOSzOS() && getTriple().isArch64Bit() &&
255 getTargetAddressSpace(AddrSpace
) == ptr32
)
260 uint64_t getPointerAlignV(LangAS AddrSpace
) const override
{
261 return getPointerWidthV(AddrSpace
);
264 } // namespace targets
266 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_SYSTEMZ_H