| 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" |
| 17 |
#include "clang/Basic/TargetOptions.h" |
| 18 |
#include "llvm/Support/Compiler.h" |
| 19 |
#include "llvm/TargetParser/Triple.h" |
| 20 |
|
| 21 |
namespace clang { |
| 22 |
namespace targets { |
| 23 |
|
| 24 |
static const unsigned ZOSAddressMap[] = { |
| 25 |
0, // Default |
| 26 |
0, // opencl_global |
| 27 |
0, // opencl_local |
| 28 |
0, // opencl_constant |
| 29 |
0, // opencl_private |
| 30 |
0, // opencl_generic |
| 31 |
0, // opencl_global_device |
| 32 |
0, // opencl_global_host |
| 33 |
0, // cuda_device |
| 34 |
0, // cuda_constant |
| 35 |
0, // cuda_shared |
| 36 |
0, // sycl_global |
| 37 |
0, // sycl_global_device |
| 38 |
0, // sycl_global_host |
| 39 |
0, // sycl_local |
| 40 |
0, // sycl_private |
| 41 |
0, // ptr32_sptr |
| 42 |
1, // ptr32_uptr |
| 43 |
0, // ptr64 |
| 44 |
0, // hlsl_groupshared |
| 45 |
0, // hlsl_constant |
| 46 |
0, // hlsl_private |
| 47 |
0, // hlsl_device |
| 48 |
0, // hlsl_input |
| 49 |
0, // hlsl_push_constant |
| 50 |
0 // wasm_funcref |
| 51 |
}; |
| 52 |
|
| 53 |
class LLVM_LIBRARY_VISIBILITY SystemZTargetInfo : public TargetInfo { |
| 54 |
|
| 55 |
static const char *const GCCRegNames[]; |
| 56 |
int ISARevision; |
| 57 |
bool HasTransactionalExecution; |
| 58 |
bool HasVector; |
| 59 |
bool SoftFloat; |
| 60 |
bool UnalignedSymbols; |
| 61 |
enum AddrSpace { ptr32 = 1 }; |
| 62 |
|
| 63 |
public: |
| 64 |
SystemZTargetInfo(const llvm::Triple &Triple, const TargetOptions &) |
| 65 |
: TargetInfo(Triple), ISARevision(getISARevision("z10")), |
| 66 |
HasTransactionalExecution(false), HasVector(false), SoftFloat(false), |
| 67 |
UnalignedSymbols(false) { |
| 68 |
IntMaxType = SignedLong; |
| 69 |
Int64Type = SignedLong; |
| 70 |
IntWidth = IntAlign = 32; |
| 71 |
LongWidth = LongLongWidth = LongAlign = LongLongAlign = 64; |
| 72 |
Int128Align = 64; |
| 73 |
PointerWidth = PointerAlign = 64; |
| 74 |
LongDoubleWidth = 128; |
| 75 |
LongDoubleAlign = 64; |
| 76 |
LongDoubleFormat = &llvm::APFloat::IEEEquad(); |
| 77 |
DefaultAlignForAttributeAligned = 64; |
| 78 |
MinGlobalAlign = 16; |
| 79 |
HasUnalignedAccess = true; |
| 80 |
if (Triple.isOSzOS()) { |
| 81 |
if (Triple.isArch64Bit()) { |
| 82 |
AddrSpaceMap = &ZOSAddressMap; |
| 83 |
} |
| 84 |
TLSSupported = false; |
| 85 |
// All vector types are default aligned on an 8-byte boundary, even if the |
| 86 |
// vector facility is not available. That is different from Linux. |
| 87 |
MaxVectorAlign = 64; |
| 88 |
} else { |
| 89 |
// Support _Float16. |
| 90 |
HasFloat16 = true; |
| 91 |
TLSSupported = true; |
| 92 |
} |
| 93 |
resetDataLayout(); |
| 94 |
MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 128; |
| 95 |
|
| 96 |
// True if the backend supports operations on the half LLVM IR type. |
| 97 |
// By setting this to false, conversions will happen for _Float16 around |
| 98 |
// a statement by default, with operations done in float. However, if |
| 99 |
// -ffloat16-excess-precision=none is given, no conversions will be made |
| 100 |
// and instead the backend will promote each half operation to float |
| 101 |
// individually. |
| 102 |
HasFastHalfType = false; |
| 103 |
|
| 104 |
HasStrictFP = true; |
| 105 |
} |
| 106 |
|
| 107 |
unsigned getMinGlobalAlign(uint64_t Size, bool HasNonWeakDef) const override; |
| 108 |
|
| 109 |
bool useFP16ConversionIntrinsics() const override { return false; } |
| 110 |
|
| 111 |
void getTargetDefines(const LangOptions &Opts, |
| 112 |
MacroBuilder &Builder) const override; |
| 113 |
|
| 114 |
llvm::SmallVector<Builtin::InfosShard> getTargetBuiltins() const override; |
| 115 |
|
| 116 |
ArrayRef<const char *> getGCCRegNames() const override; |
| 117 |
|
| 118 |
ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override { |
| 119 |
// No aliases. |
| 120 |
return {}; |
| 121 |
} |
| 122 |
|
| 123 |
ArrayRef<TargetInfo::AddlRegName> getGCCAddlRegNames() const override; |
| 124 |
|
| 125 |
bool isSPRegName(StringRef RegName) const override { |
| 126 |
return RegName == "r15"; |
| 127 |
} |
| 128 |
|
| 129 |
bool validateAsmConstraint(const char *&Name, |
| 130 |
TargetInfo::ConstraintInfo &info) const override; |
| 131 |
|
| 132 |
std::string convertConstraint(const char *&Constraint) const override { |
| 133 |
switch (Constraint[0]) { |
| 134 |
case '@': // Flag output operand. |
| 135 |
if (llvm::StringRef(Constraint) == "@cc") { |
| 136 |
Constraint += 2; |
| 137 |
return std::string("{@cc}"); |
| 138 |
} |
| 139 |
break; |
| 140 |
case 'p': // Keep 'p' constraint. |
| 141 |
return std::string("p"); |
| 142 |
case 'Z': |
| 143 |
switch (Constraint[1]) { |
| 144 |
case 'Q': // Address with base and unsigned 12-bit displacement |
| 145 |
case 'R': // Likewise, plus an index |
| 146 |
case 'S': // Address with base and signed 20-bit displacement |
| 147 |
case 'T': // Likewise, plus an index |
| 148 |
// "^" hints llvm that this is a 2 letter constraint. |
| 149 |
// "Constraint++" is used to promote the string iterator |
| 150 |
// to the next constraint. |
| 151 |
return std::string("^") + std::string(Constraint++, 2); |
| 152 |
default: |
| 153 |
break; |
| 154 |
} |
| 155 |
break; |
| 156 |
default: |
| 157 |
break; |
| 158 |
} |
| 159 |
return TargetInfo::convertConstraint(Constraint); |
| 160 |
} |
| 161 |
|
| 162 |
std::string_view getClobbers() const override { |
| 163 |
// FIXME: Is this really right? |
| 164 |
return ""; |
| 165 |
} |
| 166 |
|
| 167 |
BuiltinVaListKind getBuiltinVaListKind() const override { |
| 168 |
return TargetInfo::SystemZBuiltinVaList; |
| 169 |
} |
| 170 |
|
| 171 |
int getISARevision(StringRef Name) const; |
| 172 |
|
| 173 |
bool isValidCPUName(StringRef Name) const override { |
| 174 |
return getISARevision(Name) != -1; |
| 175 |
} |
| 176 |
|
| 177 |
void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override; |
| 178 |
|
| 179 |
bool isValidTuneCPUName(StringRef Name) const override { |
| 180 |
return isValidCPUName(Name); |
| 181 |
} |
| 182 |
|
| 183 |
void fillValidTuneCPUList(SmallVectorImpl<StringRef> &Values) const override { |
| 184 |
fillValidCPUList(Values); |
| 185 |
} |
| 186 |
|
| 187 |
bool setCPU(const std::string &Name) override { |
| 188 |
ISARevision = getISARevision(Name); |
| 189 |
return ISARevision != -1; |
| 190 |
} |
| 191 |
|
| 192 |
bool |
| 193 |
initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags, |
| 194 |
StringRef CPU, |
| 195 |
const std::vector<std::string> &FeaturesVec) const override { |
| 196 |
int ISARevision = getISARevision(CPU); |
| 197 |
if (ISARevision >= 10) |
| 198 |
Features["transactional-execution"] = true; |
| 199 |
if (ISARevision >= 11) |
| 200 |
Features["vector"] = true; |
| 201 |
if (ISARevision >= 12) |
| 202 |
Features["vector-enhancements-1"] = true; |
| 203 |
if (ISARevision >= 13) |
| 204 |
Features["vector-enhancements-2"] = true; |
| 205 |
if (ISARevision >= 14) |
| 206 |
Features["nnp-assist"] = true; |
| 207 |
if (ISARevision >= 15) { |
| 208 |
Features["miscellaneous-extensions-4"] = true; |
| 209 |
Features["vector-enhancements-3"] = true; |
| 210 |
} |
| 211 |
return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec); |
| 212 |
} |
| 213 |
|
| 214 |
bool handleTargetFeatures(std::vector<std::string> &Features, |
| 215 |
DiagnosticsEngine &Diags) override { |
| 216 |
HasTransactionalExecution = false; |
| 217 |
HasVector = false; |
| 218 |
SoftFloat = false; |
| 219 |
UnalignedSymbols = false; |
| 220 |
for (const auto &Feature : Features) { |
| 221 |
if (Feature == "+transactional-execution") |
| 222 |
HasTransactionalExecution = true; |
| 223 |
else if (Feature == "+vector") |
| 224 |
HasVector = true; |
| 225 |
else if (Feature == "+soft-float") |
| 226 |
SoftFloat = true; |
| 227 |
else if (Feature == "+unaligned-symbols") |
| 228 |
UnalignedSymbols = true; |
| 229 |
} |
| 230 |
HasVector &= !SoftFloat; |
| 231 |
|
| 232 |
// If we use the vector ABI, vector types are 64-bit aligned. The |
| 233 |
// DataLayout string is always set to this alignment as it is not a |
| 234 |
// requirement that it follows the alignment emitted by the front end. It |
| 235 |
// is assumed generally that the Datalayout should reflect only the |
| 236 |
// target triple and not any specific feature. |
| 237 |
if (HasVector && !getTriple().isOSzOS()) |
| 238 |
MaxVectorAlign = 64; |
| 239 |
|
| 240 |
return true; |
| 241 |
} |
| 242 |
|
| 243 |
bool hasFeature(StringRef Feature) const override; |
| 244 |
|
| 245 |
CallingConvCheckResult checkCallingConvention(CallingConv CC) const override { |
| 246 |
switch (CC) { |
| 247 |
case CC_C: |
| 248 |
case CC_Swift: |
| 249 |
case CC_DeviceKernel: |
| 250 |
return CCCR_OK; |
| 251 |
case CC_SwiftAsync: |
| 252 |
return CCCR_Error; |
| 253 |
default: |
| 254 |
return CCCR_Warning; |
| 255 |
} |
| 256 |
} |
| 257 |
|
| 258 |
StringRef getABI() const override { |
| 259 |
if (HasVector) |
| 260 |
return "vector"; |
| 261 |
return ""; |
| 262 |
} |
| 263 |
|
| 264 |
const char *getLongDoubleMangling() const override { return "g"; } |
| 265 |
|
| 266 |
bool hasBitIntType() const override { return true; } |
| 267 |
|
| 268 |
int getEHDataRegisterNumber(unsigned RegNo) const override { |
| 269 |
return RegNo < 4 ? 6 + RegNo : -1; |
| 270 |
} |
| 271 |
|
| 272 |
bool hasSjLjLowering() const override { return true; } |
| 273 |
|
| 274 |
std::pair<unsigned, unsigned> hardwareInterferenceSizes() const override { |
| 275 |
return std::make_pair(256, 256); |
| 276 |
} |
| 277 |
uint64_t getPointerWidthV(LangAS AddrSpace) const override { |
| 278 |
return (getTriple().isOSzOS() && getTriple().isArch64Bit() && |
| 279 |
getTargetAddressSpace(AddrSpace) == ptr32) |
| 280 |
? 32 |
| 281 |
: PointerWidth; |
| 282 |
} |
| 283 |
|
| 284 |
uint64_t getPointerAlignV(LangAS AddrSpace) const override { |
| 285 |
return getPointerWidthV(AddrSpace); |
| 286 |
} |
| 287 |
}; |
| 288 |
} // namespace targets |
| 289 |
} // namespace clang |
| 290 |
#endif // LLVM_CLANG_LIB_BASIC_TARGETS_SYSTEMZ_H |