clang 22.0.0git
LoongArch.h
Go to the documentation of this file.
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
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;
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 BitIntMaxAlign = 128;
64 }
65
66 bool setCPU(const std::string &Name) override {
67 if (!isValidCPUName(Name))
68 return false;
69 CPU = Name;
70 return true;
71 }
72
73 StringRef getCPU() const { return CPU; }
74
75 StringRef getABI() const override { return ABI; }
76
77 void getTargetDefines(const LangOptions &Opts,
78 MacroBuilder &Builder) const override;
79
80 llvm::SmallVector<Builtin::InfosShard> getTargetBuiltins() const override;
81
83 return TargetInfo::VoidPtrBuiltinVaList;
84 }
85
86 std::string_view getClobbers() const override { return ""; }
87
88 ArrayRef<const char *> getGCCRegNames() const override;
89
90 int getEHDataRegisterNumber(unsigned RegNo) const override {
91 if (RegNo == 0)
92 return 4;
93 if (RegNo == 1)
94 return 5;
95 return -1;
96 }
97
98 ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override;
99
100 bool validateAsmConstraint(const char *&Name,
101 TargetInfo::ConstraintInfo &Info) const override;
102 std::string convertConstraint(const char *&Constraint) const override;
103
104 bool hasBitIntType() const override { return true; }
105
106 bool hasBFloat16Type() const override { return true; }
107
108 bool useFP16ConversionIntrinsics() const override { return false; }
109
110 bool handleTargetFeatures(std::vector<std::string> &Features,
111 DiagnosticsEngine &Diags) override;
112
113 ParsedTargetAttr parseTargetAttr(StringRef Str) const override;
114 bool supportsTargetAttributeTune() const override { return true; }
115
116 bool
117 initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
118 StringRef CPU,
119 const std::vector<std::string> &FeaturesVec) const override;
120
121 bool hasFeature(StringRef Feature) const override;
122
123 bool isValidCPUName(StringRef Name) const override;
124 void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
125 bool isValidFeatureName(StringRef Name) const override;
126};
127
128class LLVM_LIBRARY_VISIBILITY LoongArch32TargetInfo
129 : public LoongArchTargetInfo {
130public:
131 LoongArch32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
132 : LoongArchTargetInfo(Triple, Opts) {
133 IntPtrType = SignedInt;
134 PtrDiffType = SignedInt;
135 SizeType = UnsignedInt;
136 resetDataLayout("e-m:e-p:32:32-i64:64-n32-S128");
137 // TODO: select appropriate ABI.
138 setABI("ilp32d");
139 }
140
141 bool setABI(const std::string &Name) override {
142 if (Name == "ilp32d" || Name == "ilp32f" || Name == "ilp32s") {
143 ABI = Name;
144 return true;
145 }
146 return false;
147 }
148 void setMaxAtomicWidth() override {
149 MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 32;
150 }
151};
152
153class LLVM_LIBRARY_VISIBILITY LoongArch64TargetInfo
154 : public LoongArchTargetInfo {
155public:
156 LoongArch64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
157 : LoongArchTargetInfo(Triple, Opts) {
158 LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
159 IntMaxType = Int64Type = SignedLong;
160 HasUnalignedAccess = true;
161 resetDataLayout("e-m:e-p:64:64-i64:64-i128:128-n32:64-S128");
162 // TODO: select appropriate ABI.
163 setABI("lp64d");
164 }
165
166 bool setABI(const std::string &Name) override {
167 if (Name == "lp64d" || Name == "lp64f" || Name == "lp64s") {
168 ABI = Name;
169 return true;
170 }
171 return false;
172 }
173 void setMaxAtomicWidth() override {
174 MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
175 }
176};
177} // end namespace targets
178} // end namespace clang
179
180#endif // LLVM_CLANG_LIB_BASIC_TARGETS_LOONGARCH_H
static bool hasFeature(StringRef Feature, const LangOptions &LangOpts, const TargetInfo &Target)
Determine whether a translation unit built using the current language options has the given feature.
Definition: Module.cpp:95
Defines the clang::TargetOptions class.
Concrete class used by the front-end to report problems and issues.
Definition: Diagnostic.h:231
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:434
Exposes information about the current target.
Definition: TargetInfo.h:226
BuiltinVaListKind
The different kinds of __builtin_va_list types defined by the target implementation.
Definition: TargetInfo.h:330
Options for controlling the target.
Definition: TargetOptions.h:26
LoongArch32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: LoongArch.h:131
bool setABI(const std::string &Name) override
Use the specified ABI.
Definition: LoongArch.h:141
void setMaxAtomicWidth() override
Set the maximum inline or promote width lock-free atomic operation for the given target.
Definition: LoongArch.h:148
bool setABI(const std::string &Name) override
Use the specified ABI.
Definition: LoongArch.h:166
void setMaxAtomicWidth() override
Set the maximum inline or promote width lock-free atomic operation for the given target.
Definition: LoongArch.h:173
LoongArch64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: LoongArch.h:156
BuiltinVaListKind getBuiltinVaListKind() const override
Returns the kind of __builtin_va_list type that should be used with this target.
Definition: LoongArch.h:82
StringRef getABI() const override
Get the ABI currently in use.
Definition: LoongArch.h:75
bool hasBitIntType() const override
Determine whether the _BitInt type is supported on this target.
Definition: LoongArch.h:104
bool useFP16ConversionIntrinsics() const override
Check whether llvm intrinsics such as llvm.convert.to.fp16 should be used to convert to and from __fp...
Definition: LoongArch.h:108
bool hasBFloat16Type() const override
Determine whether the _BFloat16 type is supported on this target.
Definition: LoongArch.h:106
bool setCPU(const std::string &Name) override
Target the specified CPU.
Definition: LoongArch.h:66
int getEHDataRegisterNumber(unsigned RegNo) const override
Return the register number that __builtin_eh_return_regno would return with the specified argument.
Definition: LoongArch.h:90
LoongArchTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
Definition: LoongArch.h:40
bool supportsTargetAttributeTune() const override
Determine whether this TargetInfo supports tune in target attribute.
Definition: LoongArch.h:114
std::string_view getClobbers() const override
Returns a string of target-specific clobbers, in LLVM format.
Definition: LoongArch.h:86
Defines the clang::TargetInfo interface.
The JSON file list parser is used to communicate input to InstallAPI.
Contains information gathered from parsing the contents of TargetAttr.
Definition: TargetInfo.h:60