Skip to content

Commit 3cb8a9f

Browse files
zyn0217cor3ntin
authored andcommitted
Add parameter mapping cache
This helps reduce the time cost of time_zone.cpp from 44s -> 14s It still needs improvements, as previous clang only takes 3s.
1 parent 502ce79 commit 3cb8a9f

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

clang/include/clang/Sema/Sema.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14817,6 +14817,8 @@ class Sema final : public SemaBase {
1481714817
const NamedDecl *D1, ArrayRef<AssociatedConstraint> AC1,
1481814818
const NamedDecl *D2, ArrayRef<AssociatedConstraint> AC2);
1481914819

14820+
llvm::DenseMap<unsigned, MutableArrayRef<TemplateArgumentLoc>>
14821+
ParameterMappingCache;
1482014822
private:
1482114823
/// Caches pairs of template-like decls whose associated constraints were
1482214824
/// checked for subsumption and whether or not the first's constraints did in

clang/lib/Sema/SemaConcept.cpp

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,6 +1558,7 @@ const NormalizedConstraint *Sema::getNormalizedAssociatedConstraints(
15581558
return NormalizedConstraint::fromAssociatedConstraints(
15591559
*this, nullptr, AssociatedConstraints);
15601560

1561+
// FIXME: ConstrainedDeclOrNestedReq is never a NestedRequirement!
15611562
const NamedDecl *ND =
15621563
ConstrainedDeclOrNestedReq.dyn_cast<const NamedDecl *>();
15631564
auto CacheEntry = NormalizationCache.find(ConstrainedDeclOrNestedReq);
@@ -1640,6 +1641,31 @@ substituteParameterMappings(Sema &S, NormalizedConstraintWithParamMapping &N,
16401641
{InstLocBegin, InstLocEnd});
16411642
if (Inst.isInvalid())
16421643
return true;
1644+
1645+
unsigned Hash;
1646+
llvm::FoldingSetNodeID ID;
1647+
auto &Context = S.getASTContext();
1648+
if (N.getKind() == NormalizedConstraint::ConstraintKind::ConceptId) {
1649+
ID.AddPointer(static_cast<ConceptIdConstraint &>(N)
1650+
.getConceptId()
1651+
->getNamedConcept()
1652+
->getCanonicalDecl());
1653+
for (auto &ArgLoc : static_cast<ConceptIdConstraint &>(N)
1654+
.getConceptId()
1655+
->getTemplateArgsAsWritten()
1656+
->arguments())
1657+
ArgLoc.getArgument().Profile(ID, Context);
1658+
1659+
Hash = ID.ComputeHash();
1660+
if (auto Iter = S.ParameterMappingCache.find(Hash);
1661+
Iter != S.ParameterMappingCache.end()) {
1662+
N.updateParameterMapping(N.mappingOccurenceList(), Iter->second,
1663+
N.getUsedTemplateParamList());
1664+
return false;
1665+
}
1666+
}
1667+
// FIXME: Cache for atomic constraints.
1668+
16431669
// TransformTemplateArguments is unable to preserve the source location of a
16441670
// pack. The SourceLocation is necessary for the instantiation location.
16451671
// FIXME: The BaseLoc will be used as the location of the pack expansion,
@@ -1669,10 +1695,12 @@ substituteParameterMappings(Sema &S, NormalizedConstraintWithParamMapping &N,
16691695
// N.updateParameterMapping(
16701696
// N.mappingOccurenceList(),
16711697
// MutableArrayRef<TemplateArgumentLoc>(TempArgs, SubstArgs.size()));
1672-
N.updateParameterMapping(N.mappingOccurenceList(),
1673-
MutableArrayRef<TemplateArgumentLoc>(
1674-
TempArgs, CTAI.SugaredConverted.size()),
1698+
MutableArrayRef<TemplateArgumentLoc> Mapping(TempArgs,
1699+
CTAI.SugaredConverted.size());
1700+
N.updateParameterMapping(N.mappingOccurenceList(), Mapping,
16751701
N.getUsedTemplateParamList());
1702+
if (N.getKind() == NormalizedConstraint::ConstraintKind::ConceptId)
1703+
S.ParameterMappingCache.insert({Hash, Mapping});
16761704
return false;
16771705
}
16781706

0 commit comments

Comments
 (0)