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, 28 const std::initializer_list<StringRef>); 29 void replaceCoroFree(CoroIdInst *CoroId, bool Elide); 30 31 /// Replaces all @llvm.coro.alloc intrinsics calls associated with a given 32 /// call @llvm.coro.id instruction with boolean value false. 33 void suppressCoroAllocs(CoroIdInst *CoroId); 34 /// Replaces CoroAllocs with boolean value false. 35 void suppressCoroAllocs(LLVMContext &Context, 36 ArrayRef<CoroAllocInst *> CoroAllocs); 37 38 /// Attempts to rewrite the location operand of debug intrinsics in terms of 39 /// the coroutine frame pointer, folding pointer offsets into the DIExpression 40 /// of the intrinsic. 41 /// If the frame pointer is an Argument, store it into an alloca to enhance the 42 /// debugability. 43 void salvageDebugInfo( 44 SmallDenseMap<Argument *, AllocaInst *, 4> &ArgToAllocaMap, 45 DbgVariableIntrinsic &DVI, bool IsEntryPoint); 46 void salvageDebugInfo( 47 SmallDenseMap<Argument *, AllocaInst *, 4> &ArgToAllocaMap, 48 DbgVariableRecord &DVR, bool UseEntryValue); 49 50 // Keeps data and helper functions for lowering coroutine intrinsics. 51 struct LowererBase { 52 Module &TheModule; 53 LLVMContext &Context; 54 PointerType *const Int8Ptr; 55 FunctionType *const ResumeFnType; 56 ConstantPointerNull *const NullPtr; 57 58 LowererBase(Module &M); 59 CallInst *makeSubFnCall(Value *Arg, int Index, Instruction *InsertPt); 60 }; 61 62 bool defaultMaterializable(Instruction &V); 63 void normalizeCoroutine(Function &F, coro::Shape &Shape, 64 TargetTransformInfo &TTI); 65 CallInst *createMustTailCall(DebugLoc Loc, Function *MustTailCallFn, 66 TargetTransformInfo &TTI, 67 ArrayRef<Value *> Arguments, IRBuilder<> &); 68 } // End namespace coro. 69 } // End namespace llvm 70 71 #endif 72