1 //===- MipsRegisterBankInfo.cpp ---------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 /// This file implements the targeting of the RegisterBankInfo class for Mips.
11 /// \todo This should be generated by TableGen.
12 //===----------------------------------------------------------------------===//
14 #include "MipsInstrInfo.h"
15 #include "MipsRegisterBankInfo.h"
16 #include "llvm/CodeGen/MachineRegisterInfo.h"
18 #define GET_TARGET_REGBANK_IMPL
20 #define DEBUG_TYPE "registerbankinfo"
22 #include "MipsGenRegisterBank.inc"
26 enum PartialMappingIdx {
31 RegisterBankInfo::PartialMapping PartMappings[]{
35 enum ValueMappingIdx { InvalidIdx = 0, GPRIdx = 1 };
37 RegisterBankInfo::ValueMapping ValueMappings[] = {
41 {&PartMappings[PMI_GPR - PMI_Min], 1},
42 {&PartMappings[PMI_GPR - PMI_Min], 1},
43 {&PartMappings[PMI_GPR - PMI_Min], 1}};
45 } // end namespace Mips
46 } // end namespace llvm
50 MipsRegisterBankInfo::MipsRegisterBankInfo(const TargetRegisterInfo &TRI)
51 : MipsGenRegisterBankInfo() {}
53 const RegisterBank &MipsRegisterBankInfo::getRegBankFromRegClass(
54 const TargetRegisterClass &RC) const {
58 case Mips::GPR32RegClassID:
59 case Mips::CPU16Regs_and_GPRMM16ZeroRegClassID:
60 case Mips::GPRMM16MoveP_and_CPU16Regs_and_GPRMM16ZeroRegClassID:
61 case Mips::SP32RegClassID:
62 return getRegBank(Mips::GPRBRegBankID);
64 llvm_unreachable("Register class not supported");
68 const RegisterBankInfo::InstructionMapping &
69 MipsRegisterBankInfo::getInstrMapping(const MachineInstr &MI) const {
71 unsigned Opc = MI.getOpcode();
73 const RegisterBankInfo::InstructionMapping &Mapping = getInstrMappingImpl(MI);
74 if (Mapping.isValid())
77 using namespace TargetOpcode;
79 unsigned NumOperands = MI.getNumOperands();
80 const ValueMapping *OperandsMapping = &Mips::ValueMappings[Mips::GPRIdx];
87 OperandsMapping = &Mips::ValueMappings[Mips::GPRIdx];
93 getOperandsMapping({&Mips::ValueMappings[Mips::GPRIdx], nullptr});
96 return getInvalidInstructionMapping();
99 return getInstructionMapping(DefaultMappingID, /*Cost=*/1, OperandsMapping,