@@ -102,7 +102,8 @@ class ArrayPropertiesAnalysis {
102
102
// / Check if it is profitable to specialize a loop when you see an apply
103
103
// / instruction. We consider it is not profitable to specialize the loop when:
104
104
// / 1. The callee is not found in the module, or cannot be determined
105
- // / 2. The number of instructions the analysis scans has exceeded the AnalysisThreshold
105
+ // / 2. The number of instructions the analysis scans has exceeded the
106
+ // / AnalysisThreshold
106
107
uint32_t checkProfitabilityRecursively (SILFunction *Callee) {
107
108
if (!Callee)
108
109
return AnalysisThreshold;
@@ -118,16 +119,19 @@ class ArrayPropertiesAnalysis {
118
119
for (auto &BB : *Callee) {
119
120
for (auto &I : BB) {
120
121
if (InstCount++ >= AnalysisThreshold) {
121
- LLVM_DEBUG (llvm::dbgs () << " ArrayPropertyOpt: Disabled Reason - Exceeded Analysis Threshold in "
122
+ LLVM_DEBUG (llvm::dbgs () << " ArrayPropertyOpt: Disabled Reason - "
123
+ " Exceeded Analysis Threshold in "
122
124
<< BB.getParent ()->getName () << " \n " );
123
125
InstCountCache[Callee] = AnalysisThreshold;
124
126
return AnalysisThreshold;
125
127
}
126
128
if (auto Apply = FullApplySite::isa (&I)) {
127
129
auto Callee = Apply.getReferencedFunctionOrNull ();
128
130
if (!Callee) {
129
- LLVM_DEBUG (llvm::dbgs () << " ArrayPropertyOpt: Disabled Reason - Found opaque code in "
130
- << BB.getParent ()->getName () << " \n " );
131
+ LLVM_DEBUG (
132
+ llvm::dbgs ()
133
+ << " ArrayPropertyOpt: Disabled Reason - Found opaque code in "
134
+ << BB.getParent ()->getName () << " \n " );
131
135
LLVM_DEBUG (Apply.dump ());
132
136
LLVM_DEBUG (I.getOperand (0 )->dump ());
133
137
}
@@ -182,9 +186,11 @@ class ArrayPropertiesAnalysis {
182
186
if (!FoundHoistable)
183
187
return false ;
184
188
185
- // If the LoopInstCount exceeds the threshold, we will disable the optimization on this loop
186
- // For loops of deeper nesting we increase the threshold by an additional 10%
187
- if (LoopInstCount > LoopInstCountThreshold * (1 + (Loop->getLoopDepth () - 1 ) / 10 )) {
189
+ // If the LoopInstCount exceeds the threshold, we will disable the
190
+ // optimization on this loop For loops of deeper nesting we increase the
191
+ // threshold by an additional 10%
192
+ if (LoopInstCount >
193
+ LoopInstCountThreshold * (1 + (Loop->getLoopDepth () - 1 ) / 10 )) {
188
194
LLVM_DEBUG (llvm::dbgs () << " Exceeded LoopInstCountThreshold\n " );
189
195
return false ;
190
196
}
@@ -205,8 +211,9 @@ class ArrayPropertiesAnalysis {
205
211
}
206
212
}
207
213
208
- LLVM_DEBUG (llvm::dbgs () << " Profitable ArrayPropertyOpt in "
209
- << Loop->getLoopPreheader ()->getParent ()->getName () << " \n " );
214
+ LLVM_DEBUG (llvm::dbgs ()
215
+ << " Profitable ArrayPropertyOpt in "
216
+ << Loop->getLoopPreheader ()->getParent ()->getName () << " \n " );
210
217
LLVM_DEBUG (Loop->dump ());
211
218
return true ;
212
219
}
@@ -216,7 +223,7 @@ class ArrayPropertiesAnalysis {
216
223
// / Strip the struct load and the address projection to the location
217
224
// / holding the array struct.
218
225
SILValue stripArrayStructLoad (SILValue V) {
219
- if (auto LI = dyn_cast<LoadInst>(V )) {
226
+ if (auto LI = dyn_cast<LoadInst>(lookThroughCopyValueInsts (V) )) {
220
227
auto Val = LI->getOperand ();
221
228
// We could have two arrays in a surrounding container so we can only
222
229
// strip off the 'array struct' project.
@@ -745,10 +752,6 @@ class SwiftArrayPropertyOptPass : public SILFunctionTransform {
745
752
void run () override {
746
753
auto *Fn = getFunction ();
747
754
748
- // FIXME: Add support for ownership.
749
- if (Fn->hasOwnership ())
750
- return ;
751
-
752
755
// Don't hoist array property calls at Osize.
753
756
if (Fn->optimizeForSize ())
754
757
return ;
@@ -782,7 +785,6 @@ class SwiftArrayPropertyOptPass : public SILFunctionTransform {
782
785
783
786
// Specialize the identified loop nest based on the 'array.props' calls.
784
787
if (HasChanged) {
785
- LLVM_DEBUG (getFunction ()->viewCFG ());
786
788
DominanceInfo *DT = DA->get (getFunction ());
787
789
788
790
// Process specialized loop-nests in loop-tree post-order (bottom-up).
@@ -795,8 +797,6 @@ class SwiftArrayPropertyOptPass : public SILFunctionTransform {
795
797
// Verify that no illegal critical edges were created.
796
798
getFunction ()->verifyCriticalEdges ();
797
799
798
- LLVM_DEBUG (getFunction ()->viewCFG ());
799
-
800
800
// We preserve the dominator tree. Let's invalidate everything
801
801
// else.
802
802
DA->lockInvalidation ();
0 commit comments