1 //===- CoroSplit.cpp - Converts a coroutine into a state machine ----------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 // This pass builds the coroutine frame and outlines resume and destroy parts
10 // of the coroutine into separate functions.
11 //===----------------------------------------------------------------------===//
12 
13 #include "CoroInternal.h"
14 #include "llvm/Analysis/CallGraphSCCPass.h"
15 
16 using namespace llvm;
17 
18 #define DEBUG_TYPE "coro-split"
19 
20 //===----------------------------------------------------------------------===//
21 //                              Top Level Driver
22 //===----------------------------------------------------------------------===//
23 
24 namespace {
25 
26 struct CoroSplit : public CallGraphSCCPass {
27   static char ID; // Pass identification, replacement for typeid
28   CoroSplit() : CallGraphSCCPass(ID) {}
29 
30   bool runOnSCC(CallGraphSCC &SCC) override { return false; }
31   void getAnalysisUsage(AnalysisUsage &AU) const override {
32     AU.setPreservesAll();
33     CallGraphSCCPass::getAnalysisUsage(AU);
34   }
35 };
36 
37 }
38 
39 char CoroSplit::ID = 0;
40 INITIALIZE_PASS(
41     CoroSplit, "coro-split",
42     "Split coroutine into a set of functions driving its state machine", false,
43     false)
44 
45 Pass *llvm::createCoroSplitPass() { return new CoroSplit(); }
46