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 TargetInstrInfo &TII;
30 const TargetRegisterInfo &TRI;
32 /// DstReg - The register that will be left after coalescing. It can be a
33 /// virtual or physical register.
36 /// SrcReg - the virtual register that will be coalesced into dstReg.
39 /// subReg_ - The subregister index of srcReg in DstReg. It is possible the
40 /// coalesce SrcReg into a subreg of the larger DstReg when DstReg is a
44 /// Partial - True when the original copy was a partial subregister copy.
47 /// CrossClass - True when both regs are virtual, and newRC is constrained.
50 /// Flipped - True when DstReg and SrcReg are reversed from the oriignal
54 /// NewRC - The register class of the coalesced register, or NULL if DstReg
56 const TargetRegisterClass *NewRC;
59 CoalescerPair(const TargetInstrInfo &tii, const TargetRegisterInfo &tri)
60 : TII(tii), TRI(tri), DstReg(0), SrcReg(0), SubIdx(0),
61 Partial(false), CrossClass(false), Flipped(false), NewRC(0) {}
63 /// setRegisters - set registers to match the copy instruction MI. Return
64 /// false if MI is not a coalescable copy instruction.
65 bool setRegisters(const MachineInstr*);
67 /// flip - Swap SrcReg and DstReg. Return false if swapping is impossible
68 /// because DstReg is a physical register, or SubIdx is set.
71 /// isCoalescable - Return true if MI is a copy instruction that will become
72 /// an identity copy after coalescing.
73 bool isCoalescable(const MachineInstr*) const;
75 /// isPhys - Return true if DstReg is a physical register.
76 bool isPhys() const { return !NewRC; }
78 /// isPartial - Return true if the original copy instruction did not copy
79 /// the full register, but was a subreg operation.
80 bool isPartial() const { return Partial; }
82 /// isCrossClass - Return true if DstReg is virtual and NewRC is a smaller
83 /// register class than DstReg's.
84 bool isCrossClass() const { return CrossClass; }
86 /// isFlipped - Return true when getSrcReg is the register being defined by
87 /// the original copy instruction.
88 bool isFlipped() const { return Flipped; }
90 /// getDstReg - Return the register (virtual or physical) that will remain
92 unsigned getDstReg() const { return DstReg; }
94 /// getSrcReg - Return the virtual register that will be coalesced away.
95 unsigned getSrcReg() const { return SrcReg; }
97 /// getSubIdx - Return the subregister index in DstReg that SrcReg will be
98 /// coalesced into, or 0.
99 unsigned getSubIdx() const { return SubIdx; }
101 /// getNewRC - Return the register class of the coalesced register.
102 const TargetRegisterClass *getNewRC() const { return NewRC; }
104 } // End llvm namespace