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;
37
38public:
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;
57 }
58
59 bool setCPU(const std::string &Name) override {
60 if (!isValidCPUName(Name))
61 return false;
62 CPU = Name;
63 return true;
64 }
65
66 StringRef getCPU() const { return CPU; }
67
68 StringRef getABI() const override { return ABI; }
69
70 void getTargetDefines(const LangOptions &Opts,
71 MacroBuilder &Builder) const override;
72
73 ArrayRef<Builtin::Info> getTargetBuiltins() const override;
74
76 return TargetInfo::VoidPtrBuiltinVaList;
77 }
78
79 std::string_view getClobbers() const override { return ""; }
80
81 ArrayRef<const char *> getGCCRegNames() const override;
82
83 int getEHDataRegisterNumber(unsigned RegNo) const override {
84 if (RegNo == 0)
85 return 4;
86 if (RegNo == 1)
87 return 5;
88 return -1;
89 }
90
91 ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override;
92
93 bool validateAsmConstraint(const char *&Name,
94 TargetInfo::ConstraintInfo &Info) const override;
95 std::string convertConstraint(const char *&Constraint) const override;
96
97 bool hasBitIntType() const override { return true; }
98
99 bool handleTargetFeatures(std::vector<std::string> &Features,
100 DiagnosticsEngine &Diags) override;
101
102 bool
103 initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
104 StringRef CPU,
105 const std::vector<std::string> &FeaturesVec) const override;
106
107 bool hasFeature(StringRef Feature) const override;
108
109 bool isValidCPUName(StringRef Name) const override;
110 void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
111};
112
113class LLVM_LIBRARY_VISIBILITY LoongArch32TargetInfo
114 : public LoongArchTargetInfo {
115public:
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");
124 }
125
126 bool setABI(const std::string &Name) override {
127 if (Name == "ilp32d" || Name == "ilp32f" || Name == "ilp32s") {
128 ABI = Name;
129 return true;
130 }
131 return false;
132 }
133 void setMaxAtomicWidth() override {
134 MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 32;
135 }
136};
137
138class LLVM_LIBRARY_VISIBILITY LoongArch64TargetInfo
139 : public LoongArchTargetInfo {
140public:
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");
149 }
150
151 bool setABI(const std::string &Name) override {
152 if (Name == "lp64d" || Name == "lp64f" || Name == "lp64s") {
153 ABI = Name;
154 return true;
155 }
156 return false;
157 }
158 void setMaxAtomicWidth() override {
159 MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
160 }
161};
162} // end namespace targets
163} // end namespace clang
164
165#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:116
bool setABI(const std::string &Name) override
Use the specified ABI.
Definition: LoongArch.h:126
void setMaxAtomicWidth() override
Set the maximum inline or promote width lock-free atomic operation for the given target.
Definition: LoongArch.h:133
bool setABI(const std::string &Name) override
Use the specified ABI.
Definition: LoongArch.h:151
void setMaxAtomicWidth() override
Set the maximum inline or promote width lock-free atomic operation for the given target.
Definition: LoongArch.h:158
LoongArch64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition: LoongArch.h:141
BuiltinVaListKind getBuiltinVaListKind() const override
Returns the kind of __builtin_va_list type that should be used with this target.
Definition: LoongArch.h:75
StringRef getABI() const override
Get the ABI currently in use.
Definition: LoongArch.h:68
bool hasBitIntType() const override
Determine whether the _BitInt type is supported on this target.
Definition: LoongArch.h:97
bool setCPU(const std::string &Name) override
Target the specified CPU.
Definition: LoongArch.h:59
int getEHDataRegisterNumber(unsigned RegNo) const override
Return the register number that __builtin_eh_return_regno would return with the specified argument.
Definition: LoongArch.h:83
LoongArchTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
Definition: LoongArch.h:39
std::string_view getClobbers() const override
Returns a string of target-specific clobbers, in LLVM format.
Definition: LoongArch.h:79
Defines the clang::TargetInfo interface.
The JSON file list parser is used to communicate input to InstallAPI.