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.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CLANG_LIB_BASIC_TARGETS_LOONGARCH_H
14#define LLVM_CLANG_LIB_BASIC_TARGETS_LOONGARCH_H
15
16#include "clang/Basic/TargetInfo.h"
17#include "clang/Basic/TargetOptions.h"
18#include "llvm/Support/Compiler.h"
19#include "llvm/TargetParser/Triple.h"
20
21namespace clang {
22namespace targets {
23
24class LLVM_LIBRARY_VISIBILITY LoongArchTargetInfo : public TargetInfo {
25protected:
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;
37 bool HasFeatureSCQ;
38
39public:
40 LoongArchTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
41 : TargetInfo(Triple) {
42 HasFeatureD = false;
43 HasFeatureF = false;
44 HasFeatureLSX = false;
45 HasFeatureLASX = false;
46 HasFeatureFrecipe = false;
47 HasFeatureLAM_BH = false;
48 HasFeatureLAMCAS = false;
49 HasFeatureLD_SEQ_SA = false;
50 HasFeatureDiv32 = false;
51 HasFeatureSCQ = false;
52 BFloat16Width = 16;
53 BFloat16Align = 16;
54 BFloat16Format = &llvm::APFloat::BFloat();
55 LongDoubleWidth = 128;
56 LongDoubleAlign = 128;
57 LongDoubleFormat = &llvm::APFloat::IEEEquad();
58 MCountName = "_mcount";
59 HasFloat16 = true;
60 SuitableAlign = 128;
61 WCharType = SignedInt;
62 WIntType = UnsignedInt;
63 }
64
65 bool setCPU(const std::string &Name) override {
66 if (!isValidCPUName(Name))
67 return false;
68 CPU = Name;
69 return true;
70 }
71
72 StringRef getCPU() const { return CPU; }
73
74 StringRef getABI() const override { return ABI; }
75
76 void getTargetDefines(const LangOptions &Opts,
77 MacroBuilder &Builder) const override;
78
79 llvm::SmallVector<Builtin::InfosShard> getTargetBuiltins() const override;
80
81 BuiltinVaListKind getBuiltinVaListKind() const override {
82 return TargetInfo::VoidPtrBuiltinVaList;
83 }
84
85 std::string_view getClobbers() const override { return ""; }
86
87 ArrayRef<const char *> getGCCRegNames() const override;
88
89 int getEHDataRegisterNumber(unsigned RegNo) const override {
90 if (RegNo == 0)
91 return 4;
92 if (RegNo == 1)
93 return 5;
94 return -1;
95 }
96
97 ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override;
98
99 bool validateAsmConstraint(const char *&Name,
100 TargetInfo::ConstraintInfo &Info) const override;
101 std::string convertConstraint(const char *&Constraint) const override;
102
103 bool hasBitIntType() const override { return true; }
104
105 bool hasBFloat16Type() const override { return true; }
106
107 bool useFP16ConversionIntrinsics() const override { return false; }
108
109 bool handleTargetFeatures(std::vector<std::string> &Features,
110 DiagnosticsEngine &Diags) override;
111
112 ParsedTargetAttr parseTargetAttr(StringRef Str) const override;
113 bool supportsTargetAttributeTune() const override { return true; }
114
115 bool
116 initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
117 StringRef CPU,
118 const std::vector<std::string> &FeaturesVec) const override;
119
120 bool hasFeature(StringRef Feature) const override;
121
122 bool isValidCPUName(StringRef Name) const override;
123 void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
124 bool isValidFeatureName(StringRef Name) const override;
125};
126
127class LLVM_LIBRARY_VISIBILITY LoongArch32TargetInfo
128 : public LoongArchTargetInfo {
129public:
130 LoongArch32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
131 : LoongArchTargetInfo(Triple, Opts) {
132 IntPtrType = SignedInt;
133 PtrDiffType = SignedInt;
134 SizeType = UnsignedInt;
135 resetDataLayout(DL: "e-m:e-p:32:32-i64:64-n32-S128");
136 // TODO: select appropriate ABI.
137 setABI("ilp32d");
138 }
139
140 bool setABI(const std::string &Name) override {
141 if (Name == "ilp32d" || Name == "ilp32f" || Name == "ilp32s") {
142 ABI = Name;
143 return true;
144 }
145 return false;
146 }
147 void setMaxAtomicWidth() override {
148 MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 32;
149 }
150};
151
152class LLVM_LIBRARY_VISIBILITY LoongArch64TargetInfo
153 : public LoongArchTargetInfo {
154public:
155 LoongArch64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
156 : LoongArchTargetInfo(Triple, Opts) {
157 LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
158 IntMaxType = Int64Type = SignedLong;
159 HasUnalignedAccess = true;
160 resetDataLayout(DL: "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128");
161 // TODO: select appropriate ABI.
162 setABI("lp64d");
163 }
164
165 bool setABI(const std::string &Name) override {
166 if (Name == "lp64d" || Name == "lp64f" || Name == "lp64s") {
167 ABI = Name;
168 return true;
169 }
170 return false;
171 }
172 void setMaxAtomicWidth() override {
173 MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
174 }
175};
176} // end namespace targets
177} // end namespace clang
178
179#endif // LLVM_CLANG_LIB_BASIC_TARGETS_LOONGARCH_H
180

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

source code of clang/lib/Basic/Targets/LoongArch.h