Skip to content

Commit 0060859

Browse files
committed
[Distributed] IRGen: Don't allocate offset pointer if there is nothing to load
If underlying function does not have any parameter, then let's exit early and avoid stack allocating the argument buffer cursor.
1 parent a831017 commit 0060859

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

lib/IRGen/GenDistributed.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,15 +172,20 @@ void DistributedAccessor::computeArguments(llvm::Value *argumentBuffer,
172172
Explosion &arguments) {
173173
auto fnType = Method->getLoweredFunctionType();
174174

175+
// Cover all of the arguments except to `self` of the actor.
176+
auto parameters = fnType->getParameters().drop_back();
177+
178+
// If there are no parameters to extract, we are done.
179+
if (parameters.empty())
180+
return;
181+
175182
auto offset =
176183
IGF.createAlloca(IGM.Int8PtrTy, IGM.getPointerAlignment(), "offset");
177184
IGF.Builder.CreateLifetimeStart(offset, IGM.getPointerSize());
178185

179186
// Initialize "offset" with the address of the base of the argument buffer.
180187
IGF.Builder.CreateStore(argumentBuffer, offset);
181188

182-
// Cover all of the arguments except to `self` of the actor.
183-
auto parameters = fnType->getParameters().drop_back();
184189
for (const auto &param : parameters) {
185190
auto paramTy = param.getSILStorageInterfaceType();
186191
const TypeInfo &typeInfo = IGF.getTypeInfo(paramTy);

test/IRGen/distributed_actor_accessors.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,3 +341,17 @@ public distributed actor MyOtherActor {
341341
/// RESULT is returned indirectly so there is nothing to pass to `end`
342342

343343
// CHECK: {{.*}} = call i1 (i8*, i1, ...) @llvm.coro.end.async({{.*}}, %swift.context* {{.*}}, %swift.error* {{.*}})
344+
345+
/// ---> Thunk and distributed method for `MyOtherActor.empty`
346+
347+
/// Let's check that there is no offset allocation here since parameter list is empty
348+
349+
// CHECK: define internal swifttailcc void @"$s27distributed_actor_accessors12MyOtherActorC5emptyyyFTETF"
350+
// CHECK-NEXT: entry:
351+
// CHECK-NEXT: {{.*}} = alloca %swift.context*, align 8
352+
// CHECK-NEXT: %swifterror = alloca swifterror %swift.error*, align 8
353+
// CHECK-NEXT: {{.*}} = call token @llvm.coro.id.async(i32 20, i32 16, i32 0, i8* bitcast (%swift.async_func_pointer* @"$s27distributed_actor_accessors12MyOtherActorC5emptyyyFTETFTu" to i8*))
354+
// CHECK-NEXT: {{.*}} = call i8* @llvm.coro.begin(token %4, i8* null)
355+
// CHECK-NEXT: store %swift.context* {{.*}}, %swift.context** {{.*}}, align 8
356+
// CHECK-NEXT: store %swift.error* null, %swift.error** %swifterror, align 8
357+
// CHECK-NEXT: {{.*}} = load i32, i32* getelementptr inbounds (%swift.async_func_pointer, %swift.async_func_pointer* bitcast (void (%swift.context*, %T27distributed_actor_accessors12MyOtherActorC*)* @"$s27distributed_actor_accessors12MyOtherActorC5emptyyyFTE" to %swift.async_func_pointer*), i32 0, i32 0), align 8

0 commit comments

Comments
 (0)