/src/llvm-project/clang/lib/Basic/Targets/RISCV.h
Line | Count | Source (jump to first uncovered line) |
1 | | //===--- RISCV.h - Declare RISC-V 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 RISC-V TargetInfo objects. |
10 | | // |
11 | | //===----------------------------------------------------------------------===// |
12 | | |
13 | | #ifndef LLVM_CLANG_LIB_BASIC_TARGETS_RISCV_H |
14 | | #define LLVM_CLANG_LIB_BASIC_TARGETS_RISCV_H |
15 | | |
16 | | #include "clang/Basic/TargetInfo.h" |
17 | | #include "clang/Basic/TargetOptions.h" |
18 | | #include "llvm/Support/Compiler.h" |
19 | | #include "llvm/Support/RISCVISAInfo.h" |
20 | | #include "llvm/TargetParser/Triple.h" |
21 | | #include <optional> |
22 | | |
23 | | namespace clang { |
24 | | namespace targets { |
25 | | |
26 | | // RISC-V Target |
27 | | class RISCVTargetInfo : public TargetInfo { |
28 | | protected: |
29 | | std::string ABI, CPU; |
30 | | std::unique_ptr<llvm::RISCVISAInfo> ISAInfo; |
31 | | |
32 | | private: |
33 | | bool FastUnalignedAccess; |
34 | | bool HasExperimental = false; |
35 | | |
36 | | public: |
37 | | RISCVTargetInfo(const llvm::Triple &Triple, const TargetOptions &) |
38 | 0 | : TargetInfo(Triple) { |
39 | 0 | BFloat16Width = 16; |
40 | 0 | BFloat16Align = 16; |
41 | 0 | BFloat16Format = &llvm::APFloat::BFloat(); |
42 | 0 | LongDoubleWidth = 128; |
43 | 0 | LongDoubleAlign = 128; |
44 | 0 | LongDoubleFormat = &llvm::APFloat::IEEEquad(); |
45 | 0 | SuitableAlign = 128; |
46 | 0 | WCharType = SignedInt; |
47 | 0 | WIntType = UnsignedInt; |
48 | 0 | HasRISCVVTypes = true; |
49 | 0 | MCountName = "_mcount"; |
50 | 0 | HasFloat16 = true; |
51 | 0 | HasStrictFP = true; |
52 | 0 | } |
53 | | |
54 | 0 | bool setCPU(const std::string &Name) override { |
55 | 0 | if (!isValidCPUName(Name)) |
56 | 0 | return false; |
57 | 0 | CPU = Name; |
58 | 0 | return true; |
59 | 0 | } |
60 | | |
61 | 0 | StringRef getABI() const override { return ABI; } |
62 | | void getTargetDefines(const LangOptions &Opts, |
63 | | MacroBuilder &Builder) const override; |
64 | | |
65 | | ArrayRef<Builtin::Info> getTargetBuiltins() const override; |
66 | | |
67 | 0 | BuiltinVaListKind getBuiltinVaListKind() const override { |
68 | 0 | return TargetInfo::VoidPtrBuiltinVaList; |
69 | 0 | } |
70 | | |
71 | 0 | std::string_view getClobbers() const override { return ""; } |
72 | | |
73 | | StringRef getConstraintRegister(StringRef Constraint, |
74 | 0 | StringRef Expression) const override { |
75 | 0 | return Expression; |
76 | 0 | } |
77 | | |
78 | | ArrayRef<const char *> getGCCRegNames() const override; |
79 | | |
80 | 0 | int getEHDataRegisterNumber(unsigned RegNo) const override { |
81 | 0 | if (RegNo == 0) |
82 | 0 | return 10; |
83 | 0 | else if (RegNo == 1) |
84 | 0 | return 11; |
85 | 0 | else |
86 | 0 | return -1; |
87 | 0 | } |
88 | | |
89 | | ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override; |
90 | | |
91 | | bool validateAsmConstraint(const char *&Name, |
92 | | TargetInfo::ConstraintInfo &Info) const override; |
93 | | |
94 | | std::string convertConstraint(const char *&Constraint) const override; |
95 | | |
96 | | bool |
97 | | initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags, |
98 | | StringRef CPU, |
99 | | const std::vector<std::string> &FeaturesVec) const override; |
100 | | |
101 | | std::optional<std::pair<unsigned, unsigned>> |
102 | | getVScaleRange(const LangOptions &LangOpts) const override; |
103 | | |
104 | | bool hasFeature(StringRef Feature) const override; |
105 | | |
106 | | bool handleTargetFeatures(std::vector<std::string> &Features, |
107 | | DiagnosticsEngine &Diags) override; |
108 | | |
109 | 0 | bool hasBitIntType() const override { return true; } |
110 | | |
111 | 0 | bool hasBFloat16Type() const override { return true; } |
112 | | |
113 | 0 | bool useFP16ConversionIntrinsics() const override { |
114 | 0 | return false; |
115 | 0 | } |
116 | | |
117 | | bool isValidCPUName(StringRef Name) const override; |
118 | | void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override; |
119 | | bool isValidTuneCPUName(StringRef Name) const override; |
120 | | void fillValidTuneCPUList(SmallVectorImpl<StringRef> &Values) const override; |
121 | 0 | bool supportsTargetAttributeTune() const override { return true; } |
122 | | ParsedTargetAttr parseTargetAttr(StringRef Str) const override; |
123 | | }; |
124 | | class LLVM_LIBRARY_VISIBILITY RISCV32TargetInfo : public RISCVTargetInfo { |
125 | | public: |
126 | | RISCV32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) |
127 | 0 | : RISCVTargetInfo(Triple, Opts) { |
128 | 0 | IntPtrType = SignedInt; |
129 | 0 | PtrDiffType = SignedInt; |
130 | 0 | SizeType = UnsignedInt; |
131 | 0 | resetDataLayout("e-m:e-p:32:32-i64:64-n32-S128"); |
132 | 0 | } |
133 | | |
134 | 0 | bool setABI(const std::string &Name) override { |
135 | 0 | if (Name == "ilp32e") { |
136 | 0 | ABI = Name; |
137 | 0 | resetDataLayout("e-m:e-p:32:32-i64:64-n32-S32"); |
138 | 0 | return true; |
139 | 0 | } |
140 | | |
141 | 0 | if (Name == "ilp32" || Name == "ilp32f" || Name == "ilp32d") { |
142 | 0 | ABI = Name; |
143 | 0 | return true; |
144 | 0 | } |
145 | 0 | return false; |
146 | 0 | } |
147 | | |
148 | 0 | void setMaxAtomicWidth() override { |
149 | 0 | MaxAtomicPromoteWidth = 128; |
150 | |
|
151 | 0 | if (ISAInfo->hasExtension("a")) |
152 | 0 | MaxAtomicInlineWidth = 32; |
153 | 0 | } |
154 | | }; |
155 | | class LLVM_LIBRARY_VISIBILITY RISCV64TargetInfo : public RISCVTargetInfo { |
156 | | public: |
157 | | RISCV64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) |
158 | 0 | : RISCVTargetInfo(Triple, Opts) { |
159 | 0 | LongWidth = LongAlign = PointerWidth = PointerAlign = 64; |
160 | 0 | IntMaxType = Int64Type = SignedLong; |
161 | 0 | resetDataLayout("e-m:e-p:64:64-i64:64-i128:128-n32:64-S128"); |
162 | 0 | } |
163 | | |
164 | 0 | bool setABI(const std::string &Name) override { |
165 | 0 | if (Name == "lp64e") { |
166 | 0 | ABI = Name; |
167 | 0 | resetDataLayout("e-m:e-p:64:64-i64:64-i128:128-n32:64-S64"); |
168 | 0 | return true; |
169 | 0 | } |
170 | | |
171 | 0 | if (Name == "lp64" || Name == "lp64f" || Name == "lp64d") { |
172 | 0 | ABI = Name; |
173 | 0 | return true; |
174 | 0 | } |
175 | 0 | return false; |
176 | 0 | } |
177 | | |
178 | 0 | void setMaxAtomicWidth() override { |
179 | 0 | MaxAtomicPromoteWidth = 128; |
180 | |
|
181 | 0 | if (ISAInfo->hasExtension("a")) |
182 | 0 | MaxAtomicInlineWidth = 64; |
183 | 0 | } |
184 | | }; |
185 | | } // namespace targets |
186 | | } // namespace clang |
187 | | |
188 | | #endif // LLVM_CLANG_LIB_BASIC_TARGETS_RISCV_H |