2424namespace llvm {
2525
2626template <typename PtrType> class SmallPtrSetImpl ;
27+ class AddrSpaceCastInst ;
2728class AllocaInst ;
2829class BlockFrequency ;
2930class BlockFrequencyInfo ;
@@ -85,10 +86,6 @@ class CodeExtractorAnalysisCache {
8586 // / 3) Add allocas for any scalar outputs, adding all of the outputs' allocas
8687 // / as arguments, and inserting stores to the arguments for any scalars.
8788 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 *)>;
9289 using ValueSet = SetVector<Value *>;
9390
9491 // Various bits of state computed on construction.
@@ -103,6 +100,14 @@ class CodeExtractorAnalysisCache {
103100 // / will be placed in the entry block of the function.
104101 BasicBlock *AllocationBlock;
105102
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+
106111 // / If true, varargs functions can be extracted.
107112 bool AllowVarArgs;
108113
@@ -137,25 +142,6 @@ class CodeExtractorAnalysisCache {
137142 // / space.
138143 bool ArgsInZeroAddressSpace;
139144
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-
159145 public:
160146 // / Create a code extractor for a sequence of blocks.
161147 // /
@@ -169,23 +155,23 @@ class CodeExtractorAnalysisCache {
169155 // / however code extractor won't validate whether extraction is legal.
170156 // / Any new allocations will be placed in the AllocationBlock, unless
171157 // / 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.
173161 // / If ArgsInZeroAddressSpace param is set to true, then the aggregate
174162 // / 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.
178164 LLVM_ABI
179165 CodeExtractor (ArrayRef<BasicBlock *> BBs, DominatorTree *DT = nullptr ,
180166 bool AggregateArgs = false , BlockFrequencyInfo *BFI = nullptr ,
181167 BranchProbabilityInfo *BPI = nullptr ,
182168 AssumptionCache *AC = nullptr , bool AllowVarArgs = false ,
183169 bool AllowAlloca = false ,
184170 BasicBlock *AllocationBlock = nullptr ,
185- std::string Suffix = " " , bool ArgsInZeroAddressSpace = false ,
186- CustomArgAllocatorCBTy *CustomArgAllocatorCB = nullptr ,
187171 BasicBlock *DeallocationBlock = nullptr ,
188- CustomArgDeallocatorCBTy *CustomArgDeallocatorCB = nullptr );
172+ std::string Suffix = " " , bool ArgsInZeroAddressSpace = false );
173+
174+ LLVM_ABI virtual ~CodeExtractor () = default ;
189175
190176 // / Perform the extraction, returning the new function.
191177 // /
@@ -271,6 +257,19 @@ class CodeExtractorAnalysisCache {
271257 // / region, passing it instead as a scalar.
272258 LLVM_ABI void excludeArgFromAggregate (Value *Arg);
273259
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+
274273 private:
275274 struct LifetimeMarkerInfo {
276275 bool SinkLifeStart = false ;
0 commit comments