@@ -742,7 +742,25 @@ static void processBranchOp(BranchOpInterface branchOp, RunLivenessAnalysis &la,
742742static void cleanUpDeadVals (RDVFinalCleanupList &list) {
743743 LDBG () << " Starting cleanup of dead values..." ;
744744
745- // 1. Operations
745+ // 1. Blocks
746+ LDBG () << " Cleaning up " << list.blocks .size () << " block argument lists" ;
747+ for (auto &b : list.blocks ) {
748+ // blocks that are accessed via multiple codepaths processed once
749+ if (b.b ->getNumArguments () != b.nonLiveArgs .size ())
750+ continue ;
751+ LDBG () << " Erasing " << b.nonLiveArgs .count ()
752+ << " non-live arguments from block: " << b.b ;
753+ // it iterates backwards because erase invalidates all successor indexes
754+ for (int i = b.nonLiveArgs .size () - 1 ; i >= 0 ; --i) {
755+ if (!b.nonLiveArgs [i])
756+ continue ;
757+ LDBG () << " Erasing block argument " << i << " : " << b.b ->getArgument (i);
758+ b.b ->getArgument (i).dropAllUses ();
759+ b.b ->eraseArgument (i);
760+ }
761+ }
762+
763+ // 2. Operations
746764 LDBG () << " Cleaning up " << list.operations .size () << " operations" ;
747765 for (auto &op : list.operations ) {
748766 LDBG () << " Erasing operation: "
@@ -751,14 +769,14 @@ static void cleanUpDeadVals(RDVFinalCleanupList &list) {
751769 op->erase ();
752770 }
753771
754- // 2 . Values
772+ // 3 . Values
755773 LDBG () << " Cleaning up " << list.values .size () << " values" ;
756774 for (auto &v : list.values ) {
757775 LDBG () << " Dropping all uses of value: " << v;
758776 v.dropAllUses ();
759777 }
760778
761- // 3 . Functions
779+ // 4 . Functions
762780 LDBG () << " Cleaning up " << list.functions .size () << " functions" ;
763781 // Record which function arguments were erased so we can shrink call-site
764782 // argument segments for CallOpInterface operations (e.g. ops using
@@ -780,7 +798,7 @@ static void cleanUpDeadVals(RDVFinalCleanupList &list) {
780798 (void )f.funcOp .eraseResults (f.nonLiveRets );
781799 }
782800
783- // 4 . Operands
801+ // 5 . Operands
784802 LDBG () << " Cleaning up " << list.operands .size () << " operand lists" ;
785803 for (OperationToCleanup &o : list.operands ) {
786804 // Handle call-specific cleanup only when we have a cached callee reference.
@@ -822,7 +840,7 @@ static void cleanUpDeadVals(RDVFinalCleanupList &list) {
822840 }
823841 }
824842
825- // 5 . Results
843+ // 6 . Results
826844 LDBG () << " Cleaning up " << list.results .size () << " result lists" ;
827845 for (auto &r : list.results ) {
828846 LDBG () << " Erasing " << r.nonLive .count ()
@@ -831,24 +849,6 @@ static void cleanUpDeadVals(RDVFinalCleanupList &list) {
831849 dropUsesAndEraseResults (r.op , r.nonLive );
832850 }
833851
834- // 6. Blocks
835- LDBG () << " Cleaning up " << list.blocks .size () << " block argument lists" ;
836- for (auto &b : list.blocks ) {
837- // blocks that are accessed via multiple codepaths processed once
838- if (b.b ->getNumArguments () != b.nonLiveArgs .size ())
839- continue ;
840- LDBG () << " Erasing " << b.nonLiveArgs .count ()
841- << " non-live arguments from block: " << b.b ;
842- // it iterates backwards because erase invalidates all successor indexes
843- for (int i = b.nonLiveArgs .size () - 1 ; i >= 0 ; --i) {
844- if (!b.nonLiveArgs [i])
845- continue ;
846- LDBG () << " Erasing block argument " << i << " : " << b.b ->getArgument (i);
847- b.b ->getArgument (i).dropAllUses ();
848- b.b ->eraseArgument (i);
849- }
850- }
851-
852852 // 7. Successor Operands
853853 LDBG () << " Cleaning up " << list.successorOperands .size ()
854854 << " successor operand lists" ;
0 commit comments