clang  16.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 
16 #include "clang/Basic/TargetInfo.h"
18 #include "llvm/ADT/Triple.h"
19 #include "llvm/Support/Compiler.h"
20 
21 namespace clang {
22 namespace targets {
23 
24 class LLVM_LIBRARY_VISIBILITY SystemZTargetInfo : public TargetInfo {
25 
26  static const Builtin::Info BuiltinInfo[];
27  static const char *const GCCRegNames[];
28  std::string CPU;
29  int ISARevision;
30  bool HasTransactionalExecution;
31  bool HasVector;
32  bool SoftFloat;
33 
34 public:
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;
40  TLSSupported = true;
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  // 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.
53  MaxVectorAlign = 64;
54  // Compared to Linux/ELF, the data layout differs only in that name
55  // mangling is GOFF.
56  resetDataLayout(
57  "E-m:l-i1:8:16-i8:8:16-i64:64-f128:64-v128:64-a:8:16-n32:64");
58  } else
59  resetDataLayout("E-m:e-i1:8:16-i8:8:16-i64:64-f128:64"
60  "-v128:64-a:8:16-n32:64");
61  MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
62  HasStrictFP = true;
63  }
64 
65  void getTargetDefines(const LangOptions &Opts,
66  MacroBuilder &Builder) const override;
67 
68  ArrayRef<Builtin::Info> getTargetBuiltins() const override;
69 
70  ArrayRef<const char *> getGCCRegNames() const override;
71 
73  // No aliases.
74  return None;
75  }
76 
77  ArrayRef<TargetInfo::AddlRegName> getGCCAddlRegNames() const override;
78 
79  bool isSPRegName(StringRef RegName) const override {
80  return RegName.equals("r15");
81  }
82 
83  bool validateAsmConstraint(const char *&Name,
84  TargetInfo::ConstraintInfo &info) const override;
85 
86  std::string convertConstraint(const char *&Constraint) const override {
87  switch (Constraint[0]) {
88  case 'p': // Keep 'p' constraint.
89  return std::string("p");
90  case 'Z':
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);
100  default:
101  break;
102  }
103  break;
104  default:
105  break;
106  }
107  return TargetInfo::convertConstraint(Constraint);
108  }
109 
110  const char *getClobbers() const override {
111  // FIXME: Is this really right?
112  return "";
113  }
114 
117  }
118 
119  int getISARevision(StringRef Name) const;
120 
121  bool isValidCPUName(StringRef Name) const override {
122  return getISARevision(Name) != -1;
123  }
124 
125  void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
126 
127  bool isValidTuneCPUName(StringRef Name) const override {
128  return isValidCPUName(Name);
129  }
130 
131  void fillValidTuneCPUList(SmallVectorImpl<StringRef> &Values) const override {
132  fillValidCPUList(Values);
133  }
134 
135  bool setCPU(const std::string &Name) override {
136  CPU = Name;
137  ISARevision = getISARevision(CPU);
138  return ISARevision != -1;
139  }
140 
141  bool
142  initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
143  StringRef CPU,
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);
157  }
158 
159  bool handleTargetFeatures(std::vector<std::string> &Features,
160  DiagnosticsEngine &Diags) override {
161  HasTransactionalExecution = false;
162  HasVector = false;
163  SoftFloat = false;
164  for (const auto &Feature : Features) {
165  if (Feature == "+transactional-execution")
166  HasTransactionalExecution = true;
167  else if (Feature == "+vector")
168  HasVector = true;
169  else if (Feature == "+soft-float")
170  SoftFloat = true;
171  }
172  HasVector &= !SoftFloat;
173 
174  // If we use the vector ABI, vector types are 64-bit aligned. The
175  // DataLayout string is always set to this alignment as it is not a
176  // requirement that it follows the alignment emitted by the front end. It
177  // is assumed generally that the Datalayout should reflect only the
178  // target triple and not any specific feature.
179  if (HasVector && !getTriple().isOSzOS())
180  MaxVectorAlign = 64;
181 
182  return true;
183  }
184 
185  bool hasFeature(StringRef Feature) const override;
186 
188  switch (CC) {
189  case CC_C:
190  case CC_Swift:
191  case CC_OpenCLKernel:
192  return CCCR_OK;
193  case CC_SwiftAsync:
194  return CCCR_Error;
195  default:
196  return CCCR_Warning;
197  }
198  }
199 
200  StringRef getABI() const override {
201  if (HasVector)
202  return "vector";
203  return "";
204  }
205 
206  const char *getLongDoubleMangling() const override { return "g"; }
207 
208  bool hasBitIntType() const override { return true; }
209 
210  int getEHDataRegisterNumber(unsigned RegNo) const override {
211  return RegNo < 4 ? 6 + RegNo : -1;
212  }
213 };
214 } // namespace targets
215 } // namespace clang
216 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_SYSTEMZ_H
clang::targets::SystemZTargetInfo::getLongDoubleMangling
const char * getLongDoubleMangling() const override
Return the mangled code of long double.
Definition: SystemZ.h:206
clang::targets::SystemZTargetInfo::isSPRegName
bool isSPRegName(StringRef RegName) const override
Definition: SystemZ.h:79
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
clang::RISCV::SignedLong
@ SignedLong
Definition: RISCVVIntrinsicUtils.h:166
clang::targets::SystemZTargetInfo::handleTargetFeatures
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:159
clang::TargetInfo::SystemZBuiltinVaList
@ SystemZBuiltinVaList
Definition: TargetInfo.h:325
clang::targets::SystemZTargetInfo::getClobbers
const char * getClobbers() const override
Returns a string of target-specific clobbers, in LLVM format.
Definition: SystemZ.h:110
TargetInfo.h
clang::DiagnosticsEngine
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:192
clang::TargetInfo
Exposes information about the current target.
Definition: TargetInfo.h:205
clang::targets::SystemZTargetInfo::fillValidTuneCPUList
void fillValidTuneCPUList(SmallVectorImpl< StringRef > &Values) const override
Fill a SmallVectorImpl with the valid values for tuning CPU.
Definition: SystemZ.h:131
clang::TargetInfo::BuiltinVaListKind
BuiltinVaListKind
The different kinds of __builtin_va_list types defined by the target implementation.
Definition: TargetInfo.h:289
clang::targets::SystemZTargetInfo::checkCallingConvention
CallingConvCheckResult checkCallingConvention(CallingConv CC) const override
Determines whether a given calling convention is valid for the target.
Definition: SystemZ.h:187
clang::CC_OpenCLKernel
@ CC_OpenCLKernel
Definition: Specifiers.h:280
clang::targets::SystemZTargetInfo::convertConstraint
std::string convertConstraint(const char *&Constraint) const override
Definition: SystemZ.h:86
BuiltinInfo
static const Builtin::Info BuiltinInfo[]
Definition: Builtins.cpp:21
clang::CC_Swift
@ CC_Swift
Definition: Specifiers.h:281
clang::targets::SystemZTargetInfo
Definition: SystemZ.h:24
clang::TargetInfo::initFeatureMap
virtual bool initFeatureMap(llvm::StringMap< bool > &Features, DiagnosticsEngine &Diags, StringRef CPU, const std::vector< std::string > &FeatureVec) const
Initialize the map with the default set of target features for the CPU this should include all legal ...
Definition: TargetInfo.cpp:494
clang::targets::GCCRegNames
static const char *const GCCRegNames[]
Definition: X86.cpp:43
clang::CallingConv
CallingConv
CallingConv - Specifies the calling convention that a function uses.
Definition: Specifiers.h:266
clang::targets::SystemZTargetInfo::setCPU
bool setCPU(const std::string &Name) override
Target the specified CPU.
Definition: SystemZ.h:135
clang::targets::SystemZTargetInfo::isValidTuneCPUName
bool isValidTuneCPUName(StringRef Name) const override
brief Determine whether this TargetInfo supports the given CPU name for
Definition: SystemZ.h:127
clang::CC_C
@ CC_C
Definition: Specifiers.h:267
clang::targets::SystemZTargetInfo::getBuiltinVaListKind
BuiltinVaListKind getBuiltinVaListKind() const override
Returns the kind of __builtin_va_list type that should be used with this target.
Definition: SystemZ.h:115
clang::targets::SystemZTargetInfo::getEHDataRegisterNumber
int getEHDataRegisterNumber(unsigned RegNo) const override
Return the register number that __builtin_eh_return_regno would return with the specified argument.
Definition: SystemZ.h:210
false
#define false
Definition: stdbool.h:22
TargetOptions.h
llvm::ArrayRef
Definition: LLVM.h:34
clang::targets::SystemZTargetInfo::hasBitIntType
bool hasBitIntType() const override
Determine whether the _BitInt type is supported on this target.
Definition: SystemZ.h:208
clang::targets::SystemZTargetInfo::SystemZTargetInfo
SystemZTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
Definition: SystemZ.h:35
clang::targets::SystemZTargetInfo::getABI
StringRef getABI() const override
Get the ABI currently in use.
Definition: SystemZ.h:200
clang::TargetInfo::ConstraintInfo
Definition: TargetInfo.h:1026
clang::LangOptions
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:81
clang::targets::SystemZTargetInfo::initFeatureMap
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:142
clang
Definition: CalledOnceCheck.h:17
clang::Builtin::Info
Definition: Builtins.h:59
clang::CC_SwiftAsync
@ CC_SwiftAsync
Definition: Specifiers.h:282
clang::TargetInfo::convertConstraint
virtual std::string convertConstraint(const char *&Constraint) const
Definition: TargetInfo.h:1172
clang::TargetOptions
Options for controlling the target.
Definition: TargetOptions.h:26
llvm::SmallVectorImpl
Definition: Randstruct.h:18
clang::TargetInfo::CallingConvCheckResult
CallingConvCheckResult
Definition: TargetInfo.h:1541
clang::MacroBuilder
Definition: MacroBuilder.h:23
clang::targets::SystemZTargetInfo::getGCCRegAliases
ArrayRef< TargetInfo::GCCRegAlias > getGCCRegAliases() const override
Definition: SystemZ.h:72
clang::targets::SystemZTargetInfo::isValidCPUName
bool isValidCPUName(StringRef Name) const override
brief Determine whether this TargetInfo supports the given CPU name.
Definition: SystemZ.h:121
hasFeature
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:101