https://github.com/jmorse created https://github.com/llvm/llvm-project/pull/111836
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. Compared to the other patches reducing DenseMap allocations the benefits from this one are quite small -- I've reached the point of diminishing returns: https://llvm-compile-time-tracker.com/compare.php?from=c7fbcae72557cbe14bca615038254649c1177401&to=0785a8d0fd31541d6a8af616111312780e268611&stat=instructions:u >From d2b935e3a537e065b00f543a1792d1979ba413d9 Mon Sep 17 00:00:00 2001 From: Jeremy Morse <jeremy.mo...@sony.com> Date: Thu, 10 Oct 2024 14:17:34 +0100 Subject: [PATCH] [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. --- clang/include/clang/AST/CXXInheritance.h | 2 +- clang/lib/AST/ItaniumMangle.cpp | 4 ++-- llvm/include/llvm/ADT/SCCIterator.h | 2 +- llvm/include/llvm/Analysis/ConstraintSystem.h | 8 ++++---- llvm/include/llvm/Analysis/DominanceFrontier.h | 4 ++-- llvm/include/llvm/Analysis/DominanceFrontierImpl.h | 2 +- llvm/include/llvm/Analysis/LoopIterator.h | 8 ++++---- llvm/include/llvm/Analysis/MemorySSA.h | 4 ++-- llvm/include/llvm/Analysis/MustExecute.h | 4 ++-- llvm/include/llvm/IR/EHPersonalities.h | 3 ++- llvm/include/llvm/IR/PredIteratorCache.h | 2 +- llvm/include/llvm/Transforms/Utils/Cloning.h | 2 +- llvm/include/llvm/Transforms/Utils/SSAUpdaterImpl.h | 2 +- llvm/lib/Analysis/InlineCost.cpp | 2 +- llvm/lib/Analysis/LazyValueInfo.cpp | 2 +- llvm/lib/Analysis/MustExecute.cpp | 2 +- llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp | 2 +- llvm/lib/CodeGen/MachineSSAUpdater.cpp | 2 +- llvm/lib/CodeGen/WinEHPrepare.cpp | 4 ++-- llvm/lib/IR/EHPersonalities.cpp | 4 ++-- llvm/lib/IR/Verifier.cpp | 2 +- llvm/lib/Target/X86/X86WinEHState.cpp | 10 +++++----- .../Transforms/InstCombine/InstructionCombining.cpp | 2 +- .../Transforms/Instrumentation/AddressSanitizer.cpp | 2 +- .../Transforms/Instrumentation/PGOInstrumentation.cpp | 4 ++-- llvm/lib/Transforms/ObjCARC/ObjCARC.cpp | 6 +++--- llvm/lib/Transforms/ObjCARC/ObjCARC.h | 4 ++-- llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp | 10 +++++----- llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp | 2 +- llvm/lib/Transforms/Scalar/ConstraintElimination.cpp | 6 +++--- llvm/lib/Transforms/Scalar/Reassociate.cpp | 2 +- llvm/lib/Transforms/Utils/SSAUpdater.cpp | 2 +- 32 files changed, 59 insertions(+), 58 deletions(-) diff --git a/clang/include/clang/AST/CXXInheritance.h b/clang/include/clang/AST/CXXInheritance.h index bbef01843e0b0a..b9057e15a41988 100644 --- a/clang/include/clang/AST/CXXInheritance.h +++ b/clang/include/clang/AST/CXXInheritance.h @@ -268,7 +268,7 @@ struct UniqueVirtualMethod { /// subobject in which that virtual function occurs). class OverridingMethods { using ValuesT = SmallVector<UniqueVirtualMethod, 4>; - using MapType = llvm::MapVector<unsigned, ValuesT>; + using MapType = llvm::SmallMapVector<unsigned, ValuesT, 16>; MapType Overrides; diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp index 777cdca1a0c0d7..0ec0855cf52440 100644 --- a/clang/lib/AST/ItaniumMangle.cpp +++ b/clang/lib/AST/ItaniumMangle.cpp @@ -392,8 +392,8 @@ class CXXNameMangler { AbiTagState *AbiTags = nullptr; AbiTagState AbiTagsRoot; - llvm::DenseMap<uintptr_t, unsigned> Substitutions; - llvm::DenseMap<StringRef, unsigned> ModuleSubstitutions; + llvm::SmallDenseMap<uintptr_t, unsigned, 16> Substitutions; + llvm::SmallDenseMap<StringRef, unsigned, 16> ModuleSubstitutions; ASTContext &getASTContext() const { return Context.getASTContext(); } diff --git a/llvm/include/llvm/ADT/SCCIterator.h b/llvm/include/llvm/ADT/SCCIterator.h index 3bd103c13f19f9..a35e0a3f8e8c95 100644 --- a/llvm/include/llvm/ADT/SCCIterator.h +++ b/llvm/include/llvm/ADT/SCCIterator.h @@ -73,7 +73,7 @@ class scc_iterator : public iterator_facade_base< /// /// nodeVisitNumbers are per-node visit numbers, also used as DFS flags. unsigned visitNum; - DenseMap<NodeRef, unsigned> nodeVisitNumbers; + SmallDenseMap<NodeRef, unsigned, 16> nodeVisitNumbers; /// Stack holding nodes of the SCC. std::vector<NodeRef> SCCNodeStack; diff --git a/llvm/include/llvm/Analysis/ConstraintSystem.h b/llvm/include/llvm/Analysis/ConstraintSystem.h index 449852343964ca..2ac0fc1ddc06c3 100644 --- a/llvm/include/llvm/Analysis/ConstraintSystem.h +++ b/llvm/include/llvm/Analysis/ConstraintSystem.h @@ -51,7 +51,7 @@ class ConstraintSystem { /// A map of variables (IR values) to their corresponding index in the /// constraint system. - DenseMap<Value *, unsigned> Value2Index; + SmallDenseMap<Value *, unsigned, 16> Value2Index; // Eliminate constraints from the system using Fourier–Motzkin elimination. bool eliminateUsingFM(); @@ -70,7 +70,7 @@ class ConstraintSystem { Value2Index.insert({Arg, Value2Index.size() + 1}); } } - ConstraintSystem(const DenseMap<Value *, unsigned> &Value2Index) + ConstraintSystem(const SmallDenseMap<Value *, unsigned, 16> &Value2Index) : NumVariables(Value2Index.size()), Value2Index(Value2Index) {} bool addVariableRow(ArrayRef<int64_t> R) { @@ -92,8 +92,8 @@ class ConstraintSystem { return true; } - DenseMap<Value *, unsigned> &getValue2Index() { return Value2Index; } - const DenseMap<Value *, unsigned> &getValue2Index() const { + SmallDenseMap<Value *, unsigned, 16> &getValue2Index() { return Value2Index; } + const SmallDenseMap<Value *, unsigned, 16> &getValue2Index() const { return Value2Index; } diff --git a/llvm/include/llvm/Analysis/DominanceFrontier.h b/llvm/include/llvm/Analysis/DominanceFrontier.h index 68ddcf753b59f7..394379d9750827 100644 --- a/llvm/include/llvm/Analysis/DominanceFrontier.h +++ b/llvm/include/llvm/Analysis/DominanceFrontier.h @@ -41,8 +41,8 @@ class DominanceFrontierBase { public: // Dom set for a bb. Use SetVector to make iterating dom frontiers of a bb // deterministic. - using DomSetType = SetVector<BlockT *>; - using DomSetMapType = DenseMap<BlockT *, DomSetType>; // Dom set map + using DomSetType = SmallSetVector<BlockT *, 16>; + using DomSetMapType = SmallDenseMap<BlockT *, DomSetType, 16>; // Dom set map protected: using BlockTraits = GraphTraits<BlockT *>; diff --git a/llvm/include/llvm/Analysis/DominanceFrontierImpl.h b/llvm/include/llvm/Analysis/DominanceFrontierImpl.h index e877b2c4749abe..165e137a5ecfc0 100644 --- a/llvm/include/llvm/Analysis/DominanceFrontierImpl.h +++ b/llvm/include/llvm/Analysis/DominanceFrontierImpl.h @@ -55,7 +55,7 @@ void DominanceFrontierBase<BlockT, IsPostDom>::print(raw_ostream &OS) const { OS << " <<exit node>>"; OS << " is:\t"; - const SetVector<BlockT *> &BBs = I->second; + const SmallSetVector<BlockT *, 16> &BBs = I->second; for (const BlockT *BB : BBs) { OS << ' '; diff --git a/llvm/include/llvm/Analysis/LoopIterator.h b/llvm/include/llvm/Analysis/LoopIterator.h index 523d2a21825d0d..aaca0298d21da4 100644 --- a/llvm/include/llvm/Analysis/LoopIterator.h +++ b/llvm/include/llvm/Analysis/LoopIterator.h @@ -97,8 +97,8 @@ struct LoopBodyTraits { class LoopBlocksDFS { public: /// Postorder list iterators. - typedef std::vector<BasicBlock*>::const_iterator POIterator; - typedef std::vector<BasicBlock*>::const_reverse_iterator RPOIterator; + typedef SmallVector<BasicBlock*, 16>::const_iterator POIterator; + typedef SmallVector<BasicBlock*, 16>::const_reverse_iterator RPOIterator; friend class LoopBlocksTraversal; @@ -108,8 +108,8 @@ class LoopBlocksDFS { /// Map each block to its postorder number. A block is only mapped after it is /// preorder visited by DFS. It's postorder number is initially zero and set /// to nonzero after it is finished by postorder traversal. - DenseMap<BasicBlock*, unsigned> PostNumbers; - std::vector<BasicBlock*> PostBlocks; + SmallDenseMap<BasicBlock*, unsigned, 16> PostNumbers; + SmallVector<BasicBlock*, 16> PostBlocks; public: LoopBlocksDFS(Loop *Container) : diff --git a/llvm/include/llvm/Analysis/MemorySSA.h b/llvm/include/llvm/Analysis/MemorySSA.h index 09fc34af60dc3c..1ceabfa1b13cf9 100644 --- a/llvm/include/llvm/Analysis/MemorySSA.h +++ b/llvm/include/llvm/Analysis/MemorySSA.h @@ -879,7 +879,7 @@ class MemorySSA { Loop *L = nullptr; // Memory SSA mappings - DenseMap<const Value *, MemoryAccess *> ValueToMemoryAccess; + SmallDenseMap<const Value *, MemoryAccess *, 16> ValueToMemoryAccess; // These two mappings contain the main block to access/def mappings for // MemorySSA. The list contained in PerBlockAccesses really owns all the @@ -895,7 +895,7 @@ class MemorySSA { // Note that the numbering is local to a block, even though the map is // global. mutable SmallPtrSet<const BasicBlock *, 16> BlockNumberingValid; - mutable DenseMap<const MemoryAccess *, unsigned long> BlockNumbering; + mutable SmallDenseMap<const MemoryAccess *, unsigned long, 16> BlockNumbering; // Memory SSA building info std::unique_ptr<ClobberWalkerBase> WalkerBase; diff --git a/llvm/include/llvm/Analysis/MustExecute.h b/llvm/include/llvm/Analysis/MustExecute.h index 8ac3c5eb653cd4..e49b6facf76b53 100644 --- a/llvm/include/llvm/Analysis/MustExecute.h +++ b/llvm/include/llvm/Analysis/MustExecute.h @@ -58,7 +58,7 @@ class raw_ostream; /// methods except for computeLoopSafetyInfo is undefined. class LoopSafetyInfo { // Used to update funclet bundle operands. - DenseMap<BasicBlock *, ColorVector> BlockColors; + BlockColorMapT BlockColors; protected: /// Computes block colors. @@ -66,7 +66,7 @@ class LoopSafetyInfo { public: /// Returns block colors map that is used to update funclet operand bundles. - const DenseMap<BasicBlock *, ColorVector> &getBlockColors() const; + const BlockColorMapT &getBlockColors() const; /// Copy colors of block \p Old into the block \p New. void copyColors(BasicBlock *New, BasicBlock *Old); diff --git a/llvm/include/llvm/IR/EHPersonalities.h b/llvm/include/llvm/IR/EHPersonalities.h index c70f832de40b40..2dcb7511ba4dfc 100644 --- a/llvm/include/llvm/IR/EHPersonalities.h +++ b/llvm/include/llvm/IR/EHPersonalities.h @@ -107,12 +107,13 @@ inline bool isNoOpWithoutInvoke(EHPersonality Pers) { bool canSimplifyInvokeNoUnwind(const Function *F); typedef TinyPtrVector<BasicBlock *> ColorVector; +typedef SmallDenseMap<BasicBlock *, ColorVector, 16> BlockColorMapT; /// If an EH funclet personality is in use (see isFuncletEHPersonality), /// this will recompute which blocks are in which funclet. It is possible that /// some blocks are in multiple funclets. Consider this analysis to be /// expensive. -DenseMap<BasicBlock *, ColorVector> colorEHFunclets(Function &F); +BlockColorMapT colorEHFunclets(Function &F); } // end namespace llvm diff --git a/llvm/include/llvm/IR/PredIteratorCache.h b/llvm/include/llvm/IR/PredIteratorCache.h index ba3228347076b8..055ab91a522668 100644 --- a/llvm/include/llvm/IR/PredIteratorCache.h +++ b/llvm/include/llvm/IR/PredIteratorCache.h @@ -26,7 +26,7 @@ namespace llvm { /// wants the predecessor list for the same blocks. class PredIteratorCache { /// Cached list of predecessors, allocated in Memory. - DenseMap<BasicBlock *, ArrayRef<BasicBlock *>> BlockToPredsMap; + SmallDenseMap<BasicBlock *, ArrayRef<BasicBlock *>, 16> BlockToPredsMap; /// Memory - This is the space that holds cached preds. BumpPtrAllocator Memory; diff --git a/llvm/include/llvm/Transforms/Utils/Cloning.h b/llvm/include/llvm/Transforms/Utils/Cloning.h index a4be24e32c5279..3f27cc0cf449db 100644 --- a/llvm/include/llvm/Transforms/Utils/Cloning.h +++ b/llvm/include/llvm/Transforms/Utils/Cloning.h @@ -81,7 +81,7 @@ struct ClonedCodeInfo { /// Like VMap, but maps only unsimplified instructions. Values in the map /// may be dangling, it is only intended to be used via isSimplified(), to /// check whether the main VMap mapping involves simplification or not. - DenseMap<const Value *, const Value *> OrigVMap; + SmallDenseMap<const Value *, const Value *, 16> OrigVMap; ClonedCodeInfo() = default; diff --git a/llvm/include/llvm/Transforms/Utils/SSAUpdaterImpl.h b/llvm/include/llvm/Transforms/Utils/SSAUpdaterImpl.h index 746926e5bee331..089a7d05ca0949 100644 --- a/llvm/include/llvm/Transforms/Utils/SSAUpdaterImpl.h +++ b/llvm/include/llvm/Transforms/Utils/SSAUpdaterImpl.h @@ -70,7 +70,7 @@ class SSAUpdaterImpl { : BB(ThisBB), AvailableVal(V), DefBB(V ? this : nullptr) {} }; - using AvailableValsTy = DenseMap<BlkT *, ValT>; + using AvailableValsTy = SmallDenseMap<BlkT *, ValT, 16>; AvailableValsTy *AvailableVals; diff --git a/llvm/lib/Analysis/InlineCost.cpp b/llvm/lib/Analysis/InlineCost.cpp index d2c329ba748e58..3ad137382cd5fc 100644 --- a/llvm/lib/Analysis/InlineCost.cpp +++ b/llvm/lib/Analysis/InlineCost.cpp @@ -608,7 +608,7 @@ class InlineCostCallAnalyzer final : public CallAnalyzer { /// The mapping of caller Alloca values to their accumulated cost savings. If /// we have to disable SROA for one of the allocas, this tells us how much /// cost must be added. - DenseMap<AllocaInst *, int> SROAArgCosts; + SmallDenseMap<AllocaInst *, int, 16> SROAArgCosts; /// Return true if \p Call is a cold callsite. bool isColdCallSite(CallBase &Call, BlockFrequencyInfo *CallerBFI); diff --git a/llvm/lib/Analysis/LazyValueInfo.cpp b/llvm/lib/Analysis/LazyValueInfo.cpp index 30dc4ae30dbfa5..d7e663d60d8dc8 100644 --- a/llvm/lib/Analysis/LazyValueInfo.cpp +++ b/llvm/lib/Analysis/LazyValueInfo.cpp @@ -322,7 +322,7 @@ class LazyValueInfoImpl { SmallVector<std::pair<BasicBlock*, Value*>, 8> BlockValueStack; /// Keeps track of which block-value pairs are in BlockValueStack. - DenseSet<std::pair<BasicBlock*, Value*> > BlockValueSet; + SmallDenseSet<std::pair<BasicBlock*, Value*>, 16> BlockValueSet; /// Push BV onto BlockValueStack unless it's already in there. /// Returns true on success. diff --git a/llvm/lib/Analysis/MustExecute.cpp b/llvm/lib/Analysis/MustExecute.cpp index caed62679a683c..52d631b56beb7b 100644 --- a/llvm/lib/Analysis/MustExecute.cpp +++ b/llvm/lib/Analysis/MustExecute.cpp @@ -28,7 +28,7 @@ using namespace llvm; #define DEBUG_TYPE "must-execute" -const DenseMap<BasicBlock *, ColorVector> & +const BlockColorMapT & LoopSafetyInfo::getBlockColors() const { return BlockColors; } diff --git a/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp b/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp index a9d28a39c4418b..2b65d2ed45b516 100644 --- a/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp +++ b/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp @@ -4151,7 +4151,7 @@ std::optional<ValueIDNum> InstrRefBasedLDV::resolveDbgPHIsImpl( // Adapted LLVM SSA Updater: LDVSSAUpdater Updater(Loc, MLiveIns); // Map of which Def or PHI is the current value in each block. - DenseMap<LDVSSABlock *, BlockValueNum> AvailableValues; + SmallDenseMap<LDVSSABlock *, BlockValueNum, 16> AvailableValues; // Set of PHIs that we have created along the way. SmallVector<LDVSSAPhi *, 8> CreatedPHIs; diff --git a/llvm/lib/CodeGen/MachineSSAUpdater.cpp b/llvm/lib/CodeGen/MachineSSAUpdater.cpp index 4cbb6ad3128bd9..186f729859092e 100644 --- a/llvm/lib/CodeGen/MachineSSAUpdater.cpp +++ b/llvm/lib/CodeGen/MachineSSAUpdater.cpp @@ -34,7 +34,7 @@ using namespace llvm; #define DEBUG_TYPE "machine-ssaupdater" -using AvailableValsTy = DenseMap<MachineBasicBlock *, Register>; +using AvailableValsTy = SmallDenseMap<MachineBasicBlock *, Register, 16>; static AvailableValsTy &getAvailableVals(void *AV) { return *static_cast<AvailableValsTy*>(AV); diff --git a/llvm/lib/CodeGen/WinEHPrepare.cpp b/llvm/lib/CodeGen/WinEHPrepare.cpp index c58c67b70fe3c2..07057d4fe69375 100644 --- a/llvm/lib/CodeGen/WinEHPrepare.cpp +++ b/llvm/lib/CodeGen/WinEHPrepare.cpp @@ -90,7 +90,7 @@ class WinEHPrepareImpl { EHPersonality Personality = EHPersonality::Unknown; const DataLayout *DL = nullptr; - DenseMap<BasicBlock *, ColorVector> BlockColors; + BlockColorMapT BlockColors; MapVector<BasicBlock *, std::vector<BasicBlock *>> FuncletBlocks; }; @@ -189,7 +189,7 @@ static BasicBlock *getCleanupRetUnwindDest(const CleanupPadInst *CleanupPad) { static void calculateStateNumbersForInvokes(const Function *Fn, WinEHFuncInfo &FuncInfo) { auto *F = const_cast<Function *>(Fn); - DenseMap<BasicBlock *, ColorVector> BlockColors = colorEHFunclets(*F); + BlockColorMapT BlockColors = colorEHFunclets(*F); for (BasicBlock &BB : *F) { auto *II = dyn_cast<InvokeInst>(BB.getTerminator()); if (!II) diff --git a/llvm/lib/IR/EHPersonalities.cpp b/llvm/lib/IR/EHPersonalities.cpp index 7c32601b8a83ea..08cbd92cc38baf 100644 --- a/llvm/lib/IR/EHPersonalities.cpp +++ b/llvm/lib/IR/EHPersonalities.cpp @@ -102,10 +102,10 @@ bool llvm::canSimplifyInvokeNoUnwind(const Function *F) { return !EHa && !isAsynchronousEHPersonality(Personality); } -DenseMap<BasicBlock *, ColorVector> llvm::colorEHFunclets(Function &F) { +BlockColorMapT llvm::colorEHFunclets(Function &F) { SmallVector<std::pair<BasicBlock *, BasicBlock *>, 16> Worklist; BasicBlock *EntryBlock = &F.getEntryBlock(); - DenseMap<BasicBlock *, ColorVector> BlockColors; + BlockColorMapT BlockColors; // Build up the color map, which maps each block to its set of 'colors'. // For any block B the "colors" of B are the set of funclets F (possibly diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp index b89c9ce46e7d61..2d594945ca839f 100644 --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -363,7 +363,7 @@ class Verifier : public InstVisitor<Verifier>, VerifierSupport { /// Cache which blocks are in which funclet, if an EH funclet personality is /// in use. Otherwise empty. - DenseMap<BasicBlock *, ColorVector> BlockEHFuncletColors; + BlockColorMapT BlockEHFuncletColors; /// Cache of constants visited in search of ConstantExprs. SmallPtrSet<const Constant *, 32> ConstantExprVisited; diff --git a/llvm/lib/Target/X86/X86WinEHState.cpp b/llvm/lib/Target/X86/X86WinEHState.cpp index 963d613ddbfe7d..199f8438c61e8e 100644 --- a/llvm/lib/Target/X86/X86WinEHState.cpp +++ b/llvm/lib/Target/X86/X86WinEHState.cpp @@ -70,9 +70,9 @@ class WinEHStatePass : public FunctionPass { bool isStateStoreNeeded(EHPersonality Personality, CallBase &Call); void rewriteSetJmpCall(IRBuilder<> &Builder, Function &F, CallBase &Call, Value *State); - int getBaseStateForBB(DenseMap<BasicBlock *, ColorVector> &BlockColors, + int getBaseStateForBB(BlockColorMapT &BlockColors, WinEHFuncInfo &FuncInfo, BasicBlock *BB); - int getStateForCall(DenseMap<BasicBlock *, ColorVector> &BlockColors, + int getStateForCall(BlockColorMapT &BlockColors, WinEHFuncInfo &FuncInfo, CallBase &Call); // Module-level type getters. @@ -501,7 +501,7 @@ void WinEHStatePass::rewriteSetJmpCall(IRBuilder<> &Builder, Function &F, // Figure out what state we should assign calls in this block. int WinEHStatePass::getBaseStateForBB( - DenseMap<BasicBlock *, ColorVector> &BlockColors, WinEHFuncInfo &FuncInfo, + BlockColorMapT &BlockColors, WinEHFuncInfo &FuncInfo, BasicBlock *BB) { int BaseState = ParentBaseState; auto &BBColors = BlockColors[BB]; @@ -520,7 +520,7 @@ int WinEHStatePass::getBaseStateForBB( // Calculate the state a call-site is in. int WinEHStatePass::getStateForCall( - DenseMap<BasicBlock *, ColorVector> &BlockColors, WinEHFuncInfo &FuncInfo, + BlockColorMapT &BlockColors, WinEHFuncInfo &FuncInfo, CallBase &Call) { if (auto *II = dyn_cast<InvokeInst>(&Call)) { // Look up the state number of the EH pad this unwinds to. @@ -644,7 +644,7 @@ void WinEHStatePass::addStateStores(Function &F, WinEHFuncInfo &FuncInfo) { calculateWinCXXEHStateNumbers(&F, FuncInfo); // Iterate all the instructions and emit state number stores. - DenseMap<BasicBlock *, ColorVector> BlockColors = colorEHFunclets(F); + BlockColorMapT BlockColors = colorEHFunclets(F); ReversePostOrderTraversal<Function *> RPOT(&F); // InitialStates yields the state of the first call-site for a BasicBlock. diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp index 1f4a6f793404cf..fbd11292115c2b 100644 --- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -5307,7 +5307,7 @@ bool InstCombinerImpl::prepareWorklist(Function &F) { bool MadeIRChange = false; SmallPtrSet<BasicBlock *, 32> LiveBlocks; SmallVector<Instruction *, 128> InstrsForInstructionWorklist; - DenseMap<Constant *, Constant *> FoldedConstants; + SmallDenseMap<Constant *, Constant *, 16> FoldedConstants; AliasScopeTracker SeenAliasScopes; auto HandleOnlyLiveSuccessor = [&](BasicBlock *BB, BasicBlock *LiveSucc) { diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp index 2ad89b5ba753a5..4665304632c9bd 100644 --- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp @@ -669,7 +669,7 @@ class RuntimeCallInserter { return; assert(TrackInsertedCalls && "Calls were wrongly tracked"); - DenseMap<BasicBlock *, ColorVector> BlockColors = colorEHFunclets(*OwnerFn); + BlockColorMapT BlockColors = colorEHFunclets(*OwnerFn); for (CallInst *CI : InsertedCalls) { BasicBlock *BB = CI->getParent(); assert(BB && "Instruction doesn't belong to a BasicBlock"); diff --git a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp index 10442fa0bb9003..164ffbec26421a 100644 --- a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp +++ b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp @@ -864,7 +864,7 @@ BasicBlock *FuncPGOInstrumentation<Edge, BBInfo>::getInstrBB(Edge *E) { // value profiling call for the value profile candidate call. static void populateEHOperandBundle(VPCandidateInfo &Cand, - DenseMap<BasicBlock *, ColorVector> &BlockColors, + BlockColorMapT &BlockColors, SmallVectorImpl<OperandBundleDef> &OpBundles) { auto *OrigCall = dyn_cast<CallBase>(Cand.AnnotatedInst); if (!OrigCall) @@ -1006,7 +1006,7 @@ void FunctionInstrumenter::instrument() { // Windows exception handling attached to them. However, if value profiling is // inserted for one of these calls, then a funclet value will need to be set // on the instrumentation call based on the funclet coloring. - DenseMap<BasicBlock *, ColorVector> BlockColors; + BlockColorMapT BlockColors; if (F.hasPersonalityFn() && isScopedEHPersonality(classifyEHPersonality(F.getPersonalityFn()))) BlockColors = colorEHFunclets(F); diff --git a/llvm/lib/Transforms/ObjCARC/ObjCARC.cpp b/llvm/lib/Transforms/ObjCARC/ObjCARC.cpp index 33870d7ea192a3..4745bb9bbcbb74 100644 --- a/llvm/lib/Transforms/ObjCARC/ObjCARC.cpp +++ b/llvm/lib/Transforms/ObjCARC/ObjCARC.cpp @@ -24,7 +24,7 @@ using namespace llvm::objcarc; CallInst *objcarc::createCallInstWithColors( FunctionCallee Func, ArrayRef<Value *> Args, const Twine &NameStr, BasicBlock::iterator InsertBefore, - const DenseMap<BasicBlock *, ColorVector> &BlockColors) { + const BlockColorMapT &BlockColors) { FunctionType *FTy = Func.getFunctionType(); Value *Callee = Func.getCallee(); SmallVector<OperandBundleDef, 1> OpBundles; @@ -73,13 +73,13 @@ BundledRetainClaimRVs::insertAfterInvokes(Function &F, DominatorTree *DT) { CallInst *BundledRetainClaimRVs::insertRVCall(BasicBlock::iterator InsertPt, CallBase *AnnotatedCall) { - DenseMap<BasicBlock *, ColorVector> BlockColors; + BlockColorMapT BlockColors; return insertRVCallWithColors(InsertPt, AnnotatedCall, BlockColors); } CallInst *BundledRetainClaimRVs::insertRVCallWithColors( BasicBlock::iterator InsertPt, CallBase *AnnotatedCall, - const DenseMap<BasicBlock *, ColorVector> &BlockColors) { + const BlockColorMapT &BlockColors) { IRBuilder<> Builder(InsertPt->getParent(), InsertPt); Function *Func = *objcarc::getAttachedARCFunction(AnnotatedCall); assert(Func && "operand isn't a Function"); diff --git a/llvm/lib/Transforms/ObjCARC/ObjCARC.h b/llvm/lib/Transforms/ObjCARC/ObjCARC.h index f4d7c92d499c1f..fe08aec6d4c17b 100644 --- a/llvm/lib/Transforms/ObjCARC/ObjCARC.h +++ b/llvm/lib/Transforms/ObjCARC/ObjCARC.h @@ -100,7 +100,7 @@ static inline MDString *getRVInstMarker(Module &M) { CallInst *createCallInstWithColors( FunctionCallee Func, ArrayRef<Value *> Args, const Twine &NameStr, BasicBlock::iterator InsertBefore, - const DenseMap<BasicBlock *, ColorVector> &BlockColors); + const BlockColorMapT &BlockColors); class BundledRetainClaimRVs { public: @@ -119,7 +119,7 @@ class BundledRetainClaimRVs { /// Insert a retainRV/claimRV call with colors. CallInst *insertRVCallWithColors( BasicBlock::iterator InsertPt, CallBase *AnnotatedCall, - const DenseMap<BasicBlock *, ColorVector> &BlockColors); + const BlockColorMapT &BlockColors); /// See if an instruction is a bundled retainRV/claimRV call. bool contains(const Instruction *I) const { diff --git a/llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp b/llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp index 2c8b4e76312a0d..60ba0a8752d845 100644 --- a/llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp +++ b/llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp @@ -88,7 +88,7 @@ class ObjCARCContract { bool tryToPeepholeInstruction( Function &F, Instruction *Inst, inst_iterator &Iter, bool &TailOkForStoreStrong, - const DenseMap<BasicBlock *, ColorVector> &BlockColors); + const BlockColorMapT &BlockColors); bool optimizeRetainCall(Function &F, Instruction *Retain); @@ -97,7 +97,7 @@ class ObjCARCContract { void tryToContractReleaseIntoStoreStrong( Instruction *Release, inst_iterator &Iter, - const DenseMap<BasicBlock *, ColorVector> &BlockColors); + const BlockColorMapT &BlockColors); public: bool init(Module &M); @@ -338,7 +338,7 @@ findRetainForStoreStrongContraction(Value *New, StoreInst *Store, /// safe. void ObjCARCContract::tryToContractReleaseIntoStoreStrong( Instruction *Release, inst_iterator &Iter, - const DenseMap<BasicBlock *, ColorVector> &BlockColors) { + const BlockColorMapT &BlockColors) { // See if we are releasing something that we just loaded. auto *Load = dyn_cast<LoadInst>(GetArgRCIdentityRoot(Release)); if (!Load || !Load->isSimple()) @@ -415,7 +415,7 @@ void ObjCARCContract::tryToContractReleaseIntoStoreStrong( bool ObjCARCContract::tryToPeepholeInstruction( Function &F, Instruction *Inst, inst_iterator &Iter, bool &TailOkForStoreStrongs, - const DenseMap<BasicBlock *, ColorVector> &BlockColors) { + const BlockColorMapT &BlockColors) { // Only these library routines return their argument. In particular, // objc_retainBlock does not necessarily return its argument. ARCInstKind Class = GetBasicARCInstKind(Inst); @@ -561,7 +561,7 @@ bool ObjCARCContract::run(Function &F, AAResults *A, DominatorTree *D) { Changed |= R.first; CFGChanged |= R.second; - DenseMap<BasicBlock *, ColorVector> BlockColors; + BlockColorMapT BlockColors; if (F.hasPersonalityFn() && isScopedEHPersonality(classifyEHPersonality(F.getPersonalityFn()))) BlockColors = colorEHFunclets(F); diff --git a/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp b/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp index a2434675a7b5ab..d15753e87ababc 100644 --- a/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp +++ b/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp @@ -501,7 +501,7 @@ class ObjCARCOpt { /// is in fact used in the current function. unsigned UsedInThisFunction; - DenseMap<BasicBlock *, ColorVector> BlockEHColors; + BlockColorMapT BlockEHColors; bool OptimizeRetainRVCall(Function &F, Instruction *RetainRV); void OptimizeAutoreleaseRVCall(Function &F, Instruction *AutoreleaseRV, diff --git a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp index 7c06e0c757e1cc..452750ba5ae250 100644 --- a/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp +++ b/llvm/lib/Transforms/Scalar/ConstraintElimination.cpp @@ -285,10 +285,10 @@ class ConstraintInfo { } } - DenseMap<Value *, unsigned> &getValue2Index(bool Signed) { + SmallDenseMap<Value *, unsigned, 16> &getValue2Index(bool Signed) { return Signed ? SignedCS.getValue2Index() : UnsignedCS.getValue2Index(); } - const DenseMap<Value *, unsigned> &getValue2Index(bool Signed) const { + const SmallDenseMap<Value *, unsigned, 16> &getValue2Index(bool Signed) const { return Signed ? SignedCS.getValue2Index() : UnsignedCS.getValue2Index(); } @@ -893,7 +893,7 @@ void ConstraintInfo::transferToOtherSystem( #ifndef NDEBUG static void dumpConstraint(ArrayRef<int64_t> C, - const DenseMap<Value *, unsigned> &Value2Index) { + const SmallDenseMap<Value *, unsigned, 16> &Value2Index) { ConstraintSystem CS(Value2Index); CS.addVariableRowFill(C); CS.dump(); diff --git a/llvm/lib/Transforms/Scalar/Reassociate.cpp b/llvm/lib/Transforms/Scalar/Reassociate.cpp index e742d2ed12af1a..98343b688ae240 100644 --- a/llvm/lib/Transforms/Scalar/Reassociate.cpp +++ b/llvm/lib/Transforms/Scalar/Reassociate.cpp @@ -417,7 +417,7 @@ static bool LinearizeExprTree(Instruction *I, // Leaves - Keeps track of the set of putative leaves as well as the number of // paths to each leaf seen so far. - using LeafMap = DenseMap<Value *, uint64_t>; + using LeafMap = SmallDenseMap<Value *, uint64_t, 16>; LeafMap Leaves; // Leaf -> Total weight so far. SmallVector<Value *, 8> LeafOrder; // Ensure deterministic leaf output order. const DataLayout DL = I->getDataLayout(); diff --git a/llvm/lib/Transforms/Utils/SSAUpdater.cpp b/llvm/lib/Transforms/Utils/SSAUpdater.cpp index 7fd3e51e141f30..d8b274491773bb 100644 --- a/llvm/lib/Transforms/Utils/SSAUpdater.cpp +++ b/llvm/lib/Transforms/Utils/SSAUpdater.cpp @@ -37,7 +37,7 @@ using namespace llvm; #define DEBUG_TYPE "ssaupdater" -using AvailableValsTy = DenseMap<BasicBlock *, Value *>; +using AvailableValsTy = SmallDenseMap<BasicBlock *, Value *, 16>; static AvailableValsTy &getAvailableVals(void *AV) { return *static_cast<AvailableValsTy*>(AV); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits