@@ -742,25 +742,7 @@ static void processBranchOp(BranchOpInterface branchOp, RunLivenessAnalysis &la,
742742static void cleanUpDeadVals (RDVFinalCleanupList &list) {
743743 LDBG () << " Starting cleanup of dead values..." ;
744744
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
745+ // 1. Operations
764746 LDBG () << " Cleaning up " << list.operations .size () << " operations" ;
765747 for (auto &op : list.operations ) {
766748 LDBG () << " Erasing operation: "
@@ -769,14 +751,14 @@ static void cleanUpDeadVals(RDVFinalCleanupList &list) {
769751 op->erase ();
770752 }
771753
772- // 3 . Values
754+ // 2 . Values
773755 LDBG () << " Cleaning up " << list.values .size () << " values" ;
774756 for (auto &v : list.values ) {
775757 LDBG () << " Dropping all uses of value: " << v;
776758 v.dropAllUses ();
777759 }
778760
779- // 4 . Functions
761+ // 3 . Functions
780762 LDBG () << " Cleaning up " << list.functions .size () << " functions" ;
781763 // Record which function arguments were erased so we can shrink call-site
782764 // argument segments for CallOpInterface operations (e.g. ops using
@@ -798,7 +780,7 @@ static void cleanUpDeadVals(RDVFinalCleanupList &list) {
798780 (void )f.funcOp .eraseResults (f.nonLiveRets );
799781 }
800782
801- // 5 . Operands
783+ // 4 . Operands
802784 LDBG () << " Cleaning up " << list.operands .size () << " operand lists" ;
803785 for (OperationToCleanup &o : list.operands ) {
804786 // Handle call-specific cleanup only when we have a cached callee reference.
@@ -840,7 +822,7 @@ static void cleanUpDeadVals(RDVFinalCleanupList &list) {
840822 }
841823 }
842824
843- // 6 . Results
825+ // 5 . Results
844826 LDBG () << " Cleaning up " << list.results .size () << " result lists" ;
845827 for (auto &r : list.results ) {
846828 LDBG () << " Erasing " << r.nonLive .count ()
@@ -849,6 +831,24 @@ static void cleanUpDeadVals(RDVFinalCleanupList &list) {
849831 dropUsesAndEraseResults (r.op , r.nonLive );
850832 }
851833
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