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