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