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