a2957f501e6920dbd6eec02c469c3a6ee56da6e4
[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     /// 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
41     /// virtual register.
42     unsigned subIdx_;
43
44     /// partial_ - True when the original copy was a partial subregister copy.
45     bool partial_;
46
47     /// crossClass_ - True when both regs are virtual, and newRC is constrained.
48     bool crossClass_;
49
50     /// flipped_ - True when DstReg and SrcReg are reversed from the oriignal copy
51     /// instruction.
52     bool flipped_;
53
54     /// newRC_ - The register class of the coalesced register, or NULL if dstReg_
55     /// is a physreg.
56     const TargetRegisterClass *newRC_;
57
58   public:
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) {}
62
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*);
66
67     /// flip - Swap srcReg_ and dstReg_. Return false if swapping is impossible
68     /// because dstReg_ is a physical register, or subIdx_ is set.
69     bool flip();
70
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;
74
75     /// isPhys - Return true if DstReg is a physical register.
76     bool isPhys() const { return !newRC_; }
77
78     /// isPartial - Return true if the original copy instruction did not copy the
79     /// full register, but was a subreg operation.
80     bool isPartial() const { return partial_; }
81
82     /// isCrossClass - Return true if DstReg is virtual and NewRC is a smaller register class than DstReg's.
83     bool isCrossClass() const { return crossClass_; }
84
85     /// isFlipped - Return true when getSrcReg is the register being defined by
86     /// the original copy instruction.
87     bool isFlipped() const { return flipped_; }
88
89     /// getDstReg - Return the register (virtual or physical) that will remain
90     /// after coalescing.
91     unsigned getDstReg() const { return dstReg_; }
92
93     /// getSrcReg - Return the virtual register that will be coalesced away.
94     unsigned getSrcReg() const { return srcReg_; }
95
96     /// getSubIdx - Return the subregister index in DstReg that SrcReg will be
97     /// coalesced into, or 0.
98     unsigned getSubIdx() const { return subIdx_; }
99
100     /// getNewRC - Return the register class of the coalesced register.
101     const TargetRegisterClass *getNewRC() const { return newRC_; }
102   };
103 } // End llvm namespace
104
105 #endif