RegisterCoalescer.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. #ifndef LLVM_LIB_CODEGEN_REGISTERCOALESCER_H
  15. #define LLVM_LIB_CODEGEN_REGISTERCOALESCER_H
  16. namespace llvm {
  17. class MachineInstr;
  18. class TargetRegisterInfo;
  19. class TargetRegisterClass;
  20. class TargetInstrInfo;
  21. /// A helper class for register coalescers. When deciding if
  22. /// two registers can be coalesced, CoalescerPair can determine if a copy
  23. /// instruction would become an identity copy after coalescing.
  24. class CoalescerPair {
  25. const TargetRegisterInfo &TRI;
  26. /// The register that will be left after coalescing. It can be a
  27. /// virtual or physical register.
  28. unsigned DstReg;
  29. /// The virtual register that will be coalesced into dstReg.
  30. unsigned SrcReg;
  31. /// The sub-register index of the old DstReg in the new coalesced register.
  32. unsigned DstIdx;
  33. /// The sub-register index of the old SrcReg in the new coalesced register.
  34. unsigned SrcIdx;
  35. /// True when the original copy was a partial subregister copy.
  36. bool Partial;
  37. /// True when both regs are virtual and newRC is constrained.
  38. bool CrossClass;
  39. /// True when DstReg and SrcReg are reversed from the original
  40. /// copy instruction.
  41. bool Flipped;
  42. /// The register class of the coalesced register, or NULL if DstReg
  43. /// is a physreg. This register class may be a super-register of both
  44. /// SrcReg and DstReg.
  45. const TargetRegisterClass *NewRC;
  46. public:
  47. CoalescerPair(const TargetRegisterInfo &tri)
  48. : TRI(tri), DstReg(0), SrcReg(0), DstIdx(0), SrcIdx(0),
  49. Partial(false), CrossClass(false), Flipped(false), NewRC(nullptr) {}
  50. /// Create a CoalescerPair representing a virtreg-to-physreg copy.
  51. /// No need to call setRegisters().
  52. CoalescerPair(unsigned VirtReg, unsigned PhysReg,
  53. const TargetRegisterInfo &tri)
  54. : TRI(tri), DstReg(PhysReg), SrcReg(VirtReg), DstIdx(0), SrcIdx(0),
  55. Partial(false), CrossClass(false), Flipped(false), NewRC(nullptr) {}
  56. /// Set registers to match the copy instruction MI. Return
  57. /// false if MI is not a coalescable copy instruction.
  58. bool setRegisters(const MachineInstr*);
  59. /// Swap SrcReg and DstReg. Return false if swapping is impossible
  60. /// because DstReg is a physical register, or SubIdx is set.
  61. bool flip();
  62. /// Return true if MI is a copy instruction that will become
  63. /// an identity copy after coalescing.
  64. bool isCoalescable(const MachineInstr*) const;
  65. /// Return true if DstReg is a physical register.
  66. bool isPhys() const { return !NewRC; }
  67. /// Return true if the original copy instruction did not copy
  68. /// the full register, but was a subreg operation.
  69. bool isPartial() const { return Partial; }
  70. /// Return true if DstReg is virtual and NewRC is a smaller
  71. /// register class than DstReg's.
  72. bool isCrossClass() const { return CrossClass; }
  73. /// Return true when getSrcReg is the register being defined by
  74. /// the original copy instruction.
  75. bool isFlipped() const { return Flipped; }
  76. /// Return the register (virtual or physical) that will remain
  77. /// after coalescing.
  78. unsigned getDstReg() const { return DstReg; }
  79. /// Return the virtual register that will be coalesced away.
  80. unsigned getSrcReg() const { return SrcReg; }
  81. /// Return the subregister index that DstReg will be coalesced into, or 0.
  82. unsigned getDstIdx() const { return DstIdx; }
  83. /// Return the subregister index that SrcReg will be coalesced into, or 0.
  84. unsigned getSrcIdx() const { return SrcIdx; }
  85. /// Return the register class of the coalesced register.
  86. const TargetRegisterClass *getNewRC() const { return NewRC; }
  87. };
  88. } // End llvm namespace
  89. #endif