Index: include/llvm/CodeGen/MachineScheduler.h =================================================================== --- include/llvm/CodeGen/MachineScheduler.h +++ include/llvm/CodeGen/MachineScheduler.h @@ -361,7 +361,6 @@ /// Register pressure in this region computed by initRegPressure. bool ShouldTrackPressure; - IntervalPressure RegPressure; RegPressureTracker RPTracker; /// List of pressure sets that exceed the target's pressure limit before @@ -370,11 +369,9 @@ std::vector RegionCriticalPSets; /// The top of the unscheduled zone. - IntervalPressure TopPressure; RegPressureTracker TopRPTracker; /// The bottom of the unscheduled zone. - IntervalPressure BotPressure; RegPressureTracker BotRPTracker; public: @@ -382,8 +379,8 @@ std::unique_ptr S) : ScheduleDAGMI(C, std::move(S), /*IsPostRA=*/false), RegClassInfo(C->RegClassInfo), DFSResult(nullptr), - ShouldTrackPressure(false), RPTracker(RegPressure), - TopRPTracker(TopPressure), BotRPTracker(BotPressure) {} + ShouldTrackPressure(false), RPTracker(true), TopRPTracker(true), + BotRPTracker(true) {} ~ScheduleDAGMILive() override; @@ -394,11 +391,9 @@ bool isTrackingPressure() const { return ShouldTrackPressure; } /// Get current register pressure for the top scheduled instructions. - const IntervalPressure &getTopPressure() const { return TopPressure; } const RegPressureTracker &getTopRPTracker() const { return TopRPTracker; } /// Get current register pressure for the bottom scheduled instructions. - const IntervalPressure &getBotPressure() const { return BotPressure; } const RegPressureTracker &getBotRPTracker() const { return BotRPTracker; } /// Get register pressure for the entire scheduling region before scheduling. Index: include/llvm/CodeGen/RegisterPressure.h =================================================================== --- include/llvm/CodeGen/RegisterPressure.h +++ include/llvm/CodeGen/RegisterPressure.h @@ -26,46 +26,6 @@ class RegisterClassInfo; class MachineInstr; -/// Base class for register pressure results. -struct RegisterPressure { -}; - -/// RegisterPressure computed within a region of instructions delimited by -/// TopIdx and BottomIdx. During pressure computation, the maximum pressure per -/// register pressure set is increased. Once pressure within a region is fully -/// computed, the live-in and live-out sets are recorded. -/// -/// This is preferable to RegionPressure when LiveIntervals are available, -/// because delimiting regions by SlotIndex is more robust and convenient than -/// holding block iterators. The block contents can change without invalidating -/// the pressure result. -struct IntervalPressure : RegisterPressure { - /// Record the boundary of the region being tracked. - SlotIndex TopIdx; - SlotIndex BottomIdx; - - void reset(); - - void openTop(SlotIndex NextTop); - - void openBottom(SlotIndex PrevBottom); -}; - -/// RegisterPressure computed within a region of instructions delimited by -/// TopPos and BottomPos. This is a less precise version of IntervalPressure for -/// use when LiveIntervals are unavailable. -struct RegionPressure : RegisterPressure { - /// Record the boundary of the region being tracked. - MachineBasicBlock::const_iterator TopPos; - MachineBasicBlock::const_iterator BottomPos; - - void reset(); - - void openTop(MachineBasicBlock::const_iterator PrevTop); - - void openBottom(MachineBasicBlock::const_iterator PrevBottom); -}; - /// Capture a change in pressure for a single pressure set. UnitInc may be /// expressed in terms of upward or downward pressure depending on the client /// and will be dynamically adjusted for current liveness. @@ -236,11 +196,20 @@ /// We currently only allow pressure tracking within a block. const MachineBasicBlock *MBB; - /// Track the max pressure within the region traversed so far. - RegisterPressure &P; - - /// Run in two modes dependending on whether constructed with IntervalPressure - /// or RegisterPressure. If requireIntervals is false, LIS are ignored. + /// Boundary of the region being tracked. + union Boundary { + struct { + SlotIndex TopIdx; + SlotIndex BottomIdx; + } Indizes; + struct { + MachineBasicBlock::const_iterator TopPos; + MachineBasicBlock::const_iterator BottomPos; + } Iters; + Boundary() {} + } Boundary; + + /// Run in two modes dependending on whether live intervals are available. bool RequireIntervals; /// True if UntiedDefs will be populated. @@ -269,13 +238,9 @@ std::vector LiveThruPressure; public: - RegPressureTracker(IntervalPressure &rp) : - MF(nullptr), TRI(nullptr), RCI(nullptr), LIS(nullptr), MBB(nullptr), P(rp), - RequireIntervals(true), TrackUntiedDefs(false) {} - - RegPressureTracker(RegionPressure &rp) : - MF(nullptr), TRI(nullptr), RCI(nullptr), LIS(nullptr), MBB(nullptr), P(rp), - RequireIntervals(false), TrackUntiedDefs(false) {} + RegPressureTracker(bool RequireIntervals) : + MF(nullptr), TRI(nullptr), RCI(nullptr), LIS(nullptr), MBB(nullptr), + RequireIntervals(RequireIntervals), TrackUntiedDefs(false) {} void reset(); @@ -332,12 +297,6 @@ ArrayRef getMaxSetPressure() const { return MaxSetPressure; } /// @} - /// Get the resulting register pressure over the traversed region. - /// This result is complete if either advance() or recede() has returned true, - /// or if closeRegion() was explicitly invoked. - RegisterPressure &getPressure() { return P; } - const RegisterPressure &getPressure() const { return P; } - /// Get the register set pressure at the current position, which may be less /// than the pressure across the traversed region. std::vector &getRegSetPressureAtPos() { return CurrSetPressure; } Index: lib/CodeGen/RegisterPressure.cpp =================================================================== --- lib/CodeGen/RegisterPressure.cpp +++ lib/CodeGen/RegisterPressure.cpp @@ -103,45 +103,6 @@ decreaseSetPressure(CurrSetPressure, MRI->getPressureSets(RegUnits[I])); } -/// Clear the result so it can be used for another round of pressure tracking. -void IntervalPressure::reset() { - TopIdx = BottomIdx = SlotIndex(); -} - -/// Clear the result so it can be used for another round of pressure tracking. -void RegionPressure::reset() { - TopPos = BottomPos = MachineBasicBlock::const_iterator(); -} - -/// If the current top is not less than or equal to the next index, open it. -/// We happen to need the SlotIndex for the next top for pressure update. -void IntervalPressure::openTop(SlotIndex NextTop) { - if (TopIdx <= NextTop) - return; - TopIdx = SlotIndex(); -} - -/// If the current top is the previous instruction (before receding), open it. -void RegionPressure::openTop(MachineBasicBlock::const_iterator PrevTop) { - if (TopPos != PrevTop) - return; - TopPos = MachineBasicBlock::const_iterator(); -} - -/// If the current bottom is not greater than the previous index, open it. -void IntervalPressure::openBottom(SlotIndex PrevBottom) { - if (BottomIdx > PrevBottom) - return; - BottomIdx = SlotIndex(); -} - -/// If the current bottom is the previous instr (before advancing), open it. -void RegionPressure::openBottom(MachineBasicBlock::const_iterator PrevBottom) { - if (BottomPos != PrevBottom) - return; - BottomPos = MachineBasicBlock::const_iterator(); -} - const LiveRange *RegPressureTracker::getLiveRange(unsigned Reg) const { if (TargetRegisterInfo::isVirtualRegister(Reg)) return &LIS->getInterval(Reg); @@ -156,10 +117,13 @@ LiveThruPressure.clear(); MaxSetPressure.clear(); - if (RequireIntervals) - static_cast(P).reset(); - else - static_cast(P).reset(); + if (RequireIntervals) { + Boundary.Indizes.TopIdx = SlotIndex(); + Boundary.Indizes.BottomIdx = SlotIndex(); + } else { + Boundary.Iters.TopPos = MachineBasicBlock::const_iterator(); + Boundary.Iters.BottomPos = MachineBasicBlock::const_iterator(); + } MaxSetPressure.clear(); LiveInRegs.clear(); LiveOutRegs.clear(); @@ -206,18 +170,14 @@ /// Does this pressure result have a valid top position and live ins. bool RegPressureTracker::isTopClosed() const { - if (RequireIntervals) - return static_cast(P).TopIdx.isValid(); - return (static_cast(P).TopPos == - MachineBasicBlock::const_iterator()); + return RequireIntervals ? Boundary.Indizes.TopIdx.isValid() + : Boundary.Iters.TopPos == MachineBasicBlock::const_iterator(); } /// Does this pressure result have a valid bottom position and live outs. bool RegPressureTracker::isBottomClosed() const { - if (RequireIntervals) - return static_cast(P).BottomIdx.isValid(); - return (static_cast(P).BottomPos == - MachineBasicBlock::const_iterator()); + return RequireIntervals ? Boundary.Indizes.BottomIdx.isValid() + : Boundary.Iters.BottomPos == MachineBasicBlock::const_iterator(); } @@ -233,9 +193,9 @@ /// Set the boundary for the top of the region and summarize live ins. void RegPressureTracker::closeTop() { if (RequireIntervals) - static_cast(P).TopIdx = getCurrSlot(); + Boundary.Indizes.TopIdx = getCurrSlot(); else - static_cast(P).TopPos = CurrPos; + Boundary.Iters.TopPos = CurrPos; assert(LiveInRegs.empty() && "inconsistent max pressure result"); LiveInRegs.reserve(LiveRegs.PhysRegs.size() + LiveRegs.VirtRegs.size()); @@ -246,9 +206,9 @@ /// Set the boundary for the bottom of the region and summarize live outs. void RegPressureTracker::closeBottom() { if (RequireIntervals) - static_cast(P).BottomIdx = getCurrSlot(); + Boundary.Indizes.BottomIdx = getCurrSlot(); else - static_cast(P).BottomPos = CurrPos; + Boundary.Iters.BottomPos = CurrPos; assert(LiveOutRegs.empty() && "inconsistent max pressure result"); LiveOutRegs.reserve(LiveRegs.PhysRegs.size() + LiveRegs.VirtRegs.size()); @@ -454,8 +414,12 @@ closeBottom(); // Open the top of the region using block iterators. - if (!RequireIntervals && isTopClosed()) - static_cast(P).openTop(CurrPos); + if (!RequireIntervals && isTopClosed()) { + // If the current top is the previous instruction (before receding), + // open it. + if (Boundary.Iters.TopPos == CurrPos) + Boundary.Iters.TopPos = MachineBasicBlock::const_iterator(); + } // Find the previous instruction. do @@ -472,8 +436,13 @@ // Open the top of the region using slot indexes. if (isTopClosed()) { - if (RequireIntervals) - static_cast(P).openTop(SlotIdx); + if (RequireIntervals) { + // If the current top is not less than or equal to the next index, open + // it. We happen to need the SlotIndex for the next top for pressure + // update. + if (Boundary.Indizes.TopIdx > SlotIdx) + Boundary.Indizes.TopIdx = SlotIndex(); + } LiveInRegs.clear(); } @@ -560,10 +529,16 @@ // Open the bottom of the region using slot indexes. if (isBottomClosed()) { - if (RequireIntervals) - static_cast(P).openBottom(SlotIdx); - else - static_cast(P).openBottom(CurrPos); + if (RequireIntervals) { + // If the current bottom is not greater than the previous index, open it. + if (Boundary.Indizes.BottomIdx <= SlotIdx) + Boundary.Indizes.BottomIdx = SlotIndex(); + } else { + // If the current bottom is the previous instr (before advancing), open + // it. + if (Boundary.Iters.BottomPos == CurrPos) + Boundary.Iters.BottomPos = MachineBasicBlock::const_iterator(); + } LiveInRegs.clear(); }