24
24
namespace llvm {
25
25
26
26
template <typename PtrType> class SmallPtrSetImpl ;
27
+ class AddrSpaceCastInst ;
27
28
class AllocaInst ;
28
29
class BlockFrequency ;
29
30
class BlockFrequencyInfo ;
@@ -85,10 +86,6 @@ class CodeExtractorAnalysisCache {
85
86
// / 3) Add allocas for any scalar outputs, adding all of the outputs' allocas
86
87
// / as arguments, and inserting stores to the arguments for any scalars.
87
88
class CodeExtractor {
88
- using CustomArgAllocatorCBTy = std::function<Instruction *(
89
- BasicBlock *, BasicBlock::iterator, Type *, const Twine &)>;
90
- using CustomArgDeallocatorCBTy = std::function<Instruction *(
91
- BasicBlock *, BasicBlock::iterator, Value *, Type *)>;
92
89
using ValueSet = SetVector<Value *>;
93
90
94
91
// Various bits of state computed on construction.
@@ -103,6 +100,14 @@ class CodeExtractorAnalysisCache {
103
100
// / will be placed in the entry block of the function.
104
101
BasicBlock *AllocationBlock;
105
102
103
+ // / A block outside of the extraction set where deallocations for
104
+ // / intermediate allocations can be placed inside. Not used for
105
+ // / automatically deallocated memory (e.g. `alloca`), which is the default.
106
+ // /
107
+ // / If it is null and needed, the end of the replacement basic block will be
108
+ // / used to place deallocations.
109
+ BasicBlock *DeallocationBlock;
110
+
106
111
// / If true, varargs functions can be extracted.
107
112
bool AllowVarArgs;
108
113
@@ -137,25 +142,6 @@ class CodeExtractorAnalysisCache {
137
142
// / space.
138
143
bool ArgsInZeroAddressSpace;
139
144
140
- // / If set, this callback will be used to allocate the arguments in the
141
- // / caller before passing it to the outlined function holding the extracted
142
- // / piece of code.
143
- CustomArgAllocatorCBTy *CustomArgAllocatorCB;
144
-
145
- // / A block outside of the extraction set where previously introduced
146
- // / intermediate allocations can be deallocated. This is only used when a
147
- // / custom deallocator is specified.
148
- BasicBlock *DeallocationBlock;
149
-
150
- // / If set, this callback will be used to deallocate the arguments in the
151
- // / caller after running the outlined function holding the extracted piece
152
- // / of code. It will not be called if a custom allocator isn't also present.
153
- // /
154
- // / By default, this will be done at the end of the basic block containing
155
- // / the call to the outlined function, except if a deallocation block is
156
- // / specified. In that case, that will take precedence.
157
- CustomArgDeallocatorCBTy *CustomArgDeallocatorCB;
158
-
159
145
public:
160
146
// / Create a code extractor for a sequence of blocks.
161
147
// /
@@ -169,23 +155,23 @@ class CodeExtractorAnalysisCache {
169
155
// / however code extractor won't validate whether extraction is legal.
170
156
// / Any new allocations will be placed in the AllocationBlock, unless
171
157
// / it is null, in which case it will be placed in the entry block of
172
- // / the function from which the code is being extracted.
158
+ // / the function from which the code is being extracted. Explicit
159
+ // / deallocations for the aforementioned allocations will be placed in the
160
+ // / DeallocationBlock or the end of the replacement block, if needed.
173
161
// / If ArgsInZeroAddressSpace param is set to true, then the aggregate
174
162
// / param pointer of the outlined function is declared in zero address
175
- // / space. If a CustomArgAllocatorCB callback is specified, it will be used
176
- // / to allocate any structures or variable copies needed to pass arguments
177
- // / to the outlined function, rather than using regular allocas.
163
+ // / space.
178
164
LLVM_ABI
179
165
CodeExtractor (ArrayRef<BasicBlock *> BBs, DominatorTree *DT = nullptr ,
180
166
bool AggregateArgs = false , BlockFrequencyInfo *BFI = nullptr ,
181
167
BranchProbabilityInfo *BPI = nullptr ,
182
168
AssumptionCache *AC = nullptr , bool AllowVarArgs = false ,
183
169
bool AllowAlloca = false ,
184
170
BasicBlock *AllocationBlock = nullptr ,
185
- std::string Suffix = " " , bool ArgsInZeroAddressSpace = false ,
186
- CustomArgAllocatorCBTy *CustomArgAllocatorCB = nullptr ,
187
171
BasicBlock *DeallocationBlock = nullptr ,
188
- CustomArgDeallocatorCBTy *CustomArgDeallocatorCB = nullptr );
172
+ std::string Suffix = " " , bool ArgsInZeroAddressSpace = false );
173
+
174
+ LLVM_ABI virtual ~CodeExtractor () = default ;
189
175
190
176
// / Perform the extraction, returning the new function.
191
177
// /
@@ -271,6 +257,19 @@ class CodeExtractorAnalysisCache {
271
257
// / region, passing it instead as a scalar.
272
258
LLVM_ABI void excludeArgFromAggregate (Value *Arg);
273
259
260
+ protected:
261
+ // / Allocate an intermediate variable at the specified point.
262
+ LLVM_ABI virtual Instruction *
263
+ allocateVar (BasicBlock *BB, BasicBlock::iterator AllocIP, Type *VarType,
264
+ const Twine &Name = Twine(" " ),
265
+ AddrSpaceCastInst **CastedAlloc = nullptr );
266
+
267
+ // / Deallocate a previously-allocated intermediate variable at the specified
268
+ // / point.
269
+ LLVM_ABI virtual Instruction *deallocateVar (BasicBlock *BB,
270
+ BasicBlock::iterator DeallocIP,
271
+ Value *Var, Type *VarType);
272
+
274
273
private:
275
274
struct LifetimeMarkerInfo {
276
275
bool SinkLifeStart = false ;
0 commit comments