llvm.org GIT mirror llvm / 2c937a1
Switch SmallSetVector to use DenseSet when it overflows its inline space. Summary: SetVector already used DenseSet, but SmallSetVector used std::set. This leads to surprising performance differences. Moreover, it means that the set of key types accepted by SetVector and SmallSetVector are quite different! In order to make this change, we had to convert some callsites that used SmallSetVector<std::string, N> to use SmallSetVector<CachedHashString, N> instead. Reviewers: timshen Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D25648 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@284887 91177308-0d34-0410-b5e6-96231b3b80d8 Justin Lebar 3 years ago
3 changed file(s) with 25 addition(s) and 21 deletion(s). Raw diff Collapse all Expand all
281281 /// \brief A SetVector that performs no allocations if smaller than
282282 /// a certain size.
283283 template
284 class SmallSetVector : public SetVector, SmallSet > {
284 class SmallSetVector
285 : public SetVector, SmallDenseSet> {
285286 public:
286287 SmallSetVector() {}
287288
9696 //===----------------------------------------------------------------------===//
9797
9898 #include "CodeGenTarget.h"
99 #include "llvm/ADT/CachedHashString.h"
99100 #include "llvm/ADT/PointerUnion.h"
100101 #include "llvm/ADT/STLExtras.h"
101102 #include "llvm/ADT/SmallPtrSet.h"
18211822 }
18221823 }
18231824
1824 static unsigned getConverterOperandID(const std::string &Name,
1825 SmallSetVector &Table,
1826 bool &IsNew) {
1827 IsNew = Table.insert(Name);
1825 static unsigned
1826 getConverterOperandID(const std::string &Name,
1827 SmallSetVector &Table,
1828 bool &IsNew) {
1829 IsNew = Table.insert(CachedHashString(Name));
18281830
18291831 unsigned ID = IsNew ? Table.size() - 1 : find(Table, Name) - Table.begin();
18301832
18371839 std::vector> &Infos,
18381840 bool HasMnemonicFirst, bool HasOptionalOperands,
18391841 raw_ostream &OS) {
1840 SmallSetVector OperandConversionKinds;
1841 SmallSetVector<std::string, 16> InstructionConversionKinds;
1842 SmallSetVector<CachedHashString, 16> OperandConversionKinds;
1843 SmallSetVector InstructionConversionKinds;
18421844 std::vector > ConversionTable;
18431845 size_t MaxRowLength = 2; // minimum is custom converter plus terminator.
18441846
19101912
19111913 // Pre-populate the operand conversion kinds with the standard always
19121914 // available entries.
1913 OperandConversionKinds.insert("CVT_Done");
1914 OperandConversionKinds.insert("CVT_Reg");
1915 OperandConversionKinds.insert("CVT_Tied");
1915 OperandConversionKinds.insert(CachedHashString("CVT_Done"));
1916 OperandConversionKinds.insert(CachedHashString("CVT_Reg"));
1917 OperandConversionKinds.insert(CachedHashString("CVT_Tied"));
19161918 enum { CVT_Done, CVT_Reg, CVT_Tied };
19171919
19181920 for (auto &II : Infos) {
19241926 II->ConversionFnKind = Signature;
19251927
19261928 // Check if we have already generated this signature.
1927 if (!InstructionConversionKinds.insert(Signature))
1929 if (!InstructionConversionKinds.insert(CachedHashString(Signature)))
19281930 continue;
19291931
19301932 // Remember this converter for the kind enum.
19311933 unsigned KindID = OperandConversionKinds.size();
1932 OperandConversionKinds.insert("CVT_" +
1933 getEnumNameForToken(AsmMatchConverter));
1934 OperandConversionKinds.insert(
1935 CachedHashString("CVT_" + getEnumNameForToken(AsmMatchConverter)));
19341936
19351937 // Add the converter row for this instruction.
19361938 ConversionTable.emplace_back();
21122114
21132115 // Save the signature. If we already have it, don't add a new row
21142116 // to the table.
2115 if (!InstructionConversionKinds.insert(Signature))
2117 if (!InstructionConversionKinds.insert(CachedHashString(Signature)))
21162118 continue;
21172119
21182120 // Add the row to the table.
21292131
21302132 // Output the operand conversion kind enum.
21312133 OS << "enum OperatorConversionKind {\n";
2132 for (const std::string &Converter : OperandConversionKinds)
2134 for (const auto &Converter : OperandConversionKinds)
21332135 OS << " " << Converter << ",\n";
21342136 OS << " CVT_NUM_CONVERTERS\n";
21352137 OS << "};\n\n";
21362138
21372139 // Output the instruction conversion kind enum.
21382140 OS << "enum InstructionConversionKind {\n";
2139 for (const std::string &Signature : InstructionConversionKinds)
2141 for (const auto &Signature : InstructionConversionKinds)
21402142 OS << " " << Signature << ",\n";
21412143 OS << " CVT_NUM_SIGNATURES\n";
21422144 OS << "};\n\n";
1313
1414 #include "CodeGenTarget.h"
1515 #include "llvm/ADT/APInt.h"
16 #include "llvm/ADT/CachedHashString.h"
1617 #include "llvm/ADT/SmallString.h"
1718 #include "llvm/ADT/StringExtras.h"
1819 #include "llvm/ADT/StringRef.h"
6566 typedef uint32_t DecoderFixup;
6667 typedef std::vector FixupList;
6768 typedef std::vector FixupScopeList;
68 typedef SmallSetVector PredicateSet;
69 typedef SmallSetVector<std::string, 16> DecoderSet;
69 typedef SmallSetVector<CachedHashString, 16> PredicateSet;
70 typedef SmallSetVector DecoderSet;
7071 struct DecoderTableInfo {
7172 DecoderTable Table;
7273 FixupScopeList FixupStack;
11051106 // overkill for now, though.
11061107
11071108 // Make sure the predicate is in the table.
1108 Decoders.insert(StringRef(Decoder));
1109 Decoders.insert(CachedHashString(Decoder));
11091110 // Now figure out the index for when we write out the table.
11101111 DecoderSet::const_iterator P = find(Decoders, Decoder.str());
11111112 return (unsigned)(P - Decoders.begin());
11781179 // overkill for now, though.
11791180
11801181 // Make sure the predicate is in the table.
1181 TableInfo.Predicates.insert(Predicate.str());
1182 TableInfo.Predicates.insert(CachedHashString(Predicate));
11821183 // Now figure out the index for when we write out the table.
1183 PredicateSet::const_iterator P = find(TableInfo.Predicates, Predicate.str());
1184 PredicateSet::const_iterator P = find(TableInfo.Predicates, Predicate);
11841185 return (unsigned)(P - TableInfo.Predicates.begin());
11851186 }
11861187