20#define DEBUG_TYPE "coro-cleanup"
26 Lowerer(
Module &M) : LowererBase(M), Builder(Context) {}
37 {Builder.getPtrTy(), Builder.getPtrTy()});
47 bool IsPrivateAndUnprocessed =
F.isPresplitCoroutine() &&
F.hasLocalLinkage();
51 if (
auto *
II = dyn_cast<IntrinsicInst>(&
I)) {
52 switch (
II->getIntrinsicID()) {
55 case Intrinsic::coro_begin:
56 II->replaceAllUsesWith(
II->getArgOperand(1));
58 case Intrinsic::coro_free:
59 II->replaceAllUsesWith(
II->getArgOperand(1));
61 case Intrinsic::coro_alloc:
64 case Intrinsic::coro_async_resume:
65 II->replaceAllUsesWith(
68 case Intrinsic::coro_id:
69 case Intrinsic::coro_id_retcon:
70 case Intrinsic::coro_id_retcon_once:
71 case Intrinsic::coro_id_async:
74 case Intrinsic::coro_subfn_addr:
77 case Intrinsic::coro_end:
78 case Intrinsic::coro_suspend_retcon:
79 if (IsPrivateAndUnprocessed) {
84 case Intrinsic::coro_async_size_replace:
85 auto *
Target = cast<ConstantStruct>(
86 cast<GlobalVariable>(
II->getArgOperand(0)->stripPointerCasts())
88 auto *
Source = cast<ConstantStruct>(
89 cast<GlobalVariable>(
II->getArgOperand(1)->stripPointerCasts())
91 auto *TargetSize =
Target->getOperand(1);
92 auto *SourceSize =
Source->getOperand(1);
93 if (TargetSize->isElementWiseEqual(SourceSize)) {
96 auto *TargetRelativeFunOffset =
Target->getOperand(0);
98 Target->getType(), TargetRelativeFunOffset, SourceSize);
99 Target->replaceAllUsesWith(NewFuncPtrStruct);
102 II->eraseFromParent();
112 M, {
"llvm.coro.alloc",
"llvm.coro.begin",
"llvm.coro.subfn.addr",
113 "llvm.coro.free",
"llvm.coro.id",
"llvm.coro.id.retcon",
114 "llvm.coro.id.async",
"llvm.coro.id.retcon.once",
115 "llvm.coro.async.size.replace",
"llvm.coro.async.resume"});
Expand Atomic instructions
static bool declaresCoroCleanupIntrinsics(const Module &M)
static void lowerSubFn(IRBuilder<> &Builder, CoroSubFnInst *SubFn)
Module.h This file contains the declarations for the Module class.
uint64_t IntrinsicInst * II
FunctionAnalysisManager FAM
ModuleAnalysisManager MAM
This header defines various interfaces for pass management in LLVM.
This file provides the interface for the pass responsible for both simplifying and canonicalizing the...
static const unsigned FramePtr
A container for analyses that lazily runs them and caches their results.
void invalidate(IRUnitT &IR, const PreservedAnalyses &PA)
Invalidate cached analyses for an IR unit.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Represents analyses that only rely on functions' control flow.
static ConstantInt * getTrue(LLVMContext &Context)
static ConstantPointerNull * get(PointerType *T)
Static factory methods - Return objects of the specified value.
static Constant * get(StructType *T, ArrayRef< Constant * > V)
static ConstantTokenNone * get(LLVMContext &Context)
Return the ConstantTokenNone.
This class represents the llvm.coro.subfn.addr instruction.
ResumeKind getIndex() const
LoadInst * CreateLoad(Type *Ty, Value *Ptr, const char *Name)
Provided to resolve 'CreateLoad(Ty, Ptr, "...")' correctly, instead of converting the string to 'bool...
Value * CreateConstInBoundsGEP2_32(Type *Ty, Value *Ptr, unsigned Idx0, unsigned Idx1, const Twine &Name="")
void SetInsertPoint(BasicBlock *TheBB)
This specifies that created instructions should be appended to the end of the specified block.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
An analysis over an "outer" IR unit that provides access to an analysis manager over an "inner" IR un...
A Module instance is used to store all the information related to an LLVM module.
LLVM_ATTRIBUTE_MINSIZE std::enable_if_t<!std::is_same_v< PassT, PassManager > > addPass(PassT &&Pass)
PreservedAnalyses run(IRUnitT &IR, AnalysisManagerT &AM, ExtraArgTs... ExtraArgs)
Run all of the passes in this manager over the given unit of IR.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
void preserveSet()
Mark an analysis set as preserved.
A pass to simplify and canonicalize the CFG of a function.
static StructType * get(LLVMContext &Context, ArrayRef< Type * > Elements, bool isPacked=false)
This static method is the primary way to create a literal StructType.
Target - Wrapper for Target specific information.
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
LLVM Value Representation.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
LLVMContext & getContext() const
All values hold a context through their type.
bool declaresIntrinsics(const Module &M, const std::initializer_list< StringRef >)
This is an optimization pass for GlobalISel generic memory operations.
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM)