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_CODEGEN_REGISTER_COALESCER_H
16 #define LLVM_CODEGEN_REGISTER_COALESCER_H
21 class TargetRegisterInfo;
22 class TargetRegisterClass;
23 class TargetInstrInfo;
25 /// CoalescerPair - 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.
29 const TargetRegisterInfo &TRI;
31 /// DstReg - The register that will be left after coalescing. It can be a
32 /// virtual or physical register.
35 /// SrcReg - the virtual register that will be coalesced into dstReg.
38 /// DstIdx - The sub-register index of the old DstReg in the new coalesced
42 /// SrcIdx - The sub-register index of the old SrcReg in the new coalesced
46 /// Partial - True when the original copy was a partial subregister copy.
49 /// CrossClass - True when both regs are virtual, and newRC is constrained.
52 /// Flipped - True when DstReg and SrcReg are reversed from the original
56 /// NewRC - 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;
62 CoalescerPair(const TargetRegisterInfo &tri)
63 : TRI(tri), DstReg(0), SrcReg(0), DstIdx(0), SrcIdx(0),
64 Partial(false), CrossClass(false), Flipped(false), NewRC(0) {}
66 /// setRegisters - set registers to match the copy instruction MI. Return
67 /// false if MI is not a coalescable copy instruction.
68 bool setRegisters(const MachineInstr*);
70 /// flip - Swap SrcReg and DstReg. Return false if swapping is impossible
71 /// because DstReg is a physical register, or SubIdx is set.
74 /// isCoalescable - Return true if MI is a copy instruction that will become
75 /// an identity copy after coalescing.
76 bool isCoalescable(const MachineInstr*) const;
78 /// isPhys - Return true if DstReg is a physical register.
79 bool isPhys() const { return !NewRC; }
81 /// isPartial - Return true if the original copy instruction did not copy
82 /// the full register, but was a subreg operation.
83 bool isPartial() const { return Partial; }
85 /// isCrossClass - Return true if DstReg is virtual and NewRC is a smaller
86 /// register class than DstReg's.
87 bool isCrossClass() const { return CrossClass; }
89 /// isFlipped - Return true when getSrcReg is the register being defined by
90 /// the original copy instruction.
91 bool isFlipped() const { return Flipped; }
93 /// getDstReg - Return the register (virtual or physical) that will remain
95 unsigned getDstReg() const { return DstReg; }
97 /// getSrcReg - Return the virtual register that will be coalesced away.
98 unsigned getSrcReg() const { return SrcReg; }
100 /// getDstIdx - Return the subregister index that DstReg will be coalesced
102 unsigned getDstIdx() const { return DstIdx; }
104 /// getSrcIdx - Return the subregister index that SrcReg will be coalesced
106 unsigned getSrcIdx() const { return SrcIdx; }
108 /// getNewRC - Return the register class of the coalesced register.
109 const TargetRegisterClass *getNewRC() const { return NewRC; }
111 } // End llvm namespace