27
27
#include " swift/SILOptimizer/PassManager/Passes.h"
28
28
#include " swift/SILOptimizer/PassManager/Transforms.h"
29
29
#include " swift/SILOptimizer/Utils/InstOptUtils.h"
30
+ #include " swift/SILOptimizer/Utils/OwnershipOptUtils.h"
30
31
#include " llvm/ADT/STLExtras.h"
31
32
#include " llvm/ADT/Statistic.h"
32
33
#include " llvm/Support/CommandLine.h"
@@ -917,6 +918,8 @@ static const int SinkSearchWindow = 6;
917
918
918
919
// / Returns True if we can sink this instruction to another basic block.
919
920
static bool canSinkInstruction (SILInstruction *Inst) {
921
+ if (hasOwnershipOperandsOrResults (Inst))
922
+ return false ;
920
923
return !Inst->hasUsesOfAnyResult () && !isa<TermInst>(Inst);
921
924
}
922
925
@@ -1178,6 +1181,9 @@ static bool sinkArgument(EnumCaseDataflowContext &Context, SILBasicBlock *BB, un
1178
1181
if (!FSI || !hasOneNonDebugUse (FSI))
1179
1182
return false ;
1180
1183
1184
+ if (hasOwnershipOperandsOrResults (FSI))
1185
+ return false ;
1186
+
1181
1187
// The list of identical instructions.
1182
1188
SmallVector<SingleValueInstruction *, 8 > Clones;
1183
1189
Clones.push_back (FSI);
@@ -1743,38 +1749,43 @@ static bool processFunction(SILFunction *F, AliasAnalysis *AA,
1743
1749
LLVM_DEBUG (llvm::dbgs () << " Merging predecessors!\n " );
1744
1750
State.mergePredecessorStates ();
1745
1751
1746
- // If our predecessors cover any of our enum values, attempt to hoist
1747
- // releases up the CFG onto enum payloads or sink retains out of switch
1748
- // regions.
1749
- LLVM_DEBUG (llvm::dbgs () << " Attempting to move releases into "
1750
- " predecessors!\n " );
1751
-
1752
- // Perform a relatively local forms of retain sinking and release hoisting
1753
- // regarding switch regions and SILargument. This are not handled by retain
1754
- // release code motion.
1755
- if (HoistReleases) {
1756
- Changed |= State.hoistDecrementsIntoSwitchRegions (AA);
1757
- }
1752
+ if (!F->hasOwnership ()) {
1753
+ // If our predecessors cover any of our enum values, attempt to hoist
1754
+ // releases up the CFG onto enum payloads or sink retains out of switch
1755
+ // regions.
1756
+ LLVM_DEBUG (llvm::dbgs () << " Attempting to move releases into "
1757
+ " predecessors!\n " );
1758
+
1759
+ // Perform a relatively local forms of retain sinking and release hoisting
1760
+ // regarding switch regions and SILargument. This are not handled by retain
1761
+ // release code motion.
1762
+ if (HoistReleases) {
1763
+ Changed |= State.hoistDecrementsIntoSwitchRegions (AA);
1764
+ }
1758
1765
1759
- // Sink switch related retains.
1760
- Changed |= sinkIncrementsIntoSwitchRegions (State.getBB (), AA, RCIA);
1761
- Changed |= State.sinkIncrementsOutOfSwitchRegions (AA, RCIA);
1766
+ // Sink switch related retains.
1767
+ Changed |= sinkIncrementsIntoSwitchRegions (State.getBB (), AA, RCIA);
1768
+ Changed |= State.sinkIncrementsOutOfSwitchRegions (AA, RCIA);
1762
1769
1763
- // Then attempt to sink code from predecessors. This can include retains
1764
- // which is why we always attempt to move releases up the CFG before sinking
1765
- // code from predecessors. We will never sink the hoisted releases from
1766
- // predecessors since the hoisted releases will be on the enum payload
1767
- // instead of the enum itself.
1768
- Changed |= canonicalizeRefCountInstrs (State.getBB ());
1770
+ // Then attempt to sink code from predecessors. This can include retains
1771
+ // which is why we always attempt to move releases up the CFG before sinking
1772
+ // code from predecessors. We will never sink the hoisted releases from
1773
+ // predecessors since the hoisted releases will be on the enum payload
1774
+ // instead of the enum itself.
1775
+ Changed |= canonicalizeRefCountInstrs (State.getBB ());
1776
+ }
1769
1777
Changed |= sinkCodeFromPredecessors (BBToStateMap, State.getBB ());
1770
1778
Changed |= sinkArgumentsFromPredecessors (BBToStateMap, State.getBB ());
1771
1779
Changed |= sinkLiteralsFromPredecessors (State.getBB ());
1772
- // Try to hoist release of a SILArgument to predecessors.
1773
- Changed |= hoistSILArgumentReleaseInst (State.getBB ());
1774
1780
1775
- // Then perform the dataflow.
1776
- LLVM_DEBUG (llvm::dbgs () << " Performing the dataflow!\n " );
1777
- Changed |= State.process ();
1781
+ if (!F->hasOwnership ()) {
1782
+ // Try to hoist release of a SILArgument to predecessors.
1783
+ Changed |= hoistSILArgumentReleaseInst (State.getBB ());
1784
+
1785
+ // Then perform the dataflow.
1786
+ LLVM_DEBUG (llvm::dbgs () << " Performing the dataflow!\n " );
1787
+ Changed |= State.process ();
1788
+ }
1778
1789
}
1779
1790
1780
1791
return Changed;
@@ -1791,9 +1802,6 @@ class SILCodeMotion : public SILFunctionTransform {
1791
1802
// / The entry point to the transformation.
1792
1803
void run () override {
1793
1804
auto *F = getFunction ();
1794
- // Skip functions with ownership for now.
1795
- if (F->hasOwnership ())
1796
- return ;
1797
1805
1798
1806
auto *AA = getAnalysis<AliasAnalysis>(F);
1799
1807
auto *PO = getAnalysis<PostOrderAnalysis>()->get (F);
0 commit comments