@@ -117,8 +117,8 @@ class CoroCloner {
117117  // / Create a cloner for a switch lowering.
118118  CoroCloner (Function &OrigF, const  Twine &Suffix, coro::Shape &Shape,
119119             Kind FKind)
120-     : OrigF(OrigF), NewF(nullptr ), Suffix(Suffix), Shape(Shape),
121-       FKind (FKind),  Builder(OrigF.getContext()) {
120+        : OrigF(OrigF), NewF(nullptr ), Suffix(Suffix), Shape(Shape), FKind(FKind ),
121+          Builder (OrigF.getContext()) {
122122    assert (Shape.ABI  == coro::ABI::Switch);
123123  }
124124
@@ -170,8 +170,7 @@ class CoroCloner {
170170static  void  maybeFreeRetconStorage (IRBuilder<> &Builder,
171171                                   const  coro::Shape &Shape, Value *FramePtr,
172172                                   CallGraph *CG) {
173-   assert (Shape.ABI  == coro::ABI::Retcon ||
174-          Shape.ABI  == coro::ABI::RetconOnce);
173+   assert (Shape.ABI  == coro::ABI::Retcon || Shape.ABI  == coro::ABI::RetconOnce);
175174  if  (Shape.RetconLowering .IsFrameInlineInStorage )
176175    return ;
177176
@@ -208,12 +207,17 @@ static bool replaceCoroEndAsync(AnyCoroEndInst *End) {
208207  //  Insert the return instruction.
209208  Builder.SetInsertPoint (End);
210209  Builder.CreateRetVoid ();
210+   InlineFunctionInfo FnInfo;
211211
212212  //  Remove the rest of the block, by splitting it into an unreachable block.
213213  auto  *BB = End->getParent ();
214214  BB->splitBasicBlock (End);
215215  BB->getTerminator ()->eraseFromParent ();
216216
217+   auto  InlineRes = InlineFunction (*MustTailCall, FnInfo);
218+   assert (InlineRes.isSuccess () && " Expected inlining to succeed" 
219+   (void )InlineRes;
220+ 
217221  //  We have cleaned up the coro.end block above.
218222  return  false ;
219223}
@@ -264,7 +268,7 @@ static void replaceFallthroughCoroEnd(AnyCoroEndInst *End,
264268
265269    if  (auto  *RetStructTy = dyn_cast<StructType>(RetTy)) {
266270      assert (RetStructTy->getNumElements () == NumReturns &&
267-            " numbers of returns should match resume function singature" 
271+               " numbers of returns should match resume function singature" 
268272      Value *ReturnValue = UndefValue::get (RetStructTy);
269273      unsigned  Idx = 0 ;
270274      for  (Value *RetValEl : CoroResults->return_values ())
@@ -277,7 +281,8 @@ static void replaceFallthroughCoroEnd(AnyCoroEndInst *End,
277281      assert (NumReturns == 1 );
278282      Builder.CreateRet (*CoroResults->retval_begin ());
279283    }
280-     CoroResults->replaceAllUsesWith (ConstantTokenNone::get (CoroResults->getContext ()));
284+     CoroResults->replaceAllUsesWith (
285+         ConstantTokenNone::get (CoroResults->getContext ()));
281286    CoroResults->eraseFromParent ();
282287    break ;
283288  }
@@ -291,7 +296,7 @@ static void replaceFallthroughCoroEnd(AnyCoroEndInst *End,
291296    auto  RetTy = Shape.getResumeFunctionType ()->getReturnType ();
292297    auto  RetStructTy = dyn_cast<StructType>(RetTy);
293298    PointerType *ContinuationTy =
294-       cast<PointerType>(RetStructTy ? RetStructTy->getElementType (0 ) : RetTy);
299+          cast<PointerType>(RetStructTy ? RetStructTy->getElementType (0 ) : RetTy);
295300
296301    Value *ReturnValue = ConstantPointerNull::get (ContinuationTy);
297302    if  (RetStructTy) {
@@ -480,11 +485,12 @@ void CoroCloner::replaceRetconOrAsyncSuspendUses() {
480485         Shape.ABI  == coro::ABI::Async);
481486
482487  auto  NewS = VMap[ActiveSuspend];
483-   if  (NewS->use_empty ()) return ;
488+   if  (NewS->use_empty ())
489+     return ;
484490
485491  //  Copy out all the continuation arguments after the buffer pointer into
486492  //  an easily-indexed data structure for convenience.
487-   SmallVector<Value*, 8 > Args;
493+   SmallVector<Value  *, 8 > Args;
488494  //  The async ABI includes all arguments -- including the first argument.
489495  bool  IsAsyncABI = Shape.ABI  == coro::ABI::Async;
490496  for  (auto  I = IsAsyncABI ? NewF->arg_begin () : std::next (NewF->arg_begin ()),
@@ -511,7 +517,8 @@ void CoroCloner::replaceRetconOrAsyncSuspendUses() {
511517  }
512518
513519  //  If we have no remaining uses, we're done.
514-   if  (NewS->use_empty ()) return ;
520+   if  (NewS->use_empty ())
521+     return ;
515522
516523  //  Otherwise, we need to create an aggregate.
517524  Value *Agg = PoisonValue::get (NewS->getType ());
@@ -549,7 +556,8 @@ void CoroCloner::replaceCoroSuspends() {
549556
550557  for  (AnyCoroSuspendInst *CS : Shape.CoroSuspends ) {
551558    //  The active suspend was handled earlier.
552-     if  (CS == ActiveSuspend) continue ;
559+     if  (CS == ActiveSuspend)
560+       continue ;
553561
554562    auto  *MappedCS = cast<AnyCoroSuspendInst>(VMap[CS]);
555563    MappedCS->replaceAllUsesWith (SuspendResult);
@@ -707,7 +715,7 @@ void CoroCloner::replaceEntryBlock() {
707715    //  In switch-lowering, we built a resume-entry block in the original
708716    //  function.  Make the entry block branch to this.
709717    auto  *SwitchBB =
710-       cast<BasicBlock>(VMap[Shape.SwitchLowering .ResumeEntryBlock ]);
718+          cast<BasicBlock>(VMap[Shape.SwitchLowering .ResumeEntryBlock ]);
711719    Builder.CreateBr (SwitchBB);
712720    break ;
713721  }
@@ -1055,7 +1063,7 @@ void CoroCloner::create() {
10551063  //  to suppress deallocation code.
10561064  if  (Shape.ABI  == coro::ABI::Switch)
10571065    coro::replaceCoroFree (cast<CoroIdInst>(VMap[Shape.CoroBegin ->getId ()]),
1058-                           /* Elide=*/   FKind == CoroCloner::Kind::SwitchCleanup);
1066+                           /* Elide=*/ 
10591067}
10601068
10611069static  void  updateAsyncFuncPointerContextSize (coro::Shape &Shape) {
@@ -1842,8 +1850,13 @@ static void splitAsyncCoroutine(Function &F, coro::Shape &Shape,
18421850    SmallVector<Value *, 8 > Args (Suspend->args ());
18431851    auto  FnArgs = ArrayRef<Value *>(Args).drop_front (
18441852        CoroSuspendAsyncInst::MustTailCallFuncArg + 1 );
1845-     coro::createMustTailCall (Suspend->getDebugLoc (), Fn, TTI, FnArgs, Builder);
1853+     auto  *TailCall = coro::createMustTailCall (Suspend->getDebugLoc (), Fn, TTI,
1854+                                               FnArgs, Builder);
18461855    Builder.CreateRetVoid ();
1856+     InlineFunctionInfo FnInfo;
1857+     auto  InlineRes = InlineFunction (*TailCall, FnInfo);
1858+     assert (InlineRes.isSuccess () && " Expected inlining to succeed" 
1859+     (void )InlineRes;
18471860
18481861    //  Replace the lvm.coro.async.resume intrisic call.
18491862    replaceAsyncResumeFunction (Suspend, Continuation);
@@ -1860,8 +1873,7 @@ static void splitAsyncCoroutine(Function &F, coro::Shape &Shape,
18601873
18611874static  void  splitRetconCoroutine (Function &F, coro::Shape &Shape,
18621875                                 SmallVectorImpl<Function *> &Clones) {
1863-   assert (Shape.ABI  == coro::ABI::Retcon ||
1864-          Shape.ABI  == coro::ABI::RetconOnce);
1876+   assert (Shape.ABI  == coro::ABI::Retcon || Shape.ABI  == coro::ABI::RetconOnce);
18651877  assert (Clones.empty ());
18661878
18671879  //  Reset various things that the optimizer might have decided it
@@ -1887,7 +1899,7 @@ static void splitRetconCoroutine(Function &F, coro::Shape &Shape,
18871899    //  FIXME: pass the required alignment
18881900    RawFramePtr = Shape.emitAlloc (Builder, Builder.getInt64 (Size), nullptr );
18891901    RawFramePtr =
1890-       Builder.CreateBitCast (RawFramePtr, Shape.CoroBegin ->getType ());
1902+          Builder.CreateBitCast (RawFramePtr, Shape.CoroBegin ->getType ());
18911903
18921904    //  Stash the allocated frame pointer in the continuation storage.
18931905    Builder.CreateStore (RawFramePtr, Id->getStorage ());
@@ -1927,8 +1939,8 @@ static void splitRetconCoroutine(Function &F, coro::Shape &Shape,
19271939    //  Create the unified return block.
19281940    if  (!ReturnBB) {
19291941      //  Place it before the first suspend.
1930-       ReturnBB =  BasicBlock::Create (F. getContext (),  " coro.return " , &F, 
1931-                                      NewSuspendBB);
1942+       ReturnBB =
1943+           BasicBlock::Create (F. getContext (),  " coro.return " , &F,  NewSuspendBB);
19321944      Shape.RetconLowering .ReturnBlock  = ReturnBB;
19331945
19341946      IRBuilder<> Builder (ReturnBB);
@@ -1942,8 +1954,8 @@ static void splitRetconCoroutine(Function &F, coro::Shape &Shape,
19421954
19431955      //  Next, all the directly-yielded values.
19441956      for  (auto  *ResultTy : Shape.getRetconResultTypes ())
1945-         ReturnPHIs.push_back (Builder. CreatePHI (ResultTy, 
1946-                                                 Shape.CoroSuspends .size ()));
1957+         ReturnPHIs.push_back (
1958+             Builder. CreatePHI (ResultTy,  Shape.CoroSuspends .size ()));
19471959
19481960      //  Build the return value.
19491961      auto  RetTy = F.getReturnType ();
@@ -1952,9 +1964,9 @@ static void splitRetconCoroutine(Function &F, coro::Shape &Shape,
19521964      //  We can't rely on the types matching up because that type would
19531965      //  have to be infinite.
19541966      auto  CastedContinuationTy =
1955-         (ReturnPHIs.size () == 1  ? RetTy : RetTy->getStructElementType (0 ));
1967+            (ReturnPHIs.size () == 1  ? RetTy : RetTy->getStructElementType (0 ));
19561968      auto  *CastedContinuation =
1957-         Builder.CreateBitCast (ReturnPHIs[0 ], CastedContinuationTy);
1969+            Builder.CreateBitCast (ReturnPHIs[0 ], CastedContinuationTy);
19581970
19591971      Value *RetV;
19601972      if  (ReturnPHIs.size () == 1 ) {
@@ -1988,17 +2000,18 @@ static void splitRetconCoroutine(Function &F, coro::Shape &Shape,
19882000}
19892001
19902002namespace  {
1991-   class  PrettyStackTraceFunction  : public  PrettyStackTraceEntry  {
1992-     Function &F;
1993-   public: 
1994-     PrettyStackTraceFunction (Function &F) : F(F) {}
1995-     void  print (raw_ostream &OS) const  override  {
1996-       OS << " While splitting coroutine " 
1997-       F.printAsOperand (OS, /* print type*/ false , F.getParent ());
1998-       OS << " \n " 
1999-     }
2000-   };
2001- }
2003+ class  PrettyStackTraceFunction  : public  PrettyStackTraceEntry  {
2004+   Function &F;
2005+ 
2006+ public: 
2007+   PrettyStackTraceFunction (Function &F) : F(F) {}
2008+   void  print (raw_ostream &OS) const  override  {
2009+     OS << " While splitting coroutine " 
2010+     F.printAsOperand (OS, /* print type*/ false , F.getParent ());
2011+     OS << " \n " 
2012+   }
2013+ };
2014+ } //  namespace
20022015
20032016static  coro::Shape
20042017splitCoroutine (Function &F, SmallVectorImpl<Function *> &Clones,
0 commit comments