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 TargetRegisterInfo &TRI; 30 31 /// DstReg - The register that will be left after coalescing. It can be a 32 /// virtual or physical register. 33 unsigned DstReg; 34 35 /// SrcReg - the virtual register that will be coalesced into dstReg. 36 unsigned SrcReg; 37 38 /// DstIdx - The sub-register index of the old DstReg in the new coalesced 39 /// register. 40 unsigned DstIdx; 41 42 /// SrcIdx - The sub-register index of the old SrcReg in the new coalesced 43 /// register. 44 unsigned SrcIdx; 45 46 /// Partial - True when the original copy was a partial subregister copy. 47 bool Partial; 48 49 /// CrossClass - True when both regs are virtual, and newRC is constrained. 50 bool CrossClass; 51 52 /// Flipped - True when DstReg and SrcReg are reversed from the original 53 /// copy instruction. 54 bool Flipped; 55 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; 60 61 public: 62 CoalescerPair(const TargetRegisterInfo &tri) 63 : TRI(tri), DstReg(0), SrcReg(0), DstIdx(0), SrcIdx(0), 64 Partial(false), CrossClass(false), Flipped(false), NewRC(nullptr) {} 65 66 /// Create a CoalescerPair representing a virtreg-to-physreg copy. 67 /// No need to call setRegisters(). 68 CoalescerPair(unsigned VirtReg, unsigned PhysReg, 69 const TargetRegisterInfo &tri) 70 : TRI(tri), DstReg(PhysReg), SrcReg(VirtReg), DstIdx(0), SrcIdx(0), 71 Partial(false), CrossClass(false), Flipped(false), NewRC(nullptr) {} 72 73 /// setRegisters - set registers to match the copy instruction MI. Return 74 /// false if MI is not a coalescable copy instruction. 75 bool setRegisters(const MachineInstr*); 76 77 /// flip - Swap SrcReg and DstReg. Return false if swapping is impossible 78 /// because DstReg is a physical register, or SubIdx is set. 79 bool flip(); 80 81 /// isCoalescable - Return true if MI is a copy instruction that will become 82 /// an identity copy after coalescing. 83 bool isCoalescable(const MachineInstr*) const; 84 85 /// isPhys - Return true if DstReg is a physical register. 86 bool isPhys() const { return !NewRC; } 87 88 /// isPartial - Return true if the original copy instruction did not copy 89 /// the full register, but was a subreg operation. 90 bool isPartial() const { return Partial; } 91 92 /// isCrossClass - Return true if DstReg is virtual and NewRC is a smaller 93 /// register class than DstReg's. 94 bool isCrossClass() const { return CrossClass; } 95 96 /// isFlipped - Return true when getSrcReg is the register being defined by 97 /// the original copy instruction. 98 bool isFlipped() const { return Flipped; } 99 100 /// getDstReg - Return the register (virtual or physical) that will remain 101 /// after coalescing. 102 unsigned getDstReg() const { return DstReg; } 103 104 /// getSrcReg - Return the virtual register that will be coalesced away. 105 unsigned getSrcReg() const { return SrcReg; } 106 107 /// getDstIdx - Return the subregister index that DstReg will be coalesced 108 /// into, or 0. 109 unsigned getDstIdx() const { return DstIdx; } 110 111 /// getSrcIdx - Return the subregister index that SrcReg will be coalesced 112 /// into, or 0. 113 unsigned getSrcIdx() const { return SrcIdx; } 114 115 /// getNewRC - Return the register class of the coalesced register. 116 const TargetRegisterClass *getNewRC() const { return NewRC; } 117 }; 118 } // End llvm namespace 119 120 #endif 121