26
26
27
27
#include " RISCV.h"
28
28
#include " RISCVSubtarget.h"
29
- #include " llvm/ADT/SetVector .h"
29
+ #include " llvm/ADT/PostOrderIterator .h"
30
30
#include " llvm/ADT/Statistic.h"
31
31
#include " llvm/CodeGen/LiveDebugVariables.h"
32
32
#include " llvm/CodeGen/LiveIntervals.h"
@@ -896,8 +896,7 @@ class RISCVInsertVSETVLI : public MachineFunctionPass {
896
896
897
897
bool canMutatePriorConfig (const MachineInstr &PrevMI, const MachineInstr &MI,
898
898
const DemandedFields &Used) const ;
899
- void coalesceVSETVLIs (SetVector<MachineBasicBlock *> &Worklist,
900
- MachineBasicBlock &MBB) const ;
899
+ void coalesceVSETVLIs (MachineBasicBlock &MBB) const ;
901
900
902
901
VSETVLIInfo getInfoForVSETVLI (const MachineInstr &MI) const ;
903
902
VSETVLIInfo computeInfoForInstr (const MachineInstr &MI) const ;
@@ -1644,8 +1643,7 @@ bool RISCVInsertVSETVLI::canMutatePriorConfig(
1644
1643
return areCompatibleVTYPEs (PriorVType, VType, Used);
1645
1644
}
1646
1645
1647
- void RISCVInsertVSETVLI::coalesceVSETVLIs (
1648
- SetVector<MachineBasicBlock *> &Worklist, MachineBasicBlock &MBB) const {
1646
+ void RISCVInsertVSETVLI::coalesceVSETVLIs (MachineBasicBlock &MBB) const {
1649
1647
MachineInstr *NextMI = nullptr ;
1650
1648
// We can have arbitrary code in successors, so VL and VTYPE
1651
1649
// must be considered demanded.
@@ -1664,18 +1662,9 @@ void RISCVInsertVSETVLI::coalesceVSETVLIs(
1664
1662
LIS->shrinkToUses (&LIS->getInterval (OldVLReg));
1665
1663
1666
1664
MachineInstr *VLOpDef = MRI->getUniqueVRegDef (OldVLReg);
1667
- if (VLOpDef && MRI->use_nodbg_empty (OldVLReg)) {
1668
- if (TII->isAddImmediate (*VLOpDef, OldVLReg))
1669
- ToDelete.push_back (VLOpDef);
1670
- // If the destination register of a vset* instruction becomes dead because
1671
- // of this, there might be a chance to eliminate it. Put into the worklist
1672
- // so that we can revisit it.
1673
- // Note that since this is a virtual register, the definition instruction
1674
- // is always placed earlier in the program order. Thus, we avoid
1675
- // enqueuing blocks in cycle and therefore guarantee to terminate.
1676
- if (RISCVInstrInfo::isVectorConfigInstr (*VLOpDef))
1677
- Worklist.insert (VLOpDef->getParent ());
1678
- }
1665
+ if (VLOpDef && TII->isAddImmediate (*VLOpDef, OldVLReg) &&
1666
+ MRI->use_nodbg_empty (OldVLReg))
1667
+ ToDelete.push_back (VLOpDef);
1679
1668
};
1680
1669
1681
1670
for (MachineInstr &MI : make_early_inc_range (reverse (MBB))) {
@@ -1852,14 +1841,11 @@ bool RISCVInsertVSETVLI::runOnMachineFunction(MachineFunction &MF) {
1852
1841
// any cross block analysis within the dataflow. We can't have both
1853
1842
// demanded fields based mutation and non-local analysis in the
1854
1843
// dataflow at the same time without introducing inconsistencies.
1855
- using BBPtrIterator = pointer_iterator<MachineFunction::iterator>;
1856
- SetVector<MachineBasicBlock *> Worklist (BBPtrIterator (MF.begin ()),
1857
- BBPtrIterator (MF.end ()));
1858
- while (!Worklist.empty ()) {
1859
- MachineBasicBlock *MBB = Worklist.front ();
1860
- Worklist.erase (Worklist.begin ());
1861
- coalesceVSETVLIs (Worklist, *MBB);
1862
- }
1844
+ // We're visiting blocks from the bottom up because a VSETVLI in the
1845
+ // earlier block might become dead when its uses in later blocks are
1846
+ // optimized away.
1847
+ for (MachineBasicBlock *MBB : post_order (&MF))
1848
+ coalesceVSETVLIs (*MBB);
1863
1849
1864
1850
// Insert PseudoReadVL after VLEFF/VLSEGFF and replace it with the vl output
1865
1851
// of VLEFF/VLSEGFF.
0 commit comments