xref: /freebsd/contrib/llvm-project/clang/lib/Basic/Targets/SystemZ.h (revision bdd1243df58e60e85101c09001d9812a789b6bc4)
10b57cec5SDimitry Andric //===--- SystemZ.h - Declare SystemZ target feature support -----*- C++ -*-===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric // This file declares SystemZ TargetInfo objects.
100b57cec5SDimitry Andric //
110b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
120b57cec5SDimitry Andric 
130b57cec5SDimitry Andric #ifndef LLVM_CLANG_LIB_BASIC_TARGETS_SYSTEMZ_H
140b57cec5SDimitry Andric #define LLVM_CLANG_LIB_BASIC_TARGETS_SYSTEMZ_H
150b57cec5SDimitry Andric 
160b57cec5SDimitry Andric #include "clang/Basic/TargetInfo.h"
170b57cec5SDimitry Andric #include "clang/Basic/TargetOptions.h"
180b57cec5SDimitry Andric #include "llvm/ADT/Triple.h"
190b57cec5SDimitry Andric #include "llvm/Support/Compiler.h"
200b57cec5SDimitry Andric 
210b57cec5SDimitry Andric namespace clang {
220b57cec5SDimitry Andric namespace targets {
230b57cec5SDimitry Andric 
240b57cec5SDimitry Andric class LLVM_LIBRARY_VISIBILITY SystemZTargetInfo : public TargetInfo {
250b57cec5SDimitry Andric 
260b57cec5SDimitry Andric   static const char *const GCCRegNames[];
270b57cec5SDimitry Andric   std::string CPU;
280b57cec5SDimitry Andric   int ISARevision;
290b57cec5SDimitry Andric   bool HasTransactionalExecution;
300b57cec5SDimitry Andric   bool HasVector;
315ffd83dbSDimitry Andric   bool SoftFloat;
320b57cec5SDimitry Andric 
330b57cec5SDimitry Andric public:
340b57cec5SDimitry Andric   SystemZTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
350b57cec5SDimitry Andric       : TargetInfo(Triple), CPU("z10"), ISARevision(8),
365ffd83dbSDimitry Andric         HasTransactionalExecution(false), HasVector(false), SoftFloat(false) {
370b57cec5SDimitry Andric     IntMaxType = SignedLong;
380b57cec5SDimitry Andric     Int64Type = SignedLong;
390b57cec5SDimitry Andric     TLSSupported = true;
400b57cec5SDimitry Andric     IntWidth = IntAlign = 32;
410b57cec5SDimitry Andric     LongWidth = LongLongWidth = LongAlign = LongLongAlign = 64;
42*bdd1243dSDimitry Andric     Int128Align = 64;
430b57cec5SDimitry Andric     PointerWidth = PointerAlign = 64;
440b57cec5SDimitry Andric     LongDoubleWidth = 128;
450b57cec5SDimitry Andric     LongDoubleAlign = 64;
460b57cec5SDimitry Andric     LongDoubleFormat = &llvm::APFloat::IEEEquad();
470b57cec5SDimitry Andric     DefaultAlignForAttributeAligned = 64;
480b57cec5SDimitry Andric     MinGlobalAlign = 16;
49349cc55cSDimitry Andric     if (Triple.isOSzOS()) {
50349cc55cSDimitry Andric       // All vector types are default aligned on an 8-byte boundary, even if the
51349cc55cSDimitry Andric       // vector facility is not available. That is different from Linux.
52349cc55cSDimitry Andric       MaxVectorAlign = 64;
53*bdd1243dSDimitry Andric       // Compared to Linux/ELF, the data layout differs only in that name
54*bdd1243dSDimitry Andric       // mangling is GOFF.
55349cc55cSDimitry Andric       resetDataLayout(
56349cc55cSDimitry Andric           "E-m:l-i1:8:16-i8:8:16-i64:64-f128:64-v128:64-a:8:16-n32:64");
57349cc55cSDimitry Andric     } else
58*bdd1243dSDimitry Andric       resetDataLayout("E-m:e-i1:8:16-i8:8:16-i64:64-f128:64"
59*bdd1243dSDimitry Andric                       "-v128:64-a:8:16-n32:64");
600b57cec5SDimitry Andric     MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
615ffd83dbSDimitry Andric     HasStrictFP = true;
620b57cec5SDimitry Andric   }
630b57cec5SDimitry Andric 
640b57cec5SDimitry Andric   void getTargetDefines(const LangOptions &Opts,
650b57cec5SDimitry Andric                         MacroBuilder &Builder) const override;
660b57cec5SDimitry Andric 
670b57cec5SDimitry Andric   ArrayRef<Builtin::Info> getTargetBuiltins() const override;
680b57cec5SDimitry Andric 
690b57cec5SDimitry Andric   ArrayRef<const char *> getGCCRegNames() const override;
700b57cec5SDimitry Andric 
710b57cec5SDimitry Andric   ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override {
720b57cec5SDimitry Andric     // No aliases.
73*bdd1243dSDimitry Andric     return std::nullopt;
740b57cec5SDimitry Andric   }
750b57cec5SDimitry Andric 
760b57cec5SDimitry Andric   ArrayRef<TargetInfo::AddlRegName> getGCCAddlRegNames() const override;
770b57cec5SDimitry Andric 
785ffd83dbSDimitry Andric   bool isSPRegName(StringRef RegName) const override {
795ffd83dbSDimitry Andric     return RegName.equals("r15");
805ffd83dbSDimitry Andric   }
815ffd83dbSDimitry Andric 
820b57cec5SDimitry Andric   bool validateAsmConstraint(const char *&Name,
830b57cec5SDimitry Andric                              TargetInfo::ConstraintInfo &info) const override;
840b57cec5SDimitry Andric 
8581ad6265SDimitry Andric   std::string convertConstraint(const char *&Constraint) const override {
8681ad6265SDimitry Andric     switch (Constraint[0]) {
8781ad6265SDimitry Andric     case 'p': // Keep 'p' constraint.
8881ad6265SDimitry Andric       return std::string("p");
8981ad6265SDimitry Andric     case 'Z':
9081ad6265SDimitry Andric       switch (Constraint[1]) {
9181ad6265SDimitry Andric       case 'Q': // Address with base and unsigned 12-bit displacement
9281ad6265SDimitry Andric       case 'R': // Likewise, plus an index
9381ad6265SDimitry Andric       case 'S': // Address with base and signed 20-bit displacement
9481ad6265SDimitry Andric       case 'T': // Likewise, plus an index
9581ad6265SDimitry Andric         // "^" hints llvm that this is a 2 letter constraint.
9681ad6265SDimitry Andric         // "Constraint++" is used to promote the string iterator
9781ad6265SDimitry Andric         // to the next constraint.
9881ad6265SDimitry Andric         return std::string("^") + std::string(Constraint++, 2);
9981ad6265SDimitry Andric       default:
10081ad6265SDimitry Andric         break;
10181ad6265SDimitry Andric       }
10281ad6265SDimitry Andric       break;
10381ad6265SDimitry Andric     default:
10481ad6265SDimitry Andric       break;
10581ad6265SDimitry Andric     }
10681ad6265SDimitry Andric     return TargetInfo::convertConstraint(Constraint);
10781ad6265SDimitry Andric   }
10881ad6265SDimitry Andric 
1090b57cec5SDimitry Andric   const char *getClobbers() const override {
1100b57cec5SDimitry Andric     // FIXME: Is this really right?
1110b57cec5SDimitry Andric     return "";
1120b57cec5SDimitry Andric   }
1130b57cec5SDimitry Andric 
1140b57cec5SDimitry Andric   BuiltinVaListKind getBuiltinVaListKind() const override {
1150b57cec5SDimitry Andric     return TargetInfo::SystemZBuiltinVaList;
1160b57cec5SDimitry Andric   }
1170b57cec5SDimitry Andric 
1180b57cec5SDimitry Andric   int getISARevision(StringRef Name) const;
1190b57cec5SDimitry Andric 
1200b57cec5SDimitry Andric   bool isValidCPUName(StringRef Name) const override {
1210b57cec5SDimitry Andric     return getISARevision(Name) != -1;
1220b57cec5SDimitry Andric   }
1230b57cec5SDimitry Andric 
1240b57cec5SDimitry Andric   void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
1250b57cec5SDimitry Andric 
126753f127fSDimitry Andric   bool isValidTuneCPUName(StringRef Name) const override {
127753f127fSDimitry Andric     return isValidCPUName(Name);
128753f127fSDimitry Andric   }
129753f127fSDimitry Andric 
130753f127fSDimitry Andric   void fillValidTuneCPUList(SmallVectorImpl<StringRef> &Values) const override {
131753f127fSDimitry Andric     fillValidCPUList(Values);
132753f127fSDimitry Andric   }
133753f127fSDimitry Andric 
1340b57cec5SDimitry Andric   bool setCPU(const std::string &Name) override {
1350b57cec5SDimitry Andric     CPU = Name;
1360b57cec5SDimitry Andric     ISARevision = getISARevision(CPU);
1370b57cec5SDimitry Andric     return ISARevision != -1;
1380b57cec5SDimitry Andric   }
1390b57cec5SDimitry Andric 
1400b57cec5SDimitry Andric   bool
1410b57cec5SDimitry Andric   initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
1420b57cec5SDimitry Andric                  StringRef CPU,
1430b57cec5SDimitry Andric                  const std::vector<std::string> &FeaturesVec) const override {
1440b57cec5SDimitry Andric     int ISARevision = getISARevision(CPU);
1450b57cec5SDimitry Andric     if (ISARevision >= 10)
1460b57cec5SDimitry Andric       Features["transactional-execution"] = true;
1470b57cec5SDimitry Andric     if (ISARevision >= 11)
1480b57cec5SDimitry Andric       Features["vector"] = true;
1490b57cec5SDimitry Andric     if (ISARevision >= 12)
1500b57cec5SDimitry Andric       Features["vector-enhancements-1"] = true;
1510b57cec5SDimitry Andric     if (ISARevision >= 13)
1520b57cec5SDimitry Andric       Features["vector-enhancements-2"] = true;
153fe6060f1SDimitry Andric     if (ISARevision >= 14)
154fe6060f1SDimitry Andric       Features["nnp-assist"] = true;
1550b57cec5SDimitry Andric     return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec);
1560b57cec5SDimitry Andric   }
1570b57cec5SDimitry Andric 
1580b57cec5SDimitry Andric   bool handleTargetFeatures(std::vector<std::string> &Features,
1590b57cec5SDimitry Andric                             DiagnosticsEngine &Diags) override {
1600b57cec5SDimitry Andric     HasTransactionalExecution = false;
1610b57cec5SDimitry Andric     HasVector = false;
1625ffd83dbSDimitry Andric     SoftFloat = false;
1630b57cec5SDimitry Andric     for (const auto &Feature : Features) {
1640b57cec5SDimitry Andric       if (Feature == "+transactional-execution")
1650b57cec5SDimitry Andric         HasTransactionalExecution = true;
1660b57cec5SDimitry Andric       else if (Feature == "+vector")
1670b57cec5SDimitry Andric         HasVector = true;
1685ffd83dbSDimitry Andric       else if (Feature == "+soft-float")
1695ffd83dbSDimitry Andric         SoftFloat = true;
1700b57cec5SDimitry Andric     }
1715ffd83dbSDimitry Andric     HasVector &= !SoftFloat;
1725ffd83dbSDimitry Andric 
173*bdd1243dSDimitry Andric     // If we use the vector ABI, vector types are 64-bit aligned. The
174*bdd1243dSDimitry Andric     // DataLayout string is always set to this alignment as it is not a
175*bdd1243dSDimitry Andric     // requirement that it follows the alignment emitted by the front end. It
176*bdd1243dSDimitry Andric     // is assumed generally that the Datalayout should reflect only the
177*bdd1243dSDimitry Andric     // target triple and not any specific feature.
178*bdd1243dSDimitry Andric     if (HasVector && !getTriple().isOSzOS())
1790b57cec5SDimitry Andric       MaxVectorAlign = 64;
180*bdd1243dSDimitry Andric 
1810b57cec5SDimitry Andric     return true;
1820b57cec5SDimitry Andric   }
1830b57cec5SDimitry Andric 
1840b57cec5SDimitry Andric   bool hasFeature(StringRef Feature) const override;
1850b57cec5SDimitry Andric 
1860b57cec5SDimitry Andric   CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
1870b57cec5SDimitry Andric     switch (CC) {
1880b57cec5SDimitry Andric     case CC_C:
1890b57cec5SDimitry Andric     case CC_Swift:
1900b57cec5SDimitry Andric     case CC_OpenCLKernel:
1910b57cec5SDimitry Andric       return CCCR_OK;
192fe6060f1SDimitry Andric     case CC_SwiftAsync:
193fe6060f1SDimitry Andric       return CCCR_Error;
1940b57cec5SDimitry Andric     default:
1950b57cec5SDimitry Andric       return CCCR_Warning;
1960b57cec5SDimitry Andric     }
1970b57cec5SDimitry Andric   }
1980b57cec5SDimitry Andric 
1990b57cec5SDimitry Andric   StringRef getABI() const override {
2000b57cec5SDimitry Andric     if (HasVector)
2010b57cec5SDimitry Andric       return "vector";
2020b57cec5SDimitry Andric     return "";
2030b57cec5SDimitry Andric   }
2040b57cec5SDimitry Andric 
2050b57cec5SDimitry Andric   const char *getLongDoubleMangling() const override { return "g"; }
2065ffd83dbSDimitry Andric 
2070eae32dcSDimitry Andric   bool hasBitIntType() const override { return true; }
208e8d8bef9SDimitry Andric 
209e8d8bef9SDimitry Andric   int getEHDataRegisterNumber(unsigned RegNo) const override {
210e8d8bef9SDimitry Andric     return RegNo < 4 ? 6 + RegNo : -1;
211e8d8bef9SDimitry Andric   }
2120b57cec5SDimitry Andric };
2130b57cec5SDimitry Andric } // namespace targets
2140b57cec5SDimitry Andric } // namespace clang
2150b57cec5SDimitry Andric #endif // LLVM_CLANG_LIB_BASIC_TARGETS_SYSTEMZ_H
216