1 | //===- CoroInternal.h - Internal Coroutine interfaces ---------*- 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 | // Common definitions/declarations used internally by coroutine lowering passes. |
9 | //===----------------------------------------------------------------------===// |
10 | |
11 | #ifndef LLVM_LIB_TRANSFORMS_COROUTINES_COROINTERNAL_H |
12 | #define LLVM_LIB_TRANSFORMS_COROUTINES_COROINTERNAL_H |
13 | |
14 | #include "llvm/Analysis/TargetTransformInfo.h" |
15 | #include "llvm/IR/IRBuilder.h" |
16 | #include "llvm/Transforms/Coroutines/CoroInstr.h" |
17 | #include "llvm/Transforms/Coroutines/CoroShape.h" |
18 | |
19 | namespace llvm { |
20 | |
21 | class CallGraph; |
22 | |
23 | namespace coro { |
24 | |
25 | bool isSuspendBlock(BasicBlock *BB); |
26 | bool declaresAnyIntrinsic(const Module &M); |
27 | bool declaresIntrinsics(const Module &M, ArrayRef<Intrinsic::ID> List); |
28 | void replaceCoroFree(CoroIdInst *CoroId, bool Elide); |
29 | |
30 | /// Replaces all @llvm.coro.alloc intrinsics calls associated with a given |
31 | /// call @llvm.coro.id instruction with boolean value false. |
32 | void suppressCoroAllocs(CoroIdInst *CoroId); |
33 | /// Replaces CoroAllocs with boolean value false. |
34 | void suppressCoroAllocs(LLVMContext &Context, |
35 | ArrayRef<CoroAllocInst *> CoroAllocs); |
36 | |
37 | /// Attempts to rewrite the location operand of debug intrinsics in terms of |
38 | /// the coroutine frame pointer, folding pointer offsets into the DIExpression |
39 | /// of the intrinsic. |
40 | /// If the frame pointer is an Argument, store it into an alloca to enhance the |
41 | /// debugability. |
42 | void salvageDebugInfo( |
43 | SmallDenseMap<Argument *, AllocaInst *, 4> &ArgToAllocaMap, |
44 | DbgVariableIntrinsic &DVI, bool IsEntryPoint); |
45 | void salvageDebugInfo( |
46 | SmallDenseMap<Argument *, AllocaInst *, 4> &ArgToAllocaMap, |
47 | DbgVariableRecord &DVR, bool UseEntryValue); |
48 | |
49 | // Keeps data and helper functions for lowering coroutine intrinsics. |
50 | struct LowererBase { |
51 | Module &TheModule; |
52 | LLVMContext &Context; |
53 | PointerType *const Int8Ptr; |
54 | FunctionType *const ResumeFnType; |
55 | ConstantPointerNull *const NullPtr; |
56 | |
57 | LowererBase(Module &M); |
58 | CallInst *makeSubFnCall(Value *Arg, int Index, Instruction *InsertPt); |
59 | }; |
60 | |
61 | bool defaultMaterializable(Instruction &V); |
62 | void normalizeCoroutine(Function &F, coro::Shape &Shape, |
63 | TargetTransformInfo &TTI); |
64 | CallInst *createMustTailCall(DebugLoc Loc, Function *MustTailCallFn, |
65 | TargetTransformInfo &TTI, |
66 | ArrayRef<Value *> Arguments, IRBuilder<> &); |
67 | } // End namespace coro. |
68 | } // End namespace llvm |
69 | |
70 | #endif |
71 | |