xref: /freebsd/contrib/llvm-project/clang/lib/Basic/Targets/RISCV.h (revision 25ecdc7d52770caf1c9b44b5ec11f468f6b636f3)
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;
29   bool HasA;
30   bool HasF;
31   bool HasD;
32   bool HasC;
33   bool HasB;
34 
35 public:
36   RISCVTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
37       : TargetInfo(Triple), HasM(false), HasA(false), HasF(false),
38         HasD(false), HasC(false), HasB(false) {
39     LongDoubleWidth = 128;
40     LongDoubleAlign = 128;
41     LongDoubleFormat = &llvm::APFloat::IEEEquad();
42     SuitableAlign = 128;
43     WCharType = SignedInt;
44     WIntType = UnsignedInt;
45   }
46 
47   bool setCPU(const std::string &Name) override {
48     if (!isValidCPUName(Name))
49       return false;
50     CPU = Name;
51     return true;
52   }
53 
54   StringRef getABI() const override { return ABI; }
55   void getTargetDefines(const LangOptions &Opts,
56                         MacroBuilder &Builder) const override;
57 
58   ArrayRef<Builtin::Info> getTargetBuiltins() const override { return None; }
59 
60   BuiltinVaListKind getBuiltinVaListKind() const override {
61     return TargetInfo::VoidPtrBuiltinVaList;
62   }
63 
64   const char *getClobbers() const override { return ""; }
65 
66   ArrayRef<const char *> getGCCRegNames() const override;
67 
68   int getEHDataRegisterNumber(unsigned RegNo) const override {
69     if (RegNo == 0)
70       return 10;
71     else if (RegNo == 1)
72       return 11;
73     else
74       return -1;
75   }
76 
77   ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override;
78 
79   bool validateAsmConstraint(const char *&Name,
80                              TargetInfo::ConstraintInfo &Info) const override;
81 
82   bool hasFeature(StringRef Feature) const override;
83 
84   bool handleTargetFeatures(std::vector<std::string> &Features,
85                             DiagnosticsEngine &Diags) override;
86 
87   bool hasExtIntType() const override { return true; }
88 };
89 class LLVM_LIBRARY_VISIBILITY RISCV32TargetInfo : public RISCVTargetInfo {
90 public:
91   RISCV32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
92       : RISCVTargetInfo(Triple, Opts) {
93     IntPtrType = SignedInt;
94     PtrDiffType = SignedInt;
95     SizeType = UnsignedInt;
96     resetDataLayout("e-m:e-p:32:32-i64:64-n32-S128");
97   }
98 
99   bool setABI(const std::string &Name) override {
100     if (Name == "ilp32" || Name == "ilp32f" || Name == "ilp32d") {
101       ABI = Name;
102       return true;
103     }
104     return false;
105   }
106 
107   bool isValidCPUName(StringRef Name) const override;
108   void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
109 
110   void setMaxAtomicWidth() override {
111     MaxAtomicPromoteWidth = 128;
112 
113     if (HasA)
114       MaxAtomicInlineWidth = 32;
115   }
116 };
117 class LLVM_LIBRARY_VISIBILITY RISCV64TargetInfo : public RISCVTargetInfo {
118 public:
119   RISCV64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
120       : RISCVTargetInfo(Triple, Opts) {
121     LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
122     IntMaxType = Int64Type = SignedLong;
123     resetDataLayout("e-m:e-p:64:64-i64:64-i128:128-n64-S128");
124   }
125 
126   bool setABI(const std::string &Name) override {
127     if (Name == "lp64" || Name == "lp64f" || Name == "lp64d") {
128       ABI = Name;
129       return true;
130     }
131     return false;
132   }
133 
134   bool isValidCPUName(StringRef Name) const override;
135   void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
136 
137   void setMaxAtomicWidth() override {
138     MaxAtomicPromoteWidth = 128;
139 
140     if (HasA)
141       MaxAtomicInlineWidth = 64;
142   }
143 };
144 } // namespace targets
145 } // namespace clang
146 
147 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_RISCV_H
148