Skip to content

Commit c7c1a20

Browse files
committed
[RequirementMachine] Store the singleton 'Storage' instance for shape
symbols in RewriteContext.
1 parent abb501d commit c7c1a20

File tree

3 files changed

+7
-17
lines changed

3 files changed

+7
-17
lines changed

lib/AST/RequirementMachine/RewriteContext.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ static DebugOptions parseDebugFlags(StringRef debugFlags) {
194194
}
195195

196196
RewriteContext::RewriteContext(ASTContext &ctx)
197-
: Context(ctx),
197+
: TheShapeSymbol(nullptr),
198+
Context(ctx),
198199
Stats(ctx.Stats),
199200
SymbolHistogram(Symbol::NumKinds),
200201
TermHistogram(4, /*Start=*/1),

lib/AST/RequirementMachine/RewriteContext.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ class RewriteContext final {
4545
/// Folding set for uniquing symbols.
4646
llvm::FoldingSet<Symbol::Storage> Symbols;
4747

48+
/// The singleton storage for shape symbols.
49+
Symbol::Storage *TheShapeSymbol;
50+
4851
/// Folding set for uniquing terms.
4952
llvm::FoldingSet<Term::Storage> Terms;
5053

lib/AST/RequirementMachine/Symbol.cpp

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -307,27 +307,13 @@ Symbol Symbol::forGenericParam(GenericTypeParamType *param,
307307
}
308308

309309
Symbol Symbol::forShape(RewriteContext &ctx) {
310-
llvm::FoldingSetNodeID id;
311-
id.AddInteger(unsigned(Kind::Shape));
312-
313-
void *insertPos = nullptr;
314-
if (auto *symbol = ctx.Symbols.FindNodeOrInsertPos(id, insertPos))
310+
if (auto *symbol = ctx.TheShapeSymbol)
315311
return symbol;
316312

317313
unsigned size = Storage::totalSizeToAlloc<unsigned, Term>(0, 0);
318314
void *mem = ctx.Allocator.Allocate(size, alignof(Storage));
319315
auto *symbol = new (mem) Storage(Storage::ForShape());
320-
321-
#ifndef NDEBUG
322-
llvm::FoldingSetNodeID newID;
323-
symbol->Profile(newID);
324-
assert(id == newID);
325-
#endif
326-
327-
ctx.Symbols.InsertNode(symbol, insertPos);
328-
ctx.SymbolHistogram.add(unsigned(Kind::Shape));
329-
330-
return symbol;
316+
return (ctx.TheShapeSymbol = symbol);
331317
}
332318

333319
/// Creates a layout symbol, representing a layout constraint.

0 commit comments

Comments
 (0)