aboutsummaryrefslogtreecommitdiff
path: root/include/clang/Lex/PreprocessingRecord.h
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-03-19 21:51:54 +0000
committerDouglas Gregor <dgregor@apple.com>2010-03-19 21:51:54 +0000
commit6a5a23f8e7fb65e028c8092bc1d1a1d9dfe2e9bc (patch)
treeca3c65a123fff4e56a3b6d2090f716334c63aade /include/clang/Lex/PreprocessingRecord.h
parent8d52cbdce856d6498a5c454b8e113498e645cc4d (diff)
Implement serialization and lazy deserialization of the preprocessing
record (which includes all macro instantiations and definitions). As with all lay deserialization, this introduces a new external source (here, an external preprocessing record source) that loads all of the preprocessed entities prior to iterating over the entities. The preprocessing record is an optional part of the precompiled header that is disabled by default (enabled with -detailed-preprocessing-record). When the preprocessor given to the PCH writer has a preprocessing record, that record is written into the PCH file. When the PCH reader is given a PCH file that contains a preprocessing record, it will be lazily loaded (which, effectively, implicitly adds -detailed-preprocessing-record). This is the first case where we have sections of the precompiled header that are added/removed based on a compilation flag, which is unfortunate. However, this data consumes ~550k in the PCH file for Cocoa.h (out of ~9.9MB), and there is a non-trivial cost to gathering this detailed preprocessing information, so it's too expensive to turn on by default. In the future, we should investigate a better encoding of this information. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@99002 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Lex/PreprocessingRecord.h')
-rw-r--r--include/clang/Lex/PreprocessingRecord.h51
1 files changed, 47 insertions, 4 deletions
diff --git a/include/clang/Lex/PreprocessingRecord.h b/include/clang/Lex/PreprocessingRecord.h
index 30e5a5a4b0..b40bf36bc1 100644
--- a/include/clang/Lex/PreprocessingRecord.h
+++ b/include/clang/Lex/PreprocessingRecord.h
@@ -173,7 +173,18 @@ namespace clang {
}
static bool classof(const MacroDefinition *) { return true; }
};
+
+ /// \brief An abstract class that should be subclassed by any external source
+ /// of preprocessing record entries.
+ class ExternalPreprocessingRecordSource {
+ public:
+ virtual ~ExternalPreprocessingRecordSource();
+ /// \brief Read any preallocated preprocessed entities from the external
+ /// source.
+ virtual void ReadPreprocessedEntities() = 0;
+ };
+
/// \brief A record of the steps taken while preprocessing a source file,
/// including the various preprocessing directives processed, macros
/// instantiated, etc.
@@ -188,7 +199,21 @@ namespace clang {
/// \brief Mapping from MacroInfo structures to their definitions.
llvm::DenseMap<const MacroInfo *, MacroDefinition *> MacroDefinitions;
+ /// \brief External source of preprocessed entities.
+ ExternalPreprocessingRecordSource *ExternalSource;
+
+ /// \brief The number of preallocated entities (that are known to the
+ /// external source).
+ unsigned NumPreallocatedEntities;
+
+ /// \brief Whether we have already loaded all of the preallocated entities.
+ mutable bool LoadedPreallocatedEntities;
+
+ void MaybeLoadPreallocatedEntities() const ;
+
public:
+ PreprocessingRecord();
+
/// \brief Allocate memory in the preprocessing record.
void *Allocate(unsigned Size, unsigned Align = 8) {
return BumpAlloc.Allocate(Size, Align);
@@ -200,14 +225,32 @@ namespace clang {
// Iteration over the preprocessed entities.
typedef std::vector<PreprocessedEntity *>::iterator iterator;
typedef std::vector<PreprocessedEntity *>::const_iterator const_iterator;
- iterator begin() { return PreprocessedEntities.begin(); }
- iterator end() { return PreprocessedEntities.end(); }
- const_iterator begin() const { return PreprocessedEntities.begin(); }
- const_iterator end() const { return PreprocessedEntities.end(); }
+ iterator begin(bool OnlyLocalEntities = false);
+ iterator end(bool OnlyLocalEntities = false);
+ const_iterator begin(bool OnlyLocalEntities = false) const;
+ const_iterator end(bool OnlyLocalEntities = false) const;
/// \brief Add a new preprocessed entity to this record.
void addPreprocessedEntity(PreprocessedEntity *Entity);
+ /// \brief Set the external source for preprocessed entities.
+ void SetExternalSource(ExternalPreprocessingRecordSource &Source,
+ unsigned NumPreallocatedEntities);
+
+ /// \brief Set the preallocated entry at the given index to the given
+ /// preprocessed entity.
+ void SetPreallocatedEntity(unsigned Index, PreprocessedEntity *Entity);
+
+ /// \brief Register a new macro definition.
+ void RegisterMacroDefinition(MacroInfo *Macro, MacroDefinition *MD);
+
+ /// \brief Retrieve the preprocessed entity at the given index.
+ PreprocessedEntity *getPreprocessedEntity(unsigned Index) {
+ assert(Index < PreprocessedEntities.size() &&
+ "Out-of-bounds preprocessed entity");
+ return PreprocessedEntities[Index];
+ }
+
/// \brief Retrieve the macro definition that corresponds to the given
/// \c MacroInfo.
MacroDefinition *findMacroDefinition(MacroInfo *MI);