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 13 #ifndef LLVM_LIB_TARGET_RISCV_RISCVSUBTARGET_H 14 #define LLVM_LIB_TARGET_RISCV_RISCVSUBTARGET_H 15 16 #include "RISCVFrameLowering.h" 17 #include "RISCVISelLowering.h" 18 #include "RISCVInstrInfo.h" 19 #include "Utils/RISCVBaseInfo.h" 20 #include "llvm/CodeGen/GlobalISel/CallLowering.h" 21 #include "llvm/CodeGen/GlobalISel/InstructionSelector.h" 22 #include "llvm/CodeGen/GlobalISel/LegalizerInfo.h" 23 #include "llvm/CodeGen/GlobalISel/RegisterBankInfo.h" 24 #include "llvm/CodeGen/SelectionDAGTargetInfo.h" 25 #include "llvm/CodeGen/TargetSubtargetInfo.h" 26 #include "llvm/IR/DataLayout.h" 27 #include "llvm/Target/TargetMachine.h" 28 29 #define GET_SUBTARGETINFO_HEADER 30 #include "RISCVGenSubtargetInfo.inc" 31 32 namespace llvm { 33 class StringRef; 34 35 class RISCVSubtarget : public RISCVGenSubtargetInfo { 36 virtual void anchor(); 37 bool HasStdExtM = false; 38 bool HasStdExtA = false; 39 bool HasStdExtF = false; 40 bool HasStdExtD = false; 41 bool HasStdExtC = false; 42 bool HasStdExtB = false; 43 bool HasStdExtZbb = false; 44 bool HasStdExtZbc = false; 45 bool HasStdExtZbe = false; 46 bool HasStdExtZbf = false; 47 bool HasStdExtZbm = false; 48 bool HasStdExtZbp = false; 49 bool HasStdExtZbr = false; 50 bool HasStdExtZbs = false; 51 bool HasStdExtZbt = false; 52 bool HasStdExtZbproposedc = false; 53 bool HasRV64 = false; 54 bool IsRV32E = false; 55 bool EnableLinkerRelax = false; 56 bool EnableRVCHintInstrs = false; 57 bool EnableSaveRestore = false; 58 unsigned XLen = 32; 59 MVT XLenVT = MVT::i32; 60 RISCVABI::ABI TargetABI = RISCVABI::ABI_Unknown; 61 BitVector UserReservedRegister; 62 RISCVFrameLowering FrameLowering; 63 RISCVInstrInfo InstrInfo; 64 RISCVRegisterInfo RegInfo; 65 RISCVTargetLowering TLInfo; 66 SelectionDAGTargetInfo TSInfo; 67 68 /// Initializes using the passed in CPU and feature strings so that we can 69 /// use initializer lists for subtarget initialization. 70 RISCVSubtarget &initializeSubtargetDependencies(const Triple &TT, 71 StringRef CPU, StringRef FS, 72 StringRef ABIName); 73 74 public: 75 // Initializes the data members to match that of the specified triple. 76 RISCVSubtarget(const Triple &TT, StringRef CPU, StringRef FS, 77 StringRef ABIName, const TargetMachine &TM); 78 79 // Parses features string setting specified subtarget options. The 80 // definition of this function is auto-generated by tblgen. 81 void ParseSubtargetFeatures(StringRef CPU, StringRef FS); 82 83 const RISCVFrameLowering *getFrameLowering() const override { 84 return &FrameLowering; 85 } 86 const RISCVInstrInfo *getInstrInfo() const override { return &InstrInfo; } 87 const RISCVRegisterInfo *getRegisterInfo() const override { 88 return &RegInfo; 89 } 90 const RISCVTargetLowering *getTargetLowering() const override { 91 return &TLInfo; 92 } 93 const SelectionDAGTargetInfo *getSelectionDAGInfo() const override { 94 return &TSInfo; 95 } 96 bool enableMachineScheduler() const override { return true; } 97 bool hasStdExtM() const { return HasStdExtM; } 98 bool hasStdExtA() const { return HasStdExtA; } 99 bool hasStdExtF() const { return HasStdExtF; } 100 bool hasStdExtD() const { return HasStdExtD; } 101 bool hasStdExtC() const { return HasStdExtC; } 102 bool hasStdExtB() const { return HasStdExtB; } 103 bool hasStdExtZbb() const { return HasStdExtZbb; } 104 bool hasStdExtZbc() const { return HasStdExtZbc; } 105 bool hasStdExtZbe() const { return HasStdExtZbe; } 106 bool hasStdExtZbf() const { return HasStdExtZbf; } 107 bool hasStdExtZbm() const { return HasStdExtZbm; } 108 bool hasStdExtZbp() const { return HasStdExtZbp; } 109 bool hasStdExtZbr() const { return HasStdExtZbr; } 110 bool hasStdExtZbs() const { return HasStdExtZbs; } 111 bool hasStdExtZbt() const { return HasStdExtZbt; } 112 bool hasStdExtZbproposedc() const { return HasStdExtZbproposedc; } 113 bool is64Bit() const { return HasRV64; } 114 bool isRV32E() const { return IsRV32E; } 115 bool enableLinkerRelax() const { return EnableLinkerRelax; } 116 bool enableRVCHintInstrs() const { return EnableRVCHintInstrs; } 117 bool enableSaveRestore() const { return EnableSaveRestore; } 118 MVT getXLenVT() const { return XLenVT; } 119 unsigned getXLen() const { return XLen; } 120 RISCVABI::ABI getTargetABI() const { return TargetABI; } 121 bool isRegisterReservedByUser(Register i) const { 122 assert(i < RISCV::NUM_TARGET_REGS && "Register out of range"); 123 return UserReservedRegister[i]; 124 } 125 126 protected: 127 // GlobalISel related APIs. 128 std::unique_ptr<CallLowering> CallLoweringInfo; 129 std::unique_ptr<InstructionSelector> InstSelector; 130 std::unique_ptr<LegalizerInfo> Legalizer; 131 std::unique_ptr<RegisterBankInfo> RegBankInfo; 132 133 public: 134 const CallLowering *getCallLowering() const override; 135 InstructionSelector *getInstructionSelector() const override; 136 const LegalizerInfo *getLegalizerInfo() const override; 137 const RegisterBankInfo *getRegBankInfo() const override; 138 }; 139 } // End llvm namespace 140 141 #endif 142