[llvm] [TableGen] Unique the remaining Init pools in a UniquingSet. NFC (PR #221394)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 5 16:31:32 PDT 2026
https://github.com/MaskRay updated https://github.com/llvm/llvm-project/pull/221394
>From 30281ed8a5238763df94bb8b96d5060f6beeb7c6 Mon Sep 17 00:00:00 2001
From: Fangrui Song <i at maskray.me>
Date: Fri, 4 Sep 2026 22:21:30 -0700
Subject: [PATCH 1/3] [TableGen] Unique the remaining Init pools in a
UniquingSet. NFC
Follow-up to #219630. Every one of these keys is a handful of scalars,
pointers and trailing-object arrays already stored in the node, so a
typed key removes the FoldingSetNodeID serialization on every get() and
the profile rebuild on every hit.
ArgumentInit stays on FoldingSet: its key holds an ArgAuxType, and
std::variant has no DenseMapInfo.
llvm-tblgen instructions retired, minimum of five interleaved runs:
```
RISCV -gen-asm-matcher -2.553%
RISCV -gen-register-info -2.829%
X86 -gen-dag-isel -1.268%
AMDGPU -gen-subtarget -0.985%
```
Aided by Opus 5
---
llvm/include/llvm/TableGen/Record.h | 37 ++++--
llvm/lib/TableGen/Record.cpp | 181 +++-------------------------
2 files changed, 48 insertions(+), 170 deletions(-)
diff --git a/llvm/include/llvm/TableGen/Record.h b/llvm/include/llvm/TableGen/Record.h
index ca9c813b8a0ca..8a69dc9941ac8 100644
--- a/llvm/include/llvm/TableGen/Record.h
+++ b/llvm/include/llvm/TableGen/Record.h
@@ -257,7 +257,7 @@ class RecordRecTy final : public RecTy,
ArrayRef<const Record *> Classes);
static const RecordRecTy *get(const Record *Class);
- void Profile(FoldingSetNodeID &ID) const;
+ ArrayRef<const Record *> getKey() const { return getClasses(); }
ArrayRef<const Record *> getClasses() const {
return getTrailingObjects(NumClasses);
@@ -608,7 +608,7 @@ class BitsInit final : public TypedInit,
static BitsInit *get(RecordKeeper &RK, ArrayRef<const Init *> Range);
- void Profile(FoldingSetNodeID &ID) const;
+ ArrayRef<const Init *> getKey() const { return getBits(); }
unsigned getNumBits() const { return NumBits; }
@@ -1045,7 +1045,10 @@ class CondOpInit final : public TypedInit,
ArrayRef<const Init *> Values,
const RecTy *Type);
- void Profile(FoldingSetNodeID &ID) const;
+ std::tuple<const RecTy *, ArrayRef<const Init *>, ArrayRef<const Init *>>
+ getKey() const {
+ return {ValType, getConds(), getVals()};
+ }
const RecTy *getValType() const { return ValType; }
@@ -1111,7 +1114,11 @@ class FoldOpInit final : public TypedInit, public FoldingSetNode {
const Init *A, const Init *B, const Init *Expr,
const RecTy *Type);
- void Profile(FoldingSetNodeID &ID) const;
+ std::tuple<const Init *, const Init *, const Init *, const Init *,
+ const Init *, const RecTy *>
+ getKey() const {
+ return {Start, List, A, B, Expr, getType()};
+ }
// Fold - If possible, fold this to a simpler init. Return this if not
// possible to fold.
@@ -1144,7 +1151,9 @@ class IsAOpInit final : public TypedInit, public FoldingSetNode {
static const IsAOpInit *get(const RecTy *CheckType, const Init *Expr);
- void Profile(FoldingSetNodeID &ID) const;
+ std::pair<const RecTy *, const Init *> getKey() const {
+ return {CheckType, Expr};
+ }
// Fold - If possible, fold this to a simpler init. Return this if not
// possible to fold.
@@ -1178,7 +1187,9 @@ class ExistsOpInit final : public TypedInit, public FoldingSetNode {
static const ExistsOpInit *get(const RecTy *CheckType, const Init *Expr);
- void Profile(FoldingSetNodeID &ID) const;
+ std::pair<const RecTy *, const Init *> getKey() const {
+ return {CheckType, Expr};
+ }
// Fold - If possible, fold this to a simpler init. Return this if not
// possible to fold.
@@ -1215,7 +1226,9 @@ class InstancesOpInit final : public TypedInit, public FoldingSetNode {
static const InstancesOpInit *get(const RecTy *Type, const Init *Regex);
- void Profile(FoldingSetNodeID &ID) const;
+ std::pair<const RecTy *, const Init *> getKey() const {
+ return {Type, Regex};
+ }
const Init *Fold(const Record *CurRec, bool IsFinal = false) const;
@@ -1364,7 +1377,9 @@ class VarDefInit final
static const VarDefInit *get(SMLoc Loc, const Record *Class,
ArrayRef<const ArgumentInit *> Args);
- void Profile(FoldingSetNodeID &ID) const;
+ std::pair<const Record *, ArrayRef<const ArgumentInit *>> getKey() const {
+ return {Class, args()};
+ }
const Init *resolveReferences(Resolver &R) const override;
const Init *Fold() const;
@@ -1478,7 +1493,11 @@ class DagInit final
return DagInit::get(V, nullptr, ArgAndNames);
}
- void Profile(FoldingSetNodeID &ID) const;
+ std::tuple<const Init *, const StringInit *, ArrayRef<const Init *>,
+ ArrayRef<const StringInit *>>
+ getKey() const {
+ return {Val, ValName, getArgs(), getArgNames()};
+ }
const Init *getOperator() const { return Val; }
const Record *getOperatorAsDef(ArrayRef<SMLoc> Loc) const;
diff --git a/llvm/lib/TableGen/Record.cpp b/llvm/lib/TableGen/Record.cpp
index ad645931009f0..de3272ad3c045 100644
--- a/llvm/lib/TableGen/Record.cpp
+++ b/llvm/lib/TableGen/Record.cpp
@@ -71,7 +71,7 @@ struct detail::RecordKeeperImpl {
BitInit FalseBitInit;
FoldingSet<ArgumentInit> TheArgumentInitPool;
- FoldingSet<BitsInit> TheBitsInitPool;
+ UniquingSet<BitsInit> TheBitsInitPool;
std::map<int64_t, IntInit *> TheIntInitPool;
StringMap<const StringInit *, BumpPtrAllocator &> StringInitStringPool;
StringMap<const StringInit *, BumpPtrAllocator &> StringInitCodePool;
@@ -79,19 +79,19 @@ struct detail::RecordKeeperImpl {
UniquingSet<UnOpInit> TheUnOpInitPool;
UniquingSet<BinOpInit> TheBinOpInitPool;
UniquingSet<TernOpInit> TheTernOpInitPool;
- FoldingSet<FoldOpInit> TheFoldOpInitPool;
- FoldingSet<IsAOpInit> TheIsAOpInitPool;
- FoldingSet<ExistsOpInit> TheExistsOpInitPool;
- FoldingSet<InstancesOpInit> TheInstancesOpInitPool;
+ UniquingSet<FoldOpInit> TheFoldOpInitPool;
+ UniquingSet<IsAOpInit> TheIsAOpInitPool;
+ UniquingSet<ExistsOpInit> TheExistsOpInitPool;
+ UniquingSet<InstancesOpInit> TheInstancesOpInitPool;
DenseMap<std::pair<const RecTy *, const Init *>, VarInit *> TheVarInitPool;
DenseMap<std::pair<const TypedInit *, unsigned>, VarBitInit *>
TheVarBitInitPool;
- FoldingSet<VarDefInit> TheVarDefInitPool;
+ UniquingSet<VarDefInit> TheVarDefInitPool;
DenseMap<std::pair<const Init *, const StringInit *>, FieldInit *>
TheFieldInitPool;
- FoldingSet<CondOpInit> TheCondOpInitPool;
- FoldingSet<DagInit> TheDagInitPool;
- FoldingSet<RecordRecTy> RecordTypePool;
+ UniquingSet<CondOpInit> TheCondOpInitPool;
+ UniquingSet<DagInit> TheDagInitPool;
+ UniquingSet<RecordRecTy> RecordTypePool;
unsigned AnonCounter;
unsigned LastRecordID;
@@ -226,13 +226,6 @@ std::string DagRecTy::getAsString() const {
return "dag";
}
-static void ProfileRecordRecTy(FoldingSetNodeID &ID,
- ArrayRef<const Record *> Classes) {
- ID.AddInteger(Classes.size());
- for (const Record *R : Classes)
- ID.AddPointer(R);
-}
-
RecordRecTy::RecordRecTy(RecordKeeper &RK, ArrayRef<const Record *> Classes)
: RecTy(RecordRecTyKind, RK), NumClasses(Classes.size()) {
llvm::uninitialized_copy(Classes, getTrailingObjects());
@@ -244,18 +237,15 @@ const RecordRecTy *RecordRecTy::get(RecordKeeper &RK,
if (UnsortedClasses.empty())
return &RKImpl.AnyRecord;
- FoldingSet<RecordRecTy> &ThePool = RKImpl.RecordTypePool;
+ UniquingSet<RecordRecTy> &ThePool = RKImpl.RecordTypePool;
SmallVector<const Record *, 4> Classes(UnsortedClasses);
llvm::sort(Classes, [](const Record *LHS, const Record *RHS) {
return LHS->getNameInitAsString() < RHS->getNameInitAsString();
});
- FoldingSetNodeID ID;
- ProfileRecordRecTy(ID, Classes);
-
FoldingSetInsertToken Token;
- if (RecordRecTy *Ty = ThePool.lookup(ID, Token))
+ if (RecordRecTy *Ty = ThePool.lookup(Classes, Token))
return Ty;
#ifndef NDEBUG
@@ -280,10 +270,6 @@ const RecordRecTy *RecordRecTy::get(const Record *Class) {
return get(Class->getRecords(), {Class});
}
-void RecordRecTy::Profile(FoldingSetNodeID &ID) const {
- ProfileRecordRecTy(ID, getClasses());
-}
-
std::string RecordRecTy::getAsString() const {
if (NumClasses == 1)
return getClasses()[0]->getNameInitAsString();
@@ -453,14 +439,6 @@ const Init *BitInit::convertInitializerTo(const RecTy *Ty) const {
return nullptr;
}
-static void ProfileBitsInit(FoldingSetNodeID &ID,
- ArrayRef<const Init *> Range) {
- ID.AddInteger(Range.size());
-
- for (const Init *I : Range)
- ID.AddPointer(I);
-}
-
BitsInit::BitsInit(RecordKeeper &RK, ArrayRef<const Init *> Bits)
: TypedInit(IK_BitsInit, BitsRecTy::get(RK, Bits.size())),
NumBits(Bits.size()) {
@@ -468,12 +446,9 @@ BitsInit::BitsInit(RecordKeeper &RK, ArrayRef<const Init *> Bits)
}
BitsInit *BitsInit::get(RecordKeeper &RK, ArrayRef<const Init *> Bits) {
- FoldingSetNodeID ID;
- ProfileBitsInit(ID, Bits);
-
detail::RecordKeeperImpl &RKImpl = RK.getImpl();
FoldingSetInsertToken Token;
- if (BitsInit *I = RKImpl.TheBitsInitPool.lookup(ID, Token))
+ if (BitsInit *I = RKImpl.TheBitsInitPool.lookup(Bits, Token))
return I;
void *Mem = RKImpl.Allocator.Allocate(
@@ -483,10 +458,6 @@ BitsInit *BitsInit::get(RecordKeeper &RK, ArrayRef<const Init *> Bits) {
return I;
}
-void BitsInit::Profile(FoldingSetNodeID &ID) const {
- ProfileBitsInit(ID, getBits());
-}
-
const Init *BitsInit::convertInitializerTo(const RecTy *Ty) const {
if (isa<BitRecTy>(Ty)) {
if (getNumBits() != 1) return nullptr; // Only accept if just one bit!
@@ -2040,26 +2011,12 @@ std::string TernOpInit::getAsString() const {
", " + MHS->getAsString() + ", " + RHS->getAsString() + ")");
}
-static void ProfileFoldOpInit(FoldingSetNodeID &ID, const Init *Start,
- const Init *List, const Init *A, const Init *B,
- const Init *Expr, const RecTy *Type) {
- ID.AddPointer(Start);
- ID.AddPointer(List);
- ID.AddPointer(A);
- ID.AddPointer(B);
- ID.AddPointer(Expr);
- ID.AddPointer(Type);
-}
-
const FoldOpInit *FoldOpInit::get(const Init *Start, const Init *List,
const Init *A, const Init *B,
const Init *Expr, const RecTy *Type) {
- FoldingSetNodeID ID;
- ProfileFoldOpInit(ID, Start, List, A, B, Expr, Type);
-
detail::RecordKeeperImpl &RK = Start->getRecordKeeper().getImpl();
FoldingSetInsertToken Token;
- if (const FoldOpInit *I = RK.TheFoldOpInitPool.lookup(ID, Token))
+ if (const FoldOpInit *I = RK.TheFoldOpInitPool.lookup({Start, List, A, B, Expr, Type}, Token))
return I;
FoldOpInit *I = new (RK.Allocator) FoldOpInit(Start, List, A, B, Expr, Type);
@@ -2067,10 +2024,6 @@ const FoldOpInit *FoldOpInit::get(const Init *Start, const Init *List,
return I;
}
-void FoldOpInit::Profile(FoldingSetNodeID &ID) const {
- ProfileFoldOpInit(ID, Start, List, A, B, Expr, getType());
-}
-
const Init *FoldOpInit::Fold(const Record *CurRec) const {
if (const auto *LI = dyn_cast<ListInit>(List)) {
const Init *Accum = Start;
@@ -2113,20 +2066,11 @@ std::string FoldOpInit::getAsString() const {
.str();
}
-static void ProfileIsAOpInit(FoldingSetNodeID &ID, const RecTy *CheckType,
- const Init *Expr) {
- ID.AddPointer(CheckType);
- ID.AddPointer(Expr);
-}
-
const IsAOpInit *IsAOpInit::get(const RecTy *CheckType, const Init *Expr) {
- FoldingSetNodeID ID;
- ProfileIsAOpInit(ID, CheckType, Expr);
-
detail::RecordKeeperImpl &RK = Expr->getRecordKeeper().getImpl();
FoldingSetInsertToken Token;
- if (const IsAOpInit *I = RK.TheIsAOpInitPool.lookup(ID, Token))
+ if (const IsAOpInit *I = RK.TheIsAOpInitPool.lookup({CheckType, Expr}, Token))
return I;
IsAOpInit *I = new (RK.Allocator) IsAOpInit(CheckType, Expr);
@@ -2134,10 +2078,6 @@ const IsAOpInit *IsAOpInit::get(const RecTy *CheckType, const Init *Expr) {
return I;
}
-void IsAOpInit::Profile(FoldingSetNodeID &ID) const {
- ProfileIsAOpInit(ID, CheckType, Expr);
-}
-
const Init *IsAOpInit::Fold() const {
if (const auto *TI = dyn_cast<TypedInit>(Expr)) {
// Is the expression type known to be (a subclass of) the desired type?
@@ -2177,20 +2117,11 @@ std::string IsAOpInit::getAsString() const {
.str();
}
-static void ProfileExistsOpInit(FoldingSetNodeID &ID, const RecTy *CheckType,
- const Init *Expr) {
- ID.AddPointer(CheckType);
- ID.AddPointer(Expr);
-}
-
const ExistsOpInit *ExistsOpInit::get(const RecTy *CheckType,
const Init *Expr) {
- FoldingSetNodeID ID;
- ProfileExistsOpInit(ID, CheckType, Expr);
-
detail::RecordKeeperImpl &RK = Expr->getRecordKeeper().getImpl();
FoldingSetInsertToken Token;
- if (const ExistsOpInit *I = RK.TheExistsOpInitPool.lookup(ID, Token))
+ if (const ExistsOpInit *I = RK.TheExistsOpInitPool.lookup({CheckType, Expr}, Token))
return I;
ExistsOpInit *I = new (RK.Allocator) ExistsOpInit(CheckType, Expr);
@@ -2198,10 +2129,6 @@ const ExistsOpInit *ExistsOpInit::get(const RecTy *CheckType,
return I;
}
-void ExistsOpInit::Profile(FoldingSetNodeID &ID) const {
- ProfileExistsOpInit(ID, CheckType, Expr);
-}
-
const Init *ExistsOpInit::Fold(const Record *CurRec, bool IsFinal) const {
if (const auto *Name = dyn_cast<StringInit>(Expr)) {
// Look up all defined records to see if we can find one.
@@ -2251,20 +2178,11 @@ std::string ExistsOpInit::getAsString() const {
.str();
}
-static void ProfileInstancesOpInit(FoldingSetNodeID &ID, const RecTy *Type,
- const Init *Regex) {
- ID.AddPointer(Type);
- ID.AddPointer(Regex);
-}
-
const InstancesOpInit *InstancesOpInit::get(const RecTy *Type,
const Init *Regex) {
- FoldingSetNodeID ID;
- ProfileInstancesOpInit(ID, Type, Regex);
-
detail::RecordKeeperImpl &RK = Regex->getRecordKeeper().getImpl();
FoldingSetInsertToken Token;
- if (const InstancesOpInit *I = RK.TheInstancesOpInitPool.lookup(ID, Token))
+ if (const InstancesOpInit *I = RK.TheInstancesOpInitPool.lookup({Type, Regex}, Token))
return I;
InstancesOpInit *I = new (RK.Allocator) InstancesOpInit(Type, Regex);
@@ -2272,10 +2190,6 @@ const InstancesOpInit *InstancesOpInit::get(const RecTy *Type,
return I;
}
-void InstancesOpInit::Profile(FoldingSetNodeID &ID) const {
- ProfileInstancesOpInit(ID, Type, Regex);
-}
-
const Init *InstancesOpInit::Fold(const Record *CurRec, bool IsFinal) const {
if (CurRec && !IsFinal)
return this;
@@ -2433,15 +2347,6 @@ const RecTy *DefInit::getFieldType(const StringInit *FieldName) const {
std::string DefInit::getAsString() const { return Def->getName().str(); }
-static void ProfileVarDefInit(FoldingSetNodeID &ID, const Record *Class,
- ArrayRef<const ArgumentInit *> Args) {
- ID.AddInteger(Args.size());
- ID.AddPointer(Class);
-
- for (const Init *I : Args)
- ID.AddPointer(I);
-}
-
VarDefInit::VarDefInit(SMLoc Loc, const Record *Class,
ArrayRef<const ArgumentInit *> Args)
: TypedInit(IK_VarDefInit, RecordRecTy::get(Class)), Loc(Loc), Class(Class),
@@ -2451,12 +2356,9 @@ VarDefInit::VarDefInit(SMLoc Loc, const Record *Class,
const VarDefInit *VarDefInit::get(SMLoc Loc, const Record *Class,
ArrayRef<const ArgumentInit *> Args) {
- FoldingSetNodeID ID;
- ProfileVarDefInit(ID, Class, Args);
-
detail::RecordKeeperImpl &RK = Class->getRecords().getImpl();
FoldingSetInsertToken Token;
- if (const VarDefInit *I = RK.TheVarDefInitPool.lookup(ID, Token))
+ if (const VarDefInit *I = RK.TheVarDefInitPool.lookup({Class, Args}, Token))
return I;
void *Mem = RK.Allocator.Allocate(
@@ -2466,10 +2368,6 @@ const VarDefInit *VarDefInit::get(SMLoc Loc, const Record *Class,
return I;
}
-void VarDefInit::Profile(FoldingSetNodeID &ID) const {
- ProfileVarDefInit(ID, Class, args());
-}
-
const DefInit *VarDefInit::instantiate() {
if (Def)
return Def;
@@ -2612,20 +2510,6 @@ bool FieldInit::isConcrete() const {
return false;
}
-static void ProfileCondOpInit(FoldingSetNodeID &ID,
- ArrayRef<const Init *> Conds,
- ArrayRef<const Init *> Vals,
- const RecTy *ValType) {
- assert(Conds.size() == Vals.size() &&
- "Number of conditions and values must match!");
- ID.AddPointer(ValType);
-
- for (const auto &[Cond, Val] : zip(Conds, Vals)) {
- ID.AddPointer(Cond);
- ID.AddPointer(Val);
- }
-}
-
CondOpInit::CondOpInit(ArrayRef<const Init *> Conds,
ArrayRef<const Init *> Values, const RecTy *Type)
: TypedInit(IK_CondOpInit, Type), NumConds(Conds.size()), ValType(Type) {
@@ -2634,22 +2518,15 @@ CondOpInit::CondOpInit(ArrayRef<const Init *> Conds,
llvm::uninitialized_copy(Values, TrailingObjects + NumConds);
}
-void CondOpInit::Profile(FoldingSetNodeID &ID) const {
- ProfileCondOpInit(ID, getConds(), getVals(), ValType);
-}
-
const CondOpInit *CondOpInit::get(ArrayRef<const Init *> Conds,
ArrayRef<const Init *> Values,
const RecTy *Ty) {
assert(Conds.size() == Values.size() &&
"Number of conditions and values must match!");
- FoldingSetNodeID ID;
- ProfileCondOpInit(ID, Conds, Values, Ty);
-
detail::RecordKeeperImpl &RK = Ty->getRecordKeeper().getImpl();
FoldingSetInsertToken Token;
- if (const CondOpInit *I = RK.TheCondOpInitPool.lookup(ID, Token))
+ if (const CondOpInit *I = RK.TheCondOpInitPool.lookup({Ty, Conds, Values}, Token))
return I;
void *Mem = RK.Allocator.Allocate(
@@ -2739,18 +2616,6 @@ const Init *CondOpInit::getBit(unsigned Bit) const {
return VarBitInit::get(this, Bit);
}
-static void ProfileDagInit(FoldingSetNodeID &ID, const Init *V,
- const StringInit *VN, ArrayRef<const Init *> Args,
- ArrayRef<const StringInit *> ArgNames) {
- ID.AddPointer(V);
- ID.AddPointer(VN);
-
- for (auto [Arg, Name] : zip_equal(Args, ArgNames)) {
- ID.AddPointer(Arg);
- ID.AddPointer(Name);
- }
-}
-
DagInit::DagInit(const Init *V, const StringInit *VN,
ArrayRef<const Init *> Args,
ArrayRef<const StringInit *> ArgNames)
@@ -2766,12 +2631,10 @@ const DagInit *DagInit::get(const Init *V, const StringInit *VN,
assert(Args.size() == ArgNames.size() &&
"Number of DAG args and arg names must match!");
- FoldingSetNodeID ID;
- ProfileDagInit(ID, V, VN, Args, ArgNames);
-
detail::RecordKeeperImpl &RK = V->getRecordKeeper().getImpl();
FoldingSetInsertToken Token;
- if (const DagInit *I = RK.TheDagInitPool.lookup(ID, Token))
+ if (const DagInit *I =
+ RK.TheDagInitPool.lookup({V, VN, Args, ArgNames}, Token))
return I;
void *Mem =
@@ -2791,10 +2654,6 @@ const DagInit *DagInit::get(
return DagInit::get(V, VN, Args, Names);
}
-void DagInit::Profile(FoldingSetNodeID &ID) const {
- ProfileDagInit(ID, Val, ValName, getArgs(), getArgNames());
-}
-
const Record *DagInit::getOperatorAsDef(ArrayRef<SMLoc> Loc) const {
if (const auto *DefI = dyn_cast<DefInit>(Val))
return DefI->getDef();
>From 82c7ee7218b59dd4e1226da6ca862991fc23a24d Mon Sep 17 00:00:00 2001
From: Fangrui Song <i at maskray.me>
Date: Fri, 4 Sep 2026 23:03:03 -0700
Subject: [PATCH 2/3] format
---
llvm/lib/TableGen/Record.cpp | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/llvm/lib/TableGen/Record.cpp b/llvm/lib/TableGen/Record.cpp
index de3272ad3c045..3714ba9166f01 100644
--- a/llvm/lib/TableGen/Record.cpp
+++ b/llvm/lib/TableGen/Record.cpp
@@ -2016,7 +2016,8 @@ const FoldOpInit *FoldOpInit::get(const Init *Start, const Init *List,
const Init *Expr, const RecTy *Type) {
detail::RecordKeeperImpl &RK = Start->getRecordKeeper().getImpl();
FoldingSetInsertToken Token;
- if (const FoldOpInit *I = RK.TheFoldOpInitPool.lookup({Start, List, A, B, Expr, Type}, Token))
+ if (const FoldOpInit *I =
+ RK.TheFoldOpInitPool.lookup({Start, List, A, B, Expr, Type}, Token))
return I;
FoldOpInit *I = new (RK.Allocator) FoldOpInit(Start, List, A, B, Expr, Type);
@@ -2121,7 +2122,8 @@ const ExistsOpInit *ExistsOpInit::get(const RecTy *CheckType,
const Init *Expr) {
detail::RecordKeeperImpl &RK = Expr->getRecordKeeper().getImpl();
FoldingSetInsertToken Token;
- if (const ExistsOpInit *I = RK.TheExistsOpInitPool.lookup({CheckType, Expr}, Token))
+ if (const ExistsOpInit *I =
+ RK.TheExistsOpInitPool.lookup({CheckType, Expr}, Token))
return I;
ExistsOpInit *I = new (RK.Allocator) ExistsOpInit(CheckType, Expr);
@@ -2182,7 +2184,8 @@ const InstancesOpInit *InstancesOpInit::get(const RecTy *Type,
const Init *Regex) {
detail::RecordKeeperImpl &RK = Regex->getRecordKeeper().getImpl();
FoldingSetInsertToken Token;
- if (const InstancesOpInit *I = RK.TheInstancesOpInitPool.lookup({Type, Regex}, Token))
+ if (const InstancesOpInit *I =
+ RK.TheInstancesOpInitPool.lookup({Type, Regex}, Token))
return I;
InstancesOpInit *I = new (RK.Allocator) InstancesOpInit(Type, Regex);
@@ -2526,7 +2529,8 @@ const CondOpInit *CondOpInit::get(ArrayRef<const Init *> Conds,
detail::RecordKeeperImpl &RK = Ty->getRecordKeeper().getImpl();
FoldingSetInsertToken Token;
- if (const CondOpInit *I = RK.TheCondOpInitPool.lookup({Ty, Conds, Values}, Token))
+ if (const CondOpInit *I =
+ RK.TheCondOpInitPool.lookup({Ty, Conds, Values}, Token))
return I;
void *Mem = RK.Allocator.Allocate(
>From c8ec0e388c4cf5fd60418ed13296b0c2b2d38ac0 Mon Sep 17 00:00:00 2001
From: Fangrui Song <i at maskray.me>
Date: Sat, 5 Sep 2026 16:31:19 -0700
Subject: [PATCH 3/3] Migrate ArgumentInit
---
llvm/include/llvm/TableGen/Record.h | 3 ++-
llvm/lib/TableGen/Record.cpp | 30 ++++++-----------------------
2 files changed, 8 insertions(+), 25 deletions(-)
diff --git a/llvm/include/llvm/TableGen/Record.h b/llvm/include/llvm/TableGen/Record.h
index 8a69dc9941ac8..fd191acdbe5d1 100644
--- a/llvm/include/llvm/TableGen/Record.h
+++ b/llvm/include/llvm/TableGen/Record.h
@@ -16,6 +16,7 @@
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/DenseMapInfoVariant.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/FoldingSet.h"
#include "llvm/ADT/PointerIntPair.h"
@@ -530,7 +531,7 @@ class ArgumentInit final : public Init, public FoldingSetNode {
return get(Value, Aux);
}
- void Profile(FoldingSetNodeID &ID) const;
+ std::pair<const Init *, ArgAuxType> getKey() const { return {Value, Aux}; }
const Init *resolveReferences(Resolver &R) const override;
std::string getAsString() const override {
diff --git a/llvm/lib/TableGen/Record.cpp b/llvm/lib/TableGen/Record.cpp
index 3714ba9166f01..c529734f674b1 100644
--- a/llvm/lib/TableGen/Record.cpp
+++ b/llvm/lib/TableGen/Record.cpp
@@ -70,7 +70,7 @@ struct detail::RecordKeeperImpl {
BitInit TrueBitInit;
BitInit FalseBitInit;
- FoldingSet<ArgumentInit> TheArgumentInitPool;
+ UniquingSet<ArgumentInit> TheArgumentInitPool;
UniquingSet<BitsInit> TheBitsInitPool;
std::map<int64_t, IntInit *> TheIntInitPool;
StringMap<const StringInit *, BumpPtrAllocator &> StringInitStringPool;
@@ -381,33 +381,15 @@ const Init *UnsetInit::convertInitializerTo(const RecTy *Ty) const {
return this;
}
-static void ProfileArgumentInit(FoldingSetNodeID &ID, const Init *Value,
- ArgAuxType Aux) {
- auto I = Aux.index();
- ID.AddInteger(I);
- if (I == ArgumentInit::Positional)
- ID.AddInteger(std::get<ArgumentInit::Positional>(Aux));
- if (I == ArgumentInit::Named)
- ID.AddPointer(std::get<ArgumentInit::Named>(Aux));
- ID.AddPointer(Value);
-}
-
-void ArgumentInit::Profile(FoldingSetNodeID &ID) const {
- ProfileArgumentInit(ID, Value, Aux);
-}
-
const ArgumentInit *ArgumentInit::get(const Init *Value, ArgAuxType Aux) {
- FoldingSetNodeID ID;
- ProfileArgumentInit(ID, Value, Aux);
-
- RecordKeeper &RK = Value->getRecordKeeper();
- detail::RecordKeeperImpl &RKImpl = RK.getImpl();
+ detail::RecordKeeperImpl &RK = Value->getRecordKeeper().getImpl();
FoldingSetInsertToken Token;
- if (const ArgumentInit *I = RKImpl.TheArgumentInitPool.lookup(ID, Token))
+ if (const ArgumentInit *I =
+ RK.TheArgumentInitPool.lookup({Value, Aux}, Token))
return I;
- ArgumentInit *I = new (RKImpl.Allocator) ArgumentInit(Value, Aux);
- RKImpl.TheArgumentInitPool.insert(I, Token);
+ ArgumentInit *I = new (RK.Allocator) ArgumentInit(Value, Aux);
+ RK.TheArgumentInitPool.insert(I, Token);
return I;
}
More information about the llvm-commits
mailing list