RISCVSubtarget.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. //===-- RISCVSubtarget.h - Define Subtarget for the RISCV -------*- 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 the RISCV specific subclass of TargetSubtargetInfo.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #ifndef LLVM_LIB_TARGET_RISCV_RISCVSUBTARGET_H
  13. #define LLVM_LIB_TARGET_RISCV_RISCVSUBTARGET_H
  14. #include "MCTargetDesc/RISCVBaseInfo.h"
  15. #include "RISCVFrameLowering.h"
  16. #include "RISCVISelLowering.h"
  17. #include "RISCVInstrInfo.h"
  18. #include "llvm/CodeGen/GlobalISel/CallLowering.h"
  19. #include "llvm/CodeGen/GlobalISel/InstructionSelector.h"
  20. #include "llvm/CodeGen/GlobalISel/LegalizerInfo.h"
  21. #include "llvm/CodeGen/RegisterBankInfo.h"
  22. #include "llvm/CodeGen/SelectionDAGTargetInfo.h"
  23. #include "llvm/CodeGen/TargetSubtargetInfo.h"
  24. #include "llvm/IR/DataLayout.h"
  25. #include "llvm/Target/TargetMachine.h"
  26. #define GET_SUBTARGETINFO_HEADER
  27. #include "RISCVGenSubtargetInfo.inc"
  28. namespace llvm {
  29. class StringRef;
  30. class RISCVSubtarget : public RISCVGenSubtargetInfo {
  31. public:
  32. enum RISCVProcFamilyEnum : uint8_t {
  33. Others,
  34. SiFive7,
  35. };
  36. private:
  37. virtual void anchor();
  38. RISCVProcFamilyEnum RISCVProcFamily = Others;
  39. #define GET_SUBTARGETINFO_MACRO(ATTRIBUTE, DEFAULT, GETTER) \
  40. bool ATTRIBUTE = DEFAULT;
  41. #include "RISCVGenSubtargetInfo.inc"
  42. unsigned XLen = 32;
  43. unsigned ZvlLen = 0;
  44. MVT XLenVT = MVT::i32;
  45. unsigned RVVVectorBitsMin;
  46. unsigned RVVVectorBitsMax;
  47. uint8_t MaxInterleaveFactor = 2;
  48. RISCVABI::ABI TargetABI = RISCVABI::ABI_Unknown;
  49. std::bitset<RISCV::NUM_TARGET_REGS> UserReservedRegister;
  50. RISCVFrameLowering FrameLowering;
  51. RISCVInstrInfo InstrInfo;
  52. RISCVRegisterInfo RegInfo;
  53. RISCVTargetLowering TLInfo;
  54. SelectionDAGTargetInfo TSInfo;
  55. /// Initializes using the passed in CPU and feature strings so that we can
  56. /// use initializer lists for subtarget initialization.
  57. RISCVSubtarget &initializeSubtargetDependencies(const Triple &TT,
  58. StringRef CPU,
  59. StringRef TuneCPU,
  60. StringRef FS,
  61. StringRef ABIName);
  62. public:
  63. // Initializes the data members to match that of the specified triple.
  64. RISCVSubtarget(const Triple &TT, StringRef CPU, StringRef TuneCPU,
  65. StringRef FS, StringRef ABIName, unsigned RVVVectorBitsMin,
  66. unsigned RVVVectorLMULMax, const TargetMachine &TM);
  67. // Parses features string setting specified subtarget options. The
  68. // definition of this function is auto-generated by tblgen.
  69. void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS);
  70. const RISCVFrameLowering *getFrameLowering() const override {
  71. return &FrameLowering;
  72. }
  73. const RISCVInstrInfo *getInstrInfo() const override { return &InstrInfo; }
  74. const RISCVRegisterInfo *getRegisterInfo() const override {
  75. return &RegInfo;
  76. }
  77. const RISCVTargetLowering *getTargetLowering() const override {
  78. return &TLInfo;
  79. }
  80. const SelectionDAGTargetInfo *getSelectionDAGInfo() const override {
  81. return &TSInfo;
  82. }
  83. bool enableMachineScheduler() const override { return true; }
  84. /// Returns RISCV processor family.
  85. /// Avoid this function! CPU specifics should be kept local to this class
  86. /// and preferably modeled with SubtargetFeatures or properties in
  87. /// initializeProperties().
  88. RISCVProcFamilyEnum getProcFamily() const { return RISCVProcFamily; }
  89. #define GET_SUBTARGETINFO_MACRO(ATTRIBUTE, DEFAULT, GETTER) \
  90. bool GETTER() const { return ATTRIBUTE; }
  91. #include "RISCVGenSubtargetInfo.inc"
  92. bool hasStdExtCOrZca() const { return HasStdExtC || HasStdExtZca; }
  93. bool hasStdExtZvl() const { return ZvlLen != 0; }
  94. bool hasStdExtZfhOrZfhmin() const { return HasStdExtZfh || HasStdExtZfhmin; }
  95. bool is64Bit() const { return HasRV64; }
  96. MVT getXLenVT() const { return XLenVT; }
  97. unsigned getXLen() const { return XLen; }
  98. unsigned getFLen() const {
  99. if (HasStdExtD)
  100. return 64;
  101. if (HasStdExtF)
  102. return 32;
  103. return 0;
  104. }
  105. unsigned getELEN() const {
  106. assert(hasVInstructions() && "Expected V extension");
  107. return hasVInstructionsI64() ? 64 : 32;
  108. }
  109. unsigned getRealMinVLen() const {
  110. unsigned VLen = getMinRVVVectorSizeInBits();
  111. return VLen == 0 ? ZvlLen : VLen;
  112. }
  113. unsigned getRealMaxVLen() const {
  114. unsigned VLen = getMaxRVVVectorSizeInBits();
  115. return VLen == 0 ? 65536 : VLen;
  116. }
  117. RISCVABI::ABI getTargetABI() const { return TargetABI; }
  118. bool isRegisterReservedByUser(Register i) const {
  119. assert(i < RISCV::NUM_TARGET_REGS && "Register out of range");
  120. return UserReservedRegister[i];
  121. }
  122. bool hasMacroFusion() const { return hasLUIADDIFusion(); }
  123. // Vector codegen related methods.
  124. bool hasVInstructions() const { return HasStdExtZve32x; }
  125. bool hasVInstructionsI64() const { return HasStdExtZve64x; }
  126. bool hasVInstructionsF16() const {
  127. return HasStdExtZvfh && hasStdExtZfhOrZfhmin();
  128. }
  129. // FIXME: Consider Zfinx in the future
  130. bool hasVInstructionsF32() const { return HasStdExtZve32f && HasStdExtF; }
  131. // FIXME: Consider Zdinx in the future
  132. bool hasVInstructionsF64() const { return HasStdExtZve64d && HasStdExtD; }
  133. // F16 and F64 both require F32.
  134. bool hasVInstructionsAnyF() const { return hasVInstructionsF32(); }
  135. unsigned getMaxInterleaveFactor() const {
  136. return hasVInstructions() ? MaxInterleaveFactor : 1;
  137. }
  138. protected:
  139. // GlobalISel related APIs.
  140. std::unique_ptr<CallLowering> CallLoweringInfo;
  141. std::unique_ptr<InstructionSelector> InstSelector;
  142. std::unique_ptr<LegalizerInfo> Legalizer;
  143. std::unique_ptr<RegisterBankInfo> RegBankInfo;
  144. // Return the known range for the bit length of RVV data registers as set
  145. // at the command line. A value of 0 means nothing is known about that particular
  146. // limit beyond what's implied by the architecture.
  147. // NOTE: Please use getRealMinVLen and getRealMaxVLen instead!
  148. unsigned getMaxRVVVectorSizeInBits() const;
  149. unsigned getMinRVVVectorSizeInBits() const;
  150. public:
  151. const CallLowering *getCallLowering() const override;
  152. InstructionSelector *getInstructionSelector() const override;
  153. const LegalizerInfo *getLegalizerInfo() const override;
  154. const RegisterBankInfo *getRegBankInfo() const override;
  155. bool isTargetFuchsia() const { return getTargetTriple().isOSFuchsia(); }
  156. bool useConstantPoolForLargeInts() const;
  157. // Maximum cost used for building integers, integers will be put into constant
  158. // pool if exceeded.
  159. unsigned getMaxBuildIntsCost() const;
  160. unsigned getMaxLMULForFixedLengthVectors() const;
  161. bool useRVVForFixedLengthVectors() const;
  162. bool enableSubRegLiveness() const override;
  163. void getPostRAMutations(std::vector<std::unique_ptr<ScheduleDAGMutation>>
  164. &Mutations) const override;
  165. };
  166. } // End llvm namespace
  167. #endif