LLVM 23.0.0git
RegisterCoalescer.h
Go to the documentation of this file.
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.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_LIB_CODEGEN_REGISTERCOALESCER_H
15#define LLVM_LIB_CODEGEN_REGISTERCOALESCER_H
16
19
20namespace llvm {
21
22class MachineInstr;
23class MCRegisterClass;
26
27/// A helper class for register coalescers. When deciding if
28/// two registers can be coalesced, CoalescerPair can determine if a copy
29/// instruction would become an identity copy after coalescing.
31 const TargetRegisterInfo &TRI;
32
33 /// The register that will be left after coalescing. It can be a
34 /// virtual or physical register.
35 Register DstReg;
36
37 /// The virtual register that will be coalesced into dstReg.
38 Register SrcReg;
39
40 /// The sub-register index of the old DstReg in the new coalesced register.
41 unsigned DstIdx = 0;
42
43 /// The sub-register index of the old SrcReg in the new coalesced register.
44 unsigned SrcIdx = 0;
45
46 /// True when the original copy was a partial subregister copy.
47 bool Partial = false;
48
49 /// True when both regs are virtual and newRC is constrained.
50 bool CrossClass = false;
51
52 /// True when DstReg and SrcReg are reversed from the original
53 /// copy instruction.
54 bool Flipped = false;
55
56 /// The register class of the coalesced register, or NULL if DstReg
57 /// is a physreg. This register class may be a super-register of both
58 /// SrcReg and DstReg.
59 const TargetRegisterClass *NewRC = nullptr;
60
61public:
62 CoalescerPair(const TargetRegisterInfo &tri) : TRI(tri) {}
63
64 /// Create a CoalescerPair representing a virtreg-to-physreg copy.
65 /// No need to call setRegisters().
67 const TargetRegisterInfo &tri)
68 : TRI(tri), DstReg(PhysReg), SrcReg(VirtReg) {}
69
70 /// Set registers to match the copy instruction MI. Return
71 /// false if MI is not a coalescable copy instruction.
72 bool setRegisters(const MachineInstr *);
73
74 /// Swap SrcReg and DstReg. Return false if swapping is impossible
75 /// because DstReg is a physical register, or SubIdx is set.
76 bool flip();
77
78 /// Return true if MI is a copy instruction that will become
79 /// an identity copy after coalescing.
80 bool isCoalescable(const MachineInstr *) const;
81
82 /// Return true if DstReg is a physical register.
83 bool isPhys() const { return !NewRC; }
84
85 /// Return true if the original copy instruction did not copy
86 /// the full register, but was a subreg operation.
87 bool isPartial() const { return Partial; }
88
89 /// Return true if DstReg is virtual and NewRC is a smaller
90 /// register class than DstReg's.
91 bool isCrossClass() const { return CrossClass; }
92
93 /// Return true when getSrcReg is the register being defined by
94 /// the original copy instruction.
95 bool isFlipped() const { return Flipped; }
96
97 /// Return the register (virtual or physical) that will remain
98 /// after coalescing.
99 Register getDstReg() const { return DstReg; }
100
101 /// Return the virtual register that will be coalesced away.
102 Register getSrcReg() const { return SrcReg; }
103
104 /// Return the subregister index that DstReg will be coalesced into, or 0.
105 unsigned getDstIdx() const { return DstIdx; }
106
107 /// Return the subregister index that SrcReg will be coalesced into, or 0.
108 unsigned getSrcIdx() const { return SrcIdx; }
109
110 /// Return the register class of the coalesced register.
111 const TargetRegisterClass *getNewRC() const { return NewRC; }
112};
113
114} // end namespace llvm
115
116#endif // LLVM_LIB_CODEGEN_REGISTERCOALESCER_H
unsigned getDstIdx() const
Return the subregister index that DstReg will be coalesced into, or 0.
bool isFlipped() const
Return true when getSrcReg is the register being defined by the original copy instruction.
bool isPartial() const
Return true if the original copy instruction did not copy the full register, but was a subreg operati...
bool flip()
Swap SrcReg and DstReg.
bool isPhys() const
Return true if DstReg is a physical register.
bool isCrossClass() const
Return true if DstReg is virtual and NewRC is a smaller register class than DstReg's.
Register getDstReg() const
Return the register (virtual or physical) that will remain after coalescing.
bool isCoalescable(const MachineInstr *) const
Return true if MI is a copy instruction that will become an identity copy after coalescing.
CoalescerPair(const TargetRegisterInfo &tri)
CoalescerPair(Register VirtReg, MCRegister PhysReg, const TargetRegisterInfo &tri)
Create a CoalescerPair representing a virtreg-to-physreg copy.
const TargetRegisterClass * getNewRC() const
Return the register class of the coalesced register.
bool setRegisters(const MachineInstr *)
Set registers to match the copy instruction MI.
unsigned getSrcIdx() const
Return the subregister index that SrcReg will be coalesced into, or 0.
Register getSrcReg() const
Return the virtual register that will be coalesced away.
MCRegisterClass - Base class of TargetRegisterClass.
Wrapper class representing physical registers. Should be passed by value.
Definition MCRegister.h:41
Representation of each machine instruction.
Wrapper class representing virtual and physical registers.
Definition Register.h:20
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
This is an optimization pass for GlobalISel generic memory operations.
MCRegisterClass TargetRegisterClass
Definition FastISel.h:58