[PATCH] D85379: Improve dropTriviallyDeadConstantArrays time cost ratio from 17% to 4%
Stephan Z via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 6 00:25:46 PDT 2020
stephan.yichao.zhao updated this revision to Diff 283510.
stephan.yichao.zhao added a comment.
addressed comments.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D85379/new/
https://reviews.llvm.org/D85379
Files:
llvm/lib/IR/LLVMContextImpl.cpp
Index: llvm/lib/IR/LLVMContextImpl.cpp
===================================================================
--- llvm/lib/IR/LLVMContextImpl.cpp
+++ llvm/lib/IR/LLVMContextImpl.cpp
@@ -129,18 +129,24 @@
}
void LLVMContextImpl::dropTriviallyDeadConstantArrays() {
- SmallSetVector<ConstantArray *, 4> WorkList(ArrayConstants.begin(),
- ArrayConstants.end());
+ SmallSetVector<ConstantArray *, 4> WorkList;
+
+ // When ArrayConstants are of substantial size and only a few in them are
+ // dead, starting WorkList with all elements of ArrayConstants can be
+ // wasteful. Instead, starting WorkList with only elements that have empty
+ // uses.
+ for (ConstantArray *C : ArrayConstants)
+ if (C->use_empty())
+ WorkList.insert(C);
while (!WorkList.empty()) {
ConstantArray *C = WorkList.pop_back_val();
- if (C->use_empty()) {
- for (const Use &Op : C->operands()) {
- if (auto *COp = dyn_cast<ConstantArray>(Op))
- WorkList.insert(COp);
- }
- C->destroyConstant();
- }
+ if (!C->use_empty())
+ continue;
+ for (const Use &Op : C->operands())
+ if (auto *COp = dyn_cast<ConstantArray>(Op))
+ WorkList.insert(COp);
+ C->destroyConstant();
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85379.283510.patch
Type: text/x-patch
Size: 1281 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200806/ceb25dfc/attachment.bin>
More information about the llvm-commits
mailing list