| Alex Bradbury | 71f4545 | 2018-01-11 13:36:56 +0000 | [diff] [blame] | 1 | //===--- RISCV.h - Declare RISCV target feature support ---------*- C++ -*-===// | 
|  | 2 | // | 
| Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 | 
| Alex Bradbury | 71f4545 | 2018-01-11 13:36:56 +0000 | [diff] [blame] | 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; | 
| Shiva Chen | 4891dbf | 2018-04-05 12:54:00 +0000 | [diff] [blame] | 28 | bool HasM; | 
|  | 29 | bool HasA; | 
|  | 30 | bool HasF; | 
|  | 31 | bool HasD; | 
|  | 32 | bool HasC; | 
| Scott Egerton | 61ff29637 | 2020-04-09 17:51:26 +0100 | [diff] [blame] | 33 | bool HasB; | 
| Alex Bradbury | 71f4545 | 2018-01-11 13:36:56 +0000 | [diff] [blame] | 34 |  | 
|  | 35 | public: | 
|  | 36 | RISCVTargetInfo(const llvm::Triple &Triple, const TargetOptions &) | 
| Shiva Chen | 4891dbf | 2018-04-05 12:54:00 +0000 | [diff] [blame] | 37 | : TargetInfo(Triple), HasM(false), HasA(false), HasF(false), | 
| Scott Egerton | 61ff29637 | 2020-04-09 17:51:26 +0100 | [diff] [blame] | 38 | HasD(false), HasC(false), HasB(false) { | 
| Alex Bradbury | 71f4545 | 2018-01-11 13:36:56 +0000 | [diff] [blame] | 39 | LongDoubleWidth = 128; | 
|  | 40 | LongDoubleAlign = 128; | 
|  | 41 | LongDoubleFormat = &llvm::APFloat::IEEEquad(); | 
|  | 42 | SuitableAlign = 128; | 
|  | 43 | WCharType = SignedInt; | 
|  | 44 | WIntType = UnsignedInt; | 
|  | 45 | } | 
|  | 46 |  | 
|  | 47 | StringRef getABI() const override { return ABI; } | 
|  | 48 | void getTargetDefines(const LangOptions &Opts, | 
|  | 49 | MacroBuilder &Builder) const override; | 
|  | 50 |  | 
|  | 51 | ArrayRef<Builtin::Info> getTargetBuiltins() const override { return None; } | 
|  | 52 |  | 
|  | 53 | BuiltinVaListKind getBuiltinVaListKind() const override { | 
|  | 54 | return TargetInfo::VoidPtrBuiltinVaList; | 
|  | 55 | } | 
|  | 56 |  | 
|  | 57 | const char *getClobbers() const override { return ""; } | 
|  | 58 |  | 
|  | 59 | ArrayRef<const char *> getGCCRegNames() const override; | 
|  | 60 |  | 
| Alex Bradbury | 77d4a8f | 2019-07-08 09:38:06 +0000 | [diff] [blame] | 61 | int getEHDataRegisterNumber(unsigned RegNo) const override { | 
|  | 62 | if (RegNo == 0) | 
|  | 63 | return 10; | 
|  | 64 | else if (RegNo == 1) | 
|  | 65 | return 11; | 
|  | 66 | else | 
|  | 67 | return -1; | 
|  | 68 | } | 
|  | 69 |  | 
| Alex Bradbury | 71f4545 | 2018-01-11 13:36:56 +0000 | [diff] [blame] | 70 | ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override; | 
|  | 71 |  | 
|  | 72 | bool validateAsmConstraint(const char *&Name, | 
| Lewis Revill | 5665ef3 | 2019-06-11 12:44:01 +0000 | [diff] [blame] | 73 | TargetInfo::ConstraintInfo &Info) const override; | 
| Shiva Chen | 4891dbf | 2018-04-05 12:54:00 +0000 | [diff] [blame] | 74 |  | 
|  | 75 | bool hasFeature(StringRef Feature) const override; | 
|  | 76 |  | 
|  | 77 | bool handleTargetFeatures(std::vector<std::string> &Features, | 
|  | 78 | DiagnosticsEngine &Diags) override; | 
| Erich Keane | 8a1c999 | 2020-04-29 12:48:07 -0700 | [diff] [blame] | 79 |  | 
|  | 80 | bool hasExtIntType() const override { return true; } | 
| Alex Bradbury | 71f4545 | 2018-01-11 13:36:56 +0000 | [diff] [blame] | 81 | }; | 
|  | 82 | class LLVM_LIBRARY_VISIBILITY RISCV32TargetInfo : public RISCVTargetInfo { | 
|  | 83 | public: | 
|  | 84 | RISCV32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) | 
|  | 85 | : RISCVTargetInfo(Triple, Opts) { | 
|  | 86 | IntPtrType = SignedInt; | 
|  | 87 | PtrDiffType = SignedInt; | 
|  | 88 | SizeType = UnsignedInt; | 
|  | 89 | resetDataLayout("e-m:e-p:32:32-i64:64-n32-S128"); | 
|  | 90 | } | 
|  | 91 |  | 
|  | 92 | bool setABI(const std::string &Name) override { | 
| Alex Bradbury | e078967a | 2019-07-18 18:29:59 +0000 | [diff] [blame] | 93 | if (Name == "ilp32" || Name == "ilp32f" || Name == "ilp32d") { | 
| Alex Bradbury | 71f4545 | 2018-01-11 13:36:56 +0000 | [diff] [blame] | 94 | ABI = Name; | 
|  | 95 | return true; | 
|  | 96 | } | 
|  | 97 | return false; | 
|  | 98 | } | 
| Sam Elliott | f260630 | 2019-08-27 15:41:16 +0000 | [diff] [blame] | 99 |  | 
|  | 100 | void setMaxAtomicWidth() override { | 
|  | 101 | MaxAtomicPromoteWidth = 128; | 
|  | 102 |  | 
|  | 103 | if (HasA) | 
|  | 104 | MaxAtomicInlineWidth = 32; | 
|  | 105 | } | 
| Alex Bradbury | 71f4545 | 2018-01-11 13:36:56 +0000 | [diff] [blame] | 106 | }; | 
|  | 107 | class LLVM_LIBRARY_VISIBILITY RISCV64TargetInfo : public RISCVTargetInfo { | 
|  | 108 | public: | 
|  | 109 | RISCV64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts) | 
|  | 110 | : RISCVTargetInfo(Triple, Opts) { | 
|  | 111 | LongWidth = LongAlign = PointerWidth = PointerAlign = 64; | 
|  | 112 | IntMaxType = Int64Type = SignedLong; | 
|  | 113 | resetDataLayout("e-m:e-p:64:64-i64:64-i128:128-n64-S128"); | 
|  | 114 | } | 
|  | 115 |  | 
|  | 116 | bool setABI(const std::string &Name) override { | 
| Alex Bradbury | e078967a | 2019-07-18 18:29:59 +0000 | [diff] [blame] | 117 | if (Name == "lp64" || Name == "lp64f" || Name == "lp64d") { | 
| Alex Bradbury | 71f4545 | 2018-01-11 13:36:56 +0000 | [diff] [blame] | 118 | ABI = Name; | 
|  | 119 | return true; | 
|  | 120 | } | 
|  | 121 | return false; | 
|  | 122 | } | 
| Sam Elliott | f260630 | 2019-08-27 15:41:16 +0000 | [diff] [blame] | 123 |  | 
|  | 124 | void setMaxAtomicWidth() override { | 
|  | 125 | MaxAtomicPromoteWidth = 128; | 
|  | 126 |  | 
|  | 127 | if (HasA) | 
|  | 128 | MaxAtomicInlineWidth = 64; | 
|  | 129 | } | 
| Alex Bradbury | 71f4545 | 2018-01-11 13:36:56 +0000 | [diff] [blame] | 130 | }; | 
|  | 131 | } // namespace targets | 
|  | 132 | } // namespace clang | 
|  | 133 |  | 
|  | 134 | #endif // LLVM_CLANG_LIB_BASIC_TARGETS_RISCV_H |