xref: /netbsd-src/external/apache2/llvm/dist/clang/lib/Basic/Targets/RISCV.h (revision e038c9c4676b0f19b1b7dd08a940c6ed64a6d5ae)
1 //===--- RISCV.h - Declare RISCV 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 RISCV 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/ADT/Triple.h"
19 #include "llvm/Support/Compiler.h"
20 
21 namespace clang {
22 namespace targets {
23 
24 // RISC-V Target
25 class RISCVTargetInfo : public TargetInfo {
26 protected:
27   std::string ABI, CPU;
28   bool HasM = false;
29   bool HasA = false;
30   bool HasF = false;
31   bool HasD = false;
32   bool HasC = false;
33   bool HasB = false;
34   bool HasV = false;
35   bool HasZba = false;
36   bool HasZbb = false;
37   bool HasZbc = false;
38   bool HasZbe = false;
39   bool HasZbf = false;
40   bool HasZbm = false;
41   bool HasZbp = false;
42   bool HasZbproposedc = false;
43   bool HasZbr = false;
44   bool HasZbs = false;
45   bool HasZbt = false;
46   bool HasZfh = false;
47   bool HasZvamo = false;
48   bool HasZvlsseg = false;
49 
50   static const Builtin::Info BuiltinInfo[];
51 
52 public:
RISCVTargetInfo(const llvm::Triple & Triple,const TargetOptions &)53   RISCVTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
54       : TargetInfo(Triple) {
55     LongDoubleWidth = 128;
56     LongDoubleAlign = 128;
57     LongDoubleFormat = &llvm::APFloat::IEEEquad();
58     SuitableAlign = 128;
59     WCharType = SignedInt;
60     WIntType = UnsignedInt;
61     HasRISCVVTypes = true;
62     MCountName = "_mcount";
63   }
64 
setCPU(const std::string & Name)65   bool setCPU(const std::string &Name) override {
66     if (!isValidCPUName(Name))
67       return false;
68     CPU = Name;
69     return true;
70   }
71 
getABI()72   StringRef getABI() const override { return ABI; }
73   void getTargetDefines(const LangOptions &Opts,
74                         MacroBuilder &Builder) const override;
75 
76   ArrayRef<Builtin::Info> getTargetBuiltins() const override;
77 
getBuiltinVaListKind()78   BuiltinVaListKind getBuiltinVaListKind() const override {
79     return TargetInfo::VoidPtrBuiltinVaList;
80   }
81 
getClobbers()82   const char *getClobbers() const override { return ""; }
83 
84   ArrayRef<const char *> getGCCRegNames() const override;
85 
getEHDataRegisterNumber(unsigned RegNo)86   int getEHDataRegisterNumber(unsigned RegNo) const override {
87     if (RegNo == 0)
88       return 10;
89     else if (RegNo == 1)
90       return 11;
91     else
92       return -1;
93   }
94 
95   ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override;
96 
97   bool validateAsmConstraint(const char *&Name,
98                              TargetInfo::ConstraintInfo &Info) const override;
99 
100   std::string convertConstraint(const char *&Constraint) const override;
101 
102   bool
103   initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
104                  StringRef CPU,
105                  const std::vector<std::string> &FeaturesVec) const override;
106 
107   bool hasFeature(StringRef Feature) const override;
108 
109   bool handleTargetFeatures(std::vector<std::string> &Features,
110                             DiagnosticsEngine &Diags) override;
111 
hasExtIntType()112   bool hasExtIntType() const override { return true; }
113 };
114 class LLVM_LIBRARY_VISIBILITY RISCV32TargetInfo : public RISCVTargetInfo {
115 public:
RISCV32TargetInfo(const llvm::Triple & Triple,const TargetOptions & Opts)116   RISCV32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
117       : RISCVTargetInfo(Triple, Opts) {
118     IntPtrType = SignedInt;
119     PtrDiffType = SignedInt;
120     SizeType = UnsignedInt;
121     resetDataLayout("e-m:e-p:32:32-i64:64-n32-S128");
122   }
123 
setABI(const std::string & Name)124   bool setABI(const std::string &Name) override {
125     if (Name == "ilp32" || Name == "ilp32f" || Name == "ilp32d") {
126       ABI = Name;
127       return true;
128     }
129     return false;
130   }
131 
132   bool isValidCPUName(StringRef Name) const override;
133   void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
134   bool isValidTuneCPUName(StringRef Name) const override;
135   void fillValidTuneCPUList(SmallVectorImpl<StringRef> &Values) const override;
136 
setMaxAtomicWidth()137   void setMaxAtomicWidth() override {
138     MaxAtomicPromoteWidth = 128;
139 
140     if (HasA)
141       MaxAtomicInlineWidth = 32;
142   }
143 };
144 class LLVM_LIBRARY_VISIBILITY RISCV64TargetInfo : public RISCVTargetInfo {
145 public:
RISCV64TargetInfo(const llvm::Triple & Triple,const TargetOptions & Opts)146   RISCV64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
147       : RISCVTargetInfo(Triple, Opts) {
148     LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
149     IntMaxType = Int64Type = SignedLong;
150     resetDataLayout("e-m:e-p:64:64-i64:64-i128:128-n64-S128");
151   }
152 
setABI(const std::string & Name)153   bool setABI(const std::string &Name) override {
154     if (Name == "lp64" || Name == "lp64f" || Name == "lp64d") {
155       ABI = Name;
156       return true;
157     }
158     return false;
159   }
160 
161   bool isValidCPUName(StringRef Name) const override;
162   void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
163   bool isValidTuneCPUName(StringRef Name) const override;
164   void fillValidTuneCPUList(SmallVectorImpl<StringRef> &Values) const override;
165 
setMaxAtomicWidth()166   void setMaxAtomicWidth() override {
167     MaxAtomicPromoteWidth = 128;
168 
169     if (HasA)
170       MaxAtomicInlineWidth = 64;
171   }
172 };
173 } // namespace targets
174 } // namespace clang
175 
176 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_RISCV_H
177