Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

148 lines
5.6 KiB

  1. //===-- LiveRegMatrix.h - Track register interference ---------*- 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. // The LiveRegMatrix analysis pass keeps track of virtual register interference
  11. // along two dimensions: Slot indexes and register units. The matrix is used by
  12. // register allocators to ensure that no interfering virtual registers get
  13. // assigned to overlapping physical registers.
  14. //
  15. // Register units are defined in MCRegisterInfo.h, they represent the smallest
  16. // unit of interference when dealing with overlapping physical registers. The
  17. // LiveRegMatrix is represented as a LiveIntervalUnion per register unit. When
  18. // a virtual register is assigned to a physical register, the live range for
  19. // the virtual register is inserted into the LiveIntervalUnion for each regunit
  20. // in the physreg.
  21. //
  22. //===----------------------------------------------------------------------===//
  23. #ifndef LLVM_CODEGEN_LIVEREGMATRIX_H
  24. #define LLVM_CODEGEN_LIVEREGMATRIX_H
  25. #include "llvm/ADT/BitVector.h"
  26. #include "llvm/ADT/OwningPtr.h"
  27. #include "llvm/CodeGen/LiveIntervalUnion.h"
  28. #include "llvm/CodeGen/MachineFunctionPass.h"
  29. namespace llvm {
  30. class LiveInterval;
  31. class LiveIntervalAnalysis;
  32. class MachineRegisterInfo;
  33. class TargetRegisterInfo;
  34. class VirtRegMap;
  35. class LiveRegMatrix : public MachineFunctionPass {
  36. const TargetRegisterInfo *TRI;
  37. MachineRegisterInfo *MRI;
  38. LiveIntervals *LIS;
  39. VirtRegMap *VRM;
  40. // UserTag changes whenever virtual registers have been modified.
  41. unsigned UserTag;
  42. // The matrix is represented as a LiveIntervalUnion per register unit.
  43. LiveIntervalUnion::Allocator LIUAlloc;
  44. LiveIntervalUnion::Array Matrix;
  45. // Cached queries per register unit.
  46. OwningArrayPtr<LiveIntervalUnion::Query> Queries;
  47. // Cached register mask interference info.
  48. unsigned RegMaskTag;
  49. unsigned RegMaskVirtReg;
  50. BitVector RegMaskUsable;
  51. // MachineFunctionPass boilerplate.
  52. virtual void getAnalysisUsage(AnalysisUsage&) const;
  53. virtual bool runOnMachineFunction(MachineFunction&);
  54. virtual void releaseMemory();
  55. public:
  56. static char ID;
  57. LiveRegMatrix();
  58. //===--------------------------------------------------------------------===//
  59. // High-level interface.
  60. //===--------------------------------------------------------------------===//
  61. //
  62. // Check for interference before assigning virtual registers to physical
  63. // registers.
  64. //
  65. /// Invalidate cached interference queries after modifying virtual register
  66. /// live ranges. Interference checks may return stale information unless
  67. /// caches are invalidated.
  68. void invalidateVirtRegs() { ++UserTag; }
  69. enum InterferenceKind {
  70. /// No interference, go ahead and assign.
  71. IK_Free = 0,
  72. /// Virtual register interference. There are interfering virtual registers
  73. /// assigned to PhysReg or its aliases. This interference could be resolved
  74. /// by unassigning those other virtual registers.
  75. IK_VirtReg,
  76. /// Register unit interference. A fixed live range is in the way, typically
  77. /// argument registers for a call. This can't be resolved by unassigning
  78. /// other virtual registers.
  79. IK_RegUnit,
  80. /// RegMask interference. The live range is crossing an instruction with a
  81. /// regmask operand that doesn't preserve PhysReg. This typically means
  82. /// VirtReg is live across a call, and PhysReg isn't call-preserved.
  83. IK_RegMask
  84. };
  85. /// Check for interference before assigning VirtReg to PhysReg.
  86. /// If this function returns IK_Free, it is legal to assign(VirtReg, PhysReg).
  87. /// When there is more than one kind of interference, the InterferenceKind
  88. /// with the highest enum value is returned.
  89. InterferenceKind checkInterference(LiveInterval &VirtReg, unsigned PhysReg);
  90. /// Assign VirtReg to PhysReg.
  91. /// This will mark VirtReg's live range as occupied in the LiveRegMatrix and
  92. /// update VirtRegMap. The live range is expected to be available in PhysReg.
  93. void assign(LiveInterval &VirtReg, unsigned PhysReg);
  94. /// Unassign VirtReg from its PhysReg.
  95. /// Assuming that VirtReg was previously assigned to a PhysReg, this undoes
  96. /// the assignment and updates VirtRegMap accordingly.
  97. void unassign(LiveInterval &VirtReg);
  98. //===--------------------------------------------------------------------===//
  99. // Low-level interface.
  100. //===--------------------------------------------------------------------===//
  101. //
  102. // Provide access to the underlying LiveIntervalUnions.
  103. //
  104. /// Check for regmask interference only.
  105. /// Return true if VirtReg crosses a regmask operand that clobbers PhysReg.
  106. /// If PhysReg is null, check if VirtReg crosses any regmask operands.
  107. bool checkRegMaskInterference(LiveInterval &VirtReg, unsigned PhysReg = 0);
  108. /// Check for regunit interference only.
  109. /// Return true if VirtReg overlaps a fixed assignment of one of PhysRegs's
  110. /// register units.
  111. bool checkRegUnitInterference(LiveInterval &VirtReg, unsigned PhysReg);
  112. /// Query a line of the assigned virtual register matrix directly.
  113. /// Use MCRegUnitIterator to enumerate all regunits in the desired PhysReg.
  114. /// This returns a reference to an internal Query data structure that is only
  115. /// valid until the next query() call.
  116. LiveIntervalUnion::Query &query(LiveInterval &VirtReg, unsigned RegUnit);
  117. /// Directly access the live interval unions per regunit.
  118. /// This returns an array indexed by the regunit number.
  119. LiveIntervalUnion *getLiveUnions() { return &Matrix[0]; }
  120. };
  121. } // end namespace llvm
  122. #endif // LLVM_CODEGEN_LIVEREGMATRIX_H