Author: Haojian Wu Date: 2023-06-16T10:21:44+02:00 New Revision: 3b59842a721f0729221347ce0eb20075b1135cc5
URL: https://github.com/llvm/llvm-project/commit/3b59842a721f0729221347ce0eb20075b1135cc5 DIFF: https://github.com/llvm/llvm-project/commit/3b59842a721f0729221347ce0eb20075b1135cc5.diff LOG: [include-cleaner] Reorder SymbolReference fields to avoid padding space, NFC This will bring down the size from 40 bytes to 32 bytes. Differential Revision: https://reviews.llvm.org/D153018 Added: Modified: clang-tools-extra/clangd/IncludeCleaner.cpp clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h clang-tools-extra/include-cleaner/lib/Analysis.cpp clang-tools-extra/include-cleaner/lib/HTMLReport.cpp clang-tools-extra/include-cleaner/lib/Record.cpp clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp Removed: ################################################################################ diff --git a/clang-tools-extra/clangd/IncludeCleaner.cpp b/clang-tools-extra/clangd/IncludeCleaner.cpp index 8f1be544bcfa1..dac24bcc7e4d7 100644 --- a/clang-tools-extra/clangd/IncludeCleaner.cpp +++ b/clang-tools-extra/clangd/IncludeCleaner.cpp @@ -370,10 +370,9 @@ collectMacroReferences(ParsedAST &AST) { continue; if (auto DefLoc = Macro->Info->getDefinitionLoc(); DefLoc.isValid()) Macros.push_back( - {Tok.location(), - include_cleaner::Macro{/*Name=*/PP.getIdentifierInfo(Tok.text(SM)), + {include_cleaner::Macro{/*Name=*/PP.getIdentifierInfo(Tok.text(SM)), DefLoc}, - include_cleaner::RefType::Explicit}); + Tok.location(), include_cleaner::RefType::Explicit}); } return Macros; } diff --git a/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h b/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h index 39055db5a8587..0f7fd1cfafa6b 100644 --- a/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h +++ b/clang-tools-extra/include-cleaner/include/clang-include-cleaner/Types.h @@ -95,10 +95,10 @@ llvm::raw_ostream &operator<<(llvm::raw_ostream &, RefType); /// Indicates that a piece of code refers to a symbol. struct SymbolReference { - /// The point in the code that refers to the symbol. - SourceLocation RefLocation; /// The symbol referred to. Symbol Target; + /// The point in the code that refers to the symbol. + SourceLocation RefLocation; /// Relation type between the reference location and the target. RefType RT; }; diff --git a/clang-tools-extra/include-cleaner/lib/Analysis.cpp b/clang-tools-extra/include-cleaner/lib/Analysis.cpp index 2c589ae04412a..3952d10a42334 100644 --- a/clang-tools-extra/include-cleaner/lib/Analysis.cpp +++ b/clang-tools-extra/include-cleaner/lib/Analysis.cpp @@ -45,7 +45,7 @@ void walkUsed(llvm::ArrayRef<Decl *> ASTRoots, return; // FIXME: Most of the work done here is repetitive. It might be useful to // have a cache/batching. - SymbolReference SymRef{Loc, ND, RT}; + SymbolReference SymRef{ND, Loc, RT}; return CB(SymRef, headersForSymbol(ND, SM, PI)); }); } diff --git a/clang-tools-extra/include-cleaner/lib/HTMLReport.cpp b/clang-tools-extra/include-cleaner/lib/HTMLReport.cpp index 65b82973c4290..431d4bb211e0d 100644 --- a/clang-tools-extra/include-cleaner/lib/HTMLReport.cpp +++ b/clang-tools-extra/include-cleaner/lib/HTMLReport.cpp @@ -521,7 +521,7 @@ void writeHTMLReport(FileID File, const include_cleaner::Includes &Includes, walkAST(*Root, [&](SourceLocation Loc, const NamedDecl &D, RefType T) { if(!SM.isWrittenInMainFile(SM.getSpellingLoc(Loc))) return; - R.addRef(SymbolReference{Loc, D, T}); + R.addRef(SymbolReference{D, Loc, T}); }); for (const SymbolReference &Ref : MacroRefs) { if (!SM.isWrittenInMainFile(SM.getSpellingLoc(Ref.RefLocation))) diff --git a/clang-tools-extra/include-cleaner/lib/Record.cpp b/clang-tools-extra/include-cleaner/lib/Record.cpp index e36753123392a..dc3192b8baff3 100644 --- a/clang-tools-extra/include-cleaner/lib/Record.cpp +++ b/clang-tools-extra/include-cleaner/lib/Record.cpp @@ -134,9 +134,9 @@ class PPRecorder : public PPCallbacks { RefType RT = RefType::Explicit) { if (MI.isBuiltinMacro()) return; // __FILE__ is not a reference. - Recorded.MacroReferences.push_back(SymbolReference{ - Tok.getLocation(), - Macro{Tok.getIdentifierInfo(), MI.getDefinitionLoc()}, RT}); + Recorded.MacroReferences.push_back( + SymbolReference{Macro{Tok.getIdentifierInfo(), MI.getDefinitionLoc()}, + Tok.getLocation(), RT}); } bool Active = false; diff --git a/clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp b/clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp index 8593d05a1b12d..bad55e1433549 100644 --- a/clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp +++ b/clang-tools-extra/include-cleaner/unittests/AnalysisTest.cpp @@ -182,13 +182,14 @@ TEST_F(WalkUsedTest, MacroRefs) { Symbol Answer2 = Macro{&Idents.get("ANSWER"), SM.getComposedLoc(HdrID, Hdr.point())}; EXPECT_THAT( - offsetToProviders(AST, SM, - {SymbolReference{SM.getComposedLoc(SM.getMainFileID(), - Code.point("1")), - Answer1, RefType::Explicit}, - SymbolReference{SM.getComposedLoc(SM.getMainFileID(), - Code.point("2")), - Answer2, RefType::Explicit}}), + offsetToProviders( + AST, SM, + {SymbolReference{ + Answer1, SM.getComposedLoc(SM.getMainFileID(), Code.point("1")), + RefType::Explicit}, + SymbolReference{ + Answer2, SM.getComposedLoc(SM.getMainFileID(), Code.point("2")), + RefType::Explicit}}), UnorderedElementsAre( Pair(Code.point("1"), UnorderedElementsAre(HdrFile)), Pair(Code.point("2"), UnorderedElementsAre(HdrFile)), _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits