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