clang 24.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(StringRef 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 StringRef getConstraintRegister(StringRef Constraint,
91 StringRef Expression) const override {
92 return Expression;
93 }
94
95 ArrayRef<const char *> getGCCRegNames() const override;
96
97 int getEHDataRegisterNumber(unsigned RegNo) const override {
98 if (RegNo == 0)
99 return 4;
100 if (RegNo == 1)
101 return 5;
102 return -1;
103 }
104
105 ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override;
106
107 bool validateAsmConstraint(const char *&Name,
108 TargetInfo::ConstraintInfo &Info) const override;
109 std::string convertConstraint(const char *&Constraint) const override;
110
111 bool hasBitIntType() const override { return true; }
112
113 bool hasBFloat16Type() const override { return true; }
114
115 bool handleTargetFeatures(std::vector<std::string> &Features,
116 DiagnosticsEngine &Diags) override;
117
118 ParsedTargetAttr parseTargetAttr(StringRef Str) const override;
119 bool supportsTargetAttributeTune() const override { return true; }
120
121 bool
122 initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
123 StringRef CPU,
124 const std::vector<std::string> &FeaturesVec) const override;
125
126 bool hasFeature(StringRef Feature) const override;
127
128 bool isValidCPUName(StringRef Name) const override;
129 void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
130 bool isValidFeatureName(StringRef Name) const override;
131};
132
133class LLVM_LIBRARY_VISIBILITY LoongArch32TargetInfo
134 : public LoongArchTargetInfo {
135public:
136 LoongArch32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
137 : LoongArchTargetInfo(Triple, Opts) {
141 // TODO: select appropriate ABI.
142 setABI("ilp32d");
144 }
145
146 bool setABI(const std::string &Name) override {
147 if (Name == "ilp32d" || Name == "ilp32f" || Name == "ilp32s") {
148 ABI = Name;
149 return true;
150 }
151 return false;
152 }
156};
157
158class LLVM_LIBRARY_VISIBILITY LoongArch64TargetInfo
159 : public LoongArchTargetInfo {
160public:
161 LoongArch64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
162 : LoongArchTargetInfo(Triple, Opts) {
165 HasUnalignedAccess = true;
166 // TODO: select appropriate ABI.
167 setABI("lp64d");
169 }
170
171 bool setABI(const std::string &Name) override {
172 if (Name == "lp64d" || Name == "lp64f" || Name == "lp64s") {
173 ABI = Name;
174 return true;
175 }
176 return false;
177 }
181};
182} // end namespace targets
183} // end namespace clang
184
185#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:234
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:340
@ VoidPtrBuiltinVaList
typedef void* __builtin_va_list;
Definition TargetInfo.h:345
const char * MCountName
Definition TargetInfo.h:256
unsigned HasUnalignedAccess
Definition TargetInfo.h:288
unsigned char MaxAtomicPromoteWidth
Definition TargetInfo.h:253
void resetDataLayout(StringRef DL)
Set the data layout to the given string.
unsigned char MaxAtomicInlineWidth
Definition TargetInfo.h:253
Options for controlling the target.
LoongArch32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition LoongArch.h:136
bool setABI(const std::string &Name) override
Use the specified ABI.
Definition LoongArch.h:146
void setMaxAtomicWidth() override
Set the maximum inline or promote width lock-free atomic operation for the given target.
Definition LoongArch.h:153
bool setABI(const std::string &Name) override
Use the specified ABI.
Definition LoongArch.h:171
void setMaxAtomicWidth() override
Set the maximum inline or promote width lock-free atomic operation for the given target.
Definition LoongArch.h:178
LoongArch64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
Definition LoongArch.h:161
StringRef getConstraintRegister(StringRef Constraint, StringRef Expression) const override
Extracts a register from the passed constraint (if it is a single-register constraint) and the asm la...
Definition LoongArch.h:90
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:111
bool hasBFloat16Type() const override
Determine whether the _BFloat16 type is supported on this target.
Definition LoongArch.h:113
bool setCPU(StringRef 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:97
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:119
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.
Top level wrappers for InstallAPI frontend operations.
Contains information gathered from parsing the contents of TargetAttr.
Definition TargetInfo.h:60
const llvm::fltSemantics * LongDoubleFormat
Definition TargetInfo.h:144
std::optional< unsigned > BitIntMaxAlign
Definition TargetInfo.h:106
const llvm::fltSemantics * BFloat16Format
Definition TargetInfo.h:143