summaryrefslogtreecommitdiffstats
path: root/clang/lib/Basic/IdentifierTable.cpp
diff options
context:
space:
mode:
authorBruno Ricci <riccibrun@gmail.com>2018-09-21 12:53:22 +0000
committerBruno Ricci <riccibrun@gmail.com>2018-09-21 12:53:22 +0000
commit366ba73018477a247e5b5cb3a2aca1b1592a6571 (patch)
tree29de37f36b15431ee31cfe2f4d31f54a3785e78b /clang/lib/Basic/IdentifierTable.cpp
parent4cd5cf9fc8ef39c6041aec26809813c6cb3dbf41 (diff)
downloadbcm5719-llvm-366ba73018477a247e5b5cb3a2aca1b1592a6571.tar.gz
bcm5719-llvm-366ba73018477a247e5b5cb3a2aca1b1592a6571.zip
[AST] Various optimizations + refactoring in DeclarationName(Table)
Introduce the following optimizations in DeclarationName(Table): 1. Store common kinds inline in DeclarationName instead of DeclarationNameExtra. Currently the kind of C++ constructor, destructor, conversion function and overloaded operator names is stored in DeclarationNameExtra. Instead store it inline in DeclarationName. To do this align IdentifierInfo, CXXSpecialName, DeclarationNameExtra and CXXOperatorIdName to 8 bytes so that we can use the lower 3 bits of DeclarationName::Ptr. This is already the case on 64 bits archs anyway. This also allow us to remove DeclarationNameExtra from CXXSpecialName and CXXOperatorIdName, which shave off a pointer from CXXSpecialName. 2. Synchronize the enumerations DeclarationName::NameKind, DeclarationName::StoredNameKind and Selector::IdentifierInfoFlag. This makes DeclarationName::getNameKind much more efficient since we can replace the switch table by a single comparison and an addition. 3. Put the overloaded operator names inline in DeclarationNameTable to remove an indirection. This increase the size of DeclarationNameTable a little bit but this is not important since it is only used in ASTContext, and never copied nor moved from. This also get rid of the last dynamic allocation in DeclarationNameTable. Altogether these optimizations cut the run time of parsing all of Boost by about 0.8%. While we are at it, do the following NFC modifications: 1. Put the internal classes CXXSpecialName, CXXDeductionGuideNameExtra, CXXOperatorIdName, CXXLiteralOperatorIdName and DeclarationNameExtra in a namespace detail since these classes are only meant to be used by DeclarationName and DeclarationNameTable. Make this more explicit by making the members of these classes private and friending DeclarationName(Table). 2. Make DeclarationName::getFETokenInfo a non-template since every users are using it to get a void *. It was supposed to be used with a type to avoid a subsequent static_cast. 3. Change the internal functions DeclarationName::getAs* to castAs* since when we use them we already know the correct kind. This has no external impact since all of these are private. Reviewed By: erichkeane, rjmccall Differential Revision: https://reviews.llvm.org/D52267 llvm-svn: 342729
Diffstat (limited to 'clang/lib/Basic/IdentifierTable.cpp')
-rw-r--r--clang/lib/Basic/IdentifierTable.cpp29
1 files changed, 14 insertions, 15 deletions
diff --git a/clang/lib/Basic/IdentifierTable.cpp b/clang/lib/Basic/IdentifierTable.cpp
index 7ec3cb7dd65..147f3e04751 100644
--- a/clang/lib/Basic/IdentifierTable.cpp
+++ b/clang/lib/Basic/IdentifierTable.cpp
@@ -382,24 +382,23 @@ unsigned llvm::DenseMapInfo<clang::Selector>::getHashValue(clang::Selector S) {
namespace clang {
-/// MultiKeywordSelector - One of these variable length records is kept for each
+/// One of these variable length records is kept for each
/// selector containing more than one keyword. We use a folding set
/// to unique aggregate names (keyword selectors in ObjC parlance). Access to
/// this class is provided strictly through Selector.
-class MultiKeywordSelector
- : public DeclarationNameExtra, public llvm::FoldingSetNode {
- MultiKeywordSelector(unsigned nKeys) {
- ExtraKindOrNumArgs = NUM_EXTRA_KINDS + nKeys;
- }
+class alignas(IdentifierInfoAlignment) MultiKeywordSelector
+ : public detail::DeclarationNameExtra,
+ public llvm::FoldingSetNode {
+ MultiKeywordSelector(unsigned nKeys) : DeclarationNameExtra(nKeys) {}
public:
// Constructor for keyword selectors.
- MultiKeywordSelector(unsigned nKeys, IdentifierInfo **IIV) {
+ MultiKeywordSelector(unsigned nKeys, IdentifierInfo **IIV)
+ : DeclarationNameExtra(nKeys) {
assert((nKeys > 1) && "not a multi-keyword selector");
- ExtraKindOrNumArgs = NUM_EXTRA_KINDS + nKeys;
// Fill in the trailing keyword array.
- IdentifierInfo **KeyInfo = reinterpret_cast<IdentifierInfo **>(this+1);
+ IdentifierInfo **KeyInfo = reinterpret_cast<IdentifierInfo **>(this + 1);
for (unsigned i = 0; i != nKeys; ++i)
KeyInfo[i] = IIV[i];
}
@@ -407,16 +406,16 @@ public:
// getName - Derive the full selector name and return it.
std::string getName() const;
- unsigned getNumArgs() const { return ExtraKindOrNumArgs - NUM_EXTRA_KINDS; }
+ using DeclarationNameExtra::getNumArgs;
using keyword_iterator = IdentifierInfo *const *;
keyword_iterator keyword_begin() const {
- return reinterpret_cast<keyword_iterator>(this+1);
+ return reinterpret_cast<keyword_iterator>(this + 1);
}
keyword_iterator keyword_end() const {
- return keyword_begin()+getNumArgs();
+ return keyword_begin() + getNumArgs();
}
IdentifierInfo *getIdentifierInfoForSlot(unsigned i) const {
@@ -424,8 +423,8 @@ public:
return keyword_begin()[i];
}
- static void Profile(llvm::FoldingSetNodeID &ID,
- keyword_iterator ArgTys, unsigned NumArgs) {
+ static void Profile(llvm::FoldingSetNodeID &ID, keyword_iterator ArgTys,
+ unsigned NumArgs) {
ID.AddInteger(NumArgs);
for (unsigned i = 0; i != NumArgs; ++i)
ID.AddPointer(ArgTys[i]);
@@ -462,7 +461,7 @@ IdentifierInfo *Selector::getIdentifierInfoForSlot(unsigned argIndex) const {
StringRef Selector::getNameForSlot(unsigned int argIndex) const {
IdentifierInfo *II = getIdentifierInfoForSlot(argIndex);
- return II? II->getName() : StringRef();
+ return II ? II->getName() : StringRef();
}
std::string MultiKeywordSelector::getName() const {
OpenPOWER on IntegriCloud