LLVM 22.0.0git
ModuleSummaryIndex.cpp
Go to the documentation of this file.
1//===-- ModuleSummaryIndex.cpp - Module Summary Index ---------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the module index and summary classes for the
10// IR library.
11//
12//===----------------------------------------------------------------------===//
13
16#include "llvm/ADT/Statistic.h"
18#include "llvm/Support/Path.h"
20using namespace llvm;
21
22#define DEBUG_TYPE "module-summary-index"
23
24STATISTIC(ReadOnlyLiveGVars,
25 "Number of live global variables marked read only");
26STATISTIC(WriteOnlyLiveGVars,
27 "Number of live global variables marked write only");
28
29static cl::opt<bool> PropagateAttrs("propagate-attrs", cl::init(true),
31 cl::desc("Propagate attributes in index"));
32
34 "import-constants-with-refs", cl::init(true), cl::Hidden,
35 cl::desc("Import constant global variables with references"));
36
38
42
44 bool HasProtected = false;
45 for (const auto &S : make_pointee_range(getSummaryList())) {
46 if (S.getVisibility() == GlobalValue::HiddenVisibility)
48 if (S.getVisibility() == GlobalValue::ProtectedVisibility)
49 HasProtected = true;
50 }
51 return HasProtected ? GlobalValue::ProtectedVisibility
53}
54
55bool ValueInfo::isDSOLocal(bool WithDSOLocalPropagation) const {
56 // With DSOLocal propagation done, the flag in evey summary is the same.
57 // Check the first one is enough.
58 return WithDSOLocalPropagation
59 ? getSummaryList().size() && getSummaryList()[0]->isDSOLocal()
60 : getSummaryList().size() &&
63 [](const std::unique_ptr<GlobalValueSummary> &Summary) {
64 return Summary->isDSOLocal();
65 });
66}
67
69 // Can only auto hide if all copies are eligible to auto hide.
70 return getSummaryList().size() &&
72 [](const std::unique_ptr<GlobalValueSummary> &Summary) {
73 return Summary->canAutoHide();
74 });
75}
76
77// Gets the number of readonly and writeonly refs in RefEdgeList
78std::pair<unsigned, unsigned> FunctionSummary::specialRefCounts() const {
79 // Here we take advantage of having all readonly and writeonly references
80 // located in the end of the RefEdgeList.
81 auto Refs = refs();
82 unsigned RORefCnt = 0, WORefCnt = 0;
83 int I;
84 for (I = Refs.size() - 1; I >= 0 && Refs[I].isWriteOnly(); --I)
85 WORefCnt++;
86 for (; I >= 0 && Refs[I].isReadOnly(); --I)
87 RORefCnt++;
88 return {RORefCnt, WORefCnt};
89}
90
92
94 uint64_t Flags = 0;
95 // Flags & 0x4 is reserved. DO NOT REUSE.
97 Flags |= 0x1;
99 Flags |= 0x2;
100 if (enableSplitLTOUnit())
101 Flags |= 0x8;
103 Flags |= 0x10;
105 Flags |= 0x20;
107 Flags |= 0x40;
109 Flags |= 0x80;
111 Flags |= 0x100;
112 if (hasUnifiedLTO())
113 Flags |= 0x200;
115 Flags |= 0x400;
116 return Flags;
117}
118
120 assert(Flags <= 0x7ff && "Unexpected bits in flag");
121 // 1 bit: WithGlobalValueDeadStripping flag.
122 // Set on combined index only.
123 if (Flags & 0x1)
125 // 1 bit: SkipModuleByDistributedBackend flag.
126 // Set on combined index only.
127 if (Flags & 0x2)
129 // Flags & 0x4 is reserved. DO NOT REUSE.
130 // 1 bit: DisableSplitLTOUnit flag.
131 // Set on per module indexes. It is up to the client to validate
132 // the consistency of this flag across modules being linked.
133 if (Flags & 0x8)
135 // 1 bit: PartiallySplitLTOUnits flag.
136 // Set on combined index only.
137 if (Flags & 0x10)
139 // 1 bit: WithAttributePropagation flag.
140 // Set on combined index only.
141 if (Flags & 0x20)
143 // 1 bit: WithDSOLocalPropagation flag.
144 // Set on combined index only.
145 if (Flags & 0x40)
147 // 1 bit: WithWholeProgramVisibility flag.
148 // Set on combined index only.
149 if (Flags & 0x80)
151 // 1 bit: WithSupportsHotColdNew flag.
152 // Set on combined index only.
153 if (Flags & 0x100)
155 // 1 bit: WithUnifiedLTO flag.
156 // Set on combined index only.
157 if (Flags & 0x200)
159 // 1 bit: WithInternalizeAndPromote flag.
160 // Set on combined index only.
161 if (Flags & 0x400)
163}
164
165// Collect for the given module the list of function it defines
166// (GUID -> Summary).
168 StringRef ModulePath, GVSummaryMapTy &GVSummaryMap) const {
169 for (auto &GlobalList : *this) {
170 auto GUID = GlobalList.first;
171 for (auto &GlobSummary : GlobalList.second.getSummaryList()) {
172 auto *Summary = dyn_cast_or_null<FunctionSummary>(GlobSummary.get());
173 if (!Summary)
174 // Ignore global variable, focus on functions
175 continue;
176 // Ignore summaries from other modules.
177 if (Summary->modulePath() != ModulePath)
178 continue;
179 GVSummaryMap[GUID] = Summary;
180 }
181 }
182}
183
186 bool PerModuleIndex) const {
187 auto VI = getValueInfo(ValueGUID);
188 assert(VI && "GlobalValue not found in index");
189 assert((!PerModuleIndex || VI.getSummaryList().size() == 1) &&
190 "Expected a single entry per global value in per-module index");
191 auto &Summary = VI.getSummaryList()[0];
192 return Summary.get();
193}
194
196 auto VI = getValueInfo(GUID);
197 if (!VI)
198 return true;
199 const auto &SummaryList = VI.getSummaryList();
200 if (SummaryList.empty())
201 return true;
202 for (auto &I : SummaryList)
203 if (isGlobalValueLive(I.get()))
204 return true;
205 return false;
206}
207
208static void
210 DenseSet<ValueInfo> &MarkedNonReadWriteOnly) {
211 // If reference is not readonly or writeonly then referenced summary is not
212 // read/writeonly either. Note that:
213 // - All references from GlobalVarSummary are conservatively considered as
214 // not readonly or writeonly. Tracking them properly requires more complex
215 // analysis then we have now.
216 //
217 // - AliasSummary objects have no refs at all so this function is a no-op
218 // for them.
219 for (auto &VI : S->refs()) {
220 assert(VI.getAccessSpecifier() == 0 || isa<FunctionSummary>(S));
221 if (!VI.getAccessSpecifier()) {
222 if (!MarkedNonReadWriteOnly.insert(VI).second)
223 continue;
224 } else if (MarkedNonReadWriteOnly.contains(VI))
225 continue;
226 for (auto &Ref : VI.getSummaryList())
227 // If references to alias is not read/writeonly then aliasee
228 // is not read/writeonly
229 if (auto *GVS = dyn_cast<GlobalVarSummary>(Ref->getBaseObject())) {
230 if (!VI.isReadOnly())
231 GVS->setReadOnly(false);
232 if (!VI.isWriteOnly())
233 GVS->setWriteOnly(false);
234 }
235 }
236}
237
238// Do the access attribute and DSOLocal propagation in combined index.
239// The goal of attribute propagation is internalization of readonly (RO)
240// or writeonly (WO) variables. To determine which variables are RO or WO
241// and which are not we take following steps:
242// - During analysis we speculatively assign readonly and writeonly
243// attribute to all variables which can be internalized. When computing
244// function summary we also assign readonly or writeonly attribute to a
245// reference if function doesn't modify referenced variable (readonly)
246// or doesn't read it (writeonly).
247//
248// - After computing dead symbols in combined index we do the attribute
249// and DSOLocal propagation. During this step we:
250// a. clear RO and WO attributes from variables which are preserved or
251// can't be imported
252// b. clear RO and WO attributes from variables referenced by any global
253// variable initializer
254// c. clear RO attribute from variable referenced by a function when
255// reference is not readonly
256// d. clear WO attribute from variable referenced by a function when
257// reference is not writeonly
258// e. clear IsDSOLocal flag in every summary if any of them is false.
259//
260// Because of (c, d) we don't internalize variables read by function A
261// and modified by function B.
262//
263// Internalization itself happens in the backend after import is finished
264// See internalizeGVsAfterImport.
266 const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols) {
267 if (!PropagateAttrs)
268 return;
269 DenseSet<ValueInfo> MarkedNonReadWriteOnly;
270 for (auto &P : *this) {
271 bool IsDSOLocal = true;
272 for (auto &S : P.second.getSummaryList()) {
273 if (!isGlobalValueLive(S.get())) {
274 // computeDeadSymbolsAndUpdateIndirectCalls should have marked all
275 // copies live. Note that it is possible that there is a GUID collision
276 // between internal symbols with the same name in different files of the
277 // same name but not enough distinguishing path. Because
278 // computeDeadSymbolsAndUpdateIndirectCalls should conservatively mark
279 // all copies live we can assert here that all are dead if any copy is
280 // dead.
282 P.second.getSummaryList(),
283 [&](const std::unique_ptr<GlobalValueSummary> &Summary) {
284 return isGlobalValueLive(Summary.get());
285 }));
286 // We don't examine references from dead objects
287 break;
288 }
289
290 // Global variable can't be marked read/writeonly if it is not eligible
291 // to import since we need to ensure that all external references get
292 // a local (imported) copy. It also can't be marked read/writeonly if
293 // it or any alias (since alias points to the same memory) are preserved
294 // or notEligibleToImport, since either of those means there could be
295 // writes (or reads in case of writeonly) that are not visible (because
296 // preserved means it could have external to DSO writes or reads, and
297 // notEligibleToImport means it could have writes or reads via inline
298 // assembly leading it to be in the @llvm.*used).
299 if (auto *GVS = dyn_cast<GlobalVarSummary>(S->getBaseObject()))
300 // Here we intentionally pass S.get() not GVS, because S could be
301 // an alias. We don't analyze references here, because we have to
302 // know exactly if GV is readonly to do so.
303 if (!canImportGlobalVar(S.get(), /* AnalyzeRefs */ false) ||
304 GUIDPreservedSymbols.count(P.first)) {
305 GVS->setReadOnly(false);
306 GVS->setWriteOnly(false);
307 }
308 propagateAttributesToRefs(S.get(), MarkedNonReadWriteOnly);
309
310 // If the flag from any summary is false, the GV is not DSOLocal.
311 IsDSOLocal &= S->isDSOLocal();
312 }
313 if (!IsDSOLocal)
314 // Mark the flag in all summaries false so that we can do quick check
315 // without going through the whole list.
316 for (const std::unique_ptr<GlobalValueSummary> &Summary :
317 P.second.getSummaryList())
318 Summary->setDSOLocal(false);
319 }
323 for (auto &P : *this)
324 if (P.second.getSummaryList().size())
325 if (auto *GVS = dyn_cast<GlobalVarSummary>(
326 P.second.getSummaryList()[0]->getBaseObject()))
327 if (isGlobalValueLive(GVS)) {
328 if (GVS->maybeReadOnly())
329 ReadOnlyLiveGVars++;
330 if (GVS->maybeWriteOnly())
331 WriteOnlyLiveGVars++;
332 }
333}
334
336 bool AnalyzeRefs) const {
337 bool CanImportDecl;
338 return canImportGlobalVar(S, AnalyzeRefs, CanImportDecl);
339}
340
342 bool AnalyzeRefs,
343 bool &CanImportDecl) const {
344 auto HasRefsPreventingImport = [this](const GlobalVarSummary *GVS) {
345 // We don't analyze GV references during attribute propagation, so
346 // GV with non-trivial initializer can be marked either read or
347 // write-only.
348 // Importing definiton of readonly GV with non-trivial initializer
349 // allows us doing some extra optimizations (like converting indirect
350 // calls to direct).
351 // Definition of writeonly GV with non-trivial initializer should also
352 // be imported. Not doing so will result in:
353 // a) GV internalization in source module (because it's writeonly)
354 // b) Importing of GV declaration to destination module as a result
355 // of promotion.
356 // c) Link error (external declaration with internal definition).
357 // However we do not promote objects referenced by writeonly GV
358 // initializer by means of converting it to 'zeroinitializer'
359 return !(ImportConstantsWithRefs && GVS->isConstant()) &&
360 !isReadOnly(GVS) && !isWriteOnly(GVS) && GVS->refs().size();
361 };
362 auto *GVS = cast<GlobalVarSummary>(S->getBaseObject());
363
364 const bool nonInterposable =
366 const bool eligibleToImport = !S->notEligibleToImport();
367
368 // It's correct to import a global variable only when it is not interposable
369 // and eligible to import.
370 CanImportDecl = (nonInterposable && eligibleToImport);
371
372 // Global variable with non-trivial initializer can be imported
373 // if it's readonly. This gives us extra opportunities for constant
374 // folding and converting indirect calls to direct calls. We don't
375 // analyze GV references during attribute propagation, because we
376 // don't know yet if it is readonly or not.
377 return nonInterposable && eligibleToImport &&
378 (!AnalyzeRefs || !HasRefsPreventingImport(GVS));
379}
380
381// TODO: write a graphviz dumper for SCCs (see ModuleSummaryIndex::exportToDot)
382// then delete this function and update its tests
387 !I.isAtEnd(); ++I) {
388 O << "SCC (" << utostr(I->size()) << " node" << (I->size() == 1 ? "" : "s")
389 << ") {\n";
390 for (const ValueInfo &V : *I) {
391 FunctionSummary *F = nullptr;
392 if (V.getSummaryList().size())
393 F = cast<FunctionSummary>(V.getSummaryList().front().get());
394 O << " " << (F == nullptr ? "External" : "") << " " << utostr(V.getGUID())
395 << (I.hasCycle() ? " (has cycle)" : "") << "\n";
396 }
397 O << "}\n";
398 }
399}
400
401namespace {
402struct Attributes {
403 void add(const Twine &Name, const Twine &Value,
404 const Twine &Comment = Twine());
405 void addComment(const Twine &Comment);
406 std::string getAsString() const;
407
408 std::vector<std::string> Attrs;
409 std::string Comments;
410};
411
412struct Edge {
413 uint64_t SrcMod;
414 int Hotness;
417};
418} // namespace
419
420void Attributes::add(const Twine &Name, const Twine &Value,
421 const Twine &Comment) {
422 std::string A = Name.str();
423 A += "=\"";
424 A += Value.str();
425 A += "\"";
426 Attrs.push_back(A);
427 addComment(Comment);
428}
429
430void Attributes::addComment(const Twine &Comment) {
431 if (!Comment.isTriviallyEmpty()) {
432 if (Comments.empty())
433 Comments = " // ";
434 else
435 Comments += ", ";
436 Comments += Comment.str();
437 }
438}
439
440std::string Attributes::getAsString() const {
441 if (Attrs.empty())
442 return "";
443
444 std::string Ret = "[";
445 for (auto &A : Attrs)
446 Ret += A + ",";
447 Ret.pop_back();
448 Ret += "];";
449 Ret += Comments;
450 return Ret;
451}
452
454 switch (LT) {
456 return "extern";
458 return "av_ext";
460 return "linkonce";
462 return "linkonce_odr";
464 return "weak";
466 return "weak_odr";
468 return "appending";
470 return "internal";
472 return "private";
474 return "extern_weak";
476 return "common";
477 }
478
479 return "<unknown>";
480}
481
483 auto FlagValue = [](unsigned V) { return V ? '1' : '0'; };
484 char FlagRep[] = {FlagValue(F.ReadNone),
485 FlagValue(F.ReadOnly),
486 FlagValue(F.NoRecurse),
487 FlagValue(F.ReturnDoesNotAlias),
488 FlagValue(F.NoInline),
489 FlagValue(F.AlwaysInline),
490 FlagValue(F.NoUnwind),
491 FlagValue(F.MayThrow),
492 FlagValue(F.HasUnknownCall),
493 FlagValue(F.MustBeUnreachable),
494 0};
495
496 return FlagRep;
497}
498
499// Get string representation of function instruction count and flags.
500static std::string getSummaryAttributes(GlobalValueSummary* GVS) {
501 auto *FS = dyn_cast_or_null<FunctionSummary>(GVS);
502 if (!FS)
503 return "";
504
505 return std::string("inst: ") + std::to_string(FS->instCount()) +
506 ", ffl: " + fflagsToString(FS->fflags());
507}
508
509static std::string getNodeVisualName(GlobalValue::GUID Id) {
510 return std::string("@") + std::to_string(Id);
511}
512
513static std::string getNodeVisualName(const ValueInfo &VI) {
514 return VI.name().empty() ? getNodeVisualName(VI.getGUID()) : VI.name().str();
515}
516
517static std::string getNodeLabel(const ValueInfo &VI, GlobalValueSummary *GVS) {
518 if (isa<AliasSummary>(GVS))
519 return getNodeVisualName(VI);
520
521 std::string Attrs = getSummaryAttributes(GVS);
522 std::string Label =
523 getNodeVisualName(VI) + "|" + linkageToString(GVS->linkage());
524 if (!Attrs.empty())
525 Label += std::string(" (") + Attrs + ")";
526 Label += "}";
527
528 return Label;
529}
530
531// Write definition of external node, which doesn't have any
532// specific module associated with it. Typically this is function
533// or variable defined in native object or library.
534static void defineExternalNode(raw_ostream &OS, const char *Pfx,
535 const ValueInfo &VI, GlobalValue::GUID Id) {
536 auto StrId = std::to_string(Id);
537 OS << " " << StrId << " [label=\"";
538
539 if (VI) {
540 OS << getNodeVisualName(VI);
541 } else {
542 OS << getNodeVisualName(Id);
543 }
544 OS << "\"]; // defined externally\n";
545}
546
547static bool hasReadOnlyFlag(const GlobalValueSummary *S) {
548 if (auto *GVS = dyn_cast<GlobalVarSummary>(S))
549 return GVS->maybeReadOnly();
550 return false;
551}
552
554 if (auto *GVS = dyn_cast<GlobalVarSummary>(S))
555 return GVS->maybeWriteOnly();
556 return false;
557}
558
559static bool hasConstantFlag(const GlobalValueSummary *S) {
560 if (auto *GVS = dyn_cast<GlobalVarSummary>(S))
561 return GVS->isConstant();
562 return false;
563}
564
566 raw_ostream &OS,
567 const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols) const {
568 std::vector<Edge> CrossModuleEdges;
570 using GVSOrderedMapTy = std::map<GlobalValue::GUID, GlobalValueSummary *>;
571 std::map<StringRef, GVSOrderedMapTy> ModuleToDefinedGVS;
572 collectDefinedGVSummariesPerModule(ModuleToDefinedGVS);
573
574 // Assign an id to each module path for use in graph labels. Since the
575 // StringMap iteration order isn't guaranteed, order by path string before
576 // assigning ids.
577 std::vector<StringRef> ModulePaths;
578 for (auto &[ModPath, _] : modulePaths())
579 ModulePaths.push_back(ModPath);
580 llvm::sort(ModulePaths);
582 for (auto &ModPath : ModulePaths)
583 ModuleIdMap.try_emplace(ModPath, ModuleIdMap.size());
584
585 // Get node identifier in form MXXX_<GUID>. The MXXX prefix is required,
586 // because we may have multiple linkonce functions summaries.
587 auto NodeId = [](uint64_t ModId, GlobalValue::GUID Id) {
588 return ModId == (uint64_t)-1 ? std::to_string(Id)
589 : std::string("M") + std::to_string(ModId) +
590 "_" + std::to_string(Id);
591 };
592
593 auto DrawEdge = [&](const char *Pfx, uint64_t SrcMod, GlobalValue::GUID SrcId,
594 uint64_t DstMod, GlobalValue::GUID DstId,
595 int TypeOrHotness) {
596 // 0 - alias
597 // 1 - reference
598 // 2 - constant reference
599 // 3 - writeonly reference
600 // Other value: (hotness - 4).
601 TypeOrHotness += 4;
602 static const char *EdgeAttrs[] = {
603 " [style=dotted]; // alias",
604 " [style=dashed]; // ref",
605 " [style=dashed,color=forestgreen]; // const-ref",
606 " [style=dashed,color=violetred]; // writeOnly-ref",
607 " // call (hotness : Unknown)",
608 " [color=blue]; // call (hotness : Cold)",
609 " // call (hotness : None)",
610 " [color=brown]; // call (hotness : Hot)",
611 " [style=bold,color=red]; // call (hotness : Critical)"};
612
613 assert(static_cast<size_t>(TypeOrHotness) < std::size(EdgeAttrs));
614 OS << Pfx << NodeId(SrcMod, SrcId) << " -> " << NodeId(DstMod, DstId)
615 << EdgeAttrs[TypeOrHotness] << "\n";
616 };
617
618 OS << "digraph Summary {\n";
619 for (auto &ModIt : ModuleToDefinedGVS) {
620 // Will be empty for a just built per-module index, which doesn't setup a
621 // module paths table. In that case use 0 as the module id.
622 assert(ModuleIdMap.count(ModIt.first) || ModuleIdMap.empty());
623 auto ModId = ModuleIdMap.empty() ? 0 : ModuleIdMap[ModIt.first];
624 OS << " // Module: " << ModIt.first << "\n";
625 OS << " subgraph cluster_" << std::to_string(ModId) << " {\n";
626 OS << " style = filled;\n";
627 OS << " color = lightgrey;\n";
628 OS << " label = \"" << sys::path::filename(ModIt.first) << "\";\n";
629 OS << " node [style=filled,fillcolor=lightblue];\n";
630
631 auto &GVSMap = ModIt.second;
632 auto Draw = [&](GlobalValue::GUID IdFrom, GlobalValue::GUID IdTo, int Hotness) {
633 if (!GVSMap.count(IdTo)) {
634 CrossModuleEdges.push_back({ModId, Hotness, IdFrom, IdTo});
635 return;
636 }
637 DrawEdge(" ", ModId, IdFrom, ModId, IdTo, Hotness);
638 };
639
640 for (auto &SummaryIt : GVSMap) {
641 NodeMap[SummaryIt.first].push_back(ModId);
642 auto Flags = SummaryIt.second->flags();
643 Attributes A;
644 if (isa<FunctionSummary>(SummaryIt.second)) {
645 A.add("shape", "record", "function");
646 } else if (isa<AliasSummary>(SummaryIt.second)) {
647 A.add("style", "dotted,filled", "alias");
648 A.add("shape", "box");
649 } else {
650 A.add("shape", "Mrecord", "variable");
651 if (Flags.Live && hasReadOnlyFlag(SummaryIt.second))
652 A.addComment("immutable");
653 if (Flags.Live && hasWriteOnlyFlag(SummaryIt.second))
654 A.addComment("writeOnly");
655 if (Flags.Live && hasConstantFlag(SummaryIt.second))
656 A.addComment("constant");
657 }
658 if (Flags.Visibility)
659 A.addComment("visibility");
660 if (Flags.DSOLocal)
661 A.addComment("dsoLocal");
662 if (Flags.CanAutoHide)
663 A.addComment("canAutoHide");
664 if (Flags.ImportType == GlobalValueSummary::ImportKind::Definition)
665 A.addComment("definition");
666 else if (Flags.ImportType == GlobalValueSummary::ImportKind::Declaration)
667 A.addComment("declaration");
668 if (GUIDPreservedSymbols.count(SummaryIt.first))
669 A.addComment("preserved");
670
671 auto VI = getValueInfo(SummaryIt.first);
672 A.add("label", getNodeLabel(VI, SummaryIt.second));
673 if (!Flags.Live)
674 A.add("fillcolor", "red", "dead");
675 else if (Flags.NotEligibleToImport)
676 A.add("fillcolor", "yellow", "not eligible to import");
677
678 OS << " " << NodeId(ModId, SummaryIt.first) << " " << A.getAsString()
679 << "\n";
680 }
681 OS << " // Edges:\n";
682
683 for (auto &SummaryIt : GVSMap) {
684 auto *GVS = SummaryIt.second;
685 for (auto &R : GVS->refs())
686 Draw(SummaryIt.first, R.getGUID(),
687 R.isWriteOnly() ? -1 : (R.isReadOnly() ? -2 : -3));
688
689 if (auto *AS = dyn_cast_or_null<AliasSummary>(SummaryIt.second)) {
690 Draw(SummaryIt.first, AS->getAliaseeGUID(), -4);
691 continue;
692 }
693
694 if (auto *FS = dyn_cast_or_null<FunctionSummary>(SummaryIt.second))
695 for (auto &CGEdge : FS->calls())
696 Draw(SummaryIt.first, CGEdge.first.getGUID(),
697 static_cast<int>(CGEdge.second.Hotness));
698 }
699 OS << " }\n";
700 }
701
702 OS << " // Cross-module edges:\n";
703 for (auto &E : CrossModuleEdges) {
704 auto &ModList = NodeMap[E.Dst];
705 if (ModList.empty()) {
706 defineExternalNode(OS, " ", getValueInfo(E.Dst), E.Dst);
707 // Add fake module to the list to draw an edge to an external node
708 // in the loop below.
709 ModList.push_back(-1);
710 }
711 for (auto DstMod : ModList)
712 // The edge representing call or ref is drawn to every module where target
713 // symbol is defined. When target is a linkonce symbol there can be
714 // multiple edges representing a single call or ref, both intra-module and
715 // cross-module. As we've already drawn all intra-module edges before we
716 // skip it here.
717 if (DstMod != E.SrcMod)
718 DrawEdge(" ", E.SrcMod, E.Src, DstMod, E.Dst, E.Hotness);
719 }
720
721 OS << "}";
722}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition Compiler.h:638
#define _
#define F(x, y, z)
Definition MD5.cpp:55
#define I(x, y, z)
Definition MD5.cpp:58
static std::string getNodeVisualName(GlobalValue::GUID Id)
static std::string getNodeLabel(const ValueInfo &VI, GlobalValueSummary *GVS)
static std::string getSummaryAttributes(GlobalValueSummary *GVS)
static cl::opt< bool > ImportConstantsWithRefs("import-constants-with-refs", cl::init(true), cl::Hidden, cl::desc("Import constant global variables with references"))
static std::string fflagsToString(FunctionSummary::FFlags F)
static bool hasWriteOnlyFlag(const GlobalValueSummary *S)
static void propagateAttributesToRefs(GlobalValueSummary *S, DenseSet< ValueInfo > &MarkedNonReadWriteOnly)
static std::string linkageToString(GlobalValue::LinkageTypes LT)
static void defineExternalNode(raw_ostream &OS, const char *Pfx, const ValueInfo &VI, GlobalValue::GUID Id)
static cl::opt< bool > PropagateAttrs("propagate-attrs", cl::init(true), cl::Hidden, cl::desc("Propagate attributes in index"))
static bool hasReadOnlyFlag(const GlobalValueSummary *S)
static bool hasConstantFlag(const GlobalValueSummary *S)
ModuleSummaryIndex.h This file contains the declarations the classes that hold the module index and s...
#define P(N)
This builds on the llvm/ADT/GraphTraits.h file to find the strongly connected components (SCCs) of a ...
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
Definition Statistic.h:171
std::pair< iterator, bool > try_emplace(KeyT &&Key, Ts &&...Args)
Definition DenseMap.h:248
unsigned size() const
Definition DenseMap.h:110
bool empty() const
Definition DenseMap.h:109
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
Definition DenseMap.h:174
Implements a dense probed hash-table based set.
Definition DenseSet.h:279
Function summary information to aid decisions and implementation of importing.
static LLVM_ABI FunctionSummary ExternalNode
A dummy node to reference external functions that aren't in the index.
static FunctionSummary makeDummyFunctionSummary(SmallVectorImpl< FunctionSummary::EdgeTy > &&Edges)
Create an empty FunctionSummary (with specified call edges).
LLVM_ABI std::pair< unsigned, unsigned > specialRefCounts() const
Function and variable summary information to aid decisions and implementation of importing.
GlobalValueSummary * getBaseObject()
If this is an alias summary, returns the summary of the aliased object (a global variable or function...
ArrayRef< ValueInfo > refs() const
Return the list of values referenced by this global value definition.
GlobalValue::LinkageTypes linkage() const
Return linkage type recorded for this global value.
bool notEligibleToImport() const
Return true if this global value can't be imported.
uint64_t GUID
Declare a type to represent a global unique identifier for a global value.
VisibilityTypes
An enumeration for the kinds of visibility of global values.
Definition GlobalValue.h:67
@ DefaultVisibility
The GV is visible.
Definition GlobalValue.h:68
@ HiddenVisibility
The GV is hidden.
Definition GlobalValue.h:69
@ ProtectedVisibility
The GV is protected.
Definition GlobalValue.h:70
static bool isInterposableLinkage(LinkageTypes Linkage)
Whether the definition of this global may be replaced by something non-equivalent at link time.
LinkageTypes
An enumeration for the kinds of linkage for global values.
Definition GlobalValue.h:52
@ PrivateLinkage
Like Internal, but omit from symbol table.
Definition GlobalValue.h:61
@ CommonLinkage
Tentative definitions.
Definition GlobalValue.h:63
@ InternalLinkage
Rename collisions when linking (static functions).
Definition GlobalValue.h:60
@ LinkOnceAnyLinkage
Keep one copy of function when linking (inline)
Definition GlobalValue.h:55
@ WeakODRLinkage
Same, but only replaced by something equivalent.
Definition GlobalValue.h:58
@ ExternalLinkage
Externally visible function.
Definition GlobalValue.h:53
@ WeakAnyLinkage
Keep one copy of named function when linking (weak)
Definition GlobalValue.h:57
@ AppendingLinkage
Special purpose, only applies to global arrays.
Definition GlobalValue.h:59
@ AvailableExternallyLinkage
Available for inspection, not emission.
Definition GlobalValue.h:54
@ ExternalWeakLinkage
ExternalWeak linkage description.
Definition GlobalValue.h:62
@ LinkOnceODRLinkage
Same, but only replaced by something equivalent.
Definition GlobalValue.h:56
Global variable summary information to aid decisions and implementation of importing.
LLVM_ABI bool isGUIDLive(GlobalValue::GUID GUID) const
bool isReadOnly(const GlobalVarSummary *GVS) const
LLVM_ABI void setFlags(uint64_t Flags)
bool isWriteOnly(const GlobalVarSummary *GVS) const
ValueInfo getValueInfo(const GlobalValueSummaryMapTy::value_type &R) const
Return a ValueInfo for the index value_type (convenient when iterating index).
LLVM_ABI void collectDefinedFunctionsForModule(StringRef ModulePath, GVSummaryMapTy &GVSummaryMap) const
Collect for the given module the list of functions it defines (GUID -> Summary).
LLVM_ABI void dumpSCCs(raw_ostream &OS)
Print out strongly connected components for debugging.
bool isGlobalValueLive(const GlobalValueSummary *GVS) const
LLVM_ABI void propagateAttributes(const DenseSet< GlobalValue::GUID > &PreservedSymbols)
Do the access attribute and DSOLocal propagation in combined index.
const StringMap< ModuleHash > & modulePaths() const
Table of modules, containing module hash and id.
void collectDefinedGVSummariesPerModule(Map &ModuleToDefinedGVSummaries) const
Collect for each module the list of Summaries it defines (GUID -> Summary).
static constexpr uint64_t BitcodeSummaryVersion
LLVM_ABI void exportToDot(raw_ostream &OS, const DenseSet< GlobalValue::GUID > &GUIDPreservedSymbols) const
Export summary to dot file for GraphViz.
bool skipModuleByDistributedBackend() const
LLVM_ABI uint64_t getFlags() const
GlobalValueSummary * getGlobalValueSummary(const GlobalValue &GV, bool PerModuleIndex=true) const
Returns the first GlobalValueSummary for GV, asserting that there is only one if PerModuleIndex.
LLVM_ABI bool canImportGlobalVar(const GlobalValueSummary *S, bool AnalyzeRefs) const
Checks if we can import global variable from another module.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
LLVM Value Representation.
Definition Value.h:75
std::pair< iterator, bool > insert(const ValueT &V)
Definition DenseSet.h:202
bool contains(const_arg_type_t< ValueT > V) const
Check if the set contains the given element.
Definition DenseSet.h:175
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
Definition DenseSet.h:180
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
Enumerate the SCCs of a directed graph in reverse topological order of the SCC DAG.
Definition SCCIterator.h:49
constexpr char Attrs[]
Key for Kernel::Metadata::mAttrs.
initializer< Ty > init(const Ty &Val)
LLVM_ABI StringRef filename(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get filename.
Definition Path.cpp:577
This is an optimization pass for GlobalISel generic memory operations.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1725
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:643
DenseMap< GlobalValue::GUID, GlobalValueSummary * > GVSummaryMapTy
Map of global value GUID to its summary, used to identify values defined in a particular module,...
scc_iterator< T > scc_begin(const T &G)
Construct the begin iterator for a deduced graph type T.
std::string utostr(uint64_t X, bool isNeg=false)
auto dyn_cast_or_null(const Y &Val)
Definition Casting.h:753
iterator_range< pointee_iterator< WrappedIteratorT > > make_pointee_range(RangeT &&Range)
Definition iterator.h:336
void sort(IteratorTy Start, IteratorTy End)
Definition STLExtras.h:1622
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1739
LLVM_ABI bool AreStatisticsEnabled()
Check if statistics are enabled.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
@ Ref
The access may reference the value stored in memory.
Definition ModRef.h:32
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
Flags specific to function summaries.
static constexpr uint32_t RangeWidth
Struct that holds a reference to a particular GUID in a global value summary.
LLVM_ABI GlobalValue::VisibilityTypes getELFVisibility() const
Returns the most constraining visibility among summaries.
ArrayRef< std::unique_ptr< GlobalValueSummary > > getSummaryList() const
LLVM_ABI bool canAutoHide() const
Checks if all copies are eligible for auto-hiding (have flag set).
LLVM_ABI bool isDSOLocal(bool WithDSOLocalPropagation=false) const
Checks if all summaries are DSO local (have the flag set).