LLVM  14.0.0git
M68kRegisterBankInfo.cpp
Go to the documentation of this file.
1 //===-- M68kRegisterBankInfo.cpp -------------------------------*- C++ -*-===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 /// \file
9 /// This file implements the targeting of the RegisterBankInfo class for M68k.
10 /// \todo This should be generated by TableGen.
11 //===----------------------------------------------------------------------===//
12 
13 #include "M68kRegisterBankInfo.h"
14 #include "M68kInstrInfo.h" // For the register classes
15 #include "M68kSubtarget.h"
20 
21 #define GET_TARGET_REGBANK_IMPL
22 #include "M68kGenRegisterBank.inc"
23 
24 using namespace llvm;
25 
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).
29 namespace llvm {
30 namespace M68k {
34 };
35 
37  // GPR Partial Mapping
38  {0, 32, GPRRegBank},
39 };
40 
44 };
45 
47  // invalid
48  {nullptr, 0},
49  // 3 operands in GPRs
50  {&PartMappings[PMI_GPR - PMI_Min], 1},
51  {&PartMappings[PMI_GPR - PMI_Min], 1},
52  {&PartMappings[PMI_GPR - PMI_Min], 1},
53 
54 };
55 } // end namespace M68k
56 } // end namespace llvm
57 
60 
61 const RegisterBank &
63  LLT) const {
64  return getRegBank(M68k::GPRRegBankID);
65 }
66 
69  auto Opc = MI.getOpcode();
70 
71  if (!isPreISelGenericOpcode(Opc)) {
72  const InstructionMapping &Mapping = getInstrMappingImpl(MI);
73  if (Mapping.isValid())
74  return Mapping;
75  }
76 
77  using namespace TargetOpcode;
78 
79  unsigned NumOperands = MI.getNumOperands();
80  const ValueMapping *OperandsMapping = &M68k::ValueMappings[M68k::GPR3OpsIdx];
81 
82  switch (Opc) {
83  case G_ADD:
84  case G_SUB:
85  case G_MUL:
86  case G_SDIV:
87  case G_UDIV:
88  case G_LOAD:
89  case G_STORE: {
90  OperandsMapping = &M68k::ValueMappings[M68k::GPR3OpsIdx];
91  break;
92  }
93 
94  case G_CONSTANT:
95  case G_FRAME_INDEX:
96  OperandsMapping =
98  break;
99  default:
101  }
102 
103  return getInstructionMapping(DefaultMappingID, /*Cost=*/1, OperandsMapping,
104  NumOperands);
105 }
llvm::M68k::InvalidIdx
@ InvalidIdx
Definition: M68kRegisterBankInfo.cpp:42
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:105
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
llvm::RegisterBankInfo::getInstrMappingImpl
const InstructionMapping & getInstrMappingImpl(const MachineInstr &MI) const
Try to get the mapping of MI.
Definition: RegisterBankInfo.cpp:162
llvm::isPreISelGenericOpcode
bool isPreISelGenericOpcode(unsigned Opcode)
Check whether the given Opcode is a generic opcode that is not supposed to appear after ISel.
Definition: TargetOpcodes.h:30
llvm::M68kRegisterBankInfo::getRegBankFromRegClass
const RegisterBank & getRegBankFromRegClass(const TargetRegisterClass &RC, LLT) const override
Get a register bank that covers RC.
Definition: M68kRegisterBankInfo.cpp:62
llvm::RegisterBankInfo::getRegBank
RegisterBank & getRegBank(unsigned ID)
Get the register bank identified by ID.
Definition: RegisterBankInfo.h:432
RegisterBankInfo.h
llvm::M68kGenRegisterBankInfo
Definition: M68kRegisterBankInfo.h:26
llvm::TargetRegisterInfo
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
Definition: TargetRegisterInfo.h:233
llvm::RegisterBankInfo::InstructionMapping::isValid
bool isValid() const
Check whether this object is valid.
Definition: RegisterBankInfo.h:254
TRI
unsigned const TargetRegisterInfo * TRI
Definition: MachineSink.cpp:1559
llvm::M68k::ValueMappingIdx
ValueMappingIdx
Definition: M68kRegisterBankInfo.cpp:41
MachineRegisterInfo.h
M68kInstrInfo.h
llvm::M68kRegisterBankInfo::M68kRegisterBankInfo
M68kRegisterBankInfo(const TargetRegisterInfo &TRI)
Definition: M68kRegisterBankInfo.cpp:58
llvm::RegisterBank
This class implements the register bank concept.
Definition: RegisterBank.h:28
llvm::RegisterBankInfo::PartialMapping
Helper struct that represents how a value is partially mapped into a register.
Definition: RegisterBankInfo.h:48
llvm::TargetRegisterClass
Definition: TargetRegisterInfo.h:46
llvm::M68k::PartialMappingIdx
PartialMappingIdx
Definition: M68kRegisterBankInfo.cpp:31
M68kRegisterBankInfo.h
llvm::M68kRegisterBankInfo::getInstrMapping
const InstructionMapping & getInstrMapping(const MachineInstr &MI) const override
Get the mapping of the different operands of MI on the register bank.
Definition: M68kRegisterBankInfo.cpp:68
llvm::MachineInstr
Representation of each machine instruction.
Definition: MachineInstr.h:64
llvm::RegisterBankInfo::InstructionMapping
Helper class that represents how the value of an instruction may be mapped and what is the related co...
Definition: RegisterBankInfo.h:189
llvm::RegisterBankInfo::DefaultMappingID
static const unsigned DefaultMappingID
Identifier used when the related instruction mapping instance is generated by target independent code...
Definition: RegisterBankInfo.h:652
llvm::RegisterBankInfo::getOperandsMapping
const ValueMapping * getOperandsMapping(Iterator Begin, Iterator End) const
Get the uniquely generated array of ValueMapping for the elements of between Begin and End.
Definition: RegisterBankInfo.cpp:332
llvm::RegisterBankInfo::getInstructionMapping
const InstructionMapping & getInstructionMapping(unsigned ID, unsigned Cost, const ValueMapping *OperandsMapping, unsigned NumOperands) const
Method to get a uniquely generated InstructionMapping.
Definition: RegisterBankInfo.h:526
llvm::RegisterBankInfo::ValueMapping
Helper struct that represents how a value is mapped through different register banks.
Definition: RegisterBankInfo.h:145
llvm::M68k::PartMappings
RegisterBankInfo::PartialMapping PartMappings[]
Definition: M68kRegisterBankInfo.cpp:36
llvm::M68k::GPR3OpsIdx
@ GPR3OpsIdx
Definition: M68kRegisterBankInfo.cpp:43
llvm::RegisterBankInfo::getInvalidInstructionMapping
const InstructionMapping & getInvalidInstructionMapping() const
Method to get a uniquely generated invalid InstructionMapping.
Definition: RegisterBankInfo.h:534
llvm::M68k::PMI_GPR
@ PMI_GPR
Definition: M68kRegisterBankInfo.cpp:32
llvm::M68k::ValueMappings
RegisterBankInfo::ValueMapping ValueMappings[]
Definition: M68kRegisterBankInfo.cpp:46
RegisterBank.h
M68kSubtarget.h
llvm::M68k::PMI_Min
@ PMI_Min
Definition: M68kRegisterBankInfo.cpp:33
TargetRegisterInfo.h
llvm::LLT
Definition: LowLevelTypeImpl.h:40