@@ -2639,9 +2639,6 @@ class BlockPartitionState {
2639
2639
// / Set if this block in the next iteration needs to be visited.
2640
2640
bool needsUpdate = false ;
2641
2641
2642
- // / Set if we have ever visited this block at all.
2643
- bool reached = false ;
2644
-
2645
2642
// / The partition of elements into regions at the top of the block.
2646
2643
Partition entryPartition;
2647
2644
@@ -2698,8 +2695,12 @@ class BlockPartitionState {
2698
2695
// will be suppressed
2699
2696
eval.apply (partitionOp);
2700
2697
}
2698
+ LLVM_DEBUG (llvm::dbgs() << " Working Partition: " ;
2699
+ workingPartition.print(llvm::dbgs()));
2701
2700
bool exitUpdated = !Partition::equals(exitPartition, workingPartition);
2702
2701
exitPartition = workingPartition;
2702
+ LLVM_DEBUG (llvm::dbgs() << " Exit Partition: ";
2703
+ exitPartition.print(llvm::dbgs()));
2703
2704
return exitUpdated;
2704
2705
}
2705
2706
@@ -2713,8 +2714,8 @@ class BlockPartitionState {
2713
2714
SWIFT_DEBUG_DUMP { print (llvm::dbgs ()); }
2714
2715
2715
2716
void print (llvm::raw_ostream &os) const {
2716
- os << SEP_STR << " BlockPartitionState[reached =" << reached
2717
- << " , needsUpdate= " << needsUpdate << " ]\n id: " ;
2717
+ os << SEP_STR << " BlockPartitionState[needsUpdate =" << needsUpdate
2718
+ << " ]\n id: " ;
2718
2719
#ifndef NDEBUG
2719
2720
auto printID = [&](SILBasicBlock *block) {
2720
2721
block->printID (os);
@@ -2974,9 +2975,11 @@ class PartitionAnalysis {
2974
2975
}),
2975
2976
allocator (), ptrSetFactory(allocator), function(fn), pofi(pofi),
2976
2977
solved(false ) {
2977
- // Initialize the entry block as needing an update, and having a partition
2978
- // that places all its non-sendable args in a single region
2979
- blockStates[fn->getEntryBlock ()].needsUpdate = true ;
2978
+ // Mark all blocks as needing to be updated.
2979
+ for (auto &block : *fn) {
2980
+ blockStates[&block].needsUpdate = true ;
2981
+ }
2982
+ // Set our entry partition to have the "entry partition".
2980
2983
blockStates[fn->getEntryBlock ()].entryPartition =
2981
2984
translator.getEntryPartition ();
2982
2985
}
@@ -3001,57 +3004,32 @@ class PartitionAnalysis {
3001
3004
continue ;
3002
3005
}
3003
3006
3004
- // mark this block as no longer needing an update
3007
+ // Mark this block as no longer needing an update.
3005
3008
blockState.needsUpdate = false ;
3006
3009
3007
- // mark this block as reached by the analysis
3008
- blockState.reached = true ;
3009
-
3010
- // compute the new entry partition to this block
3011
- Partition newEntryPartition;
3012
- bool firstPred = true ;
3010
+ // Compute the new entry partition to this block.
3011
+ Partition newEntryPartition = blockState.entryPartition ;
3013
3012
3014
3013
LLVM_DEBUG (llvm::dbgs () << " Visiting Preds!\n " );
3015
3014
3016
- // This loop computes the join of the exit partitions of all
3015
+ // This loop computes the union of the exit partitions of all
3017
3016
// predecessors of this block
3018
3017
for (SILBasicBlock *predBlock : block->getPredecessorBlocks ()) {
3019
3018
BlockPartitionState &predState = blockStates[predBlock];
3020
- // ignore predecessors that haven't been reached by the analysis yet
3021
- if (!predState.reached )
3022
- continue ;
3023
-
3024
- if (firstPred) {
3025
- firstPred = false ;
3026
- newEntryPartition = predState.exitPartition ;
3027
- LLVM_DEBUG (llvm::dbgs () << " First Pred. bb"
3028
- << predBlock->getDebugID () << " : " ;
3029
- newEntryPartition.print (llvm::dbgs ()));
3030
- continue ;
3031
- }
3032
3019
3020
+ // Predecessors that have not been reached yet will have an empty pred
3021
+ // state... so just merge them all. Also our initial value of
3033
3022
LLVM_DEBUG (llvm::dbgs ()
3034
3023
<< " Pred. bb" << predBlock->getDebugID () << " : " ;
3035
3024
predState.exitPartition .print (llvm::dbgs ()));
3036
3025
newEntryPartition =
3037
3026
Partition::join (newEntryPartition, predState.exitPartition );
3038
3027
}
3039
3028
3040
- // If we found predecessor blocks, then attempt to use them to update
3041
- // the entry partition for this block, and abort this block's update if
3042
- // the entry partition was not updated.
3043
- if (!firstPred) {
3044
- // if the recomputed entry partition is the same as the current one,
3045
- // perform no update
3046
- if (Partition::equals (newEntryPartition, blockState.entryPartition )) {
3047
- LLVM_DEBUG (llvm::dbgs ()
3048
- << " Entry partition is the same... skipping!\n " );
3049
- continue ;
3050
- }
3051
-
3052
- // otherwise update the entry partition
3053
- blockState.entryPartition = newEntryPartition;
3054
- }
3029
+ // Update the entry partition. We need to still try to
3030
+ // recomputeExitFromEntry before we know if we made a difference to the
3031
+ // exit partition after applying the instructions of the block.
3032
+ blockState.entryPartition = newEntryPartition;
3055
3033
3056
3034
// recompute this block's exit partition from its (updated) entry
3057
3035
// partition, and if this changed the exit partition notify all
@@ -3169,6 +3147,8 @@ class PartitionAnalysis {
3169
3147
LLVM_DEBUG (llvm::dbgs() << "Walking blocks for diagnostics.\n");
3170
3148
for (auto [block, blockState] : blockStates) {
3171
3149
LLVM_DEBUG (llvm::dbgs () << " |--> Block bb" << block.getDebugID () << " \n " );
3150
+ LLVM_DEBUG (llvm::dbgs () << " Entry Partition: " ;
3151
+ blockState.getEntryPartition ().print (llvm::dbgs ()));
3172
3152
3173
3153
// Grab its entry partition and setup an evaluator for the partition that
3174
3154
// has callbacks that emit diagnsotics...
@@ -3180,6 +3160,9 @@ class PartitionAnalysis {
3180
3160
for (auto &partitionOp : blockState.getPartitionOps ()) {
3181
3161
eval.apply (partitionOp);
3182
3162
}
3163
+
3164
+ LLVM_DEBUG (llvm::dbgs () << " Exit Partition: " ;
3165
+ workingPartition.print (llvm::dbgs ()));
3183
3166
}
3184
3167
3185
3168
// Now that we have found all of our transferInsts/Requires emit errors.
0 commit comments