aboutsummaryrefslogtreecommitdiff
path: root/include/clang/Serialization/GlobalModuleIndex.h
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2013-01-23 22:38:11 +0000
committerDouglas Gregor <dgregor@apple.com>2013-01-23 22:38:11 +0000
commita6b00fc97669aa25d89ae9f202b05dfadfd0e324 (patch)
treea6fae4a9348c9d4f18d0bafbbf41953becb6fecf /include/clang/Serialization/GlobalModuleIndex.h
parent38878aa394dc6e08146288e86939956bc742fb0b (diff)
Implement the writer side of the global module index.
The global module index is a "global" index for all of the module files within a particular subdirectory in the module cache, which keeps track of all of the "interesting" identifiers and selectors known in each of the module files. One can perform a fast lookup in the index to determine which module files will have more information about entities with a particular name/selector. This information can help eliminate redundant lookups into module files (a serious performance problem) and help with creating auto-import/auto-include Fix-Its. The global module index is created or updated at the end of a translation unit that has triggered a (re)build of a module by scraping all of the .pcm files out of the module cache subdirectory, so it catches everything. As with module rebuilds, we use the file system's atomicity to synchronize. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173301 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Serialization/GlobalModuleIndex.h')
-rw-r--r--include/clang/Serialization/GlobalModuleIndex.h119
1 files changed, 119 insertions, 0 deletions
diff --git a/include/clang/Serialization/GlobalModuleIndex.h b/include/clang/Serialization/GlobalModuleIndex.h
new file mode 100644
index 0000000000..cac6c3a56e
--- /dev/null
+++ b/include/clang/Serialization/GlobalModuleIndex.h
@@ -0,0 +1,119 @@
+//===--- GlobalModuleIndex.h - Global Module Index --------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file defines the GlobalModuleIndex class, which manages a global index
+// containing all of the identifiers with namespace-scope bindings attached to
+// them as well as all of the selectors that name methods, across all of the
+// modules within a given subdirectory of the module cache. It is used to
+// improve the performance of queries such as "does this identifier have any
+// top-level bindings in any module?"
+//
+//===----------------------------------------------------------------------===//
+#ifndef LLVM_CLANG_SERIALIZATION_GLOBAL_MODULE_INDEX_H
+#define LLVM_CLANG_SERIALIZATION_GLOBAL_MODULE_INDEX_H
+
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringRef.h"
+#include <utility>
+
+namespace clang {
+
+class DeclarationName;
+class DirectoryEntry;
+class FileEntry;
+class FileManager;
+
+using llvm::SmallVector;
+using llvm::SmallVectorImpl;
+using llvm::StringRef;
+
+/// \brief A global index for a set of module files, providing information about
+/// the top-level identifiers and selectors within those module files.
+///
+/// The global index is an aid for name lookup into modules, offering a central
+/// place where one can look for identifiers or selectors to determine which
+/// module files contain a namespace-scope identity with that identifier or
+/// a method with that selector, respectively. This allows the client to
+/// restrict the search to only those module files known to have a binding for
+/// that identifier or selector, improving performance. Moreover, the global
+/// module index may know about module files that have not been imported, and
+/// can be queried to determine which modules the currently translation could
+/// or should load to fix a problem.
+class GlobalModuleIndex {
+ /// \brief Internal constructor. Use \c readIndex() to read an index.
+ explicit GlobalModuleIndex(FileManager &FileMgr);
+
+public:
+ /// \brief An error code returned when trying to read an index.
+ enum ErrorCode {
+ /// \brief No error occurred.
+ EC_None,
+ /// \brief The index found was out-of-date, meaning that some of the
+ /// module files are newer than the index.
+ ///
+ /// This error code is not actually fatal, because if the index is
+ /// up-to-date for any module files, it is
+ EC_OutOfDate,
+ /// \brief No index was found.
+ EC_NotFound,
+ /// \brief Some other process is currently building the index; it is not
+ /// available yet.
+ EC_Building,
+ /// \brief There was an unspecified I/O error reading or writing the index.
+ EC_IOError
+ };
+
+ /// \brief Read a global index file for the given directory.
+ ///
+ /// \param FileMgr The file manager to use for reading files.
+ ///
+ /// \param Path The path to the specific module cache where the module files
+ /// for the intended configuration reside.
+ ///
+ /// \returns A pair containing the global module index (if it exists) and
+ /// the error code.
+ static std::pair<GlobalModuleIndex *, ErrorCode>
+ readIndex(FileManager &FileMgr, StringRef Path);
+
+ /// \brief Retrieve the set of modules that have up-to-date indexes.
+ ///
+ /// \param ModuleFiles Will be populated with the set of module files that
+ /// have been indexed.
+ void getKnownModules(SmallVectorImpl<const FileEntry *> &ModuleFiles);
+
+ /// \brief Retrieve the set of module files on which the given module file
+ /// directly depends.
+ void getModuleDependencies(const FileEntry *ModuleFile,
+ SmallVectorImpl<const FileEntry *> &Dependencies);
+
+ /// \brief Look for all of the module files with a namespace-scope binding
+ /// for the given name, e.g., a global function, variable, or type with that
+ /// name, or declare a method with the selector.
+ ///
+ /// \param Name The name or selector to look for.
+ ///
+ /// \param DeclaringModuleFiles Will be populated with the list of module
+ /// files that declare entities with the given name.
+ ///
+ /// \returns true if any module files were found, false otherwise.
+ bool lookupName(DeclarationName Name,
+ SmallVectorImpl<const FileEntry *> &DeclaringModuleFiles);
+
+ /// \brief Write a global index into the given
+ ///
+ /// \param FileMgr The file manager to use to load module files.
+ ///
+ /// \param Path The path to the directory containing module files, into
+ /// which the global index will be written.
+ static ErrorCode writeIndex(FileManager &FileMgr, StringRef Path);
+};
+
+}
+
+#endif