1 //===- MipsRegisterBankInfo.cpp ---------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 /// This file implements the targeting of the RegisterBankInfo class for Mips.
10 /// \todo This should be generated by TableGen.
11 //===----------------------------------------------------------------------===//
13 #include "MipsInstrInfo.h"
14 #include "MipsRegisterBankInfo.h"
15 #include "llvm/CodeGen/MachineRegisterInfo.h"
17 #define GET_TARGET_REGBANK_IMPL
19 #define DEBUG_TYPE "registerbankinfo"
21 #include "MipsGenRegisterBank.inc"
25 enum PartialMappingIdx
{
30 RegisterBankInfo::PartialMapping PartMappings
[]{
34 enum ValueMappingIdx
{ InvalidIdx
= 0, GPRIdx
= 1 };
36 RegisterBankInfo::ValueMapping ValueMappings
[] = {
40 {&PartMappings
[PMI_GPR
- PMI_Min
], 1},
41 {&PartMappings
[PMI_GPR
- PMI_Min
], 1},
42 {&PartMappings
[PMI_GPR
- PMI_Min
], 1}};
44 } // end namespace Mips
45 } // end namespace llvm
49 MipsRegisterBankInfo::MipsRegisterBankInfo(const TargetRegisterInfo
&TRI
)
50 : MipsGenRegisterBankInfo() {}
52 const RegisterBank
&MipsRegisterBankInfo::getRegBankFromRegClass(
53 const TargetRegisterClass
&RC
) const {
57 case Mips::GPR32RegClassID
:
58 case Mips::CPU16Regs_and_GPRMM16ZeroRegClassID
:
59 case Mips::GPRMM16MovePPairFirstRegClassID
:
60 case Mips::CPU16Regs_and_GPRMM16MovePPairSecondRegClassID
:
61 case Mips::GPRMM16MoveP_and_CPU16Regs_and_GPRMM16ZeroRegClassID
:
62 case Mips::GPRMM16MovePPairFirst_and_GPRMM16MovePPairSecondRegClassID
:
63 case Mips::SP32RegClassID
:
64 return getRegBank(Mips::GPRBRegBankID
);
66 llvm_unreachable("Register class not supported");
70 const RegisterBankInfo::InstructionMapping
&
71 MipsRegisterBankInfo::getInstrMapping(const MachineInstr
&MI
) const {
73 unsigned Opc
= MI
.getOpcode();
75 const RegisterBankInfo::InstructionMapping
&Mapping
= getInstrMappingImpl(MI
);
76 if (Mapping
.isValid())
79 using namespace TargetOpcode
;
81 unsigned NumOperands
= MI
.getNumOperands();
82 const ValueMapping
*OperandsMapping
= &Mips::ValueMappings
[Mips::GPRIdx
];
104 OperandsMapping
= &Mips::ValueMappings
[Mips::GPRIdx
];
111 getOperandsMapping({&Mips::ValueMappings
[Mips::GPRIdx
], nullptr});
115 getOperandsMapping({&Mips::ValueMappings
[Mips::GPRIdx
], nullptr,
116 &Mips::ValueMappings
[Mips::GPRIdx
],
117 &Mips::ValueMappings
[Mips::GPRIdx
]});
121 getOperandsMapping({&Mips::ValueMappings
[Mips::GPRIdx
],
122 &Mips::ValueMappings
[Mips::GPRIdx
],
123 &Mips::ValueMappings
[Mips::GPRIdx
],
124 &Mips::ValueMappings
[Mips::GPRIdx
]});
127 return getInvalidInstructionMapping();
130 return getInstructionMapping(DefaultMappingID
, /*Cost=*/1, OperandsMapping
,