LLVM API Documentation
00001 //===-- RegisterCoalescer.h - Register Coalescing Interface -----*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file contains the abstract interface for register coalescers, 00011 // allowing them to interact with and query register allocators. 00012 // 00013 //===----------------------------------------------------------------------===// 00014 00015 #ifndef LLVM_LIB_CODEGEN_REGISTERCOALESCER_H 00016 #define LLVM_LIB_CODEGEN_REGISTERCOALESCER_H 00017 00018 namespace llvm { 00019 00020 class MachineInstr; 00021 class TargetRegisterInfo; 00022 class TargetRegisterClass; 00023 class TargetInstrInfo; 00024 00025 /// CoalescerPair - A helper class for register coalescers. When deciding if 00026 /// two registers can be coalesced, CoalescerPair can determine if a copy 00027 /// instruction would become an identity copy after coalescing. 00028 class CoalescerPair { 00029 const TargetRegisterInfo &TRI; 00030 00031 /// DstReg - The register that will be left after coalescing. It can be a 00032 /// virtual or physical register. 00033 unsigned DstReg; 00034 00035 /// SrcReg - the virtual register that will be coalesced into dstReg. 00036 unsigned SrcReg; 00037 00038 /// DstIdx - The sub-register index of the old DstReg in the new coalesced 00039 /// register. 00040 unsigned DstIdx; 00041 00042 /// SrcIdx - The sub-register index of the old SrcReg in the new coalesced 00043 /// register. 00044 unsigned SrcIdx; 00045 00046 /// Partial - True when the original copy was a partial subregister copy. 00047 bool Partial; 00048 00049 /// CrossClass - True when both regs are virtual, and newRC is constrained. 00050 bool CrossClass; 00051 00052 /// Flipped - True when DstReg and SrcReg are reversed from the original 00053 /// copy instruction. 00054 bool Flipped; 00055 00056 /// NewRC - The register class of the coalesced register, or NULL if DstReg 00057 /// is a physreg. This register class may be a super-register of both 00058 /// SrcReg and DstReg. 00059 const TargetRegisterClass *NewRC; 00060 00061 public: 00062 CoalescerPair(const TargetRegisterInfo &tri) 00063 : TRI(tri), DstReg(0), SrcReg(0), DstIdx(0), SrcIdx(0), 00064 Partial(false), CrossClass(false), Flipped(false), NewRC(nullptr) {} 00065 00066 /// Create a CoalescerPair representing a virtreg-to-physreg copy. 00067 /// No need to call setRegisters(). 00068 CoalescerPair(unsigned VirtReg, unsigned PhysReg, 00069 const TargetRegisterInfo &tri) 00070 : TRI(tri), DstReg(PhysReg), SrcReg(VirtReg), DstIdx(0), SrcIdx(0), 00071 Partial(false), CrossClass(false), Flipped(false), NewRC(nullptr) {} 00072 00073 /// setRegisters - set registers to match the copy instruction MI. Return 00074 /// false if MI is not a coalescable copy instruction. 00075 bool setRegisters(const MachineInstr*); 00076 00077 /// flip - Swap SrcReg and DstReg. Return false if swapping is impossible 00078 /// because DstReg is a physical register, or SubIdx is set. 00079 bool flip(); 00080 00081 /// isCoalescable - Return true if MI is a copy instruction that will become 00082 /// an identity copy after coalescing. 00083 bool isCoalescable(const MachineInstr*) const; 00084 00085 /// isPhys - Return true if DstReg is a physical register. 00086 bool isPhys() const { return !NewRC; } 00087 00088 /// isPartial - Return true if the original copy instruction did not copy 00089 /// the full register, but was a subreg operation. 00090 bool isPartial() const { return Partial; } 00091 00092 /// isCrossClass - Return true if DstReg is virtual and NewRC is a smaller 00093 /// register class than DstReg's. 00094 bool isCrossClass() const { return CrossClass; } 00095 00096 /// isFlipped - Return true when getSrcReg is the register being defined by 00097 /// the original copy instruction. 00098 bool isFlipped() const { return Flipped; } 00099 00100 /// getDstReg - Return the register (virtual or physical) that will remain 00101 /// after coalescing. 00102 unsigned getDstReg() const { return DstReg; } 00103 00104 /// getSrcReg - Return the virtual register that will be coalesced away. 00105 unsigned getSrcReg() const { return SrcReg; } 00106 00107 /// getDstIdx - Return the subregister index that DstReg will be coalesced 00108 /// into, or 0. 00109 unsigned getDstIdx() const { return DstIdx; } 00110 00111 /// getSrcIdx - Return the subregister index that SrcReg will be coalesced 00112 /// into, or 0. 00113 unsigned getSrcIdx() const { return SrcIdx; } 00114 00115 /// getNewRC - Return the register class of the coalesced register. 00116 const TargetRegisterClass *getNewRC() const { return NewRC; } 00117 }; 00118 } // End llvm namespace 00119 00120 #endif