LiveIntervalCalc.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //===- LiveIntervalCalc.h - Calculate live intervals -----------*- 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. // The LiveIntervalCalc class is an extension of LiveRangeCalc targeted to the
  10. // computation and modification of the LiveInterval variants of LiveRanges.
  11. // LiveIntervals are meant to track liveness of registers and stack slots and
  12. // LiveIntervalCalc adds to LiveRangeCalc all the machinery requied to
  13. // construct the liveness of virtual registers tracked by a LiveInterval.
  14. //
  15. //===----------------------------------------------------------------------===//
  16. #ifndef LLVM_CODEGEN_LIVEINTERVALCALC_H
  17. #define LLVM_CODEGEN_LIVEINTERVALCALC_H
  18. #include "llvm/CodeGen/LiveRangeCalc.h"
  19. namespace llvm {
  20. template <class NodeT> class DomTreeNodeBase;
  21. using MachineDomTreeNode = DomTreeNodeBase<MachineBasicBlock>;
  22. class LiveIntervalCalc : public LiveRangeCalc {
  23. /// Extend the live range of @p LR to reach all uses of Reg.
  24. ///
  25. /// If @p LR is a main range, or if @p LI is null, then all uses must be
  26. /// jointly dominated by the definitions from @p LR. If @p LR is a subrange
  27. /// of the live interval @p LI, corresponding to lane mask @p LaneMask,
  28. /// all uses must be jointly dominated by the definitions from @p LR
  29. /// together with definitions of other lanes where @p LR becomes undefined
  30. /// (via <def,read-undef> operands).
  31. /// If @p LR is a main range, the @p LaneMask should be set to ~0, i.e.
  32. /// LaneBitmask::getAll().
  33. void extendToUses(LiveRange &LR, Register Reg, LaneBitmask LaneMask,
  34. LiveInterval *LI = nullptr);
  35. public:
  36. LiveIntervalCalc() = default;
  37. /// createDeadDefs - Create a dead def in LI for every def operand of Reg.
  38. /// Each instruction defining Reg gets a new VNInfo with a corresponding
  39. /// minimal live range.
  40. void createDeadDefs(LiveRange &LR, Register Reg);
  41. /// Extend the live range of @p LR to reach all uses of Reg.
  42. ///
  43. /// All uses must be jointly dominated by existing liveness. PHI-defs are
  44. /// inserted as needed to preserve SSA form.
  45. void extendToUses(LiveRange &LR, MCRegister PhysReg) {
  46. extendToUses(LR, PhysReg, LaneBitmask::getAll());
  47. }
  48. /// Calculates liveness for the register specified in live interval @p LI.
  49. /// Creates subregister live ranges as needed if subreg liveness tracking is
  50. /// enabled.
  51. void calculate(LiveInterval &LI, bool TrackSubRegs);
  52. /// For live interval \p LI with correct SubRanges construct matching
  53. /// information for the main live range. Expects the main live range to not
  54. /// have any segments or value numbers.
  55. void constructMainRangeFromSubranges(LiveInterval &LI);
  56. };
  57. } // end namespace llvm
  58. #endif // LLVM_CODEGEN_LIVEINTERVALCALC_H