From 34559ad06f82f7d1b48f7982e7a64944d72204b4 Mon Sep 17 00:00:00 2001 From: tnowicki Date: Fri, 23 Aug 2024 13:13:20 -0400 Subject: [PATCH] [Coroutines] Split buildCoroutineFrame * Split buildCoroutineFrame into code related to normalization and code related to actually building the coroutine frame. * This will enable future specialization of buildCoroutineFrame for different ABIs. --- llvm/lib/Transforms/Coroutines/CoroFrame.cpp | 14 ++++++++------ llvm/lib/Transforms/Coroutines/CoroInternal.h | 4 +++- llvm/lib/Transforms/Coroutines/CoroSplit.cpp | 3 ++- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/llvm/lib/Transforms/Coroutines/CoroFrame.cpp b/llvm/lib/Transforms/Coroutines/CoroFrame.cpp index 4b76fc7936100..8ee4bfa3b888d 100644 --- a/llvm/lib/Transforms/Coroutines/CoroFrame.cpp +++ b/llvm/lib/Transforms/Coroutines/CoroFrame.cpp @@ -1754,7 +1754,8 @@ static bool willLeaveFunctionImmediatelyAfter(BasicBlock *BB, if (depth == 0) return false; // If this is a suspend block, we're about to exit the resumption function. - if (isSuspendBlock(BB)) return true; + if (isSuspendBlock(BB)) + return true; // Recurse into the successors. for (auto *Succ : successors(BB)) { @@ -2288,9 +2289,8 @@ static void doRematerializations( rewriteMaterializableInstructions(AllRemats); } -void coro::buildCoroutineFrame( - Function &F, Shape &Shape, TargetTransformInfo &TTI, - const std::function &MaterializableCallback) { +void coro::normalizeCoroutine(Function &F, coro::Shape &Shape, + TargetTransformInfo &TTI) { // Don't eliminate swifterror in async functions that won't be split. if (Shape.ABI != coro::ABI::Async || !Shape.CoroSuspends.empty()) eliminateSwiftError(F, Shape); @@ -2337,10 +2337,12 @@ void coro::buildCoroutineFrame( // Transforms multi-edge PHI Nodes, so that any value feeding into a PHI will // never have its definition separated from the PHI by the suspend point. rewritePHIs(F); +} - // Build suspend crossing info. +void coro::buildCoroutineFrame( + Function &F, Shape &Shape, + const std::function &MaterializableCallback) { SuspendCrossingInfo Checker(F, Shape.CoroSuspends, Shape.CoroEnds); - doRematerializations(F, Checker, MaterializableCallback); const DominatorTree DT(F); diff --git a/llvm/lib/Transforms/Coroutines/CoroInternal.h b/llvm/lib/Transforms/Coroutines/CoroInternal.h index be86f96525b67..698c21a797420 100644 --- a/llvm/lib/Transforms/Coroutines/CoroInternal.h +++ b/llvm/lib/Transforms/Coroutines/CoroInternal.h @@ -281,8 +281,10 @@ struct LLVM_LIBRARY_VISIBILITY Shape { }; bool defaultMaterializable(Instruction &V); +void normalizeCoroutine(Function &F, coro::Shape &Shape, + TargetTransformInfo &TTI); void buildCoroutineFrame( - Function &F, Shape &Shape, TargetTransformInfo &TTI, + Function &F, Shape &Shape, const std::function &MaterializableCallback); CallInst *createMustTailCall(DebugLoc Loc, Function *MustTailCallFn, TargetTransformInfo &TTI, diff --git a/llvm/lib/Transforms/Coroutines/CoroSplit.cpp b/llvm/lib/Transforms/Coroutines/CoroSplit.cpp index 494c4d632de95..dc3829d7f28eb 100644 --- a/llvm/lib/Transforms/Coroutines/CoroSplit.cpp +++ b/llvm/lib/Transforms/Coroutines/CoroSplit.cpp @@ -2030,7 +2030,8 @@ splitCoroutine(Function &F, SmallVectorImpl &Clones, lowerAwaitSuspends(F, Shape); simplifySuspendPoints(Shape); - buildCoroutineFrame(F, Shape, TTI, MaterializableCallback); + normalizeCoroutine(F, Shape, TTI); + buildCoroutineFrame(F, Shape, MaterializableCallback); replaceFrameSizeAndAlignment(Shape); bool isNoSuspendCoroutine = Shape.CoroSuspends.empty();