Skip to content

Commit e3dd06f

Browse files
committed
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 1650151 commit e3dd06f

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
@@ -14901,6 +14901,8 @@ class Sema final : public SemaBase {
1490114901
const NamedDecl *D1, ArrayRef<AssociatedConstraint> AC1,
1490214902
const NamedDecl *D2, ArrayRef<AssociatedConstraint> AC2);
1490314903

14904+
llvm::DenseMap<unsigned, MutableArrayRef<TemplateArgumentLoc>>
14905+
ParameterMappingCache;
1490414906
private:
1490514907
/// Caches pairs of template-like decls whose associated constraints were
1490614908
/// 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
@@ -1542,6 +1542,7 @@ const NormalizedConstraint *Sema::getNormalizedAssociatedConstraints(
15421542
return NormalizedConstraint::fromAssociatedConstraints(
15431543
*this, nullptr, AssociatedConstraints);
15441544

1545+
// FIXME: ConstrainedDeclOrNestedReq is never a NestedRequirement!
15451546
const NamedDecl *ND =
15461547
ConstrainedDeclOrNestedReq.dyn_cast<const NamedDecl *>();
15471548
auto CacheEntry = NormalizationCache.find(ConstrainedDeclOrNestedReq);
@@ -1624,6 +1625,31 @@ substituteParameterMappings(Sema &S, NormalizedConstraintWithParamMapping &N,
16241625
{InstLocBegin, InstLocEnd});
16251626
if (Inst.isInvalid())
16261627
return true;
1628+
1629+
unsigned Hash;
1630+
llvm::FoldingSetNodeID ID;
1631+
auto &Context = S.getASTContext();
1632+
if (N.getKind() == NormalizedConstraint::ConstraintKind::ConceptId) {
1633+
ID.AddPointer(static_cast<ConceptIdConstraint &>(N)
1634+
.getConceptId()
1635+
->getNamedConcept()
1636+
->getCanonicalDecl());
1637+
for (auto &ArgLoc : static_cast<ConceptIdConstraint &>(N)
1638+
.getConceptId()
1639+
->getTemplateArgsAsWritten()
1640+
->arguments())
1641+
ArgLoc.getArgument().Profile(ID, Context);
1642+
1643+
Hash = ID.ComputeHash();
1644+
if (auto Iter = S.ParameterMappingCache.find(Hash);
1645+
Iter != S.ParameterMappingCache.end()) {
1646+
N.updateParameterMapping(N.mappingOccurenceList(), Iter->second,
1647+
N.getUsedTemplateParamList());
1648+
return false;
1649+
}
1650+
}
1651+
// FIXME: Cache for atomic constraints.
1652+
16271653
// TransformTemplateArguments is unable to preserve the source location of a
16281654
// pack. The SourceLocation is necessary for the instantiation location.
16291655
// FIXME: The BaseLoc will be used as the location of the pack expansion,
@@ -1653,10 +1679,12 @@ substituteParameterMappings(Sema &S, NormalizedConstraintWithParamMapping &N,
16531679
// N.updateParameterMapping(
16541680
// N.mappingOccurenceList(),
16551681
// MutableArrayRef<TemplateArgumentLoc>(TempArgs, SubstArgs.size()));
1656-
N.updateParameterMapping(N.mappingOccurenceList(),
1657-
MutableArrayRef<TemplateArgumentLoc>(
1658-
TempArgs, CTAI.SugaredConverted.size()),
1682+
MutableArrayRef<TemplateArgumentLoc> Mapping(TempArgs,
1683+
CTAI.SugaredConverted.size());
1684+
N.updateParameterMapping(N.mappingOccurenceList(), Mapping,
16591685
N.getUsedTemplateParamList());
1686+
if (N.getKind() == NormalizedConstraint::ConstraintKind::ConceptId)
1687+
S.ParameterMappingCache.insert({Hash, Mapping});
16601688
return false;
16611689
}
16621690

0 commit comments

Comments
 (0)