1//===- PPCGenRegisterBankInfo.def -------------------------------*- 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 defines all the static objects used by PPCRegisterBankInfo.
10/// \todo This should be generated by TableGen, because the logic here can be
11///  derived from register bank definition. Not yet implemented.
12//===----------------------------------------------------------------------===//
13
14namespace llvm {
15RegisterBankInfo::PartialMapping PPCGenRegisterBankInfo::PartMappings[]{
16    /* StartIdx, Length, RegBank */
17    // 0: GPR 32-bit value.
18    {0, 32, PPC::GPRRegBank},
19    // 1: GPR 64-bit value.
20    {0, 64, PPC::GPRRegBank},
21    // 2: FPR 32-bit value
22    {0, 32, PPC::FPRRegBank},
23    // 3: FPR 64-bit value
24    {0, 64, PPC::FPRRegBank},
25    // 4: CR 4-bit value
26    {0, 4, PPC::CRRegBank},
27};
28
29// ValueMappings.
30// Pointers to the entries in this array are returned by getValueMapping() and
31// getCopyMapping().
32//
33// The array has the following structure:
34// - At index 0 is the invalid entry.
35// - After that, the mappings for the register types from PartialMappingIdx
36//   follow. Each mapping consists of 3 entries, which is needed to cover
37//   3-operands instructions.
38// - Last, mappings for cross-register bank moves follow. Since COPY has only
39//   2 operands, a mapping consists of 2 entries.
40RegisterBankInfo::ValueMapping PPCGenRegisterBankInfo::ValMappings[]{
41    /* BreakDown, NumBreakDowns */
42    // 0: invalid
43    {nullptr, 0},
44    // 1: GPR 32-bit value.
45    {&PPCGenRegisterBankInfo::PartMappings[PMI_GPR32 - PMI_Min], 1},
46    {&PPCGenRegisterBankInfo::PartMappings[PMI_GPR32 - PMI_Min], 1},
47    {&PPCGenRegisterBankInfo::PartMappings[PMI_GPR32 - PMI_Min], 1},
48    // 4: GPR 64-bit value.
49    {&PPCGenRegisterBankInfo::PartMappings[PMI_GPR64 - PMI_Min], 1},
50    {&PPCGenRegisterBankInfo::PartMappings[PMI_GPR64 - PMI_Min], 1},
51    {&PPCGenRegisterBankInfo::PartMappings[PMI_GPR64 - PMI_Min], 1},
52    // 7: FPR 32-bit value.
53    {&PPCGenRegisterBankInfo::PartMappings[PMI_FPR32 - PMI_Min], 1},
54    {&PPCGenRegisterBankInfo::PartMappings[PMI_FPR32 - PMI_Min], 1},
55    {&PPCGenRegisterBankInfo::PartMappings[PMI_FPR32 - PMI_Min], 1},
56    // 10: FPR 64-bit value.
57    {&PPCGenRegisterBankInfo::PartMappings[PMI_FPR64 - PMI_Min], 1},
58    {&PPCGenRegisterBankInfo::PartMappings[PMI_FPR64 - PMI_Min], 1},
59    {&PPCGenRegisterBankInfo::PartMappings[PMI_FPR64 - PMI_Min], 1},
60    // 13: CR 4-bit value.
61    {&PPCGenRegisterBankInfo::PartMappings[PMI_CR - PMI_Min], 1},
62};
63
64// TODO Too simple!
65const RegisterBankInfo::ValueMapping *
66PPCGenRegisterBankInfo::getValueMapping(PartialMappingIdx RBIdx) {
67  assert(RBIdx != PartialMappingIdx::PMI_None && "No mapping needed for that");
68
69  unsigned ValMappingIdx = RBIdx - PMI_Min;
70
71  return &ValMappings[1 + 3 * ValMappingIdx];
72}
73
74// TODO Too simple!
75const RegisterBankInfo::ValueMapping *
76PPCGenRegisterBankInfo::getCopyMapping(unsigned DstBankID, unsigned SrcBankID,
77                                       unsigned Size) {
78  assert(DstBankID < PPC::NumRegisterBanks && "Invalid bank ID");
79  assert(SrcBankID < PPC::NumRegisterBanks && "Invalid bank ID");
80
81  return &ValMappings[1];
82}
83
84} // namespace llvm
85