From ad364956edb7f06e0064e90e7c37d13b3cccd1cf Mon Sep 17 00:00:00 2001 From: evgeny Date: Wed, 18 Dec 2019 18:33:15 +0300 Subject: [PATCH] [ThinLTO] Show preserved symbols in DOT files Differential revision: https://reviews.llvm.org/D71608 --- llvm/include/llvm/IR/ModuleSummaryIndex.h | 4 ++- llvm/include/llvm/LTO/Config.h | 5 +-- llvm/lib/Analysis/ModuleSummaryAnalysis.cpp | 2 +- llvm/lib/IR/ModuleSummaryIndex.cpp | 6 +++- llvm/lib/LTO/LTO.cpp | 3 +- llvm/lib/LTO/LTOBackend.cpp | 34 +++++++++++---------- llvm/test/ThinLTO/X86/dot-dumper.ll | 2 +- 7 files changed, 33 insertions(+), 23 deletions(-) diff --git a/llvm/include/llvm/IR/ModuleSummaryIndex.h b/llvm/include/llvm/IR/ModuleSummaryIndex.h index af330c1fa57b..b78c240e1d17 100644 --- a/llvm/include/llvm/IR/ModuleSummaryIndex.h +++ b/llvm/include/llvm/IR/ModuleSummaryIndex.h @@ -1376,7 +1376,9 @@ public: void dump() const; /// Export summary to dot file for GraphViz. - void exportToDot(raw_ostream& OS) const; + void + exportToDot(raw_ostream &OS, + const DenseSet &GUIDPreservedSymbols) const; /// Print out strongly connected components for debugging. void dumpSCCs(raw_ostream &OS); diff --git a/llvm/include/llvm/LTO/Config.h b/llvm/include/llvm/LTO/Config.h index 754e3126f8a9..a6ebe66f641e 100644 --- a/llvm/include/llvm/LTO/Config.h +++ b/llvm/include/llvm/LTO/Config.h @@ -183,8 +183,9 @@ struct Config { /// /// It is called regardless of whether the backend is in-process, although it /// is not called from individual backend processes. - using CombinedIndexHookFn = - std::function; + using CombinedIndexHookFn = std::function &GUIDPreservedSymbols)>; CombinedIndexHookFn CombinedIndexHook; /// This is a convenience function that configures this Config object to write diff --git a/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp b/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp index 58e583d5d3a5..8a1206f49c21 100644 --- a/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp +++ b/llvm/lib/Analysis/ModuleSummaryAnalysis.cpp @@ -820,7 +820,7 @@ ModuleSummaryIndex llvm::buildModuleSummaryIndex( if (EC) report_fatal_error(Twine("Failed to open dot file ") + ModuleSummaryDotFile + ": " + EC.message() + "\n"); - Index.exportToDot(OSDot); + Index.exportToDot(OSDot, {}); } return Index; diff --git a/llvm/lib/IR/ModuleSummaryIndex.cpp b/llvm/lib/IR/ModuleSummaryIndex.cpp index 5d35dbe06f22..180f96269a13 100644 --- a/llvm/lib/IR/ModuleSummaryIndex.cpp +++ b/llvm/lib/IR/ModuleSummaryIndex.cpp @@ -405,7 +405,9 @@ static bool hasWriteOnlyFlag(const GlobalValueSummary *S) { return false; } -void ModuleSummaryIndex::exportToDot(raw_ostream &OS) const { +void ModuleSummaryIndex::exportToDot( + raw_ostream &OS, + const DenseSet &GUIDPreservedSymbols) const { std::vector CrossModuleEdges; DenseMap> NodeMap; using GVSOrderedMapTy = std::map; @@ -485,6 +487,8 @@ void ModuleSummaryIndex::exportToDot(raw_ostream &OS) const { A.addComment("dsoLocal"); if (Flags.CanAutoHide) A.addComment("canAutoHide"); + if (GUIDPreservedSymbols.count(SummaryIt.first)) + A.addComment("preserved"); auto VI = getValueInfo(SummaryIt.first); A.add("label", getNodeLabel(VI, SummaryIt.second)); diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp index 0d48090e4268..950315fc2ed4 100644 --- a/llvm/lib/LTO/LTO.cpp +++ b/llvm/lib/LTO/LTO.cpp @@ -1264,7 +1264,8 @@ Error LTO::runThinLTO(AddStreamFn AddStream, NativeObjectCache Cache, if (ThinLTO.ModuleMap.empty()) return Error::success(); - if (Conf.CombinedIndexHook && !Conf.CombinedIndexHook(ThinLTO.CombinedIndex)) + if (Conf.CombinedIndexHook && + !Conf.CombinedIndexHook(ThinLTO.CombinedIndex, GUIDPreservedSymbols)) return Error::success(); // Collect for each module the list of function it defines (GUID -> diff --git a/llvm/lib/LTO/LTOBackend.cpp b/llvm/lib/LTO/LTOBackend.cpp index e437b4457d47..4c5302d15f0c 100644 --- a/llvm/lib/LTO/LTOBackend.cpp +++ b/llvm/lib/LTO/LTOBackend.cpp @@ -102,23 +102,25 @@ Error Config::addSaveTemps(std::string OutputFileName, setHook("4.opt", PostOptModuleHook); setHook("5.precodegen", PreCodeGenModuleHook); - CombinedIndexHook = [=](const ModuleSummaryIndex &Index) { - std::string Path = OutputFileName + "index.bc"; - std::error_code EC; - raw_fd_ostream OS(Path, EC, sys::fs::OpenFlags::OF_None); - // Because -save-temps is a debugging feature, we report the error - // directly and exit. - if (EC) - reportOpenError(Path, EC.message()); - WriteIndexToFile(Index, OS); + CombinedIndexHook = + [=](const ModuleSummaryIndex &Index, + const DenseSet &GUIDPreservedSymbols) { + std::string Path = OutputFileName + "index.bc"; + std::error_code EC; + raw_fd_ostream OS(Path, EC, sys::fs::OpenFlags::OF_None); + // Because -save-temps is a debugging feature, we report the error + // directly and exit. + if (EC) + reportOpenError(Path, EC.message()); + WriteIndexToFile(Index, OS); - Path = OutputFileName + "index.dot"; - raw_fd_ostream OSDot(Path, EC, sys::fs::OpenFlags::OF_None); - if (EC) - reportOpenError(Path, EC.message()); - Index.exportToDot(OSDot); - return true; - }; + Path = OutputFileName + "index.dot"; + raw_fd_ostream OSDot(Path, EC, sys::fs::OpenFlags::OF_None); + if (EC) + reportOpenError(Path, EC.message()); + Index.exportToDot(OSDot, GUIDPreservedSymbols); + return true; + }; return Error::success(); } diff --git a/llvm/test/ThinLTO/X86/dot-dumper.ll b/llvm/test/ThinLTO/X86/dot-dumper.ll index d2a6c9dbd70c..22cbdec28f1a 100644 --- a/llvm/test/ThinLTO/X86/dot-dumper.ll +++ b/llvm/test/ThinLTO/X86/dot-dumper.ll @@ -40,7 +40,7 @@ ; COMBINED-NEXT: label = "dot-dumper{{.*}}1.bc"; ; COMBINED-NEXT: node [style=filled,fillcolor=lightblue]; ; COMBINED-NEXT: M0_[[MAIN_ALIAS:[0-9]+]] [style="dotted,filled",shape="box",label="main_alias",fillcolor="red"]; // alias, dead -; COMBINED-NEXT: M0_[[MAIN:[0-9]+]] [shape="record",label="main|extern (inst: 4, ffl: 000000)}"]; // function +; COMBINED-NEXT: M0_[[MAIN:[0-9]+]] [shape="record",label="main|extern (inst: 4, ffl: 000000)}"]; // function, preserved ; COMBINED-NEXT: // Edges: ; COMBINED-NEXT: M0_[[MAIN_ALIAS]] -> M0_[[MAIN]] [style=dotted]; // alias ; COMBINED-NEXT: }