Skip to content

Commit d2b935e

Browse files
committed
[NFC] Replace more DenseMaps with SmallDenseMaps
These DenseMaps all appear as some of the most frequent sources of memory-allocations that could otherwise be accomodated with an initial stack allocation. For simplicity, I've typedef'd one map-type to be BlockColorMapT, used by various block colouring functions. This also features one opportunistic replacement of std::vector with SmallVector, as it's in a path that obviously always allocates.
1 parent 774893d commit d2b935e

32 files changed

+59
-58
lines changed

clang/include/clang/AST/CXXInheritance.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ struct UniqueVirtualMethod {
268268
/// subobject in which that virtual function occurs).
269269
class OverridingMethods {
270270
using ValuesT = SmallVector<UniqueVirtualMethod, 4>;
271-
using MapType = llvm::MapVector<unsigned, ValuesT>;
271+
using MapType = llvm::SmallMapVector<unsigned, ValuesT, 16>;
272272

273273
MapType Overrides;
274274

clang/lib/AST/ItaniumMangle.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,8 @@ class CXXNameMangler {
392392
AbiTagState *AbiTags = nullptr;
393393
AbiTagState AbiTagsRoot;
394394

395-
llvm::DenseMap<uintptr_t, unsigned> Substitutions;
396-
llvm::DenseMap<StringRef, unsigned> ModuleSubstitutions;
395+
llvm::SmallDenseMap<uintptr_t, unsigned, 16> Substitutions;
396+
llvm::SmallDenseMap<StringRef, unsigned, 16> ModuleSubstitutions;
397397

398398
ASTContext &getASTContext() const { return Context.getASTContext(); }
399399

llvm/include/llvm/ADT/SCCIterator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class scc_iterator : public iterator_facade_base<
7373
///
7474
/// nodeVisitNumbers are per-node visit numbers, also used as DFS flags.
7575
unsigned visitNum;
76-
DenseMap<NodeRef, unsigned> nodeVisitNumbers;
76+
SmallDenseMap<NodeRef, unsigned, 16> nodeVisitNumbers;
7777

7878
/// Stack holding nodes of the SCC.
7979
std::vector<NodeRef> SCCNodeStack;

llvm/include/llvm/Analysis/ConstraintSystem.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class ConstraintSystem {
5151

5252
/// A map of variables (IR values) to their corresponding index in the
5353
/// constraint system.
54-
DenseMap<Value *, unsigned> Value2Index;
54+
SmallDenseMap<Value *, unsigned, 16> Value2Index;
5555

5656
// Eliminate constraints from the system using Fourier–Motzkin elimination.
5757
bool eliminateUsingFM();
@@ -70,7 +70,7 @@ class ConstraintSystem {
7070
Value2Index.insert({Arg, Value2Index.size() + 1});
7171
}
7272
}
73-
ConstraintSystem(const DenseMap<Value *, unsigned> &Value2Index)
73+
ConstraintSystem(const SmallDenseMap<Value *, unsigned, 16> &Value2Index)
7474
: NumVariables(Value2Index.size()), Value2Index(Value2Index) {}
7575

7676
bool addVariableRow(ArrayRef<int64_t> R) {
@@ -92,8 +92,8 @@ class ConstraintSystem {
9292
return true;
9393
}
9494

95-
DenseMap<Value *, unsigned> &getValue2Index() { return Value2Index; }
96-
const DenseMap<Value *, unsigned> &getValue2Index() const {
95+
SmallDenseMap<Value *, unsigned, 16> &getValue2Index() { return Value2Index; }
96+
const SmallDenseMap<Value *, unsigned, 16> &getValue2Index() const {
9797
return Value2Index;
9898
}
9999

llvm/include/llvm/Analysis/DominanceFrontier.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ class DominanceFrontierBase {
4141
public:
4242
// Dom set for a bb. Use SetVector to make iterating dom frontiers of a bb
4343
// deterministic.
44-
using DomSetType = SetVector<BlockT *>;
45-
using DomSetMapType = DenseMap<BlockT *, DomSetType>; // Dom set map
44+
using DomSetType = SmallSetVector<BlockT *, 16>;
45+
using DomSetMapType = SmallDenseMap<BlockT *, DomSetType, 16>; // Dom set map
4646

4747
protected:
4848
using BlockTraits = GraphTraits<BlockT *>;

llvm/include/llvm/Analysis/DominanceFrontierImpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void DominanceFrontierBase<BlockT, IsPostDom>::print(raw_ostream &OS) const {
5555
OS << " <<exit node>>";
5656
OS << " is:\t";
5757

58-
const SetVector<BlockT *> &BBs = I->second;
58+
const SmallSetVector<BlockT *, 16> &BBs = I->second;
5959

6060
for (const BlockT *BB : BBs) {
6161
OS << ' ';

llvm/include/llvm/Analysis/LoopIterator.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ struct LoopBodyTraits {
9797
class LoopBlocksDFS {
9898
public:
9999
/// Postorder list iterators.
100-
typedef std::vector<BasicBlock*>::const_iterator POIterator;
101-
typedef std::vector<BasicBlock*>::const_reverse_iterator RPOIterator;
100+
typedef SmallVector<BasicBlock*, 16>::const_iterator POIterator;
101+
typedef SmallVector<BasicBlock*, 16>::const_reverse_iterator RPOIterator;
102102

103103
friend class LoopBlocksTraversal;
104104

@@ -108,8 +108,8 @@ class LoopBlocksDFS {
108108
/// Map each block to its postorder number. A block is only mapped after it is
109109
/// preorder visited by DFS. It's postorder number is initially zero and set
110110
/// to nonzero after it is finished by postorder traversal.
111-
DenseMap<BasicBlock*, unsigned> PostNumbers;
112-
std::vector<BasicBlock*> PostBlocks;
111+
SmallDenseMap<BasicBlock*, unsigned, 16> PostNumbers;
112+
SmallVector<BasicBlock*, 16> PostBlocks;
113113

114114
public:
115115
LoopBlocksDFS(Loop *Container) :

llvm/include/llvm/Analysis/MemorySSA.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,7 @@ class MemorySSA {
879879
Loop *L = nullptr;
880880

881881
// Memory SSA mappings
882-
DenseMap<const Value *, MemoryAccess *> ValueToMemoryAccess;
882+
SmallDenseMap<const Value *, MemoryAccess *, 16> ValueToMemoryAccess;
883883

884884
// These two mappings contain the main block to access/def mappings for
885885
// MemorySSA. The list contained in PerBlockAccesses really owns all the
@@ -895,7 +895,7 @@ class MemorySSA {
895895
// Note that the numbering is local to a block, even though the map is
896896
// global.
897897
mutable SmallPtrSet<const BasicBlock *, 16> BlockNumberingValid;
898-
mutable DenseMap<const MemoryAccess *, unsigned long> BlockNumbering;
898+
mutable SmallDenseMap<const MemoryAccess *, unsigned long, 16> BlockNumbering;
899899

900900
// Memory SSA building info
901901
std::unique_ptr<ClobberWalkerBase> WalkerBase;

llvm/include/llvm/Analysis/MustExecute.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,15 @@ class raw_ostream;
5858
/// methods except for computeLoopSafetyInfo is undefined.
5959
class LoopSafetyInfo {
6060
// Used to update funclet bundle operands.
61-
DenseMap<BasicBlock *, ColorVector> BlockColors;
61+
BlockColorMapT BlockColors;
6262

6363
protected:
6464
/// Computes block colors.
6565
void computeBlockColors(const Loop *CurLoop);
6666

6767
public:
6868
/// Returns block colors map that is used to update funclet operand bundles.
69-
const DenseMap<BasicBlock *, ColorVector> &getBlockColors() const;
69+
const BlockColorMapT &getBlockColors() const;
7070

7171
/// Copy colors of block \p Old into the block \p New.
7272
void copyColors(BasicBlock *New, BasicBlock *Old);

llvm/include/llvm/IR/EHPersonalities.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,13 @@ inline bool isNoOpWithoutInvoke(EHPersonality Pers) {
107107
bool canSimplifyInvokeNoUnwind(const Function *F);
108108

109109
typedef TinyPtrVector<BasicBlock *> ColorVector;
110+
typedef SmallDenseMap<BasicBlock *, ColorVector, 16> BlockColorMapT;
110111

111112
/// If an EH funclet personality is in use (see isFuncletEHPersonality),
112113
/// this will recompute which blocks are in which funclet. It is possible that
113114
/// some blocks are in multiple funclets. Consider this analysis to be
114115
/// expensive.
115-
DenseMap<BasicBlock *, ColorVector> colorEHFunclets(Function &F);
116+
BlockColorMapT colorEHFunclets(Function &F);
116117

117118
} // end namespace llvm
118119

0 commit comments

Comments
 (0)