diff options
author | Chuanqi Xu <yedeng.yd@linux.alibaba.com> | 2024-06-20 13:11:35 +0800 |
---|---|---|
committer | Chuanqi Xu <yedeng.yd@linux.alibaba.com> | 2024-06-20 13:13:47 +0800 |
commit | da2ad44119edf13eb944f7e685469352aa840e63 (patch) | |
tree | e05dfc691ffb8bf237be29e682a0e63c6ebbb125 /clang/lib | |
parent | 480a788e4946ac7b313291f26bca19aa65d649f1 (diff) | |
download | llvm-da2ad44119edf13eb944f7e685469352aa840e63.zip llvm-da2ad44119edf13eb944f7e685469352aa840e63.tar.gz llvm-da2ad44119edf13eb944f7e685469352aa840e63.tar.bz2 |
[HeaderSearch] Introduce LazyIdentifierInfoPtr for Controlling Macro in HeaderFileInfo
This patch is helpful to reduce 32 bits for HeaderFileInfo by combining
a uint32_t and pointer into a tagged pointer.
This is reviewed as part of
https://github.com/llvm/llvm-project/pull/92085 and required to be split
as a separate commit
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Lex/HeaderSearch.cpp | 33 | ||||
-rw-r--r-- | clang/lib/Serialization/ASTReader.cpp | 2 | ||||
-rw-r--r-- | clang/lib/Serialization/ASTWriter.cpp | 7 |
3 files changed, 21 insertions, 21 deletions
diff --git a/clang/lib/Lex/HeaderSearch.cpp b/clang/lib/Lex/HeaderSearch.cpp index 9321a36..3bd3aa4 100644 --- a/clang/lib/Lex/HeaderSearch.cpp +++ b/clang/lib/Lex/HeaderSearch.cpp @@ -60,19 +60,21 @@ ALWAYS_ENABLED_STATISTIC(NumSubFrameworkLookups, const IdentifierInfo * HeaderFileInfo::getControllingMacro(ExternalPreprocessorSource *External) { - if (ControllingMacro) { - if (ControllingMacro->isOutOfDate()) { - assert(External && "We must have an external source if we have a " - "controlling macro that is out of date."); - External->updateOutOfDateIdentifier(*ControllingMacro); - } - return ControllingMacro; - } + if (LazyControllingMacro.isID()) { + if (!External) + return nullptr; - if (!ControllingMacroID || !External) - return nullptr; + LazyControllingMacro = + External->GetIdentifier(LazyControllingMacro.getID()); + return LazyControllingMacro.getPtr(); + } - ControllingMacro = External->GetIdentifier(ControllingMacroID); + IdentifierInfo *ControllingMacro = LazyControllingMacro.getPtr(); + if (ControllingMacro && ControllingMacro->isOutOfDate()) { + assert(External && "We must have an external source if we have a " + "controlling macro that is out of date."); + External->updateOutOfDateIdentifier(*ControllingMacro); + } return ControllingMacro; } @@ -1348,10 +1350,8 @@ static void mergeHeaderFileInfo(HeaderFileInfo &HFI, mergeHeaderFileInfoModuleBits(HFI, OtherHFI.isModuleHeader, OtherHFI.isTextualModuleHeader); - if (!HFI.ControllingMacro && !HFI.ControllingMacroID) { - HFI.ControllingMacro = OtherHFI.ControllingMacro; - HFI.ControllingMacroID = OtherHFI.ControllingMacroID; - } + if (!HFI.LazyControllingMacro.isValid()) + HFI.LazyControllingMacro = OtherHFI.LazyControllingMacro; HFI.DirInfo = OtherHFI.DirInfo; HFI.External = (!HFI.IsValid || HFI.External); @@ -1426,8 +1426,7 @@ bool HeaderSearch::isFileMultipleIncludeGuarded(FileEntryRef File) const { // once. Note that we dor't check for #import, because that's not a property // of the file itself. if (auto *HFI = getExistingFileInfo(File)) - return HFI->isPragmaOnce || HFI->ControllingMacro || - HFI->ControllingMacroID; + return HFI->isPragmaOnce || HFI->LazyControllingMacro.isValid(); return false; } diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 973475c..0afbc44 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -2092,7 +2092,7 @@ HeaderFileInfoTrait::ReadData(internal_key_ref key, const unsigned char *d, HFI.isPragmaOnce |= (Flags >> 4) & 0x01; HFI.DirInfo = (Flags >> 1) & 0x07; HFI.IndexHeaderMapHeader = Flags & 0x01; - HFI.ControllingMacroID = Reader.getGlobalIdentifierID( + HFI.LazyControllingMacro = Reader.getGlobalIdentifierID( M, endian::readNext<uint32_t, llvm::endianness::little>(d)); if (unsigned FrameworkOffset = endian::readNext<uint32_t, llvm::endianness::little>(d)) { diff --git a/clang/lib/Serialization/ASTWriter.cpp b/clang/lib/Serialization/ASTWriter.cpp index 50fa44d..a60092a 100644 --- a/clang/lib/Serialization/ASTWriter.cpp +++ b/clang/lib/Serialization/ASTWriter.cpp @@ -2028,10 +2028,11 @@ namespace { | Data.HFI.IndexHeaderMapHeader; LE.write<uint8_t>(Flags); - if (!Data.HFI.ControllingMacro) - LE.write<uint32_t>(Data.HFI.ControllingMacroID); + if (Data.HFI.LazyControllingMacro.isID()) + LE.write<IdentifierID>(Data.HFI.LazyControllingMacro.getID()); else - LE.write<uint32_t>(Writer.getIdentifierRef(Data.HFI.ControllingMacro)); + LE.write<IdentifierID>( + Writer.getIdentifierRef(Data.HFI.LazyControllingMacro.getPtr())); unsigned Offset = 0; if (!Data.HFI.Framework.empty()) { |