Skip to content

Commit 0c3720b

Browse files
committed
[Distributed] introduce GenDistributed.h/cpp for code organization
1 parent ac6bee4 commit 0c3720b

File tree

5 files changed

+123
-31
lines changed

5 files changed

+123
-31
lines changed

lib/AST/Builtins.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,20 +1467,13 @@ static ValueDecl *getDistributedActorInitializeRemote(ASTContext &ctx,
14671467
return getBuiltinFunction(ctx, id, _thin,
14681468
_generics(_unrestricted), // TODO(distributed): restrict to DistributedActor
14691469
_parameters(_metatype(_typeparam(0))),
1470-
// _parameters(_nativeObject),
14711470
_rawPointer);
1472-
1473-
// return getBuiltinFunction(ctx, id, _thin,
1474-
// _generics(_unrestricted), // TODO(distributed): restrict to DistributedActor
1475-
// _parameters(_metatype(_typeparam(0))),
1476-
// // _parameters(_nativeObject),
1477-
// _rawPointer);
14781471
}
14791472

14801473
static ValueDecl *getDistributedActorDestroy(ASTContext &ctx,
14811474
Identifier id) {
14821475
return getBuiltinFunction(ctx, id, _thin,
1483-
_parameters(_nativeObject), // TODO: no idea if to pass more here?
1476+
_parameters(_nativeObject),
14841477
_void);
14851478
}
14861479

