[PATCH] D83849: [TableGen] Reserve space in a vector to reduce the number of mallocs.

Nadav Rotem via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 14 22:48:00 PDT 2020


nadav created this revision.
nadav added a reviewer: modocache.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Reserve space in a vector to reduce the number of mallocs. The size of VTList is usually 1, but often 7. Push-backing into the vector in a loop triggers calls to reallocation of the vector. This happens hundreds of thousands of times in each tablegen instance.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D83849

Files:
  llvm/utils/TableGen/CodeGenDAGPatterns.cpp


Index: llvm/utils/TableGen/CodeGenDAGPatterns.cpp
===================================================================
--- llvm/utils/TableGen/CodeGenDAGPatterns.cpp
+++ llvm/utils/TableGen/CodeGenDAGPatterns.cpp
@@ -68,6 +68,7 @@
 // inference will apply to each mode separately.
 
 TypeSetByHwMode::TypeSetByHwMode(ArrayRef<ValueTypeByHwMode> VTList) {
+  AddrSpaces.reserve(VTList.size());
   for (const ValueTypeByHwMode &VVT : VTList) {
     insert(VVT);
     AddrSpaces.push_back(VVT.PtrAddrSpace);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D83849.278071.patch
Type: text/x-patch
Size: 504 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200715/45da4409/attachment.bin>


More information about the llvm-commits mailing list