28 [](
const std::unique_ptr<GlobalValueSummary> &Summary) {
29 return Summary->isDSOLocal();
37 for (
auto &GlobalList : *
this) {
38 auto GUID = GlobalList.first;
39 for (
auto &GlobSummary : GlobalList.second.SummaryList) {
40 auto *Summary = dyn_cast_or_null<FunctionSummary>(GlobSummary.get());
45 if (Summary->modulePath() != ModulePath)
47 GVSummaryMap[GUID] = Summary;
55 for (
auto &GlobalList : *
this) {
56 auto GUID = GlobalList.first;
57 for (
auto &Summary : GlobalList.second.SummaryList) {
58 ModuleToDefinedGVSummaries[Summary->modulePath()][GUID] = Summary.get();
65 bool PerModuleIndex)
const {
66 auto VI = getValueInfo(ValueGUID);
67 assert(
VI &&
"GlobalValue not found in index");
68 assert((!PerModuleIndex ||
VI.getSummaryList().size() == 1) &&
69 "Expected a single entry per global value in per-module index");
70 auto &Summary =
VI.getSummaryList()[0];
75 auto VI = getValueInfo(GUID);
78 const auto &SummaryList =
VI.getSummaryList();
79 if (SummaryList.empty())
81 for (
auto &
I : SummaryList)
82 if (isGlobalValueLive(
I.get()))
92 scc_begin<ModuleSummaryIndex *>(
this);
94 O <<
"SCC (" <<
utostr(
I->size()) <<
" node" << (
I->size() == 1 ?
"" :
"s")
98 if (V.getSummaryList().size())
99 F = cast<FunctionSummary>(V.getSummaryList().front().get());
100 O <<
" " << (F ==
nullptr ?
"External" :
"") <<
" " <<
utostr(V.getGUID())
101 << (I.hasLoop() ?
" (has loop)" :
"") <<
"\n";
111 std::string getAsString()
const;
113 std::vector<std::string>
Attrs;
114 std::string Comments;
126 const Twine &Comment) {
127 std::string A = Name.
str();
133 if (Comments.empty())
137 Comments += Comment.
str();
141 std::string Attributes::getAsString()
const {
145 std::string
Ret =
"[";
146 for (
auto &A :
Attrs)
163 return "linkonce_odr";
175 return "extern_weak";
184 auto FlagValue = [](
unsigned V) {
return V ?
'1' :
'0'; };
193 auto *FS = dyn_cast_or_null<FunctionSummary>(GVS);
207 if (isa<AliasSummary>(GVS))
214 Label += std::string(
" (") + Attrs +
")";
227 <<
"\"]; // defined externally\n";
231 std::vector<Edge> CrossModuleEdges;
234 collectDefinedGVSummariesPerModule(ModuleToDefinedGVS);
249 static const char *EdgeAttrs[] = {
250 " [style=dotted]; // alias",
251 " [style=dashed]; // ref",
252 " // call (hotness : Unknown)",
253 " [color=blue]; // call (hotness : Cold)",
254 " // call (hotness : None)",
255 " [color=brown]; // call (hotness : Hot)",
256 " [style=bold,color=red]; // call (hotness : Critical)"};
258 assert(static_cast<size_t>(TypeOrHotness) <
259 sizeof(EdgeAttrs) /
sizeof(EdgeAttrs[0]));
260 OS << Pfx <<
NodeId(SrcMod, SrcId) <<
" -> " <<
NodeId(DstMod, DstId)
261 << EdgeAttrs[TypeOrHotness] <<
"\n";
264 OS <<
"digraph Summary {\n";
265 for (
auto &ModIt : ModuleToDefinedGVS) {
266 auto ModId = getModuleId(ModIt.first());
267 OS <<
" // Module: " << ModIt.first() <<
"\n";
269 OS <<
" style = filled;\n";
270 OS <<
" color = lightgrey;\n";
272 OS <<
" node [style=filled,fillcolor=lightblue];\n";
274 auto &GVSMap = ModIt.second;
276 if (!GVSMap.count(IdTo)) {
277 CrossModuleEdges.push_back({ModId, Hotness, IdFrom, IdTo});
280 DrawEdge(
" ", ModId, IdFrom, ModId, IdTo, Hotness);
283 for (
auto &SummaryIt : GVSMap) {
284 NodeMap[SummaryIt.first].push_back(ModId);
285 auto Flags = SummaryIt.second->flags();
287 if (isa<FunctionSummary>(SummaryIt.second)) {
288 A.add(
"shape",
"record",
"function");
289 }
else if (isa<AliasSummary>(SummaryIt.second)) {
290 A.add(
"style",
"dotted,filled",
"alias");
291 A.add(
"shape",
"box");
293 A.add(
"shape",
"Mrecord",
"variable");
296 auto VI = getValueInfo(SummaryIt.first);
299 A.add(
"fillcolor",
"red",
"dead");
300 else if (Flags.NotEligibleToImport)
301 A.add(
"fillcolor",
"yellow",
"not eligible to import");
303 OS <<
" " <<
NodeId(ModId, SummaryIt.first) <<
" " << A.getAsString()
306 OS <<
" // Edges:\n";
308 for (
auto &SummaryIt : GVSMap) {
309 auto *GVS = SummaryIt.second;
310 for (
auto &R : GVS->refs())
311 Draw(SummaryIt.first, R.getGUID(), -1);
313 if (
auto *
AS = dyn_cast_or_null<AliasSummary>(SummaryIt.second)) {
314 auto AliaseeOrigId =
AS->getAliasee().getOriginalName();
315 auto AliaseeId = getGUIDFromOriginalID(AliaseeOrigId);
317 Draw(SummaryIt.first, AliaseeId ? AliaseeId : AliaseeOrigId, -2);
321 if (
auto *FS = dyn_cast_or_null<FunctionSummary>(SummaryIt.second))
322 for (
auto &CGEdge : FS->calls())
323 Draw(SummaryIt.first, CGEdge.first.getGUID(),
324 static_cast<int>(CGEdge.second.Hotness));
329 OS <<
" // Cross-module edges:\n";
330 for (
auto &
E : CrossModuleEdges) {
331 auto &ModList = NodeMap[
E.Dst];
332 if (ModList.empty()) {
336 ModList.push_back(-1);
338 for (
auto DstMod : ModList)
344 if (DstMod !=
E.SrcMod)
345 DrawEdge(
" ",
E.SrcMod,
E.Src, DstMod,
E.Dst,
E.Hotness);
This builds on the llvm/ADT/GraphTraits.h file to find the strongly connected components (SCCs) of a ...
void collectDefinedGVSummariesPerModule(StringMap< GVSummaryMapTy > &ModuleToDefinedGVSummaries) const
Collect for each module the list of Summaries it defines (GUID -> Summary).
Special purpose, only applies to global arrays.
LLVM_NODISCARD std::string str() const
str - Get the contents as an std::string.
uint64_t GUID
Declare a type to represent a global unique identifier for a global value.
Compute iterated dominance frontiers using a linear time algorithm.
static std::string linkageToString(GlobalValue::LinkageTypes LT)
Same, but only replaced by something equivalent.
GlobalValueSummary * getGlobalValueSummary(const GlobalValue &GV, bool PerModuleIndex=true) const
Returns the first GlobalValueSummary for GV, asserting that there is only one if PerModuleIndex.
Available for inspection, not emission.
bool isTriviallyEmpty() const
Check if this twine is trivially empty; a false return value does not necessarily mean the twine is e...
Like Internal, but omit from symbol table.
Externally visible function.
GlobalValue::LinkageTypes linkage() const
Return linkage type recorded for this global value.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly...
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
GlobalValue::GUID getGUID() const
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
static void defineExternalNode(raw_ostream &OS, const char *Pfx, const ValueInfo &VI)
static std::string getSummaryAttributes(GlobalValueSummary *GVS)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
ArrayRef< std::unique_ptr< GlobalValueSummary > > getSummaryList() const
static std::string getNodeVisualName(const ValueInfo &VI)
ExternalWeak linkage description.
Same, but only replaced by something equivalent.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
bool isGUIDLive(GlobalValue::GUID GUID) const
Function and variable summary information to aid decisions and implementation of importing.
Struct that holds a reference to a particular GUID in a global value summary.
static std::string fflagsToString(FunctionSummary::FFlags F)
Keep one copy of function when linking (inline)
std::string utostr(uint64_t X, bool isNeg=false)
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
static FunctionSummary makeDummyFunctionSummary(std::vector< FunctionSummary::EdgeTy > Edges)
Create an empty FunctionSummary (with specified call edges).
LinkageTypes
An enumeration for the kinds of linkage for global values.
StringRef filename(StringRef path, Style style=Style::native)
Get filename.
void exportToDot(raw_ostream &OS) const
Export summary to dot file for GraphViz.
static std::string getNodeLabel(const ValueInfo &VI, GlobalValueSummary *GVS)
void dumpSCCs(raw_ostream &OS)
Print out strongly connected components for debugging.
Keep one copy of named function when linking (weak)
Rename collisions when linking (static functions).
Function attribute flags.
Function summary information to aid decisions and implementation of importing.
std::string str() const
Return the twine contents as a std::string.
const std::string to_string(const T &Value)
ModuleSummaryIndex.h This file contains the declarations the classes that hold the module index and s...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
This class implements an extremely fast bulk output stream that can only output to a stream...
StringRef - Represent a constant reference to a string, i.e.
unsigned ReturnDoesNotAlias
void collectDefinedFunctionsForModule(StringRef ModulePath, GVSummaryMapTy &GVSummaryMap) const
Collect for the given module the list of functions it defines (GUID -> Summary).
Enumerate the SCCs of a directed graph in reverse topological order of the SCC DAG.
static FunctionSummary ExternalNode
A dummy node to reference external functions that aren't in the index.