1 //===-- M68kRegisterBankInfo.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 M68k.
10 /// \todo This should be generated by TableGen.
11 //===----------------------------------------------------------------------===//
13 #include "M68kRegisterBankInfo.h"
14 #include "M68kInstrInfo.h" // For the register classes
15 #include "M68kSubtarget.h"
16 #include "llvm/CodeGen/GlobalISel/RegisterBank.h"
17 #include "llvm/CodeGen/GlobalISel/RegisterBankInfo.h"
18 #include "llvm/CodeGen/MachineRegisterInfo.h"
19 #include "llvm/CodeGen/TargetRegisterInfo.h"
21 #define GET_TARGET_REGBANK_IMPL
22 #include "M68kGenRegisterBank.inc"
26 // FIXME: TableGen this.
27 // If it grows too much and TableGen still isn't ready to do the job, extract it
28 // into an M68kGenRegisterBankInfo.def (similar to AArch64).
31 enum PartialMappingIdx
{
36 RegisterBankInfo::PartialMapping PartMappings
[]{
37 // GPR Partial Mapping
41 enum ValueMappingIdx
{
46 RegisterBankInfo::ValueMapping ValueMappings
[] = {
50 {&PartMappings
[PMI_GPR
- PMI_Min
], 1},
51 {&PartMappings
[PMI_GPR
- PMI_Min
], 1},
52 {&PartMappings
[PMI_GPR
- PMI_Min
], 1},
55 } // end namespace M68k
56 } // end namespace llvm
58 M68kRegisterBankInfo::M68kRegisterBankInfo(const TargetRegisterInfo
&TRI
)
59 : M68kGenRegisterBankInfo() {}
62 M68kRegisterBankInfo::getRegBankFromRegClass(const TargetRegisterClass
&RC
,
64 return getRegBank(M68k::GPRRegBankID
);
67 const RegisterBankInfo::InstructionMapping
&
68 M68kRegisterBankInfo::getInstrMapping(const MachineInstr
&MI
) const {
69 auto Opc
= MI
.getOpcode();
71 if (!isPreISelGenericOpcode(Opc
)) {
72 const InstructionMapping
&Mapping
= getInstrMappingImpl(MI
);
73 if (Mapping
.isValid())
77 using namespace TargetOpcode
;
79 unsigned NumOperands
= MI
.getNumOperands();
80 const ValueMapping
*OperandsMapping
= &M68k::ValueMappings
[M68k::GPR3OpsIdx
];
90 OperandsMapping
= &M68k::ValueMappings
[M68k::GPR3OpsIdx
];
97 getOperandsMapping({&M68k::ValueMappings
[M68k::GPR3OpsIdx
], nullptr});
100 return getInvalidInstructionMapping();
103 return getInstructionMapping(DefaultMappingID
, /*Cost=*/1, OperandsMapping
,