CriticalAntiDepBreaker.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. //=- llvm/CodeGen/CriticalAntiDepBreaker.h - Anti-Dep Support -*- 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 implements the CriticalAntiDepBreaker class, which
  11. // implements register anti-dependence breaking along a blocks
  12. // critical path during post-RA scheduler.
  13. //
  14. //===----------------------------------------------------------------------===//
  15. #ifndef LLVM_LIB_CODEGEN_CRITICALANTIDEPBREAKER_H
  16. #define LLVM_LIB_CODEGEN_CRITICALANTIDEPBREAKER_H
  17. #include "AntiDepBreaker.h"
  18. #include "llvm/ADT/BitVector.h"
  19. #include "llvm/CodeGen/MachineBasicBlock.h"
  20. #include "llvm/CodeGen/MachineFrameInfo.h"
  21. #include "llvm/CodeGen/MachineFunction.h"
  22. #include "llvm/CodeGen/MachineRegisterInfo.h"
  23. #include "llvm/CodeGen/RegisterClassInfo.h"
  24. #include "llvm/CodeGen/ScheduleDAG.h"
  25. #include <map>
  26. namespace llvm {
  27. class RegisterClassInfo;
  28. class TargetInstrInfo;
  29. class TargetRegisterInfo;
  30. class LLVM_LIBRARY_VISIBILITY CriticalAntiDepBreaker : public AntiDepBreaker {
  31. MachineFunction& MF;
  32. MachineRegisterInfo &MRI;
  33. const TargetInstrInfo *TII;
  34. const TargetRegisterInfo *TRI;
  35. const RegisterClassInfo &RegClassInfo;
  36. /// The set of allocatable registers.
  37. /// We'll be ignoring anti-dependencies on non-allocatable registers,
  38. /// because they may not be safe to break.
  39. const BitVector AllocatableSet;
  40. /// For live regs that are only used in one register class in a
  41. /// live range, the register class. If the register is not live, the
  42. /// corresponding value is null. If the register is live but used in
  43. /// multiple register classes, the corresponding value is -1 casted to a
  44. /// pointer.
  45. std::vector<const TargetRegisterClass*> Classes;
  46. /// Map registers to all their references within a live range.
  47. std::multimap<unsigned, MachineOperand *> RegRefs;
  48. typedef std::multimap<unsigned, MachineOperand *>::const_iterator
  49. RegRefIter;
  50. /// The index of the most recent kill (proceeding bottom-up),
  51. /// or ~0u if the register is not live.
  52. std::vector<unsigned> KillIndices;
  53. /// The index of the most recent complete def (proceeding
  54. /// bottom up), or ~0u if the register is live.
  55. std::vector<unsigned> DefIndices;
  56. /// A set of registers which are live and cannot be changed to
  57. /// break anti-dependencies.
  58. BitVector KeepRegs;
  59. public:
  60. CriticalAntiDepBreaker(MachineFunction& MFi, const RegisterClassInfo&);
  61. ~CriticalAntiDepBreaker() override;
  62. /// Initialize anti-dep breaking for a new basic block.
  63. void StartBlock(MachineBasicBlock *BB) override;
  64. /// Identifiy anti-dependencies along the critical path
  65. /// of the ScheduleDAG and break them by renaming registers.
  66. unsigned BreakAntiDependencies(const std::vector<SUnit>& SUnits,
  67. MachineBasicBlock::iterator Begin,
  68. MachineBasicBlock::iterator End,
  69. unsigned InsertPosIndex,
  70. DbgValueVector &DbgValues) override;
  71. /// Update liveness information to account for the current
  72. /// instruction, which will not be scheduled.
  73. void Observe(MachineInstr *MI, unsigned Count,
  74. unsigned InsertPosIndex) override;
  75. /// Finish anti-dep breaking for a basic block.
  76. void FinishBlock() override;
  77. private:
  78. void PrescanInstruction(MachineInstr *MI);
  79. void ScanInstruction(MachineInstr *MI, unsigned Count);
  80. bool isNewRegClobberedByRefs(RegRefIter RegRefBegin,
  81. RegRefIter RegRefEnd,
  82. unsigned NewReg);
  83. unsigned findSuitableFreeRegister(RegRefIter RegRefBegin,
  84. RegRefIter RegRefEnd,
  85. unsigned AntiDepReg,
  86. unsigned LastNewReg,
  87. const TargetRegisterClass *RC,
  88. SmallVectorImpl<unsigned> &Forbid);
  89. };
  90. }
  91. #endif