104eeddc0SDimitry Andric //===-- M68kRegisterBankInfo.cpp --------------------------------*- C++ -*-===// 2349cc55cSDimitry Andric // 3349cc55cSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4349cc55cSDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5349cc55cSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6349cc55cSDimitry Andric // 7349cc55cSDimitry Andric //===----------------------------------------------------------------------===// 8349cc55cSDimitry Andric /// \file 9349cc55cSDimitry Andric /// This file implements the targeting of the RegisterBankInfo class for M68k. 10349cc55cSDimitry Andric /// \todo This should be generated by TableGen. 11349cc55cSDimitry Andric //===----------------------------------------------------------------------===// 12349cc55cSDimitry Andric 13349cc55cSDimitry Andric #include "M68kRegisterBankInfo.h" 14349cc55cSDimitry Andric #include "M68kInstrInfo.h" // For the register classes 15349cc55cSDimitry Andric #include "M68kSubtarget.h" 16349cc55cSDimitry Andric #include "llvm/CodeGen/MachineRegisterInfo.h" 1781ad6265SDimitry Andric #include "llvm/CodeGen/RegisterBank.h" 1881ad6265SDimitry Andric #include "llvm/CodeGen/RegisterBankInfo.h" 19349cc55cSDimitry Andric #include "llvm/CodeGen/TargetRegisterInfo.h" 20349cc55cSDimitry Andric 21349cc55cSDimitry Andric #define GET_TARGET_REGBANK_IMPL 22349cc55cSDimitry Andric #include "M68kGenRegisterBank.inc" 23349cc55cSDimitry Andric 24349cc55cSDimitry Andric using namespace llvm; 25349cc55cSDimitry Andric 26349cc55cSDimitry Andric // FIXME: TableGen this. 27349cc55cSDimitry Andric // If it grows too much and TableGen still isn't ready to do the job, extract it 28349cc55cSDimitry Andric // into an M68kGenRegisterBankInfo.def (similar to AArch64). 29349cc55cSDimitry Andric namespace llvm { 30349cc55cSDimitry Andric namespace M68k { 31349cc55cSDimitry Andric enum PartialMappingIdx { 32349cc55cSDimitry Andric PMI_GPR, 33349cc55cSDimitry Andric PMI_Min = PMI_GPR, 34349cc55cSDimitry Andric }; 35349cc55cSDimitry Andric 36*5f757f3fSDimitry Andric const RegisterBankInfo::PartialMapping PartMappings[]{ 37349cc55cSDimitry Andric // GPR Partial Mapping 38349cc55cSDimitry Andric {0, 32, GPRRegBank}, 39349cc55cSDimitry Andric }; 40349cc55cSDimitry Andric 41349cc55cSDimitry Andric enum ValueMappingIdx { 42349cc55cSDimitry Andric InvalidIdx = 0, 43349cc55cSDimitry Andric GPR3OpsIdx = 1, 44349cc55cSDimitry Andric }; 45349cc55cSDimitry Andric 46*5f757f3fSDimitry Andric const RegisterBankInfo::ValueMapping ValueMappings[] = { 47349cc55cSDimitry Andric // invalid 48349cc55cSDimitry Andric {nullptr, 0}, 49349cc55cSDimitry Andric // 3 operands in GPRs 50349cc55cSDimitry Andric {&PartMappings[PMI_GPR - PMI_Min], 1}, 51349cc55cSDimitry Andric {&PartMappings[PMI_GPR - PMI_Min], 1}, 52349cc55cSDimitry Andric {&PartMappings[PMI_GPR - PMI_Min], 1}, 53349cc55cSDimitry Andric 54349cc55cSDimitry Andric }; 55349cc55cSDimitry Andric } // end namespace M68k 56349cc55cSDimitry Andric } // end namespace llvm 57349cc55cSDimitry Andric 58349cc55cSDimitry Andric M68kRegisterBankInfo::M68kRegisterBankInfo(const TargetRegisterInfo &TRI) 59349cc55cSDimitry Andric : M68kGenRegisterBankInfo() {} 60349cc55cSDimitry Andric 61349cc55cSDimitry Andric const RegisterBank & 62349cc55cSDimitry Andric M68kRegisterBankInfo::getRegBankFromRegClass(const TargetRegisterClass &RC, 63349cc55cSDimitry Andric LLT) const { 64349cc55cSDimitry Andric return getRegBank(M68k::GPRRegBankID); 65349cc55cSDimitry Andric } 66349cc55cSDimitry Andric 67349cc55cSDimitry Andric const RegisterBankInfo::InstructionMapping & 68349cc55cSDimitry Andric M68kRegisterBankInfo::getInstrMapping(const MachineInstr &MI) const { 69349cc55cSDimitry Andric auto Opc = MI.getOpcode(); 70349cc55cSDimitry Andric 71349cc55cSDimitry Andric if (!isPreISelGenericOpcode(Opc)) { 72349cc55cSDimitry Andric const InstructionMapping &Mapping = getInstrMappingImpl(MI); 73349cc55cSDimitry Andric if (Mapping.isValid()) 74349cc55cSDimitry Andric return Mapping; 75349cc55cSDimitry Andric } 76349cc55cSDimitry Andric 77349cc55cSDimitry Andric using namespace TargetOpcode; 78349cc55cSDimitry Andric 79349cc55cSDimitry Andric unsigned NumOperands = MI.getNumOperands(); 80349cc55cSDimitry Andric const ValueMapping *OperandsMapping = &M68k::ValueMappings[M68k::GPR3OpsIdx]; 81349cc55cSDimitry Andric 82349cc55cSDimitry Andric switch (Opc) { 83349cc55cSDimitry Andric case G_ADD: 84349cc55cSDimitry Andric case G_SUB: 85349cc55cSDimitry Andric case G_MUL: 86349cc55cSDimitry Andric case G_SDIV: 87349cc55cSDimitry Andric case G_UDIV: 88349cc55cSDimitry Andric case G_LOAD: 89349cc55cSDimitry Andric case G_STORE: { 90349cc55cSDimitry Andric OperandsMapping = &M68k::ValueMappings[M68k::GPR3OpsIdx]; 91349cc55cSDimitry Andric break; 92349cc55cSDimitry Andric } 93349cc55cSDimitry Andric 94349cc55cSDimitry Andric case G_CONSTANT: 95349cc55cSDimitry Andric case G_FRAME_INDEX: 96349cc55cSDimitry Andric OperandsMapping = 97349cc55cSDimitry Andric getOperandsMapping({&M68k::ValueMappings[M68k::GPR3OpsIdx], nullptr}); 98349cc55cSDimitry Andric break; 99349cc55cSDimitry Andric default: 100349cc55cSDimitry Andric return getInvalidInstructionMapping(); 101349cc55cSDimitry Andric } 102349cc55cSDimitry Andric 103349cc55cSDimitry Andric return getInstructionMapping(DefaultMappingID, /*Cost=*/1, OperandsMapping, 104349cc55cSDimitry Andric NumOperands); 105349cc55cSDimitry Andric } 106