LLVM 22.0.0git
ModuleSummaryIndex.h
Go to the documentation of this file.
1//===- llvm/ModuleSummaryIndex.h - Module Summary Index ---------*- C++ -*-===//
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/// @file
10/// ModuleSummaryIndex.h This file contains the declarations the classes that
11/// hold the module index and summary for function importing.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_IR_MODULESUMMARYINDEX_H
16#define LLVM_IR_MODULESUMMARYINDEX_H
17
18#include "llvm/ADT/ArrayRef.h"
19#include "llvm/ADT/DenseMap.h"
20#include "llvm/ADT/STLExtras.h"
24#include "llvm/ADT/StringMap.h"
25#include "llvm/ADT/StringRef.h"
28#include "llvm/IR/GlobalValue.h"
29#include "llvm/IR/Module.h"
37#include <algorithm>
38#include <array>
39#include <cassert>
40#include <cstddef>
41#include <cstdint>
42#include <map>
43#include <memory>
44#include <optional>
45#include <set>
46#include <string>
47#include <unordered_set>
48#include <utility>
49#include <vector>
50
51namespace llvm {
52
53template <class GraphType> struct GraphTraits;
54
55namespace yaml {
56
57template <typename T> struct MappingTraits;
58
59} // end namespace yaml
60
61/// Class to accumulate and hold information about a callee.
62struct CalleeInfo {
63 enum class HotnessType : uint8_t {
64 Unknown = 0,
65 Cold = 1,
66 None = 2,
67 Hot = 3,
68 Critical = 4
69 };
70
71 // The size of the bit-field might need to be adjusted if more values are
72 // added to HotnessType enum.
74
75 // True if at least one of the calls to the callee is a tail call.
78
79 /// The value stored in RelBlockFreq has to be interpreted as the digits of
80 /// a scaled number with a scale of \p -ScaleShift.
81 static constexpr unsigned RelBlockFreqBits = 28;
83 static constexpr int32_t ScaleShift = 8;
84 static constexpr uint64_t MaxRelBlockFreq = (1 << RelBlockFreqBits) - 1;
85
87 : Hotness(static_cast<uint32_t>(HotnessType::Unknown)),
89 explicit CalleeInfo(HotnessType Hotness, bool HasTC, uint64_t RelBF)
90 : Hotness(static_cast<uint32_t>(Hotness)), HasTailCall(HasTC),
91 RelBlockFreq(RelBF) {}
92
93 void updateHotness(const HotnessType OtherHotness) {
94 Hotness = std::max(Hotness, static_cast<uint32_t>(OtherHotness));
95 }
96
97 bool hasTailCall() const { return HasTailCall; }
98
99 void setHasTailCall(const bool HasTC) { HasTailCall = HasTC; }
100
102
103 /// Update \p RelBlockFreq from \p BlockFreq and \p EntryFreq
104 ///
105 /// BlockFreq is divided by EntryFreq and added to RelBlockFreq. To represent
106 /// fractional values, the result is represented as a fixed point number with
107 /// scale of -ScaleShift.
108 void updateRelBlockFreq(uint64_t BlockFreq, uint64_t EntryFreq) {
109 if (EntryFreq == 0)
110 return;
111 using Scaled64 = ScaledNumber<uint64_t>;
112 Scaled64 Temp(BlockFreq, ScaleShift);
113 Temp /= Scaled64::get(EntryFreq);
114
115 uint64_t Sum =
116 SaturatingAdd<uint64_t>(Temp.toInt<uint64_t>(), RelBlockFreq);
117 Sum = std::min(Sum, uint64_t(MaxRelBlockFreq));
118 RelBlockFreq = static_cast<uint32_t>(Sum);
119 }
120};
121
123 switch (HT) {
125 return "unknown";
127 return "cold";
129 return "none";
131 return "hot";
133 return "critical";
134 }
135 llvm_unreachable("invalid hotness");
136}
137
138class GlobalValueSummary;
139
140using GlobalValueSummaryList = std::vector<std::unique_ptr<GlobalValueSummary>>;
141
142struct alignas(8) GlobalValueSummaryInfo {
143 union NameOrGV {
144 NameOrGV(bool HaveGVs) {
145 if (HaveGVs)
146 GV = nullptr;
147 else
148 Name = "";
149 }
150
151 /// The GlobalValue corresponding to this summary. This is only used in
152 /// per-module summaries and when the IR is available. E.g. when module
153 /// analysis is being run, or when parsing both the IR and the summary
154 /// from assembly.
156
157 /// Summary string representation. This StringRef points to BC module
158 /// string table and is valid until module data is stored in memory.
159 /// This is guaranteed to happen until runThinLTOBackend function is
160 /// called, so it is safe to use this field during thin link. This field
161 /// is only valid if summary index was loaded from BC file.
163 } U;
164
165 inline GlobalValueSummaryInfo(bool HaveGVs);
166
167 /// List of global value summary structures for a particular value held
168 /// in the GlobalValueMap. Requires a vector in the case of multiple
169 /// COMDAT values of the same name.
171};
172
173/// Map from global value GUID to corresponding summary structures. Use a
174/// std::map rather than a DenseMap so that pointers to the map's value_type
175/// (which are used by ValueInfo) are not invalidated by insertion. Also it will
176/// likely incur less overhead, as the value type is not very small and the size
177/// of the map is unknown, resulting in inefficiencies due to repeated
178/// insertions and resizing.
180 std::map<GlobalValue::GUID, GlobalValueSummaryInfo>;
181
182/// Struct that holds a reference to a particular GUID in a global value
183/// summary.
184struct ValueInfo {
185 enum Flags { HaveGV = 1, ReadOnly = 2, WriteOnly = 4 };
188
189 ValueInfo() = default;
190 ValueInfo(bool HaveGVs, const GlobalValueSummaryMapTy::value_type *R) {
192 RefAndFlags.setInt(HaveGVs);
193 }
194
195 explicit operator bool() const { return getRef(); }
196
197 GlobalValue::GUID getGUID() const { return getRef()->first; }
198 const GlobalValue *getValue() const {
199 assert(haveGVs());
200 return getRef()->second.U.GV;
201 }
202
204 return getRef()->second.SummaryList;
205 }
206
207 // Even if the index is built with GVs available, we may not have one for
208 // summary entries synthesized for profiled indirect call targets.
209 bool hasName() const { return !haveGVs() || getValue(); }
210
211 StringRef name() const {
212 assert(!haveGVs() || getRef()->second.U.GV);
213 return haveGVs() ? getRef()->second.U.GV->getName()
214 : getRef()->second.U.Name;
215 }
216
217 bool haveGVs() const { return RefAndFlags.getInt() & HaveGV; }
218 bool isReadOnly() const {
220 return RefAndFlags.getInt() & ReadOnly;
221 }
222 bool isWriteOnly() const {
224 return RefAndFlags.getInt() & WriteOnly;
225 }
226 unsigned getAccessSpecifier() const {
228 return RefAndFlags.getInt() & (ReadOnly | WriteOnly);
229 }
231 unsigned BadAccessMask = ReadOnly | WriteOnly;
232 return (RefAndFlags.getInt() & BadAccessMask) != BadAccessMask;
233 }
234 void setReadOnly() {
235 // We expect ro/wo attribute to set only once during
236 // ValueInfo lifetime.
239 }
243 }
244
245 const GlobalValueSummaryMapTy::value_type *getRef() const {
246 return RefAndFlags.getPointer();
247 }
248
249 /// Returns the most constraining visibility among summaries. The
250 /// visibilities, ordered from least to most constraining, are: default,
251 /// protected and hidden.
253
254 /// Checks if all summaries are DSO local (have the flag set). When DSOLocal
255 /// propagation has been done, set the parameter to enable fast check.
256 LLVM_ABI bool isDSOLocal(bool WithDSOLocalPropagation = false) const;
257
258 /// Checks if all copies are eligible for auto-hiding (have flag set).
259 LLVM_ABI bool canAutoHide() const;
260};
261
263 OS << VI.getGUID();
264 if (!VI.name().empty())
265 OS << " (" << VI.name() << ")";
266 return OS;
267}
268
269inline bool operator==(const ValueInfo &A, const ValueInfo &B) {
270 assert(A.getRef() && B.getRef() &&
271 "Need ValueInfo with non-null Ref for comparison");
272 return A.getRef() == B.getRef();
273}
274
275inline bool operator!=(const ValueInfo &A, const ValueInfo &B) {
276 assert(A.getRef() && B.getRef() &&
277 "Need ValueInfo with non-null Ref for comparison");
278 return A.getRef() != B.getRef();
279}
280
281inline bool operator<(const ValueInfo &A, const ValueInfo &B) {
282 assert(A.getRef() && B.getRef() &&
283 "Need ValueInfo with non-null Ref to compare GUIDs");
284 return A.getGUID() < B.getGUID();
285}
286
287template <> struct DenseMapInfo<ValueInfo> {
288 static inline ValueInfo getEmptyKey() {
289 return ValueInfo(false, (GlobalValueSummaryMapTy::value_type *)-8);
290 }
291
292 static inline ValueInfo getTombstoneKey() {
293 return ValueInfo(false, (GlobalValueSummaryMapTy::value_type *)-16);
294 }
295
296 static inline bool isSpecialKey(ValueInfo V) {
297 return V == getTombstoneKey() || V == getEmptyKey();
298 }
299
300 static bool isEqual(ValueInfo L, ValueInfo R) {
301 // We are not supposed to mix ValueInfo(s) with different HaveGVs flag
302 // in a same container.
303 assert(isSpecialKey(L) || isSpecialKey(R) || (L.haveGVs() == R.haveGVs()));
304 return L.getRef() == R.getRef();
305 }
306 static unsigned getHashValue(ValueInfo I) { return hash_value(I.getRef()); }
307};
308
309// For optional hinted size reporting, holds a pair of the full stack id
310// (pre-trimming, from the full context in the profile), and the associated
311// total profiled size.
315};
316
317/// Summary of memprof callsite metadata.
319 // Actual callee function.
321
322 // Used to record whole program analysis cloning decisions.
323 // The ThinLTO backend will need to create as many clones as there are entries
324 // in the vector (it is expected and should be confirmed that all such
325 // summaries in the same FunctionSummary have the same number of entries).
326 // Each index records version info for the corresponding clone of this
327 // function. The value is the callee clone it calls (becomes the appended
328 // suffix id). Index 0 is the original version, and a value of 0 calls the
329 // original callee.
331
332 // Represents stack ids in this context, recorded as indices into the
333 // StackIds vector in the summary index, which in turn holds the full 64-bit
334 // stack ids. This reduces memory as there are in practice far fewer unique
335 // stack ids than stack id references.
337
344};
345
347 OS << "Callee: " << SNI.Callee;
348 OS << " Clones: " << llvm::interleaved(SNI.Clones);
349 OS << " StackIds: " << llvm::interleaved(SNI.StackIdIndices);
350 return OS;
351}
352
353// Allocation type assigned to an allocation reached by a given context.
354// More can be added, now this is cold, notcold and hot.
355// Values should be powers of two so that they can be ORed, in particular to
356// track allocations that have different behavior with different calling
357// contexts.
359 None = 0,
360 NotCold = 1,
361 Cold = 2,
362 Hot = 4,
363 All = 7 // This should always be set to the OR of all values.
364};
365
366/// Summary of a single MIB in a memprof metadata on allocations.
367struct MIBInfo {
368 // The allocation type for this profiled context.
370
371 // Represents stack ids in this context, recorded as indices into the
372 // StackIds vector in the summary index, which in turn holds the full 64-bit
373 // stack ids. This reduces memory as there are in practice far fewer unique
374 // stack ids than stack id references.
376
379};
380
382 OS << "AllocType " << (unsigned)MIB.AllocType;
383 OS << " StackIds: " << llvm::interleaved(MIB.StackIdIndices);
384 return OS;
385}
386
387/// Summary of memprof metadata on allocations.
388struct AllocInfo {
389 // Used to record whole program analysis cloning decisions.
390 // The ThinLTO backend will need to create as many clones as there are entries
391 // in the vector (it is expected and should be confirmed that all such
392 // summaries in the same FunctionSummary have the same number of entries).
393 // Each index records version info for the corresponding clone of this
394 // function. The value is the allocation type of the corresponding allocation.
395 // Index 0 is the original version. Before cloning, index 0 may have more than
396 // one allocation type.
398
399 // Vector of MIBs in this memprof metadata.
400 std::vector<MIBInfo> MIBs;
401
402 // If requested, keep track of full stack contexts and total profiled sizes
403 // for each MIB. This will be a vector of the same length and order as the
404 // MIBs vector, if non-empty. Note that each MIB in the summary can have
405 // multiple of these as we trim the contexts when possible during matching.
406 // For hinted size reporting we, however, want the original pre-trimmed full
407 // stack context id for better correlation with the profile.
408 std::vector<std::vector<ContextTotalSize>> ContextSizeInfos;
409
410 AllocInfo(std::vector<MIBInfo> MIBs) : MIBs(std::move(MIBs)) {
412 }
415};
416
418 bool First = true;
419 OS << "Versions: ";
420 for (auto V : AE.Versions) {
421 if (!First)
422 OS << ", ";
423 First = false;
424 OS << (unsigned)V;
425 }
426 OS << " MIB:\n";
427 for (auto &M : AE.MIBs) {
428 OS << "\t\t" << M << "\n";
429 }
430 if (!AE.ContextSizeInfos.empty()) {
431 OS << "\tContextSizeInfo per MIB:\n";
432 for (auto Infos : AE.ContextSizeInfos) {
433 OS << "\t\t";
434 bool FirstInfo = true;
435 for (auto [FullStackId, TotalSize] : Infos) {
436 if (!FirstInfo)
437 OS << ", ";
438 FirstInfo = false;
439 OS << "{ " << FullStackId << ", " << TotalSize << " }";
440 }
441 OS << "\n";
442 }
443 }
444 return OS;
445}
446
447/// Function and variable summary information to aid decisions and
448/// implementation of importing.
450public:
451 /// Sububclass discriminator (for dyn_cast<> et al.)
453
454 enum ImportKind : unsigned {
455 // The global value definition corresponding to the summary should be
456 // imported from source module
458
459 // When its definition doesn't exist in the destination module and not
460 // imported (e.g., function is too large to be inlined), the global value
461 // declaration corresponding to the summary should be imported, or the
462 // attributes from summary should be annotated on the function declaration.
464 };
465
466 /// Group flags (Linkage, NotEligibleToImport, etc.) as a bitfield.
467 struct GVFlags {
468 /// The linkage type of the associated global value.
469 ///
470 /// One use is to flag values that have local linkage types and need to
471 /// have module identifier appended before placing into the combined
472 /// index, to disambiguate from other values with the same name.
473 /// In the future this will be used to update and optimize linkage
474 /// types based on global summary-based analysis.
475 unsigned Linkage : 4;
476
477 /// Indicates the visibility.
478 unsigned Visibility : 2;
479
480 /// Indicate if the global value cannot be imported (e.g. it cannot
481 /// be renamed or references something that can't be renamed).
483
484 /// In per-module summary, indicate that the global value must be considered
485 /// a live root for index-based liveness analysis. Used for special LLVM
486 /// values such as llvm.global_ctors that the linker does not know about.
487 ///
488 /// In combined summary, indicate that the global value is live.
489 unsigned Live : 1;
490
491 /// Indicates that the linker resolved the symbol to a definition from
492 /// within the same linkage unit.
493 unsigned DSOLocal : 1;
494
495 /// In the per-module summary, indicates that the global value is
496 /// linkonce_odr and global unnamed addr (so eligible for auto-hiding
497 /// via hidden visibility). In the combined summary, indicates that the
498 /// prevailing linkonce_odr copy can be auto-hidden via hidden visibility
499 /// when it is upgraded to weak_odr in the backend. This is legal when
500 /// all copies are eligible for auto-hiding (i.e. all copies were
501 /// linkonce_odr global unnamed addr. If any copy is not (e.g. it was
502 /// originally weak_odr, we cannot auto-hide the prevailing copy as it
503 /// means the symbol was externally visible.
504 unsigned CanAutoHide : 1;
505
506 /// This field is written by the ThinLTO indexing step to postlink combined
507 /// summary. The value is interpreted as 'ImportKind' enum defined above.
508 unsigned ImportType : 1;
509
510 /// Convenience Constructors
513 bool NotEligibleToImport, bool Live, bool IsLocal,
518 ImportType(static_cast<unsigned>(ImportType)) {}
519 };
520
521private:
522 /// Kind of summary for use in dyn_cast<> et al.
523 SummaryKind Kind;
524
525 GVFlags Flags;
526
527 /// This is the hash of the name of the symbol in the original file. It is
528 /// identical to the GUID for global symbols, but differs for local since the
529 /// GUID includes the module level id in the hash.
530 GlobalValue::GUID OriginalName = 0;
531
532 /// Path of module IR containing value's definition, used to locate
533 /// module during importing.
534 ///
535 /// This is only used during parsing of the combined index, or when
536 /// parsing the per-module index for creation of the combined summary index,
537 /// not during writing of the per-module index which doesn't contain a
538 /// module path string table.
539 StringRef ModulePath;
540
541 /// List of values referenced by this global value's definition
542 /// (either by the initializer of a global variable, or referenced
543 /// from within a function). This does not include functions called, which
544 /// are listed in the derived FunctionSummary object.
545 /// We use SmallVector<ValueInfo, 0> instead of std::vector<ValueInfo> for its
546 /// smaller memory footprint.
547 SmallVector<ValueInfo, 0> RefEdgeList;
548
549protected:
552 : Kind(K), Flags(Flags), RefEdgeList(std::move(Refs)) {
553 assert((K != AliasKind || Refs.empty()) &&
554 "Expect no references for AliasSummary");
555 }
556
557public:
558 virtual ~GlobalValueSummary() = default;
559
560 /// Returns the hash of the original name, it is identical to the GUID for
561 /// externally visible symbols, but not for local ones.
562 GlobalValue::GUID getOriginalName() const { return OriginalName; }
563
564 /// Initialize the original name hash in this summary.
565 void setOriginalName(GlobalValue::GUID Name) { OriginalName = Name; }
566
567 /// Which kind of summary subclass this is.
568 SummaryKind getSummaryKind() const { return Kind; }
569
570 /// Set the path to the module containing this function, for use in
571 /// the combined index.
572 void setModulePath(StringRef ModPath) { ModulePath = ModPath; }
573
574 /// Get the path to the module containing this function.
575 StringRef modulePath() const { return ModulePath; }
576
577 /// Get the flags for this GlobalValue (see \p struct GVFlags).
578 GVFlags flags() const { return Flags; }
579
580 /// Return linkage type recorded for this global value.
582 return static_cast<GlobalValue::LinkageTypes>(Flags.Linkage);
583 }
584
585 /// Sets the linkage to the value determined by global summary-based
586 /// optimization. Will be applied in the ThinLTO backends.
588 Flags.Linkage = Linkage;
589 }
590
591 /// Return true if this global value can't be imported.
592 bool notEligibleToImport() const { return Flags.NotEligibleToImport; }
593
594 bool isLive() const { return Flags.Live; }
595
596 void setLive(bool Live) { Flags.Live = Live; }
597
598 void setDSOLocal(bool Local) { Flags.DSOLocal = Local; }
599
600 bool isDSOLocal() const { return Flags.DSOLocal; }
601
602 void setCanAutoHide(bool CanAutoHide) { Flags.CanAutoHide = CanAutoHide; }
603
604 bool canAutoHide() const { return Flags.CanAutoHide; }
605
606 bool shouldImportAsDecl() const {
607 return Flags.ImportType == GlobalValueSummary::ImportKind::Declaration;
608 }
609
610 void setImportKind(ImportKind IK) { Flags.ImportType = IK; }
611
613 return static_cast<ImportKind>(Flags.ImportType);
614 }
615
617 return (GlobalValue::VisibilityTypes)Flags.Visibility;
618 }
620 Flags.Visibility = (unsigned)Vis;
621 }
622
623 /// Flag that this global value cannot be imported.
624 void setNotEligibleToImport() { Flags.NotEligibleToImport = true; }
625
626 /// Return the list of values referenced by this global value definition.
627 ArrayRef<ValueInfo> refs() const { return RefEdgeList; }
628
629 /// If this is an alias summary, returns the summary of the aliased object (a
630 /// global variable or function), otherwise returns itself.
632 const GlobalValueSummary *getBaseObject() const;
633
634 friend class ModuleSummaryIndex;
635};
636
638
639/// Alias summary information.
641 ValueInfo AliaseeValueInfo;
642
643 /// This is the Aliasee in the same module as alias (could get from VI, trades
644 /// memory for time). Note that this pointer may be null (and the value info
645 /// empty) when we have a distributed index where the alias is being imported
646 /// (as a copy of the aliasee), but the aliasee is not.
647 GlobalValueSummary *AliaseeSummary = nullptr;
648
649public:
652
653 /// Check if this is an alias summary.
654 static bool classof(const GlobalValueSummary *GVS) {
655 return GVS->getSummaryKind() == AliasKind;
656 }
657
658 void setAliasee(ValueInfo &AliaseeVI, GlobalValueSummary *Aliasee) {
659 AliaseeValueInfo = AliaseeVI;
660 AliaseeSummary = Aliasee;
661 }
662
663 bool hasAliasee() const {
664 assert(!!AliaseeSummary == (AliaseeValueInfo &&
665 !AliaseeValueInfo.getSummaryList().empty()) &&
666 "Expect to have both aliasee summary and summary list or neither");
667 return !!AliaseeSummary;
668 }
669
671 assert(AliaseeSummary && "Unexpected missing aliasee summary");
672 return *AliaseeSummary;
673 }
674
676 return const_cast<GlobalValueSummary &>(
677 static_cast<const AliasSummary *>(this)->getAliasee());
678 }
680 assert(AliaseeValueInfo && "Unexpected missing aliasee");
681 return AliaseeValueInfo;
682 }
684 assert(AliaseeValueInfo && "Unexpected missing aliasee");
685 return AliaseeValueInfo.getGUID();
686 }
687};
688
690 if (auto *AS = dyn_cast<AliasSummary>(this))
691 return &AS->getAliasee();
692 return this;
693}
694
696 if (auto *AS = dyn_cast<AliasSummary>(this))
697 return &AS->getAliasee();
698 return this;
699}
700
701/// Function summary information to aid decisions and implementation of
702/// importing.
704public:
705 /// <CalleeValueInfo, CalleeInfo> call edge pair.
706 using EdgeTy = std::pair<ValueInfo, CalleeInfo>;
707
708 /// Types for -force-summary-edges-cold debugging option.
709 enum ForceSummaryHotnessType : unsigned {
713 };
714
715 /// An "identifier" for a virtual function. This contains the type identifier
716 /// represented as a GUID and the offset from the address point to the virtual
717 /// function pointer, where "address point" is as defined in the Itanium ABI:
718 /// https://itanium-cxx-abi.github.io/cxx-abi/abi.html#vtable-general
719 struct VFuncId {
722 };
723
724 /// A specification for a virtual function call with all constant integer
725 /// arguments. This is used to perform virtual constant propagation on the
726 /// summary.
727 struct ConstVCall {
729 std::vector<uint64_t> Args;
730 };
731
732 /// All type identifier related information. Because these fields are
733 /// relatively uncommon we only allocate space for them if necessary.
734 struct TypeIdInfo {
735 /// List of type identifiers used by this function in llvm.type.test
736 /// intrinsics referenced by something other than an llvm.assume intrinsic,
737 /// represented as GUIDs.
738 std::vector<GlobalValue::GUID> TypeTests;
739
740 /// List of virtual calls made by this function using (respectively)
741 /// llvm.assume(llvm.type.test) or llvm.type.checked.load intrinsics that do
742 /// not have all constant integer arguments.
744
745 /// List of virtual calls made by this function using (respectively)
746 /// llvm.assume(llvm.type.test) or llvm.type.checked.load intrinsics with
747 /// all constant integer arguments.
748 std::vector<ConstVCall> TypeTestAssumeConstVCalls,
750 };
751
752 /// Flags specific to function summaries.
753 struct FFlags {
754 // Function attribute flags. Used to track if a function accesses memory,
755 // recurses or aliases.
756 unsigned ReadNone : 1;
757 unsigned ReadOnly : 1;
758 unsigned NoRecurse : 1;
759 unsigned ReturnDoesNotAlias : 1;
760
761 // Indicate if the global value cannot be inlined.
762 unsigned NoInline : 1;
763 // Indicate if function should be always inlined.
764 unsigned AlwaysInline : 1;
765 // Indicate if function never raises an exception. Can be modified during
766 // thinlink function attribute propagation
767 unsigned NoUnwind : 1;
768 // Indicate if function contains instructions that mayThrow
769 unsigned MayThrow : 1;
770
771 // If there are calls to unknown targets (e.g. indirect)
772 unsigned HasUnknownCall : 1;
773
774 // Indicate if a function must be an unreachable function.
775 //
776 // This bit is sufficient but not necessary;
777 // if this bit is on, the function must be regarded as unreachable;
778 // if this bit is off, the function might be reachable or unreachable.
779 unsigned MustBeUnreachable : 1;
780
782 this->ReadNone &= RHS.ReadNone;
783 this->ReadOnly &= RHS.ReadOnly;
784 this->NoRecurse &= RHS.NoRecurse;
786 this->NoInline &= RHS.NoInline;
787 this->AlwaysInline &= RHS.AlwaysInline;
788 this->NoUnwind &= RHS.NoUnwind;
789 this->MayThrow &= RHS.MayThrow;
790 this->HasUnknownCall &= RHS.HasUnknownCall;
792 return *this;
793 }
794
795 bool anyFlagSet() {
796 return this->ReadNone | this->ReadOnly | this->NoRecurse |
797 this->ReturnDoesNotAlias | this->NoInline | this->AlwaysInline |
798 this->NoUnwind | this->MayThrow | this->HasUnknownCall |
799 this->MustBeUnreachable;
800 }
801
802 operator std::string() {
803 std::string Output;
804 raw_string_ostream OS(Output);
805 OS << "funcFlags: (";
806 OS << "readNone: " << this->ReadNone;
807 OS << ", readOnly: " << this->ReadOnly;
808 OS << ", noRecurse: " << this->NoRecurse;
809 OS << ", returnDoesNotAlias: " << this->ReturnDoesNotAlias;
810 OS << ", noInline: " << this->NoInline;
811 OS << ", alwaysInline: " << this->AlwaysInline;
812 OS << ", noUnwind: " << this->NoUnwind;
813 OS << ", mayThrow: " << this->MayThrow;
814 OS << ", hasUnknownCall: " << this->HasUnknownCall;
815 OS << ", mustBeUnreachable: " << this->MustBeUnreachable;
816 OS << ")";
817 return Output;
818 }
819 };
820
821 /// Describes the uses of a parameter by the function.
822 struct ParamAccess {
823 static constexpr uint32_t RangeWidth = 64;
824
825 /// Describes the use of a value in a call instruction, specifying the
826 /// call's target, the value's parameter number, and the possible range of
827 /// offsets from the beginning of the value that are passed.
828 struct Call {
831 ConstantRange Offsets{/*BitWidth=*/RangeWidth, /*isFullSet=*/true};
832
833 Call() = default;
836 };
837
839 /// The range contains byte offsets from the parameter pointer which
840 /// accessed by the function. In the per-module summary, it only includes
841 /// accesses made by the function instructions. In the combined summary, it
842 /// also includes accesses by nested function calls.
843 ConstantRange Use{/*BitWidth=*/RangeWidth, /*isFullSet=*/true};
844 /// In the per-module summary, it summarizes the byte offset applied to each
845 /// pointer parameter before passing to each corresponding callee.
846 /// In the combined summary, it's empty and information is propagated by
847 /// inter-procedural analysis and applied to the Use field.
848 std::vector<Call> Calls;
849
850 ParamAccess() = default;
852 : ParamNo(ParamNo), Use(Use) {}
853 };
854
855 /// Create an empty FunctionSummary (with specified call edges).
856 /// Used to represent external nodes and the dummy root node.
857 static FunctionSummary
859 return FunctionSummary(
863 /*NotEligibleToImport=*/true, /*Live=*/true, /*IsLocal=*/false,
864 /*CanAutoHide=*/false, GlobalValueSummary::ImportKind::Definition),
866 std::move(Edges), std::vector<GlobalValue::GUID>(),
867 std::vector<FunctionSummary::VFuncId>(),
868 std::vector<FunctionSummary::VFuncId>(),
869 std::vector<FunctionSummary::ConstVCall>(),
870 std::vector<FunctionSummary::ConstVCall>(),
871 std::vector<FunctionSummary::ParamAccess>(),
872 std::vector<CallsiteInfo>(), std::vector<AllocInfo>());
873 }
874
875 /// A dummy node to reference external functions that aren't in the index
877
878private:
879 /// Number of instructions (ignoring debug instructions, e.g.) computed
880 /// during the initial compile step when the summary index is first built.
881 unsigned InstCount;
882
883 /// Function summary specific flags.
884 FFlags FunFlags;
885
886 /// List of <CalleeValueInfo, CalleeInfo> call edge pairs from this function.
887 /// We use SmallVector<ValueInfo, 0> instead of std::vector<ValueInfo> for its
888 /// smaller memory footprint.
889 SmallVector<EdgeTy, 0> CallGraphEdgeList;
890
891 std::unique_ptr<TypeIdInfo> TIdInfo;
892
893 /// Uses for every parameter to this function.
894 using ParamAccessesTy = std::vector<ParamAccess>;
895 std::unique_ptr<ParamAccessesTy> ParamAccesses;
896
897 /// Optional list of memprof callsite metadata summaries. The correspondence
898 /// between the callsite summary and the callsites in the function is implied
899 /// by the order in the vector (and can be validated by comparing the stack
900 /// ids in the CallsiteInfo to those in the instruction callsite metadata).
901 /// As a memory savings optimization, we only create these for the prevailing
902 /// copy of a symbol when creating the combined index during LTO.
903 using CallsitesTy = std::vector<CallsiteInfo>;
904 std::unique_ptr<CallsitesTy> Callsites;
905
906 /// Optional list of allocation memprof metadata summaries. The correspondence
907 /// between the alloc memprof summary and the allocation callsites in the
908 /// function is implied by the order in the vector (and can be validated by
909 /// comparing the stack ids in the AllocInfo to those in the instruction
910 /// memprof metadata).
911 /// As a memory savings optimization, we only create these for the prevailing
912 /// copy of a symbol when creating the combined index during LTO.
913 using AllocsTy = std::vector<AllocInfo>;
914 std::unique_ptr<AllocsTy> Allocs;
915
916public:
917 FunctionSummary(GVFlags Flags, unsigned NumInsts, FFlags FunFlags,
919 SmallVectorImpl<EdgeTy> &&CGEdges,
920 std::vector<GlobalValue::GUID> TypeTests,
921 std::vector<VFuncId> TypeTestAssumeVCalls,
922 std::vector<VFuncId> TypeCheckedLoadVCalls,
923 std::vector<ConstVCall> TypeTestAssumeConstVCalls,
924 std::vector<ConstVCall> TypeCheckedLoadConstVCalls,
925 std::vector<ParamAccess> Params, CallsitesTy CallsiteList,
926 AllocsTy AllocList)
927 : GlobalValueSummary(FunctionKind, Flags, std::move(Refs)),
928 InstCount(NumInsts), FunFlags(FunFlags),
929 CallGraphEdgeList(std::move(CGEdges)) {
930 if (!TypeTests.empty() || !TypeTestAssumeVCalls.empty() ||
931 !TypeCheckedLoadVCalls.empty() || !TypeTestAssumeConstVCalls.empty() ||
932 !TypeCheckedLoadConstVCalls.empty())
933 TIdInfo = std::make_unique<TypeIdInfo>(
934 TypeIdInfo{std::move(TypeTests), std::move(TypeTestAssumeVCalls),
935 std::move(TypeCheckedLoadVCalls),
936 std::move(TypeTestAssumeConstVCalls),
937 std::move(TypeCheckedLoadConstVCalls)});
938 if (!Params.empty())
939 ParamAccesses = std::make_unique<ParamAccessesTy>(std::move(Params));
940 if (!CallsiteList.empty())
941 Callsites = std::make_unique<CallsitesTy>(std::move(CallsiteList));
942 if (!AllocList.empty())
943 Allocs = std::make_unique<AllocsTy>(std::move(AllocList));
944 }
945 // Gets the number of readonly and writeonly refs in RefEdgeList
946 LLVM_ABI std::pair<unsigned, unsigned> specialRefCounts() const;
947
948 /// Check if this is a function summary.
949 static bool classof(const GlobalValueSummary *GVS) {
950 return GVS->getSummaryKind() == FunctionKind;
951 }
952
953 /// Get function summary flags.
954 FFlags fflags() const { return FunFlags; }
955
956 void setNoRecurse() { FunFlags.NoRecurse = true; }
957
958 void setNoUnwind() { FunFlags.NoUnwind = true; }
959
960 /// Get the instruction count recorded for this function.
961 unsigned instCount() const { return InstCount; }
962
963 /// Return the list of <CalleeValueInfo, CalleeInfo> pairs.
964 ArrayRef<EdgeTy> calls() const { return CallGraphEdgeList; }
965
966 SmallVector<EdgeTy, 0> &mutableCalls() { return CallGraphEdgeList; }
967
968 void addCall(EdgeTy E) { CallGraphEdgeList.push_back(E); }
969
970 /// Returns the list of type identifiers used by this function in
971 /// llvm.type.test intrinsics other than by an llvm.assume intrinsic,
972 /// represented as GUIDs.
974 if (TIdInfo)
975 return TIdInfo->TypeTests;
976 return {};
977 }
978
979 /// Returns the list of virtual calls made by this function using
980 /// llvm.assume(llvm.type.test) intrinsics that do not have all constant
981 /// integer arguments.
983 if (TIdInfo)
984 return TIdInfo->TypeTestAssumeVCalls;
985 return {};
986 }
987
988 /// Returns the list of virtual calls made by this function using
989 /// llvm.type.checked.load intrinsics that do not have all constant integer
990 /// arguments.
992 if (TIdInfo)
993 return TIdInfo->TypeCheckedLoadVCalls;
994 return {};
995 }
996
997 /// Returns the list of virtual calls made by this function using
998 /// llvm.assume(llvm.type.test) intrinsics with all constant integer
999 /// arguments.
1001 if (TIdInfo)
1002 return TIdInfo->TypeTestAssumeConstVCalls;
1003 return {};
1004 }
1005
1006 /// Returns the list of virtual calls made by this function using
1007 /// llvm.type.checked.load intrinsics with all constant integer arguments.
1009 if (TIdInfo)
1010 return TIdInfo->TypeCheckedLoadConstVCalls;
1011 return {};
1012 }
1013
1014 /// Returns the list of known uses of pointer parameters.
1016 if (ParamAccesses)
1017 return *ParamAccesses;
1018 return {};
1019 }
1020
1021 /// Sets the list of known uses of pointer parameters.
1022 void setParamAccesses(std::vector<ParamAccess> NewParams) {
1023 if (NewParams.empty())
1024 ParamAccesses.reset();
1025 else if (ParamAccesses)
1026 *ParamAccesses = std::move(NewParams);
1027 else
1028 ParamAccesses = std::make_unique<ParamAccessesTy>(std::move(NewParams));
1029 }
1030
1031 /// Add a type test to the summary. This is used by WholeProgramDevirt if we
1032 /// were unable to devirtualize a checked call.
1034 if (!TIdInfo)
1035 TIdInfo = std::make_unique<TypeIdInfo>();
1036 TIdInfo->TypeTests.push_back(Guid);
1037 }
1038
1039 const TypeIdInfo *getTypeIdInfo() const { return TIdInfo.get(); };
1040
1042 if (Callsites)
1043 return *Callsites;
1044 return {};
1045 }
1046
1047 CallsitesTy &mutableCallsites() {
1048 assert(Callsites);
1049 return *Callsites;
1050 }
1051
1052 void addCallsite(CallsiteInfo &Callsite) {
1053 if (!Callsites)
1054 Callsites = std::make_unique<CallsitesTy>();
1055 Callsites->push_back(Callsite);
1056 }
1057
1059 if (Allocs)
1060 return *Allocs;
1061 return {};
1062 }
1063
1064 AllocsTy &mutableAllocs() {
1065 assert(Allocs);
1066 return *Allocs;
1067 }
1068
1069 friend struct GraphTraits<ValueInfo>;
1070};
1071
1072template <> struct DenseMapInfo<FunctionSummary::VFuncId> {
1073 static FunctionSummary::VFuncId getEmptyKey() { return {0, uint64_t(-1)}; }
1074
1076 return {0, uint64_t(-2)};
1077 }
1078
1080 return L.GUID == R.GUID && L.Offset == R.Offset;
1081 }
1082
1083 static unsigned getHashValue(FunctionSummary::VFuncId I) { return I.GUID; }
1084};
1085
1086template <> struct DenseMapInfo<FunctionSummary::ConstVCall> {
1088 return {{0, uint64_t(-1)}, {}};
1089 }
1090
1092 return {{0, uint64_t(-2)}, {}};
1093 }
1094
1097 return DenseMapInfo<FunctionSummary::VFuncId>::isEqual(L.VFunc, R.VFunc) &&
1098 L.Args == R.Args;
1099 }
1100
1102 return I.VFunc.GUID;
1103 }
1104};
1105
1106/// The ValueInfo and offset for a function within a vtable definition
1107/// initializer array.
1110 : FuncVI(VI), VTableOffset(Offset) {}
1111
1114};
1115/// List of functions referenced by a particular vtable definition.
1116using VTableFuncList = std::vector<VirtFuncOffset>;
1117
1118/// Global variable summary information to aid decisions and
1119/// implementation of importing.
1120///
1121/// Global variable summary has two extra flag, telling if it is
1122/// readonly or writeonly. Both readonly and writeonly variables
1123/// can be optimized in the backed: readonly variables can be
1124/// const-folded, while writeonly vars can be completely eliminated
1125/// together with corresponding stores. We let both things happen
1126/// by means of internalizing such variables after ThinLTO import.
1128private:
1129 /// For vtable definitions this holds the list of functions and
1130 /// their corresponding offsets within the initializer array.
1131 std::unique_ptr<VTableFuncList> VTableFuncs;
1132
1133public:
1134 struct GVarFlags {
1135 GVarFlags(bool ReadOnly, bool WriteOnly, bool Constant,
1137 : MaybeReadOnly(ReadOnly), MaybeWriteOnly(WriteOnly),
1139
1140 // If true indicates that this global variable might be accessed
1141 // purely by non-volatile load instructions. This in turn means
1142 // it can be internalized in source and destination modules during
1143 // thin LTO import because it neither modified nor its address
1144 // is taken.
1145 unsigned MaybeReadOnly : 1;
1146 // If true indicates that variable is possibly only written to, so
1147 // its value isn't loaded and its address isn't taken anywhere.
1148 // False, when 'Constant' attribute is set.
1149 unsigned MaybeWriteOnly : 1;
1150 // Indicates that value is a compile-time constant. Global variable
1151 // can be 'Constant' while not being 'ReadOnly' on several occasions:
1152 // - it is volatile, (e.g mapped device address)
1153 // - its address is taken, meaning that unlike 'ReadOnly' vars we can't
1154 // internalize it.
1155 // Constant variables are always imported thus giving compiler an
1156 // opportunity to make some extra optimizations. Readonly constants
1157 // are also internalized.
1158 unsigned Constant : 1;
1159 // Set from metadata on vtable definitions during the module summary
1160 // analysis.
1161 unsigned VCallVisibility : 2;
1163
1166 : GlobalValueSummary(GlobalVarKind, Flags, std::move(Refs)),
1167 VarFlags(VarFlags) {}
1168
1169 /// Check if this is a global variable summary.
1170 static bool classof(const GlobalValueSummary *GVS) {
1171 return GVS->getSummaryKind() == GlobalVarKind;
1172 }
1173
1174 GVarFlags varflags() const { return VarFlags; }
1175 void setReadOnly(bool RO) { VarFlags.MaybeReadOnly = RO; }
1176 void setWriteOnly(bool WO) { VarFlags.MaybeWriteOnly = WO; }
1177 bool maybeReadOnly() const { return VarFlags.MaybeReadOnly; }
1178 bool maybeWriteOnly() const { return VarFlags.MaybeWriteOnly; }
1179 bool isConstant() const { return VarFlags.Constant; }
1182 }
1185 }
1186
1188 assert(!VTableFuncs);
1189 VTableFuncs = std::make_unique<VTableFuncList>(std::move(Funcs));
1190 }
1191
1193 if (VTableFuncs)
1194 return *VTableFuncs;
1195 return {};
1196 }
1197};
1198
1200 /// Specifies which kind of type check we should emit for this byte array.
1201 /// See http://clang.llvm.org/docs/ControlFlowIntegrityDesign.html for full
1202 /// details on each kind of check; the enumerators are described with
1203 /// reference to that document.
1204 enum Kind {
1205 Unsat, ///< Unsatisfiable type (i.e. no global has this type metadata)
1206 ByteArray, ///< Test a byte array (first example)
1207 Inline, ///< Inlined bit vector ("Short Inline Bit Vectors")
1208 Single, ///< Single element (last example in "Short Inline Bit Vectors")
1209 AllOnes, ///< All-ones bit vector ("Eliminating Bit Vector Checks for
1210 /// All-Ones Bit Vectors")
1211 Unknown, ///< Unknown (analysis not performed, don't lower)
1213
1214 /// Range of size-1 expressed as a bit width. For example, if the size is in
1215 /// range [1,256], this number will be 8. This helps generate the most compact
1216 /// instruction sequences.
1217 unsigned SizeM1BitWidth = 0;
1218
1219 // The following fields are only used if the target does not support the use
1220 // of absolute symbols to store constants. Their meanings are the same as the
1221 // corresponding fields in LowerTypeTestsModule::TypeIdLowering in
1222 // LowerTypeTests.cpp.
1223
1228};
1229
1231 enum Kind {
1232 Indir, ///< Just do a regular virtual call
1233 SingleImpl, ///< Single implementation devirtualization
1234 BranchFunnel, ///< When retpoline mitigation is enabled, use a branch funnel
1235 ///< that is defined in the merged module. Otherwise same as
1236 ///< Indir.
1238
1239 std::string SingleImplName;
1240
1241 struct ByArg {
1242 enum Kind {
1243 Indir, ///< Just do a regular virtual call
1244 UniformRetVal, ///< Uniform return value optimization
1245 UniqueRetVal, ///< Unique return value optimization
1246 VirtualConstProp, ///< Virtual constant propagation
1248
1249 /// Additional information for the resolution:
1250 /// - UniformRetVal: the uniform return value.
1251 /// - UniqueRetVal: the return value associated with the unique vtable (0 or
1252 /// 1).
1254
1255 // The following fields are only used if the target does not support the use
1256 // of absolute symbols to store constants.
1257
1260 };
1261
1262 /// Resolutions for calls with all constant integer arguments (excluding the
1263 /// first argument, "this"), where the key is the argument vector.
1264 std::map<std::vector<uint64_t>, ByArg> ResByArg;
1265};
1266
1269
1270 /// Mapping from byte offset to whole-program devirt resolution for that
1271 /// (typeid, byte offset) pair.
1272 std::map<uint64_t, WholeProgramDevirtResolution> WPDRes;
1273};
1274
1277 using IndexIterator =
1279 std::set<std::string, std::less<>>>::const_iterator;
1280 using NestedIterator = std::set<std::string, std::less<>>::const_iterator;
1281
1282public:
1283 // Iterates keys of the DenseMap.
1284 class GUIDIterator : public iterator_adaptor_base<GUIDIterator, IndexIterator,
1285 std::forward_iterator_tag,
1286 GlobalValue::GUID> {
1288
1289 public:
1290 GUIDIterator() = default;
1291 explicit GUIDIterator(IndexIterator I) : base(I) {}
1292
1293 GlobalValue::GUID operator*() const { return this->wrapped()->first; }
1294 };
1295
1296 CfiFunctionIndex() = default;
1297 template <typename It> CfiFunctionIndex(It B, It E) {
1298 for (; B != E; ++B)
1299 emplace(*B);
1300 }
1301
1302 std::vector<StringRef> symbols() const {
1303 std::vector<StringRef> Symbols;
1304 for (auto &[GUID, Syms] : Index) {
1305 (void)GUID;
1306 llvm::append_range(Symbols, Syms);
1307 }
1308 return Symbols;
1309 }
1310
1311 GUIDIterator guid_begin() const { return GUIDIterator(Index.begin()); }
1312 GUIDIterator guid_end() const { return GUIDIterator(Index.end()); }
1314 return make_range(guid_begin(), guid_end());
1315 }
1316
1318 auto I = Index.find(GUID);
1319 if (I == Index.end())
1320 return make_range(NestedIterator{}, NestedIterator{});
1321 return make_range(I->second.begin(), I->second.end());
1322 }
1323
1324 template <typename... Args> void emplace(Args &&...A) {
1325 StringRef S(std::forward<Args>(A)...);
1328 Index[GUID].emplace(S);
1329 }
1330
1331 size_t count(StringRef S) const {
1334 auto I = Index.find(GUID);
1335 if (I == Index.end())
1336 return 0;
1337 return I->second.count(S);
1338 }
1339
1340 bool empty() const { return Index.empty(); }
1341};
1342
1343/// 160 bits SHA1
1344using ModuleHash = std::array<uint32_t, 5>;
1345
1346/// Type used for iterating through the global value summary map.
1347using const_gvsummary_iterator = GlobalValueSummaryMapTy::const_iterator;
1348using gvsummary_iterator = GlobalValueSummaryMapTy::iterator;
1349
1350/// String table to hold/own module path strings, as well as a hash
1351/// of the module. The StringMap makes a copy of and owns inserted strings.
1353
1354/// Map of global value GUID to its summary, used to identify values defined in
1355/// a particular module, and provide efficient access to their summary.
1357
1358/// Map of a module name to the GUIDs and summaries we will import from that
1359/// module.
1361 std::map<std::string, GVSummaryMapTy, std::less<>>;
1362
1363/// A set of global value summary pointers.
1364using GVSummaryPtrSet = std::unordered_set<GlobalValueSummary *>;
1365
1366/// Map of a type GUID to type id string and summary (multimap used
1367/// in case of GUID conflicts).
1369 std::multimap<GlobalValue::GUID, std::pair<StringRef, TypeIdSummary>>;
1370
1371/// The following data structures summarize type metadata information.
1372/// For type metadata overview see https://llvm.org/docs/TypeMetadata.html.
1373/// Each type metadata includes both the type identifier and the offset of
1374/// the address point of the type (the address held by objects of that type
1375/// which may not be the beginning of the virtual table). Vtable definitions
1376/// are decorated with type metadata for the types they are compatible with.
1377///
1378/// Holds information about vtable definitions decorated with type metadata:
1379/// the vtable definition value and its address point offset in a type
1380/// identifier metadata it is decorated (compatible) with.
1384
1387};
1388/// List of vtable definitions decorated by a particular type identifier,
1389/// and their corresponding offsets in that type identifier's metadata.
1390/// Note that each type identifier may be compatible with multiple vtables, due
1391/// to inheritance, which is why this is a vector.
1392using TypeIdCompatibleVtableInfo = std::vector<TypeIdOffsetVtableInfo>;
1393
1394/// Class to hold module path string table and global value map,
1395/// and encapsulate methods for operating on them.
1397private:
1398 /// Map from value name to list of summary instances for values of that
1399 /// name (may be duplicates in the COMDAT case, e.g.).
1400 GlobalValueSummaryMapTy GlobalValueMap;
1401
1402 /// Holds strings for combined index, mapping to the corresponding module ID.
1403 ModulePathStringTableTy ModulePathStringTable;
1404
1405 BumpPtrAllocator TypeIdSaverAlloc;
1406 UniqueStringSaver TypeIdSaver;
1407
1408 /// Mapping from type identifier GUIDs to type identifier and its summary
1409 /// information. Produced by thin link.
1410 TypeIdSummaryMapTy TypeIdMap;
1411
1412 /// Mapping from type identifier to information about vtables decorated
1413 /// with that type identifier's metadata. Produced by per module summary
1414 /// analysis and consumed by thin link. For more information, see description
1415 /// above where TypeIdCompatibleVtableInfo is defined.
1416 std::map<StringRef, TypeIdCompatibleVtableInfo, std::less<>>
1417 TypeIdCompatibleVtableMap;
1418
1419 /// Mapping from original ID to GUID. If original ID can map to multiple
1420 /// GUIDs, it will be mapped to 0.
1422
1423 /// Indicates that summary-based GlobalValue GC has run, and values with
1424 /// GVFlags::Live==false are really dead. Otherwise, all values must be
1425 /// considered live.
1426 bool WithGlobalValueDeadStripping = false;
1427
1428 /// Indicates that summary-based attribute propagation has run and
1429 /// GVarFlags::MaybeReadonly / GVarFlags::MaybeWriteonly are really
1430 /// read/write only.
1431 bool WithAttributePropagation = false;
1432
1433 /// Indicates that summary-based DSOLocal propagation has run and the flag in
1434 /// every summary of a GV is synchronized.
1435 bool WithDSOLocalPropagation = false;
1436
1437 /// Indicates that we have whole program visibility.
1438 bool WithWholeProgramVisibility = false;
1439
1440 /// Indicates that summary-based synthetic entry count propagation has run
1441 bool HasSyntheticEntryCounts = false;
1442
1443 /// Indicates that we linked with allocator supporting hot/cold new operators.
1444 bool WithSupportsHotColdNew = false;
1445
1446 /// Indicates that distributed backend should skip compilation of the
1447 /// module. Flag is suppose to be set by distributed ThinLTO indexing
1448 /// when it detected that the module is not needed during the final
1449 /// linking. As result distributed backend should just output a minimal
1450 /// valid object file.
1451 bool SkipModuleByDistributedBackend = false;
1452
1453 /// If true then we're performing analysis of IR module, or parsing along with
1454 /// the IR from assembly. The value of 'false' means we're reading summary
1455 /// from BC or YAML source. Affects the type of value stored in NameOrGV
1456 /// union.
1457 bool HaveGVs;
1458
1459 // True if the index was created for a module compiled with -fsplit-lto-unit.
1460 bool EnableSplitLTOUnit;
1461
1462 // True if the index was created for a module compiled with -funified-lto
1463 bool UnifiedLTO;
1464
1465 // True if some of the modules were compiled with -fsplit-lto-unit and
1466 // some were not. Set when the combined index is created during the thin link.
1467 bool PartiallySplitLTOUnits = false;
1468
1469 /// True if some of the FunctionSummary contains a ParamAccess.
1470 bool HasParamAccess = false;
1471
1472 CfiFunctionIndex CfiFunctionDefs;
1473 CfiFunctionIndex CfiFunctionDecls;
1474
1475 // Used in cases where we want to record the name of a global, but
1476 // don't have the string owned elsewhere (e.g. the Strtab on a module).
1477 BumpPtrAllocator Alloc;
1478 StringSaver Saver;
1479
1480 // The total number of basic blocks in the module in the per-module summary or
1481 // the total number of basic blocks in the LTO unit in the combined index.
1482 // FIXME: Putting this in the distributed ThinLTO index files breaks LTO
1483 // backend caching on any BB change to any linked file. It is currently not
1484 // used except in the case of a SamplePGO partial profile, and should be
1485 // reevaluated/redesigned to allow more effective incremental builds in that
1486 // case.
1487 uint64_t BlockCount = 0;
1488
1489 // List of unique stack ids (hashes). We use a 4B index of the id in the
1490 // stack id lists on the alloc and callsite summaries for memory savings,
1491 // since the number of unique ids is in practice much smaller than the
1492 // number of stack id references in the summaries.
1493 std::vector<uint64_t> StackIds;
1494
1495 // Temporary map while building StackIds list. Clear when index is completely
1496 // built via releaseTemporaryMemory.
1497 DenseMap<uint64_t, unsigned> StackIdToIndex;
1498
1499 // YAML I/O support.
1501
1502 GlobalValueSummaryMapTy::value_type *
1503 getOrInsertValuePtr(GlobalValue::GUID GUID) {
1504 return &*GlobalValueMap.emplace(GUID, GlobalValueSummaryInfo(HaveGVs))
1505 .first;
1506 }
1507
1508public:
1509 // See HaveGVs variable comment.
1510 ModuleSummaryIndex(bool HaveGVs, bool EnableSplitLTOUnit = false,
1511 bool UnifiedLTO = false)
1512 : TypeIdSaver(TypeIdSaverAlloc), HaveGVs(HaveGVs),
1513 EnableSplitLTOUnit(EnableSplitLTOUnit), UnifiedLTO(UnifiedLTO),
1514 Saver(Alloc) {}
1515
1516 // Current version for the module summary in bitcode files.
1517 // The BitcodeSummaryVersion should be bumped whenever we introduce changes
1518 // in the way some record are interpreted, like flags for instance.
1519 // Note that incrementing this may require changes in both BitcodeReader.cpp
1520 // and BitcodeWriter.cpp.
1521 static constexpr uint64_t BitcodeSummaryVersion = 12;
1522
1523 // Regular LTO module name for ASM writer
1524 static constexpr const char *getRegularLTOModuleName() {
1525 return "[Regular LTO]";
1526 }
1527
1528 bool haveGVs() const { return HaveGVs; }
1529
1530 LLVM_ABI uint64_t getFlags() const;
1531 LLVM_ABI void setFlags(uint64_t Flags);
1532
1533 uint64_t getBlockCount() const { return BlockCount; }
1534 void addBlockCount(uint64_t C) { BlockCount += C; }
1535 void setBlockCount(uint64_t C) { BlockCount = C; }
1536
1537 gvsummary_iterator begin() { return GlobalValueMap.begin(); }
1538 const_gvsummary_iterator begin() const { return GlobalValueMap.begin(); }
1539 gvsummary_iterator end() { return GlobalValueMap.end(); }
1540 const_gvsummary_iterator end() const { return GlobalValueMap.end(); }
1541 size_t size() const { return GlobalValueMap.size(); }
1542
1543 const std::vector<uint64_t> &stackIds() const { return StackIds; }
1544
1545 unsigned addOrGetStackIdIndex(uint64_t StackId) {
1546 auto Inserted = StackIdToIndex.insert({StackId, StackIds.size()});
1547 if (Inserted.second)
1548 StackIds.push_back(StackId);
1549 return Inserted.first->second;
1550 }
1551
1553 assert(StackIds.size() > Index);
1554 return StackIds[Index];
1555 }
1556
1557 // Facility to release memory from data structures only needed during index
1558 // construction (including while building combined index). Currently this only
1559 // releases the temporary map used while constructing a correspondence between
1560 // stack ids and their index in the StackIds vector. Mostly impactful when
1561 // building a large combined index.
1563 assert(StackIdToIndex.size() == StackIds.size());
1564 StackIdToIndex.clear();
1565 StackIds.shrink_to_fit();
1566 }
1567
1568 /// Convenience function for doing a DFS on a ValueInfo. Marks the function in
1569 /// the FunctionHasParent map.
1571 std::map<ValueInfo, bool> &FunctionHasParent) {
1572 if (!V.getSummaryList().size())
1573 return; // skip external functions that don't have summaries
1574
1575 // Mark discovered if we haven't yet
1576 auto S = FunctionHasParent.emplace(V, false);
1577
1578 // Stop if we've already discovered this node
1579 if (!S.second)
1580 return;
1581
1583 dyn_cast<FunctionSummary>(V.getSummaryList().front().get());
1584 assert(F != nullptr && "Expected FunctionSummary node");
1585
1586 for (const auto &C : F->calls()) {
1587 // Insert node if necessary
1588 auto S = FunctionHasParent.emplace(C.first, true);
1589
1590 // Skip nodes that we're sure have parents
1591 if (!S.second && S.first->second)
1592 continue;
1593
1594 if (S.second)
1595 discoverNodes(C.first, FunctionHasParent);
1596 else
1597 S.first->second = true;
1598 }
1599 }
1600
1601 // Calculate the callgraph root
1603 // Functions that have a parent will be marked in FunctionHasParent pair.
1604 // Once we've marked all functions, the functions in the map that are false
1605 // have no parent (so they're the roots)
1606 std::map<ValueInfo, bool> FunctionHasParent;
1607
1608 for (auto &S : *this) {
1609 // Skip external functions
1610 if (!S.second.SummaryList.size() ||
1611 !isa<FunctionSummary>(S.second.SummaryList.front().get()))
1612 continue;
1613 discoverNodes(ValueInfo(HaveGVs, &S), FunctionHasParent);
1614 }
1615
1617 // create edges to all roots in the Index
1618 for (auto &P : FunctionHasParent) {
1619 if (P.second)
1620 continue; // skip over non-root nodes
1621 Edges.push_back(std::make_pair(P.first, CalleeInfo{}));
1622 }
1623 return FunctionSummary::makeDummyFunctionSummary(std::move(Edges));
1624 }
1625
1627 return WithGlobalValueDeadStripping;
1628 }
1630 WithGlobalValueDeadStripping = true;
1631 }
1632
1633 bool withAttributePropagation() const { return WithAttributePropagation; }
1635 WithAttributePropagation = true;
1636 }
1637
1638 bool withDSOLocalPropagation() const { return WithDSOLocalPropagation; }
1639 void setWithDSOLocalPropagation() { WithDSOLocalPropagation = true; }
1640
1641 bool withWholeProgramVisibility() const { return WithWholeProgramVisibility; }
1642 void setWithWholeProgramVisibility() { WithWholeProgramVisibility = true; }
1643
1644 bool isReadOnly(const GlobalVarSummary *GVS) const {
1645 return WithAttributePropagation && GVS->maybeReadOnly();
1646 }
1647 bool isWriteOnly(const GlobalVarSummary *GVS) const {
1648 return WithAttributePropagation && GVS->maybeWriteOnly();
1649 }
1650
1651 bool withSupportsHotColdNew() const { return WithSupportsHotColdNew; }
1652 void setWithSupportsHotColdNew() { WithSupportsHotColdNew = true; }
1653
1655 return SkipModuleByDistributedBackend;
1656 }
1658 SkipModuleByDistributedBackend = true;
1659 }
1660
1661 bool enableSplitLTOUnit() const { return EnableSplitLTOUnit; }
1662 void setEnableSplitLTOUnit() { EnableSplitLTOUnit = true; }
1663
1664 bool hasUnifiedLTO() const { return UnifiedLTO; }
1665 void setUnifiedLTO() { UnifiedLTO = true; }
1666
1667 bool partiallySplitLTOUnits() const { return PartiallySplitLTOUnits; }
1668 void setPartiallySplitLTOUnits() { PartiallySplitLTOUnits = true; }
1669
1670 bool hasParamAccess() const { return HasParamAccess; }
1671
1672 bool isGlobalValueLive(const GlobalValueSummary *GVS) const {
1673 return !WithGlobalValueDeadStripping || GVS->isLive();
1674 }
1675 LLVM_ABI bool isGUIDLive(GlobalValue::GUID GUID) const;
1676
1677 /// Return a ValueInfo for the index value_type (convenient when iterating
1678 /// index).
1679 ValueInfo getValueInfo(const GlobalValueSummaryMapTy::value_type &R) const {
1680 return ValueInfo(HaveGVs, &R);
1681 }
1682
1683 /// Return a ValueInfo for GUID if it exists, otherwise return ValueInfo().
1685 auto I = GlobalValueMap.find(GUID);
1686 return ValueInfo(HaveGVs, I == GlobalValueMap.end() ? nullptr : &*I);
1687 }
1688
1689 /// Return a ValueInfo for \p GUID.
1691 return ValueInfo(HaveGVs, getOrInsertValuePtr(GUID));
1692 }
1693
1694 // Save a string in the Index. Use before passing Name to
1695 // getOrInsertValueInfo when the string isn't owned elsewhere (e.g. on the
1696 // module's Strtab).
1698
1699 /// Return a ValueInfo for \p GUID setting value \p Name.
1701 assert(!HaveGVs);
1702 auto VP = getOrInsertValuePtr(GUID);
1703 VP->second.U.Name = Name;
1704 return ValueInfo(HaveGVs, VP);
1705 }
1706
1707 /// Return a ValueInfo for \p GV and mark it as belonging to GV.
1709 assert(HaveGVs);
1710 auto VP = getOrInsertValuePtr(GV->getGUID());
1711 VP->second.U.GV = GV;
1712 return ValueInfo(HaveGVs, VP);
1713 }
1714
1715 /// Return the GUID for \p OriginalId in the OidGuidMap.
1717 const auto I = OidGuidMap.find(OriginalID);
1718 return I == OidGuidMap.end() ? 0 : I->second;
1719 }
1720
1721 CfiFunctionIndex &cfiFunctionDefs() { return CfiFunctionDefs; }
1722 const CfiFunctionIndex &cfiFunctionDefs() const { return CfiFunctionDefs; }
1723
1724 CfiFunctionIndex &cfiFunctionDecls() { return CfiFunctionDecls; }
1725 const CfiFunctionIndex &cfiFunctionDecls() const { return CfiFunctionDecls; }
1726
1727 /// Add a global value summary for a value.
1729 std::unique_ptr<GlobalValueSummary> Summary) {
1730 addGlobalValueSummary(getOrInsertValueInfo(&GV), std::move(Summary));
1731 }
1732
1733 /// Add a global value summary for a value of the given name.
1735 std::unique_ptr<GlobalValueSummary> Summary) {
1739 std::move(Summary));
1740 }
1741
1742 /// Add a global value summary for the given ValueInfo.
1744 std::unique_ptr<GlobalValueSummary> Summary) {
1745 if (const FunctionSummary *FS = dyn_cast<FunctionSummary>(Summary.get()))
1746 HasParamAccess |= !FS->paramAccesses().empty();
1747 addOriginalName(VI.getGUID(), Summary->getOriginalName());
1748 // Here we have a notionally const VI, but the value it points to is owned
1749 // by the non-const *this.
1750 const_cast<GlobalValueSummaryMapTy::value_type *>(VI.getRef())
1751 ->second.SummaryList.push_back(std::move(Summary));
1752 }
1753
1754 /// Add an original name for the value of the given GUID.
1756 GlobalValue::GUID OrigGUID) {
1757 if (OrigGUID == 0 || ValueGUID == OrigGUID)
1758 return;
1759 auto [It, Inserted] = OidGuidMap.try_emplace(OrigGUID, ValueGUID);
1760 if (!Inserted && It->second != ValueGUID)
1761 It->second = 0;
1762 }
1763
1764 /// Find the summary for ValueInfo \p VI in module \p ModuleId, or nullptr if
1765 /// not found.
1767 auto SummaryList = VI.getSummaryList();
1768 auto Summary =
1769 llvm::find_if(SummaryList,
1770 [&](const std::unique_ptr<GlobalValueSummary> &Summary) {
1771 return Summary->modulePath() == ModuleId;
1772 });
1773 if (Summary == SummaryList.end())
1774 return nullptr;
1775 return Summary->get();
1776 }
1777
1778 /// Find the summary for global \p GUID in module \p ModuleId, or nullptr if
1779 /// not found.
1781 StringRef ModuleId) const {
1782 auto CalleeInfo = getValueInfo(ValueGUID);
1783 if (!CalleeInfo)
1784 return nullptr; // This function does not have a summary
1785 return findSummaryInModule(CalleeInfo, ModuleId);
1786 }
1787
1788 /// Returns the first GlobalValueSummary for \p GV, asserting that there
1789 /// is only one if \p PerModuleIndex.
1791 bool PerModuleIndex = true) const {
1792 assert(GV.hasName() && "Can't get GlobalValueSummary for GV with no name");
1793 return getGlobalValueSummary(GV.getGUID(), PerModuleIndex);
1794 }
1795
1796 /// Returns the first GlobalValueSummary for \p ValueGUID, asserting that
1797 /// there
1798 /// is only one if \p PerModuleIndex.
1801 bool PerModuleIndex = true) const;
1802
1803 /// Table of modules, containing module hash and id.
1805 return ModulePathStringTable;
1806 }
1807
1808 /// Table of modules, containing hash and id.
1809 StringMap<ModuleHash> &modulePaths() { return ModulePathStringTable; }
1810
1811 /// Get the module SHA1 hash recorded for the given module path.
1812 const ModuleHash &getModuleHash(const StringRef ModPath) const {
1813 auto It = ModulePathStringTable.find(ModPath);
1814 assert(It != ModulePathStringTable.end() && "Module not registered");
1815 return It->second;
1816 }
1817
1818 /// Convenience method for creating a promoted global name
1819 /// for the given value name of a local, and its original module's ID.
1820 static std::string getGlobalNameForLocal(StringRef Name, ModuleHash ModHash) {
1821 std::string Suffix = utostr((uint64_t(ModHash[0]) << 32) |
1822 ModHash[1]); // Take the first 64 bits
1823 return getGlobalNameForLocal(Name, Suffix);
1824 }
1825
1826 static std::string getGlobalNameForLocal(StringRef Name, StringRef Suffix) {
1827 SmallString<256> NewName(Name);
1828 NewName += ".llvm.";
1829 NewName += Suffix;
1830 return std::string(NewName);
1831 }
1832
1833 /// Helper to obtain the unpromoted name for a global value (or the original
1834 /// name if not promoted). Split off the rightmost ".llvm.${hash}" suffix,
1835 /// because it is possible in certain clients (not clang at the moment) for
1836 /// two rounds of ThinLTO optimization and therefore promotion to occur.
1838 std::pair<StringRef, StringRef> Pair = Name.rsplit(".llvm.");
1839 return Pair.first;
1840 }
1841
1843
1844 /// Add a new module with the given \p Hash, mapped to the given \p
1845 /// ModID, and return a reference to the module.
1847 return &*ModulePathStringTable.insert({ModPath, Hash}).first;
1848 }
1849
1850 /// Return module entry for module with the given \p ModPath.
1852 auto It = ModulePathStringTable.find(ModPath);
1853 assert(It != ModulePathStringTable.end() && "Module not registered");
1854 return &*It;
1855 }
1856
1857 /// Return module entry for module with the given \p ModPath.
1858 const ModuleInfo *getModule(StringRef ModPath) const {
1859 auto It = ModulePathStringTable.find(ModPath);
1860 assert(It != ModulePathStringTable.end() && "Module not registered");
1861 return &*It;
1862 }
1863
1864 /// Check if the given Module has any functions available for exporting
1865 /// in the index. We consider any module present in the ModulePathStringTable
1866 /// to have exported functions.
1867 bool hasExportedFunctions(const Module &M) const {
1868 return ModulePathStringTable.count(M.getModuleIdentifier());
1869 }
1870
1871 const TypeIdSummaryMapTy &typeIds() const { return TypeIdMap; }
1872
1873 /// Return an existing or new TypeIdSummary entry for \p TypeId.
1874 /// This accessor can mutate the map and therefore should not be used in
1875 /// the ThinLTO backends.
1877 auto TidIter = TypeIdMap.equal_range(
1879 for (auto &[GUID, TypeIdPair] : make_range(TidIter))
1880 if (TypeIdPair.first == TypeId)
1881 return TypeIdPair.second;
1882 auto It =
1883 TypeIdMap.insert({GlobalValue::getGUIDAssumingExternalLinkage(TypeId),
1884 {TypeIdSaver.save(TypeId), TypeIdSummary()}});
1885 return It->second.second;
1886 }
1887
1888 /// This returns either a pointer to the type id summary (if present in the
1889 /// summary map) or null (if not present). This may be used when importing.
1891 auto TidIter = TypeIdMap.equal_range(
1893 for (const auto &[GUID, TypeIdPair] : make_range(TidIter))
1894 if (TypeIdPair.first == TypeId)
1895 return &TypeIdPair.second;
1896 return nullptr;
1897 }
1898
1900 return const_cast<TypeIdSummary *>(
1901 static_cast<const ModuleSummaryIndex *>(this)->getTypeIdSummary(
1902 TypeId));
1903 }
1904
1905 const auto &typeIdCompatibleVtableMap() const {
1906 return TypeIdCompatibleVtableMap;
1907 }
1908
1909 /// Return an existing or new TypeIdCompatibleVtableMap entry for \p TypeId.
1910 /// This accessor can mutate the map and therefore should not be used in
1911 /// the ThinLTO backends.
1914 return TypeIdCompatibleVtableMap[TypeIdSaver.save(TypeId)];
1915 }
1916
1917 /// For the given \p TypeId, this returns the TypeIdCompatibleVtableMap
1918 /// entry if present in the summary map. This may be used when importing.
1919 std::optional<TypeIdCompatibleVtableInfo>
1921 auto I = TypeIdCompatibleVtableMap.find(TypeId);
1922 if (I == TypeIdCompatibleVtableMap.end())
1923 return std::nullopt;
1924 return I->second;
1925 }
1926
1927 /// Collect for the given module the list of functions it defines
1928 /// (GUID -> Summary).
1929 LLVM_ABI void
1931 GVSummaryMapTy &GVSummaryMap) const;
1932
1933 /// Collect for each module the list of Summaries it defines (GUID ->
1934 /// Summary).
1935 template <class Map>
1936 void
1937 collectDefinedGVSummariesPerModule(Map &ModuleToDefinedGVSummaries) const {
1938 for (const auto &GlobalList : *this) {
1939 auto GUID = GlobalList.first;
1940 for (const auto &Summary : GlobalList.second.SummaryList) {
1941 ModuleToDefinedGVSummaries[Summary->modulePath()][GUID] = Summary.get();
1942 }
1943 }
1944 }
1945
1946 /// Print to an output stream.
1947 LLVM_ABI void print(raw_ostream &OS, bool IsForDebug = false) const;
1948
1949 /// Dump to stderr (for debugging).
1950 LLVM_ABI void dump() const;
1951
1952 /// Export summary to dot file for GraphViz.
1953 LLVM_ABI void
1955 const DenseSet<GlobalValue::GUID> &GUIDPreservedSymbols) const;
1956
1957 /// Print out strongly connected components for debugging.
1959
1960 /// Do the access attribute and DSOLocal propagation in combined index.
1961 LLVM_ABI void
1962 propagateAttributes(const DenseSet<GlobalValue::GUID> &PreservedSymbols);
1963
1964 /// Checks if we can import global variable from another module.
1966 bool AnalyzeRefs) const;
1967
1968 /// Same as above but checks whether the global var is importable as a
1969 /// declaration.
1971 bool AnalyzeRefs, bool &CanImportDecl) const;
1972};
1973
1974/// GraphTraits definition to build SCC for the index
1975template <> struct GraphTraits<ValueInfo> {
1978
1980 return P.first;
1981 }
1984 decltype(&valueInfoFromEdge)>;
1985
1988
1989 static NodeRef getEntryNode(ValueInfo V) { return V; }
1990
1992 if (!N.getSummaryList().size()) // handle external function
1993 return ChildIteratorType(
1994 FunctionSummary::ExternalNode.CallGraphEdgeList.begin(),
1995 &valueInfoFromEdge);
1997 cast<FunctionSummary>(N.getSummaryList().front()->getBaseObject());
1998 return ChildIteratorType(F->CallGraphEdgeList.begin(), &valueInfoFromEdge);
1999 }
2000
2002 if (!N.getSummaryList().size()) // handle external function
2003 return ChildIteratorType(
2004 FunctionSummary::ExternalNode.CallGraphEdgeList.end(),
2005 &valueInfoFromEdge);
2007 cast<FunctionSummary>(N.getSummaryList().front()->getBaseObject());
2008 return ChildIteratorType(F->CallGraphEdgeList.end(), &valueInfoFromEdge);
2009 }
2010
2012 if (!N.getSummaryList().size()) // handle external function
2013 return FunctionSummary::ExternalNode.CallGraphEdgeList.begin();
2014
2016 cast<FunctionSummary>(N.getSummaryList().front()->getBaseObject());
2017 return F->CallGraphEdgeList.begin();
2018 }
2019
2021 if (!N.getSummaryList().size()) // handle external function
2022 return FunctionSummary::ExternalNode.CallGraphEdgeList.end();
2023
2025 cast<FunctionSummary>(N.getSummaryList().front()->getBaseObject());
2026 return F->CallGraphEdgeList.end();
2027 }
2028
2029 static NodeRef edge_dest(EdgeRef E) { return E.first; }
2030};
2031
2032template <>
2035 std::unique_ptr<GlobalValueSummary> Root =
2036 std::make_unique<FunctionSummary>(I->calculateCallGraphRoot());
2037 GlobalValueSummaryInfo G(I->haveGVs());
2038 G.SummaryList.push_back(std::move(Root));
2039 static auto P =
2040 GlobalValueSummaryMapTy::value_type(GlobalValue::GUID(0), std::move(G));
2041 return ValueInfo(I->haveGVs(), &P);
2042 }
2043};
2044} // end namespace llvm
2045
2046#endif // LLVM_IR_MODULESUMMARYINDEX_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the StringMap class.
This file defines the BumpPtrAllocator interface.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define LLVM_PREFERRED_TYPE(T)
\macro LLVM_PREFERRED_TYPE Adjust type of bit-field in debug info.
Definition: Compiler.h:706
#define LLVM_ABI
Definition: Compiler.h:213
DXIL Finalize Linkage
Looks at all the uses of the given value Returns the Liveness deduced from the uses of this value Adds all uses that cause the result to be MaybeLive to MaybeLiveRetUses If the result is Live
This file defines the DenseMap class.
std::string Name
uint32_t Index
Module.h This file contains the declarations for the Module class.
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
#define G(x, y, z)
Definition: MD5.cpp:56
AllocType
#define P(N)
This file contains some templates that are useful if you are working with the STL at all.
raw_pwrite_stream & OS
This file defines the SmallString class.
This file defines the SmallVector class.
This file contains some functions that are useful when dealing with strings.
Value * RHS
Alias summary information.
GlobalValue::GUID getAliaseeGUID() const
const GlobalValueSummary & getAliasee() const
ValueInfo getAliaseeVI() const
static bool classof(const GlobalValueSummary *GVS)
Check if this is an alias summary.
AliasSummary(GVFlags Flags)
GlobalValueSummary & getAliasee()
void setAliasee(ValueInfo &AliaseeVI, GlobalValueSummary *Aliasee)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:67
GUIDIterator guid_end() const
size_t count(StringRef S) const
std::vector< StringRef > symbols() const
iterator_range< GUIDIterator > guids() const
iterator_range< NestedIterator > forGuid(GlobalValue::GUID GUID) const
GUIDIterator guid_begin() const
This class represents a range of values.
Definition: ConstantRange.h:47
This is an important base class in LLVM.
Definition: Constant.h:43
iterator find(const_arg_type_t< KeyT > Val)
Definition: DenseMap.h:177
std::pair< iterator, bool > try_emplace(KeyT &&Key, Ts &&...Args)
Definition: DenseMap.h:245
unsigned size() const
Definition: DenseMap.h:120
iterator end()
Definition: DenseMap.h:87
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Definition: DenseMap.h:230
Implements a dense probed hash-table based set.
Definition: DenseSet.h:263
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.
void addCallsite(CallsiteInfo &Callsite)
static FunctionSummary makeDummyFunctionSummary(SmallVectorImpl< FunctionSummary::EdgeTy > &&Edges)
Create an empty FunctionSummary (with specified call edges).
FunctionSummary(GVFlags Flags, unsigned NumInsts, FFlags FunFlags, SmallVectorImpl< ValueInfo > &&Refs, SmallVectorImpl< EdgeTy > &&CGEdges, std::vector< GlobalValue::GUID > TypeTests, std::vector< VFuncId > TypeTestAssumeVCalls, std::vector< VFuncId > TypeCheckedLoadVCalls, std::vector< ConstVCall > TypeTestAssumeConstVCalls, std::vector< ConstVCall > TypeCheckedLoadConstVCalls, std::vector< ParamAccess > Params, CallsitesTy CallsiteList, AllocsTy AllocList)
ArrayRef< VFuncId > type_test_assume_vcalls() const
Returns the list of virtual calls made by this function using llvm.assume(llvm.type....
ArrayRef< ConstVCall > type_test_assume_const_vcalls() const
Returns the list of virtual calls made by this function using llvm.assume(llvm.type....
std::pair< ValueInfo, CalleeInfo > EdgeTy
<CalleeValueInfo, CalleeInfo> call edge pair.
LLVM_ABI std::pair< unsigned, unsigned > specialRefCounts() const
SmallVector< EdgeTy, 0 > & mutableCalls()
ArrayRef< AllocInfo > allocs() const
ArrayRef< CallsiteInfo > callsites() const
void addTypeTest(GlobalValue::GUID Guid)
Add a type test to the summary.
ArrayRef< VFuncId > type_checked_load_vcalls() const
Returns the list of virtual calls made by this function using llvm.type.checked.load intrinsics that ...
void setParamAccesses(std::vector< ParamAccess > NewParams)
Sets the list of known uses of pointer parameters.
unsigned instCount() const
Get the instruction count recorded for this function.
const TypeIdInfo * getTypeIdInfo() const
ArrayRef< ConstVCall > type_checked_load_const_vcalls() const
Returns the list of virtual calls made by this function using llvm.type.checked.load intrinsics with ...
ArrayRef< EdgeTy > calls() const
Return the list of <CalleeValueInfo, CalleeInfo> pairs.
ArrayRef< ParamAccess > paramAccesses() const
Returns the list of known uses of pointer parameters.
CallsitesTy & mutableCallsites()
ForceSummaryHotnessType
Types for -force-summary-edges-cold debugging option.
FFlags fflags() const
Get function summary flags.
ArrayRef< GlobalValue::GUID > type_tests() const
Returns the list of type identifiers used by this function in llvm.type.test intrinsics other than by...
static bool classof(const GlobalValueSummary *GVS)
Check if this is a function summary.
Function and variable summary information to aid decisions and implementation of importing.
SummaryKind
Sububclass discriminator (for dyn_cast<> et al.)
GVFlags flags() const
Get the flags for this GlobalValue (see struct GVFlags).
StringRef modulePath() const
Get the path to the module containing this function.
GlobalValueSummary * getBaseObject()
If this is an alias summary, returns the summary of the aliased object (a global variable or function...
SummaryKind getSummaryKind() const
Which kind of summary subclass this is.
GlobalValue::GUID getOriginalName() const
Returns the hash of the original name, it is identical to the GUID for externally visible symbols,...
GlobalValue::VisibilityTypes getVisibility() const
ArrayRef< ValueInfo > refs() const
Return the list of values referenced by this global value definition.
void setLinkage(GlobalValue::LinkageTypes Linkage)
Sets the linkage to the value determined by global summary-based optimization.
void setVisibility(GlobalValue::VisibilityTypes Vis)
virtual ~GlobalValueSummary()=default
GlobalValueSummary::ImportKind importType() const
void setModulePath(StringRef ModPath)
Set the path to the module containing this function, for use in the combined index.
void setNotEligibleToImport()
Flag that this global value cannot be imported.
void setCanAutoHide(bool CanAutoHide)
GlobalValueSummary(SummaryKind K, GVFlags Flags, SmallVectorImpl< ValueInfo > &&Refs)
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.
void setImportKind(ImportKind IK)
void setOriginalName(GlobalValue::GUID Name)
Initialize the original name hash in this summary.
static LLVM_ABI GUID getGUIDAssumingExternalLinkage(StringRef GlobalName)
Return a 64-bit global unique ID constructed from the name of a global symbol.
Definition: Globals.cpp:77
uint64_t GUID
Declare a type to represent a global unique identifier for a global value.
Definition: GlobalValue.h:577
static StringRef dropLLVMManglingEscape(StringRef Name)
If the given string begins with the GlobalValue name mangling escape character '\1',...
Definition: GlobalValue.h:569
GUID getGUID() const
Return a 64-bit global unique ID constructed from global value name (i.e.
Definition: GlobalValue.h:600
VisibilityTypes
An enumeration for the kinds of visibility of global values.
Definition: GlobalValue.h:67
@ DefaultVisibility
The GV is visible.
Definition: GlobalValue.h:68
LinkageTypes
An enumeration for the kinds of linkage for global values.
Definition: GlobalValue.h:52
@ AvailableExternallyLinkage
Available for inspection, not emission.
Definition: GlobalValue.h:54
Global variable summary information to aid decisions and implementation of importing.
void setVCallVisibility(GlobalObject::VCallVisibility Vis)
struct llvm::GlobalVarSummary::GVarFlags VarFlags
GVarFlags varflags() const
ArrayRef< VirtFuncOffset > vTableFuncs() const
GlobalVarSummary(GVFlags Flags, GVarFlags VarFlags, SmallVectorImpl< ValueInfo > &&Refs)
GlobalObject::VCallVisibility getVCallVisibility() const
static bool classof(const GlobalValueSummary *GVS)
Check if this is a global variable summary.
void setVTableFuncs(VTableFuncList Funcs)
Class to hold module path string table and global value map, and encapsulate methods for operating on...
TypeIdSummary & getOrInsertTypeIdSummary(StringRef TypeId)
Return an existing or new TypeIdSummary entry for TypeId.
std::optional< TypeIdCompatibleVtableInfo > getTypeIdCompatibleVtableSummary(StringRef TypeId) const
For the given TypeId, this returns the TypeIdCompatibleVtableMap entry if present in the summary map.
gvsummary_iterator end()
void addGlobalValueSummary(ValueInfo VI, std::unique_ptr< GlobalValueSummary > Summary)
Add a global value summary for the given ValueInfo.
ModulePathStringTableTy::value_type ModuleInfo
ValueInfo getOrInsertValueInfo(GlobalValue::GUID GUID)
Return a ValueInfo for GUID.
bool withGlobalValueDeadStripping() const
static void discoverNodes(ValueInfo V, std::map< ValueInfo, bool > &FunctionHasParent)
Convenience function for doing a DFS on a ValueInfo.
StringRef saveString(StringRef String)
const TypeIdSummaryMapTy & typeIds() const
static StringRef getOriginalNameBeforePromote(StringRef Name)
Helper to obtain the unpromoted name for a global value (or the original name if not promoted).
const TypeIdSummary * getTypeIdSummary(StringRef TypeId) const
This returns either a pointer to the type id summary (if present in the summary map) or null (if not ...
LLVM_ABI bool isGUIDLive(GlobalValue::GUID GUID) const
gvsummary_iterator begin()
const_gvsummary_iterator end() const
bool isReadOnly(const GlobalVarSummary *GVS) const
LLVM_ABI void setFlags(uint64_t Flags)
const_gvsummary_iterator begin() const
CfiFunctionIndex & cfiFunctionDecls()
bool isWriteOnly(const GlobalVarSummary *GVS) const
const std::vector< uint64_t > & stackIds() const
GlobalValueSummary * findSummaryInModule(GlobalValue::GUID ValueGUID, StringRef ModuleId) const
Find the summary for global GUID in module ModuleId, or nullptr if not found.
ValueInfo getValueInfo(const GlobalValueSummaryMapTy::value_type &R) const
Return a ValueInfo for the index value_type (convenient when iterating index).
const ModuleHash & getModuleHash(const StringRef ModPath) const
Get the module SHA1 hash recorded for the given module path.
static constexpr const char * getRegularLTOModuleName()
const CfiFunctionIndex & cfiFunctionDefs() const
void addGlobalValueSummary(StringRef ValueName, std::unique_ptr< GlobalValueSummary > Summary)
Add a global value summary for a value of the given name.
ModuleSummaryIndex(bool HaveGVs, bool EnableSplitLTOUnit=false, bool UnifiedLTO=false)
LLVM_ABI void collectDefinedFunctionsForModule(StringRef ModulePath, GVSummaryMapTy &GVSummaryMap) const
Collect for the given module the list of functions it defines (GUID -> Summary).
const auto & typeIdCompatibleVtableMap() const
LLVM_ABI void dumpSCCs(raw_ostream &OS)
Print out strongly connected components for debugging.
bool isGlobalValueLive(const GlobalValueSummary *GVS) const
const ModuleInfo * getModule(StringRef ModPath) const
Return module entry for module with the given ModPath.
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.
LLVM_ABI void dump() const
Dump to stderr (for debugging).
Definition: AsmWriter.cpp:5517
ModuleInfo * addModule(StringRef ModPath, ModuleHash Hash=ModuleHash{{0}})
Add a new module with the given Hash, mapped to the given ModID, and return a reference to the module...
void collectDefinedGVSummariesPerModule(Map &ModuleToDefinedGVSummaries) const
Collect for each module the list of Summaries it defines (GUID -> Summary).
void addGlobalValueSummary(const GlobalValue &GV, std::unique_ptr< GlobalValueSummary > Summary)
Add a global value summary for a value.
bool hasExportedFunctions(const Module &M) const
Check if the given Module has any functions available for exporting in the index.
static std::string getGlobalNameForLocal(StringRef Name, ModuleHash ModHash)
Convenience method for creating a promoted global name for the given value name of a local,...
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.
uint64_t getStackIdAtIndex(unsigned Index) const
StringMap< ModuleHash > & modulePaths()
Table of modules, containing hash and id.
LLVM_ABI void print(raw_ostream &OS, bool IsForDebug=false) const
Print to an output stream.
Definition: AsmWriter.cpp:5444
bool skipModuleByDistributedBackend() const
CfiFunctionIndex & cfiFunctionDefs()
ValueInfo getOrInsertValueInfo(const GlobalValue *GV)
Return a ValueInfo for GV and mark it as belonging to GV.
GlobalValueSummary * findSummaryInModule(ValueInfo VI, StringRef ModuleId) const
Find the summary for ValueInfo VI in module ModuleId, or nullptr if not found.
ValueInfo getValueInfo(GlobalValue::GUID GUID) const
Return a ValueInfo for GUID if it exists, otherwise return ValueInfo().
LLVM_ABI uint64_t getFlags() const
unsigned addOrGetStackIdIndex(uint64_t StackId)
GlobalValue::GUID getGUIDFromOriginalID(GlobalValue::GUID OriginalID) const
Return the GUID for OriginalId in the OidGuidMap.
GlobalValueSummary * getGlobalValueSummary(const GlobalValue &GV, bool PerModuleIndex=true) const
Returns the first GlobalValueSummary for GV, asserting that there is only one if PerModuleIndex.
ModuleInfo * getModule(StringRef ModPath)
Return module entry for module with the given ModPath.
ValueInfo getOrInsertValueInfo(GlobalValue::GUID GUID, StringRef Name)
Return a ValueInfo for GUID setting value Name.
LLVM_ABI bool canImportGlobalVar(const GlobalValueSummary *S, bool AnalyzeRefs) const
Checks if we can import global variable from another module.
static std::string getGlobalNameForLocal(StringRef Name, StringRef Suffix)
void addOriginalName(GlobalValue::GUID ValueGUID, GlobalValue::GUID OrigGUID)
Add an original name for the value of the given GUID.
FunctionSummary calculateCallGraphRoot()
const CfiFunctionIndex & cfiFunctionDecls() const
TypeIdSummary * getTypeIdSummary(StringRef TypeId)
TypeIdCompatibleVtableInfo & getOrInsertTypeIdCompatibleVtableSummary(StringRef TypeId)
Return an existing or new TypeIdCompatibleVtableMap entry for TypeId.
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
PointerIntPair - This class implements a pair of a pointer and small integer.
void setPointer(PointerTy PtrVal) &
IntType getInt() const
void setInt(IntType IntVal) &
PointerTy getPointer() const
Simple representation of a scaled number.
Definition: ScaledNumber.h:496
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition: SmallString.h:26
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:574
void push_back(const T &Elt)
Definition: SmallVector.h:414
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1197
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
iterator end()
Definition: StringMap.h:224
iterator find(StringRef Key)
Definition: StringMap.h:237
size_type count(StringRef Key) const
count - Return 1 if the element is in the map, 0 otherwise.
Definition: StringMap.h:280
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
Definition: StringMap.h:312
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
Saves strings in the provided stable storage and returns a StringRef with a stable character pointer.
Definition: StringSaver.h:22
StringRef save(const char *S)
Definition: StringSaver.h:31
Saves strings in the provided stable storage and returns a StringRef with a stable character pointer.
Definition: StringSaver.h:45
StringRef save(const char *S)
Definition: StringSaver.h:53
A Use represents the edge between a Value definition and its users.
Definition: Use.h:35
bool hasName() const
Definition: Value.h:262
CRTP base class for adapting an iterator to a different type.
Definition: iterator.h:237
A range adaptor for a pair of iterators.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:662
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ Cold
Attempts to make code in the caller as efficient as possible under the assumption that the call is no...
Definition: CallingConv.h:47
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
GlobalValueSummaryMapTy::iterator gvsummary_iterator
@ Offset
Definition: DWP.cpp:477
bool operator<(int64_t V1, const APSInt &V2)
Definition: APSInt.h:362
hash_code hash_value(const FixedPointSemantics &Val)
Definition: APFixedPoint.h:137
InterleavedRange< Range > interleaved(const Range &R, StringRef Separator=", ", StringRef Prefix="", StringRef Suffix="")
Output range R as a sequence of interleaved elements.
const char * getHotnessName(CalleeInfo::HotnessType HT)
bool operator!=(uint64_t V1, const APInt &V2)
Definition: APInt.h:2113
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
Definition: STLExtras.h:2155
bool operator==(const AddressRangeValuePair &LHS, const AddressRangeValuePair &RHS)
std::vector< VirtFuncOffset > VTableFuncList
List of functions referenced by a particular vtable definition.
@ None
Definition: CodeGenData.h:107
std::vector< std::unique_ptr< GlobalValueSummary > > GlobalValueSummaryList
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
std::unordered_set< GlobalValueSummary * > GVSummaryPtrSet
A set of global value summary pointers.
GlobalValueSummaryMapTy::const_iterator const_gvsummary_iterator
Type used for iterating through the global value summary map.
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
Definition: APFixedPoint.h:312
std::map< std::string, GVSummaryMapTy, std::less<> > ModuleToSummariesForIndexTy
Map of a module name to the GUIDs and summaries we will import from that module.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1886
std::multimap< GlobalValue::GUID, std::pair< StringRef, TypeIdSummary > > TypeIdSummaryMapTy
Map of a type GUID to type id string and summary (multimap used in case of GUID conflicts).
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1777
std::array< uint32_t, 5 > ModuleHash
160 bits SHA1
std::map< GlobalValue::GUID, GlobalValueSummaryInfo > GlobalValueSummaryMapTy
Map from global value GUID to corresponding summary structures.
std::vector< TypeIdOffsetVtableInfo > TypeIdCompatibleVtableInfo
List of vtable definitions decorated by a particular type identifier, and their corresponding offsets...
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:856
#define N
Summary of memprof metadata on allocations.
AllocInfo(std::vector< MIBInfo > MIBs)
AllocInfo(SmallVector< uint8_t > Versions, std::vector< MIBInfo > MIBs)
std::vector< std::vector< ContextTotalSize > > ContextSizeInfos
SmallVector< uint8_t > Versions
std::vector< MIBInfo > MIBs
Class to accumulate and hold information about a callee.
static constexpr uint64_t MaxRelBlockFreq
bool hasTailCall() const
void updateHotness(const HotnessType OtherHotness)
CalleeInfo(HotnessType Hotness, bool HasTC, uint64_t RelBF)
HotnessType getHotness() const
static constexpr int32_t ScaleShift
void setHasTailCall(const bool HasTC)
void updateRelBlockFreq(uint64_t BlockFreq, uint64_t EntryFreq)
Update RelBlockFreq from BlockFreq and EntryFreq.
static constexpr unsigned RelBlockFreqBits
The value stored in RelBlockFreq has to be interpreted as the digits of a scaled number with a scale ...
Summary of memprof callsite metadata.
SmallVector< unsigned > StackIdIndices
SmallVector< unsigned > Clones
CallsiteInfo(ValueInfo Callee, SmallVector< unsigned > StackIdIndices)
CallsiteInfo(ValueInfo Callee, SmallVector< unsigned > Clones, SmallVector< unsigned > StackIdIndices)
static FunctionSummary::ConstVCall getEmptyKey()
static FunctionSummary::ConstVCall getTombstoneKey()
static unsigned getHashValue(FunctionSummary::ConstVCall I)
static bool isEqual(FunctionSummary::ConstVCall L, FunctionSummary::ConstVCall R)
static FunctionSummary::VFuncId getEmptyKey()
static bool isEqual(FunctionSummary::VFuncId L, FunctionSummary::VFuncId R)
static FunctionSummary::VFuncId getTombstoneKey()
static unsigned getHashValue(FunctionSummary::VFuncId I)
static bool isEqual(ValueInfo L, ValueInfo R)
static bool isSpecialKey(ValueInfo V)
static unsigned getHashValue(ValueInfo I)
An information struct used to provide DenseMap with the various necessary components for a given valu...
Definition: DenseMapInfo.h:54
A specification for a virtual function call with all constant integer arguments.
Flags specific to function summaries.
FFlags & operator&=(const FFlags &RHS)
Describes the use of a value in a call instruction, specifying the call's target, the value's paramet...
Call(uint64_t ParamNo, ValueInfo Callee, const ConstantRange &Offsets)
Describes the uses of a parameter by the function.
ParamAccess(uint64_t ParamNo, const ConstantRange &Use)
std::vector< Call > Calls
In the per-module summary, it summarizes the byte offset applied to each pointer parameter before pas...
static constexpr uint32_t RangeWidth
All type identifier related information.
std::vector< ConstVCall > TypeCheckedLoadConstVCalls
std::vector< VFuncId > TypeCheckedLoadVCalls
std::vector< ConstVCall > TypeTestAssumeConstVCalls
List of virtual calls made by this function using (respectively) llvm.assume(llvm....
std::vector< GlobalValue::GUID > TypeTests
List of type identifiers used by this function in llvm.type.test intrinsics referenced by something o...
std::vector< VFuncId > TypeTestAssumeVCalls
List of virtual calls made by this function using (respectively) llvm.assume(llvm....
An "identifier" for a virtual function.
GlobalValueSummaryList SummaryList
List of global value summary structures for a particular value held in the GlobalValueMap.
union llvm::GlobalValueSummaryInfo::NameOrGV U
Group flags (Linkage, NotEligibleToImport, etc.) as a bitfield.
GVFlags(GlobalValue::LinkageTypes Linkage, GlobalValue::VisibilityTypes Visibility, bool NotEligibleToImport, bool Live, bool IsLocal, bool CanAutoHide, ImportKind ImportType)
Convenience Constructors.
unsigned DSOLocal
Indicates that the linker resolved the symbol to a definition from within the same linkage unit.
unsigned CanAutoHide
In the per-module summary, indicates that the global value is linkonce_odr and global unnamed addr (s...
unsigned ImportType
This field is written by the ThinLTO indexing step to postlink combined summary.
unsigned NotEligibleToImport
Indicate if the global value cannot be imported (e.g.
unsigned Linkage
The linkage type of the associated global value.
unsigned Visibility
Indicates the visibility.
unsigned Live
In per-module summary, indicate that the global value must be considered a live root for index-based ...
GVarFlags(bool ReadOnly, bool WriteOnly, bool Constant, GlobalObject::VCallVisibility Vis)
static NodeRef getEntryNode(ModuleSummaryIndex *I)
static NodeRef valueInfoFromEdge(FunctionSummary::EdgeTy &P)
static ChildIteratorType child_begin(NodeRef N)
static ChildEdgeIteratorType child_edge_begin(NodeRef N)
static NodeRef edge_dest(EdgeRef E)
static NodeRef getEntryNode(ValueInfo V)
static ChildIteratorType child_end(NodeRef N)
static ChildEdgeIteratorType child_edge_end(NodeRef N)
FunctionSummary::EdgeTy & EdgeRef
Summary of a single MIB in a memprof metadata on allocations.
MIBInfo(AllocationType AllocType, SmallVector< unsigned > StackIdIndices)
AllocationType AllocType
SmallVector< unsigned > StackIdIndices
The following data structures summarize type metadata information.
TypeIdOffsetVtableInfo(uint64_t Offset, ValueInfo VI)
std::map< uint64_t, WholeProgramDevirtResolution > WPDRes
Mapping from byte offset to whole-program devirt resolution for that (typeid, byte offset) pair.
TypeTestResolution TTRes
Kind
Specifies which kind of type check we should emit for this byte array.
@ Unknown
Unknown (analysis not performed, don't lower)
@ Single
Single element (last example in "Short Inline Bit Vectors")
@ Inline
Inlined bit vector ("Short Inline Bit Vectors")
@ Unsat
Unsatisfiable type (i.e. no global has this type metadata)
@ AllOnes
All-ones bit vector ("Eliminating Bit Vector Checks for All-Ones Bit Vectors")
@ ByteArray
Test a byte array (first example)
unsigned SizeM1BitWidth
Range of size-1 expressed as a bit width.
enum llvm::TypeTestResolution::Kind TheKind
Struct that holds a reference to a particular GUID in a global value summary.
PointerIntPair< const GlobalValueSummaryMapTy::value_type *, 3, int > RefAndFlags
LLVM_ABI GlobalValue::VisibilityTypes getELFVisibility() const
Returns the most constraining visibility among summaries.
bool isValidAccessSpecifier() const
const GlobalValueSummaryMapTy::value_type * getRef() const
ArrayRef< std::unique_ptr< GlobalValueSummary > > getSummaryList() const
StringRef name() const
bool isWriteOnly() const
const GlobalValue * getValue() const
bool hasName() const
ValueInfo(bool HaveGVs, const GlobalValueSummaryMapTy::value_type *R)
bool isReadOnly() const
LLVM_ABI bool canAutoHide() const
Checks if all copies are eligible for auto-hiding (have flag set).
unsigned getAccessSpecifier() const
ValueInfo()=default
LLVM_ABI bool isDSOLocal(bool WithDSOLocalPropagation=false) const
Checks if all summaries are DSO local (have the flag set).
GlobalValue::GUID getGUID() const
bool haveGVs() const
The ValueInfo and offset for a function within a vtable definition initializer array.
VirtFuncOffset(ValueInfo VI, uint64_t Offset)
@ UniformRetVal
Uniform return value optimization.
@ VirtualConstProp
Virtual constant propagation.
@ UniqueRetVal
Unique return value optimization.
@ Indir
Just do a regular virtual call.
uint64_t Info
Additional information for the resolution:
enum llvm::WholeProgramDevirtResolution::ByArg::Kind TheKind
enum llvm::WholeProgramDevirtResolution::Kind TheKind
std::map< std::vector< uint64_t >, ByArg > ResByArg
Resolutions for calls with all constant integer arguments (excluding the first argument,...
@ SingleImpl
Single implementation devirtualization.
@ Indir
Just do a regular virtual call.
@ BranchFunnel
When retpoline mitigation is enabled, use a branch funnel that is defined in the merged module.
const GlobalValue * GV
The GlobalValue corresponding to this summary.
StringRef Name
Summary string representation.