RISCV.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. #ifndef LLVM_CLANG_LIB_BASIC_TARGETS_RISCV_H
  13. #define LLVM_CLANG_LIB_BASIC_TARGETS_RISCV_H
  14. #include "clang/Basic/TargetInfo.h"
  15. #include "clang/Basic/TargetOptions.h"
  16. #include "llvm/ADT/Triple.h"
  17. #include "llvm/Support/Compiler.h"
  18. #include "llvm/Support/RISCVISAInfo.h"
  19. namespace clang {
  20. namespace targets {
  21. // RISC-V Target
  22. class RISCVTargetInfo : public TargetInfo {
  23. protected:
  24. std::string ABI, CPU;
  25. std::unique_ptr<llvm::RISCVISAInfo> ISAInfo;
  26. static const Builtin::Info BuiltinInfo[];
  27. public:
  28. RISCVTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
  29. : TargetInfo(Triple) {
  30. LongDoubleWidth = 128;
  31. LongDoubleAlign = 128;
  32. LongDoubleFormat = &llvm::APFloat::IEEEquad();
  33. SuitableAlign = 128;
  34. WCharType = SignedInt;
  35. WIntType = UnsignedInt;
  36. HasRISCVVTypes = true;
  37. MCountName = "_mcount";
  38. HasFloat16 = true;
  39. }
  40. bool setCPU(const std::string &Name) override {
  41. if (!isValidCPUName(Name))
  42. return false;
  43. CPU = Name;
  44. return true;
  45. }
  46. StringRef getABI() const override { return ABI; }
  47. void getTargetDefines(const LangOptions &Opts,
  48. MacroBuilder &Builder) const override;
  49. ArrayRef<Builtin::Info> getTargetBuiltins() const override;
  50. BuiltinVaListKind getBuiltinVaListKind() const override {
  51. return TargetInfo::VoidPtrBuiltinVaList;
  52. }
  53. const char *getClobbers() const override { return ""; }
  54. StringRef getConstraintRegister(StringRef Constraint,
  55. StringRef Expression) const override {
  56. return Expression;
  57. }
  58. ArrayRef<const char *> getGCCRegNames() const override;
  59. int getEHDataRegisterNumber(unsigned RegNo) const override {
  60. if (RegNo == 0)
  61. return 10;
  62. else if (RegNo == 1)
  63. return 11;
  64. else
  65. return -1;
  66. }
  67. ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override;
  68. bool validateAsmConstraint(const char *&Name,
  69. TargetInfo::ConstraintInfo &Info) const override;
  70. std::string convertConstraint(const char *&Constraint) const override;
  71. bool
  72. initFeatureMap(llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags,
  73. StringRef CPU,
  74. const std::vector<std::string> &FeaturesVec) const override;
  75. bool hasFeature(StringRef Feature) const override;
  76. bool handleTargetFeatures(std::vector<std::string> &Features,
  77. DiagnosticsEngine &Diags) override;
  78. bool hasBitIntType() const override { return true; }
  79. };
  80. class LLVM_LIBRARY_VISIBILITY RISCV32TargetInfo : public RISCVTargetInfo {
  81. public:
  82. RISCV32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
  83. : RISCVTargetInfo(Triple, Opts) {
  84. IntPtrType = SignedInt;
  85. PtrDiffType = SignedInt;
  86. SizeType = UnsignedInt;
  87. resetDataLayout("e-m:e-p:32:32-i64:64-n32-S128");
  88. }
  89. bool setABI(const std::string &Name) override {
  90. if (Name == "ilp32" || Name == "ilp32f" || Name == "ilp32d") {
  91. ABI = Name;
  92. return true;
  93. }
  94. return false;
  95. }
  96. bool isValidCPUName(StringRef Name) const override;
  97. void fillValidCPUList(SmallVectorImpl<StringRef> &Values) const override;
  98. bool isValidTuneCPUName(StringRef Name) const override;
  99. void fillValidTuneCPUList(SmallVectorImpl<StringRef> &Values) const override;
  100. void setMaxAtomicWidth() override {
  101. MaxAtomicPromoteWidth = 128;
  102. if (ISAInfo->hasExtension("a"))
  103. MaxAtomicInlineWidth = 32;
  104. }
  105. };
  106. class LLVM_LIBRARY_VISIBILITY RISCV64TargetInfo : public RISCVTargetInfo {
  107. public:
  108. RISCV64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
  109. : RISCVTargetInfo(Triple, Opts) {
  110. LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
  111. IntMaxType = Int64Type = SignedLong;
  112. resetDataLayout("e-m:e-p:64:64-i64:64-i128:128-n64-S128");
  113. }
  114. bool setABI(const std::string &Name) override {
  115. if (Name == "lp64" || Name == "lp64f" || Name == "lp64d") {
  116. ABI = Name;
  117. return true;
  118. }
  119. return false;
  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. void setMaxAtomicWidth() override {
  126. MaxAtomicPromoteWidth = 128;
  127. if (ISAInfo->hasExtension("a"))
  128. MaxAtomicInlineWidth = 64;
  129. }
  130. };
  131. } // namespace targets
  132. } // namespace clang
  133. #endif // LLVM_CLANG_LIB_BASIC_TARGETS_RISCV_H