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/ADT/Triple.h"
19 #include "llvm/Support/Compiler.h"
24 class LLVM_LIBRARY_VISIBILITY SystemZTargetInfo
: public TargetInfo
{
26 static const Builtin::Info BuiltinInfo
[];
27 static const char *const GCCRegNames
[];
30 bool HasTransactionalExecution
;
35 SystemZTargetInfo(const llvm::Triple
&Triple
, const TargetOptions
&)
36 : TargetInfo(Triple
), CPU("z10"), ISARevision(8),
37 HasTransactionalExecution(false), HasVector(false), SoftFloat(false) {
38 IntMaxType
= SignedLong
;
39 Int64Type
= SignedLong
;
41 IntWidth
= IntAlign
= 32;
42 LongWidth
= LongLongWidth
= LongAlign
= LongLongAlign
= 64;
44 PointerWidth
= PointerAlign
= 64;
45 LongDoubleWidth
= 128;
47 LongDoubleFormat
= &llvm::APFloat::IEEEquad();
48 DefaultAlignForAttributeAligned
= 64;
50 if (Triple
.isOSzOS()) {
51 // All vector types are default aligned on an 8-byte boundary, even if the
52 // vector facility is not available. That is different from Linux.
54 // Compared to Linux/ELF, the data layout differs only in some details:
55 // - name mangling is GOFF
56 // - 128 bit vector types are 64 bit aligned
58 "E-m:l-i1:8:16-i8:8:16-i64:64-f128:64-v128:64-a:8:16-n32:64");
60 resetDataLayout("E-m:e-i1:8:16-i8:8:16-i64:64-f128:64-a:8:16-n32:64");
61 MaxAtomicPromoteWidth
= MaxAtomicInlineWidth
= 64;
65 void getTargetDefines(const LangOptions
&Opts
,
66 MacroBuilder
&Builder
) const override
;
68 ArrayRef
<Builtin::Info
> getTargetBuiltins() const override
;
70 ArrayRef
<const char *> getGCCRegNames() const override
;
72 ArrayRef
<TargetInfo::GCCRegAlias
> getGCCRegAliases() const override
{
77 ArrayRef
<TargetInfo::AddlRegName
> getGCCAddlRegNames() const override
;
79 bool isSPRegName(StringRef RegName
) const override
{
80 return RegName
.equals("r15");
83 bool validateAsmConstraint(const char *&Name
,
84 TargetInfo::ConstraintInfo
&info
) const override
;
86 std::string
convertConstraint(const char *&Constraint
) const override
{
87 switch (Constraint
[0]) {
88 case 'p': // Keep 'p' constraint.
89 return std::string("p");
91 switch (Constraint
[1]) {
92 case 'Q': // Address with base and unsigned 12-bit displacement
93 case 'R': // Likewise, plus an index
94 case 'S': // Address with base and signed 20-bit displacement
95 case 'T': // Likewise, plus an index
96 // "^" hints llvm that this is a 2 letter constraint.
97 // "Constraint++" is used to promote the string iterator
98 // to the next constraint.
99 return std::string("^") + std::string(Constraint
++, 2);
107 return TargetInfo::convertConstraint(Constraint
);
110 const char *getClobbers() const override
{
111 // FIXME: Is this really right?
115 BuiltinVaListKind
getBuiltinVaListKind() const override
{
116 return TargetInfo::SystemZBuiltinVaList
;
119 int getISARevision(StringRef Name
) const;
121 bool isValidCPUName(StringRef Name
) const override
{
122 return getISARevision(Name
) != -1;
125 void fillValidCPUList(SmallVectorImpl
<StringRef
> &Values
) const override
;
127 bool isValidTuneCPUName(StringRef Name
) const override
{
128 return isValidCPUName(Name
);
131 void fillValidTuneCPUList(SmallVectorImpl
<StringRef
> &Values
) const override
{
132 fillValidCPUList(Values
);
135 bool setCPU(const std::string
&Name
) override
{
137 ISARevision
= getISARevision(CPU
);
138 return ISARevision
!= -1;
142 initFeatureMap(llvm::StringMap
<bool> &Features
, DiagnosticsEngine
&Diags
,
144 const std::vector
<std::string
> &FeaturesVec
) const override
{
145 int ISARevision
= getISARevision(CPU
);
146 if (ISARevision
>= 10)
147 Features
["transactional-execution"] = true;
148 if (ISARevision
>= 11)
149 Features
["vector"] = true;
150 if (ISARevision
>= 12)
151 Features
["vector-enhancements-1"] = true;
152 if (ISARevision
>= 13)
153 Features
["vector-enhancements-2"] = true;
154 if (ISARevision
>= 14)
155 Features
["nnp-assist"] = true;
156 return TargetInfo::initFeatureMap(Features
, Diags
, CPU
, FeaturesVec
);
159 bool handleTargetFeatures(std::vector
<std::string
> &Features
,
160 DiagnosticsEngine
&Diags
) override
{
161 HasTransactionalExecution
= false;
164 for (const auto &Feature
: Features
) {
165 if (Feature
== "+transactional-execution")
166 HasTransactionalExecution
= true;
167 else if (Feature
== "+vector")
169 else if (Feature
== "+soft-float")
172 HasVector
&= !SoftFloat
;
174 // If we use the vector ABI, vector types are 64-bit aligned.
175 if (HasVector
&& !getTriple().isOSzOS()) {
177 resetDataLayout("E-m:e-i1:8:16-i8:8:16-i64:64-f128:64"
178 "-v128:64-a:8:16-n32:64");
183 bool hasFeature(StringRef Feature
) const override
;
185 CallingConvCheckResult
checkCallingConvention(CallingConv CC
) const override
{
189 case CC_OpenCLKernel
:
198 StringRef
getABI() const override
{
204 const char *getLongDoubleMangling() const override
{ return "g"; }
206 bool hasBitIntType() const override
{ return true; }
208 int getEHDataRegisterNumber(unsigned RegNo
) const override
{
209 return RegNo
< 4 ? 6 + RegNo
: -1;
212 } // namespace targets
214 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_SYSTEMZ_H