RISCV.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. namespace clang {
  19. namespace targets {
  20. // RISC-V Target
  21. class RISCVTargetInfo : public TargetInfo {
  22. protected:
  23. std::string ABI;
  24. bool HasM;
  25. bool HasA;
  26. bool HasF;
  27. bool HasD;
  28. bool HasC;
  29. public:
  30. RISCVTargetInfo(const llvm::Triple &Triple, const TargetOptions &)
  31. : TargetInfo(Triple), HasM(false), HasA(false), HasF(false),
  32. HasD(false), HasC(false) {
  33. LongDoubleWidth = 128;
  34. LongDoubleAlign = 128;
  35. LongDoubleFormat = &llvm::APFloat::IEEEquad();
  36. SuitableAlign = 128;
  37. WCharType = SignedInt;
  38. WIntType = UnsignedInt;
  39. }
  40. StringRef getABI() const override { return ABI; }
  41. void getTargetDefines(const LangOptions &Opts,
  42. MacroBuilder &Builder) const override;
  43. ArrayRef<Builtin::Info> getTargetBuiltins() const override { return None; }
  44. BuiltinVaListKind getBuiltinVaListKind() const override {
  45. return TargetInfo::VoidPtrBuiltinVaList;
  46. }
  47. const char *getClobbers() const override { return ""; }
  48. ArrayRef<const char *> getGCCRegNames() const override;
  49. int getEHDataRegisterNumber(unsigned RegNo) const override {
  50. if (RegNo == 0)
  51. return 10;
  52. else if (RegNo == 1)
  53. return 11;
  54. else
  55. return -1;
  56. }
  57. ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override;
  58. bool validateAsmConstraint(const char *&Name,
  59. TargetInfo::ConstraintInfo &Info) const override;
  60. bool hasFeature(StringRef Feature) const override;
  61. bool handleTargetFeatures(std::vector<std::string> &Features,
  62. DiagnosticsEngine &Diags) override;
  63. };
  64. class LLVM_LIBRARY_VISIBILITY RISCV32TargetInfo : public RISCVTargetInfo {
  65. public:
  66. RISCV32TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
  67. : RISCVTargetInfo(Triple, Opts) {
  68. IntPtrType = SignedInt;
  69. PtrDiffType = SignedInt;
  70. SizeType = UnsignedInt;
  71. resetDataLayout("e-m:e-p:32:32-i64:64-n32-S128");
  72. }
  73. bool setABI(const std::string &Name) override {
  74. if (Name == "ilp32" || Name == "ilp32f" || Name == "ilp32d") {
  75. ABI = Name;
  76. return true;
  77. }
  78. return false;
  79. }
  80. void setMaxAtomicWidth() override {
  81. MaxAtomicPromoteWidth = 128;
  82. if (HasA)
  83. MaxAtomicInlineWidth = 32;
  84. }
  85. };
  86. class LLVM_LIBRARY_VISIBILITY RISCV64TargetInfo : public RISCVTargetInfo {
  87. public:
  88. RISCV64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
  89. : RISCVTargetInfo(Triple, Opts) {
  90. LongWidth = LongAlign = PointerWidth = PointerAlign = 64;
  91. IntMaxType = Int64Type = SignedLong;
  92. resetDataLayout("e-m:e-p:64:64-i64:64-i128:128-n64-S128");
  93. }
  94. bool setABI(const std::string &Name) override {
  95. if (Name == "lp64" || Name == "lp64f" || Name == "lp64d") {
  96. ABI = Name;
  97. return true;
  98. }
  99. return false;
  100. }
  101. void setMaxAtomicWidth() override {
  102. MaxAtomicPromoteWidth = 128;
  103. if (HasA)
  104. MaxAtomicInlineWidth = 64;
  105. }
  106. };
  107. } // namespace targets
  108. } // namespace clang
  109. #endif // LLVM_CLANG_LIB_BASIC_TARGETS_RISCV_H