[clang][modules] Don't prevent translation of FW_Private includes when explicitly...
[llvm-project.git] / clang / lib / Basic / Targets / RISCV.h
blobe5424d318401fb0cd79035c58d66300aacf35083
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.
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_CLANG_LIB_BASIC_TARGETS_RISCV_H
14 #define LLVM_CLANG_LIB_BASIC_TARGETS_RISCV_H
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>
23 namespace clang {
24 namespace targets {
26 // RISC-V Target
27 class RISCVTargetInfo : public TargetInfo {
28 protected:
29 std::string ABI, CPU;
30 std::unique_ptr<llvm::RISCVISAInfo> ISAInfo;
32 private:
33 bool FastUnalignedAccess;
35 public:
36 RISCVTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
37 : TargetInfo(Triple) {
38 BFloat16Width = 16;
39 BFloat16Align = 16;
40 BFloat16Format = &llvm::APFloat::BFloat();
41 LongDoubleWidth = 128;
42 LongDoubleAlign = 128;
43 LongDoubleFormat = &llvm::APFloat::IEEEquad();
44 SuitableAlign = 128;
45 WCharType = SignedInt;
46 WIntType = UnsignedInt;
47 HasRISCVVTypes = true;
48 MCountName = "_mcount";
49 HasFloat16 = true;
50 HasStrictFP = true;
53 bool setCPU(const std::string &Name) override {
54 if (!isValidCPUName(Name))
55 return false;
56 CPU = Name;
57 return true;
60 StringRef getABI() const override { return ABI; }
61 void getTargetDefines(const LangOptions &Opts,
62 MacroBuilder &Builder) const override;
64 ArrayRef<Builtin::Info> getTargetBuiltins() const override;
66 BuiltinVaListKind getBuiltinVaListKind() const override {
67 return TargetInfo::VoidPtrBuiltinVaList;
70 std::string_view getClobbers() const override { return ""; }
72 StringRef getConstraintRegister(StringRef Constraint,
73 StringRef Expression) const override {
74 return Expression;
77 ArrayRef<const char *> getGCCRegNames() const override;
79 int getEHDataRegisterNumber(unsigned RegNo) const override {
80 if (RegNo == 0)
81 return 10;
82 else if (RegNo == 1)
83 return 11;
84 else
85 return -1;
88 ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override;
90 bool validateAsmConstraint(const char *&Name,
91 TargetInfo::ConstraintInfo &Info) const override;
93 std::string convertConstraint(const char *&Constraint) const override;
95 bool
96 initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
97 StringRef CPU,
98 const std::vector<std::string> &FeaturesVec) const override;
100 std::optional<std::pair<unsigned, unsigned>>
101 getVScaleRange(const LangOptions &LangOpts) const override;
103 bool hasFeature(StringRef Feature) const override;
105 bool handleTargetFeatures(std::vector<std::string> &Features,
106 DiagnosticsEngine &Diags) override;
108 bool hasBitIntType() const override { return true; }
110 bool hasBFloat16Type() const override { return true; }
112 bool useFP16ConversionIntrinsics() const override {
113 return false;
116 bool isValidCPUName(StringRef Name) const override;
117 void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
118 bool isValidTuneCPUName(StringRef Name) const override;
119 void fillValidTuneCPUList(SmallVectorImpl<StringRef> &Values) const override;
121 class LLVM_LIBRARY_VISIBILITY RISCV32TargetInfo : public RISCVTargetInfo {
122 public:
123 RISCV32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
124 : RISCVTargetInfo(Triple, Opts) {
125 IntPtrType = SignedInt;
126 PtrDiffType = SignedInt;
127 SizeType = UnsignedInt;
128 resetDataLayout("e-m:e-p:32:32-i64:64-n32-S128");
131 bool setABI(const std::string &Name) override {
132 if (Name == "ilp32" || Name == "ilp32f" || Name == "ilp32d") {
133 ABI = Name;
134 return true;
136 return false;
139 void setMaxAtomicWidth() override {
140 MaxAtomicPromoteWidth = 128;
142 if (ISAInfo->hasExtension("a"))
143 MaxAtomicInlineWidth = 32;
146 class LLVM_LIBRARY_VISIBILITY RISCV64TargetInfo : public RISCVTargetInfo {
147 public:
148 RISCV64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
149 : RISCVTargetInfo(Triple, Opts) {
150 LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
151 IntMaxType = Int64Type = SignedLong;
152 resetDataLayout("e-m:e-p:64:64-i64:64-i128:128-n32:64-S128");
155 bool setABI(const std::string &Name) override {
156 if (Name == "lp64" || Name == "lp64f" || Name == "lp64d") {
157 ABI = Name;
158 return true;
160 return false;
163 void setMaxAtomicWidth() override {
164 MaxAtomicPromoteWidth = 128;
166 if (ISAInfo->hasExtension("a"))
167 MaxAtomicInlineWidth = 64;
170 } // namespace targets
171 } // namespace clang
173 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_RISCV_H