summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorCameron Zwarich <zwarich@apple.com>2015-04-08 18:26:20 +0000
committerCameron Zwarich <zwarich@apple.com>2015-04-08 18:26:20 +0000
commitb282ef011109929f30de6e860e7bcbbdcc742527 (patch)
treec43d4a41263a5b74238485d50673d3388caba5ad /llvm
parentce48250f1103e1f4bfaa24b23b1060fcaacf16ef (diff)
downloadbcm5719-llvm-b282ef011109929f30de6e860e7bcbbdcc742527.tar.gz
bcm5719-llvm-b282ef011109929f30de6e860e7bcbbdcc742527.zip
Eliminate O(n^2) worst-case behavior in SSA construction
The code uses a priority queue and a worklist, which share the same visited set, but the visited set is only updated when inserting into the priority queue. Instead, switch to using separate visited sets for the priority queue and worklist. llvm-svn: 234425
Diffstat (limited to 'llvm')
-rw-r--r--llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp b/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
index 4b34b193773..54e1733c3f6 100644
--- a/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
+++ b/llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
@@ -872,8 +872,10 @@ void PromoteMem2Reg::DetermineInsertionPoint(AllocaInst *AI, unsigned AllocaNum,
}
SmallVector<std::pair<unsigned, BasicBlock *>, 32> DFBlocks;
- SmallPtrSet<DomTreeNode *, 32> Visited;
SmallVector<DomTreeNode *, 32> Worklist;
+ SmallPtrSet<DomTreeNode *, 32> VisitedPQ;
+ SmallPtrSet<DomTreeNode *, 32> VisitedWorklist;
+
while (!PQ.empty()) {
DomTreeNodePair RootPair = PQ.top();
PQ.pop();
@@ -887,6 +889,7 @@ void PromoteMem2Reg::DetermineInsertionPoint(AllocaInst *AI, unsigned AllocaNum,
Worklist.clear();
Worklist.push_back(Root);
+ VisitedWorklist.insert(Root);
while (!Worklist.empty()) {
DomTreeNode *Node = Worklist.pop_back_val();
@@ -905,7 +908,7 @@ void PromoteMem2Reg::DetermineInsertionPoint(AllocaInst *AI, unsigned AllocaNum,
if (SuccLevel > RootLevel)
continue;
- if (!Visited.insert(SuccNode).second)
+ if (!VisitedPQ.insert(SuccNode).second)
continue;
BasicBlock *SuccBB = SuccNode->getBlock();
@@ -919,7 +922,7 @@ void PromoteMem2Reg::DetermineInsertionPoint(AllocaInst *AI, unsigned AllocaNum,
for (DomTreeNode::iterator CI = Node->begin(), CE = Node->end(); CI != CE;
++CI) {
- if (!Visited.count(*CI))
+ if (VisitedWorklist.insert(*CI).second)
Worklist.push_back(*CI);
}
}
OpenPOWER on IntegriCloud