LLVM  7.0.0svn
ModuleSummaryIndex.h
Go to the documentation of this file.
1 //===- llvm/ModuleSummaryIndex.h - Module Summary Index ---------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 /// @file
11 /// ModuleSummaryIndex.h This file contains the declarations the classes that
12 /// hold the module index and summary for function importing.
13 //
14 //===----------------------------------------------------------------------===//
15 
16 #ifndef LLVM_IR_MODULESUMMARYINDEX_H
17 #define LLVM_IR_MODULESUMMARYINDEX_H
18 
19 #include "llvm/ADT/ArrayRef.h"
20 #include "llvm/ADT/DenseMap.h"
21 #include "llvm/ADT/STLExtras.h"
22 #include "llvm/ADT/SmallString.h"
23 #include "llvm/ADT/StringExtras.h"
24 #include "llvm/ADT/StringMap.h"
25 #include "llvm/ADT/StringRef.h"
26 #include "llvm/IR/GlobalValue.h"
27 #include "llvm/IR/Module.h"
30 #include <algorithm>
31 #include <array>
32 #include <cassert>
33 #include <cstddef>
34 #include <cstdint>
35 #include <map>
36 #include <memory>
37 #include <set>
38 #include <string>
39 #include <utility>
40 #include <vector>
41 
42 namespace llvm {
43 
44 namespace yaml {
45 
46 template <typename T> struct MappingTraits;
47 
48 } // end namespace yaml
49 
50 /// \brief Class to accumulate and hold information about a callee.
51 struct CalleeInfo {
52  enum class HotnessType : uint8_t {
53  Unknown = 0,
54  Cold = 1,
55  None = 2,
56  Hot = 3,
57  Critical = 4
58  };
59 
60  // The size of the bit-field might need to be adjusted if more values are
61  // added to HotnessType enum.
63 
64  /// The value stored in RelBlockFreq has to be interpreted as the digits of
65  /// a scaled number with a scale of \p -ScaleShift.
67  static constexpr int32_t ScaleShift = 8;
68  static constexpr uint64_t MaxRelBlockFreq = (1 << 29) - 1;
69 
71  : Hotness(static_cast<uint32_t>(HotnessType::Unknown)), RelBlockFreq(0) {}
72  explicit CalleeInfo(HotnessType Hotness, uint64_t RelBF)
73  : Hotness(static_cast<uint32_t>(Hotness)), RelBlockFreq(RelBF) {}
74 
75  void updateHotness(const HotnessType OtherHotness) {
76  Hotness = std::max(Hotness, static_cast<uint32_t>(OtherHotness));
77  }
78 
79  HotnessType getHotness() const { return HotnessType(Hotness); }
80 
81  /// Update \p RelBlockFreq from \p BlockFreq and \p EntryFreq
82  ///
83  /// BlockFreq is divided by EntryFreq and added to RelBlockFreq. To represent
84  /// fractional values, the result is represented as a fixed point number with
85  /// scale of -ScaleShift.
86  void updateRelBlockFreq(uint64_t BlockFreq, uint64_t EntryFreq) {
87  if (EntryFreq == 0)
88  return;
90  Scaled64 Temp(BlockFreq, ScaleShift);
91  Temp /= Scaled64::get(EntryFreq);
92 
93  uint64_t Sum =
94  SaturatingAdd<uint64_t>(Temp.toInt<uint64_t>(), RelBlockFreq);
95  Sum = std::min(Sum, uint64_t(MaxRelBlockFreq));
96  RelBlockFreq = static_cast<uint32_t>(Sum);
97  }
98 };
99 
100 class GlobalValueSummary;
101 
102 using GlobalValueSummaryList = std::vector<std::unique_ptr<GlobalValueSummary>>;
103 
105  union NameOrGV {
106  NameOrGV(bool IsAnalysis) {
107  if (IsAnalysis)
108  GV = nullptr;
109  else
110  Name = "";
111  }
112 
113  /// The GlobalValue corresponding to this summary. This is only used in
114  /// per-module summaries, when module analysis is being run.
115  const GlobalValue *GV;
116 
117  /// Summary string representation. This StringRef points to BC module
118  /// string table and is valid until module data is stored in memory.
119  /// This is guaranteed to happen until runThinLTOBackend function is
120  /// called, so it is safe to use this field during thin link. This field
121  /// is only valid if summary index was loaded from BC file.
123  } U;
124 
125  GlobalValueSummaryInfo(bool IsAnalysis) : U(IsAnalysis) {}
126 
127  /// List of global value summary structures for a particular value held
128  /// in the GlobalValueMap. Requires a vector in the case of multiple
129  /// COMDAT values of the same name.
131 };
132 
133 /// Map from global value GUID to corresponding summary structures. Use a
134 /// std::map rather than a DenseMap so that pointers to the map's value_type
135 /// (which are used by ValueInfo) are not invalidated by insertion. Also it will
136 /// likely incur less overhead, as the value type is not very small and the size
137 /// of the map is unknown, resulting in inefficiencies due to repeated
138 /// insertions and resizing.
140  std::map<GlobalValue::GUID, GlobalValueSummaryInfo>;
141 
142 /// Struct that holds a reference to a particular GUID in a global value
143 /// summary.
144 struct ValueInfo {
147 
148  ValueInfo() = default;
149  ValueInfo(bool IsAnalysis, const GlobalValueSummaryMapTy::value_type *R) {
150  RefAndFlag.setPointer(R);
151  RefAndFlag.setInt(IsAnalysis);
152  }
153 
154  operator bool() const { return getRef(); }
155 
156  GlobalValue::GUID getGUID() const { return getRef()->first; }
157  const GlobalValue *getValue() const {
158  assert(isFromAnalysis());
159  return getRef()->second.U.GV;
160  }
161 
163  return getRef()->second.SummaryList;
164  }
165 
166  StringRef name() const {
167  return isFromAnalysis() ? getRef()->second.U.GV->getName()
168  : getRef()->second.U.Name;
169  }
170 
171  bool isFromAnalysis() const { return RefAndFlag.getInt(); }
172 
173  const GlobalValueSummaryMapTy::value_type *getRef() const {
174  return RefAndFlag.getPointer();
175  }
176 
177  bool isDSOLocal() const;
178 };
179 
180 inline bool operator==(const ValueInfo &A, const ValueInfo &B) {
181  assert(A.getRef() && B.getRef() &&
182  "Need ValueInfo with non-null Ref to compare GUIDs");
183  return A.getRef() == B.getRef();
184 }
185 
186 inline bool operator!=(const ValueInfo &A, const ValueInfo &B) {
187  assert(A.getRef() && B.getRef() &&
188  "Need ValueInfo with non-null Ref to compare GUIDs");
189  return A.getGUID() != B.getGUID();
190 }
191 
192 inline bool operator<(const ValueInfo &A, const ValueInfo &B) {
193  assert(A.getRef() && B.getRef() &&
194  "Need ValueInfo with non-null Ref to compare GUIDs");
195  return A.getGUID() < B.getGUID();
196 }
197 
198 template <> struct DenseMapInfo<ValueInfo> {
199  static inline ValueInfo getEmptyKey() {
200  return ValueInfo(false, (GlobalValueSummaryMapTy::value_type *)-8);
201  }
202 
203  static inline ValueInfo getTombstoneKey() {
204  return ValueInfo(false, (GlobalValueSummaryMapTy::value_type *)-16);
205  }
206 
207  static inline bool isSpecialKey(ValueInfo V) {
208  return V == getTombstoneKey() || V == getEmptyKey();
209  }
210 
211  static bool isEqual(ValueInfo L, ValueInfo R) {
212  // We are not supposed to mix ValueInfo(s) with different analysis flag
213  // in a same container.
214  assert(isSpecialKey(L) || isSpecialKey(R) ||
215  (L.isFromAnalysis() == R.isFromAnalysis()));
216  return L.getRef() == R.getRef();
217  }
218  static unsigned getHashValue(ValueInfo I) { return (uintptr_t)I.getRef(); }
219 };
220 
221 /// \brief Function and variable summary information to aid decisions and
222 /// implementation of importing.
224 public:
225  /// \brief Sububclass discriminator (for dyn_cast<> et al.)
226  enum SummaryKind : unsigned { AliasKind, FunctionKind, GlobalVarKind };
227 
228  /// Group flags (Linkage, NotEligibleToImport, etc.) as a bitfield.
229  struct GVFlags {
230  /// \brief The linkage type of the associated global value.
231  ///
232  /// One use is to flag values that have local linkage types and need to
233  /// have module identifier appended before placing into the combined
234  /// index, to disambiguate from other values with the same name.
235  /// In the future this will be used to update and optimize linkage
236  /// types based on global summary-based analysis.
237  unsigned Linkage : 4;
238 
239  /// Indicate if the global value cannot be imported (e.g. it cannot
240  /// be renamed or references something that can't be renamed).
241  unsigned NotEligibleToImport : 1;
242 
243  /// In per-module summary, indicate that the global value must be considered
244  /// a live root for index-based liveness analysis. Used for special LLVM
245  /// values such as llvm.global_ctors that the linker does not know about.
246  ///
247  /// In combined summary, indicate that the global value is live.
248  unsigned Live : 1;
249 
250  /// Indicates that the linker resolved the symbol to a definition from
251  /// within the same linkage unit.
252  unsigned DSOLocal : 1;
253 
254  /// Convenience Constructors
256  bool NotEligibleToImport, bool Live, bool IsLocal)
257  : Linkage(Linkage), NotEligibleToImport(NotEligibleToImport),
258  Live(Live), DSOLocal(IsLocal) {}
259  };
260 
261 private:
262  /// Kind of summary for use in dyn_cast<> et al.
264 
265  GVFlags Flags;
266 
267  /// This is the hash of the name of the symbol in the original file. It is
268  /// identical to the GUID for global symbols, but differs for local since the
269  /// GUID includes the module level id in the hash.
270  GlobalValue::GUID OriginalName = 0;
271 
272  /// \brief Path of module IR containing value's definition, used to locate
273  /// module during importing.
274  ///
275  /// This is only used during parsing of the combined index, or when
276  /// parsing the per-module index for creation of the combined summary index,
277  /// not during writing of the per-module index which doesn't contain a
278  /// module path string table.
279  StringRef ModulePath;
280 
281  /// List of values referenced by this global value's definition
282  /// (either by the initializer of a global variable, or referenced
283  /// from within a function). This does not include functions called, which
284  /// are listed in the derived FunctionSummary object.
285  std::vector<ValueInfo> RefEdgeList;
286 
287 protected:
288  GlobalValueSummary(SummaryKind K, GVFlags Flags, std::vector<ValueInfo> Refs)
289  : Kind(K), Flags(Flags), RefEdgeList(std::move(Refs)) {
290  assert((K != AliasKind || Refs.empty()) &&
291  "Expect no references for AliasSummary");
292  }
293 
294 public:
295  virtual ~GlobalValueSummary() = default;
296 
297  /// Returns the hash of the original name, it is identical to the GUID for
298  /// externally visible symbols, but not for local ones.
299  GlobalValue::GUID getOriginalName() { return OriginalName; }
300 
301  /// Initialize the original name hash in this summary.
302  void setOriginalName(GlobalValue::GUID Name) { OriginalName = Name; }
303 
304  /// Which kind of summary subclass this is.
305  SummaryKind getSummaryKind() const { return Kind; }
306 
307  /// Set the path to the module containing this function, for use in
308  /// the combined index.
309  void setModulePath(StringRef ModPath) { ModulePath = ModPath; }
310 
311  /// Get the path to the module containing this function.
312  StringRef modulePath() const { return ModulePath; }
313 
314  /// Get the flags for this GlobalValue (see \p struct GVFlags).
315  GVFlags flags() { return Flags; }
316 
317  /// Return linkage type recorded for this global value.
319  return static_cast<GlobalValue::LinkageTypes>(Flags.Linkage);
320  }
321 
322  /// Sets the linkage to the value determined by global summary-based
323  /// optimization. Will be applied in the ThinLTO backends.
325  Flags.Linkage = Linkage;
326  }
327 
328  /// Return true if this global value can't be imported.
329  bool notEligibleToImport() const { return Flags.NotEligibleToImport; }
330 
331  bool isLive() const { return Flags.Live; }
332 
333  void setLive(bool Live) { Flags.Live = Live; }
334 
335  void setDSOLocal(bool Local) { Flags.DSOLocal = Local; }
336 
337  bool isDSOLocal() const { return Flags.DSOLocal; }
338 
339  /// Flag that this global value cannot be imported.
341 
342  /// Return the list of values referenced by this global value definition.
343  ArrayRef<ValueInfo> refs() const { return RefEdgeList; }
344 
345  /// If this is an alias summary, returns the summary of the aliased object (a
346  /// global variable or function), otherwise returns itself.
347  GlobalValueSummary *getBaseObject();
348  const GlobalValueSummary *getBaseObject() const;
349 
350  friend class ModuleSummaryIndex;
351 };
352 
353 /// \brief Alias summary information.
355  GlobalValueSummary *AliaseeSummary;
356  // AliaseeGUID is only set and accessed when we are building a combined index
357  // via the BitcodeReader.
358  GlobalValue::GUID AliaseeGUID;
359 
360 public:
362  : GlobalValueSummary(AliasKind, Flags, ArrayRef<ValueInfo>{}),
363  AliaseeSummary(nullptr), AliaseeGUID(0) {}
364 
365  /// Check if this is an alias summary.
366  static bool classof(const GlobalValueSummary *GVS) {
367  return GVS->getSummaryKind() == AliasKind;
368  }
369 
370  void setAliasee(GlobalValueSummary *Aliasee) { AliaseeSummary = Aliasee; }
371  void setAliaseeGUID(GlobalValue::GUID GUID) { AliaseeGUID = GUID; }
372 
374  assert(AliaseeSummary && "Unexpected missing aliasee summary");
375  return *AliaseeSummary;
376  }
377 
379  return const_cast<GlobalValueSummary &>(
380  static_cast<const AliasSummary *>(this)->getAliasee());
381  }
383  assert(AliaseeGUID && "Unexpected missing aliasee GUID");
384  return AliaseeGUID;
385  }
386 };
387 
389  if (auto *AS = dyn_cast<AliasSummary>(this))
390  return &AS->getAliasee();
391  return this;
392 }
393 
395  if (auto *AS = dyn_cast<AliasSummary>(this))
396  return &AS->getAliasee();
397  return this;
398 }
399 
400 /// \brief Function summary information to aid decisions and implementation of
401 /// importing.
403 public:
404  /// <CalleeValueInfo, CalleeInfo> call edge pair.
405  using EdgeTy = std::pair<ValueInfo, CalleeInfo>;
406 
407  /// Types for -force-summary-edges-cold debugging option.
408  enum ForceSummaryHotnessType : unsigned {
411  FSHT_All
412  };
413 
414  /// An "identifier" for a virtual function. This contains the type identifier
415  /// represented as a GUID and the offset from the address point to the virtual
416  /// function pointer, where "address point" is as defined in the Itanium ABI:
417  /// https://itanium-cxx-abi.github.io/cxx-abi/abi.html#vtable-general
418  struct VFuncId {
420  uint64_t Offset;
421  };
422 
423  /// A specification for a virtual function call with all constant integer
424  /// arguments. This is used to perform virtual constant propagation on the
425  /// summary.
426  struct ConstVCall {
428  std::vector<uint64_t> Args;
429  };
430 
431  /// Function attribute flags. Used to track if a function accesses memory,
432  /// recurses or aliases.
433  struct FFlags {
434  unsigned ReadNone : 1;
435  unsigned ReadOnly : 1;
436  unsigned NoRecurse : 1;
437  unsigned ReturnDoesNotAlias : 1;
438  };
439 
440  /// Create an empty FunctionSummary (with specified call edges).
441  /// Used to represent external nodes and the dummy root node.
442  static FunctionSummary
443  makeDummyFunctionSummary(std::vector<FunctionSummary::EdgeTy> Edges) {
444  return FunctionSummary(
446  GlobalValue::LinkageTypes::AvailableExternallyLinkage,
447  /*NotEligibleToImport=*/true, /*Live=*/true, /*IsLocal=*/false),
448  0, FunctionSummary::FFlags{}, std::vector<ValueInfo>(),
449  std::move(Edges), std::vector<GlobalValue::GUID>(),
450  std::vector<FunctionSummary::VFuncId>(),
451  std::vector<FunctionSummary::VFuncId>(),
452  std::vector<FunctionSummary::ConstVCall>(),
453  std::vector<FunctionSummary::ConstVCall>());
454  }
455 
456  /// A dummy node to reference external functions that aren't in the index
458 
459 private:
460  /// Number of instructions (ignoring debug instructions, e.g.) computed
461  /// during the initial compile step when the summary index is first built.
462  unsigned InstCount;
463 
464  /// Function attribute flags. Used to track if a function accesses memory,
465  /// recurses or aliases.
466  FFlags FunFlags;
467 
468  /// List of <CalleeValueInfo, CalleeInfo> call edge pairs from this function.
469  std::vector<EdgeTy> CallGraphEdgeList;
470 
471  /// All type identifier related information. Because these fields are
472  /// relatively uncommon we only allocate space for them if necessary.
473  struct TypeIdInfo {
474  /// List of type identifiers used by this function in llvm.type.test
475  /// intrinsics other than by an llvm.assume intrinsic, represented as GUIDs.
476  std::vector<GlobalValue::GUID> TypeTests;
477 
478  /// List of virtual calls made by this function using (respectively)
479  /// llvm.assume(llvm.type.test) or llvm.type.checked.load intrinsics that do
480  /// not have all constant integer arguments.
481  std::vector<VFuncId> TypeTestAssumeVCalls, TypeCheckedLoadVCalls;
482 
483  /// List of virtual calls made by this function using (respectively)
484  /// llvm.assume(llvm.type.test) or llvm.type.checked.load intrinsics with
485  /// all constant integer arguments.
486  std::vector<ConstVCall> TypeTestAssumeConstVCalls,
487  TypeCheckedLoadConstVCalls;
488  };
489 
490  std::unique_ptr<TypeIdInfo> TIdInfo;
491 
492 public:
493  FunctionSummary(GVFlags Flags, unsigned NumInsts, FFlags FunFlags,
494  std::vector<ValueInfo> Refs, std::vector<EdgeTy> CGEdges,
495  std::vector<GlobalValue::GUID> TypeTests,
496  std::vector<VFuncId> TypeTestAssumeVCalls,
497  std::vector<VFuncId> TypeCheckedLoadVCalls,
498  std::vector<ConstVCall> TypeTestAssumeConstVCalls,
499  std::vector<ConstVCall> TypeCheckedLoadConstVCalls)
500  : GlobalValueSummary(FunctionKind, Flags, std::move(Refs)),
501  InstCount(NumInsts), FunFlags(FunFlags),
502  CallGraphEdgeList(std::move(CGEdges)) {
503  if (!TypeTests.empty() || !TypeTestAssumeVCalls.empty() ||
504  !TypeCheckedLoadVCalls.empty() || !TypeTestAssumeConstVCalls.empty() ||
505  !TypeCheckedLoadConstVCalls.empty())
506  TIdInfo = llvm::make_unique<TypeIdInfo>(TypeIdInfo{
507  std::move(TypeTests), std::move(TypeTestAssumeVCalls),
508  std::move(TypeCheckedLoadVCalls),
509  std::move(TypeTestAssumeConstVCalls),
510  std::move(TypeCheckedLoadConstVCalls)});
511  }
512 
513  /// Check if this is a function summary.
514  static bool classof(const GlobalValueSummary *GVS) {
515  return GVS->getSummaryKind() == FunctionKind;
516  }
517 
518  /// Get function attribute flags.
519  FFlags &fflags() { return FunFlags; }
520 
521  /// Get the instruction count recorded for this function.
522  unsigned instCount() const { return InstCount; }
523 
524  /// Return the list of <CalleeValueInfo, CalleeInfo> pairs.
525  ArrayRef<EdgeTy> calls() const { return CallGraphEdgeList; }
526 
527  /// Returns the list of type identifiers used by this function in
528  /// llvm.type.test intrinsics other than by an llvm.assume intrinsic,
529  /// represented as GUIDs.
531  if (TIdInfo)
532  return TIdInfo->TypeTests;
533  return {};
534  }
535 
536  /// Returns the list of virtual calls made by this function using
537  /// llvm.assume(llvm.type.test) intrinsics that do not have all constant
538  /// integer arguments.
540  if (TIdInfo)
541  return TIdInfo->TypeTestAssumeVCalls;
542  return {};
543  }
544 
545  /// Returns the list of virtual calls made by this function using
546  /// llvm.type.checked.load intrinsics that do not have all constant integer
547  /// arguments.
549  if (TIdInfo)
550  return TIdInfo->TypeCheckedLoadVCalls;
551  return {};
552  }
553 
554  /// Returns the list of virtual calls made by this function using
555  /// llvm.assume(llvm.type.test) intrinsics with all constant integer
556  /// arguments.
558  if (TIdInfo)
559  return TIdInfo->TypeTestAssumeConstVCalls;
560  return {};
561  }
562 
563  /// Returns the list of virtual calls made by this function using
564  /// llvm.type.checked.load intrinsics with all constant integer arguments.
566  if (TIdInfo)
567  return TIdInfo->TypeCheckedLoadConstVCalls;
568  return {};
569  }
570 
571  /// Add a type test to the summary. This is used by WholeProgramDevirt if we
572  /// were unable to devirtualize a checked call.
574  if (!TIdInfo)
575  TIdInfo = llvm::make_unique<TypeIdInfo>();
576  TIdInfo->TypeTests.push_back(Guid);
577  }
578 
579  friend struct GraphTraits<ValueInfo>;
580 };
581 
582 template <> struct DenseMapInfo<FunctionSummary::VFuncId> {
583  static FunctionSummary::VFuncId getEmptyKey() { return {0, uint64_t(-1)}; }
584 
586  return {0, uint64_t(-2)};
587  }
588 
590  return L.GUID == R.GUID && L.Offset == R.Offset;
591  }
592 
593  static unsigned getHashValue(FunctionSummary::VFuncId I) { return I.GUID; }
594 };
595 
596 template <> struct DenseMapInfo<FunctionSummary::ConstVCall> {
598  return {{0, uint64_t(-1)}, {}};
599  }
600 
602  return {{0, uint64_t(-2)}, {}};
603  }
604 
608  L.Args == R.Args;
609  }
610 
612  return I.VFunc.GUID;
613  }
614 };
615 
616 /// \brief Global variable summary information to aid decisions and
617 /// implementation of importing.
618 ///
619 /// Currently this doesn't add anything to the base \p GlobalValueSummary,
620 /// but is a placeholder as additional info may be added to the summary
621 /// for variables.
623 
624 public:
625  GlobalVarSummary(GVFlags Flags, std::vector<ValueInfo> Refs)
626  : GlobalValueSummary(GlobalVarKind, Flags, std::move(Refs)) {}
627 
628  /// Check if this is a global variable summary.
629  static bool classof(const GlobalValueSummary *GVS) {
630  return GVS->getSummaryKind() == GlobalVarKind;
631  }
632 };
633 
635  /// Specifies which kind of type check we should emit for this byte array.
636  /// See http://clang.llvm.org/docs/ControlFlowIntegrityDesign.html for full
637  /// details on each kind of check; the enumerators are described with
638  /// reference to that document.
639  enum Kind {
640  Unsat, ///< Unsatisfiable type (i.e. no global has this type metadata)
641  ByteArray, ///< Test a byte array (first example)
642  Inline, ///< Inlined bit vector ("Short Inline Bit Vectors")
643  Single, ///< Single element (last example in "Short Inline Bit Vectors")
644  AllOnes, ///< All-ones bit vector ("Eliminating Bit Vector Checks for
645  /// All-Ones Bit Vectors")
646  } TheKind = Unsat;
647 
648  /// Range of size-1 expressed as a bit width. For example, if the size is in
649  /// range [1,256], this number will be 8. This helps generate the most compact
650  /// instruction sequences.
651  unsigned SizeM1BitWidth = 0;
652 
653  // The following fields are only used if the target does not support the use
654  // of absolute symbols to store constants. Their meanings are the same as the
655  // corresponding fields in LowerTypeTestsModule::TypeIdLowering in
656  // LowerTypeTests.cpp.
657 
658  uint64_t AlignLog2 = 0;
659  uint64_t SizeM1 = 0;
660  uint8_t BitMask = 0;
661  uint64_t InlineBits = 0;
662 };
663 
665  enum Kind {
666  Indir, ///< Just do a regular virtual call
667  SingleImpl, ///< Single implementation devirtualization
668  BranchFunnel, ///< When retpoline mitigation is enabled, use a branch funnel
669  ///< that is defined in the merged module. Otherwise same as
670  ///< Indir.
671  } TheKind = Indir;
672 
673  std::string SingleImplName;
674 
675  struct ByArg {
676  enum Kind {
677  Indir, ///< Just do a regular virtual call
678  UniformRetVal, ///< Uniform return value optimization
679  UniqueRetVal, ///< Unique return value optimization
680  VirtualConstProp, ///< Virtual constant propagation
681  } TheKind = Indir;
682 
683  /// Additional information for the resolution:
684  /// - UniformRetVal: the uniform return value.
685  /// - UniqueRetVal: the return value associated with the unique vtable (0 or
686  /// 1).
687  uint64_t Info = 0;
688 
689  // The following fields are only used if the target does not support the use
690  // of absolute symbols to store constants.
691 
692  uint32_t Byte = 0;
694  };
695 
696  /// Resolutions for calls with all constant integer arguments (excluding the
697  /// first argument, "this"), where the key is the argument vector.
698  std::map<std::vector<uint64_t>, ByArg> ResByArg;
699 };
700 
703 
704  /// Mapping from byte offset to whole-program devirt resolution for that
705  /// (typeid, byte offset) pair.
706  std::map<uint64_t, WholeProgramDevirtResolution> WPDRes;
707 };
708 
709 /// 160 bits SHA1
710 using ModuleHash = std::array<uint32_t, 5>;
711 
712 /// Type used for iterating through the global value summary map.
713 using const_gvsummary_iterator = GlobalValueSummaryMapTy::const_iterator;
714 using gvsummary_iterator = GlobalValueSummaryMapTy::iterator;
715 
716 /// String table to hold/own module path strings, which additionally holds the
717 /// module ID assigned to each module during the plugin step, as well as a hash
718 /// of the module. The StringMap makes a copy of and owns inserted strings.
720 
721 /// Map of global value GUID to its summary, used to identify values defined in
722 /// a particular module, and provide efficient access to their summary.
724 
725 /// Class to hold module path string table and global value map,
726 /// and encapsulate methods for operating on them.
728 private:
729  /// Map from value name to list of summary instances for values of that
730  /// name (may be duplicates in the COMDAT case, e.g.).
731  GlobalValueSummaryMapTy GlobalValueMap;
732 
733  /// Holds strings for combined index, mapping to the corresponding module ID.
734  ModulePathStringTableTy ModulePathStringTable;
735 
736  /// Mapping from type identifiers to summary information for that type
737  /// identifier.
738  std::map<std::string, TypeIdSummary> TypeIdMap;
739 
740  /// Mapping from original ID to GUID. If original ID can map to multiple
741  /// GUIDs, it will be mapped to 0.
742  std::map<GlobalValue::GUID, GlobalValue::GUID> OidGuidMap;
743 
744  /// Indicates that summary-based GlobalValue GC has run, and values with
745  /// GVFlags::Live==false are really dead. Otherwise, all values must be
746  /// considered live.
747  bool WithGlobalValueDeadStripping = false;
748 
749  /// Indicates that distributed backend should skip compilation of the
750  /// module. Flag is suppose to be set by distributed ThinLTO indexing
751  /// when it detected that the module is not needed during the final
752  /// linking. As result distributed backend should just output a minimal
753  /// valid object file.
754  bool SkipModuleByDistributedBackend = false;
755 
756  /// If true then we're performing analysis of IR module, filling summary
757  /// accordingly. The value of 'false' means we're reading summary from
758  /// BC or YAML source. Affects the type of value stored in NameOrGV union
759  bool IsAnalysis;
760 
761  std::set<std::string> CfiFunctionDefs;
762  std::set<std::string> CfiFunctionDecls;
763 
764  // YAML I/O support.
766 
767  GlobalValueSummaryMapTy::value_type *
768  getOrInsertValuePtr(GlobalValue::GUID GUID) {
769  return &*GlobalValueMap.emplace(GUID, GlobalValueSummaryInfo(IsAnalysis)).first;
770  }
771 
772 public:
773  // See IsAnalysis variable comment.
774  ModuleSummaryIndex(bool IsPerformingAnalysis)
775  : IsAnalysis(IsPerformingAnalysis) {}
776 
777  bool isPerformingAnalysis() const { return IsAnalysis; }
778 
779  gvsummary_iterator begin() { return GlobalValueMap.begin(); }
780  const_gvsummary_iterator begin() const { return GlobalValueMap.begin(); }
781  gvsummary_iterator end() { return GlobalValueMap.end(); }
782  const_gvsummary_iterator end() const { return GlobalValueMap.end(); }
783  size_t size() const { return GlobalValueMap.size(); }
784 
785  /// Convenience function for doing a DFS on a ValueInfo. Marks the function in
786  /// the FunctionHasParent map.
787  static void discoverNodes(ValueInfo V,
788  std::map<ValueInfo, bool> &FunctionHasParent) {
789  if (!V.getSummaryList().size())
790  return; // skip external functions that don't have summaries
791 
792  // Mark discovered if we haven't yet
793  auto S = FunctionHasParent.emplace(V, false);
794 
795  // Stop if we've already discovered this node
796  if (!S.second)
797  return;
798 
799  FunctionSummary *F =
800  dyn_cast<FunctionSummary>(V.getSummaryList().front().get());
801  assert(F != nullptr && "Expected FunctionSummary node");
802 
803  for (auto &C : F->calls()) {
804  // Insert node if necessary
805  auto S = FunctionHasParent.emplace(C.first, true);
806 
807  // Skip nodes that we're sure have parents
808  if (!S.second && S.first->second)
809  continue;
810 
811  if (S.second)
812  discoverNodes(C.first, FunctionHasParent);
813  else
814  S.first->second = true;
815  }
816  }
817 
818  // Calculate the callgraph root
820  // Functions that have a parent will be marked in FunctionHasParent pair.
821  // Once we've marked all functions, the functions in the map that are false
822  // have no parent (so they're the roots)
823  std::map<ValueInfo, bool> FunctionHasParent;
824 
825  for (auto &S : *this) {
826  // Skip external functions
827  if (!S.second.SummaryList.size() ||
828  !isa<FunctionSummary>(S.second.SummaryList.front().get()))
829  continue;
830  discoverNodes(ValueInfo(IsAnalysis, &S), FunctionHasParent);
831  }
832 
833  std::vector<FunctionSummary::EdgeTy> Edges;
834  // create edges to all roots in the Index
835  for (auto &P : FunctionHasParent) {
836  if (P.second)
837  continue; // skip over non-root nodes
838  Edges.push_back(std::make_pair(P.first, CalleeInfo{}));
839  }
840  if (Edges.empty()) {
841  // Failed to find root - return an empty node
843  }
844  auto CallGraphRoot = FunctionSummary::makeDummyFunctionSummary(Edges);
845  return CallGraphRoot;
846  }
847 
849  return WithGlobalValueDeadStripping;
850  }
852  WithGlobalValueDeadStripping = true;
853  }
854 
856  return SkipModuleByDistributedBackend;
857  }
859  SkipModuleByDistributedBackend = true;
860  }
861 
862  bool isGlobalValueLive(const GlobalValueSummary *GVS) const {
863  return !WithGlobalValueDeadStripping || GVS->isLive();
864  }
865  bool isGUIDLive(GlobalValue::GUID GUID) const;
866 
867  /// Return a ValueInfo for GUID if it exists, otherwise return ValueInfo().
868  ValueInfo getValueInfo(GlobalValue::GUID GUID) const {
869  auto I = GlobalValueMap.find(GUID);
870  return ValueInfo(IsAnalysis, I == GlobalValueMap.end() ? nullptr : &*I);
871  }
872 
873  /// Return a ValueInfo for \p GUID.
875  return ValueInfo(IsAnalysis, getOrInsertValuePtr(GUID));
876  }
877 
878  /// Return a ValueInfo for \p GUID setting value \p Name.
880  assert(!IsAnalysis);
881  auto VP = getOrInsertValuePtr(GUID);
882  VP->second.U.Name = Name;
883  return ValueInfo(IsAnalysis, VP);
884  }
885 
886  /// Return a ValueInfo for \p GV and mark it as belonging to GV.
887  ValueInfo getOrInsertValueInfo(const GlobalValue *GV) {
888  assert(IsAnalysis);
889  auto VP = getOrInsertValuePtr(GV->getGUID());
890  VP->second.U.GV = GV;
891  return ValueInfo(IsAnalysis, VP);
892  }
893 
894  /// Return the GUID for \p OriginalId in the OidGuidMap.
896  const auto I = OidGuidMap.find(OriginalID);
897  return I == OidGuidMap.end() ? 0 : I->second;
898  }
899 
900  std::set<std::string> &cfiFunctionDefs() { return CfiFunctionDefs; }
901  const std::set<std::string> &cfiFunctionDefs() const { return CfiFunctionDefs; }
902 
903  std::set<std::string> &cfiFunctionDecls() { return CfiFunctionDecls; }
904  const std::set<std::string> &cfiFunctionDecls() const { return CfiFunctionDecls; }
905 
906  /// Add a global value summary for a value of the given name.
908  std::unique_ptr<GlobalValueSummary> Summary) {
909  addGlobalValueSummary(getOrInsertValueInfo(GlobalValue::getGUID(ValueName)),
910  std::move(Summary));
911  }
912 
913  /// Add a global value summary for the given ValueInfo.
914  void addGlobalValueSummary(ValueInfo VI,
915  std::unique_ptr<GlobalValueSummary> Summary) {
916  addOriginalName(VI.getGUID(), Summary->getOriginalName());
917  // Here we have a notionally const VI, but the value it points to is owned
918  // by the non-const *this.
919  const_cast<GlobalValueSummaryMapTy::value_type *>(VI.getRef())
920  ->second.SummaryList.push_back(std::move(Summary));
921  }
922 
923  /// Add an original name for the value of the given GUID.
925  GlobalValue::GUID OrigGUID) {
926  if (OrigGUID == 0 || ValueGUID == OrigGUID)
927  return;
928  if (OidGuidMap.count(OrigGUID) && OidGuidMap[OrigGUID] != ValueGUID)
929  OidGuidMap[OrigGUID] = 0;
930  else
931  OidGuidMap[OrigGUID] = ValueGUID;
932  }
933 
934  /// Find the summary for global \p GUID in module \p ModuleId, or nullptr if
935  /// not found.
937  StringRef ModuleId) const {
938  auto CalleeInfo = getValueInfo(ValueGUID);
939  if (!CalleeInfo) {
940  return nullptr; // This function does not have a summary
941  }
942  auto Summary =
943  llvm::find_if(CalleeInfo.getSummaryList(),
944  [&](const std::unique_ptr<GlobalValueSummary> &Summary) {
945  return Summary->modulePath() == ModuleId;
946  });
947  if (Summary == CalleeInfo.getSummaryList().end())
948  return nullptr;
949  return Summary->get();
950  }
951 
952  /// Returns the first GlobalValueSummary for \p GV, asserting that there
953  /// is only one if \p PerModuleIndex.
955  bool PerModuleIndex = true) const {
956  assert(GV.hasName() && "Can't get GlobalValueSummary for GV with no name");
957  return getGlobalValueSummary(GlobalValue::getGUID(GV.getName()),
958  PerModuleIndex);
959  }
960 
961  /// Returns the first GlobalValueSummary for \p ValueGUID, asserting that
962  /// there
963  /// is only one if \p PerModuleIndex.
964  GlobalValueSummary *getGlobalValueSummary(GlobalValue::GUID ValueGUID,
965  bool PerModuleIndex = true) const;
966 
967  /// Table of modules, containing module hash and id.
969  return ModulePathStringTable;
970  }
971 
972  /// Table of modules, containing hash and id.
974  return ModulePathStringTable;
975  }
976 
977  /// Get the module ID recorded for the given module path.
978  uint64_t getModuleId(const StringRef ModPath) const {
979  return ModulePathStringTable.lookup(ModPath).first;
980  }
981 
982  /// Get the module SHA1 hash recorded for the given module path.
983  const ModuleHash &getModuleHash(const StringRef ModPath) const {
984  auto It = ModulePathStringTable.find(ModPath);
985  assert(It != ModulePathStringTable.end() && "Module not registered");
986  return It->second.second;
987  }
988 
989  /// Convenience method for creating a promoted global name
990  /// for the given value name of a local, and its original module's ID.
991  static std::string getGlobalNameForLocal(StringRef Name, ModuleHash ModHash) {
992  SmallString<256> NewName(Name);
993  NewName += ".llvm.";
994  NewName += utostr((uint64_t(ModHash[0]) << 32) |
995  ModHash[1]); // Take the first 64 bits
996  return NewName.str();
997  }
998 
999  /// Helper to obtain the unpromoted name for a global value (or the original
1000  /// name if not promoted).
1002  std::pair<StringRef, StringRef> Pair = Name.split(".llvm.");
1003  return Pair.first;
1004  }
1005 
1007 
1008  /// Add a new module with the given \p Hash, mapped to the given \p
1009  /// ModID, and return a reference to the module.
1010  ModuleInfo *addModule(StringRef ModPath, uint64_t ModId,
1011  ModuleHash Hash = ModuleHash{{0}}) {
1012  return &*ModulePathStringTable.insert({ModPath, {ModId, Hash}}).first;
1013  }
1014 
1015  /// Check if the given Module has any functions available for exporting
1016  /// in the index. We consider any module present in the ModulePathStringTable
1017  /// to have exported functions.
1018  bool hasExportedFunctions(const Module &M) const {
1019  return ModulePathStringTable.count(M.getModuleIdentifier());
1020  }
1021 
1022  const std::map<std::string, TypeIdSummary> &typeIds() const {
1023  return TypeIdMap;
1024  }
1025 
1026  /// This accessor should only be used when exporting because it can mutate the
1027  /// map.
1029  return TypeIdMap[TypeId];
1030  }
1031 
1032  /// This returns either a pointer to the type id summary (if present in the
1033  /// summary map) or null (if not present). This may be used when importing.
1035  auto I = TypeIdMap.find(TypeId);
1036  if (I == TypeIdMap.end())
1037  return nullptr;
1038  return &I->second;
1039  }
1040 
1041  /// Collect for the given module the list of function it defines
1042  /// (GUID -> Summary).
1043  void collectDefinedFunctionsForModule(StringRef ModulePath,
1044  GVSummaryMapTy &GVSummaryMap) const;
1045 
1046  /// Collect for each module the list of Summaries it defines (GUID ->
1047  /// Summary).
1048  void collectDefinedGVSummariesPerModule(
1049  StringMap<GVSummaryMapTy> &ModuleToDefinedGVSummaries) const;
1050 
1051  /// Export summary to dot file for GraphViz.
1052  void exportToDot(raw_ostream& OS) const;
1053 
1054  /// Print out strongly connected components for debugging.
1055  void dumpSCCs(raw_ostream &OS);
1056 };
1057 
1058 /// GraphTraits definition to build SCC for the index
1059 template <> struct GraphTraits<ValueInfo> {
1060  typedef ValueInfo NodeRef;
1061 
1063  return P.first;
1064  }
1065  using ChildIteratorType =
1067  decltype(&valueInfoFromEdge)>;
1068 
1069  static NodeRef getEntryNode(ValueInfo V) { return V; }
1070 
1071  static ChildIteratorType child_begin(NodeRef N) {
1072  if (!N.getSummaryList().size()) // handle external function
1073  return ChildIteratorType(
1074  FunctionSummary::ExternalNode.CallGraphEdgeList.begin(),
1075  &valueInfoFromEdge);
1076  FunctionSummary *F =
1077  cast<FunctionSummary>(N.getSummaryList().front()->getBaseObject());
1078  return ChildIteratorType(F->CallGraphEdgeList.begin(), &valueInfoFromEdge);
1079  }
1080 
1081  static ChildIteratorType child_end(NodeRef N) {
1082  if (!N.getSummaryList().size()) // handle external function
1083  return ChildIteratorType(
1084  FunctionSummary::ExternalNode.CallGraphEdgeList.end(),
1085  &valueInfoFromEdge);
1086  FunctionSummary *F =
1087  cast<FunctionSummary>(N.getSummaryList().front()->getBaseObject());
1088  return ChildIteratorType(F->CallGraphEdgeList.end(), &valueInfoFromEdge);
1089  }
1090 };
1091 
1092 template <>
1095  std::unique_ptr<GlobalValueSummary> Root =
1096  make_unique<FunctionSummary>(I->calculateCallGraphRoot());
1098  G.SummaryList.push_back(std::move(Root));
1099  static auto P =
1100  GlobalValueSummaryMapTy::value_type(GlobalValue::GUID(0), std::move(G));
1101  return ValueInfo(I->isPerformingAnalysis(), &P);
1102  }
1103 };
1104 
1105 } // end namespace llvm
1106 
1107 #endif // LLVM_IR_MODULESUMMARYINDEX_H
static FunctionSummary::ConstVCall getEmptyKey()
const NoneType None
Definition: None.h:24
uint64_t CallInst * C
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:99
static FunctionSummary::ConstVCall getTombstoneKey()
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
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:492
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
Definition: StringMap.h:126
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.
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:63
GlobalValueSummary * findSummaryInModule(GlobalValue::GUID ValueGUID, StringRef ModuleId) const
Find the summary for global GUID in module ModuleId, or nullptr if not found.
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:335
const StringMap< std::pair< uint64_t, ModuleHash > > & modulePaths() const
Table of modules, containing module hash and id.
GlobalValue::LinkageTypes linkage() const
Return linkage type recorded for this global value.
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
bool isGlobalValueLive(const GlobalValueSummary *GVS) const
F(f)
FunctionSummary(GVFlags Flags, unsigned NumInsts, FFlags FunFlags, 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)
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.
TypeTestResolution TTRes
GlobalValue::GUID getOriginalName()
Returns the hash of the original name, it is identical to the GUID for externally visible symbols...
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.
uint32_t RelBlockFreq
The value stored in RelBlockFreq has to be interpreted as the digits of a scaled number with a scale ...
bool isFromAnalysis() const
unsigned NotEligibleToImport
Indicate if the global value cannot be imported (e.g.
GlobalValue::GUID getGUID() const
bool skipModuleByDistributedBackend() const
Definition: BitVector.h:921
static unsigned getHashValue(FunctionSummary::VFuncId I)
GVFlags flags()
Get the flags for this GlobalValue (see struct GVFlags).
ValueInfo(bool IsAnalysis, const GlobalValueSummaryMapTy::value_type *R)
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...
std::array< uint32_t, 5 > ModuleHash
160 bits SHA1
Just do a regular virtual call.
std::map< GlobalValue::GUID, GlobalValueSummaryInfo > GlobalValueSummaryMapTy
Map from global value GUID to corresponding summary structures.
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:267
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 ...
const std::map< std::string, TypeIdSummary > & typeIds() const
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.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
TypeIdSummary & getOrInsertTypeIdSummary(StringRef TypeId)
This accessor should only be used when exporting because it can mutate the map.
ModulePathStringTableTy::value_type ModuleInfo
Class to hold module path string table and global value map, and encapsulate methods for operating on...
ArrayRef< std::unique_ptr< GlobalValueSummary > > getSummaryList() const
static bool isEqual(FunctionSummary::VFuncId L, FunctionSummary::VFuncId R)
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")
size_type count(StringRef Key) const
count - Return 1 if the element is in the map, 0 otherwise.
Definition: StringMap.h:361
bool hasName() const
Definition: Value.h:251
static bool classof(const GlobalValueSummary *GVS)
Check if this is a global variable summary.
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
const ModuleHash & getModuleHash(const StringRef ModPath) const
Get the module SHA1 hash recorded for the given module path.
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:349
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:874
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:496
const_gvsummary_iterator end() const
const AMDGPUAS & AS
ModuleSummaryIndex(bool IsPerformingAnalysis)
const std::string & getModuleIdentifier() const
Get the module identifier which is, essentially, the name of the module.
Definition: Module.h:208
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.
GlobalValueSummary * getBaseObject()
If this is an alias summary, returns the summary of the aliased object (a global variable or function...
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:727
Single implementation devirtualization.
ValueInfo getOrInsertValueInfo(GlobalValue::GUID GUID, StringRef Name)
Return a ValueInfo for GUID setting value Name.
const DataFlowGraph & G
Definition: RDFGraph.cpp:211
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)
std::string utostr(uint64_t X, bool isNeg=false)
Definition: StringExtras.h:193
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
Definition: StringMap.h:368
static FunctionSummary makeDummyFunctionSummary(std::vector< FunctionSummary::EdgeTy > Edges)
Create an empty FunctionSummary (with specified call edges).
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:48
GUID getGUID() const
Return a 64-bit global unique ID constructed from global value name (i.e.
Definition: GlobalValue.h:500
SummaryKind
Sububclass discriminator (for dyn_cast<> et al.)
PointerIntPair< const GlobalValueSummaryMapTy::value_type *, 1, bool > RefAndFlag
ValueInfo getOrInsertValueInfo(GlobalValue::GUID GUID)
Return a ValueInfo for GUID.
bool withGlobalValueDeadStripping() const
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:1948
Test a byte array (first example)
GlobalVarSummary(GVFlags Flags, std::vector< ValueInfo > Refs)
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.
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...
StringRef getName() const
Return a constant reference to the value&#39;s name.
Definition: Value.cpp:224
GlobalValueSummaryInfo(bool IsAnalysis)
#define I(x, y, z)
Definition: MD5.cpp:58
#define N
GVFlags(GlobalValue::LinkageTypes Linkage, bool NotEligibleToImport, bool Live, bool IsLocal)
Convenience Constructors.
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:323
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)
Function attribute flags.
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.
const unsigned Kind
bool notEligibleToImport() const
Return true if this global value can&#39;t be imported.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
std::set< std::string > & cfiFunctionDecls()
void setAliaseeGUID(GlobalValue::GUID GUID)
bool operator<(int64_t V1, const APSInt &V2)
Definition: APSInt.h:326
ScaledNumber< uint64_t > Scaled64
static FunctionSummary::VFuncId getTombstoneKey()
static ChildIteratorType child_begin(NodeRef N)
gvsummary_iterator end()
void setAliasee(GlobalValueSummary *Aliasee)
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:44
gvsummary_iterator begin()
const GlobalValue::GUID & getAliaseeGUID() const
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
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.
void updateRelBlockFreq(uint64_t BlockFreq, uint64_t EntryFreq)
Update RelBlockFreq from BlockFreq and EntryFreq.
FFlags & fflags()
Get function attribute flags.
iterator end()
Definition: StringMap.h:320
GlobalValueSummaryList SummaryList
List of global value summary structures for a particular value held in the GlobalValueMap.
static FunctionSummary ExternalNode
A dummy node to reference external functions that aren&#39;t in the index.