1 //===--- RISCV.h - Declare RISCV target feature support ---------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file declares RISCV TargetInfo objects.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CLANG_LIB_BASIC_TARGETS_RISCV_H
15 #define LLVM_CLANG_LIB_BASIC_TARGETS_RISCV_H
16 
17 #include "clang/Basic/TargetInfo.h"
18 #include "clang/Basic/TargetOptions.h"
19 #include "llvm/ADT/Triple.h"
20 #include "llvm/Support/Compiler.h"
21 
22 namespace clang {
23 namespace targets {
24 
25 // RISC-V Target
26 class RISCVTargetInfo : public TargetInfo {
27 protected:
28   std::string ABI;
29   bool HasM;
30   bool HasA;
31   bool HasF;
32   bool HasD;
33   bool HasC;
34 
35 public:
RISCVTargetInfo(const llvm::Triple & Triple,const TargetOptions &)36   RISCVTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
37       : TargetInfo(Triple), HasM(false), HasA(false), HasF(false),
38         HasD(false), HasC(false) {
39     TLSSupported = false;
40     LongDoubleWidth = 128;
41     LongDoubleAlign = 128;
42     LongDoubleFormat = &llvm::APFloat::IEEEquad();
43     SuitableAlign = 128;
44     WCharType = SignedInt;
45     WIntType = UnsignedInt;
46   }
47 
getABI()48   StringRef getABI() const override { return ABI; }
49   void getTargetDefines(const LangOptions &Opts,
50                         MacroBuilder &Builder) const override;
51 
getTargetBuiltins()52   ArrayRef<Builtin::Info> getTargetBuiltins() const override { return None; }
53 
getBuiltinVaListKind()54   BuiltinVaListKind getBuiltinVaListKind() const override {
55     return TargetInfo::VoidPtrBuiltinVaList;
56   }
57 
getClobbers()58   const char *getClobbers() const override { return ""; }
59 
60   ArrayRef<const char *> getGCCRegNames() const override;
61 
62   ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override;
63 
validateAsmConstraint(const char * & Name,TargetInfo::ConstraintInfo & Info)64   bool validateAsmConstraint(const char *&Name,
65                              TargetInfo::ConstraintInfo &Info) const override {
66     return false;
67   }
68 
69   bool hasFeature(StringRef Feature) const override;
70 
71   bool handleTargetFeatures(std::vector<std::string> &Features,
72                             DiagnosticsEngine &Diags) override;
73 };
74 class LLVM_LIBRARY_VISIBILITY RISCV32TargetInfo : public RISCVTargetInfo {
75 public:
RISCV32TargetInfo(const llvm::Triple & Triple,const TargetOptions & Opts)76   RISCV32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
77       : RISCVTargetInfo(Triple, Opts) {
78     IntPtrType = SignedInt;
79     PtrDiffType = SignedInt;
80     SizeType = UnsignedInt;
81     resetDataLayout("e-m:e-p:32:32-i64:64-n32-S128");
82   }
83 
setABI(const std::string & Name)84   bool setABI(const std::string &Name) override {
85     // TODO: support ilp32f and ilp32d ABIs.
86     if (Name == "ilp32") {
87       ABI = Name;
88       return true;
89     }
90     return false;
91   }
92 };
93 class LLVM_LIBRARY_VISIBILITY RISCV64TargetInfo : public RISCVTargetInfo {
94 public:
RISCV64TargetInfo(const llvm::Triple & Triple,const TargetOptions & Opts)95   RISCV64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
96       : RISCVTargetInfo(Triple, Opts) {
97     LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
98     IntMaxType = Int64Type = SignedLong;
99     resetDataLayout("e-m:e-p:64:64-i64:64-i128:128-n64-S128");
100   }
101 
setABI(const std::string & Name)102   bool setABI(const std::string &Name) override {
103     // TODO: support lp64f and lp64d ABIs.
104     if (Name == "lp64") {
105       ABI = Name;
106       return true;
107     }
108     return false;
109   }
110 };
111 } // namespace targets
112 } // namespace clang
113 
114 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_RISCV_H
115