Skip to content

Commit 9a9f155

Browse files
authored
[Coroutines] Split buildCoroutineFrame into normalization and frame building (#108076)
* 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 while the normalization can be done by splitCoroutine prior to calling buildCoroutineFrame. See RFC for more info: https://discourse.llvm.org/t/rfc-abi-objects-for-coroutines/81057
1 parent 1741b9c commit 9a9f155

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

llvm/lib/Transforms/Coroutines/CoroFrame.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1754,7 +1754,8 @@ static bool willLeaveFunctionImmediatelyAfter(BasicBlock *BB,
17541754
if (depth == 0) return false;
17551755

17561756
// If this is a suspend block, we're about to exit the resumption function.
1757-
if (isSuspendBlock(BB)) return true;
1757+
if (isSuspendBlock(BB))
1758+
return true;
17581759

17591760
// Recurse into the successors.
17601761
for (auto *Succ : successors(BB)) {
@@ -2288,9 +2289,8 @@ static void doRematerializations(
22882289
rewriteMaterializableInstructions(AllRemats);
22892290
}
22902291

2291-
void coro::buildCoroutineFrame(
2292-
Function &F, Shape &Shape, TargetTransformInfo &TTI,
2293-
const std::function<bool(Instruction &)> &MaterializableCallback) {
2292+
void coro::normalizeCoroutine(Function &F, coro::Shape &Shape,
2293+
TargetTransformInfo &TTI) {
22942294
// Don't eliminate swifterror in async functions that won't be split.
22952295
if (Shape.ABI != coro::ABI::Async || !Shape.CoroSuspends.empty())
22962296
eliminateSwiftError(F, Shape);
@@ -2337,10 +2337,12 @@ void coro::buildCoroutineFrame(
23372337
// Transforms multi-edge PHI Nodes, so that any value feeding into a PHI will
23382338
// never have its definition separated from the PHI by the suspend point.
23392339
rewritePHIs(F);
2340+
}
23402341

2341-
// Build suspend crossing info.
2342+
void coro::buildCoroutineFrame(
2343+
Function &F, Shape &Shape,
2344+
const std::function<bool(Instruction &)> &MaterializableCallback) {
23422345
SuspendCrossingInfo Checker(F, Shape.CoroSuspends, Shape.CoroEnds);
2343-
23442346
doRematerializations(F, Checker, MaterializableCallback);
23452347

23462348
const DominatorTree DT(F);

llvm/lib/Transforms/Coroutines/CoroInternal.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,10 @@ struct LLVM_LIBRARY_VISIBILITY Shape {
281281
};
282282

283283
bool defaultMaterializable(Instruction &V);
284+
void normalizeCoroutine(Function &F, coro::Shape &Shape,
285+
TargetTransformInfo &TTI);
284286
void buildCoroutineFrame(
285-
Function &F, Shape &Shape, TargetTransformInfo &TTI,
287+
Function &F, Shape &Shape,
286288
const std::function<bool(Instruction &)> &MaterializableCallback);
287289
CallInst *createMustTailCall(DebugLoc Loc, Function *MustTailCallFn,
288290
TargetTransformInfo &TTI,

llvm/lib/Transforms/Coroutines/CoroSplit.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2030,7 +2030,8 @@ splitCoroutine(Function &F, SmallVectorImpl<Function *> &Clones,
20302030
lowerAwaitSuspends(F, Shape);
20312031

20322032
simplifySuspendPoints(Shape);
2033-
buildCoroutineFrame(F, Shape, TTI, MaterializableCallback);
2033+
normalizeCoroutine(F, Shape, TTI);
2034+
buildCoroutineFrame(F, Shape, MaterializableCallback);
20342035
replaceFrameSizeAndAlignment(Shape);
20352036
bool isNoSuspendCoroutine = Shape.CoroSuspends.empty();
20362037

0 commit comments

Comments
 (0)