1 //===-- PPCRegisterBankInfo.h -----------------------------------*- 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 ///
9 /// \file
10 /// This file declares the targeting of the RegisterBankInfo class for PowerPC.
11 ///
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_LIB_TARGET_PPC_GISEL_PPCREGISTERBANKINFO_H
15 #define LLVM_LIB_TARGET_PPC_GISEL_PPCREGISTERBANKINFO_H
16 
17 #include "llvm/CodeGen/RegisterBank.h"
18 #include "llvm/CodeGen/RegisterBankInfo.h"
19 #include "llvm/CodeGen/TargetRegisterInfo.h"
20 
21 #define GET_REGBANK_DECLARATIONS
22 #include "PPCGenRegisterBank.inc"
23 
24 namespace llvm {
25 class TargetRegisterInfo;
26 
27 class PPCGenRegisterBankInfo : public RegisterBankInfo {
28 protected:
29   enum PartialMappingIdx {
30     PMI_None = -1,
31     PMI_GPR32 = 1,
32     PMI_GPR64 = 2,
33     PMI_FPR32 = 3,
34     PMI_FPR64 = 4,
35     PMI_CR = 5,
36     PMI_Min = PMI_GPR32,
37   };
38 
39   static RegisterBankInfo::PartialMapping PartMappings[];
40   static RegisterBankInfo::ValueMapping ValMappings[];
41   static PartialMappingIdx BankIDToCopyMapIdx[];
42 
43   /// Get the pointer to the ValueMapping representing the RegisterBank
44   /// at \p RBIdx.
45   ///
46   /// The returned mapping works for instructions with the same kind of
47   /// operands for up to 3 operands.
48   ///
49   /// \pre \p RBIdx != PartialMappingIdx::None
50   static const RegisterBankInfo::ValueMapping *
51   getValueMapping(PartialMappingIdx RBIdx);
52 
53   /// Get the pointer to the ValueMapping of the operands of a copy
54   /// instruction from the \p SrcBankID register bank to the \p DstBankID
55   /// register bank with a size of \p Size.
56   static const RegisterBankInfo::ValueMapping *
57   getCopyMapping(unsigned DstBankID, unsigned SrcBankID, unsigned Size);
58 
59 #define GET_TARGET_REGBANK_CLASS
60 #include "PPCGenRegisterBank.inc"
61 };
62 
63 class PPCRegisterBankInfo final : public PPCGenRegisterBankInfo {
64 public:
65   PPCRegisterBankInfo(const TargetRegisterInfo &TRI);
66 
67   const RegisterBank &getRegBankFromRegClass(const TargetRegisterClass &RC,
68                                              LLT Ty) const override;
69   const InstructionMapping &
70   getInstrMapping(const MachineInstr &MI) const override;
71 
72   InstructionMappings
73   getInstrAlternativeMappings(const MachineInstr &MI) const override;
74 
75 private:
76   /// Maximum recursion depth for hasFPConstraints.
77   const unsigned MaxFPRSearchDepth = 2;
78 
79   /// \returns true if \p MI only uses and defines FPRs.
80   bool hasFPConstraints(const MachineInstr &MI, const MachineRegisterInfo &MRI,
81                         const TargetRegisterInfo &TRI,
82                         unsigned Depth = 0) const;
83 
84   /// \returns true if \p MI only uses FPRs.
85   bool onlyUsesFP(const MachineInstr &MI, const MachineRegisterInfo &MRI,
86                   const TargetRegisterInfo &TRI, unsigned Depth = 0) const;
87 
88   /// \returns true if \p MI only defines FPRs.
89   bool onlyDefinesFP(const MachineInstr &MI, const MachineRegisterInfo &MRI,
90                      const TargetRegisterInfo &TRI, unsigned Depth = 0) const;
91 };
92 } // namespace llvm
93 
94 #endif
95