Movatterモバイル変換


[0]ホーム

URL:


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

Generated on Fri Jul 18 2025 11:42:10 for LLVM by doxygen 1.9.6
[8]ページ先頭

©2009-2025 Movatter.jp