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/Support/Compiler.h" 22 #include "llvm/Transforms/Coroutines/ABI.h" 23 24 namespace llvm { 25 26 namespace coro { 27 class BaseABI; 28 struct Shape; 29 } // namespace coro 30 31 struct CoroSplitPass : PassInfoMixin<CoroSplitPass> { 32 using BaseABITy = 33 std::function<std::unique_ptr<coro::BaseABI>(Function &, coro::Shape &)>; 34 35 LLVM_ABI CoroSplitPass(bool OptimizeFrame = false); 36 37 LLVM_ABI CoroSplitPass(SmallVector<BaseABITy> GenCustomABIs, 38 bool OptimizeFrame = false); 39 40 LLVM_ABI 41 CoroSplitPass(std::function<bool(Instruction &)> MaterializableCallback, 42 bool OptimizeFrame = false); 43 44 LLVM_ABI 45 CoroSplitPass(std::function<bool(Instruction &)> MaterializableCallback, 46 SmallVector<BaseABITy> GenCustomABIs, 47 bool OptimizeFrame = false); 48 49 LLVM_ABI PreservedAnalyses run(LazyCallGraph::SCC &C, 50 CGSCCAnalysisManager &AM, LazyCallGraph &CG, 51 CGSCCUpdateResult &UR); 52 isRequiredCoroSplitPass53 static bool isRequired() { return true; } 54 55 // Generator for an ABI transformer 56 BaseABITy CreateAndInitABI; 57 58 // Would be true if the Optimization level isn't O0. 59 bool OptimizeFrame; 60 }; 61 } // end namespace llvm 62 63 #endif // LLVM_TRANSFORMS_COROUTINES_COROSPLIT_H 64