LLVM 20.0.0git
CoroCloner.h
Go to the documentation of this file.
1//
2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
3// See https://llvm.org/LICENSE.txt for license information.
4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5//
6//===----------------------------------------------------------------------===//
7// Helper class for splitting a coroutine into separate functions. For example
8// the returned-continuation coroutine is split into separate continuation
9// functions.
10//===----------------------------------------------------------------------===//
11
12#ifndef LLVM_LIB_TRANSFORMS_COROUTINES_COROCLONER_H
13#define LLVM_LIB_TRANSFORMS_COROUTINES_COROCLONER_H
14
15#include "llvm/IR/Function.h"
16#include "llvm/IR/IRBuilder.h"
21
22namespace llvm {
23
24namespace coro {
25
26enum class CloneKind {
27 /// The shared resume function for a switch lowering.
29
30 /// The shared unwind function for a switch lowering.
32
33 /// The shared cleanup function for a switch lowering.
35
36 /// An individual continuation function.
38
39 /// An async resume function.
40 Async,
41};
42
44protected:
46 const Twine &Suffix;
51
53 Function *NewF = nullptr;
54 Value *NewFramePtr = nullptr;
55
56 /// The active suspend instruction; meaningful only for continuation and async
57 /// ABIs.
59
60 /// Create a cloner for a continuation lowering.
67 Builder(OrigF.getContext()), TTI(TTI), NewF(NewF),
71 assert(NewF && "need existing function for continuation");
72 assert(ActiveSuspend && "need active suspend point for continuation");
73 }
74
75public:
79 Builder(OrigF.getContext()), TTI(TTI) {}
80
81 virtual ~BaseCloner() {}
82
83 /// Create a clone for a continuation lowering.
90 TimeTraceScope FunctionScope("BaseCloner");
91
93 Cloner.create();
94 return Cloner.getFunction();
95 }
96
98 assert(NewF != nullptr && "declaration not yet set");
99 return NewF;
100 }
101
102 virtual void create();
103
104protected:
106 switch (FKind) {
107 case CloneKind::Async:
110 return false;
113 return true;
114 }
115 llvm_unreachable("Unknown ClonerKind enum");
116 }
117
118 void replaceEntryBlock();
121 void replaceCoroSuspends();
122 void replaceCoroEnds();
124 void salvageDebugInfo();
125 void handleFinalSuspend();
126};
127
128class SwitchCloner : public BaseCloner {
129protected:
130 /// Create a cloner for a switch lowering.
134
135 void create() override;
136
137public:
138 /// Create a clone for a switch lowering.
143 TimeTraceScope FunctionScope("SwitchCloner");
144
146 Cloner.create();
147 return Cloner.getFunction();
148 }
149};
150
151} // end namespace coro
152
153} // end namespace llvm
154
155#endif // LLVM_LIB_TRANSFORMS_COROUTINES_COROCLONER_H
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
Definition: IRBuilder.h:2697
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
The TimeTraceScope is a helper class to call the begin and end functions of the time trace profiler.
Definition: TimeProfiler.h:180
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
LLVM Value Representation.
Definition: Value.h:74
AnyCoroSuspendInst * ActiveSuspend
The active suspend instruction; meaningful only for continuation and async ABIs.
Definition: CoroCloner.h:58
Value * deriveNewFramePointer()
Derive the value of the new frame pointer.
Definition: CoroSplit.cpp:742
TargetTransformInfo & TTI
Definition: CoroCloner.h:50
BaseCloner(Function &OrigF, const Twine &Suffix, coro::Shape &Shape, Function *NewF, AnyCoroSuspendInst *ActiveSuspend, TargetTransformInfo &TTI)
Create a cloner for a continuation lowering.
Definition: CoroCloner.h:61
coro::Shape & Shape
Definition: CoroCloner.h:47
static Function * createClone(Function &OrigF, const Twine &Suffix, coro::Shape &Shape, Function *NewF, AnyCoroSuspendInst *ActiveSuspend, TargetTransformInfo &TTI)
Create a clone for a continuation lowering.
Definition: CoroCloner.h:84
BaseCloner(Function &OrigF, const Twine &Suffix, coro::Shape &Shape, CloneKind FKind, TargetTransformInfo &TTI)
Definition: CoroCloner.h:76
ValueToValueMapTy VMap
Definition: CoroCloner.h:52
bool isSwitchDestroyFunction()
Definition: CoroCloner.h:105
const Twine & Suffix
Definition: CoroCloner.h:46
Function * getFunction() const
Definition: CoroCloner.h:97
void replaceRetconOrAsyncSuspendUses()
Replace uses of the active llvm.coro.suspend.retcon/async call with the arguments to the continuation...
Definition: CoroSplit.cpp:469
virtual void create()
Clone the body of the original function into a resume function of some sort.
Definition: CoroSplit.cpp:866
static Function * createClone(Function &OrigF, const Twine &Suffix, coro::Shape &Shape, CloneKind FKind, TargetTransformInfo &TTI)
Create a clone for a switch lowering.
Definition: CoroCloner.h:139
void create() override
Clone the body of the original function into a resume function of some sort.
Definition: CoroSplit.cpp:1093
SwitchCloner(Function &OrigF, const Twine &Suffix, coro::Shape &Shape, CloneKind FKind, TargetTransformInfo &TTI)
Create a cloner for a switch lowering.
Definition: CoroCloner.h:131
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ Async
The "async continuation" lowering, where each suspend point creates a single continuation function.
@ RetconOnce
The "unique returned-continuation" lowering, where each suspend point creates a single continuation f...
@ Retcon
The "returned-continuation" lowering, where each suspend point creates a single continuation function...
@ Switch
The "resume-switch" lowering, where there are separate resume and destroy functions that are shared b...
@ Async
An async resume function.
@ SwitchCleanup
The shared cleanup function for a switch lowering.
@ SwitchResume
The shared resume function for a switch lowering.
@ SwitchUnwind
The shared unwind function for a switch lowering.
@ Continuation
An individual continuation function.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
coro::ABI ABI
Definition: CoroShape.h:107