lib/IRGen/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ add_swift_host_library(swiftIRGen STATIC
1717
GenControl.cpp
1818
GenCoverage.cpp
1919
GenConcurrency.cpp
20+
GenDistributed.cpp
2021
GenDecl.cpp
2122
GenDiffFunc.cpp
2223
GenDiffWitness.cpp

lib/IRGen/GenBuiltin.cpp

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "GenCall.h"
3030
#include "GenCast.h"
3131
#include "GenConcurrency.h"
32+
#include "GenDistributed.h"
3233
#include "GenPointerAuth.h"
3334
#include "GenIntegerLiteral.h"
3435
#include "IRGenFunction.h"
@@ -388,34 +389,14 @@ void irgen::emitBuiltinCall(IRGenFunction &IGF, const BuiltinInfo &Builtin,
388389
}
389390

390391
if (Builtin.ID == BuiltinValueKind::InitializeDistributedRemoteActor) {
391-
auto fn = IGF.IGM.getDistributedActorInitializeRemoteFn();
392-
auto actorTy = args.claimNext();
393-
fprintf(stderr, "[%s:%d] (%s) ARGUMENT ONE\n", __FILE__, __LINE__, __FUNCTION__);
394-
actorTy->dump();
395-
fprintf(stderr, "[%s:%d] (%s) ARGUMENT ONE CAST\n", __FILE__, __LINE__, __FUNCTION__);
396-
actorTy = IGF.Builder.CreateBitCast(actorTy, IGF.IGM.TypeMetadataPtrTy);
397-
actorTy->dump();
398-
auto call = IGF.Builder.CreateCall(fn, { actorTy });
399-
call->setCallingConv(IGF.IGM.SwiftCC);
400-
call->setDoesNotThrow();
401-
fprintf(stderr, "[%s:%d] (%s) CALL\n", __FILE__, __LINE__, __FUNCTION__);
402-
call->dump();
403-
404-
// Cast back to opaque value
405-
// auto result = IGF.Builder.CreateBitCast(call, IGF.IGM.OpaquePtrTy);
406-
// out.add(result);
407-
out.add(call);
408-
392+
auto actorMetatype = args.claimNext();
393+
emitDistributedActorInitializeRemote(IGF, actorMetatype, out);
409394
return;
410395
}
411396

412397
if (Builtin.ID == BuiltinValueKind::DestroyDistributedActor) {
413-
auto fn = IGF.IGM.getDistributedActorDestroyFn();
414398
auto actor = args.claimNext();
415-
actor = IGF.Builder.CreateBitCast(actor, IGF.IGM.RefCountedPtrTy);
416-
auto call = IGF.Builder.CreateCall(fn, {actor});
417-
call->setCallingConv(IGF.IGM.SwiftCC);
418-
call->setDoesNotThrow();
399+
emitDistributedActorDestroy(IGF, actor);
419400
return;
420401
}
421402

lib/IRGen/GenDistributed.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
//===--- GenDistributed.cpp - IRGen for distributed features --------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2020 - 2021 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// This file implements IR generation for distributed features.
14+
//
15+
//===----------------------------------------------------------------------===//
16+
17+
#include "GenDistributed.h"
18+
19+
#include "BitPatternBuilder.h"
20+
#include "ExtraInhabitants.h"
21+
#include "GenProto.h"
22+
#include "GenType.h"
23+
#include "IRGenDebugInfo.h"
24+
#include "IRGenFunction.h"
25+
#include "IRGenModule.h"
26+
#include "LoadableTypeInfo.h"
27+
#include "ScalarPairTypeInfo.h"
28+
#include "swift/AST/ProtocolConformanceRef.h"
29+
#include "swift/ABI/MetadataValues.h"
30+
31+
using namespace swift;
32+
using namespace irgen;
33+
34+
namespace {} // end anonymous namespace
35+
36+
llvm::Value *irgen::emitDistributedActorInitializeRemote(
37+
IRGenFunction &IGF, llvm::Value *actorMetatype, Explosion &out) {
38+
auto fn = IGF.IGM.getDistributedActorInitializeRemoteFn();
39+
actorMetatype =
40+
IGF.Builder.CreateBitCast(actorMetatype, IGF.IGM.TypeMetadataPtrTy);
41+
42+
auto call = IGF.Builder.CreateCall(fn, {actorMetatype});
43+
call->setCallingConv(IGF.IGM.SwiftCC);
44+
call->setDoesNotThrow();
45+
46+
out.add(call);
47+
48+
return call;
49+
}
50+
51+
void irgen::emitDistributedActorDestroy(IRGenFunction &IGF,
52+
llvm::Value *actor) {
53+
auto fn = IGF.IGM.getDistributedActorDestroyFn();
54+
actor = IGF.Builder.CreateBitCast(actor, IGF.IGM.RefCountedPtrTy);
55+
56+
auto call = IGF.Builder.CreateCall(fn, {actor});
57+
call->setCallingConv(IGF.IGM.SwiftCC);
58+
call->setDoesNotThrow();
59+
}

lib/IRGen/GenDistributed.h

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
//===--- GenDistributed.h - IRGen for distributed features ------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2020 - 2021 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// This file defines interfaces for emitting code for various distributed
14+
// features.
15+
//
16+
//===----------------------------------------------------------------------===//
17+
18+
#ifndef SWIFT_IRGEN_GENDISTRIBUTED_H
19+
#define SWIFT_IRGEN_GENDISTRIBUTED_H
20+
21+
#include "swift/AST/Types.h"
22+
#include "swift/Basic/LLVM.h"
23+
#include "swift/SIL/ApplySite.h"
24+
#include "llvm/IR/CallingConv.h"
25+
26+
#include "Callee.h"
27+
#include "GenHeap.h"
28+
#include "IRGenModule.h"
29+
30+
namespace llvm {
31+
class Value;
32+
}
33+
34+
namespace swift {
35+
class CanType;
36+
class ProtocolConformanceRef;
37+
class SILType;
38+
39+
namespace irgen {
40+
class Explosion;
41+
class IRGenFunction;
42+
43+
/// Emit the '_distributedActorRemoteInitialize' call.
44+
llvm::Value *emitDistributedActorInitializeRemote(
45+
IRGenFunction &IGF,
46+
llvm::Value *actorMetatype,
47+
Explosion &out);
48+
49+
/// Destroy the distributed actor.
50+
/// E.g. a remote actor has to be destroyed differently from a local one.
51+
void emitDistributedActorDestroy(
52+
IRGenFunction &IGF,
53+
llvm::Value *actor);
54+
55+
} // end namespace irgen
56+
} // end namespace swift
57+
58+
#endif

0 commit comments

Comments
 (0)