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/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 resetDataLayout("E-m:e-i1:8:16-i8:8:16-i64:64-f128:64-a:8:16-n32:64"); 50 MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64; 51 } 52 53 void getTargetDefines(const LangOptions &Opts, 54 MacroBuilder &Builder) const override; 55 56 ArrayRef<Builtin::Info> getTargetBuiltins() const override; 57 58 ArrayRef<const char *> getGCCRegNames() const override; 59 60 ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override { 61 // No aliases. 62 return None; 63 } 64 65 ArrayRef<TargetInfo::AddlRegName> getGCCAddlRegNames() const override; 66 67 bool validateAsmConstraint(const char *&Name, 68 TargetInfo::ConstraintInfo &info) const override; 69 70 const char *getClobbers() const override { 71 // FIXME: Is this really right? 72 return ""; 73 } 74 75 BuiltinVaListKind getBuiltinVaListKind() const override { 76 return TargetInfo::SystemZBuiltinVaList; 77 } 78 79 int getISARevision(StringRef Name) const; 80 81 bool isValidCPUName(StringRef Name) const override { 82 return getISARevision(Name) != -1; 83 } 84 85 void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override; 86 87 bool setCPU(const std::string &Name) override { 88 CPU = Name; 89 ISARevision = getISARevision(CPU); 90 return ISARevision != -1; 91 } 92 93 bool 94 initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags, 95 StringRef CPU, 96 const std::vector<std::string> &FeaturesVec) const override { 97 int ISARevision = getISARevision(CPU); 98 if (ISARevision >= 10) 99 Features["transactional-execution"] = true; 100 if (ISARevision >= 11) 101 Features["vector"] = true; 102 if (ISARevision >= 12) 103 Features["vector-enhancements-1"] = true; 104 if (ISARevision >= 13) 105 Features["vector-enhancements-2"] = true; 106 return TargetInfo::initFeatureMap(Features, Diags, CPU, FeaturesVec); 107 } 108 109 bool handleTargetFeatures(std::vector<std::string> &Features, 110 DiagnosticsEngine &Diags) override { 111 HasTransactionalExecution = false; 112 HasVector = false; 113 SoftFloat = false; 114 for (const auto &Feature : Features) { 115 if (Feature == "+transactional-execution") 116 HasTransactionalExecution = true; 117 else if (Feature == "+vector") 118 HasVector = true; 119 else if (Feature == "+soft-float") 120 SoftFloat = true; 121 } 122 HasVector &= !SoftFloat; 123 124 // If we use the vector ABI, vector types are 64-bit aligned. 125 if (HasVector) { 126 MaxVectorAlign = 64; 127 resetDataLayout("E-m:e-i1:8:16-i8:8:16-i64:64-f128:64" 128 "-v128:64-a:8:16-n32:64"); 129 } 130 return true; 131 } 132 133 bool hasFeature(StringRef Feature) const override; 134 135 CallingConvCheckResult checkCallingConvention(CallingConv CC) const override { 136 switch (CC) { 137 case CC_C: 138 case CC_Swift: 139 case CC_OpenCLKernel: 140 return CCCR_OK; 141 default: 142 return CCCR_Warning; 143 } 144 } 145 146 StringRef getABI() const override { 147 if (HasVector) 148 return "vector"; 149 return ""; 150 } 151 152 const char *getLongDoubleMangling() const override { return "g"; } 153 154 bool hasExtIntType() const override { return true; } 155 }; 156 } // namespace targets 157 } // namespace clang 158 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_SYSTEMZ_H 159