xref: /llvm-project/llvm/include/llvm/Transforms/Coroutines/CoroSplit.h (revision 3737a5321901574b3f4b2cf0d798faea5c4a2302)
1 //===- CoroSplit.h - Converts a coroutine into a state machine -*- C++ -*--===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // \file
10 // This file declares the pass that builds the coroutine frame and outlines
11 // the resume and destroy parts of the coroutine into separate functions.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef LLVM_TRANSFORMS_COROUTINES_COROSPLIT_H
16 #define LLVM_TRANSFORMS_COROUTINES_COROSPLIT_H
17 
18 #include "llvm/Analysis/CGSCCPassManager.h"
19 #include "llvm/Analysis/LazyCallGraph.h"
20 #include "llvm/IR/PassManager.h"
21 #include "llvm/Transforms/Coroutines/ABI.h"
22 
23 namespace llvm {
24 
25 namespace coro {
26 class BaseABI;
27 struct Shape;
28 } // namespace coro
29 
30 struct CoroSplitPass : PassInfoMixin<CoroSplitPass> {
31   using BaseABITy =
32       std::function<std::unique_ptr<coro::BaseABI>(Function &, coro::Shape &)>;
33 
34   CoroSplitPass(bool OptimizeFrame = false);
35 
36   CoroSplitPass(SmallVector<BaseABITy> GenCustomABIs,
37                 bool OptimizeFrame = false);
38 
39   CoroSplitPass(std::function<bool(Instruction &)> MaterializableCallback,
40                 bool OptimizeFrame = false);
41 
42   CoroSplitPass(std::function<bool(Instruction &)> MaterializableCallback,
43                 SmallVector<BaseABITy> GenCustomABIs,
44                 bool OptimizeFrame = false);
45 
46   PreservedAnalyses run(LazyCallGraph::SCC &C, CGSCCAnalysisManager &AM,
47                         LazyCallGraph &CG, CGSCCUpdateResult &UR);
48 
49   static bool isRequired() { return true; }
50 
51   // Generator for an ABI transformer
52   BaseABITy CreateAndInitABI;
53 
54   // Would be true if the Optimization level isn't O0.
55   bool OptimizeFrame;
56 };
57 } // end namespace llvm
58 
59 #endif // LLVM_TRANSFORMS_COROUTINES_COROSPLIT_H
60