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