Path: blob/main/contrib/llvm-project/clang/lib/Basic/Targets/SystemZ.h
35268 views
//===--- SystemZ.h - Declare SystemZ target feature support -----*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file declares SystemZ TargetInfo objects.9//10//===----------------------------------------------------------------------===//1112#ifndef LLVM_CLANG_LIB_BASIC_TARGETS_SYSTEMZ_H13#define LLVM_CLANG_LIB_BASIC_TARGETS_SYSTEMZ_H1415#include "clang/Basic/TargetInfo.h"16#include "clang/Basic/TargetOptions.h"17#include "llvm/Support/Compiler.h"18#include "llvm/TargetParser/Triple.h"1920namespace clang {21namespace targets {2223class LLVM_LIBRARY_VISIBILITY SystemZTargetInfo : public TargetInfo {2425static const char *const GCCRegNames[];26std::string CPU;27int ISARevision;28bool HasTransactionalExecution;29bool HasVector;30bool SoftFloat;31bool UnalignedSymbols;3233public:34SystemZTargetInfo(const llvm::Triple &Triple, const TargetOptions &)35: TargetInfo(Triple), CPU("z10"), ISARevision(8),36HasTransactionalExecution(false), HasVector(false), SoftFloat(false),37UnalignedSymbols(false) {38IntMaxType = SignedLong;39Int64Type = SignedLong;40IntWidth = IntAlign = 32;41LongWidth = LongLongWidth = LongAlign = LongLongAlign = 64;42Int128Align = 64;43PointerWidth = PointerAlign = 64;44LongDoubleWidth = 128;45LongDoubleAlign = 64;46LongDoubleFormat = &llvm::APFloat::IEEEquad();47DefaultAlignForAttributeAligned = 64;48MinGlobalAlign = 16;49HasUnalignedAccess = true;50if (Triple.isOSzOS()) {51TLSSupported = false;52// All vector types are default aligned on an 8-byte boundary, even if the53// vector facility is not available. That is different from Linux.54MaxVectorAlign = 64;55// Compared to Linux/ELF, the data layout differs only in some details:56// - name mangling is GOFF.57// - 32 bit pointers, either as default or special address space58resetDataLayout("E-m:l-i1:8:16-i8:8:16-i64:64-f128:64-v128:64-"59"a:8:16-n32:64");60} else {61TLSSupported = true;62resetDataLayout("E-m:e-i1:8:16-i8:8:16-i64:64-f128:64"63"-v128:64-a:8:16-n32:64");64}65MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 128;66HasStrictFP = true;67}6869unsigned getMinGlobalAlign(uint64_t Size, bool HasNonWeakDef) const override;7071void getTargetDefines(const LangOptions &Opts,72MacroBuilder &Builder) const override;7374ArrayRef<Builtin::Info> getTargetBuiltins() const override;7576ArrayRef<const char *> getGCCRegNames() const override;7778ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override {79// No aliases.80return std::nullopt;81}8283ArrayRef<TargetInfo::AddlRegName> getGCCAddlRegNames() const override;8485bool isSPRegName(StringRef RegName) const override {86return RegName == "r15";87}8889bool validateAsmConstraint(const char *&Name,90TargetInfo::ConstraintInfo &info) const override;9192std::string convertConstraint(const char *&Constraint) const override {93switch (Constraint[0]) {94case 'p': // Keep 'p' constraint.95return std::string("p");96case 'Z':97switch (Constraint[1]) {98case 'Q': // Address with base and unsigned 12-bit displacement99case 'R': // Likewise, plus an index100case 'S': // Address with base and signed 20-bit displacement101case 'T': // Likewise, plus an index102// "^" hints llvm that this is a 2 letter constraint.103// "Constraint++" is used to promote the string iterator104// to the next constraint.105return std::string("^") + std::string(Constraint++, 2);106default:107break;108}109break;110default:111break;112}113return TargetInfo::convertConstraint(Constraint);114}115116std::string_view getClobbers() const override {117// FIXME: Is this really right?118return "";119}120121BuiltinVaListKind getBuiltinVaListKind() const override {122return TargetInfo::SystemZBuiltinVaList;123}124125int getISARevision(StringRef Name) const;126127bool isValidCPUName(StringRef Name) const override {128return getISARevision(Name) != -1;129}130131void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;132133bool isValidTuneCPUName(StringRef Name) const override {134return isValidCPUName(Name);135}136137void fillValidTuneCPUList(SmallVectorImpl<StringRef> &Values) const override {138fillValidCPUList(Values);139}140141bool setCPU(const std::string &Name) override {142CPU = Name;143ISARevision = getISARevision(CPU);144return ISARevision != -1;145}146147bool148initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,149StringRef CPU,150const std::vector<std::string> &FeaturesVec) const override {151int ISARevision = getISARevision(CPU);152if (ISARevision >= 10)153Features["transactional-execution"] = true;154if (ISARevision >= 11)155Features["vector"] = true;156if (ISARevision >= 12)157Features["vector-enhancements-1"] = true;158if (ISARevision >= 13)159Features["vector-enhancements-2"] = true;160if (ISARevision >= 14)161Features["nnp-assist"] = true;162return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);163}164165bool handleTargetFeatures(std::vector<std::string> &Features,166DiagnosticsEngine &Diags) override {167HasTransactionalExecution = false;168HasVector = false;169SoftFloat = false;170UnalignedSymbols = false;171for (const auto &Feature : Features) {172if (Feature == "+transactional-execution")173HasTransactionalExecution = true;174else if (Feature == "+vector")175HasVector = true;176else if (Feature == "+soft-float")177SoftFloat = true;178else if (Feature == "+unaligned-symbols")179UnalignedSymbols = true;180}181HasVector &= !SoftFloat;182183// If we use the vector ABI, vector types are 64-bit aligned. The184// DataLayout string is always set to this alignment as it is not a185// requirement that it follows the alignment emitted by the front end. It186// is assumed generally that the Datalayout should reflect only the187// target triple and not any specific feature.188if (HasVector && !getTriple().isOSzOS())189MaxVectorAlign = 64;190191return true;192}193194bool hasFeature(StringRef Feature) const override;195196CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {197switch (CC) {198case CC_C:199case CC_Swift:200case CC_OpenCLKernel:201return CCCR_OK;202case CC_SwiftAsync:203return CCCR_Error;204default:205return CCCR_Warning;206}207}208209StringRef getABI() const override {210if (HasVector)211return "vector";212return "";213}214215const char *getLongDoubleMangling() const override { return "g"; }216217bool hasBitIntType() const override { return true; }218219int getEHDataRegisterNumber(unsigned RegNo) const override {220return RegNo < 4 ? 6 + RegNo : -1;221}222223std::pair<unsigned, unsigned> hardwareInterferenceSizes() const override {224return std::make_pair(256, 256);225}226};227} // namespace targets228} // namespace clang229#endif // LLVM_CLANG_LIB_BASIC_TARGETS_SYSTEMZ_H230231232