summaryrefslogtreecommitdiffstats
path: root/clang/include
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-08-16 18:08:11 +0000
committerDouglas Gregor <dgregor@apple.com>2010-08-16 18:08:11 +0000
commitb61c07aca03841b461bc8f9b44c93be9abc0c640 (patch)
tree6d22032ef78a7331f93e4832aa8cdcf1608a92dd /clang/include
parent8be0196afeed5dd738fce4c7df950f205e462c13 (diff)
downloadbcm5719-llvm-b61c07aca03841b461bc8f9b44c93be9abc0c640.tar.gz
bcm5719-llvm-b61c07aca03841b461bc8f9b44c93be9abc0c640.zip
When caching code completions for global declarations, keep track of
the usage type of each declaration result, then compare those types to the preferred type of the completion. This provides parity in the priority calculation between the code-completion results produced directly from Sema and those cached by ASTUnit. For the standard Cocoa.h (+ others) example, there's a penalty of 3-4 hundredeths of a second when caching the global results (for ~31,000 results), because we need an ASTContext-agnostic representation of types for the comparison, and therefore we use... strings. Eventually, we'd like to implement a more efficient ASTContext-agnostic encoding of types. llvm-svn: 111165
Diffstat (limited to 'clang/include')
-rw-r--r--clang/include/clang/AST/CanonicalType.h6
-rw-r--r--clang/include/clang/AST/TypeOrdering.h21
-rw-r--r--clang/include/clang/Frontend/ASTUnit.h18
3 files changed, 42 insertions, 3 deletions
diff --git a/clang/include/clang/AST/CanonicalType.h b/clang/include/clang/AST/CanonicalType.h
index a1023a2810d..dad4dfc926e 100644
--- a/clang/include/clang/AST/CanonicalType.h
+++ b/clang/include/clang/AST/CanonicalType.h
@@ -703,9 +703,9 @@ inline CanQual<Type> CanQual<T>::getNonReferenceType() const {
template<typename T>
CanQual<T> CanQual<T>::getFromOpaquePtr(void *Ptr) {
CanQual<T> Result;
- Result.Stored.setFromOpaqueValue(Ptr);
- assert((!Result || Result.Stored.isCanonical())
- && "Type is not canonical!");
+ Result.Stored = QualType::getFromOpaquePtr(Ptr);
+ assert((!Result || Result.Stored.getAsOpaquePtr() == (void*)-1 ||
+ Result.Stored.isCanonical()) && "Type is not canonical!");
return Result;
}
diff --git a/clang/include/clang/AST/TypeOrdering.h b/clang/include/clang/AST/TypeOrdering.h
index 1a050d29c86..7cf0d5e999b 100644
--- a/clang/include/clang/AST/TypeOrdering.h
+++ b/clang/include/clang/AST/TypeOrdering.h
@@ -17,6 +17,7 @@
#define LLVM_CLANG_TYPE_ORDERING_H
#include "clang/AST/Type.h"
+#include "clang/AST/CanonicalType.h"
#include <functional>
namespace clang {
@@ -51,6 +52,26 @@ namespace llvm {
return LHS == RHS;
}
};
+
+ template<> struct DenseMapInfo<clang::CanQualType> {
+ static inline clang::CanQualType getEmptyKey() {
+ return clang::CanQualType();
+ }
+
+ static inline clang::CanQualType getTombstoneKey() {
+ using clang::CanQualType;
+ return CanQualType::getFromOpaquePtr(reinterpret_cast<clang::Type *>(-1));
+ }
+
+ static unsigned getHashValue(clang::CanQualType Val) {
+ return (unsigned)((uintptr_t)Val.getAsOpaquePtr()) ^
+ ((unsigned)((uintptr_t)Val.getAsOpaquePtr() >> 9));
+ }
+
+ static bool isEqual(clang::CanQualType LHS, clang::CanQualType RHS) {
+ return LHS == RHS;
+ }
+ };
}
#endif
diff --git a/clang/include/clang/Frontend/ASTUnit.h b/clang/include/clang/Frontend/ASTUnit.h
index f8859425ff9..77a641a2c5d 100644
--- a/clang/include/clang/Frontend/ASTUnit.h
+++ b/clang/include/clang/Frontend/ASTUnit.h
@@ -235,12 +235,30 @@ public:
/// \brief The simplified type class for a non-macro completion result.
SimplifiedTypeClass TypeClass;
+
+ /// \brief The type of a non-macro completion result, stored as a unique
+ /// integer used by the string map of cached completion types.
+ ///
+ /// This value will be zero if the type is not known, or a unique value
+ /// determined by the formatted type string. Se \c CachedCompletionTypes
+ /// for more information.
+ unsigned Type;
};
+ /// \brief Retrieve the mapping from formatted type names to unique type
+ /// identifiers.
+ llvm::StringMap<unsigned> &getCachedCompletionTypes() {
+ return CachedCompletionTypes;
+ }
+
private:
/// \brief The set of cached code-completion results.
std::vector<CachedCodeCompletionResult> CachedCompletionResults;
+ /// \brief A mapping from the formatted type name to a unique number for that
+ /// type, which is used for type equality comparisons.
+ llvm::StringMap<unsigned> CachedCompletionTypes;
+
/// \brief Cache any "global" code-completion results, so that we can avoid
/// recomputing them with each completion.
void CacheCodeCompletionResults();
OpenPOWER on IntegriCloud