clang 20.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 LongDoubleWidth = 128;
53 LongDoubleAlign = 128;
54 LongDoubleFormat = &llvm::APFloat::IEEEquad();
55 MCountName = "_mcount";
56 SuitableAlign = 128;
57 WCharType = SignedInt;
58 WIntType = UnsignedInt;
59 }
60
61 bool setCPU(const std::string &Name) override {
62 if (!isValidCPUName(Name))
63 return false;
64 CPU = Name;
65 return true;
66 }
67
68 StringRef getCPU() const { return CPU; }
69
70 StringRef getABI() const override { return ABI; }
71
72 void getTargetDefines(const LangOptions &Opts,
73 MacroBuilder &Builder) const override;
74
75 ArrayRef<Builtin::Info> getTargetBuiltins() const override;
76
78 return TargetInfo::VoidPtrBuiltinVaList;
79 }
80
81 std::string_view getClobbers() const override { return ""; }
82
83 ArrayRef<const char *> getGCCRegNames() const override;
84
85 int getEHDataRegisterNumber(unsigned RegNo) const override {
86 if (RegNo == 0)
87 return 4;
88 if (RegNo == 1)
89 return 5;
90 return -1;
91 }
92
93 ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override;
94
95 bool validateAsmConstraint(const char *&Name,
96 TargetInfo::ConstraintInfo &Info) const override;
97 std::string convertConstraint(const char *&Constraint) const override;
98
99 bool hasBitIntType() const override { return true; }
100
101 bool handleTargetFeatures(std::vector<std::string> &Features,
102 DiagnosticsEngine &Diags) override;
103
104 bool
105 initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
106 StringRef CPU,
107 const std::vector<std::string> &FeaturesVec) const override;
108
109 bool hasFeature(StringRef Feature) const override;
110
111 bool isValidCPUName(StringRef Name) const override;
112 void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
113};
114
115class LLVM_LIBRARY_VISIBILITY LoongArch32TargetInfo
116 : public LoongArchTargetInfo {
117public:
118 LoongArch32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
119 : LoongArchTargetInfo(Triple, Opts) {
120 IntPtrType = SignedInt;
121 PtrDiffType = SignedInt;
122 SizeType = UnsignedInt;
123 resetDataLayout("e-m:e-p:32:32-i64:64-n32-S128");
124 // TODO: select appropriate ABI.
125 setABI("ilp32d");
126 }
127
128 bool setABI(const std::string &Name) override {
129 if (Name == "ilp32d" || Name == "ilp32f" || Name == "ilp32s") {
130 ABI = Name;
131 return true;
132 }
133 return false;
134 }
135 void setMaxAtomicWidth() override {
136 MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 32;
137 }
138};
139
140class LLVM_LIBRARY_VISIBILITY LoongArch64TargetInfo
141 : public LoongArchTargetInfo {
142public:
143 LoongArch64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
144 : LoongArchTargetInfo(Triple, Opts) {
145 LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
146 IntMaxType = Int64Type = SignedLong;
147 HasUnalignedAccess = true;
148 resetDataLayout("e-m:e-p:64:64-i64:64-i128:128-n32:64-S128");
149 // TODO: select appropriate ABI.
150 setABI("lp64d");
151 }
152
153 bool setABI(const std::string &Name) override {
154 if (Name == "lp64d" || Name == "lp64f" || Name == "lp64s") {
155 ABI = Name;
156 return true;
157 }
158 return false;
159 }
160 void setMaxAtomicWidth() override {
161 MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
162 }
163};
164} // end namespace targets
165} // end namespace clang
166
167#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:96
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:499
Exposes information about the current target.
Definition: TargetInfo.h:220
BuiltinVaListKind
The different kinds of __builtin_va_list types defined by the target implementation.
Definition: TargetInfo.h:318
Options for controlling the target.
Definition: TargetOptions.h:26
LoongArch32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: LoongArch.h:118
bool setABI(const std::string &Name) override
Use the specified ABI.
Definition: LoongArch.h:128
void setMaxAtomicWidth() override
Set the maximum inline or promote width lock-free atomic operation for the given target.
Definition: LoongArch.h:135
bool setABI(const std::string &Name) override
Use the specified ABI.
Definition: LoongArch.h:153
void setMaxAtomicWidth() override
Set the maximum inline or promote width lock-free atomic operation for the given target.
Definition: LoongArch.h:160
LoongArch64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: LoongArch.h:143
BuiltinVaListKind getBuiltinVaListKind() const override
Returns the kind of __builtin_va_list type that should be used with this target.
Definition: LoongArch.h:77
StringRef getABI() const override
Get the ABI currently in use.
Definition: LoongArch.h:70
bool hasBitIntType() const override
Determine whether the _BitInt type is supported on this target.
Definition: LoongArch.h:99
bool setCPU(const std::string &Name) override
Target the specified CPU.
Definition: LoongArch.h:61
int getEHDataRegisterNumber(unsigned RegNo) const override
Return the register number that __builtin_eh_return_regno would return with the specified argument.
Definition: LoongArch.h:85
LoongArchTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
Definition: LoongArch.h:40
std::string_view getClobbers() const override
Returns a string of target-specific clobbers, in LLVM format.
Definition: LoongArch.h:81
Defines the clang::TargetInfo interface.
The JSON file list parser is used to communicate input to InstallAPI.