Skip to content

Commit b4a750f

Browse files
committed
[DFAJumpThreading] Prevent pass from using too much memory.
The limit 'dfa-max-num-paths' that is used to control number of enumerated paths was not checked against inside getPathsFromStateDefMap. It may lead to large memory consumption for complex enough switch statements.
1 parent c51b48b commit b4a750f

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

llvm/lib/Transforms/Scalar/DFAJumpThreading.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,8 @@ struct AllSwitchPaths {
618618

619619
VisitedBlocks UniqueBlocks;
620620
for (auto *IncomingBB : Phi->blocks()) {
621+
if(Res.size() >= MaxNumPaths)
622+
break;
621623
if (!UniqueBlocks.insert(IncomingBB).second)
622624
continue;
623625
if (!SwitchOuterLoop->contains(IncomingBB))
@@ -657,6 +659,8 @@ struct AllSwitchPaths {
657659
getPathsFromStateDefMap(StateDef, IncomingPhi, VB);
658660
for (ThreadingPath &Path : PredPaths) {
659661
Path.push_back(PhiBB);
662+
if(Res.size() >= MaxNumPaths)
663+
break;
660664
Res.push_back(std::move(Path));
661665
}
662666
continue;
@@ -679,6 +683,10 @@ struct AllSwitchPaths {
679683
ThreadingPath NewPath(Path);
680684
NewPath.appendExcludingFirst(IPath);
681685
NewPath.push_back(PhiBB);
686+
if(Res.size() >= MaxNumPaths) {
687+
VB.erase(PhiBB);
688+
return Res;
689+
}
682690
Res.push_back(NewPath);
683691
}
684692
}

0 commit comments

Comments
 (0)