@@ -799,9 +799,10 @@ void coro::buildCoroutineFrame(Function &F, Shape &Shape) {
799
799
splitAround (CSI, " CoroSuspend" );
800
800
}
801
801
802
- // Put fallthrough CoroEnd into its own block. Note: Shape::buildFrom places
803
- // the fallthrough coro.end as the first element of CoroEnds array.
804
- splitAround (Shape.CoroEnds .front (), " CoroEnd" );
802
+ // Put CoroEnds into their own blocks.
803
+ for (CoroEndInst *CE : Shape.CoroEnds ) {
804
+ splitAround (CE, " CoroEnd" );
805
+ }
805
806
806
807
// Transforms multi-edge PHI Nodes, so that any value feeding into a PHI will
807
808
// never has its definition separated from the PHI by the suspend point.
@@ -813,19 +814,24 @@ void coro::buildCoroutineFrame(Function &F, Shape &Shape) {
813
814
IRBuilder<> Builder (F.getContext ());
814
815
SpillInfo Spills;
815
816
816
- // See if there are materializable instructions across suspend points.
817
- for (Instruction &I : instructions (F))
818
- if (materializable (I))
819
- for (User *U : I.users ())
820
- if (Checker.isDefinitionAcrossSuspend (I, U))
821
- Spills.emplace_back (&I, U);
817
+ for (int repeat = 0 ; repeat < 4 ; ++repeat) {
818
+ // See if there are materializable instructions across suspend points.
819
+ for (Instruction &I : instructions (F))
820
+ if (materializable (I))
821
+ for (User *U : I.users ())
822
+ if (Checker.isDefinitionAcrossSuspend (I, U))
823
+ Spills.emplace_back (&I, U);
824
+
825
+ if (Spills.empty ())
826
+ break ;
822
827
823
- // Rewrite materializable instructions to be materialized at the use point.
824
- DEBUG (dump (" Materializations" , Spills));
825
- rewriteMaterializableInstructions (Builder, Spills);
828
+ // Rewrite materializable instructions to be materialized at the use point.
829
+ DEBUG (dump (" Materializations" , Spills));
830
+ rewriteMaterializableInstructions (Builder, Spills);
831
+ Spills.clear ();
832
+ }
826
833
827
834
// Collect the spills for arguments and other not-materializable values.
828
- Spills.clear ();
829
835
for (Argument &A : F.args ())
830
836
for (User *U : A.users ())
831
837
if (Checker.isDefinitionAcrossSuspend (A, U))
@@ -847,8 +853,6 @@ void coro::buildCoroutineFrame(Function &F, Shape &Shape) {
847
853
if (I.getType ()->isTokenTy ())
848
854
report_fatal_error (
849
855
" token definition is separated from the use by a suspend point" );
850
- assert (!materializable (I) &&
851
- " rewriteMaterializable did not do its job" );
852
856
Spills.emplace_back (&I, U);
853
857
}
854
858
}
0 commit comments