Alex Bradbury | 8971842 | 2017-10-19 21:37:38 +0000 | [diff] [blame] | 1 | //===-- RISCVSubtarget.cpp - RISCV Subtarget Information ------------------===// |
| 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 | 8971842 | 2017-10-19 21:37:38 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file implements the RISCV specific subclass of TargetSubtargetInfo. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #include "RISCVSubtarget.h" |
| 14 | #include "RISCV.h" |
Daniel Sanders | a16bd4f | 2019-08-20 22:53:24 +0000 | [diff] [blame] | 15 | #include "RISCVCallLowering.h" |
Alex Bradbury | 8971842 | 2017-10-19 21:37:38 +0000 | [diff] [blame] | 16 | #include "RISCVFrameLowering.h" |
Daniel Sanders | a16bd4f | 2019-08-20 22:53:24 +0000 | [diff] [blame] | 17 | #include "RISCVLegalizerInfo.h" |
| 18 | #include "RISCVRegisterBankInfo.h" |
| 19 | #include "RISCVTargetMachine.h" |
Alex Bradbury | 8971842 | 2017-10-19 21:37:38 +0000 | [diff] [blame] | 20 | #include "llvm/Support/TargetRegistry.h" |
| 21 | |
| 22 | using namespace llvm; |
| 23 | |
| 24 | #define DEBUG_TYPE "riscv-subtarget" |
| 25 | |
| 26 | #define GET_SUBTARGETINFO_TARGET_DESC |
| 27 | #define GET_SUBTARGETINFO_CTOR |
| 28 | #include "RISCVGenSubtargetInfo.inc" |
| 29 | |
| 30 | void RISCVSubtarget::anchor() {} |
| 31 | |
Alex Bradbury | fea4957 | 2019-03-09 09:28:06 +0000 | [diff] [blame] | 32 | RISCVSubtarget &RISCVSubtarget::initializeSubtargetDependencies( |
| 33 | const Triple &TT, StringRef CPU, StringRef FS, StringRef ABIName) { |
Alex Bradbury | 8971842 | 2017-10-19 21:37:38 +0000 | [diff] [blame] | 34 | // Determine default and user-specified characteristics |
Alex Bradbury | fea4957 | 2019-03-09 09:28:06 +0000 | [diff] [blame] | 35 | bool Is64Bit = TT.isArch64Bit(); |
Benjamin Kramer | adcd026 | 2020-01-28 20:23:46 +0100 | [diff] [blame] | 36 | std::string CPUName = std::string(CPU); |
Alex Bradbury | 8971842 | 2017-10-19 21:37:38 +0000 | [diff] [blame] | 37 | if (CPUName.empty()) |
| 38 | CPUName = Is64Bit ? "generic-rv64" : "generic-rv32"; |
| 39 | ParseSubtargetFeatures(CPUName, FS); |
| 40 | if (Is64Bit) { |
| 41 | XLenVT = MVT::i64; |
| 42 | XLen = 64; |
| 43 | } |
Alex Bradbury | fea4957 | 2019-03-09 09:28:06 +0000 | [diff] [blame] | 44 | |
| 45 | TargetABI = RISCVABI::computeTargetABI(TT, getFeatureBits(), ABIName); |
Alex Bradbury | dab1f6f | 2019-03-22 11:21:40 +0000 | [diff] [blame] | 46 | RISCVFeatures::validate(TT, getFeatureBits()); |
Alex Bradbury | 8971842 | 2017-10-19 21:37:38 +0000 | [diff] [blame] | 47 | return *this; |
| 48 | } |
| 49 | |
Alex Bradbury | 6aae216 | 2019-02-19 14:42:00 +0000 | [diff] [blame] | 50 | RISCVSubtarget::RISCVSubtarget(const Triple &TT, StringRef CPU, StringRef FS, |
Alex Bradbury | fea4957 | 2019-03-09 09:28:06 +0000 | [diff] [blame] | 51 | StringRef ABIName, const TargetMachine &TM) |
Alex Bradbury | 8971842 | 2017-10-19 21:37:38 +0000 | [diff] [blame] | 52 | : RISCVGenSubtargetInfo(TT, CPU, FS), |
Simon Cook | aed9d6d | 2019-10-22 21:25:01 +0100 | [diff] [blame] | 53 | UserReservedRegister(RISCV::NUM_TARGET_REGS), |
Alex Bradbury | fea4957 | 2019-03-09 09:28:06 +0000 | [diff] [blame] | 54 | FrameLowering(initializeSubtargetDependencies(TT, CPU, FS, ABIName)), |
Luis Marques | 1893f9a | 2019-10-16 15:06:02 +0000 | [diff] [blame] | 55 | InstrInfo(*this), RegInfo(getHwMode()), TLInfo(TM, *this) { |
Daniel Sanders | a16bd4f | 2019-08-20 22:53:24 +0000 | [diff] [blame] | 56 | CallLoweringInfo.reset(new RISCVCallLowering(*getTargetLowering())); |
| 57 | Legalizer.reset(new RISCVLegalizerInfo(*this)); |
| 58 | |
| 59 | auto *RBI = new RISCVRegisterBankInfo(*getRegisterInfo()); |
| 60 | RegBankInfo.reset(RBI); |
| 61 | InstSelector.reset(createRISCVInstructionSelector( |
| 62 | *static_cast<const RISCVTargetMachine *>(&TM), *this, *RBI)); |
| 63 | } |
| 64 | |
| 65 | const CallLowering *RISCVSubtarget::getCallLowering() const { |
| 66 | return CallLoweringInfo.get(); |
| 67 | } |
| 68 | |
| 69 | InstructionSelector *RISCVSubtarget::getInstructionSelector() const { |
| 70 | return InstSelector.get(); |
| 71 | } |
| 72 | |
| 73 | const LegalizerInfo *RISCVSubtarget::getLegalizerInfo() const { |
| 74 | return Legalizer.get(); |
| 75 | } |
| 76 | |
| 77 | const RegisterBankInfo *RISCVSubtarget::getRegBankInfo() const { |
| 78 | return RegBankInfo.get(); |
| 79 | } |