40
40
// / Region B to Region A, that means there is no blocking operation from where
41
41
// / the release was in Region B and where the release is hoisted to in Region A.
42
42
// /
43
- // / The question is whether we can introduce such operation while we hoist other
44
- // / releases. The answer is NO. because if such releases exist, they would be
45
- // / blocked by the old release (we remove old release and recreate new ones at
46
- // / the end of the pass) and will not be able to be hoisted beyond the old
47
- // / release.
43
+ // / The question is whether we can introduce such operation while we hoist
44
+ // / other releases. The answer is NO. because if such releases exist, they
45
+ // / would be blocked by the old release (we remove old release and recreate new
46
+ // / ones at the end of the pass) and will not be able to be hoisted beyond the
47
+ // / old release.
48
48
// /
49
49
// / This proof also hinges on the fact that if release A interferes with
50
50
// / releases B then release B must interfere with release A. i.e. the 2
64
64
// /
65
65
// / TODO: There are a lot of code duplications between retain and release code
66
66
// / motion in the data flow part. Consider whether we can share them.
67
- // / Essentially, we can implement the release code motion by inverting the retain
68
- // / code motion, but this can also make the code less readable.
67
+ // / Essentially, we can implement the release code motion by inverting the
68
+ // / retain code motion, but this can also make the code less readable.
69
69
// /
70
70
// ===----------------------------------------------------------------------===//
71
71
72
72
#define DEBUG_TYPE " sil-rr-code-motion"
73
73
#include " swift/SIL/SILBuilder.h"
74
74
#include " swift/SILOptimizer/Analysis/AliasAnalysis.h"
75
+ #include " swift/SILOptimizer/Analysis/ARCAnalysis.h"
75
76
#include " swift/SILOptimizer/Analysis/EscapeAnalysis.h"
76
- #include " swift/SILOptimizer/Analysis/LoopAnalysis.h"
77
77
#include " swift/SILOptimizer/Analysis/PostOrderAnalysis.h"
78
78
#include " swift/SILOptimizer/Analysis/RCIdentityAnalysis.h"
79
- #include " swift/SILOptimizer/Analysis/ValueTracking.h"
80
79
#include " swift/SILOptimizer/PassManager/Passes.h"
81
80
#include " swift/SILOptimizer/PassManager/Transforms.h"
82
81
#include " swift/SILOptimizer/Utils/CFG.h"
@@ -94,19 +93,8 @@ STATISTIC(NumRetainsSunk, "Number of retains sunk");
94
93
STATISTIC (NumReleasesHoisted, " Number of releases hoisted" );
95
94
96
95
llvm::cl::opt<bool > DisableRRCodeMotion (" disable-rr-cm" , llvm::cl::init(false ));
97
- llvm::cl::opt<bool > DisableIfWithCriticalEdge (" disable-with-critical-edge" , llvm::cl::init(false ));
98
-
99
- // ===----------------------------------------------------------------------===//
100
- // Utility
101
- // ===----------------------------------------------------------------------===//
102
-
103
- static bool isRetainInstruction (SILInstruction *I) {
104
- return isa<StrongRetainInst>(I) || isa<RetainValueInst>(I);
105
- }
106
-
107
- static bool isReleaseInstruction (SILInstruction *I) {
108
- return isa<StrongReleaseInst>(I) || isa<ReleaseValueInst>(I);
109
- }
96
+ llvm::cl::opt<bool >
97
+ DisableIfWithCriticalEdge (" disable-with-critical-edge" , llvm::cl::init(false ));
110
98
111
99
// ===----------------------------------------------------------------------===//
112
100
// Block State
@@ -199,13 +187,14 @@ class CodeMotionContext {
199
187
// / retain or release.
200
188
SILValue getRCRoot (SILInstruction *I) {
201
189
assert (isRetainInstruction (I) || isReleaseInstruction (I) &&
202
- " Extracting RC root from Invalid instruction" );
190
+ " Extracting RC root from invalid instruction" );
203
191
return getRCRoot (I->getOperand (0 ));
204
192
}
205
193
206
194
public:
207
195
// / Constructor.
208
- CodeMotionContext (llvm::SpecificBumpPtrAllocator<BlockState> &BPA, SILFunction *F,
196
+ CodeMotionContext (llvm::SpecificBumpPtrAllocator<BlockState> &BPA,
197
+ SILFunction *F,
209
198
PostOrderFunctionInfo *PO, AliasAnalysis *AA,
210
199
RCIdentityFunctionInfo *RCFI)
211
200
: MultiIteration(true ), BPA(BPA), F(F), PO(PO), AA(AA), RCFI(RCFI) {}
@@ -396,8 +385,9 @@ void RetainCodeMotionContext::initializeCodeMotionDataFlow() {
396
385
397
386
// Initialize all the data flow bit vector for all basic blocks.
398
387
for (auto &BB : *F) {
399
- BlockStates[&BB] = new (BPA.Allocate ()) RetainBlockState (&BB == &*F->begin (),
400
- RCRootVault.size (), MultiIteration);
388
+ BlockStates[&BB] = new (BPA.Allocate ())
389
+ RetainBlockState (&BB == &*F->begin (),
390
+ RCRootVault.size (), MultiIteration);
401
391
}
402
392
}
403
393
@@ -981,11 +971,11 @@ void ReleaseCodeMotionContext::computeCodeMotionInsertPoints() {
981
971
namespace {
982
972
983
973
// / Code motion kind.
984
- enum CMKind : unsigned { Retain = 0 , Release = 1 };
974
+ enum CodeMotionKind : unsigned { Retain = 0 , Release = 1 };
985
975
986
976
class RRCodeMotion : public SILFunctionTransform {
987
977
// / Whether to hoist releases or sink retains.
988
- CMKind Kind;
978
+ CodeMotionKind Kind;
989
979
990
980
// / Freeze epilogue release or not.
991
981
bool FreezeEpilogueReleases;
@@ -994,10 +984,11 @@ class RRCodeMotion : public SILFunctionTransform {
994
984
StringRef getName () override { return " SIL Retain Release Code Motion" ; }
995
985
996
986
// / Constructor.
997
- RRCodeMotion (CMKind H, bool F) : Kind(H), FreezeEpilogueReleases(F) {}
987
+ RRCodeMotion (CodeMotionKind H, bool F) : Kind(H), FreezeEpilogueReleases(F) {}
998
988
999
989
// / The entry point to the transformation.
1000
990
void run () override {
991
+ // Code motion disabled.
1001
992
if (DisableRRCodeMotion)
1002
993
return ;
1003
994
@@ -1056,15 +1047,15 @@ class RRCodeMotion : public SILFunctionTransform {
1056
1047
1057
1048
// / Sink Retains.
1058
1049
SILTransform *swift::createRetainSinking () {
1059
- return new RRCodeMotion (CMKind ::Retain, false );
1050
+ return new RRCodeMotion (CodeMotionKind ::Retain, false );
1060
1051
}
1061
1052
1062
1053
// / Hoist releases, but not epilogue release.
1063
1054
SILTransform *swift::createReleaseHoisting () {
1064
- return new RRCodeMotion (CMKind ::Release, true );
1055
+ return new RRCodeMotion (CodeMotionKind ::Release, true );
1065
1056
}
1066
1057
1067
1058
// / Hoist all releases.
1068
1059
SILTransform *swift::createLateReleaseHoisting () {
1069
- return new RRCodeMotion (CMKind ::Release, false );
1060
+ return new RRCodeMotion (CodeMotionKind ::Release, false );
1070
1061
}
0 commit comments