mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-12-13 19:24:21 +00:00
Implement AST/PCH chaining support for macro definitions. Previously,
we would deserialize all of the macro definitions we knew about while serializing the macro definitions at the end of the AST/PCH file. Even though we skipped most of them (since they were unchanged), it's still a performance problem. Now, we do the standard AST/PCH chaining trick: watch what identifiers are deserialized as macro names, and consider only those identifiers (along with macro definitions that have been deserialized/written in the source) when serializing the preprocessor state. llvm-svn: 125324
This commit is contained in:
parent
0061ff20d8
commit
68051a74ec
@ -184,6 +184,9 @@ private:
|
||||
/// defined.
|
||||
llvm::DenseMap<const IdentifierInfo *, uint64_t> MacroOffsets;
|
||||
|
||||
/// \brief The set of identifiers that had macro definitions at some point.
|
||||
std::vector<const IdentifierInfo *> DeserializedMacroNames;
|
||||
|
||||
/// \brief The first ID number we can use for our own macro definitions.
|
||||
serialization::MacroID FirstMacroID;
|
||||
|
||||
|
@ -1536,7 +1536,8 @@ void ASTWriter::WritePreprocessor(const Preprocessor &PP) {
|
||||
llvm::SmallVector<std::pair<const IdentifierInfo *, MacroInfo *>, 2>
|
||||
MacrosToEmit;
|
||||
llvm::SmallPtrSet<const IdentifierInfo*, 4> MacroDefinitionsSeen;
|
||||
for (Preprocessor::macro_iterator I = PP.macro_begin(), E = PP.macro_end();
|
||||
for (Preprocessor::macro_iterator I = PP.macro_begin(Chain == 0),
|
||||
E = PP.macro_end(Chain == 0);
|
||||
I != E; ++I) {
|
||||
MacroDefinitionsSeen.insert(I->first);
|
||||
MacrosToEmit.push_back(std::make_pair(I->first, I->second));
|
||||
@ -1547,10 +1548,21 @@ void ASTWriter::WritePreprocessor(const Preprocessor &PP) {
|
||||
llvm::array_pod_sort(MacrosToEmit.begin(), MacrosToEmit.end(),
|
||||
&compareMacroDefinitions);
|
||||
|
||||
// Resolve any identifiers that defined macros at the time they were
|
||||
// deserialized, adding them to the list of macros to emit (if appropriate).
|
||||
for (unsigned I = 0, N = DeserializedMacroNames.size(); I != N; ++I) {
|
||||
IdentifierInfo *Name
|
||||
= const_cast<IdentifierInfo *>(DeserializedMacroNames[I]);
|
||||
if (Name->hasMacroDefinition() && MacroDefinitionsSeen.insert(Name))
|
||||
MacrosToEmit.push_back(std::make_pair(Name, PP.getMacroInfo(Name)));
|
||||
}
|
||||
|
||||
for (unsigned I = 0, N = MacrosToEmit.size(); I != N; ++I) {
|
||||
const IdentifierInfo *Name = MacrosToEmit[I].first;
|
||||
MacroInfo *MI = MacrosToEmit[I].second;
|
||||
|
||||
if (!MI)
|
||||
continue;
|
||||
|
||||
// Don't emit builtin macros like __LINE__ to the AST file unless they have
|
||||
// been redefined by the header (in which case they are not isBuiltinMacro).
|
||||
// Also skip macros from a AST file if we're chaining.
|
||||
@ -1603,7 +1615,6 @@ void ASTWriter::WritePreprocessor(const Preprocessor &PP) {
|
||||
// FIXME: When reading literal tokens, reconstruct the literal pointer if
|
||||
// it is needed.
|
||||
AddIdentifierRef(Tok.getIdentifierInfo(), Record);
|
||||
|
||||
// FIXME: Should translate token kind to a stable encoding.
|
||||
Record.push_back(Tok.getKind());
|
||||
// FIXME: Should translate token flags to a stable encoding.
|
||||
@ -3681,6 +3692,8 @@ void ASTWriter::ReaderInitialized(ASTReader *Reader) {
|
||||
|
||||
void ASTWriter::IdentifierRead(IdentID ID, IdentifierInfo *II) {
|
||||
IdentifierIDs[II] = ID;
|
||||
if (II->hasMacroDefinition())
|
||||
DeserializedMacroNames.push_back(II);
|
||||
}
|
||||
|
||||
void ASTWriter::TypeRead(TypeIdx Idx, QualType T) {
|
||||
|
@ -2,3 +2,6 @@ namespace A {
|
||||
int x;
|
||||
int y;
|
||||
}
|
||||
|
||||
int foo;
|
||||
#define foo foo
|
||||
|
Loading…
Reference in New Issue
Block a user