1 //===- RegisterCoalescer.h - Register Coalescing Interface ------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains the abstract interface for register coalescers,
11 // allowing them to interact with and query register allocators.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_LIB_CODEGEN_REGISTERCOALESCER_H
16 #define LLVM_LIB_CODEGEN_REGISTERCOALESCER_H
21 class TargetRegisterClass
;
22 class TargetRegisterInfo
;
24 /// A helper class for register coalescers. When deciding if
25 /// two registers can be coalesced, CoalescerPair can determine if a copy
26 /// instruction would become an identity copy after coalescing.
28 const TargetRegisterInfo
&TRI
;
30 /// The register that will be left after coalescing. It can be a
31 /// virtual or physical register.
34 /// The virtual register that will be coalesced into dstReg.
37 /// The sub-register index of the old DstReg in the new coalesced register.
40 /// The sub-register index of the old SrcReg in the new coalesced register.
43 /// True when the original copy was a partial subregister copy.
46 /// True when both regs are virtual and newRC is constrained.
47 bool CrossClass
= false;
49 /// True when DstReg and SrcReg are reversed from the original
53 /// The register class of the coalesced register, or NULL if DstReg
54 /// is a physreg. This register class may be a super-register of both
55 /// SrcReg and DstReg.
56 const TargetRegisterClass
*NewRC
= nullptr;
59 CoalescerPair(const TargetRegisterInfo
&tri
) : TRI(tri
) {}
61 /// Create a CoalescerPair representing a virtreg-to-physreg copy.
62 /// No need to call setRegisters().
63 CoalescerPair(unsigned VirtReg
, unsigned PhysReg
,
64 const TargetRegisterInfo
&tri
)
65 : TRI(tri
), DstReg(PhysReg
), SrcReg(VirtReg
) {}
67 /// Set registers to match the copy instruction MI. Return
68 /// false if MI is not a coalescable copy instruction.
69 bool setRegisters(const MachineInstr
*);
71 /// Swap SrcReg and DstReg. Return false if swapping is impossible
72 /// because DstReg is a physical register, or SubIdx is set.
75 /// Return true if MI is a copy instruction that will become
76 /// an identity copy after coalescing.
77 bool isCoalescable(const MachineInstr
*) const;
79 /// Return true if DstReg is a physical register.
80 bool isPhys() const { return !NewRC
; }
82 /// Return true if the original copy instruction did not copy
83 /// the full register, but was a subreg operation.
84 bool isPartial() const { return Partial
; }
86 /// Return true if DstReg is virtual and NewRC is a smaller
87 /// register class than DstReg's.
88 bool isCrossClass() const { return CrossClass
; }
90 /// Return true when getSrcReg is the register being defined by
91 /// the original copy instruction.
92 bool isFlipped() const { return Flipped
; }
94 /// Return the register (virtual or physical) that will remain
96 unsigned getDstReg() const { return DstReg
; }
98 /// Return the virtual register that will be coalesced away.
99 unsigned getSrcReg() const { return SrcReg
; }
101 /// Return the subregister index that DstReg will be coalesced into, or 0.
102 unsigned getDstIdx() const { return DstIdx
; }
104 /// Return the subregister index that SrcReg will be coalesced into, or 0.
105 unsigned getSrcIdx() const { return SrcIdx
; }
107 /// Return the register class of the coalesced register.
108 const TargetRegisterClass
*getNewRC() const { return NewRC
; }
111 } // end namespace llvm
113 #endif // LLVM_LIB_CODEGEN_REGISTERCOALESCER_H