[PATCH] D156016: [Support] Change MapVector's default template parameter to SmallVector<*, 0>
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 21 19:59:17 PDT 2023
MaskRay created this revision.
MaskRay added reviewers: lld-macho, serge-sans-paille, JDevlieghere.
Herald added subscribers: hoy, hiraditya.
Herald added projects: lld-macho, All.
MaskRay requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
SmallVector<*, 0> is often a better replacement for std::vector :
both the object size and the code size are smaller.
(SmallMapVector is not common.)
clang size decreases by 0.0226%.
instructions:u decreases 0.037% when compiling a sqlite3 amalgram.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D156016
Files:
lld/MachO/UnwindInfoSection.cpp
llvm/include/llvm/ADT/MapVector.h
llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
Index: llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
===================================================================
--- llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
+++ llvm/lib/Analysis/ModuleSummaryAnalysis.cpp
@@ -266,7 +266,9 @@
unsigned NumInsts = 0;
// Map from callee ValueId to profile count. Used to accumulate profile
// counts for all static calls to a given callee.
- MapVector<ValueInfo, CalleeInfo> CallGraphEdges;
+ MapVector<ValueInfo, CalleeInfo, DenseMap<ValueInfo, unsigned>,
+ std::vector<std::pair<ValueInfo, CalleeInfo>>>
+ CallGraphEdges;
SetVector<ValueInfo> RefEdges, LoadRefEdges, StoreRefEdges;
SetVector<GlobalValue::GUID> TypeTests;
SetVector<FunctionSummary::VFuncId> TypeTestAssumeVCalls,
Index: llvm/include/llvm/ADT/MapVector.h
===================================================================
--- llvm/include/llvm/ADT/MapVector.h
+++ llvm/include/llvm/ADT/MapVector.h
@@ -10,7 +10,7 @@
/// This file implements a map that provides insertion order iteration. The
/// interface is purposefully minimal. The key is assumed to be cheap to copy
/// and 2 copies are kept, one for indexing in a DenseMap, one for iteration in
-/// a std::vector.
+/// a SmallVector.
///
//===----------------------------------------------------------------------===//
@@ -24,16 +24,15 @@
#include <iterator>
#include <type_traits>
#include <utility>
-#include <vector>
namespace llvm {
/// This class implements a map that also provides access to all stored values
-/// in a deterministic order. The values are kept in a std::vector and the
+/// in a deterministic order. The values are kept in a SmallVector<*, 0> and the
/// mapping is done with DenseMap from Keys to indexes in that vector.
-template<typename KeyT, typename ValueT,
- typename MapType = DenseMap<KeyT, unsigned>,
- typename VectorType = std::vector<std::pair<KeyT, ValueT>>>
+template <typename KeyT, typename ValueT,
+ typename MapType = DenseMap<KeyT, unsigned>,
+ typename VectorType = SmallVector<std::pair<KeyT, ValueT>, 0>>
class MapVector {
MapType Map;
VectorType Vector;
Index: lld/MachO/UnwindInfoSection.cpp
===================================================================
--- lld/MachO/UnwindInfoSection.cpp
+++ lld/MachO/UnwindInfoSection.cpp
@@ -146,7 +146,7 @@
Symbol *canonicalizePersonality(Symbol *);
uint64_t unwindInfoSize = 0;
- std::vector<decltype(symbols)::value_type> symbolsVec;
+ SmallVector<decltype(symbols)::value_type, 0> symbolsVec;
CompactUnwindLayout cuLayout;
std::vector<std::pair<compact_unwind_encoding_t, size_t>> commonEncodings;
EncodingMap commonEncodingIndexes;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156016.543141.patch
Type: text/x-patch
Size: 2707 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230722/d9974c11/attachment.bin>
More information about the llvm-commits
mailing list