blob: f114c6ac1925fbc5d77143c622d790cdd913915d [file] [log] [blame]
Alex Bradbury89718422017-10-19 21:37:38 +00001//===-- RISCVSubtarget.cpp - RISCV Subtarget Information ------------------===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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 Bradbury89718422017-10-19 21:37:38 +00006//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the RISCV specific subclass of TargetSubtargetInfo.
10//
11//===----------------------------------------------------------------------===//
12
13#include "RISCVSubtarget.h"
14#include "RISCV.h"
Daniel Sandersa16bd4f2019-08-20 22:53:24 +000015#include "RISCVCallLowering.h"
Alex Bradbury89718422017-10-19 21:37:38 +000016#include "RISCVFrameLowering.h"
Daniel Sandersa16bd4f2019-08-20 22:53:24 +000017#include "RISCVLegalizerInfo.h"
18#include "RISCVRegisterBankInfo.h"
19#include "RISCVTargetMachine.h"
Alex Bradbury89718422017-10-19 21:37:38 +000020#include "llvm/Support/TargetRegistry.h"
21
22using 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
30void RISCVSubtarget::anchor() {}
31
Alex Bradburyfea49572019-03-09 09:28:06 +000032RISCVSubtarget &RISCVSubtarget::initializeSubtargetDependencies(
33 const Triple &TT, StringRef CPU, StringRef FS, StringRef ABIName) {
Alex Bradbury89718422017-10-19 21:37:38 +000034 // Determine default and user-specified characteristics
Alex Bradburyfea49572019-03-09 09:28:06 +000035 bool Is64Bit = TT.isArch64Bit();
Alex Bradbury89718422017-10-19 21:37:38 +000036 std::string CPUName = CPU;
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 Bradburyfea49572019-03-09 09:28:06 +000044
45 TargetABI = RISCVABI::computeTargetABI(TT, getFeatureBits(), ABIName);
Alex Bradburydab1f6f2019-03-22 11:21:40 +000046 RISCVFeatures::validate(TT, getFeatureBits());
Alex Bradbury89718422017-10-19 21:37:38 +000047 return *this;
48}
49
Alex Bradbury6aae2162019-02-19 14:42:00 +000050RISCVSubtarget::RISCVSubtarget(const Triple &TT, StringRef CPU, StringRef FS,
Alex Bradburyfea49572019-03-09 09:28:06 +000051 StringRef ABIName, const TargetMachine &TM)
Alex Bradbury89718422017-10-19 21:37:38 +000052 : RISCVGenSubtargetInfo(TT, CPU, FS),
Alex Bradburyfea49572019-03-09 09:28:06 +000053 FrameLowering(initializeSubtargetDependencies(TT, CPU, FS, ABIName)),
Luis Marques1893f9a2019-10-16 15:06:02 +000054 InstrInfo(*this), RegInfo(getHwMode()), TLInfo(TM, *this) {
Daniel Sandersa16bd4f2019-08-20 22:53:24 +000055 CallLoweringInfo.reset(new RISCVCallLowering(*getTargetLowering()));
56 Legalizer.reset(new RISCVLegalizerInfo(*this));
57
58 auto *RBI = new RISCVRegisterBankInfo(*getRegisterInfo());
59 RegBankInfo.reset(RBI);
60 InstSelector.reset(createRISCVInstructionSelector(
61 *static_cast<const RISCVTargetMachine *>(&TM), *this, *RBI));
62}
63
64const CallLowering *RISCVSubtarget::getCallLowering() const {
65 return CallLoweringInfo.get();
66}
67
68InstructionSelector *RISCVSubtarget::getInstructionSelector() const {
69 return InstSelector.get();
70}
71
72const LegalizerInfo *RISCVSubtarget::getLegalizerInfo() const {
73 return Legalizer.get();
74}
75
76const RegisterBankInfo *RISCVSubtarget::getRegBankInfo() const {
77 return RegBankInfo.get();
78}