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 public: 51 RISCVTargetInfo(const llvm::Triple &Triple, const TargetOptions &) 52 : TargetInfo(Triple) { 53 LongDoubleWidth = 128; 54 LongDoubleAlign = 128; 55 LongDoubleFormat = &llvm::APFloat::IEEEquad(); 56 SuitableAlign = 128; 57 WCharType = SignedInt; 58 WIntType = UnsignedInt; 59 } 60 61 bool setCPU(const std::string &Name) override { 62 if (!isValidCPUName(Name)) 63 return false; 64 CPU = Name; 65 return true; 66 } 67 68 StringRef getABI() const override { return ABI; } 69 void getTargetDefines(const LangOptions &Opts, 70 MacroBuilder &Builder) const override; 71 72 ArrayRef<Builtin::Info> getTargetBuiltins() const override { return None; } 73 74 BuiltinVaListKind getBuiltinVaListKind() const override { 75 return TargetInfo::VoidPtrBuiltinVaList; 76 } 77 78 const char *getClobbers() const override { return ""; } 79 80 ArrayRef<const char *> getGCCRegNames() const override; 81 82 int getEHDataRegisterNumber(unsigned RegNo) const override { 83 if (RegNo == 0) 84 return 10; 85 else if (RegNo == 1) 86 return 11; 87 else 88 return -1; 89 } 90 91 ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override; 92 93 bool validateAsmConstraint(const char *&Name, 94 TargetInfo::ConstraintInfo &Info) const override; 95 96 bool hasFeature(StringRef Feature) const override; 97 98 bool handleTargetFeatures(std::vector<std::string> &Features, 99 DiagnosticsEngine &Diags) override; 100 101 bool hasExtIntType() const override { return true; } 102 }; 103 class LLVM_LIBRARY_VISIBILITY RISCV32TargetInfo : public RISCVTargetInfo { 104 public: 105 RISCV32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) 106 : RISCVTargetInfo(Triple, Opts) { 107 IntPtrType = SignedInt; 108 PtrDiffType = SignedInt; 109 SizeType = UnsignedInt; 110 resetDataLayout("e-m:e-p:32:32-i64:64-n32-S128"); 111 } 112 113 bool setABI(const std::string &Name) override { 114 if (Name == "ilp32" || Name == "ilp32f" || Name == "ilp32d") { 115 ABI = Name; 116 return true; 117 } 118 return false; 119 } 120 121 bool isValidCPUName(StringRef Name) const override; 122 void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override; 123 bool isValidTuneCPUName(StringRef Name) const override; 124 void fillValidTuneCPUList(SmallVectorImpl<StringRef> &Values) const override; 125 126 void setMaxAtomicWidth() override { 127 MaxAtomicPromoteWidth = 128; 128 129 if (HasA) 130 MaxAtomicInlineWidth = 32; 131 } 132 }; 133 class LLVM_LIBRARY_VISIBILITY RISCV64TargetInfo : public RISCVTargetInfo { 134 public: 135 RISCV64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) 136 : RISCVTargetInfo(Triple, Opts) { 137 LongWidth = LongAlign = PointerWidth = PointerAlign = 64; 138 IntMaxType = Int64Type = SignedLong; 139 resetDataLayout("e-m:e-p:64:64-i64:64-i128:128-n64-S128"); 140 } 141 142 bool setABI(const std::string &Name) override { 143 if (Name == "lp64" || Name == "lp64f" || Name == "lp64d") { 144 ABI = Name; 145 return true; 146 } 147 return false; 148 } 149 150 bool isValidCPUName(StringRef Name) const override; 151 void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override; 152 bool isValidTuneCPUName(StringRef Name) const override; 153 void fillValidTuneCPUList(SmallVectorImpl<StringRef> &Values) const override; 154 155 void setMaxAtomicWidth() override { 156 MaxAtomicPromoteWidth = 128; 157 158 if (HasA) 159 MaxAtomicInlineWidth = 64; 160 } 161 }; 162 } // namespace targets 163 } // namespace clang 164 165 #endif // LLVM_CLANG_LIB_BASIC_TARGETS_RISCV_H 166