[llvm] [llvm] Replace unordered_{map,set} with Dense{Map,Set}/SmallPtrSet (PR #202222)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 11 22:50:28 PDT 2026
https://github.com/MaskRay updated https://github.com/llvm/llvm-project/pull/202222
>From 182374eaca55fa641e9d1f54e4d598f24dc67ac4 Mon Sep 17 00:00:00 2001
From: Fangrui Song <i at maskray.me>
Date: Sat, 6 Jun 2026 22:17:20 -0700
Subject: [PATCH 1/2] [llvm] Replace unordered_{map,set} with Dense{Map,Set}
std::unordered_map is slow. The remaining uses are pointer stability,
key spanning the full value range, or huge pair<key,value>. After
PR #201281 DenseMap no longer reserves sentinel keys, so more of these maps
can switch.
---
.../LogicalView/Readers/LVDWARFReader.h | 7 +-
llvm/include/llvm/IR/ModuleSummaryIndex.h | 3 +-
.../llvm/Support/ELFAttrParserCompact.h | 8 +--
llvm/include/llvm/XRay/InstrumentationMap.h | 6 +-
llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp | 3 +-
llvm/lib/CodeGen/RDFLiveness.cpp | 3 +-
llvm/lib/ObjCopy/ELF/ELFObject.cpp | 4 +-
llvm/lib/Passes/StandardInstrumentations.cpp | 14 ++--
llvm/lib/Target/BPF/BTFDebug.cpp | 12 ++--
llvm/lib/Target/BPF/BTFDebug.h | 15 ++---
.../Target/Hexagon/HexagonISelDAGToDAGHVX.cpp | 3 +-
llvm/lib/Target/PowerPC/PPCInstrInfo.cpp | 2 +-
.../SPIRVConvergenceRegionAnalysis.cpp | 6 +-
llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp | 66 +++++++++----------
llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.h | 2 +-
.../SPIRV/SPIRVMergeRegionExitTargets.cpp | 3 +-
llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp | 2 +-
llvm/lib/Target/SPIRV/SPIRVStructurizer.cpp | 12 ++--
llvm/lib/Target/SPIRV/SPIRVUtils.cpp | 8 +--
llvm/lib/Target/SPIRV/SPIRVUtils.h | 9 +--
.../IPO/MemProfContextDisambiguation.cpp | 5 +-
.../Instrumentation/IndirectCallPromotion.cpp | 3 +-
.../Utils/SampleProfileInference.cpp | 4 +-
llvm/tools/llvm-xray/func-id-helper.h | 3 +-
24 files changed, 98 insertions(+), 105 deletions(-)
diff --git a/llvm/include/llvm/DebugInfo/LogicalView/Readers/LVDWARFReader.h b/llvm/include/llvm/DebugInfo/LogicalView/Readers/LVDWARFReader.h
index 1cf29147fe2a1..b6d514edab6e4 100644
--- a/llvm/include/llvm/DebugInfo/LogicalView/Readers/LVDWARFReader.h
+++ b/llvm/include/llvm/DebugInfo/LogicalView/Readers/LVDWARFReader.h
@@ -14,10 +14,11 @@
#ifndef LLVM_DEBUGINFO_LOGICALVIEW_READERS_LVDWARFREADER_H
#define LLVM_DEBUGINFO_LOGICALVIEW_READERS_LVDWARFREADER_H
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/DenseSet.h"
#include "llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h"
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
#include "llvm/DebugInfo/LogicalView/Readers/LVBinaryReader.h"
-#include <unordered_set>
namespace llvm {
namespace logicalview {
@@ -62,14 +63,14 @@ class LVDWARFReader final : public LVBinaryReader {
std::optional<LVAddress> TombstoneAddress;
// Cross references (Elements).
- using LVElementSet = std::unordered_set<LVElement *>;
+ using LVElementSet = DenseSet<LVElement *>;
struct LVElementEntry {
LVElement *Element;
LVElementSet References;
LVElementSet Types;
LVElementEntry(LVElement *Element = nullptr) : Element(Element) {}
};
- using LVElementReference = std::unordered_map<LVOffset, LVElementEntry>;
+ using LVElementReference = DenseMap<LVOffset, LVElementEntry>;
LVElementReference ElementTable;
Error loadTargetInfo(const object::ObjectFile &Obj);
diff --git a/llvm/include/llvm/IR/ModuleSummaryIndex.h b/llvm/include/llvm/IR/ModuleSummaryIndex.h
index 359026cfc85a0..de487d0429e7e 100644
--- a/llvm/include/llvm/IR/ModuleSummaryIndex.h
+++ b/llvm/include/llvm/IR/ModuleSummaryIndex.h
@@ -45,7 +45,6 @@
#include <optional>
#include <set>
#include <string>
-#include <unordered_set>
#include <utility>
#include <vector>
@@ -1401,7 +1400,7 @@ using ModuleToSummariesForIndexTy =
std::map<std::string, GVSummaryMapTy, std::less<>>;
/// A set of global value summary pointers.
-using GVSummaryPtrSet = std::unordered_set<GlobalValueSummary *>;
+using GVSummaryPtrSet = DenseSet<GlobalValueSummary *>;
/// Map of a type GUID to type id string and summary (multimap used
/// in case of GUID conflicts).
diff --git a/llvm/include/llvm/Support/ELFAttrParserCompact.h b/llvm/include/llvm/Support/ELFAttrParserCompact.h
index d7e415331d1c3..f55c21d42de3d 100644
--- a/llvm/include/llvm/Support/ELFAttrParserCompact.h
+++ b/llvm/include/llvm/Support/ELFAttrParserCompact.h
@@ -10,6 +10,7 @@
#define LLVM_SUPPORT_ELFCOMPACTATTRPARSER_H
#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/DenseMap.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/DataExtractor.h"
#include "llvm/Support/ELFAttributeParser.h"
@@ -17,7 +18,6 @@
#include "llvm/Support/Error.h"
#include <optional>
-#include <unordered_map>
namespace llvm {
class StringRef;
@@ -25,8 +25,8 @@ class ScopedPrinter;
class LLVM_ABI ELFCompactAttrParser : public ELFAttributeParser {
StringRef vendor;
- std::unordered_map<unsigned, unsigned> attributes;
- std::unordered_map<unsigned, StringRef> attributesStr;
+ DenseMap<unsigned, unsigned> attributes;
+ DenseMap<unsigned, StringRef> attributesStr;
virtual Error handler(uint64_t tag, bool &handled) = 0;
@@ -45,7 +45,7 @@ class LLVM_ABI ELFCompactAttrParser : public ELFAttributeParser {
Error parseSubsection(uint32_t length);
void setAttributeString(unsigned tag, StringRef value) {
- attributesStr.emplace(tag, value);
+ attributesStr.try_emplace(tag, value);
}
public:
diff --git a/llvm/include/llvm/XRay/InstrumentationMap.h b/llvm/include/llvm/XRay/InstrumentationMap.h
index c5e7ebff0e2c1..9305b2e3ad36c 100644
--- a/llvm/include/llvm/XRay/InstrumentationMap.h
+++ b/llvm/include/llvm/XRay/InstrumentationMap.h
@@ -14,13 +14,13 @@
#ifndef LLVM_XRAY_INSTRUMENTATIONMAP_H
#define LLVM_XRAY_INSTRUMENTATIONMAP_H
+#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/YAMLTraits.h"
#include <cstdint>
#include <optional>
-#include <unordered_map>
#include <vector>
namespace llvm::xray {
@@ -74,8 +74,8 @@ struct YAMLXRaySledEntry {
///
class InstrumentationMap {
public:
- using FunctionAddressMap = std::unordered_map<int32_t, uint64_t>;
- using FunctionAddressReverseMap = std::unordered_map<uint64_t, int32_t>;
+ using FunctionAddressMap = DenseMap<int32_t, uint64_t>;
+ using FunctionAddressReverseMap = DenseMap<uint64_t, int32_t>;
using SledContainer = std::vector<SledEntry>;
private:
diff --git a/llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp b/llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp
index 2f2ee6f535f40..23dc6fbd6e500 100644
--- a/llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp
+++ b/llvm/lib/CodeGen/MLRegAllocEvictAdvisor.cpp
@@ -42,7 +42,6 @@
#include <array>
#include <bitset>
#include <memory>
-#include <unordered_map>
using namespace llvm;
@@ -329,7 +328,7 @@ class MLEvictAdvisor : public RegAllocEvictionAdvisor {
using RegID = unsigned;
mutable DenseMap<RegID, LIFeatureComponents> CachedFeatures;
- mutable std::unordered_map<unsigned, unsigned> VirtRegEvictionCounts;
+ mutable DenseMap<unsigned, unsigned> VirtRegEvictionCounts;
void onEviction(Register RegBeingEvicted) const {
// If we cannot find the virtual register in the map, we just assume it has
diff --git a/llvm/lib/CodeGen/RDFLiveness.cpp b/llvm/lib/CodeGen/RDFLiveness.cpp
index 195446e61076e..10ab9b88a05e1 100644
--- a/llvm/lib/CodeGen/RDFLiveness.cpp
+++ b/llvm/lib/CodeGen/RDFLiveness.cpp
@@ -471,8 +471,7 @@ void Liveness::computePhiInfo() {
// phi use -> (map: reaching phi -> set of registers defined in between)
std::map<NodeId, std::map<NodeId, RegisterAggr>> PhiUp;
std::vector<NodeId> PhiUQ; // Work list of phis for upward propagation.
- std::unordered_map<NodeId, RegisterAggr>
- PhiDRs; // Phi -> registers defined by it.
+ DenseMap<NodeId, RegisterAggr> PhiDRs; // Phi -> registers defined by it.
// Go over all phis.
for (NodeAddr<PhiNode *> PhiA : Phis) {
diff --git a/llvm/lib/ObjCopy/ELF/ELFObject.cpp b/llvm/lib/ObjCopy/ELF/ELFObject.cpp
index 3c6f9a966694a..0982e3c02de08 100644
--- a/llvm/lib/ObjCopy/ELF/ELFObject.cpp
+++ b/llvm/lib/ObjCopy/ELF/ELFObject.cpp
@@ -8,6 +8,7 @@
#include "ELFObject.h"
#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
@@ -23,7 +24,6 @@
#include <cstddef>
#include <cstdint>
#include <iterator>
-#include <unordered_set>
#include <utility>
#include <vector>
@@ -2235,7 +2235,7 @@ Error Object::removeSections(
// Now make sure there are no remaining references to the sections that will
// be removed. Sometimes it is impossible to remove a reference so we emit
// an error here instead.
- std::unordered_set<const SectionBase *> RemoveSections;
+ DenseSet<const SectionBase *> RemoveSections;
RemoveSections.reserve(std::distance(Iter, std::end(Sections)));
for (auto &RemoveSec : make_range(Iter, std::end(Sections))) {
for (auto &Segment : Segments)
diff --git a/llvm/lib/Passes/StandardInstrumentations.cpp b/llvm/lib/Passes/StandardInstrumentations.cpp
index 19e72a8612c4a..3f00a15dbc617 100644
--- a/llvm/lib/Passes/StandardInstrumentations.cpp
+++ b/llvm/lib/Passes/StandardInstrumentations.cpp
@@ -14,6 +14,8 @@
#include "llvm/Passes/StandardInstrumentations.h"
#include "llvm/ADT/Any.h"
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Analysis/LazyCallGraph.h"
#include "llvm/Analysis/LoopInfo.h"
@@ -40,8 +42,6 @@
#include "llvm/Support/Signals.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/xxhash.h"
-#include <unordered_map>
-#include <unordered_set>
#include <utility>
#include <vector>
@@ -1635,9 +1635,9 @@ class DisplayNode : public DisplayElement {
: DisplayElement(Colour), Content(Content) {}
// Iterator to the child nodes. Required by GraphWriter.
- using ChildIterator = std::unordered_set<DisplayNode *>::const_iterator;
- ChildIterator children_begin() const { return Children.cbegin(); }
- ChildIterator children_end() const { return Children.cend(); }
+ using ChildIterator = DenseSet<DisplayNode *>::const_iterator;
+ ChildIterator children_begin() const { return Children.begin(); }
+ ChildIterator children_end() const { return Children.end(); }
// Iterator for the edges. Required by GraphWriter.
using EdgeIterator = std::vector<DisplayEdge *>::const_iterator;
@@ -1673,8 +1673,8 @@ class DisplayNode : public DisplayElement {
std::vector<DisplayEdge> Edges;
std::vector<DisplayEdge *> EdgePtrs;
- std::unordered_set<DisplayNode *> Children;
- std::unordered_map<const DisplayNode *, const DisplayEdge *> EdgeMap;
+ DenseSet<DisplayNode *> Children;
+ DenseMap<const DisplayNode *, const DisplayEdge *> EdgeMap;
// Safeguard adding of edges.
bool AllEdgesCreated = false;
diff --git a/llvm/lib/Target/BPF/BTFDebug.cpp b/llvm/lib/Target/BPF/BTFDebug.cpp
index c847c1cb4b65c..227a9db86b62d 100644
--- a/llvm/lib/Target/BPF/BTFDebug.cpp
+++ b/llvm/lib/Target/BPF/BTFDebug.cpp
@@ -398,7 +398,7 @@ std::string BTFTypeStruct::getName() { return std::string(STy->getName()); }
/// for subprogram.
BTFTypeFuncProto::BTFTypeFuncProto(
const DISubroutineType *STy, uint32_t VLen,
- const std::unordered_map<uint32_t, StringRef> &FuncArgNames)
+ const DenseMap<uint32_t, StringRef> &FuncArgNames)
: STy(STy), FuncArgNames(FuncArgNames) {
Kind = BTF::BTF_KIND_FUNC_PROTO;
BTFType.Info = (Kind << 24) | VLen;
@@ -626,8 +626,7 @@ void BTFDebug::visitBasicType(const DIBasicType *BTy, uint32_t &TypeId) {
/// Handle subprogram or subroutine types.
void BTFDebug::visitSubroutineType(
const DISubroutineType *STy, bool ForSubprog,
- const std::unordered_map<uint32_t, StringRef> &FuncArgNames,
- uint32_t &TypeId) {
+ const DenseMap<uint32_t, StringRef> &FuncArgNames, uint32_t &TypeId) {
DITypeArray Elements = STy->getTypeArray();
uint32_t VLen = Elements.size() - 1;
if (VLen > BTF::MAX_VLEN)
@@ -1036,8 +1035,7 @@ void BTFDebug::visitTypeEntry(const DIType *Ty, uint32_t &TypeId,
if (const auto *BTy = dyn_cast<DIBasicType>(Ty))
visitBasicType(BTy, TypeId);
else if (const auto *STy = dyn_cast<DISubroutineType>(Ty))
- visitSubroutineType(STy, false, std::unordered_map<uint32_t, StringRef>(),
- TypeId);
+ visitSubroutineType(STy, false, DenseMap<uint32_t, StringRef>(), TypeId);
else if (const auto *CTy = dyn_cast<DICompositeType>(Ty))
visitCompositeType(CTy, TypeId);
else if (const auto *DTy = dyn_cast<DIDerivedType>(Ty))
@@ -1331,7 +1329,7 @@ void BTFDebug::beginFunctionImpl(const MachineFunction *MF) {
// Collect all types locally referenced in this function.
// Use RetainedNodes so we can collect all argument names
// even if the argument is not used.
- std::unordered_map<uint32_t, StringRef> FuncArgNames;
+ DenseMap<uint32_t, StringRef> FuncArgNames;
for (const DINode *DN : SP->getRetainedNodes()) {
if (const auto *DV = dyn_cast<DILocalVariable>(DN)) {
// Collect function arguments for subprogram func type.
@@ -1713,7 +1711,7 @@ void BTFDebug::processFuncPrototypes(const Function *F) {
return;
uint32_t ProtoTypeId;
- const std::unordered_map<uint32_t, StringRef> FuncArgNames;
+ const DenseMap<uint32_t, StringRef> FuncArgNames;
visitSubroutineType(SP->getType(), false, FuncArgNames, ProtoTypeId);
uint32_t FuncId = processDISubprogram(SP, ProtoTypeId, BTF::FUNC_EXTERN);
diff --git a/llvm/lib/Target/BPF/BTFDebug.h b/llvm/lib/Target/BPF/BTFDebug.h
index 75858fcc8bfde..7d2b7032f1faf 100644
--- a/llvm/lib/Target/BPF/BTFDebug.h
+++ b/llvm/lib/Target/BPF/BTFDebug.h
@@ -14,13 +14,13 @@
#ifndef LLVM_LIB_TARGET_BPF_BTFDEBUG_H
#define LLVM_LIB_TARGET_BPF_BTFDEBUG_H
+#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/CodeGen/DebugHandlerBase.h"
#include "llvm/DebugInfo/BTF/BTF.h"
#include <cstdint>
#include <map>
#include <set>
-#include <unordered_map>
namespace llvm {
@@ -142,12 +142,12 @@ class BTFTypeStruct : public BTFTypeBase {
/// Handle function pointer.
class BTFTypeFuncProto : public BTFTypeBase {
const DISubroutineType *STy;
- std::unordered_map<uint32_t, StringRef> FuncArgNames;
+ DenseMap<uint32_t, StringRef> FuncArgNames;
std::vector<struct BTF::BTFParam> Parameters;
public:
BTFTypeFuncProto(const DISubroutineType *STy, uint32_t NumParams,
- const std::unordered_map<uint32_t, StringRef> &FuncArgNames);
+ const DenseMap<uint32_t, StringRef> &FuncArgNames);
uint32_t getSize() override {
return BTFTypeBase::getSize() + Parameters.size() * BTF::BTFParamSize;
}
@@ -295,7 +295,7 @@ class BTFDebug : public DebugHandlerBase {
bool MapDefNotCollected;
BTFStringTable StringTable;
std::vector<std::unique_ptr<BTFTypeBase>> TypeEntries;
- std::unordered_map<const DIType *, uint32_t> DIToIdMap;
+ DenseMap<const DIType *, uint32_t> DIToIdMap;
std::map<uint32_t, std::vector<BTFFuncInfo>> FuncInfoTable;
std::map<uint32_t, std::vector<BTFLineInfo>> LineInfoTable;
std::map<uint32_t, std::vector<BTFFieldReloc>> FieldRelocTable;
@@ -323,10 +323,9 @@ class BTFDebug : public DebugHandlerBase {
void visitTypeEntry(const DIType *Ty, uint32_t &TypeId, bool CheckPointer,
bool SeenPointer);
void visitBasicType(const DIBasicType *BTy, uint32_t &TypeId);
- void visitSubroutineType(
- const DISubroutineType *STy, bool ForSubprog,
- const std::unordered_map<uint32_t, StringRef> &FuncArgNames,
- uint32_t &TypeId);
+ void visitSubroutineType(const DISubroutineType *STy, bool ForSubprog,
+ const DenseMap<uint32_t, StringRef> &FuncArgNames,
+ uint32_t &TypeId);
void visitFwdDeclType(const DICompositeType *CTy, bool IsUnion,
uint32_t &TypeId);
void visitCompositeType(const DICompositeType *CTy, uint32_t &TypeId);
diff --git a/llvm/lib/Target/Hexagon/HexagonISelDAGToDAGHVX.cpp b/llvm/lib/Target/Hexagon/HexagonISelDAGToDAGHVX.cpp
index ae369fe7ce901..a59ec1820a092 100644
--- a/llvm/lib/Target/Hexagon/HexagonISelDAGToDAGHVX.cpp
+++ b/llvm/lib/Target/Hexagon/HexagonISelDAGToDAGHVX.cpp
@@ -23,7 +23,6 @@
#include <map>
#include <optional>
#include <set>
-#include <unordered_map>
#include <utility>
#include <vector>
@@ -2747,7 +2746,7 @@ void HexagonDAGToDAGISel::ppHvxShuffleOfShuffle(std::vector<SDNode *> &&Nodes) {
unsigned HalfIdx;
};
- using MapType = std::unordered_map<SDValue, unsigned>;
+ using MapType = DenseMap<SDValue, unsigned>;
auto getMaskElt = [&](unsigned Idx, ShuffleVectorSDNode *Shuff0,
ShuffleVectorSDNode *Shuff1,
diff --git a/llvm/lib/Target/PowerPC/PPCInstrInfo.cpp b/llvm/lib/Target/PowerPC/PPCInstrInfo.cpp
index 59d18de06b2e0..925c679450ded 100644
--- a/llvm/lib/Target/PowerPC/PPCInstrInfo.cpp
+++ b/llvm/lib/Target/PowerPC/PPCInstrInfo.cpp
@@ -5448,7 +5448,7 @@ void PPCInstrInfo::promoteInstr32To64ForElimEXTSW(const Register &Reg,
// Map the 32bit to 64bit opcodes for instructions that are not signed or zero
// extended themselves, but may have operands who's destination registers of
// signed or zero extended instructions.
- std::unordered_map<unsigned, unsigned> OpcodeMap = {
+ DenseMap<unsigned, unsigned> OpcodeMap = {
{PPC::OR, PPC::OR8}, {PPC::ISEL, PPC::ISEL8},
{PPC::ORI, PPC::ORI8}, {PPC::XORI, PPC::XORI8},
{PPC::ORIS, PPC::ORIS8}, {PPC::XORIS, PPC::XORIS8},
diff --git a/llvm/lib/Target/SPIRV/Analysis/SPIRVConvergenceRegionAnalysis.cpp b/llvm/lib/Target/SPIRV/Analysis/SPIRVConvergenceRegionAnalysis.cpp
index 0798483462e18..1cb32cce32cbd 100644
--- a/llvm/lib/Target/SPIRV/Analysis/SPIRVConvergenceRegionAnalysis.cpp
+++ b/llvm/lib/Target/SPIRV/Analysis/SPIRVConvergenceRegionAnalysis.cpp
@@ -14,6 +14,7 @@
#include "SPIRVConvergenceRegionAnalysis.h"
#include "SPIRV.h"
+#include "llvm/ADT/DenseSet.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/IntrinsicInst.h"
@@ -21,7 +22,6 @@
#include "llvm/Transforms/Utils/LoopSimplify.h"
#include <optional>
#include <queue>
-#include <unordered_set>
#define DEBUG_TYPE "spirv-convergence-region-analysis"
@@ -210,10 +210,10 @@ class ConvergenceRegionAnalyzer {
return false;
}
- std::unordered_set<BasicBlock *>
+ DenseSet<BasicBlock *>
findPathsToMatch(LoopInfo &LI, BasicBlock *From,
std::function<bool(const BasicBlock *)> isMatch) const {
- std::unordered_set<BasicBlock *> Output;
+ DenseSet<BasicBlock *> Output;
if (isMatch(From))
Output.insert(From);
diff --git a/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp b/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp
index 97fa49d8836fb..1e1b0080be5ac 100644
--- a/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp
@@ -17,6 +17,7 @@
#include "SPIRVSubtarget.h"
#include "SPIRVTargetMachine.h"
#include "SPIRVUtils.h"
+#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/Analysis/LoopInfo.h"
@@ -35,7 +36,6 @@
#include <cassert>
#include <optional>
#include <queue>
-#include <unordered_set>
// This pass performs the following transformation on LLVM IR level required
// for the following translation to SPIR-V:
@@ -192,7 +192,7 @@ class SPIRVEmitIntrinsics
DenseSet<Instruction *> AggrStores;
SmallPtrSet<Instruction *, 8> DeletedInstrs;
GlobalVariableUsers GVUsers;
- std::unordered_set<Value *> Named;
+ DenseSet<Value *> Named;
// map of function declarations to <pointer arg index => element type>
DenseMap<Function *, SmallVector<std::pair<unsigned, Type *>>> FDeclPtrTys;
@@ -224,7 +224,7 @@ class SPIRVEmitIntrinsics
}
// a register of Instructions that were visited by deduceOperandElementType()
// to validate operand types with an instruction
- std::unordered_set<Instruction *> TypeValidated;
+ DenseSet<Instruction *> TypeValidated;
// well known result types of builtins
enum WellKnownTypes { Event };
@@ -232,24 +232,22 @@ class SPIRVEmitIntrinsics
// deduce element type of untyped pointers
Type *deduceElementType(Value *I, bool UnknownElemTypeI8);
Type *deduceElementTypeHelper(Value *I, bool UnknownElemTypeI8);
- Type *deduceElementTypeHelper(Value *I, std::unordered_set<Value *> &Visited,
+ Type *deduceElementTypeHelper(Value *I, DenseSet<Value *> &Visited,
bool UnknownElemTypeI8,
bool IgnoreKnownType = false);
Type *deduceElementTypeByValueDeep(Type *ValueTy, Value *Operand,
bool UnknownElemTypeI8);
Type *deduceElementTypeByValueDeep(Type *ValueTy, Value *Operand,
- std::unordered_set<Value *> &Visited,
+ DenseSet<Value *> &Visited,
bool UnknownElemTypeI8);
- Type *deduceElementTypeByUsersDeep(Value *Op,
- std::unordered_set<Value *> &Visited,
+ Type *deduceElementTypeByUsersDeep(Value *Op, DenseSet<Value *> &Visited,
bool UnknownElemTypeI8);
void maybeAssignPtrType(Type *&Ty, Value *I, Type *RefTy,
bool UnknownElemTypeI8);
// deduce nested types of composites
Type *deduceNestedTypeHelper(User *U, bool UnknownElemTypeI8);
- Type *deduceNestedTypeHelper(User *U, Type *Ty,
- std::unordered_set<Value *> &Visited,
+ Type *deduceNestedTypeHelper(User *U, Type *Ty, DenseSet<Value *> &Visited,
bool UnknownElemTypeI8);
// deduce Types of operands of the Instruction if possible
@@ -287,7 +285,7 @@ class SPIRVEmitIntrinsics
void processParamTypesByFunHeader(Function *F, IRBuilder<> &B);
Type *deduceFunParamElementType(Function *F, unsigned OpIdx);
Type *deduceFunParamElementType(Function *F, unsigned OpIdx,
- std::unordered_set<Function *> &FVisited);
+ DenseSet<Function *> &FVisited);
bool deduceOperandElementTypeCalledFunction(
CallInst *CI, SmallVector<std::pair<Value *, unsigned>> &Ops,
@@ -310,7 +308,7 @@ class SPIRVEmitIntrinsics
DenseSet<std::pair<Value *, Value *>> &VisitedSubst);
void propagateElemTypeRec(Value *Op, Type *PtrElemTy, Type *CastElemTy,
DenseSet<std::pair<Value *, Value *>> &VisitedSubst,
- std::unordered_set<Value *> &Visited,
+ DenseSet<Value *> &Visited,
DenseMap<Function *, CallInst *> Ptrcasts);
void replaceAllUsesWith(Value *Src, Value *Dest, bool DeleteOld = true);
@@ -647,7 +645,7 @@ void SPIRVEmitIntrinsics::propagateElemType(
void SPIRVEmitIntrinsics::propagateElemTypeRec(
Value *Op, Type *PtrElemTy, Type *CastElemTy,
DenseSet<std::pair<Value *, Value *>> &VisitedSubst) {
- std::unordered_set<Value *> Visited;
+ DenseSet<Value *> Visited;
DenseMap<Function *, CallInst *> Ptrcasts;
propagateElemTypeRec(Op, PtrElemTy, CastElemTy, VisitedSubst, Visited,
std::move(Ptrcasts));
@@ -656,8 +654,7 @@ void SPIRVEmitIntrinsics::propagateElemTypeRec(
void SPIRVEmitIntrinsics::propagateElemTypeRec(
Value *Op, Type *PtrElemTy, Type *CastElemTy,
DenseSet<std::pair<Value *, Value *>> &VisitedSubst,
- std::unordered_set<Value *> &Visited,
- DenseMap<Function *, CallInst *> Ptrcasts) {
+ DenseSet<Value *> &Visited, DenseMap<Function *, CallInst *> Ptrcasts) {
if (!Visited.insert(Op).second)
return;
SmallVector<User *> Users(Op->users());
@@ -680,14 +677,15 @@ void SPIRVEmitIntrinsics::propagateElemTypeRec(
Type *
SPIRVEmitIntrinsics::deduceElementTypeByValueDeep(Type *ValueTy, Value *Operand,
bool UnknownElemTypeI8) {
- std::unordered_set<Value *> Visited;
+ DenseSet<Value *> Visited;
return deduceElementTypeByValueDeep(ValueTy, Operand, Visited,
UnknownElemTypeI8);
}
-Type *SPIRVEmitIntrinsics::deduceElementTypeByValueDeep(
- Type *ValueTy, Value *Operand, std::unordered_set<Value *> &Visited,
- bool UnknownElemTypeI8) {
+Type *
+SPIRVEmitIntrinsics::deduceElementTypeByValueDeep(Type *ValueTy, Value *Operand,
+ DenseSet<Value *> &Visited,
+ bool UnknownElemTypeI8) {
Type *Ty = ValueTy;
if (Operand) {
if (auto *PtrTy = dyn_cast<PointerType>(Ty)) {
@@ -704,7 +702,7 @@ Type *SPIRVEmitIntrinsics::deduceElementTypeByValueDeep(
// Traverse User instructions to deduce an element pointer type of the operand.
Type *SPIRVEmitIntrinsics::deduceElementTypeByUsersDeep(
- Value *Op, std::unordered_set<Value *> &Visited, bool UnknownElemTypeI8) {
+ Value *Op, DenseSet<Value *> &Visited, bool UnknownElemTypeI8) {
if (!Op || !isPointerTy(Op->getType()) || isa<ConstantPointerNull>(Op) ||
isa<UndefValue>(Op))
return nullptr;
@@ -742,7 +740,7 @@ static Type *getPointeeTypeByCallInst(StringRef DemangledName,
// or nullptr otherwise.
Type *SPIRVEmitIntrinsics::deduceElementTypeHelper(Value *I,
bool UnknownElemTypeI8) {
- std::unordered_set<Value *> Visited;
+ DenseSet<Value *> Visited;
return deduceElementTypeHelper(I, Visited, UnknownElemTypeI8);
}
@@ -929,9 +927,10 @@ Type *SPIRVEmitIntrinsics::getGEPType(GetElementPtrInst *Ref) {
return Ty;
}
-Type *SPIRVEmitIntrinsics::deduceElementTypeHelper(
- Value *I, std::unordered_set<Value *> &Visited, bool UnknownElemTypeI8,
- bool IgnoreKnownType) {
+Type *SPIRVEmitIntrinsics::deduceElementTypeHelper(Value *I,
+ DenseSet<Value *> &Visited,
+ bool UnknownElemTypeI8,
+ bool IgnoreKnownType) {
// allow to pass nullptr as an argument
if (!I)
return nullptr;
@@ -1089,13 +1088,13 @@ Type *SPIRVEmitIntrinsics::deduceElementTypeHelper(
// information is found or needed.
Type *SPIRVEmitIntrinsics::deduceNestedTypeHelper(User *U,
bool UnknownElemTypeI8) {
- std::unordered_set<Value *> Visited;
+ DenseSet<Value *> Visited;
return deduceNestedTypeHelper(U, U->getType(), Visited, UnknownElemTypeI8);
}
-Type *SPIRVEmitIntrinsics::deduceNestedTypeHelper(
- User *U, Type *OrigTy, std::unordered_set<Value *> &Visited,
- bool UnknownElemTypeI8) {
+Type *SPIRVEmitIntrinsics::deduceNestedTypeHelper(User *U, Type *OrigTy,
+ DenseSet<Value *> &Visited,
+ bool UnknownElemTypeI8) {
if (!U)
return OrigTy;
@@ -2931,7 +2930,7 @@ void SPIRVEmitIntrinsics::insertConstantsForFPFastMathDefault(Module &M) {
}
}
- std::unordered_map<unsigned, GlobalVariable *> GlobalVars;
+ DenseMap<unsigned, GlobalVariable *> GlobalVars;
for (auto &[Func, FPFastMathDefaultInfoVec] : FPFastMathDefaultInfoMap) {
if (FPFastMathDefaultInfoVec.empty())
continue;
@@ -3051,17 +3050,18 @@ void SPIRVEmitIntrinsics::processInstrAfterVisit(Instruction *I,
Type *SPIRVEmitIntrinsics::deduceFunParamElementType(Function *F,
unsigned OpIdx) {
- std::unordered_set<Function *> FVisited;
+ DenseSet<Function *> FVisited;
return deduceFunParamElementType(F, OpIdx, FVisited);
}
-Type *SPIRVEmitIntrinsics::deduceFunParamElementType(
- Function *F, unsigned OpIdx, std::unordered_set<Function *> &FVisited) {
+Type *
+SPIRVEmitIntrinsics::deduceFunParamElementType(Function *F, unsigned OpIdx,
+ DenseSet<Function *> &FVisited) {
// maybe a cycle
if (!FVisited.insert(F).second)
return nullptr;
- std::unordered_set<Value *> Visited;
+ DenseSet<Value *> Visited;
SmallVector<std::pair<Function *, unsigned>> Lookup;
// search in function's call sites
for (User *U : F->users()) {
@@ -3546,7 +3546,7 @@ bool SPIRVEmitIntrinsics::postprocessTypes(Module &M) {
// Try to improve the type deduced after all Functions are processed.
if (auto *CI = dyn_cast<Instruction>(Op)) {
CurrF = CI->getParent()->getParent();
- std::unordered_set<Value *> Visited;
+ DenseSet<Value *> Visited;
if (Type *ElemTy = deduceElementTypeHelper(Op, Visited, false, true)) {
if (ElemTy != KnownTy) {
DenseSet<std::pair<Value *, Value *>> VisitedSubst;
diff --git a/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.h b/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.h
index f05bdc2cc9861..fcb8b3fd66f91 100644
--- a/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.h
+++ b/llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.h
@@ -87,7 +87,7 @@ class SPIRVGlobalRegistry : public SPIRVIRMapping {
DenseMap<std::pair<const MachineFunction *, Register>, const Value *> Reg2GO;
// map of aliasing decorations to aliasing metadata
- std::unordered_map<const MDNode *, MachineInstr *> AliasInstMDMap;
+ DenseMap<const MDNode *, MachineInstr *> AliasInstMDMap;
// Add a new OpTypeXXX instruction without checking for duplicates.
SPIRVTypeInst createSPIRVType(const Type *Type, MachineIRBuilder &MIRBuilder,
diff --git a/llvm/lib/Target/SPIRV/SPIRVMergeRegionExitTargets.cpp b/llvm/lib/Target/SPIRV/SPIRVMergeRegionExitTargets.cpp
index 959e7eb1e9e04..899026fd95ef4 100644
--- a/llvm/lib/Target/SPIRV/SPIRVMergeRegionExitTargets.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVMergeRegionExitTargets.cpp
@@ -18,6 +18,7 @@
#include "SPIRVSubtarget.h"
#include "SPIRVUtils.h"
#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/IR/Dominators.h"
@@ -166,7 +167,7 @@ static void validateRegionExits(const SPIRV::ConvergenceRegion *CR) {
for (auto *Child : CR->Children)
validateRegionExits(Child);
- std::unordered_set<BasicBlock *> ExitTargets;
+ DenseSet<BasicBlock *> ExitTargets;
for (auto *Exit : CR->Exits) {
for (auto *BB : successors(Exit)) {
if (CR->Blocks.count(BB) == 0)
diff --git a/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp b/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp
index 49d9dc95603ca..ea0635dfdf89d 100644
--- a/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp
@@ -2152,7 +2152,7 @@ void addInstrRequirements(const MachineInstr &MI,
// Check Layout operand in case if it's not a standard one and add the
// appropriate capability.
- std::unordered_map<unsigned, unsigned> LayoutToInstMap = {
+ DenseMap<unsigned, unsigned> LayoutToInstMap = {
{SPIRV::OpCooperativeMatrixLoadKHR, 3},
{SPIRV::OpCooperativeMatrixStoreKHR, 2},
{SPIRV::OpCooperativeMatrixLoadCheckedINTEL, 5},
diff --git a/llvm/lib/Target/SPIRV/SPIRVStructurizer.cpp b/llvm/lib/Target/SPIRV/SPIRVStructurizer.cpp
index d2befa50789fa..b9d3095c36a8e 100644
--- a/llvm/lib/Target/SPIRV/SPIRVStructurizer.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVStructurizer.cpp
@@ -14,6 +14,7 @@
#include "SPIRVSubtarget.h"
#include "SPIRVUtils.h"
#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/IR/CFG.h"
@@ -29,12 +30,11 @@
#include "llvm/Transforms/Utils/LoopSimplify.h"
#include "llvm/Transforms/Utils/LowerMemIntrinsics.h"
#include <stack>
-#include <unordered_set>
using namespace llvm;
using namespace SPIRV;
-using BlockSet = std::unordered_set<BasicBlock *>;
+using BlockSet = DenseSet<BasicBlock *>;
using Edge = std::pair<BasicBlock *, BasicBlock *>;
// Helper function to do a partial order visit from the block |Start|, calling
@@ -63,7 +63,7 @@ getRegionForHeader(const ConvergenceRegion *Node, BasicBlock *BB) {
// Returns the single BasicBlock exiting the convergence region `CR`,
// nullptr if no such exit exists.
static BasicBlock *getExitFor(const ConvergenceRegion *CR) {
- std::unordered_set<BasicBlock *> ExitTargets;
+ DenseSet<BasicBlock *> ExitTargets;
for (BasicBlock *Exit : CR->Exits) {
for (BasicBlock *Successor : successors(Exit)) {
if (CR->Blocks.count(Successor) == 0)
@@ -427,7 +427,7 @@ class SPIRVStructurizer : public FunctionPass {
// clang-format on
std::vector<Edge>
createAliasBlocksForComplexEdges(std::vector<Edge> Edges) {
- std::unordered_set<BasicBlock *> Seen;
+ DenseSet<BasicBlock *> Seen;
std::vector<Edge> Output;
Output.reserve(Edges.size());
@@ -465,14 +465,14 @@ class SPIRVStructurizer : public FunctionPass {
std::vector<Edge> FixedEdges = createAliasBlocksForComplexEdges(Edges);
std::vector<BasicBlock *> Dsts;
- std::unordered_map<BasicBlock *, ConstantInt *> DstToIndex;
+ DenseMap<BasicBlock *, ConstantInt *> DstToIndex;
auto NewExit = BasicBlock::Create(F.getContext(),
Header->getName() + ".new.exit", &F);
IRBuilder<> ExitBuilder(NewExit);
for (auto &[Src, Dst] : FixedEdges) {
if (DstToIndex.count(Dst) != 0)
continue;
- DstToIndex.emplace(Dst, ExitBuilder.getInt32(DstToIndex.size()));
+ DstToIndex.try_emplace(Dst, ExitBuilder.getInt32(DstToIndex.size()));
Dsts.push_back(Dst);
}
diff --git a/llvm/lib/Target/SPIRV/SPIRVUtils.cpp b/llvm/lib/Target/SPIRV/SPIRVUtils.cpp
index 6c5619c4585ef..6abdffe743f74 100644
--- a/llvm/lib/Target/SPIRV/SPIRVUtils.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVUtils.cpp
@@ -678,12 +678,12 @@ Type *parseBasicTypeName(StringRef &TypeName, LLVMContext &Ctx) {
return nullptr;
}
-std::unordered_set<BasicBlock *>
+DenseSet<BasicBlock *>
PartialOrderingVisitor::getReachableFrom(BasicBlock *Start) {
std::queue<BasicBlock *> ToVisit;
ToVisit.push(Start);
- std::unordered_set<BasicBlock *> Output;
+ DenseSet<BasicBlock *> Output;
while (ToVisit.size() != 0) {
BasicBlock *BB = ToVisit.front();
ToVisit.pop();
@@ -792,7 +792,7 @@ size_t PartialOrderingVisitor::visit(BasicBlock *BB, size_t Unused) {
QueueIndex = 0;
size_t Rank = GetNodeRank(BB);
OrderInfo Info = {Rank, BlockToOrder.size()};
- BlockToOrder.emplace(BB, Info);
+ BlockToOrder.try_emplace(BB, Info);
for (BasicBlock *S : successors(BB)) {
if (Queued.count(S) != 0)
@@ -831,7 +831,7 @@ bool PartialOrderingVisitor::compare(const BasicBlock *LHS,
void PartialOrderingVisitor::partialOrderVisit(
BasicBlock &Start, std::function<bool(BasicBlock *)> Op) {
- std::unordered_set<BasicBlock *> Reachable = getReachableFrom(&Start);
+ DenseSet<BasicBlock *> Reachable = getReachableFrom(&Start);
assert(BlockToOrder.count(&Start) != 0);
// Skipping blocks with a rank inferior to |Start|'s rank.
diff --git a/llvm/lib/Target/SPIRV/SPIRVUtils.h b/llvm/lib/Target/SPIRV/SPIRVUtils.h
index 27b196cb8dad3..78346abeeafd8 100644
--- a/llvm/lib/Target/SPIRV/SPIRVUtils.h
+++ b/llvm/lib/Target/SPIRV/SPIRVUtils.h
@@ -14,6 +14,8 @@
#define LLVM_LIB_TARGET_SPIRV_SPIRVUTILS_H
#include "MCTargetDesc/SPIRVBaseInfo.h"
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/DenseSet.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/IR/Dominators.h"
@@ -24,7 +26,6 @@
#include <set>
#include <string>
#include <unordered_map>
-#include <unordered_set>
#include "SPIRVTypeInst.h"
@@ -72,7 +73,7 @@ class PartialOrderingVisitor {
DomTreeBuilder::BBDomTree DT;
LoopInfo LI;
- std::unordered_set<BasicBlock *> Queued = {};
+ DenseSet<BasicBlock *> Queued = {};
std::queue<BasicBlock *> ToVisit = {};
struct OrderInfo {
@@ -80,12 +81,12 @@ class PartialOrderingVisitor {
size_t TraversalIndex;
};
- using BlockToOrderInfoMap = std::unordered_map<BasicBlock *, OrderInfo>;
+ using BlockToOrderInfoMap = DenseMap<BasicBlock *, OrderInfo>;
BlockToOrderInfoMap BlockToOrder;
std::vector<BasicBlock *> Order = {};
// Get all basic-blocks reachable from Start.
- std::unordered_set<BasicBlock *> getReachableFrom(BasicBlock *Start);
+ DenseSet<BasicBlock *> getReachableFrom(BasicBlock *Start);
// Internal function used to determine the partial ordering.
// Visits |BB| with the current rank being |Rank|.
diff --git a/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp b/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp
index ac93576391aff..73583981df31b 100644
--- a/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp
+++ b/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp
@@ -49,7 +49,6 @@
#include "llvm/Transforms/Utils/Instrumentation.h"
#include <deque>
#include <sstream>
-#include <unordered_map>
#include <vector>
using namespace llvm;
using namespace llvm::memprof;
@@ -1103,8 +1102,8 @@ class IndexCallsiteContextGraph
// frames that we discover while building the graph.
// It maps from the summary of the function making the tail call, to a map
// of callee ValueInfo to corresponding synthesized callsite info.
- std::unordered_map<FunctionSummary *,
- std::map<ValueInfo, std::unique_ptr<CallsiteInfo>>>
+ DenseMap<FunctionSummary *,
+ std::map<ValueInfo, std::unique_ptr<CallsiteInfo>>>
FunctionCalleesToSynthesizedCallsiteInfos;
};
} // namespace
diff --git a/llvm/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp b/llvm/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp
index 9fe751a56df64..cc6361f03d89b 100644
--- a/llvm/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp
+++ b/llvm/lib/Transforms/Instrumentation/IndirectCallPromotion.cpp
@@ -44,7 +44,6 @@
#include <cstdint>
#include <set>
#include <string>
-#include <unordered_map>
#include <utility>
#include <vector>
@@ -167,7 +166,7 @@ namespace {
// In the inner map, the key represents address point offsets and the value is a
// constant for this address point.
using VTableAddressPointOffsetValMap =
- SmallDenseMap<const GlobalVariable *, std::unordered_map<int, Constant *>>;
+ SmallDenseMap<const GlobalVariable *, DenseMap<int, Constant *>>;
// A struct to collect type information for a virtual call site.
struct VirtualCallSiteInfo {
diff --git a/llvm/lib/Transforms/Utils/SampleProfileInference.cpp b/llvm/lib/Transforms/Utils/SampleProfileInference.cpp
index 3e40cced8771c..69a6f18baef10 100644
--- a/llvm/lib/Transforms/Utils/SampleProfileInference.cpp
+++ b/llvm/lib/Transforms/Utils/SampleProfileInference.cpp
@@ -15,12 +15,12 @@
#include "llvm/Transforms/Utils/SampleProfileInference.h"
#include "llvm/ADT/BitVector.h"
+#include "llvm/ADT/DenseSet.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include <queue>
#include <set>
#include <stack>
-#include <unordered_set>
using namespace llvm;
#define DEBUG_TYPE "sample-profile-inference"
@@ -1229,7 +1229,7 @@ void verifyInput(const FlowFunction &Func) {
// Verify that there are no parallel edges
for (auto &Block : Func.Blocks) {
- std::unordered_set<uint64_t> UniqueSuccs;
+ DenseSet<uint64_t> UniqueSuccs;
for (auto &Jump : Block.SuccJumps) {
auto It = UniqueSuccs.insert(Jump->Target);
assert(It.second && "input CFG contains parallel edges");
diff --git a/llvm/tools/llvm-xray/func-id-helper.h b/llvm/tools/llvm-xray/func-id-helper.h
index d1a66282bab0b..389415fa038fb 100644
--- a/llvm/tools/llvm-xray/func-id-helper.h
+++ b/llvm/tools/llvm-xray/func-id-helper.h
@@ -15,14 +15,13 @@
#include "llvm/ADT/DenseMap.h"
#include "llvm/DebugInfo/Symbolize/SymbolizableModule.h"
#include "llvm/DebugInfo/Symbolize/Symbolize.h"
-#include <unordered_map>
namespace llvm::xray {
// This class consolidates common operations related to Function IDs.
class FuncIdConversionHelper {
public:
- using FunctionAddressMap = std::unordered_map<int32_t, uint64_t>;
+ using FunctionAddressMap = DenseMap<int32_t, uint64_t>;
private:
std::string BinaryInstrMap;
>From 2837ed2ae7f4d4928012803427ed38c0b0bd6760 Mon Sep 17 00:00:00 2001
From: Fangrui Song <i at maskray.me>
Date: Sun, 7 Jun 2026 14:11:08 -0700
Subject: [PATCH 2/2] use SmallPtrSet<T *, 0>
---
.../LogicalView/Readers/LVDWARFReader.h | 4 +-
llvm/include/llvm/IR/ModuleSummaryIndex.h | 3 +-
llvm/lib/ObjCopy/ELF/ELFObject.cpp | 4 +-
llvm/lib/Passes/StandardInstrumentations.cpp | 6 +-
.../SPIRVConvergenceRegionAnalysis.cpp | 6 +-
llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp | 66 ++++++++++---------
.../SPIRV/SPIRVMergeRegionExitTargets.cpp | 3 +-
llvm/lib/Target/SPIRV/SPIRVStructurizer.cpp | 7 +-
llvm/lib/Target/SPIRV/SPIRVUtils.cpp | 6 +-
llvm/lib/Target/SPIRV/SPIRVUtils.h | 6 +-
10 files changed, 56 insertions(+), 55 deletions(-)
diff --git a/llvm/include/llvm/DebugInfo/LogicalView/Readers/LVDWARFReader.h b/llvm/include/llvm/DebugInfo/LogicalView/Readers/LVDWARFReader.h
index b6d514edab6e4..930eeac5f400e 100644
--- a/llvm/include/llvm/DebugInfo/LogicalView/Readers/LVDWARFReader.h
+++ b/llvm/include/llvm/DebugInfo/LogicalView/Readers/LVDWARFReader.h
@@ -15,7 +15,7 @@
#define LLVM_DEBUGINFO_LOGICALVIEW_READERS_LVDWARFREADER_H
#include "llvm/ADT/DenseMap.h"
-#include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h"
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
#include "llvm/DebugInfo/LogicalView/Readers/LVBinaryReader.h"
@@ -63,7 +63,7 @@ class LVDWARFReader final : public LVBinaryReader {
std::optional<LVAddress> TombstoneAddress;
// Cross references (Elements).
- using LVElementSet = DenseSet<LVElement *>;
+ using LVElementSet = SmallPtrSet<LVElement *, 0>;
struct LVElementEntry {
LVElement *Element;
LVElementSet References;
diff --git a/llvm/include/llvm/IR/ModuleSummaryIndex.h b/llvm/include/llvm/IR/ModuleSummaryIndex.h
index de487d0429e7e..7858bd1f015d9 100644
--- a/llvm/include/llvm/IR/ModuleSummaryIndex.h
+++ b/llvm/include/llvm/IR/ModuleSummaryIndex.h
@@ -19,6 +19,7 @@
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SetVector.h"
+#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
@@ -1400,7 +1401,7 @@ using ModuleToSummariesForIndexTy =
std::map<std::string, GVSummaryMapTy, std::less<>>;
/// A set of global value summary pointers.
-using GVSummaryPtrSet = DenseSet<GlobalValueSummary *>;
+using GVSummaryPtrSet = SmallPtrSet<GlobalValueSummary *, 0>;
/// Map of a type GUID to type id string and summary (multimap used
/// in case of GUID conflicts).
diff --git a/llvm/lib/ObjCopy/ELF/ELFObject.cpp b/llvm/lib/ObjCopy/ELF/ELFObject.cpp
index 0982e3c02de08..ac818343f3f8f 100644
--- a/llvm/lib/ObjCopy/ELF/ELFObject.cpp
+++ b/llvm/lib/ObjCopy/ELF/ELFObject.cpp
@@ -8,8 +8,8 @@
#include "ELFObject.h"
#include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
#include "llvm/ADT/iterator_range.h"
@@ -2235,7 +2235,7 @@ Error Object::removeSections(
// Now make sure there are no remaining references to the sections that will
// be removed. Sometimes it is impossible to remove a reference so we emit
// an error here instead.
- DenseSet<const SectionBase *> RemoveSections;
+ SmallPtrSet<const SectionBase *, 0> RemoveSections;
RemoveSections.reserve(std::distance(Iter, std::end(Sections)));
for (auto &RemoveSec : make_range(Iter, std::end(Sections))) {
for (auto &Segment : Segments)
diff --git a/llvm/lib/Passes/StandardInstrumentations.cpp b/llvm/lib/Passes/StandardInstrumentations.cpp
index 3f00a15dbc617..ef02299445391 100644
--- a/llvm/lib/Passes/StandardInstrumentations.cpp
+++ b/llvm/lib/Passes/StandardInstrumentations.cpp
@@ -15,7 +15,7 @@
#include "llvm/Passes/StandardInstrumentations.h"
#include "llvm/ADT/Any.h"
#include "llvm/ADT/DenseMap.h"
-#include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Analysis/LazyCallGraph.h"
#include "llvm/Analysis/LoopInfo.h"
@@ -1635,7 +1635,7 @@ class DisplayNode : public DisplayElement {
: DisplayElement(Colour), Content(Content) {}
// Iterator to the child nodes. Required by GraphWriter.
- using ChildIterator = DenseSet<DisplayNode *>::const_iterator;
+ using ChildIterator = SmallPtrSet<DisplayNode *, 0>::const_iterator;
ChildIterator children_begin() const { return Children.begin(); }
ChildIterator children_end() const { return Children.end(); }
@@ -1673,7 +1673,7 @@ class DisplayNode : public DisplayElement {
std::vector<DisplayEdge> Edges;
std::vector<DisplayEdge *> EdgePtrs;
- DenseSet<DisplayNode *> Children;
+ SmallPtrSet<DisplayNode *, 0> Children;
DenseMap<const DisplayNode *, const DisplayEdge *> EdgeMap;
// Safeguard adding of edges.
diff --git a/llvm/lib/Target/SPIRV/Analysis/SPIRVConvergenceRegionAnalysis.cpp b/llvm/lib/Target/SPIRV/Analysis/SPIRVConvergenceRegionAnalysis.cpp
index 1cb32cce32cbd..f24877611f077 100644
--- a/llvm/lib/Target/SPIRV/Analysis/SPIRVConvergenceRegionAnalysis.cpp
+++ b/llvm/lib/Target/SPIRV/Analysis/SPIRVConvergenceRegionAnalysis.cpp
@@ -14,7 +14,7 @@
#include "SPIRVConvergenceRegionAnalysis.h"
#include "SPIRV.h"
-#include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/IR/Dominators.h"
#include "llvm/IR/IntrinsicInst.h"
@@ -210,10 +210,10 @@ class ConvergenceRegionAnalyzer {
return false;
}
- DenseSet<BasicBlock *>
+ SmallPtrSet<BasicBlock *, 0>
findPathsToMatch(LoopInfo &LI, BasicBlock *From,
std::function<bool(const BasicBlock *)> isMatch) const {
- DenseSet<BasicBlock *> Output;
+ SmallPtrSet<BasicBlock *, 0> Output;
if (isMatch(From))
Output.insert(From);
diff --git a/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp b/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp
index 1e1b0080be5ac..e94b17d420b32 100644
--- a/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVEmitIntrinsics.cpp
@@ -19,6 +19,7 @@
#include "SPIRVUtils.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/IR/Dominators.h"
@@ -189,10 +190,10 @@ class SPIRVEmitIntrinsics
bool HaveFunPtrs = false;
DenseMap<Instruction *, Constant *> AggrConsts;
DenseMap<Instruction *, Type *> AggrConstTypes;
- DenseSet<Instruction *> AggrStores;
+ SmallPtrSet<Instruction *, 0> AggrStores;
SmallPtrSet<Instruction *, 8> DeletedInstrs;
GlobalVariableUsers GVUsers;
- DenseSet<Value *> Named;
+ SmallPtrSet<Value *, 0> Named;
// map of function declarations to <pointer arg index => element type>
DenseMap<Function *, SmallVector<std::pair<unsigned, Type *>>> FDeclPtrTys;
@@ -224,7 +225,7 @@ class SPIRVEmitIntrinsics
}
// a register of Instructions that were visited by deduceOperandElementType()
// to validate operand types with an instruction
- DenseSet<Instruction *> TypeValidated;
+ SmallPtrSet<Instruction *, 0> TypeValidated;
// well known result types of builtins
enum WellKnownTypes { Event };
@@ -232,22 +233,24 @@ class SPIRVEmitIntrinsics
// deduce element type of untyped pointers
Type *deduceElementType(Value *I, bool UnknownElemTypeI8);
Type *deduceElementTypeHelper(Value *I, bool UnknownElemTypeI8);
- Type *deduceElementTypeHelper(Value *I, DenseSet<Value *> &Visited,
+ Type *deduceElementTypeHelper(Value *I, SmallPtrSet<Value *, 0> &Visited,
bool UnknownElemTypeI8,
bool IgnoreKnownType = false);
Type *deduceElementTypeByValueDeep(Type *ValueTy, Value *Operand,
bool UnknownElemTypeI8);
Type *deduceElementTypeByValueDeep(Type *ValueTy, Value *Operand,
- DenseSet<Value *> &Visited,
+ SmallPtrSet<Value *, 0> &Visited,
bool UnknownElemTypeI8);
- Type *deduceElementTypeByUsersDeep(Value *Op, DenseSet<Value *> &Visited,
+ Type *deduceElementTypeByUsersDeep(Value *Op,
+ SmallPtrSet<Value *, 0> &Visited,
bool UnknownElemTypeI8);
void maybeAssignPtrType(Type *&Ty, Value *I, Type *RefTy,
bool UnknownElemTypeI8);
// deduce nested types of composites
Type *deduceNestedTypeHelper(User *U, bool UnknownElemTypeI8);
- Type *deduceNestedTypeHelper(User *U, Type *Ty, DenseSet<Value *> &Visited,
+ Type *deduceNestedTypeHelper(User *U, Type *Ty,
+ SmallPtrSet<Value *, 0> &Visited,
bool UnknownElemTypeI8);
// deduce Types of operands of the Instruction if possible
@@ -285,7 +288,7 @@ class SPIRVEmitIntrinsics
void processParamTypesByFunHeader(Function *F, IRBuilder<> &B);
Type *deduceFunParamElementType(Function *F, unsigned OpIdx);
Type *deduceFunParamElementType(Function *F, unsigned OpIdx,
- DenseSet<Function *> &FVisited);
+ SmallPtrSet<Function *, 0> &FVisited);
bool deduceOperandElementTypeCalledFunction(
CallInst *CI, SmallVector<std::pair<Value *, unsigned>> &Ops,
@@ -308,7 +311,7 @@ class SPIRVEmitIntrinsics
DenseSet<std::pair<Value *, Value *>> &VisitedSubst);
void propagateElemTypeRec(Value *Op, Type *PtrElemTy, Type *CastElemTy,
DenseSet<std::pair<Value *, Value *>> &VisitedSubst,
- DenseSet<Value *> &Visited,
+ SmallPtrSet<Value *, 0> &Visited,
DenseMap<Function *, CallInst *> Ptrcasts);
void replaceAllUsesWith(Value *Src, Value *Dest, bool DeleteOld = true);
@@ -645,7 +648,7 @@ void SPIRVEmitIntrinsics::propagateElemType(
void SPIRVEmitIntrinsics::propagateElemTypeRec(
Value *Op, Type *PtrElemTy, Type *CastElemTy,
DenseSet<std::pair<Value *, Value *>> &VisitedSubst) {
- DenseSet<Value *> Visited;
+ SmallPtrSet<Value *, 0> Visited;
DenseMap<Function *, CallInst *> Ptrcasts;
propagateElemTypeRec(Op, PtrElemTy, CastElemTy, VisitedSubst, Visited,
std::move(Ptrcasts));
@@ -654,7 +657,8 @@ void SPIRVEmitIntrinsics::propagateElemTypeRec(
void SPIRVEmitIntrinsics::propagateElemTypeRec(
Value *Op, Type *PtrElemTy, Type *CastElemTy,
DenseSet<std::pair<Value *, Value *>> &VisitedSubst,
- DenseSet<Value *> &Visited, DenseMap<Function *, CallInst *> Ptrcasts) {
+ SmallPtrSet<Value *, 0> &Visited,
+ DenseMap<Function *, CallInst *> Ptrcasts) {
if (!Visited.insert(Op).second)
return;
SmallVector<User *> Users(Op->users());
@@ -677,15 +681,14 @@ void SPIRVEmitIntrinsics::propagateElemTypeRec(
Type *
SPIRVEmitIntrinsics::deduceElementTypeByValueDeep(Type *ValueTy, Value *Operand,
bool UnknownElemTypeI8) {
- DenseSet<Value *> Visited;
+ SmallPtrSet<Value *, 0> Visited;
return deduceElementTypeByValueDeep(ValueTy, Operand, Visited,
UnknownElemTypeI8);
}
-Type *
-SPIRVEmitIntrinsics::deduceElementTypeByValueDeep(Type *ValueTy, Value *Operand,
- DenseSet<Value *> &Visited,
- bool UnknownElemTypeI8) {
+Type *SPIRVEmitIntrinsics::deduceElementTypeByValueDeep(
+ Type *ValueTy, Value *Operand, SmallPtrSet<Value *, 0> &Visited,
+ bool UnknownElemTypeI8) {
Type *Ty = ValueTy;
if (Operand) {
if (auto *PtrTy = dyn_cast<PointerType>(Ty)) {
@@ -702,7 +705,7 @@ SPIRVEmitIntrinsics::deduceElementTypeByValueDeep(Type *ValueTy, Value *Operand,
// Traverse User instructions to deduce an element pointer type of the operand.
Type *SPIRVEmitIntrinsics::deduceElementTypeByUsersDeep(
- Value *Op, DenseSet<Value *> &Visited, bool UnknownElemTypeI8) {
+ Value *Op, SmallPtrSet<Value *, 0> &Visited, bool UnknownElemTypeI8) {
if (!Op || !isPointerTy(Op->getType()) || isa<ConstantPointerNull>(Op) ||
isa<UndefValue>(Op))
return nullptr;
@@ -740,7 +743,7 @@ static Type *getPointeeTypeByCallInst(StringRef DemangledName,
// or nullptr otherwise.
Type *SPIRVEmitIntrinsics::deduceElementTypeHelper(Value *I,
bool UnknownElemTypeI8) {
- DenseSet<Value *> Visited;
+ SmallPtrSet<Value *, 0> Visited;
return deduceElementTypeHelper(I, Visited, UnknownElemTypeI8);
}
@@ -927,10 +930,9 @@ Type *SPIRVEmitIntrinsics::getGEPType(GetElementPtrInst *Ref) {
return Ty;
}
-Type *SPIRVEmitIntrinsics::deduceElementTypeHelper(Value *I,
- DenseSet<Value *> &Visited,
- bool UnknownElemTypeI8,
- bool IgnoreKnownType) {
+Type *SPIRVEmitIntrinsics::deduceElementTypeHelper(
+ Value *I, SmallPtrSet<Value *, 0> &Visited, bool UnknownElemTypeI8,
+ bool IgnoreKnownType) {
// allow to pass nullptr as an argument
if (!I)
return nullptr;
@@ -1088,13 +1090,14 @@ Type *SPIRVEmitIntrinsics::deduceElementTypeHelper(Value *I,
// information is found or needed.
Type *SPIRVEmitIntrinsics::deduceNestedTypeHelper(User *U,
bool UnknownElemTypeI8) {
- DenseSet<Value *> Visited;
+ SmallPtrSet<Value *, 0> Visited;
return deduceNestedTypeHelper(U, U->getType(), Visited, UnknownElemTypeI8);
}
-Type *SPIRVEmitIntrinsics::deduceNestedTypeHelper(User *U, Type *OrigTy,
- DenseSet<Value *> &Visited,
- bool UnknownElemTypeI8) {
+Type *
+SPIRVEmitIntrinsics::deduceNestedTypeHelper(User *U, Type *OrigTy,
+ SmallPtrSet<Value *, 0> &Visited,
+ bool UnknownElemTypeI8) {
if (!U)
return OrigTy;
@@ -3050,18 +3053,17 @@ void SPIRVEmitIntrinsics::processInstrAfterVisit(Instruction *I,
Type *SPIRVEmitIntrinsics::deduceFunParamElementType(Function *F,
unsigned OpIdx) {
- DenseSet<Function *> FVisited;
+ SmallPtrSet<Function *, 0> FVisited;
return deduceFunParamElementType(F, OpIdx, FVisited);
}
-Type *
-SPIRVEmitIntrinsics::deduceFunParamElementType(Function *F, unsigned OpIdx,
- DenseSet<Function *> &FVisited) {
+Type *SPIRVEmitIntrinsics::deduceFunParamElementType(
+ Function *F, unsigned OpIdx, SmallPtrSet<Function *, 0> &FVisited) {
// maybe a cycle
if (!FVisited.insert(F).second)
return nullptr;
- DenseSet<Value *> Visited;
+ SmallPtrSet<Value *, 0> Visited;
SmallVector<std::pair<Function *, unsigned>> Lookup;
// search in function's call sites
for (User *U : F->users()) {
@@ -3546,7 +3548,7 @@ bool SPIRVEmitIntrinsics::postprocessTypes(Module &M) {
// Try to improve the type deduced after all Functions are processed.
if (auto *CI = dyn_cast<Instruction>(Op)) {
CurrF = CI->getParent()->getParent();
- DenseSet<Value *> Visited;
+ SmallPtrSet<Value *, 0> Visited;
if (Type *ElemTy = deduceElementTypeHelper(Op, Visited, false, true)) {
if (ElemTy != KnownTy) {
DenseSet<std::pair<Value *, Value *>> VisitedSubst;
diff --git a/llvm/lib/Target/SPIRV/SPIRVMergeRegionExitTargets.cpp b/llvm/lib/Target/SPIRV/SPIRVMergeRegionExitTargets.cpp
index 899026fd95ef4..d1d40d0d899a5 100644
--- a/llvm/lib/Target/SPIRV/SPIRVMergeRegionExitTargets.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVMergeRegionExitTargets.cpp
@@ -18,7 +18,6 @@
#include "SPIRVSubtarget.h"
#include "SPIRVUtils.h"
#include "llvm/ADT/DenseMap.h"
-#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/IR/Dominators.h"
@@ -167,7 +166,7 @@ static void validateRegionExits(const SPIRV::ConvergenceRegion *CR) {
for (auto *Child : CR->Children)
validateRegionExits(Child);
- DenseSet<BasicBlock *> ExitTargets;
+ SmallPtrSet<BasicBlock *, 0> ExitTargets;
for (auto *Exit : CR->Exits) {
for (auto *BB : successors(Exit)) {
if (CR->Blocks.count(BB) == 0)
diff --git a/llvm/lib/Target/SPIRV/SPIRVStructurizer.cpp b/llvm/lib/Target/SPIRV/SPIRVStructurizer.cpp
index b9d3095c36a8e..2b13a8da1f5e1 100644
--- a/llvm/lib/Target/SPIRV/SPIRVStructurizer.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVStructurizer.cpp
@@ -14,7 +14,6 @@
#include "SPIRVSubtarget.h"
#include "SPIRVUtils.h"
#include "llvm/ADT/DenseMap.h"
-#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/IR/CFG.h"
@@ -34,7 +33,7 @@
using namespace llvm;
using namespace SPIRV;
-using BlockSet = DenseSet<BasicBlock *>;
+using BlockSet = SmallPtrSet<BasicBlock *, 0>;
using Edge = std::pair<BasicBlock *, BasicBlock *>;
// Helper function to do a partial order visit from the block |Start|, calling
@@ -63,7 +62,7 @@ getRegionForHeader(const ConvergenceRegion *Node, BasicBlock *BB) {
// Returns the single BasicBlock exiting the convergence region `CR`,
// nullptr if no such exit exists.
static BasicBlock *getExitFor(const ConvergenceRegion *CR) {
- DenseSet<BasicBlock *> ExitTargets;
+ SmallPtrSet<BasicBlock *, 0> ExitTargets;
for (BasicBlock *Exit : CR->Exits) {
for (BasicBlock *Successor : successors(Exit)) {
if (CR->Blocks.count(Successor) == 0)
@@ -427,7 +426,7 @@ class SPIRVStructurizer : public FunctionPass {
// clang-format on
std::vector<Edge>
createAliasBlocksForComplexEdges(std::vector<Edge> Edges) {
- DenseSet<BasicBlock *> Seen;
+ SmallPtrSet<BasicBlock *, 0> Seen;
std::vector<Edge> Output;
Output.reserve(Edges.size());
diff --git a/llvm/lib/Target/SPIRV/SPIRVUtils.cpp b/llvm/lib/Target/SPIRV/SPIRVUtils.cpp
index 6abdffe743f74..7246a968aabac 100644
--- a/llvm/lib/Target/SPIRV/SPIRVUtils.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVUtils.cpp
@@ -678,12 +678,12 @@ Type *parseBasicTypeName(StringRef &TypeName, LLVMContext &Ctx) {
return nullptr;
}
-DenseSet<BasicBlock *>
+SmallPtrSet<BasicBlock *, 0>
PartialOrderingVisitor::getReachableFrom(BasicBlock *Start) {
std::queue<BasicBlock *> ToVisit;
ToVisit.push(Start);
- DenseSet<BasicBlock *> Output;
+ SmallPtrSet<BasicBlock *, 0> Output;
while (ToVisit.size() != 0) {
BasicBlock *BB = ToVisit.front();
ToVisit.pop();
@@ -831,7 +831,7 @@ bool PartialOrderingVisitor::compare(const BasicBlock *LHS,
void PartialOrderingVisitor::partialOrderVisit(
BasicBlock &Start, std::function<bool(BasicBlock *)> Op) {
- DenseSet<BasicBlock *> Reachable = getReachableFrom(&Start);
+ SmallPtrSet<BasicBlock *, 0> Reachable = getReachableFrom(&Start);
assert(BlockToOrder.count(&Start) != 0);
// Skipping blocks with a rank inferior to |Start|'s rank.
diff --git a/llvm/lib/Target/SPIRV/SPIRVUtils.h b/llvm/lib/Target/SPIRV/SPIRVUtils.h
index 78346abeeafd8..a52012deff403 100644
--- a/llvm/lib/Target/SPIRV/SPIRVUtils.h
+++ b/llvm/lib/Target/SPIRV/SPIRVUtils.h
@@ -15,7 +15,7 @@
#include "MCTargetDesc/SPIRVBaseInfo.h"
#include "llvm/ADT/DenseMap.h"
-#include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/Analysis/LoopInfo.h"
#include "llvm/CodeGen/MachineBasicBlock.h"
#include "llvm/IR/Dominators.h"
@@ -73,7 +73,7 @@ class PartialOrderingVisitor {
DomTreeBuilder::BBDomTree DT;
LoopInfo LI;
- DenseSet<BasicBlock *> Queued = {};
+ SmallPtrSet<BasicBlock *, 0> Queued = {};
std::queue<BasicBlock *> ToVisit = {};
struct OrderInfo {
@@ -86,7 +86,7 @@ class PartialOrderingVisitor {
std::vector<BasicBlock *> Order = {};
// Get all basic-blocks reachable from Start.
- DenseSet<BasicBlock *> getReachableFrom(BasicBlock *Start);
+ SmallPtrSet<BasicBlock *, 0> getReachableFrom(BasicBlock *Start);
// Internal function used to determine the partial ordering.
// Visits |BB| with the current rank being |Rank|.
More information about the llvm-commits
mailing list