Skip to content

Commit ff8845e

Browse files
committed
[capture-promotion] Move to ./lib/SILOptimizer/{IPO,Mandatory}.
1 parent 23d6312 commit ff8845e

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

lib/SILOptimizer/IPO/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
target_sources(swiftSILOptimizer PRIVATE
2-
CapturePromotion.cpp
32
CapturePropagation.cpp
43
ClosureSpecializer.cpp
54
CrossModuleSerializationSetup.cpp

lib/SILOptimizer/Mandatory/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ target_sources(swiftSILOptimizer PRIVATE
22
AccessEnforcementSelection.cpp
33
AccessMarkerElimination.cpp
44
AddressLowering.cpp
5+
CapturePromotion.cpp
56
ClosureLifetimeFixup.cpp
67
ConstantPropagation.cpp
78
DefiniteInitialization.cpp

lib/SILOptimizer/IPO/CapturePromotion.cpp renamed to lib/SILOptimizer/Mandatory/CapturePromotion.cpp

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
///
1818
/// Swift's closure model is that all local variables are capture by reference.
1919
/// 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:
2222
///
2323
/// func foo(a : () -> ()) {} // assume this has an unknown body
2424
///
@@ -30,25 +30,25 @@
3030
///
3131
/// Since x is captured by-ref by the closure, x must live on the heap. By
3232
/// 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:
3535
///
3636
/// 1. If x is not modified in the closure body and is only loaded.
3737
/// 2. If we can prove that all mutations to x occur before the closure is
3838
/// formed.
3939
///
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.
4242
///
4343
//===----------------------------------------------------------------------===//
4444

4545
#define DEBUG_TYPE "sil-capture-promotion"
4646
#include "swift/AST/GenericEnvironment.h"
4747
#include "swift/SIL/SILCloner.h"
48-
#include "swift/SILOptimizer/Utils/SILOptFunctionBuilder.h"
4948
#include "swift/SIL/TypeSubstCloner.h"
5049
#include "swift/SILOptimizer/PassManager/Passes.h"
5150
#include "swift/SILOptimizer/PassManager/Transforms.h"
51+
#include "swift/SILOptimizer/Utils/SILOptFunctionBuilder.h"
5252
#include "swift/SILOptimizer/Utils/SpecializationMangler.h"
5353
#include "llvm/ADT/BitVector.h"
5454
#include "llvm/ADT/SmallSet.h"
@@ -365,8 +365,8 @@ computeNewArgInterfaceTypes(SILFunction *f, IndicesSet &promotableIndices,
365365
param.getSILStorageType(fnConv.silConv.getModule(), fnConv.funcTy,
366366
TypeExpansionContext::minimal());
367367
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");
370370
auto paramBoxedTy =
371371
getSILBoxFieldType(TypeExpansionContext(*f), paramBoxTy, types, 0);
372372
assert(expansion == f->getResilienceExpansion());
@@ -452,8 +452,7 @@ ClosureCloner::initCloned(SILOptFunctionBuilder &functionBuilder,
452452

453453
/// Populate the body of the cloned closure, modifying instructions as
454454
/// necessary to take into consideration the promoted capture(s)
455-
void
456-
ClosureCloner::populateCloned() {
455+
void ClosureCloner::populateCloned() {
457456
SILFunction *cloned = getCloned();
458457

459458
// Create arguments for the entry block
@@ -868,10 +867,10 @@ class NonEscapingUserVisitor
868867
/// the old behavior of non-top-level uses not being able to have partial
869868
/// apply and project box uses.
870869
struct detail {
871-
enum IsMutating_t {
872-
IsNotMutating = 0,
873-
IsMutating = 1,
874-
};
870+
enum IsMutating_t {
871+
IsNotMutating = 0,
872+
IsMutating = 1,
873+
};
875874
};
876875
#define RECURSIVE_INST_VISITOR(MUTATING, INST) \
877876
bool visit##INST##Inst(INST##Inst *i) { \
@@ -898,7 +897,7 @@ class NonEscapingUserVisitor
898897
// begin_access may signify a modification, but is considered nonmutating
899898
// because we will peek though it's uses to find the actual mutation.
900899
RECURSIVE_INST_VISITOR(IsNotMutating, BeginAccess)
901-
RECURSIVE_INST_VISITOR(IsMutating , UncheckedTakeEnumDataAddr)
900+
RECURSIVE_INST_VISITOR(IsMutating, UncheckedTakeEnumDataAddr)
902901
#undef RECURSIVE_INST_VISITOR
903902

904903
bool visitCopyAddrInst(CopyAddrInst *cai) {

0 commit comments

Comments
 (0)