clang  15.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  PointerWidth = PointerAlign = 64;
44  LongDoubleWidth = 128;
45  LongDoubleAlign = 64;
46  LongDoubleFormat = &llvm::APFloat::IEEEquad();
47  DefaultAlignForAttributeAligned = 64;
48  MinGlobalAlign = 16;
49  if (Triple.isOSzOS()) {
50  // All vector types are default aligned on an 8-byte boundary, even if the
51  // vector facility is not available. That is different from Linux.
52  MaxVectorAlign = 64;
53  // Compared to Linux/ELF, the data layout differs only in some details:
54  // - name mangling is GOFF
55  // - 128 bit vector types are 64 bit aligned
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-a:8:16-n32:64");
60  MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
61  HasStrictFP = true;
62  }
63 
64  void getTargetDefines(const LangOptions &Opts,
65  MacroBuilder &Builder) const override;
66 
67  ArrayRef<Builtin::Info> getTargetBuiltins() const override;
68 
69  ArrayRef<const char *> getGCCRegNames() const override;
70 
72  // No aliases.
73  return None;
74  }
75 
76  ArrayRef<TargetInfo::AddlRegName> getGCCAddlRegNames() const override;
77 
78  bool isSPRegName(StringRef RegName) const override {
79  return RegName.equals("r15");
80  }
81 
82  bool validateAsmConstraint(const char *&Name,
83  TargetInfo::ConstraintInfo &info) const override;
84 
85  std::string convertConstraint(const char *&Constraint) const override {
86  switch (Constraint[0]) {
87  case 'p': // Keep 'p' constraint.
88  return std::string("p");
89  case 'Z':
90  switch (Constraint[1]) {
91  case 'Q': // Address with base and unsigned 12-bit displacement
92  case 'R': // Likewise, plus an index
93  case 'S': // Address with base and signed 20-bit displacement
94  case 'T': // Likewise, plus an index
95  // "^" hints llvm that this is a 2 letter constraint.
96  // "Constraint++" is used to promote the string iterator
97  // to the next constraint.
98  return std::string("^") + std::string(Constraint++, 2);
99  default:
100  break;
101  }
102  break;
103  default:
104  break;
105  }
106  return TargetInfo::convertConstraint(Constraint);
107  }
108 
109  const char *getClobbers() const override {
110  // FIXME: Is this really right?
111  return "";
112  }
113 
116  }
117 
118  int getISARevision(StringRef Name) const;
119 
120  bool isValidCPUName(StringRef Name) const override {
121  return getISARevision(Name) != -1;
122  }
123 
124  void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
125 
126  bool setCPU(const std::string &Name) override {
127  CPU = Name;
128  ISARevision = getISARevision(CPU);
129  return ISARevision != -1;
130  }
131 
132  bool
133  initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
134  StringRef CPU,
135  const std::vector<std::string> &FeaturesVec) const override {
136  int ISARevision = getISARevision(CPU);
137  if (ISARevision >= 10)
138  Features["transactional-execution"] = true;
139  if (ISARevision >= 11)
140  Features["vector"] = true;
141  if (ISARevision >= 12)
142  Features["vector-enhancements-1"] = true;
143  if (ISARevision >= 13)
144  Features["vector-enhancements-2"] = true;
145  if (ISARevision >= 14)
146  Features["nnp-assist"] = true;
147  return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
148  }
149 
150  bool handleTargetFeatures(std::vector<std::string> &Features,
151  DiagnosticsEngine &Diags) override {
152  HasTransactionalExecution = false;
153  HasVector = false;
154  SoftFloat = false;
155  for (const auto &Feature : Features) {
156  if (Feature == "+transactional-execution")
157  HasTransactionalExecution = true;
158  else if (Feature == "+vector")
159  HasVector = true;
160  else if (Feature == "+soft-float")
161  SoftFloat = true;
162  }
163  HasVector &= !SoftFloat;
164 
165  // If we use the vector ABI, vector types are 64-bit aligned.
166  if (HasVector && !getTriple().isOSzOS()) {
167  MaxVectorAlign = 64;
168  resetDataLayout("E-m:e-i1:8:16-i8:8:16-i64:64-f128:64"
169  "-v128:64-a:8:16-n32:64");
170  }
171  return true;
172  }
173 
174  bool hasFeature(StringRef Feature) const override;
175 
177  switch (CC) {
178  case CC_C:
179  case CC_Swift:
180  case CC_OpenCLKernel:
181  return CCCR_OK;
182  case CC_SwiftAsync:
183  return CCCR_Error;
184  default:
185  return CCCR_Warning;
186  }
187  }
188 
189  StringRef getABI() const override {
190  if (HasVector)
191  return "vector";
192  return "";
193  }
194 
195  const char *getLongDoubleMangling() const override { return "g"; }
196 
197  bool hasBitIntType() const override { return true; }
198 
199  int getEHDataRegisterNumber(unsigned RegNo) const override {
200  return RegNo < 4 ? 6 + RegNo : -1;
201  }
202 };
203 } // namespace targets
204 } // namespace clang
205 #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:195
clang::targets::SystemZTargetInfo::isSPRegName
bool isSPRegName(StringRef RegName) const override
Definition: SystemZ.h:78
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:143
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:150
clang::TargetInfo::SystemZBuiltinVaList
@ SystemZBuiltinVaList
Definition: TargetInfo.h:303
clang::targets::SystemZTargetInfo::getClobbers
const char * getClobbers() const override
Returns a string of target-specific clobbers, in LLVM format.
Definition: SystemZ.h:109
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:186
clang::TargetInfo::BuiltinVaListKind
BuiltinVaListKind
The different kinds of __builtin_va_list types defined by the target implementation.
Definition: TargetInfo.h:267
clang::targets::SystemZTargetInfo::checkCallingConvention
CallingConvCheckResult checkCallingConvention(CallingConv CC) const override
Determines whether a given calling convention is valid for the target.
Definition: SystemZ.h:176
clang::CC_OpenCLKernel
@ CC_OpenCLKernel
Definition: Specifiers.h:277
clang::targets::SystemZTargetInfo::convertConstraint
std::string convertConstraint(const char *&Constraint) const override
Definition: SystemZ.h:85
BuiltinInfo
static const Builtin::Info BuiltinInfo[]
Definition: Builtins.cpp:21
clang::CC_Swift
@ CC_Swift
Definition: Specifiers.h:278
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:483
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:263
clang::targets::SystemZTargetInfo::setCPU
bool setCPU(const std::string &Name) override
Target the specified CPU.
Definition: SystemZ.h:126
clang::CC_C
@ CC_C
Definition: Specifiers.h:264
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:114
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:199
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:197
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:189
clang::TargetInfo::ConstraintInfo
Definition: TargetInfo.h:991
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:78
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:133
clang
Definition: CalledOnceCheck.h:17
clang::Builtin::Info
Definition: Builtins.h:58
clang::CC_SwiftAsync
@ CC_SwiftAsync
Definition: Specifiers.h:279
clang::TargetInfo::convertConstraint
virtual std::string convertConstraint(const char *&Constraint) const
Definition: TargetInfo.h:1137
clang::TargetOptions
Options for controlling the target.
Definition: TargetOptions.h:26
llvm::SmallVectorImpl
Definition: Randstruct.h:18
clang::TargetInfo::CallingConvCheckResult
CallingConvCheckResult
Definition: TargetInfo.h:1502
clang::MacroBuilder
Definition: MacroBuilder.h:23
clang::targets::SystemZTargetInfo::getGCCRegAliases
ArrayRef< TargetInfo::GCCRegAlias > getGCCRegAliases() const override
Definition: SystemZ.h:71
clang::targets::SystemZTargetInfo::isValidCPUName
bool isValidCPUName(StringRef Name) const override
brief Determine whether this TargetInfo supports the given CPU name.
Definition: SystemZ.h:120
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