LLVM  10.0.0svn
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"
21 #include "llvm/ADT/SmallString.h"
22 #include "llvm/ADT/StringExtras.h"
23 #include "llvm/ADT/StringMap.h"
24 #include "llvm/ADT/StringRef.h"
25 #include "llvm/ADT/TinyPtrVector.h"
26 #include "llvm/IR/GlobalValue.h"
27 #include "llvm/IR/Module.h"
28 #include "llvm/Support/Allocator.h"
32 #include <algorithm>
33 #include <array>
34 #include <cassert>
35 #include <cstddef>
36 #include <cstdint>
37 #include <map>
38 #include <memory>
39 #include <set>
40 #include <string>
41 #include <utility>
42 #include <vector>
43 
44 namespace llvm {
45 
46 namespace yaml {
47 
48 template <typename T> struct MappingTraits;
49 
50 } // end namespace yaml
51 
52 /// Class to accumulate and hold information about a callee.
53 struct CalleeInfo {
54  enum class HotnessType : uint8_t {
55  Unknown = 0,
56  Cold = 1,
57  None = 2,
58  Hot = 3,
59  Critical = 4
60  };
61 
62  // The size of the bit-field might need to be adjusted if more values are
63  // added to HotnessType enum.
65 
66  /// The value stored in RelBlockFreq has to be interpreted as the digits of
67  /// a scaled number with a scale of \p -ScaleShift.
69  static constexpr int32_t ScaleShift = 8;
70  static constexpr uint64_t MaxRelBlockFreq = (1 << 29) - 1;
71 
73  : Hotness(static_cast<uint32_t>(HotnessType::Unknown)), RelBlockFreq(0) {}
74  explicit CalleeInfo(HotnessType Hotness, uint64_t RelBF)
75  : Hotness(static_cast<uint32_t>(Hotness)), RelBlockFreq(RelBF) {}
76 
77  void updateHotness(const HotnessType OtherHotness) {
78  Hotness = std::max(Hotness, static_cast<uint32_t>(OtherHotness));
79  }
80 
81  HotnessType getHotness() const { return HotnessType(Hotness); }
82 
83  /// Update \p RelBlockFreq from \p BlockFreq and \p EntryFreq
84  ///
85  /// BlockFreq is divided by EntryFreq and added to RelBlockFreq. To represent
86  /// fractional values, the result is represented as a fixed point number with
87  /// scale of -ScaleShift.
88  void updateRelBlockFreq(uint64_t BlockFreq, uint64_t EntryFreq) {
89  if (EntryFreq == 0)
90  return;
92  Scaled64 Temp(BlockFreq, ScaleShift);
93  Temp /= Scaled64::get(EntryFreq);
94 
95  uint64_t Sum =
96  SaturatingAdd<uint64_t>(Temp.toInt<uint64_t>(), RelBlockFreq);
97  Sum = std::min(Sum, uint64_t(MaxRelBlockFreq));
98  RelBlockFreq = static_cast<uint32_t>(Sum);
99  }
100 };
101 
102 inline const char *getHotnessName(CalleeInfo::HotnessType HT) {
103  switch (HT) {
105  return "unknown";
107  return "cold";
109  return "none";
111  return "hot";
113  return "critical";
114  }
115  llvm_unreachable("invalid hotness");
116 }
117 
118 class GlobalValueSummary;
119 
120 using GlobalValueSummaryList = std::vector<std::unique_ptr<GlobalValueSummary>>;
121 
122 struct alignas(8) GlobalValueSummaryInfo {
123  union NameOrGV {
124  NameOrGV(bool HaveGVs) {
125  if (HaveGVs)
126  GV = nullptr;
127  else
128  Name = "";
129  }
130 
131  /// The GlobalValue corresponding to this summary. This is only used in
132  /// per-module summaries and when the IR is available. E.g. when module
133  /// analysis is being run, or when parsing both the IR and the summary
134  /// from assembly.
135  const GlobalValue *GV;
136 
137  /// Summary string representation. This StringRef points to BC module
138  /// string table and is valid until module data is stored in memory.
139  /// This is guaranteed to happen until runThinLTOBackend function is
140  /// called, so it is safe to use this field during thin link. This field
141  /// is only valid if summary index was loaded from BC file.
143  } U;
144 
145  GlobalValueSummaryInfo(bool HaveGVs) : U(HaveGVs) {}
146 
147  /// List of global value summary structures for a particular value held
148  /// in the GlobalValueMap. Requires a vector in the case of multiple
149  /// COMDAT values of the same name.
151 };
152 
153 /// Map from global value GUID to corresponding summary structures. Use a
154 /// std::map rather than a DenseMap so that pointers to the map's value_type
155 /// (which are used by ValueInfo) are not invalidated by insertion. Also it will
156 /// likely incur less overhead, as the value type is not very small and the size
157 /// of the map is unknown, resulting in inefficiencies due to repeated
158 /// insertions and resizing.
160  std::map<GlobalValue::GUID, GlobalValueSummaryInfo>;
161 
162 /// Struct that holds a reference to a particular GUID in a global value
163 /// summary.
164 struct ValueInfo {
165  enum Flags { HaveGV = 1, ReadOnly = 2, WriteOnly = 4 };
168 
169  ValueInfo() = default;
170  ValueInfo(bool HaveGVs, const GlobalValueSummaryMapTy::value_type *R) {
171  RefAndFlags.setPointer(R);
172  RefAndFlags.setInt(HaveGVs);
173  }
174 
175  operator bool() const { return getRef(); }
176 
177  GlobalValue::GUID getGUID() const { return getRef()->first; }
178  const GlobalValue *getValue() const {
179  assert(haveGVs());
180  return getRef()->second.U.GV;
181  }
182 
184  return getRef()->second.SummaryList;
185  }
186 
187  StringRef name() const {
188  return haveGVs() ? getRef()->second.U.GV->getName()
189  : getRef()->second.U.Name;
190  }
191 
192  bool haveGVs() const { return RefAndFlags.getInt() & HaveGV; }
193  bool isReadOnly() const {
194  assert(isValidAccessSpecifier());
195  return RefAndFlags.getInt() & ReadOnly;
196  }
197  bool isWriteOnly() const {
198  assert(isValidAccessSpecifier());
199  return RefAndFlags.getInt() & WriteOnly;
200  }
201  unsigned getAccessSpecifier() const {
202  assert(isValidAccessSpecifier());
203  return RefAndFlags.getInt() & (ReadOnly | WriteOnly);
204  }
205  bool isValidAccessSpecifier() const {
206  unsigned BadAccessMask = ReadOnly | WriteOnly;
207  return (RefAndFlags.getInt() & BadAccessMask) != BadAccessMask;
208  }
209  void setReadOnly() {
210  // We expect ro/wo attribute to set only once during
211  // ValueInfo lifetime.
212  assert(getAccessSpecifier() == 0);
213  RefAndFlags.setInt(RefAndFlags.getInt() | ReadOnly);
214  }
215  void setWriteOnly() {
216  assert(getAccessSpecifier() == 0);
217  RefAndFlags.setInt(RefAndFlags.getInt() | WriteOnly);
218  }
219 
220  const GlobalValueSummaryMapTy::value_type *getRef() const {
221  return RefAndFlags.getPointer();
222  }
223 
224  bool isDSOLocal() const;
225 
226  /// Checks if all copies are eligible for auto-hiding (have flag set).
227  bool canAutoHide() const;
228 };
229 
231  OS << VI.getGUID();
232  if (!VI.name().empty())
233  OS << " (" << VI.name() << ")";
234  return OS;
235 }
236 
237 inline bool operator==(const ValueInfo &A, const ValueInfo &B) {
238  assert(A.getRef() && B.getRef() &&
239  "Need ValueInfo with non-null Ref for comparison");
240  return A.getRef() == B.getRef();
241 }
242 
243 inline bool operator!=(const ValueInfo &A, const ValueInfo &B) {
244  assert(A.getRef() && B.getRef() &&
245  "Need ValueInfo with non-null Ref for comparison");
246  return A.getRef() != B.getRef();
247 }
248 
249 inline bool operator<(const ValueInfo &A, const ValueInfo &B) {
250  assert(A.getRef() && B.getRef() &&
251  "Need ValueInfo with non-null Ref to compare GUIDs");
252  return A.getGUID() < B.getGUID();
253 }
254 
255 template <> struct DenseMapInfo<ValueInfo> {
256  static inline ValueInfo getEmptyKey() {
257  return ValueInfo(false, (GlobalValueSummaryMapTy::value_type *)-8);
258  }
259 
260  static inline ValueInfo getTombstoneKey() {
261  return ValueInfo(false, (GlobalValueSummaryMapTy::value_type *)-16);
262  }
263 
264  static inline bool isSpecialKey(ValueInfo V) {
265  return V == getTombstoneKey() || V == getEmptyKey();
266  }
267 
268  static bool isEqual(ValueInfo L, ValueInfo R) {
269  // We are not supposed to mix ValueInfo(s) with different HaveGVs flag
270  // in a same container.
271  assert(isSpecialKey(L) || isSpecialKey(R) || (L.haveGVs() == R.haveGVs()));
272  return L.getRef() == R.getRef();
273  }
274  static unsigned getHashValue(ValueInfo I) { return (uintptr_t)I.getRef(); }
275 };
276 
277 /// Function and variable summary information to aid decisions and
278 /// implementation of importing.
280 public:
281  /// Sububclass discriminator (for dyn_cast<> et al.)
282  enum SummaryKind : unsigned { AliasKind, FunctionKind, GlobalVarKind };
283 
284  /// Group flags (Linkage, NotEligibleToImport, etc.) as a bitfield.
285  struct GVFlags {
286  /// The linkage type of the associated global value.
287  ///
288  /// One use is to flag values that have local linkage types and need to
289  /// have module identifier appended before placing into the combined
290  /// index, to disambiguate from other values with the same name.
291  /// In the future this will be used to update and optimize linkage
292  /// types based on global summary-based analysis.
293  unsigned Linkage : 4;
294 
295  /// Indicate if the global value cannot be imported (e.g. it cannot
296  /// be renamed or references something that can't be renamed).
297  unsigned NotEligibleToImport : 1;
298 
299  /// In per-module summary, indicate that the global value must be considered
300  /// a live root for index-based liveness analysis. Used for special LLVM
301  /// values such as llvm.global_ctors that the linker does not know about.
302  ///
303  /// In combined summary, indicate that the global value is live.
304  unsigned Live : 1;
305 
306  /// Indicates that the linker resolved the symbol to a definition from
307  /// within the same linkage unit.
308  unsigned DSOLocal : 1;
309 
310  /// In the per-module summary, indicates that the global value is
311  /// linkonce_odr and global unnamed addr (so eligible for auto-hiding
312  /// via hidden visibility). In the combined summary, indicates that the
313  /// prevailing linkonce_odr copy can be auto-hidden via hidden visibility
314  /// when it is upgraded to weak_odr in the backend. This is legal when
315  /// all copies are eligible for auto-hiding (i.e. all copies were
316  /// linkonce_odr global unnamed addr. If any copy is not (e.g. it was
317  /// originally weak_odr, we cannot auto-hide the prevailing copy as it
318  /// means the symbol was externally visible.
319  unsigned CanAutoHide : 1;
320 
321  /// Convenience Constructors
323  bool NotEligibleToImport, bool Live, bool IsLocal,
324  bool CanAutoHide)
325  : Linkage(Linkage), NotEligibleToImport(NotEligibleToImport),
326  Live(Live), DSOLocal(IsLocal), CanAutoHide(CanAutoHide) {}
327  };
328 
329 private:
330  /// Kind of summary for use in dyn_cast<> et al.
332 
333  GVFlags Flags;
334 
335  /// This is the hash of the name of the symbol in the original file. It is
336  /// identical to the GUID for global symbols, but differs for local since the
337  /// GUID includes the module level id in the hash.
338  GlobalValue::GUID OriginalName = 0;
339 
340  /// Path of module IR containing value's definition, used to locate
341  /// module during importing.
342  ///
343  /// This is only used during parsing of the combined index, or when
344  /// parsing the per-module index for creation of the combined summary index,
345  /// not during writing of the per-module index which doesn't contain a
346  /// module path string table.
347  StringRef ModulePath;
348 
349  /// List of values referenced by this global value's definition
350  /// (either by the initializer of a global variable, or referenced
351  /// from within a function). This does not include functions called, which
352  /// are listed in the derived FunctionSummary object.
353  std::vector<ValueInfo> RefEdgeList;
354 
355 protected:
356  GlobalValueSummary(SummaryKind K, GVFlags Flags, std::vector<ValueInfo> Refs)
357  : Kind(K), Flags(Flags), RefEdgeList(std::move(Refs)) {
358  assert((K != AliasKind || Refs.empty()) &&
359  "Expect no references for AliasSummary");
360  }
361 
362 public:
363  virtual ~GlobalValueSummary() = default;
364 
365  /// Returns the hash of the original name, it is identical to the GUID for
366  /// externally visible symbols, but not for local ones.
367  GlobalValue::GUID getOriginalName() const { return OriginalName; }
368 
369  /// Initialize the original name hash in this summary.
370  void setOriginalName(GlobalValue::GUID Name) { OriginalName = Name; }
371 
372  /// Which kind of summary subclass this is.
373  SummaryKind getSummaryKind() const { return Kind; }
374 
375  /// Set the path to the module containing this function, for use in
376  /// the combined index.
377  void setModulePath(StringRef ModPath) { ModulePath = ModPath; }
378 
379  /// Get the path to the module containing this function.
380  StringRef modulePath() const { return ModulePath; }
381 
382  /// Get the flags for this GlobalValue (see \p struct GVFlags).
383  GVFlags flags() const { return Flags; }
384 
385  /// Return linkage type recorded for this global value.
387  return static_cast<GlobalValue::LinkageTypes>(Flags.Linkage);
388  }
389 
390  /// Sets the linkage to the value determined by global summary-based
391  /// optimization. Will be applied in the ThinLTO backends.
393  Flags.Linkage = Linkage;
394  }
395 
396  /// Return true if this global value can't be imported.
397  bool notEligibleToImport() const { return Flags.NotEligibleToImport; }
398 
399  bool isLive() const { return Flags.Live; }
400 
401  void setLive(bool Live) { Flags.Live = Live; }
402 
403  void setDSOLocal(bool Local) { Flags.DSOLocal = Local; }
404 
405  bool isDSOLocal() const { return Flags.DSOLocal; }
406 
407  void setCanAutoHide(bool CanAutoHide) { Flags.CanAutoHide = CanAutoHide; }
408 
409  bool canAutoHide() const { return Flags.CanAutoHide; }
410 
411  /// Flag that this global value cannot be imported.
413 
414  /// Return the list of values referenced by this global value definition.
415  ArrayRef<ValueInfo> refs() const { return RefEdgeList; }
416 
417  /// If this is an alias summary, returns the summary of the aliased object (a
418  /// global variable or function), otherwise returns itself.
419  GlobalValueSummary *getBaseObject();
420  const GlobalValueSummary *getBaseObject() const;
421 
422  friend class ModuleSummaryIndex;
423 };
424 
425 /// Alias summary information.
427  ValueInfo AliaseeValueInfo;
428 
429  /// This is the Aliasee in the same module as alias (could get from VI, trades
430  /// memory for time). Note that this pointer may be null (and the value info
431  /// empty) when we have a distributed index where the alias is being imported
432  /// (as a copy of the aliasee), but the aliasee is not.
433  GlobalValueSummary *AliaseeSummary;
434 
435 public:
437  : GlobalValueSummary(AliasKind, Flags, ArrayRef<ValueInfo>{}),
438  AliaseeSummary(nullptr) {}
439 
440  /// Check if this is an alias summary.
441  static bool classof(const GlobalValueSummary *GVS) {
442  return GVS->getSummaryKind() == AliasKind;
443  }
444 
445  void setAliasee(ValueInfo &AliaseeVI, GlobalValueSummary *Aliasee) {
446  AliaseeValueInfo = AliaseeVI;
447  AliaseeSummary = Aliasee;
448  }
449 
450  bool hasAliasee() const {
451  assert(!!AliaseeSummary == (AliaseeValueInfo &&
452  !AliaseeValueInfo.getSummaryList().empty()) &&
453  "Expect to have both aliasee summary and summary list or neither");
454  return !!AliaseeSummary;
455  }
456 
458  assert(AliaseeSummary && "Unexpected missing aliasee summary");
459  return *AliaseeSummary;
460  }
461 
463  return const_cast<GlobalValueSummary &>(
464  static_cast<const AliasSummary *>(this)->getAliasee());
465  }
467  assert(AliaseeValueInfo && "Unexpected missing aliasee");
468  return AliaseeValueInfo;
469  }
471  assert(AliaseeValueInfo && "Unexpected missing aliasee");
472  return AliaseeValueInfo.getGUID();
473  }
474 };
475 
477  if (auto *AS = dyn_cast<AliasSummary>(this))
478  return &AS->getAliasee();
479  return this;
480 }
481 
483  if (auto *AS = dyn_cast<AliasSummary>(this))
484  return &AS->getAliasee();
485  return this;
486 }
487 
488 /// Function summary information to aid decisions and implementation of
489 /// importing.
491 public:
492  /// <CalleeValueInfo, CalleeInfo> call edge pair.
493  using EdgeTy = std::pair<ValueInfo, CalleeInfo>;
494 
495  /// Types for -force-summary-edges-cold debugging option.
496  enum ForceSummaryHotnessType : unsigned {
499  FSHT_All
500  };
501 
502  /// An "identifier" for a virtual function. This contains the type identifier
503  /// represented as a GUID and the offset from the address point to the virtual
504  /// function pointer, where "address point" is as defined in the Itanium ABI:
505  /// https://itanium-cxx-abi.github.io/cxx-abi/abi.html#vtable-general
506  struct VFuncId {
508  uint64_t Offset;
509  };
510 
511  /// A specification for a virtual function call with all constant integer
512  /// arguments. This is used to perform virtual constant propagation on the
513  /// summary.
514  struct ConstVCall {
516  std::vector<uint64_t> Args;
517  };
518 
519  /// All type identifier related information. Because these fields are
520  /// relatively uncommon we only allocate space for them if necessary.
521  struct TypeIdInfo {
522  /// List of type identifiers used by this function in llvm.type.test
523  /// intrinsics referenced by something other than an llvm.assume intrinsic,
524  /// represented as GUIDs.
525  std::vector<GlobalValue::GUID> TypeTests;
526 
527  /// List of virtual calls made by this function using (respectively)
528  /// llvm.assume(llvm.type.test) or llvm.type.checked.load intrinsics that do
529  /// not have all constant integer arguments.
530  std::vector<VFuncId> TypeTestAssumeVCalls, TypeCheckedLoadVCalls;
531 
532  /// List of virtual calls made by this function using (respectively)
533  /// llvm.assume(llvm.type.test) or llvm.type.checked.load intrinsics with
534  /// all constant integer arguments.
535  std::vector<ConstVCall> TypeTestAssumeConstVCalls,
536  TypeCheckedLoadConstVCalls;
537  };
538 
539  /// Flags specific to function summaries.
540  struct FFlags {
541  // Function attribute flags. Used to track if a function accesses memory,
542  // recurses or aliases.
543  unsigned ReadNone : 1;
544  unsigned ReadOnly : 1;
545  unsigned NoRecurse : 1;
546  unsigned ReturnDoesNotAlias : 1;
547 
548  // Indicate if the global value cannot be inlined.
549  unsigned NoInline : 1;
550  };
551 
552  /// Create an empty FunctionSummary (with specified call edges).
553  /// Used to represent external nodes and the dummy root node.
554  static FunctionSummary
555  makeDummyFunctionSummary(std::vector<FunctionSummary::EdgeTy> Edges) {
556  return FunctionSummary(
558  GlobalValue::LinkageTypes::AvailableExternallyLinkage,
559  /*NotEligibleToImport=*/true, /*Live=*/true, /*IsLocal=*/false,
560  /*CanAutoHide=*/false),
561  /*InsCount=*/0, FunctionSummary::FFlags{}, /*EntryCount=*/0,
562  std::vector<ValueInfo>(), std::move(Edges),
563  std::vector<GlobalValue::GUID>(),
564  std::vector<FunctionSummary::VFuncId>(),
565  std::vector<FunctionSummary::VFuncId>(),
566  std::vector<FunctionSummary::ConstVCall>(),
567  std::vector<FunctionSummary::ConstVCall>());
568  }
569 
570  /// A dummy node to reference external functions that aren't in the index
572 
573 private:
574  /// Number of instructions (ignoring debug instructions, e.g.) computed
575  /// during the initial compile step when the summary index is first built.
576  unsigned InstCount;
577 
578  /// Function summary specific flags.
579  FFlags FunFlags;
580 
581  /// The synthesized entry count of the function.
582  /// This is only populated during ThinLink phase and remains unused while
583  /// generating per-module summaries.
584  uint64_t EntryCount = 0;
585 
586  /// List of <CalleeValueInfo, CalleeInfo> call edge pairs from this function.
587  std::vector<EdgeTy> CallGraphEdgeList;
588 
589  std::unique_ptr<TypeIdInfo> TIdInfo;
590 
591 public:
592  FunctionSummary(GVFlags Flags, unsigned NumInsts, FFlags FunFlags,
593  uint64_t EntryCount, std::vector<ValueInfo> Refs,
594  std::vector<EdgeTy> CGEdges,
595  std::vector<GlobalValue::GUID> TypeTests,
596  std::vector<VFuncId> TypeTestAssumeVCalls,
597  std::vector<VFuncId> TypeCheckedLoadVCalls,
598  std::vector<ConstVCall> TypeTestAssumeConstVCalls,
599  std::vector<ConstVCall> TypeCheckedLoadConstVCalls)
600  : GlobalValueSummary(FunctionKind, Flags, std::move(Refs)),
601  InstCount(NumInsts), FunFlags(FunFlags), EntryCount(EntryCount),
602  CallGraphEdgeList(std::move(CGEdges)) {
603  if (!TypeTests.empty() || !TypeTestAssumeVCalls.empty() ||
604  !TypeCheckedLoadVCalls.empty() || !TypeTestAssumeConstVCalls.empty() ||
605  !TypeCheckedLoadConstVCalls.empty())
606  TIdInfo = std::make_unique<TypeIdInfo>(TypeIdInfo{
607  std::move(TypeTests), std::move(TypeTestAssumeVCalls),
608  std::move(TypeCheckedLoadVCalls),
609  std::move(TypeTestAssumeConstVCalls),
610  std::move(TypeCheckedLoadConstVCalls)});
611  }
612  // Gets the number of readonly and writeonly refs in RefEdgeList
613  std::pair<unsigned, unsigned> specialRefCounts() const;
614 
615  /// Check if this is a function summary.
616  static bool classof(const GlobalValueSummary *GVS) {
617  return GVS->getSummaryKind() == FunctionKind;
618  }
619 
620  /// Get function summary flags.
621  FFlags fflags() const { return FunFlags; }
622 
623  /// Get the instruction count recorded for this function.
624  unsigned instCount() const { return InstCount; }
625 
626  /// Get the synthetic entry count for this function.
627  uint64_t entryCount() const { return EntryCount; }
628 
629  /// Set the synthetic entry count for this function.
630  void setEntryCount(uint64_t EC) { EntryCount = EC; }
631 
632  /// Return the list of <CalleeValueInfo, CalleeInfo> pairs.
633  ArrayRef<EdgeTy> calls() const { return CallGraphEdgeList; }
634 
635  void addCall(EdgeTy E) { CallGraphEdgeList.push_back(E); }
636 
637  /// Returns the list of type identifiers used by this function in
638  /// llvm.type.test intrinsics other than by an llvm.assume intrinsic,
639  /// represented as GUIDs.
641  if (TIdInfo)
642  return TIdInfo->TypeTests;
643  return {};
644  }
645 
646  /// Returns the list of virtual calls made by this function using
647  /// llvm.assume(llvm.type.test) intrinsics that do not have all constant
648  /// integer arguments.
650  if (TIdInfo)
651  return TIdInfo->TypeTestAssumeVCalls;
652  return {};
653  }
654 
655  /// Returns the list of virtual calls made by this function using
656  /// llvm.type.checked.load intrinsics that do not have all constant integer
657  /// arguments.
659  if (TIdInfo)
660  return TIdInfo->TypeCheckedLoadVCalls;
661  return {};
662  }
663 
664  /// Returns the list of virtual calls made by this function using
665  /// llvm.assume(llvm.type.test) intrinsics with all constant integer
666  /// arguments.
668  if (TIdInfo)
669  return TIdInfo->TypeTestAssumeConstVCalls;
670  return {};
671  }
672 
673  /// Returns the list of virtual calls made by this function using
674  /// llvm.type.checked.load intrinsics with all constant integer arguments.
676  if (TIdInfo)
677  return TIdInfo->TypeCheckedLoadConstVCalls;
678  return {};
679  }
680 
681  /// Add a type test to the summary. This is used by WholeProgramDevirt if we
682  /// were unable to devirtualize a checked call.
684  if (!TIdInfo)
685  TIdInfo = std::make_unique<TypeIdInfo>();
686  TIdInfo->TypeTests.push_back(Guid);
687  }
688 
689  const TypeIdInfo *getTypeIdInfo() const { return TIdInfo.get(); };
690 
691  friend struct GraphTraits<ValueInfo>;
692 };
693 
694 template <> struct DenseMapInfo<FunctionSummary::VFuncId> {
695  static FunctionSummary::VFuncId getEmptyKey() { return {0, uint64_t(-1)}; }
696 
698  return {0, uint64_t(-2)};
699  }
700 
702  return L.GUID == R.GUID && L.Offset == R.Offset;
703  }
704 
705  static unsigned getHashValue(FunctionSummary::VFuncId I) { return I.GUID; }
706 };
707 
708 template <> struct DenseMapInfo<FunctionSummary::ConstVCall> {
710  return {{0, uint64_t(-1)}, {}};
711  }
712 
714  return {{0, uint64_t(-2)}, {}};
715  }
716 
720  L.Args == R.Args;
721  }
722 
724  return I.VFunc.GUID;
725  }
726 };
727 
728 /// The ValueInfo and offset for a function within a vtable definition
729 /// initializer array.
731  VirtFuncOffset(ValueInfo VI, uint64_t Offset)
732  : FuncVI(VI), VTableOffset(Offset) {}
733 
734  ValueInfo FuncVI;
735  uint64_t VTableOffset;
736 };
737 /// List of functions referenced by a particular vtable definition.
738 using VTableFuncList = std::vector<VirtFuncOffset>;
739 
740 /// Global variable summary information to aid decisions and
741 /// implementation of importing.
742 ///
743 /// Global variable summary has two extra flag, telling if it is
744 /// readonly or writeonly. Both readonly and writeonly variables
745 /// can be optimized in the backed: readonly variables can be
746 /// const-folded, while writeonly vars can be completely eliminated
747 /// together with corresponding stores. We let both things happen
748 /// by means of internalizing such variables after ThinLTO import.
750 private:
751  /// For vtable definitions this holds the list of functions and
752  /// their corresponding offsets within the initializer array.
753  std::unique_ptr<VTableFuncList> VTableFuncs;
754 
755 public:
756  struct GVarFlags {
757  GVarFlags(bool ReadOnly, bool WriteOnly)
758  : MaybeReadOnly(ReadOnly), MaybeWriteOnly(WriteOnly) {}
759 
760  // In permodule summaries both MaybeReadOnly and MaybeWriteOnly
761  // bits are set, because attribute propagation occurs later on
762  // thin link phase.
763  unsigned MaybeReadOnly : 1;
764  unsigned MaybeWriteOnly : 1;
765  } VarFlags;
766 
768  std::vector<ValueInfo> Refs)
769  : GlobalValueSummary(GlobalVarKind, Flags, std::move(Refs)),
770  VarFlags(VarFlags) {}
771 
772  /// Check if this is a global variable summary.
773  static bool classof(const GlobalValueSummary *GVS) {
774  return GVS->getSummaryKind() == GlobalVarKind;
775  }
776 
777  GVarFlags varflags() const { return VarFlags; }
778  void setReadOnly(bool RO) { VarFlags.MaybeReadOnly = RO; }
779  void setWriteOnly(bool WO) { VarFlags.MaybeWriteOnly = WO; }
780  bool maybeReadOnly() const { return VarFlags.MaybeReadOnly; }
781  bool maybeWriteOnly() const { return VarFlags.MaybeWriteOnly; }
782 
784  assert(!VTableFuncs);
785  VTableFuncs = std::make_unique<VTableFuncList>(std::move(Funcs));
786  }
787 
789  if (VTableFuncs)
790  return *VTableFuncs;
791  return {};
792  }
793 };
794 
796  /// Specifies which kind of type check we should emit for this byte array.
797  /// See http://clang.llvm.org/docs/ControlFlowIntegrityDesign.html for full
798  /// details on each kind of check; the enumerators are described with
799  /// reference to that document.
800  enum Kind {
801  Unsat, ///< Unsatisfiable type (i.e. no global has this type metadata)
802  ByteArray, ///< Test a byte array (first example)
803  Inline, ///< Inlined bit vector ("Short Inline Bit Vectors")
804  Single, ///< Single element (last example in "Short Inline Bit Vectors")
805  AllOnes, ///< All-ones bit vector ("Eliminating Bit Vector Checks for
806  /// All-Ones Bit Vectors")
807  } TheKind = Unsat;
808 
809  /// Range of size-1 expressed as a bit width. For example, if the size is in
810  /// range [1,256], this number will be 8. This helps generate the most compact
811  /// instruction sequences.
812  unsigned SizeM1BitWidth = 0;
813 
814  // The following fields are only used if the target does not support the use
815  // of absolute symbols to store constants. Their meanings are the same as the
816  // corresponding fields in LowerTypeTestsModule::TypeIdLowering in
817  // LowerTypeTests.cpp.
818 
819  uint64_t AlignLog2 = 0;
820  uint64_t SizeM1 = 0;
821  uint8_t BitMask = 0;
822  uint64_t InlineBits = 0;
823 };
824 
826  enum Kind {
827  Indir, ///< Just do a regular virtual call
828  SingleImpl, ///< Single implementation devirtualization
829  BranchFunnel, ///< When retpoline mitigation is enabled, use a branch funnel
830  ///< that is defined in the merged module. Otherwise same as
831  ///< Indir.
832  } TheKind = Indir;
833 
834  std::string SingleImplName;
835 
836  struct ByArg {
837  enum Kind {
838  Indir, ///< Just do a regular virtual call
839  UniformRetVal, ///< Uniform return value optimization
840  UniqueRetVal, ///< Unique return value optimization
841  VirtualConstProp, ///< Virtual constant propagation
842  } TheKind = Indir;
843 
844  /// Additional information for the resolution:
845  /// - UniformRetVal: the uniform return value.
846  /// - UniqueRetVal: the return value associated with the unique vtable (0 or
847  /// 1).
848  uint64_t Info = 0;
849 
850  // The following fields are only used if the target does not support the use
851  // of absolute symbols to store constants.
852 
853  uint32_t Byte = 0;
855  };
856 
857  /// Resolutions for calls with all constant integer arguments (excluding the
858  /// first argument, "this"), where the key is the argument vector.
859  std::map<std::vector<uint64_t>, ByArg> ResByArg;
860 };
861 
864 
865  /// Mapping from byte offset to whole-program devirt resolution for that
866  /// (typeid, byte offset) pair.
867  std::map<uint64_t, WholeProgramDevirtResolution> WPDRes;
868 };
869 
870 /// 160 bits SHA1
871 using ModuleHash = std::array<uint32_t, 5>;
872 
873 /// Type used for iterating through the global value summary map.
874 using const_gvsummary_iterator = GlobalValueSummaryMapTy::const_iterator;
875 using gvsummary_iterator = GlobalValueSummaryMapTy::iterator;
876 
877 /// String table to hold/own module path strings, which additionally holds the
878 /// module ID assigned to each module during the plugin step, as well as a hash
879 /// of the module. The StringMap makes a copy of and owns inserted strings.
881 
882 /// Map of global value GUID to its summary, used to identify values defined in
883 /// a particular module, and provide efficient access to their summary.
885 
886 /// Map of a type GUID to type id string and summary (multimap used
887 /// in case of GUID conflicts).
888 using TypeIdSummaryMapTy =
889  std::multimap<GlobalValue::GUID, std::pair<std::string, TypeIdSummary>>;
890 
891 /// The following data structures summarize type metadata information.
892 /// For type metadata overview see https://llvm.org/docs/TypeMetadata.html.
893 /// Each type metadata includes both the type identifier and the offset of
894 /// the address point of the type (the address held by objects of that type
895 /// which may not be the beginning of the virtual table). Vtable definitions
896 /// are decorated with type metadata for the types they are compatible with.
897 ///
898 /// Holds information about vtable definitions decorated with type metadata:
899 /// the vtable definition value and its address point offset in a type
900 /// identifier metadata it is decorated (compatible) with.
902  TypeIdOffsetVtableInfo(uint64_t Offset, ValueInfo VI)
903  : AddressPointOffset(Offset), VTableVI(VI) {}
904 
906  ValueInfo VTableVI;
907 };
908 /// List of vtable definitions decorated by a particular type identifier,
909 /// and their corresponding offsets in that type identifier's metadata.
910 /// Note that each type identifier may be compatible with multiple vtables, due
911 /// to inheritance, which is why this is a vector.
912 using TypeIdCompatibleVtableInfo = std::vector<TypeIdOffsetVtableInfo>;
913 
914 /// Class to hold module path string table and global value map,
915 /// and encapsulate methods for operating on them.
917 private:
918  /// Map from value name to list of summary instances for values of that
919  /// name (may be duplicates in the COMDAT case, e.g.).
920  GlobalValueSummaryMapTy GlobalValueMap;
921 
922  /// Holds strings for combined index, mapping to the corresponding module ID.
923  ModulePathStringTableTy ModulePathStringTable;
924 
925  /// Mapping from type identifier GUIDs to type identifier and its summary
926  /// information. Produced by thin link.
927  TypeIdSummaryMapTy TypeIdMap;
928 
929  /// Mapping from type identifier to information about vtables decorated
930  /// with that type identifier's metadata. Produced by per module summary
931  /// analysis and consumed by thin link. For more information, see description
932  /// above where TypeIdCompatibleVtableInfo is defined.
933  std::map<std::string, TypeIdCompatibleVtableInfo> TypeIdCompatibleVtableMap;
934 
935  /// Mapping from original ID to GUID. If original ID can map to multiple
936  /// GUIDs, it will be mapped to 0.
937  std::map<GlobalValue::GUID, GlobalValue::GUID> OidGuidMap;
938 
939  /// Indicates that summary-based GlobalValue GC has run, and values with
940  /// GVFlags::Live==false are really dead. Otherwise, all values must be
941  /// considered live.
942  bool WithGlobalValueDeadStripping = false;
943 
944  /// Indicates that summary-based synthetic entry count propagation has run
945  bool HasSyntheticEntryCounts = false;
946 
947  /// Indicates that distributed backend should skip compilation of the
948  /// module. Flag is suppose to be set by distributed ThinLTO indexing
949  /// when it detected that the module is not needed during the final
950  /// linking. As result distributed backend should just output a minimal
951  /// valid object file.
952  bool SkipModuleByDistributedBackend = false;
953 
954  /// If true then we're performing analysis of IR module, or parsing along with
955  /// the IR from assembly. The value of 'false' means we're reading summary
956  /// from BC or YAML source. Affects the type of value stored in NameOrGV
957  /// union.
958  bool HaveGVs;
959 
960  // True if the index was created for a module compiled with -fsplit-lto-unit.
961  bool EnableSplitLTOUnit;
962 
963  // True if some of the modules were compiled with -fsplit-lto-unit and
964  // some were not. Set when the combined index is created during the thin link.
965  bool PartiallySplitLTOUnits = false;
966 
967  std::set<std::string> CfiFunctionDefs;
968  std::set<std::string> CfiFunctionDecls;
969 
970  // Used in cases where we want to record the name of a global, but
971  // don't have the string owned elsewhere (e.g. the Strtab on a module).
972  StringSaver Saver;
973  BumpPtrAllocator Alloc;
974 
975  // YAML I/O support.
977 
978  GlobalValueSummaryMapTy::value_type *
979  getOrInsertValuePtr(GlobalValue::GUID GUID) {
980  return &*GlobalValueMap.emplace(GUID, GlobalValueSummaryInfo(HaveGVs))
981  .first;
982  }
983 
984 public:
985  // See HaveGVs variable comment.
986  ModuleSummaryIndex(bool HaveGVs, bool EnableSplitLTOUnit = false)
987  : HaveGVs(HaveGVs), EnableSplitLTOUnit(EnableSplitLTOUnit), Saver(Alloc) {
988  }
989 
990  bool haveGVs() const { return HaveGVs; }
991 
992  gvsummary_iterator begin() { return GlobalValueMap.begin(); }
993  const_gvsummary_iterator begin() const { return GlobalValueMap.begin(); }
994  gvsummary_iterator end() { return GlobalValueMap.end(); }
995  const_gvsummary_iterator end() const { return GlobalValueMap.end(); }
996  size_t size() const { return GlobalValueMap.size(); }
997 
998  /// Convenience function for doing a DFS on a ValueInfo. Marks the function in
999  /// the FunctionHasParent map.
1000  static void discoverNodes(ValueInfo V,
1001  std::map<ValueInfo, bool> &FunctionHasParent) {
1002  if (!V.getSummaryList().size())
1003  return; // skip external functions that don't have summaries
1004 
1005  // Mark discovered if we haven't yet
1006  auto S = FunctionHasParent.emplace(V, false);
1007 
1008  // Stop if we've already discovered this node
1009  if (!S.second)
1010  return;
1011 
1012  FunctionSummary *F =
1013  dyn_cast<FunctionSummary>(V.getSummaryList().front().get());
1014  assert(F != nullptr && "Expected FunctionSummary node");
1015 
1016  for (auto &C : F->calls()) {
1017  // Insert node if necessary
1018  auto S = FunctionHasParent.emplace(C.first, true);
1019 
1020  // Skip nodes that we're sure have parents
1021  if (!S.second && S.first->second)
1022  continue;
1023 
1024  if (S.second)
1025  discoverNodes(C.first, FunctionHasParent);
1026  else
1027  S.first->second = true;
1028  }
1029  }
1030 
1031  // Calculate the callgraph root
1033  // Functions that have a parent will be marked in FunctionHasParent pair.
1034  // Once we've marked all functions, the functions in the map that are false
1035  // have no parent (so they're the roots)
1036  std::map<ValueInfo, bool> FunctionHasParent;
1037 
1038  for (auto &S : *this) {
1039  // Skip external functions
1040  if (!S.second.SummaryList.size() ||
1041  !isa<FunctionSummary>(S.second.SummaryList.front().get()))
1042  continue;
1043  discoverNodes(ValueInfo(HaveGVs, &S), FunctionHasParent);
1044  }
1045 
1046  std::vector<FunctionSummary::EdgeTy> Edges;
1047  // create edges to all roots in the Index
1048  for (auto &P : FunctionHasParent) {
1049  if (P.second)
1050  continue; // skip over non-root nodes
1051  Edges.push_back(std::make_pair(P.first, CalleeInfo{}));
1052  }
1053  if (Edges.empty()) {
1054  // Failed to find root - return an empty node
1056  }
1057  auto CallGraphRoot = FunctionSummary::makeDummyFunctionSummary(Edges);
1058  return CallGraphRoot;
1059  }
1060 
1062  return WithGlobalValueDeadStripping;
1063  }
1065  WithGlobalValueDeadStripping = true;
1066  }
1067 
1068  bool hasSyntheticEntryCounts() const { return HasSyntheticEntryCounts; }
1069  void setHasSyntheticEntryCounts() { HasSyntheticEntryCounts = true; }
1070 
1072  return SkipModuleByDistributedBackend;
1073  }
1075  SkipModuleByDistributedBackend = true;
1076  }
1077 
1078  bool enableSplitLTOUnit() const { return EnableSplitLTOUnit; }
1079  void setEnableSplitLTOUnit() { EnableSplitLTOUnit = true; }
1080 
1081  bool partiallySplitLTOUnits() const { return PartiallySplitLTOUnits; }
1082  void setPartiallySplitLTOUnits() { PartiallySplitLTOUnits = true; }
1083 
1084  bool isGlobalValueLive(const GlobalValueSummary *GVS) const {
1085  return !WithGlobalValueDeadStripping || GVS->isLive();
1086  }
1087  bool isGUIDLive(GlobalValue::GUID GUID) const;
1088 
1089  /// Return a ValueInfo for the index value_type (convenient when iterating
1090  /// index).
1091  ValueInfo getValueInfo(const GlobalValueSummaryMapTy::value_type &R) const {
1092  return ValueInfo(HaveGVs, &R);
1093  }
1094 
1095  /// Return a ValueInfo for GUID if it exists, otherwise return ValueInfo().
1096  ValueInfo getValueInfo(GlobalValue::GUID GUID) const {
1097  auto I = GlobalValueMap.find(GUID);
1098  return ValueInfo(HaveGVs, I == GlobalValueMap.end() ? nullptr : &*I);
1099  }
1100 
1101  /// Return a ValueInfo for \p GUID.
1103  return ValueInfo(HaveGVs, getOrInsertValuePtr(GUID));
1104  }
1105 
1106  // Save a string in the Index. Use before passing Name to
1107  // getOrInsertValueInfo when the string isn't owned elsewhere (e.g. on the
1108  // module's Strtab).
1109  StringRef saveString(StringRef String) { return Saver.save(String); }
1110 
1111  /// Return a ValueInfo for \p GUID setting value \p Name.
1113  assert(!HaveGVs);
1114  auto VP = getOrInsertValuePtr(GUID);
1115  VP->second.U.Name = Name;
1116  return ValueInfo(HaveGVs, VP);
1117  }
1118 
1119  /// Return a ValueInfo for \p GV and mark it as belonging to GV.
1120  ValueInfo getOrInsertValueInfo(const GlobalValue *GV) {
1121  assert(HaveGVs);
1122  auto VP = getOrInsertValuePtr(GV->getGUID());
1123  VP->second.U.GV = GV;
1124  return ValueInfo(HaveGVs, VP);
1125  }
1126 
1127  /// Return the GUID for \p OriginalId in the OidGuidMap.
1129  const auto I = OidGuidMap.find(OriginalID);
1130  return I == OidGuidMap.end() ? 0 : I->second;
1131  }
1132 
1133  std::set<std::string> &cfiFunctionDefs() { return CfiFunctionDefs; }
1134  const std::set<std::string> &cfiFunctionDefs() const { return CfiFunctionDefs; }
1135 
1136  std::set<std::string> &cfiFunctionDecls() { return CfiFunctionDecls; }
1137  const std::set<std::string> &cfiFunctionDecls() const { return CfiFunctionDecls; }
1138 
1139  /// Add a global value summary for a value.
1141  std::unique_ptr<GlobalValueSummary> Summary) {
1142  addGlobalValueSummary(getOrInsertValueInfo(&GV), std::move(Summary));
1143  }
1144 
1145  /// Add a global value summary for a value of the given name.
1147  std::unique_ptr<GlobalValueSummary> Summary) {
1148  addGlobalValueSummary(getOrInsertValueInfo(GlobalValue::getGUID(ValueName)),
1149  std::move(Summary));
1150  }
1151 
1152  /// Add a global value summary for the given ValueInfo.
1153  void addGlobalValueSummary(ValueInfo VI,
1154  std::unique_ptr<GlobalValueSummary> Summary) {
1155  addOriginalName(VI.getGUID(), Summary->getOriginalName());
1156  // Here we have a notionally const VI, but the value it points to is owned
1157  // by the non-const *this.
1158  const_cast<GlobalValueSummaryMapTy::value_type *>(VI.getRef())
1159  ->second.SummaryList.push_back(std::move(Summary));
1160  }
1161 
1162  /// Add an original name for the value of the given GUID.
1164  GlobalValue::GUID OrigGUID) {
1165  if (OrigGUID == 0 || ValueGUID == OrigGUID)
1166  return;
1167  if (OidGuidMap.count(OrigGUID) && OidGuidMap[OrigGUID] != ValueGUID)
1168  OidGuidMap[OrigGUID] = 0;
1169  else
1170  OidGuidMap[OrigGUID] = ValueGUID;
1171  }
1172 
1173  /// Find the summary for ValueInfo \p VI in module \p ModuleId, or nullptr if
1174  /// not found.
1175  GlobalValueSummary *findSummaryInModule(ValueInfo VI, StringRef ModuleId) const {
1176  auto SummaryList = VI.getSummaryList();
1177  auto Summary =
1178  llvm::find_if(SummaryList,
1179  [&](const std::unique_ptr<GlobalValueSummary> &Summary) {
1180  return Summary->modulePath() == ModuleId;
1181  });
1182  if (Summary == SummaryList.end())
1183  return nullptr;
1184  return Summary->get();
1185  }
1186 
1187  /// Find the summary for global \p GUID in module \p ModuleId, or nullptr if
1188  /// not found.
1190  StringRef ModuleId) const {
1191  auto CalleeInfo = getValueInfo(ValueGUID);
1192  if (!CalleeInfo)
1193  return nullptr; // This function does not have a summary
1194  return findSummaryInModule(CalleeInfo, ModuleId);
1195  }
1196 
1197  /// Returns the first GlobalValueSummary for \p GV, asserting that there
1198  /// is only one if \p PerModuleIndex.
1200  bool PerModuleIndex = true) const {
1201  assert(GV.hasName() && "Can't get GlobalValueSummary for GV with no name");
1202  return getGlobalValueSummary(GV.getGUID(), PerModuleIndex);
1203  }
1204 
1205  /// Returns the first GlobalValueSummary for \p ValueGUID, asserting that
1206  /// there
1207  /// is only one if \p PerModuleIndex.
1208  GlobalValueSummary *getGlobalValueSummary(GlobalValue::GUID ValueGUID,
1209  bool PerModuleIndex = true) const;
1210 
1211  /// Table of modules, containing module hash and id.
1213  return ModulePathStringTable;
1214  }
1215 
1216  /// Table of modules, containing hash and id.
1218  return ModulePathStringTable;
1219  }
1220 
1221  /// Get the module ID recorded for the given module path.
1222  uint64_t getModuleId(const StringRef ModPath) const {
1223  return ModulePathStringTable.lookup(ModPath).first;
1224  }
1225 
1226  /// Get the module SHA1 hash recorded for the given module path.
1227  const ModuleHash &getModuleHash(const StringRef ModPath) const {
1228  auto It = ModulePathStringTable.find(ModPath);
1229  assert(It != ModulePathStringTable.end() && "Module not registered");
1230  return It->second.second;
1231  }
1232 
1233  /// Convenience method for creating a promoted global name
1234  /// for the given value name of a local, and its original module's ID.
1235  static std::string getGlobalNameForLocal(StringRef Name, ModuleHash ModHash) {
1236  SmallString<256> NewName(Name);
1237  NewName += ".llvm.";
1238  NewName += utostr((uint64_t(ModHash[0]) << 32) |
1239  ModHash[1]); // Take the first 64 bits
1240  return NewName.str();
1241  }
1242 
1243  /// Helper to obtain the unpromoted name for a global value (or the original
1244  /// name if not promoted).
1246  std::pair<StringRef, StringRef> Pair = Name.split(".llvm.");
1247  return Pair.first;
1248  }
1249 
1251 
1252  /// Add a new module with the given \p Hash, mapped to the given \p
1253  /// ModID, and return a reference to the module.
1254  ModuleInfo *addModule(StringRef ModPath, uint64_t ModId,
1255  ModuleHash Hash = ModuleHash{{0}}) {
1256  return &*ModulePathStringTable.insert({ModPath, {ModId, Hash}}).first;
1257  }
1258 
1259  /// Return module entry for module with the given \p ModPath.
1260  ModuleInfo *getModule(StringRef ModPath) {
1261  auto It = ModulePathStringTable.find(ModPath);
1262  assert(It != ModulePathStringTable.end() && "Module not registered");
1263  return &*It;
1264  }
1265 
1266  /// Check if the given Module has any functions available for exporting
1267  /// in the index. We consider any module present in the ModulePathStringTable
1268  /// to have exported functions.
1269  bool hasExportedFunctions(const Module &M) const {
1270  return ModulePathStringTable.count(M.getModuleIdentifier());
1271  }
1272 
1273  const TypeIdSummaryMapTy &typeIds() const { return TypeIdMap; }
1274 
1275  /// Return an existing or new TypeIdSummary entry for \p TypeId.
1276  /// This accessor can mutate the map and therefore should not be used in
1277  /// the ThinLTO backends.
1279  auto TidIter = TypeIdMap.equal_range(GlobalValue::getGUID(TypeId));
1280  for (auto It = TidIter.first; It != TidIter.second; ++It)
1281  if (It->second.first == TypeId)
1282  return It->second.second;
1283  auto It = TypeIdMap.insert(
1284  {GlobalValue::getGUID(TypeId), {TypeId, TypeIdSummary()}});
1285  return It->second.second;
1286  }
1287 
1288  /// This returns either a pointer to the type id summary (if present in the
1289  /// summary map) or null (if not present). This may be used when importing.
1291  auto TidIter = TypeIdMap.equal_range(GlobalValue::getGUID(TypeId));
1292  for (auto It = TidIter.first; It != TidIter.second; ++It)
1293  if (It->second.first == TypeId)
1294  return &It->second.second;
1295  return nullptr;
1296  }
1297 
1299  return const_cast<TypeIdSummary *>(
1300  static_cast<const ModuleSummaryIndex *>(this)->getTypeIdSummary(
1301  TypeId));
1302  }
1303 
1304  const std::map<std::string, TypeIdCompatibleVtableInfo> &
1306  return TypeIdCompatibleVtableMap;
1307  }
1308 
1309  /// Return an existing or new TypeIdCompatibleVtableMap entry for \p TypeId.
1310  /// This accessor can mutate the map and therefore should not be used in
1311  /// the ThinLTO backends.
1314  return TypeIdCompatibleVtableMap[TypeId];
1315  }
1316 
1317  /// For the given \p TypeId, this returns the TypeIdCompatibleVtableMap
1318  /// entry if present in the summary map. This may be used when importing.
1321  auto I = TypeIdCompatibleVtableMap.find(TypeId);
1322  if (I == TypeIdCompatibleVtableMap.end())
1323  return None;
1324  return I->second;
1325  }
1326 
1327  /// Collect for the given module the list of functions it defines
1328  /// (GUID -> Summary).
1329  void collectDefinedFunctionsForModule(StringRef ModulePath,
1330  GVSummaryMapTy &GVSummaryMap) const;
1331 
1332  /// Collect for each module the list of Summaries it defines (GUID ->
1333  /// Summary).
1334  template <class Map>
1335  void
1336  collectDefinedGVSummariesPerModule(Map &ModuleToDefinedGVSummaries) const {
1337  for (auto &GlobalList : *this) {
1338  auto GUID = GlobalList.first;
1339  for (auto &Summary : GlobalList.second.SummaryList) {
1340  ModuleToDefinedGVSummaries[Summary->modulePath()][GUID] = Summary.get();
1341  }
1342  }
1343  }
1344 
1345  /// Print to an output stream.
1346  void print(raw_ostream &OS, bool IsForDebug = false) const;
1347 
1348  /// Dump to stderr (for debugging).
1349  void dump() const;
1350 
1351  /// Export summary to dot file for GraphViz.
1352  void exportToDot(raw_ostream& OS) const;
1353 
1354  /// Print out strongly connected components for debugging.
1355  void dumpSCCs(raw_ostream &OS);
1356 
1357  /// Analyze index and detect unmodified globals
1358  void propagateAttributes(const DenseSet<GlobalValue::GUID> &PreservedSymbols);
1359 };
1360 
1361 /// GraphTraits definition to build SCC for the index
1362 template <> struct GraphTraits<ValueInfo> {
1363  typedef ValueInfo NodeRef;
1365 
1367  return P.first;
1368  }
1369  using ChildIteratorType =
1371  decltype(&valueInfoFromEdge)>;
1372 
1373  using ChildEdgeIteratorType = std::vector<FunctionSummary::EdgeTy>::iterator;
1374 
1375  static NodeRef getEntryNode(ValueInfo V) { return V; }
1376 
1377  static ChildIteratorType child_begin(NodeRef N) {
1378  if (!N.getSummaryList().size()) // handle external function
1379  return ChildIteratorType(
1380  FunctionSummary::ExternalNode.CallGraphEdgeList.begin(),
1381  &valueInfoFromEdge);
1382  FunctionSummary *F =
1383  cast<FunctionSummary>(N.getSummaryList().front()->getBaseObject());
1384  return ChildIteratorType(F->CallGraphEdgeList.begin(), &valueInfoFromEdge);
1385  }
1386 
1387  static ChildIteratorType child_end(NodeRef N) {
1388  if (!N.getSummaryList().size()) // handle external function
1389  return ChildIteratorType(
1390  FunctionSummary::ExternalNode.CallGraphEdgeList.end(),
1391  &valueInfoFromEdge);
1392  FunctionSummary *F =
1393  cast<FunctionSummary>(N.getSummaryList().front()->getBaseObject());
1394  return ChildIteratorType(F->CallGraphEdgeList.end(), &valueInfoFromEdge);
1395  }
1396 
1398  if (!N.getSummaryList().size()) // handle external function
1399  return FunctionSummary::ExternalNode.CallGraphEdgeList.begin();
1400 
1401  FunctionSummary *F =
1402  cast<FunctionSummary>(N.getSummaryList().front()->getBaseObject());
1403  return F->CallGraphEdgeList.begin();
1404  }
1405 
1407  if (!N.getSummaryList().size()) // handle external function
1408  return FunctionSummary::ExternalNode.CallGraphEdgeList.end();
1409 
1410  FunctionSummary *F =
1411  cast<FunctionSummary>(N.getSummaryList().front()->getBaseObject());
1412  return F->CallGraphEdgeList.end();
1413  }
1414 
1415  static NodeRef edge_dest(EdgeRef E) { return E.first; }
1416 };
1417 
1418 template <>
1421  std::unique_ptr<GlobalValueSummary> Root =
1422  std::make_unique<FunctionSummary>(I->calculateCallGraphRoot());
1424  G.SummaryList.push_back(std::move(Root));
1425  static auto P =
1426  GlobalValueSummaryMapTy::value_type(GlobalValue::GUID(0), std::move(G));
1427  return ValueInfo(I->haveGVs(), &P);
1428  }
1429 };
1430 
1431 static inline bool canImportGlobalVar(GlobalValueSummary *S) {
1432  assert(isa<GlobalVarSummary>(S->getBaseObject()));
1433 
1434  // We don't import GV with references, because it can result
1435  // in promotion of local variables in the source module.
1437  !S->notEligibleToImport() && S->refs().empty();
1438 }
1439 } // end namespace llvm
1440 
1441 #endif // LLVM_IR_MODULESUMMARYINDEX_H
static FunctionSummary::ConstVCall getEmptyKey()
static bool isInterposableLinkage(LinkageTypes Linkage)
Whether the definition of this global may be replaced by something non-equivalent at link time...
Definition: GlobalValue.h:346
const NoneType None
Definition: None.h:23
uint64_t CallInst * C
std::vector< TypeIdOffsetVtableInfo > TypeIdCompatibleVtableInfo
List of vtable definitions decorated by a particular type identifier, and their corresponding offsets...
unsigned Live
In per-module summary, indicate that the global value must be considered a live root for index-based ...
void setNotEligibleToImport()
Flag that this global value cannot be imported.
static bool classof(const GlobalValueSummary *GVS)
Check if this is an alias summary.
bool operator==(const BinaryRef &LHS, const BinaryRef &RHS)
Definition: YAML.h:97
static FunctionSummary::ConstVCall getTombstoneKey()
bool haveGVs() const
std::vector< std::unique_ptr< GlobalValueSummary > > GlobalValueSummaryList
uint64_t GUID
Declare a type to represent a global unique identifier for a global value.
Definition: GlobalValue.h:502
This class represents lattice values for constants.
Definition: AllocatorList.h:23
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
Definition: StringMap.h:158
ValueInfo getValueInfo(GlobalValue::GUID GUID) const
Return a ValueInfo for GUID if it exists, otherwise return ValueInfo().
unsigned Linkage
The linkage type of the associated global value.
const GlobalValueSummary & getAliasee() const
StringRef Name
Summary string representation.
std::multimap< GlobalValue::GUID, std::pair< std::string, TypeIdSummary > > TypeIdSummaryMapTy
Map of a type GUID to type id string and summary (multimap used in case of GUID conflicts).
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:66
GlobalValueSummary * findSummaryInModule(GlobalValue::GUID ValueGUID, StringRef ModuleId) const
Find the summary for global GUID in module ModuleId, or nullptr if not found.
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
GlobalValueSummary * getGlobalValueSummary(const GlobalValue &GV, bool PerModuleIndex=true) const
Returns the first GlobalValueSummary for GV, asserting that there is only one if PerModuleIndex.
const GlobalValue * getValue() const
ArrayRef< VFuncId > type_test_assume_vcalls() const
Returns the list of virtual calls made by this function using llvm.assume(llvm.type.test) intrinsics that do not have all constant integer arguments.
Global variable summary information to aid decisions and implementation of importing.
Unsatisfiable type (i.e. no global has this type metadata)
void addTypeTest(GlobalValue::GUID Guid)
Add a type test to the summary.
ArrayRef< ValueInfo > refs() const
Return the list of values referenced by this global value definition.
static void discoverNodes(ValueInfo V, std::map< ValueInfo, bool > &FunctionHasParent)
Convenience function for doing a DFS on a ValueInfo.
GlobalValueSummaryMapTy::iterator gvsummary_iterator
iterator find(StringRef Key)
Definition: StringMap.h:355
const StringMap< std::pair< uint64_t, ModuleHash > > & modulePaths() const
Table of modules, containing module hash and id.
const std::map< std::string, TypeIdCompatibleVtableInfo > & typeIdCompatibleVtableMap() const
GlobalValue::LinkageTypes linkage() const
Return linkage type recorded for this global value.
std::vector< VFuncId > TypeTestAssumeVCalls
List of virtual calls made by this function using (respectively) llvm.assume(llvm.type.test) or llvm.type.checked.load intrinsics that do not have all constant integer arguments.
static StringRef getOriginalNameBeforePromote(StringRef Name)
Helper to obtain the unpromoted name for a global value (or the original name if not promoted)...
unsigned second
const std::set< std::string > & cfiFunctionDecls() const
VirtFuncOffset(ValueInfo VI, uint64_t Offset)
bool isGlobalValueLive(const GlobalValueSummary *GVS) const
F(f)
Kind
Specifies which kind of type check we should emit for this byte array.
static unsigned getHashValue(ValueInfo I)
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 ...
std::map< uint64_t, WholeProgramDevirtResolution > WPDRes
Mapping from byte offset to whole-program devirt resolution for that (typeid, byte offset) pair...
StringMap< std::pair< uint64_t, ModuleHash > > & modulePaths()
Table of modules, containing hash and id.
This file defines the MallocAllocator and BumpPtrAllocator interfaces.
TypeTestResolution TTRes
bool hasExportedFunctions(const Module &M) const
Check if the given Module has any functions available for exporting in the index. ...
static bool isSpecialKey(ValueInfo V)
void addOriginalName(GlobalValue::GUID ValueGUID, GlobalValue::GUID OrigGUID)
Add an original name for the value of the given GUID.
static bool isEqual(ValueInfo L, ValueInfo R)
const GlobalValue * GV
The GlobalValue corresponding to this summary.
GVarFlags(bool ReadOnly, bool WriteOnly)
uint32_t RelBlockFreq
The value stored in RelBlockFreq has to be interpreted as the digits of a scaled number with a scale ...
TypeIdOffsetVtableInfo(uint64_t Offset, ValueInfo VI)
unsigned NotEligibleToImport
Indicate if the global value cannot be imported (e.g.
GlobalValue::GUID getGUID() const
bool skipModuleByDistributedBackend() const
Definition: BitVector.h:937
bool isValidAccessSpecifier() const
ModuleInfo * getModule(StringRef ModPath)
Return module entry for module with the given ModPath.
static unsigned getHashValue(FunctionSummary::VFuncId I)
StringRef saveString(StringRef String)
const_gvsummary_iterator begin() const
static std::string getGlobalNameForLocal(StringRef Name, ModuleHash ModHash)
Convenience method for creating a promoted global name for the given value name of a local...
const TypeIdSummaryMapTy & typeIds() const
std::array< uint32_t, 5 > ModuleHash
160 bits SHA1
Just do a regular virtual call.
static bool canImportGlobalVar(GlobalValueSummary *S)
std::map< GlobalValue::GUID, GlobalValueSummaryInfo > GlobalValueSummaryMapTy
Map from global value GUID to corresponding summary structures.
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:140
ArrayRef< GlobalValue::GUID > type_tests() const
Returns the list of type identifiers used by this function in llvm.type.test intrinsics other than by...
StringRef str() const
Explicit conversion to StringRef.
Definition: SmallString.h:266
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 ...
static NodeRef getEntryNode(ValueInfo V)
static bool isEqual(const Function &Caller, const Function &Callee)
ArrayRef< VFuncId > type_checked_load_vcalls() const
Returns the list of virtual calls made by this function using llvm.type.checked.load intrinsics that ...
std::pair< ValueInfo, CalleeInfo > EdgeTy
<CalleeValueInfo, CalleeInfo> call edge pair.
The ValueInfo and offset for a function within a vtable definition initializer array.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:32
TypeIdSummary & getOrInsertTypeIdSummary(StringRef TypeId)
Return an existing or new TypeIdSummary entry for TypeId.
ModuleSummaryIndex(bool HaveGVs, bool EnableSplitLTOUnit=false)
void setCanAutoHide(bool CanAutoHide)
ModulePathStringTableTy::value_type ModuleInfo
Class to hold module path string table and global value map, and encapsulate methods for operating on...
static ChildEdgeIteratorType child_edge_begin(NodeRef N)
ArrayRef< std::unique_ptr< GlobalValueSummary > > getSummaryList() const
static ChildEdgeIteratorType child_edge_end(NodeRef N)
Analysis containing CSE Info
Definition: CSEInfo.cpp:20
static bool isEqual(FunctionSummary::VFuncId L, FunctionSummary::VFuncId R)
void setVTableFuncs(VTableFuncList Funcs)
ForceSummaryHotnessType
Types for -force-summary-edges-cold debugging option.
static unsigned getHashValue(FunctionSummary::ConstVCall I)
GlobalValueSummaryMapTy::const_iterator const_gvsummary_iterator
Type used for iterating through the global value summary map.
#define P(N)
static FunctionSummary::VFuncId getEmptyKey()
GlobalValue::GUID getGUIDFromOriginalID(GlobalValue::GUID OriginalID) const
Return the GUID for OriginalId in the OidGuidMap.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
GlobalValue::GUID getAliaseeGUID() const
PointerIntPair< const GlobalValueSummaryMapTy::value_type *, 3, int > RefAndFlags
size_type count(StringRef Key) const
count - Return 1 if the element is in the map, 0 otherwise.
Definition: StringMap.h:381
bool hasName() const
Definition: Value.h:252
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:141
static bool classof(const GlobalValueSummary *GVS)
Check if this is a global variable summary.
ValueInfo(bool HaveGVs, const GlobalValueSummaryMapTy::value_type *R)
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
SummaryKind getSummaryKind() const
Which kind of summary subclass this is.
const std::set< std::string > & cfiFunctionDefs() const
unsigned instCount() const
Get the instruction count recorded for this function.
CalleeInfo(HotnessType Hotness, uint64_t RelBF)
Class to accumulate and hold information about a callee.
Single element (last example in "Short Inline Bit Vectors")
StringRef name() const
GlobalVarSummary(GVFlags Flags, GVarFlags VarFlags, std::vector< ValueInfo > Refs)
TypeIdCompatibleVtableInfo & getOrInsertTypeIdCompatibleVtableSummary(StringRef TypeId)
Return an existing or new TypeIdCompatibleVtableMap entry for TypeId.
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
uint64_t entryCount() const
Get the synthetic entry count for this function.
const ModuleHash & getModuleHash(const StringRef ModPath) const
Get the module SHA1 hash recorded for the given module path.
GlobalValue::GUID getOriginalName() const
Returns the hash of the original name, it is identical to the GUID for externally visible symbols...
ValueTy lookup(StringRef Key) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
Definition: StringMap.h:369
ValueInfo getOrInsertValueInfo(const GlobalValue *GV)
Return a ValueInfo for GV and mark it as belonging to GV.
auto find_if(R &&Range, UnaryPredicate P) -> decltype(adl_begin(Range))
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:1193
All type identifier related information.
Function and variable summary information to aid decisions and implementation of importing.
static GUID getGUID(StringRef GlobalName)
Return a 64-bit global unique ID constructed from global value name (i.e.
Definition: GlobalValue.h:506
std::vector< FunctionSummary::EdgeTy >::iterator ChildEdgeIteratorType
Optional< TypeIdCompatibleVtableInfo > getTypeIdCompatibleVtableSummary(StringRef TypeId) const
For the given TypeId, this returns the TypeIdCompatibleVtableMap entry if present in the summary map...
const_gvsummary_iterator end() const
const std::string & getModuleIdentifier() const
Get the module identifier which is, essentially, the name of the module.
Definition: Module.h:211
GVFlags flags() const
Get the flags for this GlobalValue (see struct GVFlags).
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void addGlobalValueSummary(StringRef ValueName, std::unique_ptr< GlobalValueSummary > Summary)
Add a global value summary for a value of the given name.
unsigned first
An "identifier" for a virtual function.
ArrayRef< ConstVCall > type_test_assume_const_vcalls() const
Returns the list of virtual calls made by this function using llvm.assume(llvm.type.test) intrinsics with all constant integer arguments.
void addGlobalValueSummary(ValueInfo VI, std::unique_ptr< GlobalValueSummary > Summary)
Add a global value summary for the given ValueInfo.
Struct that holds a reference to a particular GUID in a global value summary.
HotnessType getHotness() const
void updateHotness(const HotnessType OtherHotness)
ModuleInfo * addModule(StringRef ModPath, uint64_t ModId, ModuleHash Hash=ModuleHash{{0}})
Add a new module with the given Hash, mapped to the given ModID, and return a reference to the module...
static bool classof(const GlobalValueSummary *GVS)
Check if this is a function summary.
const char * getHotnessName(CalleeInfo::HotnessType HT)
GlobalValueSummary * getBaseObject()
If this is an alias summary, returns the summary of the aliased object (a global variable or function...
Align max(MaybeAlign Lhs, Align Rhs)
Definition: Alignment.h:390
static ChildIteratorType child_end(NodeRef N)
Module.h This file contains the declarations for the Module class.
LLVM_NODISCARD std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition: StringRef.h:710
Single implementation devirtualization.
ValueInfo getAliaseeVI() const
ValueInfo getOrInsertValueInfo(GlobalValue::GUID GUID, StringRef Name)
Return a ValueInfo for GUID setting value Name.
const DataFlowGraph & G
Definition: RDFGraph.cpp:202
uint64_t getModuleId(const StringRef ModPath) const
Get the module ID recorded for the given module path.
Alias summary information.
static NodeRef getEntryNode(ModuleSummaryIndex *I)
bool isReadOnly() const
std::string utostr(uint64_t X, bool isNeg=false)
Definition: StringExtras.h:223
ArrayRef< VirtFuncOffset > vTableFuncs() const
FunctionSummary::EdgeTy & EdgeRef
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
Definition: StringMap.h:393
static FunctionSummary makeDummyFunctionSummary(std::vector< FunctionSummary::EdgeTy > Edges)
Create an empty FunctionSummary (with specified call edges).
StringRef save(const char *S)
Definition: StringSaver.h:28
A specification for a virtual function call with all constant integer arguments.
LinkageTypes
An enumeration for the kinds of linkage for global values.
Definition: GlobalValue.h:47
GUID getGUID() const
Return a 64-bit global unique ID constructed from global value name (i.e.
Definition: GlobalValue.h:510
SummaryKind
Sububclass discriminator (for dyn_cast<> et al.)
ValueInfo getValueInfo(const GlobalValueSummaryMapTy::value_type &R) const
Return a ValueInfo for the index value_type (convenient when iterating index).
ValueInfo getOrInsertValueInfo(GlobalValue::GUID GUID)
Return a ValueInfo for GUID.
bool withGlobalValueDeadStripping() const
FFlags fflags() const
Get function summary flags.
GlobalValueSummary(SummaryKind K, GVFlags Flags, std::vector< ValueInfo > Refs)
std::set< std::string > & cfiFunctionDefs()
bool operator!=(uint64_t V1, const APInt &V2)
Definition: APInt.h:1977
Test a byte array (first example)
Saves strings in the provided stable storage and returns a StringRef with a stable character pointer...
Definition: StringSaver.h:21
FunctionSummary calculateCallGraphRoot()
std::map< std::vector< uint64_t >, ByArg > ResByArg
Resolutions for calls with all constant integer arguments (excluding the first argument, "this"), where the key is the argument vector.
unsigned getAccessSpecifier() const
void setAliasee(ValueInfo &AliaseeVI, GlobalValueSummary *Aliasee)
StringRef modulePath() const
Get the path to the module containing this function.
void setLinkage(GlobalValue::LinkageTypes Linkage)
Sets the linkage to the value determined by global summary-based optimization.
unsigned DSOLocal
Indicates that the linker resolved the symbol to a definition from within the same linkage unit...
void addGlobalValueSummary(const GlobalValue &GV, std::unique_ptr< GlobalValueSummary > Summary)
Add a global value summary for a value.
bool isWriteOnly() const
unsigned CanAutoHide
In the per-module summary, indicates that the global value is linkonce_odr and global unnamed addr (s...
#define I(x, y, z)
Definition: MD5.cpp:58
#define N
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:332
ArrayRef< EdgeTy > calls() const
Return the list of <CalleeValueInfo, CalleeInfo> pairs.
void setOriginalName(GlobalValue::GUID Name)
Initialize the original name hash in this summary.
static NodeRef valueInfoFromEdge(FunctionSummary::EdgeTy &P)
Flags specific to function summaries.
GlobalValueSummary * findSummaryInModule(ValueInfo VI, StringRef ModuleId) const
Find the summary for ValueInfo VI in module ModuleId, or nullptr if not found.
Inlined bit vector ("Short Inline Bit Vectors")
Function summary information to aid decisions and implementation of importing.
GlobalValueSummary & getAliasee()
void setModulePath(StringRef ModPath)
Set the path to the module containing this function, for use in the combined index.
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
Definition: APInt.h:2047
bool notEligibleToImport() const
Return true if this global value can&#39;t be imported.
FunctionSummary(GVFlags Flags, unsigned NumInsts, FFlags FunFlags, uint64_t EntryCount, std::vector< ValueInfo > Refs, std::vector< EdgeTy > CGEdges, std::vector< GlobalValue::GUID > TypeTests, std::vector< VFuncId > TypeTestAssumeVCalls, std::vector< VFuncId > TypeCheckedLoadVCalls, std::vector< ConstVCall > TypeTestAssumeConstVCalls, std::vector< ConstVCall > TypeCheckedLoadConstVCalls)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
std::set< std::string > & cfiFunctionDecls()
GVFlags(GlobalValue::LinkageTypes Linkage, bool NotEligibleToImport, bool Live, bool IsLocal, bool CanAutoHide)
Convenience Constructors.
void collectDefinedGVSummariesPerModule(Map &ModuleToDefinedGVSummaries) const
Collect for each module the list of Summaries it defines (GUID -> Summary).
TypeIdSummary * getTypeIdSummary(StringRef TypeId)
bool operator<(int64_t V1, const APSInt &V2)
Definition: APSInt.h:343
std::vector< VirtFuncOffset > VTableFuncList
List of functions referenced by a particular vtable definition.
void setEntryCount(uint64_t EC)
Set the synthetic entry count for this function.
ScaledNumber< uint64_t > Scaled64
static FunctionSummary::VFuncId getTombstoneKey()
static ChildIteratorType child_begin(NodeRef N)
gvsummary_iterator end()
GVarFlags varflags() const
Group flags (Linkage, NotEligibleToImport, etc.) as a bitfield.
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
gvsummary_iterator begin()
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
const GlobalValueSummaryMapTy::value_type * getRef() const
AliasSummary(GVFlags Flags)
static bool isEqual(FunctionSummary::ConstVCall L, FunctionSummary::ConstVCall R)
GraphTraits definition to build SCC for the index.
static NodeRef edge_dest(EdgeRef E)
void updateRelBlockFreq(uint64_t BlockFreq, uint64_t EntryFreq)
Update RelBlockFreq from BlockFreq and EntryFreq.
iterator end()
Definition: StringMap.h:340
The following data structures summarize type metadata information.
GlobalValueSummaryList SummaryList
List of global value summary structures for a particular value held in the GlobalValueMap.
std::vector< GlobalValue::GUID > TypeTests
List of type identifiers used by this function in llvm.type.test intrinsics referenced by something o...
static FunctionSummary ExternalNode
A dummy node to reference external functions that aren&#39;t in the index.
std::vector< ConstVCall > TypeTestAssumeConstVCalls
List of virtual calls made by this function using (respectively) llvm.assume(llvm.type.test) or llvm.type.checked.load intrinsics with all constant integer arguments.