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 
30 public:
31   RISCVTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
32       : TargetInfo(Triple) {
33     TLSSupported = false;
34     LongDoubleWidth = 128;
35     LongDoubleAlign = 128;
36     LongDoubleFormat = &llvm::APFloat::IEEEquad();
37     SuitableAlign = 128;
38     WCharType = SignedInt;
39     WIntType = UnsignedInt;
40   }
41 
42   StringRef getABI() const override { return ABI; }
43   void getTargetDefines(const LangOptions &Opts,
44                         MacroBuilder &Builder) const override;
45 
46   ArrayRef<Builtin::Info> getTargetBuiltins() const override { return None; }
47 
48   BuiltinVaListKind getBuiltinVaListKind() const override {
49     return TargetInfo::VoidPtrBuiltinVaList;
50   }
51 
52   const char *getClobbers() const override { return ""; }
53 
54   ArrayRef<const char *> getGCCRegNames() const override;
55 
56   ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override;
57 
58   bool validateAsmConstraint(const char *&Name,
59                              TargetInfo::ConstraintInfo &Info) const override {
60     return false;
61   }
62 };
63 class LLVM_LIBRARY_VISIBILITY RISCV32TargetInfo : public RISCVTargetInfo {
64 public:
65   RISCV32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
66       : RISCVTargetInfo(Triple, Opts) {
67     IntPtrType = SignedInt;
68     PtrDiffType = SignedInt;
69     SizeType = UnsignedInt;
70     resetDataLayout("e-m:e-p:32:32-i64:64-n32-S128");
71   }
72 
73   bool setABI(const std::string &Name) override {
74     // TODO: support ilp32f and ilp32d ABIs.
75     if (Name == "ilp32") {
76       ABI = Name;
77       return true;
78     }
79     return false;
80   }
81 };
82 class LLVM_LIBRARY_VISIBILITY RISCV64TargetInfo : public RISCVTargetInfo {
83 public:
84   RISCV64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
85       : RISCVTargetInfo(Triple, Opts) {
86     LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
87     IntMaxType = Int64Type = SignedLong;
88     resetDataLayout("e-m:e-p:64:64-i64:64-i128:128-n64-S128");
89   }
90 
91   bool setABI(const std::string &Name) override {
92     // TODO: support lp64f and lp64d ABIs.
93     if (Name == "lp64") {
94       ABI = Name;
95       return true;
96     }
97     return false;
98   }
99 };
100 } // namespace targets
101 } // namespace clang
102 
103 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_RISCV_H
104