xref: /openbsd-src/gnu/llvm/clang/lib/Basic/Targets/SystemZ.h (revision c090f2041eb492fe987c78c48e798d9bc57c5191)
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 
33 public:
34   SystemZTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
35       : TargetInfo(Triple), CPU("z10"), ISARevision(8),
36         HasTransactionalExecution(false), HasVector(false) {
37     IntMaxType = SignedLong;
38     Int64Type = SignedLong;
39     TLSSupported = true;
40     IntWidth = IntAlign = 32;
41     LongWidth = LongLongWidth = LongAlign = LongLongAlign = 64;
42     PointerWidth = PointerAlign = 64;
43     LongDoubleWidth = 128;
44     LongDoubleAlign = 64;
45     LongDoubleFormat = &llvm::APFloat::IEEEquad();
46     DefaultAlignForAttributeAligned = 64;
47     MinGlobalAlign = 16;
48     resetDataLayout("E-m:e-i1:8:16-i8:8:16-i64:64-f128:64-a:8:16-n32:64");
49     MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
50     HasStrictFP = true;
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     for (const auto &Feature : Features) {
114       if (Feature == "+transactional-execution")
115         HasTransactionalExecution = true;
116       else if (Feature == "+vector")
117         HasVector = true;
118     }
119     // If we use the vector ABI, vector types are 64-bit aligned.
120     if (HasVector) {
121       MaxVectorAlign = 64;
122       resetDataLayout("E-m:e-i1:8:16-i8:8:16-i64:64-f128:64"
123                       "-v128:64-a:8:16-n32:64");
124     }
125     return true;
126   }
127 
128   bool hasFeature(StringRef Feature) const override;
129 
130   CallingConvCheckResult checkCallingConvention(CallingConv CC) const override {
131     switch (CC) {
132     case CC_C:
133     case CC_Swift:
134     case CC_OpenCLKernel:
135       return CCCR_OK;
136     default:
137       return CCCR_Warning;
138     }
139   }
140 
141   StringRef getABI() const override {
142     if (HasVector)
143       return "vector";
144     return "";
145   }
146 
147   const char *getLongDoubleMangling() const override { return "g"; }
148 };
149 } // namespace targets
150 } // namespace clang
151 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_SYSTEMZ_H
152