17
17
// /
18
18
// / Swift's closure model is that all local variables are capture by reference.
19
19
// / This produces a very simple programming model which is great to use, but
20
- // / relies on the optimizer to promote by-ref captures to by-value (i.e. by-copy)
21
- // / captures for decent performance. Consider this simple example:
20
+ // / relies on the optimizer to promote by-ref captures to by-value (i.e.
21
+ // / by-copy) captures for decent performance. Consider this simple example:
22
22
// /
23
23
// / func foo(a : () -> ()) {} // assume this has an unknown body
24
24
// /
30
30
// /
31
31
// / Since x is captured by-ref by the closure, x must live on the heap. By
32
32
// / looking at bar without any knowledge of foo, we can know that it is safe to
33
- // / promote this to a by-value capture, allowing x to live on the stack under the
34
- // / following conditions:
33
+ // / promote this to a by-value capture, allowing x to live on the stack under
34
+ // / the following conditions:
35
35
// /
36
36
// / 1. If x is not modified in the closure body and is only loaded.
37
37
// / 2. If we can prove that all mutations to x occur before the closure is
38
38
// / formed.
39
39
// /
40
- // / Under these conditions if x is loadable then we can even load the given value
41
- // / and pass it as a scalar instead of an address.
40
+ // / Under these conditions if x is loadable then we can even load the given
41
+ // / value and pass it as a scalar instead of an address.
42
42
// /
43
43
// ===----------------------------------------------------------------------===//
44
44
45
45
#define DEBUG_TYPE " sil-capture-promotion"
46
46
#include " swift/AST/GenericEnvironment.h"
47
47
#include " swift/SIL/SILCloner.h"
48
- #include " swift/SILOptimizer/Utils/SILOptFunctionBuilder.h"
49
48
#include " swift/SIL/TypeSubstCloner.h"
50
49
#include " swift/SILOptimizer/PassManager/Passes.h"
51
50
#include " swift/SILOptimizer/PassManager/Transforms.h"
51
+ #include " swift/SILOptimizer/Utils/SILOptFunctionBuilder.h"
52
52
#include " swift/SILOptimizer/Utils/SpecializationMangler.h"
53
53
#include " llvm/ADT/BitVector.h"
54
54
#include " llvm/ADT/SmallSet.h"
@@ -365,8 +365,8 @@ computeNewArgInterfaceTypes(SILFunction *f, IndicesSet &promotableIndices,
365
365
param.getSILStorageType (fnConv.silConv .getModule (), fnConv.funcTy ,
366
366
TypeExpansionContext::minimal ());
367
367
auto paramBoxTy = paramTy.castTo <SILBoxType>();
368
- assert (paramBoxTy->getLayout ()->getFields ().size () == 1
369
- && " promoting compound box not implemented yet" );
368
+ assert (paramBoxTy->getLayout ()->getFields ().size () == 1 &&
369
+ " promoting compound box not implemented yet" );
370
370
auto paramBoxedTy =
371
371
getSILBoxFieldType (TypeExpansionContext (*f), paramBoxTy, types, 0 );
372
372
assert (expansion == f->getResilienceExpansion ());
@@ -452,8 +452,7 @@ ClosureCloner::initCloned(SILOptFunctionBuilder &functionBuilder,
452
452
453
453
// / Populate the body of the cloned closure, modifying instructions as
454
454
// / necessary to take into consideration the promoted capture(s)
455
- void
456
- ClosureCloner::populateCloned () {
455
+ void ClosureCloner::populateCloned () {
457
456
SILFunction *cloned = getCloned ();
458
457
459
458
// Create arguments for the entry block
@@ -868,10 +867,10 @@ class NonEscapingUserVisitor
868
867
// / the old behavior of non-top-level uses not being able to have partial
869
868
// / apply and project box uses.
870
869
struct detail {
871
- enum IsMutating_t {
872
- IsNotMutating = 0 ,
873
- IsMutating = 1 ,
874
- };
870
+ enum IsMutating_t {
871
+ IsNotMutating = 0 ,
872
+ IsMutating = 1 ,
873
+ };
875
874
};
876
875
#define RECURSIVE_INST_VISITOR (MUTATING, INST ) \
877
876
bool visit##INST##Inst(INST##Inst *i) { \
@@ -898,7 +897,7 @@ class NonEscapingUserVisitor
898
897
// begin_access may signify a modification, but is considered nonmutating
899
898
// because we will peek though it's uses to find the actual mutation.
900
899
RECURSIVE_INST_VISITOR (IsNotMutating, BeginAccess)
901
- RECURSIVE_INST_VISITOR (IsMutating , UncheckedTakeEnumDataAddr)
900
+ RECURSIVE_INST_VISITOR (IsMutating, UncheckedTakeEnumDataAddr)
902
901
#undef RECURSIVE_INST_VISITOR
903
902
904
903
bool visitCopyAddrInst (CopyAddrInst *cai) {
0 commit comments