@@ -378,10 +378,10 @@ static bool areCompatibleVTYPEs(uint64_t CurVType, uint64_t NewVType,
378378
379379// / Return the fields and properties demanded by the provided instruction.
380380DemandedFields getDemanded (const MachineInstr &MI, const RISCVSubtarget *ST) {
381- // This function works in RISCVCoalesceVSETVLI too. We can still use the value
382- // of a SEW, VL, or Policy operand even though it might not be the exact value
383- // in the VL or VTYPE, since we only care about what the instruction
384- // originally demanded.
381+ // This function works in coalesceVSETVLI too. We can still use the value of a
382+ // SEW, VL, or Policy operand even though it might not be the exact value in
383+ // the VL or VTYPE, since we only care about what the instruction originally
384+ // demanded.
385385
386386 // Most instructions don't use any of these subfeilds.
387387 DemandedFields Res;
@@ -900,36 +900,7 @@ class RISCVInsertVSETVLI : public MachineFunctionPass {
900900 void emitVSETVLIs (MachineBasicBlock &MBB);
901901 void doPRE (MachineBasicBlock &MBB);
902902 void insertReadVL (MachineBasicBlock &MBB);
903- };
904-
905- class RISCVCoalesceVSETVLI : public MachineFunctionPass {
906- public:
907- static char ID;
908- const RISCVSubtarget *ST;
909- const TargetInstrInfo *TII;
910- MachineRegisterInfo *MRI;
911- LiveIntervals *LIS;
912-
913- RISCVCoalesceVSETVLI () : MachineFunctionPass(ID) {}
914- bool runOnMachineFunction (MachineFunction &MF) override ;
915-
916- void getAnalysisUsage (AnalysisUsage &AU) const override {
917- AU.setPreservesCFG ();
918-
919- AU.addRequired <LiveIntervals>();
920- AU.addPreserved <LiveIntervals>();
921- AU.addRequired <SlotIndexes>();
922- AU.addPreserved <SlotIndexes>();
923- AU.addPreserved <LiveDebugVariables>();
924- AU.addPreserved <LiveStacks>();
925-
926- MachineFunctionPass::getAnalysisUsage (AU);
927- }
928-
929- StringRef getPassName () const override { return RISCV_COALESCE_VSETVLI_NAME; }
930-
931- private:
932- bool coalesceVSETVLIs (MachineBasicBlock &MBB);
903+ void coalesceVSETVLIs (MachineBasicBlock &MBB) const ;
933904};
934905
935906} // end anonymous namespace
@@ -940,11 +911,6 @@ char &llvm::RISCVInsertVSETVLIID = RISCVInsertVSETVLI::ID;
940911INITIALIZE_PASS (RISCVInsertVSETVLI, DEBUG_TYPE, RISCV_INSERT_VSETVLI_NAME,
941912 false , false )
942913
943- char RISCVCoalesceVSETVLI::ID = 0;
944-
945- INITIALIZE_PASS (RISCVCoalesceVSETVLI, " riscv-coalesce-vsetvli" ,
946- RISCV_COALESCE_VSETVLI_NAME, false , false )
947-
948914// Return a VSETVLIInfo representing the changes made by this VSETVLI or
949915// VSETIVLI instruction.
950916static VSETVLIInfo getInfoForVSETVLI(const MachineInstr &MI,
@@ -1653,7 +1619,7 @@ static bool canMutatePriorConfig(const MachineInstr &PrevMI,
16531619 return areCompatibleVTYPEs (PriorVType, VType, Used);
16541620}
16551621
1656- bool RISCVCoalesceVSETVLI ::coalesceVSETVLIs (MachineBasicBlock &MBB) {
1622+ void RISCVInsertVSETVLI ::coalesceVSETVLIs (MachineBasicBlock &MBB) const {
16571623 MachineInstr *NextMI = nullptr ;
16581624 // We can have arbitrary code in successors, so VL and VTYPE
16591625 // must be considered demanded.
@@ -1745,8 +1711,6 @@ bool RISCVCoalesceVSETVLI::coalesceVSETVLIs(MachineBasicBlock &MBB) {
17451711 LIS->RemoveMachineInstrFromMaps (*MI);
17461712 MI->eraseFromParent ();
17471713 }
1748-
1749- return !ToDelete.empty ();
17501714}
17511715
17521716void RISCVInsertVSETVLI::insertReadVL (MachineBasicBlock &MBB) {
@@ -1836,6 +1800,15 @@ bool RISCVInsertVSETVLI::runOnMachineFunction(MachineFunction &MF) {
18361800 for (MachineBasicBlock &MBB : MF)
18371801 insertReadVL (MBB);
18381802
1803+ // Now that all vsetvlis are explicit, go through and do block local
1804+ // DSE and peephole based demanded fields based transforms. Note that
1805+ // this *must* be done outside the main dataflow so long as we allow
1806+ // any cross block analysis within the dataflow. We can't have both
1807+ // demanded fields based mutation and non-local analysis in the
1808+ // dataflow at the same time without introducing inconsistencies.
1809+ for (MachineBasicBlock &MBB : MF)
1810+ coalesceVSETVLIs (MBB);
1811+
18391812 BlockInfo.clear ();
18401813 return HaveVectorOp;
18411814}
@@ -1844,29 +1817,3 @@ bool RISCVInsertVSETVLI::runOnMachineFunction(MachineFunction &MF) {
18441817FunctionPass *llvm::createRISCVInsertVSETVLIPass () {
18451818 return new RISCVInsertVSETVLI ();
18461819}
1847-
1848- // Now that all vsetvlis are explicit, go through and do block local
1849- // DSE and peephole based demanded fields based transforms. Note that
1850- // this *must* be done outside the main dataflow so long as we allow
1851- // any cross block analysis within the dataflow. We can't have both
1852- // demanded fields based mutation and non-local analysis in the
1853- // dataflow at the same time without introducing inconsistencies.
1854- bool RISCVCoalesceVSETVLI::runOnMachineFunction (MachineFunction &MF) {
1855- // Skip if the vector extension is not enabled.
1856- ST = &MF.getSubtarget <RISCVSubtarget>();
1857- if (!ST->hasVInstructions ())
1858- return false ;
1859- TII = ST->getInstrInfo ();
1860- MRI = &MF.getRegInfo ();
1861- LIS = &getAnalysis<LiveIntervals>();
1862-
1863- bool Changed = false ;
1864- for (MachineBasicBlock &MBB : MF)
1865- Changed |= coalesceVSETVLIs (MBB);
1866-
1867- return Changed;
1868- }
1869-
1870- FunctionPass *llvm::createRISCVCoalesceVSETVLIPass () {
1871- return new RISCVCoalesceVSETVLI ();
1872- }
0 commit comments