@@ -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,
@@ -1650,7 +1616,7 @@ static bool canMutatePriorConfig(const MachineInstr &PrevMI,
16501616 return areCompatibleVTYPEs (PriorVType, VType, Used);
16511617}
16521618
1653- bool RISCVCoalesceVSETVLI ::coalesceVSETVLIs (MachineBasicBlock &MBB) {
1619+ void RISCVInsertVSETVLI ::coalesceVSETVLIs (MachineBasicBlock &MBB) const {
16541620 MachineInstr *NextMI = nullptr ;
16551621 // We can have arbitrary code in successors, so VL and VTYPE
16561622 // must be considered demanded.
@@ -1742,8 +1708,6 @@ bool RISCVCoalesceVSETVLI::coalesceVSETVLIs(MachineBasicBlock &MBB) {
17421708 LIS->RemoveMachineInstrFromMaps (*MI);
17431709 MI->eraseFromParent ();
17441710 }
1745-
1746- return !ToDelete.empty ();
17471711}
17481712
17491713void RISCVInsertVSETVLI::insertReadVL (MachineBasicBlock &MBB) {
@@ -1833,6 +1797,15 @@ bool RISCVInsertVSETVLI::runOnMachineFunction(MachineFunction &MF) {
18331797 for (MachineBasicBlock &MBB : MF)
18341798 insertReadVL (MBB);
18351799
1800+ // Now that all vsetvlis are explicit, go through and do block local
1801+ // DSE and peephole based demanded fields based transforms. Note that
1802+ // this *must* be done outside the main dataflow so long as we allow
1803+ // any cross block analysis within the dataflow. We can't have both
1804+ // demanded fields based mutation and non-local analysis in the
1805+ // dataflow at the same time without introducing inconsistencies.
1806+ for (MachineBasicBlock &MBB : MF)
1807+ coalesceVSETVLIs (MBB);
1808+
18361809 BlockInfo.clear ();
18371810 return HaveVectorOp;
18381811}
@@ -1841,29 +1814,3 @@ bool RISCVInsertVSETVLI::runOnMachineFunction(MachineFunction &MF) {
18411814FunctionPass *llvm::createRISCVInsertVSETVLIPass () {
18421815 return new RISCVInsertVSETVLI ();
18431816}
1844-
1845- // Now that all vsetvlis are explicit, go through and do block local
1846- // DSE and peephole based demanded fields based transforms. Note that
1847- // this *must* be done outside the main dataflow so long as we allow
1848- // any cross block analysis within the dataflow. We can't have both
1849- // demanded fields based mutation and non-local analysis in the
1850- // dataflow at the same time without introducing inconsistencies.
1851- bool RISCVCoalesceVSETVLI::runOnMachineFunction (MachineFunction &MF) {
1852- // Skip if the vector extension is not enabled.
1853- ST = &MF.getSubtarget <RISCVSubtarget>();
1854- if (!ST->hasVInstructions ())
1855- return false ;
1856- TII = ST->getInstrInfo ();
1857- MRI = &MF.getRegInfo ();
1858- LIS = &getAnalysis<LiveIntervals>();
1859-
1860- bool Changed = false ;
1861- for (MachineBasicBlock &MBB : MF)
1862- Changed |= coalesceVSETVLIs (MBB);
1863-
1864- return Changed;
1865- }
1866-
1867- FunctionPass *llvm::createRISCVCoalesceVSETVLIPass () {
1868- return new RISCVCoalesceVSETVLI ();
1869- }
0 commit comments