18
18
19
19
#include " RISCV.h"
20
20
#include " RISCVSubtarget.h"
21
- #include " llvm/ADT/SetVector .h"
21
+ #include " llvm/ADT/PostOrderIterator .h"
22
22
#include " llvm/CodeGen/MachineDominators.h"
23
23
#include " llvm/CodeGen/MachineFunctionPass.h"
24
24
#include " llvm/InitializePasses.h"
@@ -1343,21 +1343,22 @@ bool RISCVVLOptimizer::runOnMachineFunction(MachineFunction &MF) {
1343
1343
1344
1344
TII = ST.getInstrInfo ();
1345
1345
1346
- bool MadeChange = false ;
1347
- for (MachineBasicBlock &MBB : MF) {
1348
- // Avoid unreachable blocks as they have degenerate dominance
1349
- if (!MDT->isReachableFromEntry (&MBB))
1350
- continue ;
1351
1346
1352
- // For each instruction that defines a vector, compute what VL its
1353
- // downstream users demand.
1354
- for (MachineInstr &MI : reverse (MBB)) {
1347
+ // For each instruction that defines a vector, compute what VL its
1348
+ // downstream users demand.
1349
+ for (MachineBasicBlock *MBB : post_order (&MF)) {
1350
+ // Avoid unreachable blocks as they have degenerate dominance
1351
+ assert (MDT->isReachableFromEntry (MBB));
1352
+ for (MachineInstr &MI : reverse (*MBB)) {
1355
1353
if (!isCandidate (MI))
1356
1354
continue ;
1357
1355
if (auto DemandedVL = checkUsers (MI))
1358
1356
DemandedVLs.insert ({&MI, *DemandedVL});
1359
1357
}
1358
+ }
1360
1359
1360
+ bool MadeChange = false ;
1361
+ for (MachineBasicBlock &MBB : MF) {
1361
1362
// Then go through and see if we can reduce the VL of any instructions to
1362
1363
// only what's demanded.
1363
1364
for (auto &MI : MBB) {
@@ -1367,8 +1368,6 @@ bool RISCVVLOptimizer::runOnMachineFunction(MachineFunction &MF) {
1367
1368
continue ;
1368
1369
MadeChange = true ;
1369
1370
}
1370
-
1371
- DemandedVLs.clear ();
1372
1371
}
1373
1372
1374
1373
return MadeChange;
0 commit comments