From c36c53588a763152f6585c0010963c95fa529e86 Mon Sep 17 00:00:00 2001 From: Arthur Eubanks Date: Thu, 7 Jan 2021 12:45:23 -0800 Subject: [PATCH] [CoroSplit][NewPM] Don't call LazyCallGraph functions to split when no clones Apparently there can be no clones, as happens in coro-retcon-unreachable.ll. The alternative is to allow no split functions in addSplitRefRecursiveFunctions(), but it seems better to have the caller make sure it's not accidentally splitting no functions out. Reviewed By: rnk Differential Revision: https://reviews.llvm.org/D94258 --- lib/Transforms/Coroutines/CoroSplit.cpp | 36 ++++++++++--------- .../Coroutines/coro-retcon-unreachable.ll | 1 + 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/lib/Transforms/Coroutines/CoroSplit.cpp b/lib/Transforms/Coroutines/CoroSplit.cpp index 6fd894d4bcf..e0bee13d83b 100644 --- a/lib/Transforms/Coroutines/CoroSplit.cpp +++ b/lib/Transforms/Coroutines/CoroSplit.cpp @@ -1748,24 +1748,26 @@ static void updateCallGraphAfterCoroutineSplit( End->eraseFromParent(); } - switch (Shape.ABI) { - case coro::ABI::Switch: - // Each clone in the Switch lowering is independent of the other clones. Let - // the LazyCallGraph know about each one separately. - for (Function *Clone : Clones) - CG.addSplitFunction(N.getFunction(), *Clone); - break; - case coro::ABI::Async: - case coro::ABI::Retcon: - case coro::ABI::RetconOnce: - // Each clone in the Async/Retcon lowering references of the other clones. - // Let the LazyCallGraph know about all of them at once. - CG.addSplitRefRecursiveFunctions(N.getFunction(), Clones); - break; - } + if (!Clones.empty()) { + switch (Shape.ABI) { + case coro::ABI::Switch: + // Each clone in the Switch lowering is independent of the other clones. + // Let the LazyCallGraph know about each one separately. + for (Function *Clone : Clones) + CG.addSplitFunction(N.getFunction(), *Clone); + break; + case coro::ABI::Async: + case coro::ABI::Retcon: + case coro::ABI::RetconOnce: + // Each clone in the Async/Retcon lowering references of the other clones. + // Let the LazyCallGraph know about all of them at once. + CG.addSplitRefRecursiveFunctions(N.getFunction(), Clones); + break; + } - // Let the CGSCC infra handle the changes to the original function. - updateCGAndAnalysisManagerForCGSCCPass(CG, C, N, AM, UR, FAM); + // Let the CGSCC infra handle the changes to the original function. + updateCGAndAnalysisManagerForCGSCCPass(CG, C, N, AM, UR, FAM); + } // Do some cleanup and let the CGSCC infra see if we've cleaned up any edges // to the split functions. diff --git a/test/Transforms/Coroutines/coro-retcon-unreachable.ll b/test/Transforms/Coroutines/coro-retcon-unreachable.ll index 27ee2fd540a..4a1c44061b4 100644 --- a/test/Transforms/Coroutines/coro-retcon-unreachable.ll +++ b/test/Transforms/Coroutines/coro-retcon-unreachable.ll @@ -1,4 +1,5 @@ ; RUN: opt < %s -coro-early -coro-split -S | FileCheck %s +; RUN: opt < %s -passes='function(coro-early),cgscc(coro-split)' -S | FileCheck %s target datalayout = "E-p:64:64" %swift.type = type { i64 }