From: Fangrui Song Date: Tue, 25 Jul 2023 05:04:03 +0000 (-0700) Subject: [Support] Change MapVector's default template parameter to SmallVector<*, 0> X-Git-Tag: upstream/17.0.6~444 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fb2a971c015fa991b47aa8d93bd97379c012cb68;p=platform%2Fupstream%2Fllvm.git [Support] Change MapVector's default template parameter to SmallVector<*, 0> SmallVector<*, 0> is often a better replacement for std::vector : both the object size and the code size are smaller. (SmallMapVector uses SmallVector as well, but it is not common.) clang size decreases by 0.0226%. instructions:u decreases 0.037% when compiling a sqlite3 amalgram. Reviewed By: JDevlieghere Differential Revision: https://reviews.llvm.org/D156016 --- diff --git a/lld/MachO/UnwindInfoSection.cpp b/lld/MachO/UnwindInfoSection.cpp index 0bffce0e06ea..1466e7b4fb39 100644 --- a/lld/MachO/UnwindInfoSection.cpp +++ b/lld/MachO/UnwindInfoSection.cpp @@ -146,7 +146,7 @@ private: Symbol *canonicalizePersonality(Symbol *); uint64_t unwindInfoSize = 0; - std::vector symbolsVec; + SmallVector symbolsVec; CompactUnwindLayout cuLayout; std::vector> commonEncodings; EncodingMap commonEncodingIndexes; diff --git a/llvm/include/llvm/ADT/MapVector.h b/llvm/include/llvm/ADT/MapVector.h index a129b63f8be7..c45779c0ce8e 100644 --- a/llvm/include/llvm/ADT/MapVector.h +++ b/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 #include #include -#include 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 VectorType = std::vector>> +template , + typename VectorType = SmallVector, 0>> class MapVector { MapType Map; VectorType Vector; diff --git a/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp b/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp index 165b8f172c35..2076ed48ea34 100644 --- a/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp +++ b/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp @@ -266,7 +266,9 @@ static void computeFunctionSummary( unsigned NumInsts = 0; // Map from callee ValueId to profile count. Used to accumulate profile // counts for all static calls to a given callee. - MapVector CallGraphEdges; + MapVector, + std::vector>> + CallGraphEdges; SetVector RefEdges, LoadRefEdges, StoreRefEdges; SetVector TypeTests; SetVector TypeTestAssumeVCalls, diff --git a/mlir/lib/IR/AsmPrinter.cpp b/mlir/lib/IR/AsmPrinter.cpp index ea31d18d832c..325f986f9769 100644 --- a/mlir/lib/IR/AsmPrinter.cpp +++ b/mlir/lib/IR/AsmPrinter.cpp @@ -975,8 +975,8 @@ static StringRef sanitizeIdentifier(StringRef name, SmallString<16> &buffer, void AliasInitializer::initializeAliases( llvm::MapVector &visitedSymbols, llvm::MapVector &symbolToAlias) { - std::vector> unprocessedAliases = - visitedSymbols.takeVector(); + SmallVector, 0> + unprocessedAliases = visitedSymbols.takeVector(); llvm::stable_sort(unprocessedAliases, [](const auto &lhs, const auto &rhs) { return lhs.second < rhs.second; });