Skip to content

Commit 05f259f

Browse files
committed
[NFC] IRGen: Extract this function.
1 parent 69a40d5 commit 05f259f

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

lib/IRGen/GenCoro.cpp

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,23 +1002,21 @@ llvm::Constant *swift::irgen::getCoroDeallocFrameFn(IRGenModule &IGM) {
10021002
return getCoroDeallocFn(AllocationKind::Frame, IGM);
10031003
}
10041004

1005-
using GetAllocatorFunctionPointer = FunctionPointer (IRGenModule::*)();
1006-
1007-
static llvm::Constant *
1008-
getAddrOfSwiftCoroAllocatorThunk(StringRef name, Allocator::Field field,
1009-
GetAllocatorFunctionPointer getCator,
1010-
IRGenModule &IGM) {
1005+
static llvm::Constant *getAddrOfSwiftCoroAllocatorThunk(
1006+
StringRef name, Allocator::Field field, IRGenModule &IGM,
1007+
llvm::function_ref<llvm::Value *(IRGenFunction &, llvm::Value *,
1008+
llvm::Value *, llvm::Value *)>
1009+
builder) {
10111010
auto *ty = field.getFunctionType(IGM);
10121011
return IGM.getOrCreateHelperFunction(
10131012
name, ty->getReturnType(), ty->params(),
1014-
[getCator, ty](IRGenFunction &IGF) {
1013+
[builder, ty](IRGenFunction &IGF) {
10151014
auto parameters = IGF.collectParameters();
1016-
parameters.claimNext(); // frame
1017-
parameters.claimNext(); // allocator
1018-
// allocator - size; deallocator - address
1015+
auto *frame = parameters.claimNext();
1016+
auto *allocator = parameters.claimNext();
1017+
// allocate - size; deallocate - address
10191018
auto *value = parameters.claimNext();
1020-
auto alloc = (IGF.IGM.*getCator)();
1021-
auto *result = IGF.Builder.CreateCall(alloc, {value});
1019+
auto *result = builder(IGF, frame, allocator, value);
10221020
if (!ty->getReturnType()->isVoidTy()) {
10231021
IGF.Builder.CreateRet(result);
10241022
} else {
@@ -1035,6 +1033,22 @@ getAddrOfSwiftCoroAllocatorThunk(StringRef name, Allocator::Field field,
10351033
});
10361034
}
10371035

1036+
using GetAllocatorFunctionPointer = FunctionPointer (IRGenModule::*)();
1037+
1038+
static llvm::Constant *
1039+
getAddrOfSwiftCoroAllocatorThunk(StringRef name, Allocator::Field field,
1040+
GetAllocatorFunctionPointer getCator,
1041+
IRGenModule &IGM) {
1042+
return getAddrOfSwiftCoroAllocatorThunk(
1043+
name, field, IGM,
1044+
[getCator](IRGenFunction &IGF, auto *frame, auto *allocator,
1045+
auto *value) {
1046+
auto alloc = (IGF.IGM.*getCator)();
1047+
auto *call = IGF.Builder.CreateCall(alloc, {value});
1048+
return call;
1049+
});
1050+
}
1051+
10381052
static llvm::Constant *getAddrOfGlobalCoroAllocator(
10391053
IRGenModule &IGM, CoroAllocatorKind kind, bool shouldDeallocateImmediately,
10401054
llvm::Constant *allocFn, llvm::Constant *deallocFn,

0 commit comments

Comments
 (0)