[libc] Deprecate LLVM_ENABLE_PROJECTS in favor of LLVM_ENABLE_RUNTIMES. (#117265)
[llvm-project.git] / clang / lib / Basic / Targets / LoongArch.h
blobabaa05aa42d43896248e9d80f28d88dae2867004
1 //===-- LoongArch.h - Declare LoongArch 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 LoongArch TargetInfo objects.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_CLANG_LIB_BASIC_TARGETS_LOONGARCH_H
14 #define LLVM_CLANG_LIB_BASIC_TARGETS_LOONGARCH_H
16 #include "clang/Basic/TargetInfo.h"
17 #include "clang/Basic/TargetOptions.h"
18 #include "llvm/Support/Compiler.h"
19 #include "llvm/TargetParser/Triple.h"
21 namespace clang {
22 namespace targets {
24 class LLVM_LIBRARY_VISIBILITY LoongArchTargetInfo : public TargetInfo {
25 protected:
26 std::string ABI;
27 std::string CPU;
28 bool HasFeatureD;
29 bool HasFeatureF;
30 bool HasFeatureLSX;
31 bool HasFeatureLASX;
32 bool HasFeatureFrecipe;
33 bool HasFeatureLAM_BH;
34 bool HasFeatureLAMCAS;
35 bool HasFeatureLD_SEQ_SA;
36 bool HasFeatureDiv32;
38 public:
39 LoongArchTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
40 : TargetInfo(Triple) {
41 HasFeatureD = false;
42 HasFeatureF = false;
43 HasFeatureLSX = false;
44 HasFeatureLASX = false;
45 HasFeatureFrecipe = false;
46 HasFeatureLAM_BH = false;
47 HasFeatureLAMCAS = false;
48 HasFeatureLD_SEQ_SA = false;
49 HasFeatureDiv32 = false;
50 LongDoubleWidth = 128;
51 LongDoubleAlign = 128;
52 LongDoubleFormat = &llvm::APFloat::IEEEquad();
53 MCountName = "_mcount";
54 SuitableAlign = 128;
55 WCharType = SignedInt;
56 WIntType = UnsignedInt;
59 bool setCPU(const std::string &Name) override {
60 if (!isValidCPUName(Name))
61 return false;
62 CPU = Name;
63 return true;
66 StringRef getCPU() const { return CPU; }
68 StringRef getABI() const override { return ABI; }
70 void getTargetDefines(const LangOptions &Opts,
71 MacroBuilder &Builder) const override;
73 ArrayRef<Builtin::Info> getTargetBuiltins() const override;
75 BuiltinVaListKind getBuiltinVaListKind() const override {
76 return TargetInfo::VoidPtrBuiltinVaList;
79 std::string_view getClobbers() const override { return ""; }
81 ArrayRef<const char *> getGCCRegNames() const override;
83 int getEHDataRegisterNumber(unsigned RegNo) const override {
84 if (RegNo == 0)
85 return 4;
86 if (RegNo == 1)
87 return 5;
88 return -1;
91 ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override;
93 bool validateAsmConstraint(const char *&Name,
94 TargetInfo::ConstraintInfo &Info) const override;
95 std::string convertConstraint(const char *&Constraint) const override;
97 bool hasBitIntType() const override { return true; }
99 bool handleTargetFeatures(std::vector<std::string> &Features,
100 DiagnosticsEngine &Diags) override;
102 bool
103 initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
104 StringRef CPU,
105 const std::vector<std::string> &FeaturesVec) const override;
107 bool hasFeature(StringRef Feature) const override;
109 bool isValidCPUName(StringRef Name) const override;
110 void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
113 class LLVM_LIBRARY_VISIBILITY LoongArch32TargetInfo
114 : public LoongArchTargetInfo {
115 public:
116 LoongArch32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
117 : LoongArchTargetInfo(Triple, Opts) {
118 IntPtrType = SignedInt;
119 PtrDiffType = SignedInt;
120 SizeType = UnsignedInt;
121 resetDataLayout("e-m:e-p:32:32-i64:64-n32-S128");
122 // TODO: select appropriate ABI.
123 setABI("ilp32d");
126 bool setABI(const std::string &Name) override {
127 if (Name == "ilp32d" || Name == "ilp32f" || Name == "ilp32s") {
128 ABI = Name;
129 return true;
131 return false;
133 void setMaxAtomicWidth() override {
134 MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 32;
138 class LLVM_LIBRARY_VISIBILITY LoongArch64TargetInfo
139 : public LoongArchTargetInfo {
140 public:
141 LoongArch64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
142 : LoongArchTargetInfo(Triple, Opts) {
143 LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
144 IntMaxType = Int64Type = SignedLong;
145 HasUnalignedAccess = true;
146 resetDataLayout("e-m:e-p:64:64-i64:64-i128:128-n32:64-S128");
147 // TODO: select appropriate ABI.
148 setABI("lp64d");
151 bool setABI(const std::string &Name) override {
152 if (Name == "lp64d" || Name == "lp64f" || Name == "lp64s") {
153 ABI = Name;
154 return true;
156 return false;
158 void setMaxAtomicWidth() override {
159 MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
162 } // end namespace targets
163 } // end namespace clang
165 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_LOONGARCH_H