Extend the CoalescerPair interface to handle symmetric sub-register copies.
[oota-llvm.git] / lib / CodeGen / RegisterCoalescer.h
1 //===-- RegisterCoalescer.h - Register Coalescing Interface -----*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains the abstract interface for register coalescers,
11 // allowing them to interact with and query register allocators.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_CODEGEN_REGISTER_COALESCER_H
16 #define LLVM_CODEGEN_REGISTER_COALESCER_H
17
18 namespace llvm {
19
20   class MachineInstr;
21   class TargetRegisterInfo;
22   class TargetRegisterClass;
23   class TargetInstrInfo;
24
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.
28   class CoalescerPair {
29     const TargetInstrInfo &TII;
30     const TargetRegisterInfo &TRI;
31
32     /// DstReg - The register that will be left after coalescing. It can be a
33     /// virtual or physical register.
34     unsigned DstReg;
35
36     /// SrcReg - the virtual register that will be coalesced into dstReg.
37     unsigned SrcReg;
38
39     /// DstIdx - The sub-register index of the old DstReg in the new coalesced
40     /// register.
41     unsigned DstIdx;
42
43     /// SrcIdx - The sub-register index of the old SrcReg in the new coalesced
44     /// register.
45     unsigned SrcIdx;
46
47     /// Partial - True when the original copy was a partial subregister copy.
48     bool Partial;
49
50     /// CrossClass - True when both regs are virtual, and newRC is constrained.
51     bool CrossClass;
52
53     /// Flipped - True when DstReg and SrcReg are reversed from the original
54     /// copy instruction.
55     bool Flipped;
56
57     /// NewRC - The register class of the coalesced register, or NULL if DstReg
58     /// is a physreg. This register class may be a super-register of both
59     /// SrcReg and DstReg.
60     const TargetRegisterClass *NewRC;
61
62   public:
63     CoalescerPair(const TargetInstrInfo &tii, const TargetRegisterInfo &tri)
64       : TII(tii), TRI(tri), DstReg(0), SrcReg(0), DstIdx(0), SrcIdx(0),
65         Partial(false), CrossClass(false), Flipped(false), NewRC(0) {}
66
67     /// setRegisters - set registers to match the copy instruction MI. Return
68     /// false if MI is not a coalescable copy instruction.
69     bool setRegisters(const MachineInstr*);
70
71     /// flip - Swap SrcReg and DstReg. Return false if swapping is impossible
72     /// because DstReg is a physical register, or SubIdx is set.
73     bool flip();
74
75     /// isCoalescable - Return true if MI is a copy instruction that will become
76     /// an identity copy after coalescing.
77     bool isCoalescable(const MachineInstr*) const;
78
79     /// isPhys - Return true if DstReg is a physical register.
80     bool isPhys() const { return !NewRC; }
81
82     /// isPartial - 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; }
85
86     /// isCrossClass - Return true if DstReg is virtual and NewRC is a smaller
87     /// register class than DstReg's.
88     bool isCrossClass() const { return CrossClass; }
89
90     /// isFlipped - Return true when getSrcReg is the register being defined by
91     /// the original copy instruction.
92     bool isFlipped() const { return Flipped; }
93
94     /// getDstReg - Return the register (virtual or physical) that will remain
95     /// after coalescing.
96     unsigned getDstReg() const { return DstReg; }
97
98     /// getSrcReg - Return the virtual register that will be coalesced away.
99     unsigned getSrcReg() const { return SrcReg; }
100
101     /// getDstIdx - Return the subregister index that DstReg will be coalesced
102     /// into, or 0.
103     unsigned getDstIdx() const { return DstIdx; }
104
105     /// getSrcIdx - Return the subregister index that SrcReg will be coalesced
106     /// into, or 0.
107     unsigned getSrcIdx() const { return SrcIdx; }
108
109     /// getNewRC - Return the register class of the coalesced register.
110     const TargetRegisterClass *getNewRC() const { return NewRC; }
111   };
112 } // End llvm namespace
113
114 #endif