clang 23.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;
39
40public:
41 LoongArchTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
42 : TargetInfo(Triple) {
43 HasFeature32S = false;
44 HasFeatureD = false;
45 HasFeatureF = false;
46 HasFeatureLSX = false;
47 HasFeatureLASX = false;
48 HasFeatureFrecipe = false;
49 HasFeatureLAM_BH = false;
50 HasFeatureLAMCAS = false;
51 HasFeatureLD_SEQ_SA = false;
52 HasFeatureDiv32 = false;
53 HasFeatureSCQ = false;
54 BFloat16Width = 16;
55 BFloat16Align = 16;
56 BFloat16Format = &llvm::APFloat::BFloat();
57 LongDoubleWidth = 128;
58 LongDoubleAlign = 128;
59 LongDoubleFormat = &llvm::APFloat::IEEEquad();
60 MCountName = "_mcount";
61 HasFloat16 = true;
62 SuitableAlign = 128;
65 BitIntMaxAlign = 128;
66 }
67
68 bool setCPU(const std::string &Name) override {
69 if (!isValidCPUName(Name))
70 return false;
71 CPU = Name;
72 return true;
73 }
74
75 StringRef getCPU() const { return CPU; }
76
77 StringRef getABI() const override { return ABI; }
78
79 void getTargetDefines(const LangOptions &Opts,
80 MacroBuilder &Builder) const override;
81
82 llvm::SmallVector<Builtin::InfosShard> getTargetBuiltins() const override;
83
87
88 std::string_view getClobbers() const override { return ""; }
89
90 ArrayRef<const char *> getGCCRegNames() const override;
91
92 int getEHDataRegisterNumber(unsigned RegNo) const override {
93 if (RegNo == 0)
94 return 4;
95 if (RegNo == 1)
96 return 5;
97 return -1;
98 }
99
100 ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override;
101
102 bool validateAsmConstraint(const char *&Name,
103 TargetInfo::ConstraintInfo &Info) const override;
104 std::string convertConstraint(const char *&Constraint) const override;
105
106 bool hasBitIntType() const override { return true; }
107
108 bool hasBFloat16Type() const override { return true; }
109
110 bool useFP16ConversionIntrinsics() const override { return false; }
111
112 bool handleTargetFeatures(std::vector<std::string> &Features,
113 DiagnosticsEngine &Diags) override;
114
115 ParsedTargetAttr parseTargetAttr(StringRef Str) const override;
116 bool supportsTargetAttributeTune() const override { return true; }
117
118 bool
119 initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
120 StringRef CPU,
121 const std::vector<std::string> &FeaturesVec) const override;
122
123 bool hasFeature(StringRef Feature) const override;
124
125 bool isValidCPUName(StringRef Name) const override;
126 void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
127 bool isValidFeatureName(StringRef Name) const override;
128};
129
130class LLVM_LIBRARY_VISIBILITY LoongArch32TargetInfo
131 : public LoongArchTargetInfo {
132public:
133 LoongArch32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
134 : LoongArchTargetInfo(Triple, Opts) {
138 // TODO: select appropriate ABI.
139 setABI("ilp32d");
141 }
142
143 bool setABI(const std::string &Name) override {
144 if (Name == "ilp32d" || Name == "ilp32f" || Name == "ilp32s") {
145 ABI = Name;
146 return true;
147 }
148 return false;
149 }
153};
154
155class LLVM_LIBRARY_VISIBILITY LoongArch64TargetInfo
156 : public LoongArchTargetInfo {
157public:
158 LoongArch64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
159 : LoongArchTargetInfo(Triple, Opts) {
162 HasUnalignedAccess = true;
163 // TODO: select appropriate ABI.
164 setABI("lp64d");
166 }
167
168 bool setABI(const std::string &Name) override {
169 if (Name == "lp64d" || Name == "lp64f" || Name == "lp64s") {
170 ABI = Name;
171 return true;
172 }
173 return false;
174 }
178};
179} // end namespace targets
180} // end namespace clang
181
182#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:232
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
TargetInfo(const llvm::Triple &T)
BuiltinVaListKind
The different kinds of __builtin_va_list types defined by the target implementation.
Definition TargetInfo.h:333
@ VoidPtrBuiltinVaList
typedef void* __builtin_va_list;
Definition TargetInfo.h:338
const char * MCountName
Definition TargetInfo.h:255
unsigned HasUnalignedAccess
Definition TargetInfo.h:284
unsigned char MaxAtomicPromoteWidth
Definition TargetInfo.h:252
void resetDataLayout(StringRef DL)
Set the data layout to the given string.
unsigned char MaxAtomicInlineWidth
Definition TargetInfo.h:252
Options for controlling the target.
LoongArch32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition LoongArch.h:133
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
bool setABI(const std::string &Name) override
Use the specified ABI.
Definition LoongArch.h:168
void setMaxAtomicWidth() override
Set the maximum inline or promote width lock-free atomic operation for the given target.
Definition LoongArch.h:175
LoongArch64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition LoongArch.h:158
BuiltinVaListKind getBuiltinVaListKind() const override
Returns the kind of __builtin_va_list type that should be used with this target.
Definition LoongArch.h:84
StringRef getABI() const override
Get the ABI currently in use.
Definition LoongArch.h:77
bool isValidCPUName(StringRef Name) const override
Determine whether this TargetInfo supports the given CPU name.
bool hasBitIntType() const override
Determine whether the _BitInt type is supported on this target.
Definition LoongArch.h:106
bool useFP16ConversionIntrinsics() const override
Check whether conversions to and from __fp16 should go through an integer bitcast with i16.
Definition LoongArch.h:110
bool hasBFloat16Type() const override
Determine whether the _BFloat16 type is supported on this target.
Definition LoongArch.h:108
bool setCPU(const std::string &Name) override
Target the specified CPU.
Definition LoongArch.h:68
int getEHDataRegisterNumber(unsigned RegNo) const override
Return the register number that __builtin_eh_return_regno would return with the specified argument.
Definition LoongArch.h:92
LoongArchTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
Definition LoongArch.h:41
bool supportsTargetAttributeTune() const override
Determine whether this TargetInfo supports tune in target attribute.
Definition LoongArch.h:116
std::string_view getClobbers() const override
Returns a string of target-specific clobbers, in LLVM format.
Definition LoongArch.h:88
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
const llvm::fltSemantics * LongDoubleFormat
Definition TargetInfo.h:143
std::optional< unsigned > BitIntMaxAlign
Definition TargetInfo.h:106
const llvm::fltSemantics * BFloat16Format
Definition TargetInfo.h:142