From 065194781ff040afb8f1dbf2346735751c36dd7a Mon Sep 17 00:00:00 2001 From: John McCall Date: Wed, 14 Aug 2019 03:54:13 +0000 Subject: [PATCH] Remove unreachable blocks before splitting a coroutine. The suspend-crossing algorithm is not correct in the presence of uses that cannot be reached on some successor path from their defs. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@368796 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Coroutines/CoroSplit.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/Transforms/Coroutines/CoroSplit.cpp b/lib/Transforms/Coroutines/CoroSplit.cpp index db318d858da..01357f0c8bd 100644 --- a/lib/Transforms/Coroutines/CoroSplit.cpp +++ b/lib/Transforms/Coroutines/CoroSplit.cpp @@ -55,6 +55,7 @@ #include "llvm/Pass.h" #include "llvm/Support/Casting.h" #include "llvm/Support/Debug.h" +#include "llvm/Support/PrettyStackTrace.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Transforms/Scalar.h" #include "llvm/Transforms/Utils/BasicBlockUtils.h" @@ -1397,6 +1398,19 @@ static void splitRetconCoroutine(Function &F, coro::Shape &Shape, } } +namespace { + class PrettyStackTraceFunction : public PrettyStackTraceEntry { + Function &F; + public: + PrettyStackTraceFunction(Function &F) : F(F) {} + void print(raw_ostream &OS) const override { + OS << "While splitting coroutine "; + F.printAsOperand(OS, /*print type*/ false, F.getParent()); + OS << "\n"; + } + }; +} + static void splitCoroutine(Function &F, coro::Shape &Shape, SmallVectorImpl &Clones) { switch (Shape.ABI) { @@ -1410,7 +1424,11 @@ static void splitCoroutine(Function &F, coro::Shape &Shape, } static void splitCoroutine(Function &F, CallGraph &CG, CallGraphSCC &SCC) { - EliminateUnreachableBlocks(F); + PrettyStackTraceFunction prettyStackTrace(F); + + // The suspend-crossing algorithm in buildCoroutineFrame get tripped + // up by uses in unreachable blocks, so remove them as a first pass. + removeUnreachableBlocks(F); coro::Shape Shape(F); if (!Shape.CoroBegin) -- 2.40.0