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 copy
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 the
79 /// 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 register class than DstReg's.
83 bool isCrossClass() const { return crossClass_; }
85 /// isFlipped - Return true when getSrcReg is the register being defined by
86 /// the original copy instruction.
87 bool isFlipped() const { return flipped_; }
89 /// getDstReg - Return the register (virtual or physical) that will remain
91 unsigned getDstReg() const { return dstReg_; }
93 /// getSrcReg - Return the virtual register that will be coalesced away.
94 unsigned getSrcReg() const { return srcReg_; }
96 /// getSubIdx - Return the subregister index in DstReg that SrcReg will be
97 /// coalesced into, or 0.
98 unsigned getSubIdx() const { return subIdx_; }
100 /// getNewRC - Return the register class of the coalesced register.
101 const TargetRegisterClass *getNewRC() const { return newRC_; }
103 } // End llvm namespace