Skip to content

Commit d73686a

Browse files
committed
SILCombine: limit the worklist size for instruction canonicalization
To be precise: don't add instruction uses to the worklist if it already has more than 10000 elements. This avoids quadratic behavior for very large functions. rdar://problem/56268570
1 parent 4e2cffb commit d73686a

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

include/swift/SIL/SILInstructionWorklist.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ class SILInstructionWorklist : SILInstructionWorklistBase {
7272
/// Returns true if the worklist is empty.
7373
bool isEmpty() const { return worklist.empty(); }
7474

75+
/// Returns the number of elements in the worklist.
76+
unsigned size() const { return worklist.size(); }
77+
7578
/// Add the specified instruction to the worklist if it isn't already in it.
7679
void add(SILInstruction *instruction) {
7780
if (worklist.insert(instruction).second) {

lib/SILOptimizer/SILCombiner/SILCombine.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ class SILCombineCanonicalize final : CanonicalizeInstruction {
131131
}
132132

133133
void notifyHasNewUsers(SILValue value) override {
134-
Worklist.addUsersToWorklist(value);
134+
if (Worklist.size() < 10000) {
135+
Worklist.addUsersToWorklist(value);
136+
}
135137
changed = true;
136138
}
137139

0 commit comments

Comments
 (0)