CriticalAntiDepBreaker.h 4.2 KB

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