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