@@ -378,10 +378,10 @@ static bool areCompatibleVTYPEs(uint64_t CurVType, uint64_t NewVType,
378
378
379
379
// / Return the fields and properties demanded by the provided instruction.
380
380
DemandedFields 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.
385
385
386
386
// Most instructions don't use any of these subfeilds.
387
387
DemandedFields Res;
@@ -900,36 +900,7 @@ class RISCVInsertVSETVLI : public MachineFunctionPass {
900
900
void emitVSETVLIs (MachineBasicBlock &MBB);
901
901
void doPRE (MachineBasicBlock &MBB);
902
902
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 ;
933
904
};
934
905
935
906
} // end anonymous namespace
@@ -940,11 +911,6 @@ char &llvm::RISCVInsertVSETVLIID = RISCVInsertVSETVLI::ID;
940
911
INITIALIZE_PASS (RISCVInsertVSETVLI, DEBUG_TYPE, RISCV_INSERT_VSETVLI_NAME,
941
912
false , false )
942
913
943
- char RISCVCoalesceVSETVLI::ID = 0;
944
-
945
- INITIALIZE_PASS (RISCVCoalesceVSETVLI, " riscv-coalesce-vsetvli" ,
946
- RISCV_COALESCE_VSETVLI_NAME, false , false )
947
-
948
914
// Return a VSETVLIInfo representing the changes made by this VSETVLI or
949
915
// VSETIVLI instruction.
950
916
static VSETVLIInfo getInfoForVSETVLI(const MachineInstr &MI,
@@ -1653,7 +1619,7 @@ static bool canMutatePriorConfig(const MachineInstr &PrevMI,
1653
1619
return areCompatibleVTYPEs (PriorVType, VType, Used);
1654
1620
}
1655
1621
1656
- bool RISCVCoalesceVSETVLI ::coalesceVSETVLIs (MachineBasicBlock &MBB) {
1622
+ void RISCVInsertVSETVLI ::coalesceVSETVLIs (MachineBasicBlock &MBB) const {
1657
1623
MachineInstr *NextMI = nullptr ;
1658
1624
// We can have arbitrary code in successors, so VL and VTYPE
1659
1625
// must be considered demanded.
@@ -1745,8 +1711,6 @@ bool RISCVCoalesceVSETVLI::coalesceVSETVLIs(MachineBasicBlock &MBB) {
1745
1711
LIS->RemoveMachineInstrFromMaps (*MI);
1746
1712
MI->eraseFromParent ();
1747
1713
}
1748
-
1749
- return !ToDelete.empty ();
1750
1714
}
1751
1715
1752
1716
void RISCVInsertVSETVLI::insertReadVL (MachineBasicBlock &MBB) {
@@ -1836,6 +1800,15 @@ bool RISCVInsertVSETVLI::runOnMachineFunction(MachineFunction &MF) {
1836
1800
for (MachineBasicBlock &MBB : MF)
1837
1801
insertReadVL (MBB);
1838
1802
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
+
1839
1812
BlockInfo.clear ();
1840
1813
return HaveVectorOp;
1841
1814
}
@@ -1844,29 +1817,3 @@ bool RISCVInsertVSETVLI::runOnMachineFunction(MachineFunction &MF) {
1844
1817
FunctionPass *llvm::createRISCVInsertVSETVLIPass () {
1845
1818
return new RISCVInsertVSETVLI ();
1846
1819
}
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