@@ -83,13 +83,8 @@ class SimplifyCFG {
83
83
// this set may or may not still be LoopHeaders.
84
84
// (ultimately this can be used to eliminate findLoopHeaders)
85
85
SmallPtrSet<SILBasicBlock *, 4 > ClonedLoopHeaders;
86
- // The accumulated cost of jump threading per basic block. Initially
87
- // zero. Each clone increases the cost by ~ the number of copied instructions.
88
- // Effectively multiplying a block's cost is by the number of times it has
89
- // been cloned prevents any one block from being cloned indefinitely. Cloned
90
- // blocks inherit their original block's current cost to avoid indefinitely
91
- // optimizing the newly cloned blocks (primarily relevant for loops where the
92
- // number of predecessors can remain the same).
86
+ // The cost (~ number of copied instructions) of jump threading per basic
87
+ // block. Used to prevent infinite jump threading loops.
93
88
llvm::SmallDenseMap<SILBasicBlock *, int , 8 > JumpThreadingCost;
94
89
95
90
// Dominance and post-dominance info for the current function
@@ -323,8 +318,8 @@ bool SimplifyCFG::threadEdge(const ThreadInfo &ti) {
323
318
return false ;
324
319
325
320
Cloner.cloneBranchTarget (SrcTerm);
326
- JumpThreadingCost[Cloner.getNewBB ()] =
327
- JumpThreadingCost[SrcTerm-> getDestBB ()];
321
+ JumpThreadingCost[Cloner.getNewBB ()] = JumpThreadingCost[SrcTerm-> getDestBB ()];
322
+
328
323
329
324
// We have copied the threaded block into the edge.
330
325
auto *clonedSrc = Cloner.getNewBB ();
@@ -1095,7 +1090,7 @@ bool SimplifyCFG::tryJumpThreading(BranchInst *BI) {
1095
1090
}
1096
1091
}
1097
1092
}
1098
- // Deduct the prior cost of cloning these blocks (initially zero).
1093
+
1099
1094
ThreadingBudget -= JumpThreadingCost[SrcBB];
1100
1095
ThreadingBudget -= JumpThreadingCost[DestBB];
1101
1096
@@ -1131,7 +1126,6 @@ bool SimplifyCFG::tryJumpThreading(BranchInst *BI) {
1131
1126
LLVM_DEBUG (llvm::dbgs () << " jump thread from bb" << SrcBB->getDebugID ()
1132
1127
<< " to bb" << DestBB->getDebugID () << ' \n ' );
1133
1128
1134
- // Accumulate the cost of cloning the block to avoid indefinite cloning.
1135
1129
JumpThreadingCost[DestBB] += copyCosts;
1136
1130
1137
1131
// Duplicate the destination block into this one, rewriting uses of the BBArgs
@@ -1140,8 +1134,7 @@ bool SimplifyCFG::tryJumpThreading(BranchInst *BI) {
1140
1134
Cloner.updateSSAAfterCloning ();
1141
1135
1142
1136
// Also account the costs to the cloned DestBB, so the jump threading cannot
1143
- // loop by cloning the cloned block again. This is primarily relevant for
1144
- // loops where the number of predecessors might not decrease with each clone.
1137
+ // loop by cloning the cloned block again.
1145
1138
JumpThreadingCost[Cloner.getNewBB ()] += copyCosts;
1146
1139
1147
1140
// Once all the instructions are copied, we can nuke BI itself. We also add
0 commit comments