Skip to content

Commit 108a6a5

Browse files
authored
Merge pull request #64320 from eeckstein/fix-compile-time-problems
SILOptimizer: add complexity limit in ARCCodeMotion and DeadStoreElimination
2 parents 837ef1a + 9604962 commit 108a6a5

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

lib/SILOptimizer/Transforms/ARCCodeMotion.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,17 @@ bool CodeMotionContext::run() {
254254
// Initialize the data flow.
255255
initializeCodeMotionDataFlow();
256256

257+
if (RCRootVault.size() > 500) {
258+
// Emergency exit to avoid bad compile time problems in rare corner cases.
259+
// This limit is more than enough for "real world" code.
260+
// Even large functions have < 100 locations.
261+
// But in some corner cases - especially in generated code - we can run
262+
// into quadratic complexity for large functions.
263+
// TODO: eventually the ARCCodeMotion passes will be replaced by OSSA
264+
// optimizations which shouldn't have this problem.
265+
return false;
266+
}
267+
257268
// Converge the BBSetOut with iterative data flow.
258269
if (MultiIteration) {
259270
initializeCodeMotionBBMaxSet();

lib/SILOptimizer/Transforms/DeadStoreElimination.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,6 +1204,17 @@ bool DSEContext::run() {
12041204
//
12051205
// Initialize the BBToLocState mapping.
12061206
unsigned LocationNum = this->getLocationVault().size();
1207+
1208+
if (LocationNum > 500) {
1209+
// Emergency exit to avoid bad compile time problems in rare corner cases.
1210+
// This limit is more than enough for "real world" code.
1211+
// Even large functions have < 100 locations.
1212+
// But in some corner cases - especially in generated code - we can run
1213+
// into quadratic complexity for large functions.
1214+
// TODO: implement DSE with a better (non-quadratic) algorithm
1215+
return false;
1216+
}
1217+
12071218
for (auto bs : BBToLocState) {
12081219
bs.data.init(&bs.block, LocationNum, Optimistic);
12091220
bs.data.initStoreSetAtEndOfBlock(*this);

0 commit comments

Comments
 (0)