Revert " [LoongArch][ISel] Check the number of sign bits in `PatGprGpr_32` (#107432)"
[llvm-project.git] / llvm / lib / CodeGen / RegisterCoalescer.h
blobf265d93fb0d63d5f2fda33028443bccd5f006c07
1 //===- RegisterCoalescer.h - Register Coalescing Interface ------*- 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 // This file contains the abstract interface for register coalescers,
10 // allowing them to interact with and query register allocators.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_LIB_CODEGEN_REGISTERCOALESCER_H
15 #define LLVM_LIB_CODEGEN_REGISTERCOALESCER_H
17 #include "llvm/CodeGen/Register.h"
19 namespace llvm {
21 class MachineInstr;
22 class TargetRegisterClass;
23 class TargetRegisterInfo;
25 /// A helper class for register coalescers. When deciding if
26 /// two registers can be coalesced, CoalescerPair can determine if a copy
27 /// instruction would become an identity copy after coalescing.
28 class CoalescerPair {
29 const TargetRegisterInfo &TRI;
31 /// The register that will be left after coalescing. It can be a
32 /// virtual or physical register.
33 Register DstReg;
35 /// The virtual register that will be coalesced into dstReg.
36 Register SrcReg;
38 /// The sub-register index of the old DstReg in the new coalesced register.
39 unsigned DstIdx = 0;
41 /// The sub-register index of the old SrcReg in the new coalesced register.
42 unsigned SrcIdx = 0;
44 /// True when the original copy was a partial subregister copy.
45 bool Partial = false;
47 /// True when both regs are virtual and newRC is constrained.
48 bool CrossClass = false;
50 /// True when DstReg and SrcReg are reversed from the original
51 /// copy instruction.
52 bool Flipped = false;
54 /// The register class of the coalesced register, or NULL if DstReg
55 /// is a physreg. This register class may be a super-register of both
56 /// SrcReg and DstReg.
57 const TargetRegisterClass *NewRC = nullptr;
59 public:
60 CoalescerPair(const TargetRegisterInfo &tri) : TRI(tri) {}
62 /// Create a CoalescerPair representing a virtreg-to-physreg copy.
63 /// No need to call setRegisters().
64 CoalescerPair(Register VirtReg, MCRegister PhysReg,
65 const TargetRegisterInfo &tri)
66 : TRI(tri), DstReg(PhysReg), SrcReg(VirtReg) {}
68 /// Set registers to match the copy instruction MI. Return
69 /// false if MI is not a coalescable copy instruction.
70 bool setRegisters(const MachineInstr*);
72 /// Swap SrcReg and DstReg. Return false if swapping is impossible
73 /// because DstReg is a physical register, or SubIdx is set.
74 bool flip();
76 /// Return true if MI is a copy instruction that will become
77 /// an identity copy after coalescing.
78 bool isCoalescable(const MachineInstr*) const;
80 /// Return true if DstReg is a physical register.
81 bool isPhys() const { return !NewRC; }
83 /// Return true if the original copy instruction did not copy
84 /// the full register, but was a subreg operation.
85 bool isPartial() const { return Partial; }
87 /// Return true if DstReg is virtual and NewRC is a smaller
88 /// register class than DstReg's.
89 bool isCrossClass() const { return CrossClass; }
91 /// Return true when getSrcReg is the register being defined by
92 /// the original copy instruction.
93 bool isFlipped() const { return Flipped; }
95 /// Return the register (virtual or physical) that will remain
96 /// after coalescing.
97 Register getDstReg() const { return DstReg; }
99 /// Return the virtual register that will be coalesced away.
100 Register getSrcReg() const { return SrcReg; }
102 /// Return the subregister index that DstReg will be coalesced into, or 0.
103 unsigned getDstIdx() const { return DstIdx; }
105 /// Return the subregister index that SrcReg will be coalesced into, or 0.
106 unsigned getSrcIdx() const { return SrcIdx; }
108 /// Return the register class of the coalesced register.
109 const TargetRegisterClass *getNewRC() const { return NewRC; }
112 } // end namespace llvm
114 #endif // LLVM_LIB_CODEGEN_REGISTERCOALESCER_H