@@ -731,7 +731,25 @@ static void processBranchOp(BranchOpInterface branchOp, RunLivenessAnalysis &la,
731731static void cleanUpDeadVals (RDVFinalCleanupList &list) {
732732 LDBG () << " Starting cleanup of dead values..." ;
733733
734- // 1. Operations
734+ // 1. Blocks
735+ LDBG () << " Cleaning up " << list.blocks .size () << " block argument lists" ;
736+ for (auto &b : list.blocks ) {
737+ // blocks that are accessed via multiple codepaths processed once
738+ if (b.b ->getNumArguments () != b.nonLiveArgs .size ())
739+ continue ;
740+ LDBG () << " Erasing " << b.nonLiveArgs .count ()
741+ << " non-live arguments from block: " << b.b ;
742+ // it iterates backwards because erase invalidates all successor indexes
743+ for (int i = b.nonLiveArgs .size () - 1 ; i >= 0 ; --i) {
744+ if (!b.nonLiveArgs [i])
745+ continue ;
746+ LDBG () << " Erasing block argument " << i << " : " << b.b ->getArgument (i);
747+ b.b ->getArgument (i).dropAllUses ();
748+ b.b ->eraseArgument (i);
749+ }
750+ }
751+
752+ // 2. Operations
735753 LDBG () << " Cleaning up " << list.operations .size () << " operations" ;
736754 for (auto &op : list.operations ) {
737755 LDBG () << " Erasing operation: "
@@ -740,14 +758,14 @@ static void cleanUpDeadVals(RDVFinalCleanupList &list) {
740758 op->erase ();
741759 }
742760
743- // 2 . Values
761+ // 3 . Values
744762 LDBG () << " Cleaning up " << list.values .size () << " values" ;
745763 for (auto &v : list.values ) {
746764 LDBG () << " Dropping all uses of value: " << v;
747765 v.dropAllUses ();
748766 }
749767
750- // 3 . Functions
768+ // 4 . Functions
751769 LDBG () << " Cleaning up " << list.functions .size () << " functions" ;
752770 // Record which function arguments were erased so we can shrink call-site
753771 // argument segments for CallOpInterface operations (e.g. ops using
@@ -769,7 +787,7 @@ static void cleanUpDeadVals(RDVFinalCleanupList &list) {
769787 (void )f.funcOp .eraseResults (f.nonLiveRets );
770788 }
771789
772- // 4 . Operands
790+ // 5 . Operands
773791 LDBG () << " Cleaning up " << list.operands .size () << " operand lists" ;
774792 for (OperationToCleanup &o : list.operands ) {
775793 // Handle call-specific cleanup only when we have a cached callee reference.
@@ -811,7 +829,7 @@ static void cleanUpDeadVals(RDVFinalCleanupList &list) {
811829 }
812830 }
813831
814- // 5 . Results
832+ // 6 . Results
815833 LDBG () << " Cleaning up " << list.results .size () << " result lists" ;
816834 for (auto &r : list.results ) {
817835 LDBG () << " Erasing " << r.nonLive .count ()
@@ -820,24 +838,6 @@ static void cleanUpDeadVals(RDVFinalCleanupList &list) {
820838 dropUsesAndEraseResults (r.op , r.nonLive );
821839 }
822840
823- // 6. Blocks
824- LDBG () << " Cleaning up " << list.blocks .size () << " block argument lists" ;
825- for (auto &b : list.blocks ) {
826- // blocks that are accessed via multiple codepaths processed once
827- if (b.b ->getNumArguments () != b.nonLiveArgs .size ())
828- continue ;
829- LDBG () << " Erasing " << b.nonLiveArgs .count ()
830- << " non-live arguments from block: " << b.b ;
831- // it iterates backwards because erase invalidates all successor indexes
832- for (int i = b.nonLiveArgs .size () - 1 ; i >= 0 ; --i) {
833- if (!b.nonLiveArgs [i])
834- continue ;
835- LDBG () << " Erasing block argument " << i << " : " << b.b ->getArgument (i);
836- b.b ->getArgument (i).dropAllUses ();
837- b.b ->eraseArgument (i);
838- }
839- }
840-
841841 // 7. Successor Operands
842842 LDBG () << " Cleaning up " << list.successorOperands .size ()
843843 << " successor operand lists" ;
0 commit comments