@@ -93,6 +93,8 @@ STATISTIC(NumRetainsSunk, "Number of retains sunk");
93
93
STATISTIC (NumReleasesHoisted, " Number of releases hoisted" );
94
94
95
95
llvm::cl::opt<bool > DisableRRCodeMotion (" disable-rr-cm" , llvm::cl::init(false ));
96
+
97
+ // / Disable optimization if we have to break critical edges in the function.
96
98
llvm::cl::opt<bool >
97
99
DisableIfWithCriticalEdge (" disable-with-critical-edge" , llvm::cl::init(false ));
98
100
@@ -127,6 +129,7 @@ struct BlockState {
127
129
// / RCRootVault. If this bit is set, that means this is potentially a retain
128
130
// / or release that can be sunk or hoisted to this point. This is used to
129
131
// / optimize the time for computing genset and killset.
132
+ // /
130
133
// / NOTE: this vector contains an approximation of whether there will be a
131
134
// / retain or release to a certain point of a basic block.
132
135
llvm::SmallBitVector BBMaxSet;
@@ -275,6 +278,8 @@ class RetainBlockState : public BlockState {
275
278
RetainBlockState (bool IsEntry, unsigned size, bool MultiIteration) {
276
279
// Iterative forward data flow.
277
280
BBSetIn.resize (size, false );
281
+ // Initilize to true if we are running optimistic data flow, i.e.
282
+ // MultiIteration is true.
278
283
BBSetOut.resize (size, MultiIteration);
279
284
BBMaxSet.resize (size, !IsEntry && MultiIteration);
280
285
@@ -316,7 +321,7 @@ class RetainCodeMotionContext : public CodeMotionContext {
316
321
RetainCodeMotionContext (llvm::SpecificBumpPtrAllocator<BlockState> &BPA,
317
322
SILFunction *F, PostOrderFunctionInfo *PO,
318
323
AliasAnalysis *AA, RCIdentityFunctionInfo *RCFI)
319
- : CodeMotionContext(BPA, F, PO, AA, RCFI) {
324
+ : CodeMotionContext(BPA, F, PO, AA, RCFI) {
320
325
MultiIteration = requireIteration ();
321
326
}
322
327
@@ -597,6 +602,8 @@ class ReleaseBlockState : public BlockState {
597
602
// / constructor.
598
603
ReleaseBlockState (bool IsExit, unsigned size, bool MultiIteration) {
599
604
// backward data flow.
605
+ // Initilize to true if we are running optimistic data flow, i.e.
606
+ // MultiIteration is true.
600
607
BBSetIn.resize (size, MultiIteration);
601
608
BBSetOut.resize (size, false );
602
609
BBMaxSet.resize (size, !IsExit && MultiIteration);
@@ -645,10 +652,10 @@ class ReleaseCodeMotionContext : public CodeMotionContext {
645
652
AliasAnalysis *AA, RCIdentityFunctionInfo *RCFI,
646
653
bool FreezeEpilogueReleases,
647
654
ConsumedArgToEpilogueReleaseMatcher &ERM)
648
- : CodeMotionContext(BPA, F, PO, AA, RCFI),
649
- FreezeEpilogueReleases (FreezeEpilogueReleases), ERM(ERM) {
650
- MultiIteration = requireIteration ();
651
- }
655
+ : CodeMotionContext(BPA, F, PO, AA, RCFI),
656
+ FreezeEpilogueReleases (FreezeEpilogueReleases), ERM(ERM) {
657
+ MultiIteration = requireIteration ();
658
+ }
652
659
653
660
// / virtual destructor.
654
661
virtual ~ReleaseCodeMotionContext () {}
@@ -717,16 +724,10 @@ void ReleaseCodeMotionContext::initializeCodeMotionDataFlow() {
717
724
}
718
725
719
726
// Initialize all the data flow bit vector for all basic blocks.
720
- llvm::SmallPtrSet<SILBasicBlock *, 2 > Exits;
721
- auto Return = F->findReturnBB ();
722
- auto Throw = F->findThrowBB ();
723
- if (Return != F->end ())
724
- Exits.insert (&*Return);
725
- if (Throw != F->end ())
726
- Exits.insert (&*Throw);
727
727
for (auto &BB : *F) {
728
- BlockStates[&BB] = new (BPA.Allocate ()) ReleaseBlockState (Exits.count (&BB),
729
- RCRootVault.size (), MultiIteration);
728
+ BlockStates[&BB] = new (BPA.Allocate ())
729
+ ReleaseBlockState (BB.getTerminator ()->isFunctionExiting (),
730
+ RCRootVault.size (), MultiIteration);
730
731
}
731
732
}
732
733
@@ -1050,7 +1051,8 @@ SILTransform *swift::createRetainSinking() {
1050
1051
return new RRCodeMotion (CodeMotionKind::Retain, false );
1051
1052
}
1052
1053
1053
- // / Hoist releases, but not epilogue release.
1054
+ // / Hoist releases, but not epilogue release. ASO relies on epilogue releases
1055
+ // / to prove knownsafety on enclosed releases.
1054
1056
SILTransform *swift::createReleaseHoisting () {
1055
1057
return new RRCodeMotion (CodeMotionKind::Release, true );
1056
1058
}
0 commit comments