1//===- llvm/ModuleSummaryIndex.h - Module Summary Index ---------*- C++ -*-===// 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 7//===----------------------------------------------------------------------===// 10/// ModuleSummaryIndex.h This file contains the declarations the classes that 11/// hold the module index and summary for function importing. 13//===----------------------------------------------------------------------===// 15#ifndef LLVM_IR_MODULESUMMARYINDEX_H 16#define LLVM_IR_MODULESUMMARYINDEX_H 44#include <unordered_set> 50template <
class GraphType>
structGraphTraits;
58/// Class to accumulate and hold information about a callee. 68// The size of the bit-field might need to be adjusted if more values are 69// added to HotnessType enum. 72// True if at least one of the calls to the callee is a tail call. 75 /// The value stored in RelBlockFreq has to be interpreted as the digits of 76 /// a scaled number with a scale of \p -ScaleShift. 99 /// Update \p RelBlockFreq from \p BlockFreq and \p EntryFreq 101 /// BlockFreq is divided by EntryFreq and added to RelBlockFreq. To represent 102 /// fractional values, the result is represented as a fixed point number with 103 /// scale of -ScaleShift. 109 Temp /= Scaled64::get(EntryFreq);
134classGlobalValueSummary;
147 /// The GlobalValue corresponding to this summary. This is only used in 148 /// per-module summaries and when the IR is available. E.g. when module 149 /// analysis is being run, or when parsing both the IR and the summary 153 /// Summary string representation. This StringRef points to BC module 154 /// string table and is valid until module data is stored in memory. 155 /// This is guaranteed to happen until runThinLTOBackend function is 156 /// called, so it is safe to use this field during thin link. This field 157 /// is only valid if summary index was loaded from BC file. 163 /// List of global value summary structures for a particular value held 164 /// in the GlobalValueMap. Requires a vector in the case of multiple 165 /// COMDAT values of the same name. 169/// Map from global value GUID to corresponding summary structures. Use a 170/// std::map rather than a DenseMap so that pointers to the map's value_type 171/// (which are used by ValueInfo) are not invalidated by insertion. Also it will 172/// likely incur less overhead, as the value type is not very small and the size 173/// of the map is unknown, resulting in inefficiencies due to repeated 174/// insertions and resizing. 176 std::map<GlobalValue::GUID, GlobalValueSummaryInfo>;
178/// Struct that holds a reference to a particular GUID in a global value 186ValueInfo(
bool HaveGVs,
const GlobalValueSummaryMapTy::value_type *R) {
196returngetRef()->second.U.GV;
200returngetRef()->second.SummaryList;
203// Even if the index is built with GVs available, we may not have one for 204// summary entries synthesized for profiled indirect call targets. 231// We expect ro/wo attribute to set only once during 232// ValueInfo lifetime. 241const GlobalValueSummaryMapTy::value_type *
getRef()
const{
245 /// Returns the most constraining visibility among summaries. The 246 /// visibilities, ordered from least to most constraining, are: default, 247 /// protected and hidden. 250 /// Checks if all summaries are DSO local (have the flag set). When DSOLocal 251 /// propagation has been done, set the parameter to enable fast check. 252boolisDSOLocal(
bool WithDSOLocalPropagation =
false)
const;
254 /// Checks if all copies are eligible for auto-hiding (have flag set). 260if (!VI.name().empty())
261OS <<
" (" << VI.name() <<
")";
267"Need ValueInfo with non-null Ref for comparison");
268returnA.getRef() ==
B.getRef();
273"Need ValueInfo with non-null Ref for comparison");
274returnA.getRef() !=
B.getRef();
279"Need ValueInfo with non-null Ref to compare GUIDs");
280returnA.getGUID() <
B.getGUID();
285returnValueInfo(
false, (GlobalValueSummaryMapTy::value_type *)-8);
289returnValueInfo(
false, (GlobalValueSummaryMapTy::value_type *)-16);
293return V == getTombstoneKey() || V == getEmptyKey();
297// We are not supposed to mix ValueInfo(s) with different HaveGVs flag 298// in a same container. 299assert(isSpecialKey(L) || isSpecialKey(R) || (L.haveGVs() == R.haveGVs()));
300return L.getRef() == R.getRef();
305// For optional hinted size reporting, holds a pair of the full stack id 306// (pre-trimming, from the full context in the profile), and the associated 307// total profiled size. 313/// Summary of memprof callsite metadata. 315// Actual callee function. 318// Used to record whole program analysis cloning decisions. 319// The ThinLTO backend will need to create as many clones as there are entries 320// in the vector (it is expected and should be confirmed that all such 321// summaries in the same FunctionSummary have the same number of entries). 322// Each index records version info for the corresponding clone of this 323// function. The value is the callee clone it calls (becomes the appended 324// suffix id). Index 0 is the original version, and a value of 0 calls the 328// Represents stack ids in this context, recorded as indices into the 329// StackIds vector in the summary index, which in turn holds the full 64-bit 330// stack ids. This reduces memory as there are in practice far fewer unique 331// stack ids than stack id references. 346for (
auto V : SNI.
Clones) {
363// Allocation type assigned to an allocation reached by a given context. 364// More can be added, now this is cold, notcold and hot. 365// Values should be powers of two so that they can be ORed, in particular to 366// track allocations that have different behavior with different calling 373All = 7
// This should always be set to the OR of all values. 376/// Summary of a single MIB in a memprof metadata on allocations. 378// The allocation type for this profiled context. 381// Represents stack ids in this context, recorded as indices into the 382// StackIds vector in the summary index, which in turn holds the full 64-bit 383// stack ids. This reduces memory as there are in practice far fewer unique 384// stack ids than stack id references. 404/// Summary of memprof metadata on allocations. 406// Used to record whole program analysis cloning decisions. 407// The ThinLTO backend will need to create as many clones as there are entries 408// in the vector (it is expected and should be confirmed that all such 409// summaries in the same FunctionSummary have the same number of entries). 410// Each index records version info for the corresponding clone of this 411// function. The value is the allocation type of the corresponding allocation. 412// Index 0 is the original version. Before cloning, index 0 may have more than 413// one allocation type. 416// Vector of MIBs in this memprof metadata. 419// If requested, keep track of full stack contexts and total profiled sizes 420// for each MIB. This will be a vector of the same length and order as the 421// MIBs vector, if non-empty. Note that each MIB in the summary can have 422// multiple of these as we trim the contexts when possible during matching. 423// For hinted size reporting we, however, want the original pre-trimmed full 424// stack context id for better correlation with the profile. 444for (
auto &M : AE.
MIBs) {
445OS <<
"\t\t" << M <<
"\n";
448OS <<
"\tContextSizeInfo per MIB:\n";
452for (
auto [FullStackId, TotalSize] : Infos) {
456OS <<
"{ " << FullStackId <<
", " << TotalSize <<
" }";
464/// Function and variable summary information to aid decisions and 465/// implementation of importing. 468 /// Sububclass discriminator (for dyn_cast<> et al.) 472// The global value definition corresponding to the summary should be 473// imported from source module 476// When its definition doesn't exist in the destination module and not 477// imported (e.g., function is too large to be inlined), the global value 478// declaration corresponding to the summary should be imported, or the 479// attributes from summary should be annotated on the function declaration. 483 /// Group flags (Linkage, NotEligibleToImport, etc.) as a bitfield. 485 /// The linkage type of the associated global value. 487 /// One use is to flag values that have local linkage types and need to 488 /// have module identifier appended before placing into the combined 489 /// index, to disambiguate from other values with the same name. 490 /// In the future this will be used to update and optimize linkage 491 /// types based on global summary-based analysis. 494 /// Indicates the visibility. 497 /// Indicate if the global value cannot be imported (e.g. it cannot 498 /// be renamed or references something that can't be renamed). 501 /// In per-module summary, indicate that the global value must be considered 502 /// a live root for index-based liveness analysis. Used for special LLVM 503 /// values such as llvm.global_ctors that the linker does not know about. 505 /// In combined summary, indicate that the global value is live. 508 /// Indicates that the linker resolved the symbol to a definition from 509 /// within the same linkage unit. 512 /// In the per-module summary, indicates that the global value is 513 /// linkonce_odr and global unnamed addr (so eligible for auto-hiding 514 /// via hidden visibility). In the combined summary, indicates that the 515 /// prevailing linkonce_odr copy can be auto-hidden via hidden visibility 516 /// when it is upgraded to weak_odr in the backend. This is legal when 517 /// all copies are eligible for auto-hiding (i.e. all copies were 518 /// linkonce_odr global unnamed addr. If any copy is not (e.g. it was 519 /// originally weak_odr, we cannot auto-hide the prevailing copy as it 520 /// means the symbol was externally visible. 523 /// This field is written by the ThinLTO indexing step to postlink combined 524 /// summary. The value is interpreted as 'ImportKind' enum defined above. 527 /// Convenience Constructors 539 /// Kind of summary for use in dyn_cast<> et al. 544 /// This is the hash of the name of the symbol in the original file. It is 545 /// identical to the GUID for global symbols, but differs for local since the 546 /// GUID includes the module level id in the hash. 549 /// Path of module IR containing value's definition, used to locate 550 /// module during importing. 552 /// This is only used during parsing of the combined index, or when 553 /// parsing the per-module index for creation of the combined summary index, 554 /// not during writing of the per-module index which doesn't contain a 555 /// module path string table. 558 /// List of values referenced by this global value's definition 559 /// (either by the initializer of a global variable, or referenced 560 /// from within a function). This does not include functions called, which 561 /// are listed in the derived FunctionSummary object. 562 /// We use SmallVector<ValueInfo, 0> instead of std::vector<ValueInfo> for its 563 /// smaller memory footprint. 569 : Kind(K), Flags(Flags), RefEdgeList(
std::
move(Refs)) {
571"Expect no references for AliasSummary");
577 /// Returns the hash of the original name, it is identical to the GUID for 578 /// externally visible symbols, but not for local ones. 581 /// Initialize the original name hash in this summary. 584 /// Which kind of summary subclass this is. 587 /// Set the path to the module containing this function, for use in 588 /// the combined index. 591 /// Get the path to the module containing this function. 594 /// Get the flags for this GlobalValue (see \p struct GVFlags). 597 /// Return linkage type recorded for this global value. 602 /// Sets the linkage to the value determined by global summary-based 603 /// optimization. Will be applied in the ThinLTO backends. 608 /// Return true if this global value can't be imported. 630returnstatic_cast<ImportKind>(Flags.ImportType);
640 /// Flag that this global value cannot be imported. 643 /// Return the list of values referenced by this global value definition. 646 /// If this is an alias summary, returns the summary of the aliased object (a 647 /// global variable or function), otherwise returns itself. 656/// Alias summary information. 660 /// This is the Aliasee in the same module as alias (could get from VI, trades 661 /// memory for time). Note that this pointer may be null (and the value info 662 /// empty) when we have a distributed index where the alias is being imported 663 /// (as a copy of the aliasee), but the aliasee is not. 670 /// Check if this is an alias summary. 676 AliaseeValueInfo = AliaseeVI;
677 AliaseeSummary = Aliasee;
681assert(!!AliaseeSummary == (AliaseeValueInfo &&
683"Expect to have both aliasee summary and summary list or neither");
684return !!AliaseeSummary;
688assert(AliaseeSummary &&
"Unexpected missing aliasee summary");
689return *AliaseeSummary;
697assert(AliaseeValueInfo &&
"Unexpected missing aliasee");
698return AliaseeValueInfo;
701assert(AliaseeValueInfo &&
"Unexpected missing aliasee");
702return AliaseeValueInfo.
getGUID();
707if (
auto *AS = dyn_cast<AliasSummary>(
this))
708return &AS->getAliasee();
713if (
auto *AS = dyn_cast<AliasSummary>(
this))
714return &AS->getAliasee();
718/// Function summary information to aid decisions and implementation of 722 /// <CalleeValueInfo, CalleeInfo> call edge pair. 723usingEdgeTy = std::pair<ValueInfo, CalleeInfo>;
725 /// Types for -force-summary-edges-cold debugging option. 732 /// An "identifier" for a virtual function. This contains the type identifier 733 /// represented as a GUID and the offset from the address point to the virtual 734 /// function pointer, where "address point" is as defined in the Itanium ABI: 735 /// https://itanium-cxx-abi.github.io/cxx-abi/abi.html#vtable-general 741 /// A specification for a virtual function call with all constant integer 742 /// arguments. This is used to perform virtual constant propagation on the 749 /// All type identifier related information. Because these fields are 750 /// relatively uncommon we only allocate space for them if necessary. 752 /// List of type identifiers used by this function in llvm.type.test 753 /// intrinsics referenced by something other than an llvm.assume intrinsic, 754 /// represented as GUIDs. 757 /// List of virtual calls made by this function using (respectively) 758 /// llvm.assume(llvm.type.test) or llvm.type.checked.load intrinsics that do 759 /// not have all constant integer arguments. 762 /// List of virtual calls made by this function using (respectively) 763 /// llvm.assume(llvm.type.test) or llvm.type.checked.load intrinsics with 764 /// all constant integer arguments. 769 /// Flags specific to function summaries. 771// Function attribute flags. Used to track if a function accesses memory, 772// recurses or aliases. 778// Indicate if the global value cannot be inlined. 780// Indicate if function should be always inlined. 782// Indicate if function never raises an exception. Can be modified during 783// thinlink function attribute propagation 785// Indicate if function contains instructions that mayThrow 788// If there are calls to unknown targets (e.g. indirect) 791// Indicate if a function must be an unreachable function. 793// This bit is sufficient but not necessary; 794// if this bit is on, the function must be regarded as unreachable; 795// if this bit is off, the function might be reachable or unreachable. 819operator std::string() {
824 OS <<
", readOnly: " << this->
ReadOnly;
827 OS <<
", noInline: " << this->
NoInline;
829 OS <<
", noUnwind: " << this->
NoUnwind;
830 OS <<
", mayThrow: " << this->
MayThrow;
838 /// Describes the uses of a parameter by the function. 842 /// Describes the use of a value in a call instruction, specifying the 843 /// call's target, the value's parameter number, and the possible range of 844 /// offsets from the beginning of the value that are passed. 856 /// The range contains byte offsets from the parameter pointer which 857 /// accessed by the function. In the per-module summary, it only includes 858 /// accesses made by the function instructions. In the combined summary, it 859 /// also includes accesses by nested function calls. 861 /// In the per-module summary, it summarizes the byte offset applied to each 862 /// pointer parameter before passing to each corresponding callee. 863 /// In the combined summary, it's empty and information is propagated by 864 /// inter-procedural analysis and applied to the Use field. 872 /// Create an empty FunctionSummary (with specified call edges). 873 /// Used to represent external nodes and the dummy root node. 880/*NotEligibleToImport=*/true,
/*Live=*/true,
/*IsLocal=*/false,
883 std::move(Edges), std::vector<GlobalValue::GUID>(),
884 std::vector<FunctionSummary::VFuncId>(),
885 std::vector<FunctionSummary::VFuncId>(),
886 std::vector<FunctionSummary::ConstVCall>(),
887 std::vector<FunctionSummary::ConstVCall>(),
888 std::vector<FunctionSummary::ParamAccess>(),
889 std::vector<CallsiteInfo>(), std::vector<AllocInfo>());
892 /// A dummy node to reference external functions that aren't in the index 896 /// Number of instructions (ignoring debug instructions, e.g.) computed 897 /// during the initial compile step when the summary index is first built. 900 /// Function summary specific flags. 903 /// List of <CalleeValueInfo, CalleeInfo> call edge pairs from this function. 904 /// We use SmallVector<ValueInfo, 0> instead of std::vector<ValueInfo> for its 905 /// smaller memory footprint. 908 std::unique_ptr<TypeIdInfo> TIdInfo;
910 /// Uses for every parameter to this function. 911usingParamAccessesTy = std::vector<ParamAccess>;
912 std::unique_ptr<ParamAccessesTy> ParamAccesses;
914 /// Optional list of memprof callsite metadata summaries. The correspondence 915 /// between the callsite summary and the callsites in the function is implied 916 /// by the order in the vector (and can be validated by comparing the stack 917 /// ids in the CallsiteInfo to those in the instruction callsite metadata). 918 /// As a memory savings optimization, we only create these for the prevailing 919 /// copy of a symbol when creating the combined index during LTO. 920usingCallsitesTy = std::vector<CallsiteInfo>;
921 std::unique_ptr<CallsitesTy> Callsites;
923 /// Optional list of allocation memprof metadata summaries. The correspondence 924 /// between the alloc memprof summary and the allocation callsites in the 925 /// function is implied by the order in the vector (and can be validated by 926 /// comparing the stack ids in the AllocInfo to those in the instruction 927 /// memprof metadata). 928 /// As a memory savings optimization, we only create these for the prevailing 929 /// copy of a symbol when creating the combined index during LTO. 930usingAllocsTy = std::vector<AllocInfo>;
931 std::unique_ptr<AllocsTy> Allocs;
937 std::vector<GlobalValue::GUID> TypeTests,
938 std::vector<VFuncId> TypeTestAssumeVCalls,
939 std::vector<VFuncId> TypeCheckedLoadVCalls,
940 std::vector<ConstVCall> TypeTestAssumeConstVCalls,
941 std::vector<ConstVCall> TypeCheckedLoadConstVCalls,
942 std::vector<ParamAccess> Params, CallsitesTy CallsiteList,
945 InstCount(NumInsts), FunFlags(FunFlags),
946 CallGraphEdgeList(
std::
move(CGEdges)) {
947if (!TypeTests.empty() || !TypeTestAssumeVCalls.empty() ||
948 !TypeCheckedLoadVCalls.empty() || !TypeTestAssumeConstVCalls.empty() ||
949 !TypeCheckedLoadConstVCalls.empty())
950 TIdInfo = std::make_unique<TypeIdInfo>(
951TypeIdInfo{std::move(TypeTests), std::move(TypeTestAssumeVCalls),
952 std::move(TypeCheckedLoadVCalls),
953 std::move(TypeTestAssumeConstVCalls),
954 std::move(TypeCheckedLoadConstVCalls)});
956 ParamAccesses = std::make_unique<ParamAccessesTy>(std::move(Params));
957if (!CallsiteList.empty())
958 Callsites = std::make_unique<CallsitesTy>(std::move(CallsiteList));
959if (!AllocList.empty())
960 Allocs = std::make_unique<AllocsTy>(std::move(AllocList));
962// Gets the number of readonly and writeonly refs in RefEdgeList 965 /// Check if this is a function summary. 970 /// Get function summary flags. 977 /// Get the instruction count recorded for this function. 980 /// Return the list of <CalleeValueInfo, CalleeInfo> pairs. 987 /// Returns the list of type identifiers used by this function in 988 /// llvm.type.test intrinsics other than by an llvm.assume intrinsic, 989 /// represented as GUIDs. 992return TIdInfo->TypeTests;
996 /// Returns the list of virtual calls made by this function using 997 /// llvm.assume(llvm.type.test) intrinsics that do not have all constant 998 /// integer arguments. 1001return TIdInfo->TypeTestAssumeVCalls;
1005 /// Returns the list of virtual calls made by this function using 1006 /// llvm.type.checked.load intrinsics that do not have all constant integer 1010return TIdInfo->TypeCheckedLoadVCalls;
1014 /// Returns the list of virtual calls made by this function using 1015 /// llvm.assume(llvm.type.test) intrinsics with all constant integer 1019return TIdInfo->TypeTestAssumeConstVCalls;
1023 /// Returns the list of virtual calls made by this function using 1024 /// llvm.type.checked.load intrinsics with all constant integer arguments. 1027return TIdInfo->TypeCheckedLoadConstVCalls;
1031 /// Returns the list of known uses of pointer parameters. 1034return *ParamAccesses;
1038 /// Sets the list of known uses of pointer parameters. 1040if (NewParams.empty())
1041 ParamAccesses.reset();
1042elseif (ParamAccesses)
1043 *ParamAccesses = std::move(NewParams);
1045 ParamAccesses = std::make_unique<ParamAccessesTy>(std::move(NewParams));
1048 /// Add a type test to the summary. This is used by WholeProgramDevirt if we 1049 /// were unable to devirtualize a checked call. 1052 TIdInfo = std::make_unique<TypeIdInfo>();
1053 TIdInfo->TypeTests.push_back(
Guid);
1071 Callsites = std::make_unique<CallsitesTy>();
1072 Callsites->push_back(Callsite);
1097return L.GUID == R.GUID && L.Offset == R.Offset;
1123/// The ValueInfo and offset for a function within a vtable definition 1124/// initializer array. 1132/// List of functions referenced by a particular vtable definition. 1135/// Global variable summary information to aid decisions and 1136/// implementation of importing. 1138/// Global variable summary has two extra flag, telling if it is 1139/// readonly or writeonly. Both readonly and writeonly variables 1140/// can be optimized in the backed: readonly variables can be 1141/// const-folded, while writeonly vars can be completely eliminated 1142/// together with corresponding stores. We let both things happen 1143/// by means of internalizing such variables after ThinLTO import. 1146 /// For vtable definitions this holds the list of functions and 1147 /// their corresponding offsets within the initializer array. 1148 std::unique_ptr<VTableFuncList> VTableFuncs;
1157// If true indicates that this global variable might be accessed 1158// purely by non-volatile load instructions. This in turn means 1159// it can be internalized in source and destination modules during 1160// thin LTO import because it neither modified nor its address 1163// If true indicates that variable is possibly only written to, so 1164// its value isn't loaded and its address isn't taken anywhere. 1165// False, when 'Constant' attribute is set. 1167// Indicates that value is a compile-time constant. Global variable 1168// can be 'Constant' while not being 'ReadOnly' on several occasions: 1169// - it is volatile, (e.g mapped device address) 1170// - its address is taken, meaning that unlike 'ReadOnly' vars we can't 1172// Constant variables are always imported thus giving compiler an 1173// opportunity to make some extra optimizations. Readonly constants 1174// are also internalized. 1176// Set from metadata on vtable definitions during the module summary 1186 /// Check if this is a global variable summary. 1206 VTableFuncs = std::make_unique<VTableFuncList>(std::move(Funcs));
1217 /// Specifies which kind of type check we should emit for this byte array. 1218 /// See http://clang.llvm.org/docs/ControlFlowIntegrityDesign.html for full 1219 /// details on each kind of check; the enumerators are described with 1220 /// reference to that document. 1222Unsat,
///< Unsatisfiable type (i.e. no global has this type metadata) 1224Inline,
///< Inlined bit vector ("Short Inline Bit Vectors") 1225Single,
///< Single element (last example in "Short Inline Bit Vectors") 1226AllOnes,
///< All-ones bit vector ("Eliminating Bit Vector Checks for 1227 /// All-Ones Bit Vectors") 1228Unknown,
///< Unknown (analysis not performed, don't lower) 1231 /// Range of size-1 expressed as a bit width. For example, if the size is in 1232 /// range [1,256], this number will be 8. This helps generate the most compact 1233 /// instruction sequences. 1236// The following fields are only used if the target does not support the use 1237// of absolute symbols to store constants. Their meanings are the same as the 1238// corresponding fields in LowerTypeTestsModule::TypeIdLowering in 1239// LowerTypeTests.cpp. 1249Indir,
///< Just do a regular virtual call 1251BranchFunnel,
///< When retpoline mitigation is enabled, use a branch funnel 1252 ///< that is defined in the merged module. Otherwise same as 1260Indir,
///< Just do a regular virtual call 1266 /// Additional information for the resolution: 1267 /// - UniformRetVal: the uniform return value. 1268 /// - UniqueRetVal: the return value associated with the unique vtable (0 or 1272// The following fields are only used if the target does not support the use 1273// of absolute symbols to store constants. 1279 /// Resolutions for calls with all constant integer arguments (excluding the 1280 /// first argument, "this"), where the key is the argument vector. 1287 /// Mapping from byte offset to whole-program devirt resolution for that 1288 /// (typeid, byte offset) pair. 1289 std::map<uint64_t, WholeProgramDevirtResolution>
WPDRes;
1295/// Type used for iterating through the global value summary map. 1299/// String table to hold/own module path strings, as well as a hash 1300/// of the module. The StringMap makes a copy of and owns inserted strings. 1303/// Map of global value GUID to its summary, used to identify values defined in 1304/// a particular module, and provide efficient access to their summary. 1307/// Map of a module name to the GUIDs and summaries we will import from that 1310 std::map<std::string, GVSummaryMapTy, std::less<>>;
1312/// A set of global value summary pointers. 1315/// Map of a type GUID to type id string and summary (multimap used 1316/// in case of GUID conflicts). 1318 std::multimap<GlobalValue::GUID, std::pair<StringRef, TypeIdSummary>>;
1320/// The following data structures summarize type metadata information. 1321/// For type metadata overview see https://llvm.org/docs/TypeMetadata.html. 1322/// Each type metadata includes both the type identifier and the offset of 1323/// the address point of the type (the address held by objects of that type 1324/// which may not be the beginning of the virtual table). Vtable definitions 1325/// are decorated with type metadata for the types they are compatible with. 1327/// Holds information about vtable definitions decorated with type metadata: 1328/// the vtable definition value and its address point offset in a type 1329/// identifier metadata it is decorated (compatible) with. 1337/// List of vtable definitions decorated by a particular type identifier, 1338/// and their corresponding offsets in that type identifier's metadata. 1339/// Note that each type identifier may be compatible with multiple vtables, due 1340/// to inheritance, which is why this is a vector. 1343/// Class to hold module path string table and global value map, 1344/// and encapsulate methods for operating on them. 1347 /// Map from value name to list of summary instances for values of that 1348 /// name (may be duplicates in the COMDAT case, e.g.). 1351 /// Holds strings for combined index, mapping to the corresponding module ID. 1357 /// Mapping from type identifier GUIDs to type identifier and its summary 1358 /// information. Produced by thin link. 1361 /// Mapping from type identifier to information about vtables decorated 1362 /// with that type identifier's metadata. Produced by per module summary 1363 /// analysis and consumed by thin link. For more information, see description 1364 /// above where TypeIdCompatibleVtableInfo is defined. 1365 std::map<StringRef, TypeIdCompatibleVtableInfo, std::less<>>
1366 TypeIdCompatibleVtableMap;
1368 /// Mapping from original ID to GUID. If original ID can map to multiple 1369 /// GUIDs, it will be mapped to 0. 1372 /// Indicates that summary-based GlobalValue GC has run, and values with 1373 /// GVFlags::Live==false are really dead. Otherwise, all values must be 1374 /// considered live. 1375bool WithGlobalValueDeadStripping =
false;
1377 /// Indicates that summary-based attribute propagation has run and 1378 /// GVarFlags::MaybeReadonly / GVarFlags::MaybeWriteonly are really 1379 /// read/write only. 1380bool WithAttributePropagation =
false;
1382 /// Indicates that summary-based DSOLocal propagation has run and the flag in 1383 /// every summary of a GV is synchronized. 1384bool WithDSOLocalPropagation =
false;
1386 /// Indicates that we have whole program visibility. 1387bool WithWholeProgramVisibility =
false;
1389 /// Indicates that summary-based synthetic entry count propagation has run 1390bool HasSyntheticEntryCounts =
false;
1392 /// Indicates that we linked with allocator supporting hot/cold new operators. 1393bool WithSupportsHotColdNew =
false;
1395 /// Indicates that distributed backend should skip compilation of the 1396 /// module. Flag is suppose to be set by distributed ThinLTO indexing 1397 /// when it detected that the module is not needed during the final 1398 /// linking. As result distributed backend should just output a minimal 1399 /// valid object file. 1400bool SkipModuleByDistributedBackend =
false;
1402 /// If true then we're performing analysis of IR module, or parsing along with 1403 /// the IR from assembly. The value of 'false' means we're reading summary 1404 /// from BC or YAML source. Affects the type of value stored in NameOrGV 1408// True if the index was created for a module compiled with -fsplit-lto-unit. 1409bool EnableSplitLTOUnit;
1411// True if the index was created for a module compiled with -funified-lto 1414// True if some of the modules were compiled with -fsplit-lto-unit and 1415// some were not. Set when the combined index is created during the thin link. 1416bool PartiallySplitLTOUnits =
false;
1418 /// True if some of the FunctionSummary contains a ParamAccess. 1419bool HasParamAccess =
false;
1421 std::set<std::string, std::less<>> CfiFunctionDefs;
1422 std::set<std::string, std::less<>> CfiFunctionDecls;
1424// Used in cases where we want to record the name of a global, but 1425// don't have the string owned elsewhere (e.g. the Strtab on a module). 1429// The total number of basic blocks in the module in the per-module summary or 1430// the total number of basic blocks in the LTO unit in the combined index. 1431// FIXME: Putting this in the distributed ThinLTO index files breaks LTO 1432// backend caching on any BB change to any linked file. It is currently not 1433// used except in the case of a SamplePGO partial profile, and should be 1434// reevaluated/redesigned to allow more effective incremental builds in that 1438// List of unique stack ids (hashes). We use a 4B index of the id in the 1439// stack id lists on the alloc and callsite summaries for memory savings, 1440// since the number of unique ids is in practice much smaller than the 1441// number of stack id references in the summaries. 1442 std::vector<uint64_t> StackIds;
1444// Temporary map while building StackIds list. Clear when index is completely 1445// built via releaseTemporaryMemory. 1451 GlobalValueSummaryMapTy::value_type *
1458// See HaveGVs variable comment. 1460bool UnifiedLTO =
false)
1461 : TypeIdSaver(TypeIdSaverAlloc), HaveGVs(HaveGVs),
1462 EnableSplitLTOUnit(EnableSplitLTOUnit), UnifiedLTO(UnifiedLTO),
1465// Current version for the module summary in bitcode files. 1466// The BitcodeSummaryVersion should be bumped whenever we introduce changes 1467// in the way some record are interpreted, like flags for instance. 1468// Note that incrementing this may require changes in both BitcodeReader.cpp 1469// and BitcodeWriter.cpp. 1472// Regular LTO module name for ASM writer 1474return"[Regular LTO]";
1490size_tsize()
const{
return GlobalValueMap.size(); }
1492const std::vector<uint64_t> &
stackIds()
const{
return StackIds; }
1495auto Inserted = StackIdToIndex.
insert({StackId, StackIds.size()});
1497 StackIds.push_back(StackId);
1498return Inserted.first->second;
1503return StackIds[
Index];
1506// Facility to release memory from data structures only needed during index 1507// construction (including while building combined index). Currently this only 1508// releases the temporary map used while constructing a correspondence between 1509// stack ids and their index in the StackIds vector. Mostly impactful when 1510// building a large combined index. 1512assert(StackIdToIndex.
size() == StackIds.size());
1513 StackIdToIndex.
clear();
1514 StackIds.shrink_to_fit();
1517 /// Convenience function for doing a DFS on a ValueInfo. Marks the function in 1518 /// the FunctionHasParent map. 1520 std::map<ValueInfo, bool> &FunctionHasParent) {
1521if (!V.getSummaryList().size())
1522return;
// skip external functions that don't have summaries 1524// Mark discovered if we haven't yet 1525auto S = FunctionHasParent.emplace(V,
false);
1527// Stop if we've already discovered this node 1532 dyn_cast<FunctionSummary>(V.getSummaryList().front().get());
1533assert(
F !=
nullptr &&
"Expected FunctionSummary node");
1535for (
constauto &
C :
F->calls()) {
1536// Insert node if necessary 1537auto S = FunctionHasParent.emplace(
C.first,
true);
1539// Skip nodes that we're sure have parents 1540if (!S.second && S.first->second)
1546 S.first->second =
true;
1550// Calculate the callgraph root 1552// Functions that have a parent will be marked in FunctionHasParent pair. 1553// Once we've marked all functions, the functions in the map that are false 1554// have no parent (so they're the roots) 1555 std::map<ValueInfo, bool> FunctionHasParent;
1557for (
auto &S : *
this) {
1558// Skip external functions 1559if (!S.second.SummaryList.size() ||
1560 !isa<FunctionSummary>(S.second.SummaryList.front().get()))
1566// create edges to all roots in the Index 1567for (
auto &
P : FunctionHasParent) {
1569continue;
// skip over non-root nodes 1576return WithGlobalValueDeadStripping;
1579 WithGlobalValueDeadStripping =
true;
1584 WithAttributePropagation =
true;
1604return SkipModuleByDistributedBackend;
1607 SkipModuleByDistributedBackend =
true;
1622return !WithGlobalValueDeadStripping || GVS->
isLive();
1626 /// Return a ValueInfo for the index value_type (convenient when iterating 1632 /// Return a ValueInfo for GUID if it exists, otherwise return ValueInfo(). 1634autoI = GlobalValueMap.find(GUID);
1635returnValueInfo(HaveGVs,
I == GlobalValueMap.end() ?
nullptr : &*
I);
1638 /// Return a ValueInfo for \p GUID. 1640returnValueInfo(HaveGVs, getOrInsertValuePtr(GUID));
1643// Save a string in the Index. Use before passing Name to 1644// getOrInsertValueInfo when the string isn't owned elsewhere (e.g. on the 1648 /// Return a ValueInfo for \p GUID setting value \p Name. 1651auto VP = getOrInsertValuePtr(GUID);
1652 VP->second.U.Name =
Name;
1656 /// Return a ValueInfo for \p GV and mark it as belonging to GV. 1659auto VP = getOrInsertValuePtr(GV->
getGUID());
1660 VP->second.U.GV = GV;
1664 /// Return the GUID for \p OriginalId in the OidGuidMap. 1666constautoI = OidGuidMap.
find(OriginalID);
1667returnI == OidGuidMap.
end() ? 0 :
I->second;
1671return CfiFunctionDefs;
1674return CfiFunctionDefs;
1678return CfiFunctionDecls;
1681return CfiFunctionDecls;
1684 /// Add a global value summary for a value. 1686 std::unique_ptr<GlobalValueSummary> Summary) {
1690 /// Add a global value summary for a value of the given name. 1692 std::unique_ptr<GlobalValueSummary> Summary) {
1694 std::move(Summary));
1697 /// Add a global value summary for the given ValueInfo. 1699 std::unique_ptr<GlobalValueSummary> Summary) {
1700if (
constFunctionSummary *FS = dyn_cast<FunctionSummary>(Summary.get()))
1701 HasParamAccess |= !FS->paramAccesses().empty();
1703// Here we have a notionally const VI, but the value it points to is owned 1704// by the non-const *this. 1705const_cast<GlobalValueSummaryMapTy::value_type *
>(VI.getRef())
1706 ->second.SummaryList.push_back(std::move(Summary));
1709 /// Add an original name for the value of the given GUID. 1712if (OrigGUID == 0 || ValueGUID == OrigGUID)
1714auto [It, Inserted] = OidGuidMap.
try_emplace(OrigGUID, ValueGUID);
1715if (!Inserted && It->second != ValueGUID)
1719 /// Find the summary for ValueInfo \p VI in module \p ModuleId, or nullptr if 1722auto SummaryList = VI.getSummaryList();
1725 [&](
const std::unique_ptr<GlobalValueSummary> &Summary) {
1726return Summary->modulePath() == ModuleId;
1728if (Summary == SummaryList.end())
1730return Summary->get();
1733 /// Find the summary for global \p GUID in module \p ModuleId, or nullptr if 1739returnnullptr;
// This function does not have a summary 1743 /// Returns the first GlobalValueSummary for \p GV, asserting that there 1744 /// is only one if \p PerModuleIndex. 1746bool PerModuleIndex =
true)
const{
1747assert(GV.
hasName() &&
"Can't get GlobalValueSummary for GV with no name");
1751 /// Returns the first GlobalValueSummary for \p ValueGUID, asserting that 1753 /// is only one if \p PerModuleIndex. 1755bool PerModuleIndex =
true)
const;
1757 /// Table of modules, containing module hash and id. 1759return ModulePathStringTable;
1762 /// Table of modules, containing hash and id. 1765 /// Get the module SHA1 hash recorded for the given module path. 1767auto It = ModulePathStringTable.
find(ModPath);
1768assert(It != ModulePathStringTable.
end() &&
"Module not registered");
1772 /// Convenience method for creating a promoted global name 1773 /// for the given value name of a local, and its original module's ID. 1775 std::string Suffix = utostr((
uint64_t(ModHash[0]) << 32) |
1776 ModHash[1]);
// Take the first 64 bits 1784return std::string(NewName);
1787 /// Helper to obtain the unpromoted name for a global value (or the original 1788 /// name if not promoted). Split off the rightmost ".llvm.${hash}" suffix, 1789 /// because it is possible in certain clients (not clang at the moment) for 1790 /// two rounds of ThinLTO optimization and therefore promotion to occur. 1792 std::pair<StringRef, StringRef> Pair =
Name.rsplit(
".llvm.");
1798 /// Add a new module with the given \p Hash, mapped to the given \p 1799 /// ModID, and return a reference to the module. 1801return &*ModulePathStringTable.
insert({ModPath, Hash}).first;
1804 /// Return module entry for module with the given \p ModPath. 1806auto It = ModulePathStringTable.
find(ModPath);
1807assert(It != ModulePathStringTable.
end() &&
"Module not registered");
1811 /// Return module entry for module with the given \p ModPath. 1813auto It = ModulePathStringTable.
find(ModPath);
1814assert(It != ModulePathStringTable.
end() &&
"Module not registered");
1818 /// Check if the given Module has any functions available for exporting 1819 /// in the index. We consider any module present in the ModulePathStringTable 1820 /// to have exported functions. 1822return ModulePathStringTable.
count(M.getModuleIdentifier());
1827 /// Return an existing or new TypeIdSummary entry for \p TypeId. 1828 /// This accessor can mutate the map and therefore should not be used in 1829 /// the ThinLTO backends. 1832for (
auto &[GUID, TypeIdPair] :
make_range(TidIter))
1833if (TypeIdPair.first == TypeId)
1834return TypeIdPair.second;
1837return It->second.second;
1840 /// This returns either a pointer to the type id summary (if present in the 1841 /// summary map) or null (if not present). This may be used when importing. 1844for (
constauto &[GUID, TypeIdPair] :
make_range(TidIter))
1845if (TypeIdPair.first == TypeId)
1846return &TypeIdPair.second;
1857return TypeIdCompatibleVtableMap;
1860 /// Return an existing or new TypeIdCompatibleVtableMap entry for \p TypeId. 1861 /// This accessor can mutate the map and therefore should not be used in 1862 /// the ThinLTO backends. 1865return TypeIdCompatibleVtableMap[TypeIdSaver.
save(TypeId)];
1868 /// For the given \p TypeId, this returns the TypeIdCompatibleVtableMap 1869 /// entry if present in the summary map. This may be used when importing. 1870 std::optional<TypeIdCompatibleVtableInfo>
1872autoI = TypeIdCompatibleVtableMap.find(TypeId);
1873if (
I == TypeIdCompatibleVtableMap.end())
1878 /// Collect for the given module the list of functions it defines 1879 /// (GUID -> Summary). 1883 /// Collect for each module the list of Summaries it defines (GUID -> 1888for (
constauto &GlobalList : *
this) {
1889auto GUID = GlobalList.first;
1890for (
constauto &Summary : GlobalList.second.SummaryList) {
1891 ModuleToDefinedGVSummaries[Summary->modulePath()][GUID] = Summary.get();
1896 /// Print to an output stream. 1899 /// Dump to stderr (for debugging). 1902 /// Export summary to dot file for GraphViz. 1907 /// Print out strongly connected components for debugging. 1910 /// Do the access attribute and DSOLocal propagation in combined index. 1913 /// Checks if we can import global variable from another module. 1916 /// Same as above but checks whether the global var is importable as a 1919bool &CanImportDecl)
const;
1922/// GraphTraits definition to build SCC for the index 1932decltype(&valueInfoFromEdge)>;
1940if (!
N.getSummaryList().size())
// handle external function 1943 &valueInfoFromEdge);
1945 cast<FunctionSummary>(
N.getSummaryList().front()->getBaseObject());
1950if (!
N.getSummaryList().size())
// handle external function 1953 &valueInfoFromEdge);
1955 cast<FunctionSummary>(
N.getSummaryList().front()->getBaseObject());
1960if (!
N.getSummaryList().size())
// handle external function 1964 cast<FunctionSummary>(
N.getSummaryList().front()->getBaseObject());
1965returnF->CallGraphEdgeList.begin();
1969if (!
N.getSummaryList().size())
// handle external function 1973 cast<FunctionSummary>(
N.getSummaryList().front()->getBaseObject());
1974returnF->CallGraphEdgeList.end();
1983 std::unique_ptr<GlobalValueSummary> Root =
1984 std::make_unique<FunctionSummary>(
I->calculateCallGraphRoot());
1986G.SummaryList.push_back(std::move(Root));
1992}
// end namespace llvm 1994#endif// LLVM_IR_MODULESUMMARYINDEX_H for(const MachineOperand &MO :llvm::drop_begin(OldMI.operands(), Desc.getNumOperands()))
This file defines the StringMap class.
This file defines the BumpPtrAllocator interface.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Looks at all the uses of the given value Returns the Liveness deduced from the uses of this value Adds all uses that cause the result to be MaybeLive to MaybeLiveRetUses If the result is Live
This file defines the DenseMap class.
static const char * PreservedSymbols[]
Module.h This file contains the declarations for the Module class.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file contains some templates that are useful if you are working with the STL at all.
This file defines the SmallString class.
This file defines the SmallVector class.
This file contains some functions that are useful when dealing with strings.
Alias summary information.
GlobalValue::GUID getAliaseeGUID() const
const GlobalValueSummary & getAliasee() const
ValueInfo getAliaseeVI() const
static bool classof(const GlobalValueSummary *GVS)
Check if this is an alias summary.
AliasSummary(GVFlags Flags)
GlobalValueSummary & getAliasee()
void setAliasee(ValueInfo &AliaseeVI, GlobalValueSummary *Aliasee)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Allocate memory in an ever growing pool, as if by bump-pointer.
This class represents a range of values.
This is an important base class in LLVM.
iterator find(const_arg_type_t< KeyT > Val)
std::pair< iterator, bool > try_emplace(KeyT &&Key, Ts &&...Args)
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Implements a dense probed hash-table based set.
Function summary information to aid decisions and implementation of importing.
static FunctionSummary ExternalNode
A dummy node to reference external functions that aren't in the index.
void addCallsite(CallsiteInfo &Callsite)
static FunctionSummary makeDummyFunctionSummary(SmallVectorImpl< FunctionSummary::EdgeTy > &&Edges)
Create an empty FunctionSummary (with specified call edges).
FunctionSummary(GVFlags Flags, unsigned NumInsts, FFlags FunFlags, SmallVectorImpl< ValueInfo > &&Refs, SmallVectorImpl< EdgeTy > &&CGEdges, std::vector< GlobalValue::GUID > TypeTests, std::vector< VFuncId > TypeTestAssumeVCalls, std::vector< VFuncId > TypeCheckedLoadVCalls, std::vector< ConstVCall > TypeTestAssumeConstVCalls, std::vector< ConstVCall > TypeCheckedLoadConstVCalls, std::vector< ParamAccess > Params, CallsitesTy CallsiteList, AllocsTy AllocList)
ArrayRef< VFuncId > type_test_assume_vcalls() const
Returns the list of virtual calls made by this function using llvm.assume(llvm.type....
AllocsTy & mutableAllocs()
ArrayRef< ConstVCall > type_test_assume_const_vcalls() const
Returns the list of virtual calls made by this function using llvm.assume(llvm.type....
std::pair< ValueInfo, CalleeInfo > EdgeTy
<CalleeValueInfo, CalleeInfo> call edge pair.
std::pair< unsigned, unsigned > specialRefCounts() const
SmallVector< EdgeTy, 0 > & mutableCalls()
ArrayRef< AllocInfo > allocs() const
ArrayRef< CallsiteInfo > callsites() const
void addTypeTest(GlobalValue::GUID Guid)
Add a type test to the summary.
ArrayRef< VFuncId > type_checked_load_vcalls() const
Returns the list of virtual calls made by this function using llvm.type.checked.load intrinsics that ...
void setParamAccesses(std::vector< ParamAccess > NewParams)
Sets the list of known uses of pointer parameters.
unsigned instCount() const
Get the instruction count recorded for this function.
const TypeIdInfo * getTypeIdInfo() const
ArrayRef< ConstVCall > type_checked_load_const_vcalls() const
Returns the list of virtual calls made by this function using llvm.type.checked.load intrinsics with ...
ArrayRef< EdgeTy > calls() const
Return the list of <CalleeValueInfo, CalleeInfo> pairs.
ArrayRef< ParamAccess > paramAccesses() const
Returns the list of known uses of pointer parameters.
CallsitesTy & mutableCallsites()
ForceSummaryHotnessType
Types for -force-summary-edges-cold debugging option.
FFlags fflags() const
Get function summary flags.
ArrayRef< GlobalValue::GUID > type_tests() const
Returns the list of type identifiers used by this function in llvm.type.test intrinsics other than by...
static bool classof(const GlobalValueSummary *GVS)
Check if this is a function summary.
Function and variable summary information to aid decisions and implementation of importing.
SummaryKind
Sububclass discriminator (for dyn_cast<> et al.)
GVFlags flags() const
Get the flags for this GlobalValue (see struct GVFlags).
void setDSOLocal(bool Local)
StringRef modulePath() const
Get the path to the module containing this function.
GlobalValueSummary * getBaseObject()
If this is an alias summary, returns the summary of the aliased object (a global variable or function...
SummaryKind getSummaryKind() const
Which kind of summary subclass this is.
GlobalValue::GUID getOriginalName() const
Returns the hash of the original name, it is identical to the GUID for externally visible symbols,...
GlobalValue::VisibilityTypes getVisibility() const
ArrayRef< ValueInfo > refs() const
Return the list of values referenced by this global value definition.
bool shouldImportAsDecl() const
void setLinkage(GlobalValue::LinkageTypes Linkage)
Sets the linkage to the value determined by global summary-based optimization.
void setVisibility(GlobalValue::VisibilityTypes Vis)
virtual ~GlobalValueSummary()=default
GlobalValueSummary::ImportKind importType() const
void setModulePath(StringRef ModPath)
Set the path to the module containing this function, for use in the combined index.
void setNotEligibleToImport()
Flag that this global value cannot be imported.
void setCanAutoHide(bool CanAutoHide)
GlobalValueSummary(SummaryKind K, GVFlags Flags, SmallVectorImpl< ValueInfo > &&Refs)
GlobalValue::LinkageTypes linkage() const
Return linkage type recorded for this global value.
bool notEligibleToImport() const
Return true if this global value can't be imported.
void setImportKind(ImportKind IK)
void setOriginalName(GlobalValue::GUID Name)
Initialize the original name hash in this summary.
static GUID getGUID(StringRef GlobalName)
Return a 64-bit global unique ID constructed from global value name (i.e.
GUID getGUID() const
Return a 64-bit global unique ID constructed from global value name (i.e.
VisibilityTypes
An enumeration for the kinds of visibility of global values.
@ DefaultVisibility
The GV is visible.
LinkageTypes
An enumeration for the kinds of linkage for global values.
@ AvailableExternallyLinkage
Available for inspection, not emission.
Global variable summary information to aid decisions and implementation of importing.
void setWriteOnly(bool WO)
bool maybeWriteOnly() const
void setVCallVisibility(GlobalObject::VCallVisibility Vis)
struct llvm::GlobalVarSummary::GVarFlags VarFlags
GVarFlags varflags() const
bool maybeReadOnly() const
void setReadOnly(bool RO)
ArrayRef< VirtFuncOffset > vTableFuncs() const
GlobalVarSummary(GVFlags Flags, GVarFlags VarFlags, SmallVectorImpl< ValueInfo > &&Refs)
GlobalObject::VCallVisibility getVCallVisibility() const
static bool classof(const GlobalValueSummary *GVS)
Check if this is a global variable summary.
void setVTableFuncs(VTableFuncList Funcs)
Class to hold module path string table and global value map, and encapsulate methods for operating on...
bool withAttributePropagation() const
TypeIdSummary & getOrInsertTypeIdSummary(StringRef TypeId)
Return an existing or new TypeIdSummary entry for TypeId.
std::optional< TypeIdCompatibleVtableInfo > getTypeIdCompatibleVtableSummary(StringRef TypeId) const
For the given TypeId, this returns the TypeIdCompatibleVtableMap entry if present in the summary map.
void addGlobalValueSummary(ValueInfo VI, std::unique_ptr< GlobalValueSummary > Summary)
Add a global value summary for the given ValueInfo.
ModulePathStringTableTy::value_type ModuleInfo
uint64_t getBlockCount() const
ValueInfo getOrInsertValueInfo(GlobalValue::GUID GUID)
Return a ValueInfo for GUID.
bool withGlobalValueDeadStripping() const
static void discoverNodes(ValueInfo V, std::map< ValueInfo, bool > &FunctionHasParent)
Convenience function for doing a DFS on a ValueInfo.
StringRef saveString(StringRef String)
bool withWholeProgramVisibility() const
const TypeIdSummaryMapTy & typeIds() const
static StringRef getOriginalNameBeforePromote(StringRef Name)
Helper to obtain the unpromoted name for a global value (or the original name if not promoted).
const TypeIdSummary * getTypeIdSummary(StringRef TypeId) const
This returns either a pointer to the type id summary (if present in the summary map) or null (if not ...
bool isGUIDLive(GlobalValue::GUID GUID) const
gvsummary_iterator begin()
const_gvsummary_iterator end() const
bool isReadOnly(const GlobalVarSummary *GVS) const
void setFlags(uint64_t Flags)
const_gvsummary_iterator begin() const
bool isWriteOnly(const GlobalVarSummary *GVS) const
void addBlockCount(uint64_t C)
void setPartiallySplitLTOUnits()
const std::vector< uint64_t > & stackIds() const
GlobalValueSummary * findSummaryInModule(GlobalValue::GUID ValueGUID, StringRef ModuleId) const
Find the summary for global GUID in module ModuleId, or nullptr if not found.
void releaseTemporaryMemory()
void setBlockCount(uint64_t C)
ValueInfo getValueInfo(const GlobalValueSummaryMapTy::value_type &R) const
Return a ValueInfo for the index value_type (convenient when iterating index).
const ModuleHash & getModuleHash(const StringRef ModPath) const
Get the module SHA1 hash recorded for the given module path.
static constexpr const char * getRegularLTOModuleName()
void setEnableSplitLTOUnit()
void addGlobalValueSummary(StringRef ValueName, std::unique_ptr< GlobalValueSummary > Summary)
Add a global value summary for a value of the given name.
ModuleSummaryIndex(bool HaveGVs, bool EnableSplitLTOUnit=false, bool UnifiedLTO=false)
bool partiallySplitLTOUnits() const
void collectDefinedFunctionsForModule(StringRef ModulePath, GVSummaryMapTy &GVSummaryMap) const
Collect for the given module the list of functions it defines (GUID -> Summary).
const std::set< std::string, std::less<> > & cfiFunctionDecls() const
const auto & typeIdCompatibleVtableMap() const
void dumpSCCs(raw_ostream &OS)
Print out strongly connected components for debugging.
bool isGlobalValueLive(const GlobalValueSummary *GVS) const
bool enableSplitLTOUnit() const
void setWithSupportsHotColdNew()
const ModuleInfo * getModule(StringRef ModPath) const
Return module entry for module with the given ModPath.
void propagateAttributes(const DenseSet< GlobalValue::GUID > &PreservedSymbols)
Do the access attribute and DSOLocal propagation in combined index.
void setSkipModuleByDistributedBackend()
const std::set< std::string, std::less<> > & cfiFunctionDefs() const
void setWithAttributePropagation()
const StringMap< ModuleHash > & modulePaths() const
Table of modules, containing module hash and id.
bool withSupportsHotColdNew() const
void dump() const
Dump to stderr (for debugging).
ModuleInfo * addModule(StringRef ModPath, ModuleHash Hash=ModuleHash{{0}})
Add a new module with the given Hash, mapped to the given ModID, and return a reference to the module...
void collectDefinedGVSummariesPerModule(Map &ModuleToDefinedGVSummaries) const
Collect for each module the list of Summaries it defines (GUID -> Summary).
void addGlobalValueSummary(const GlobalValue &GV, std::unique_ptr< GlobalValueSummary > Summary)
Add a global value summary for a value.
bool hasExportedFunctions(const Module &M) const
Check if the given Module has any functions available for exporting in the index.
std::set< std::string, std::less<> > & cfiFunctionDefs()
static std::string getGlobalNameForLocal(StringRef Name, ModuleHash ModHash)
Convenience method for creating a promoted global name for the given value name of a local,...
static constexpr uint64_t BitcodeSummaryVersion
bool withDSOLocalPropagation() const
void exportToDot(raw_ostream &OS, const DenseSet< GlobalValue::GUID > &GUIDPreservedSymbols) const
Export summary to dot file for GraphViz.
bool hasUnifiedLTO() const
bool hasParamAccess() const
void setWithDSOLocalPropagation()
uint64_t getStackIdAtIndex(unsigned Index) const
StringMap< ModuleHash > & modulePaths()
Table of modules, containing hash and id.
void print(raw_ostream &OS, bool IsForDebug=false) const
Print to an output stream.
bool skipModuleByDistributedBackend() const
ValueInfo getOrInsertValueInfo(const GlobalValue *GV)
Return a ValueInfo for GV and mark it as belonging to GV.
std::set< std::string, std::less<> > & cfiFunctionDecls()
GlobalValueSummary * findSummaryInModule(ValueInfo VI, StringRef ModuleId) const
Find the summary for ValueInfo VI in module ModuleId, or nullptr if not found.
ValueInfo getValueInfo(GlobalValue::GUID GUID) const
Return a ValueInfo for GUID if it exists, otherwise return ValueInfo().
uint64_t getFlags() const
unsigned addOrGetStackIdIndex(uint64_t StackId)
GlobalValue::GUID getGUIDFromOriginalID(GlobalValue::GUID OriginalID) const
Return the GUID for OriginalId in the OidGuidMap.
GlobalValueSummary * getGlobalValueSummary(const GlobalValue &GV, bool PerModuleIndex=true) const
Returns the first GlobalValueSummary for GV, asserting that there is only one if PerModuleIndex.
void setWithGlobalValueDeadStripping()
ModuleInfo * getModule(StringRef ModPath)
Return module entry for module with the given ModPath.
ValueInfo getOrInsertValueInfo(GlobalValue::GUID GUID, StringRef Name)
Return a ValueInfo for GUID setting value Name.
void setWithWholeProgramVisibility()
bool canImportGlobalVar(const GlobalValueSummary *S, bool AnalyzeRefs) const
Checks if we can import global variable from another module.
static std::string getGlobalNameForLocal(StringRef Name, StringRef Suffix)
void addOriginalName(GlobalValue::GUID ValueGUID, GlobalValue::GUID OrigGUID)
Add an original name for the value of the given GUID.
FunctionSummary calculateCallGraphRoot()
TypeIdSummary * getTypeIdSummary(StringRef TypeId)
TypeIdCompatibleVtableInfo & getOrInsertTypeIdCompatibleVtableSummary(StringRef TypeId)
Return an existing or new TypeIdCompatibleVtableMap entry for TypeId.
A Module instance is used to store all the information related to an LLVM module.
PointerIntPair - This class implements a pair of a pointer and small integer.
void setPointer(PointerTy PtrVal) &
void setInt(IntType IntVal) &
PointerTy getPointer() const
Simple representation of a scaled number.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
iterator find(StringRef Key)
size_type count(StringRef Key) const
count - Return 1 if the element is in the map, 0 otherwise.
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
StringRef - Represent a constant reference to a string, i.e.
Saves strings in the provided stable storage and returns a StringRef with a stable character pointer.
StringRef save(const char *S)
Saves strings in the provided stable storage and returns a StringRef with a stable character pointer.
StringRef save(const char *S)
A Use represents the edge between a Value definition and its users.
This class implements an extremely fast bulk output stream that can only output to a stream.
A raw_ostream that writes to an std::string.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ Cold
Attempts to make code in the caller as efficient as possible under the assumption that the call is no...
@ C
The default llvm calling convention, compatible with C.
This is an optimization pass for GlobalISel generic memory operations.
GlobalValueSummaryMapTy::iterator gvsummary_iterator
bool operator<(int64_t V1, const APSInt &V2)
const char * getHotnessName(CalleeInfo::HotnessType HT)
bool operator!=(uint64_t V1, const APInt &V2)
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
bool operator==(const AddressRangeValuePair &LHS, const AddressRangeValuePair &RHS)
std::vector< VirtFuncOffset > VTableFuncList
List of functions referenced by a particular vtable definition.
std::vector< std::unique_ptr< GlobalValueSummary > > GlobalValueSummaryList
@ First
Helpers to iterate all locations in the MemoryEffectsBase class.
std::unordered_set< GlobalValueSummary * > GVSummaryPtrSet
A set of global value summary pointers.
GlobalValueSummaryMapTy::const_iterator const_gvsummary_iterator
Type used for iterating through the global value summary map.
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
std::map< std::string, GVSummaryMapTy, std::less<> > ModuleToSummariesForIndexTy
Map of a module name to the GUIDs and summaries we will import from that module.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
std::multimap< GlobalValue::GUID, std::pair< StringRef, TypeIdSummary > > TypeIdSummaryMapTy
Map of a type GUID to type id string and summary (multimap used in case of GUID conflicts).
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
std::array< uint32_t, 5 > ModuleHash
160 bits SHA1
std::map< GlobalValue::GUID, GlobalValueSummaryInfo > GlobalValueSummaryMapTy
Map from global value GUID to corresponding summary structures.
std::vector< TypeIdOffsetVtableInfo > TypeIdCompatibleVtableInfo
List of vtable definitions decorated by a particular type identifier, and their corresponding offsets...
Implement std::hash so that hash_code can be used in STL containers.
Summary of memprof metadata on allocations.
AllocInfo(std::vector< MIBInfo > MIBs)
AllocInfo(SmallVector< uint8_t > Versions, std::vector< MIBInfo > MIBs)
std::vector< std::vector< ContextTotalSize > > ContextSizeInfos
SmallVector< uint8_t > Versions
std::vector< MIBInfo > MIBs
Class to accumulate and hold information about a callee.
static constexpr uint64_t MaxRelBlockFreq
void updateHotness(const HotnessType OtherHotness)
CalleeInfo(HotnessType Hotness, bool HasTC, uint64_t RelBF)
HotnessType getHotness() const
static constexpr int32_t ScaleShift
void setHasTailCall(const bool HasTC)
void updateRelBlockFreq(uint64_t BlockFreq, uint64_t EntryFreq)
Update RelBlockFreq from BlockFreq and EntryFreq.
static constexpr unsigned RelBlockFreqBits
The value stored in RelBlockFreq has to be interpreted as the digits of a scaled number with a scale ...
Summary of memprof callsite metadata.
SmallVector< unsigned > StackIdIndices
SmallVector< unsigned > Clones
CallsiteInfo(ValueInfo Callee, SmallVector< unsigned > StackIdIndices)
CallsiteInfo(ValueInfo Callee, SmallVector< unsigned > Clones, SmallVector< unsigned > StackIdIndices)
static FunctionSummary::ConstVCall getEmptyKey()
static FunctionSummary::ConstVCall getTombstoneKey()
static unsigned getHashValue(FunctionSummary::ConstVCall I)
static bool isEqual(FunctionSummary::ConstVCall L, FunctionSummary::ConstVCall R)
static FunctionSummary::VFuncId getEmptyKey()
static bool isEqual(FunctionSummary::VFuncId L, FunctionSummary::VFuncId R)
static FunctionSummary::VFuncId getTombstoneKey()
static unsigned getHashValue(FunctionSummary::VFuncId I)
static bool isEqual(ValueInfo L, ValueInfo R)
static ValueInfo getEmptyKey()
static ValueInfo getTombstoneKey()
static bool isSpecialKey(ValueInfo V)
static unsigned getHashValue(ValueInfo I)
An information struct used to provide DenseMap with the various necessary components for a given valu...
A specification for a virtual function call with all constant integer arguments.
std::vector< uint64_t > Args
Flags specific to function summaries.
FFlags & operator&=(const FFlags &RHS)
unsigned ReturnDoesNotAlias
unsigned MustBeUnreachable
Describes the use of a value in a call instruction, specifying the call's target, the value's paramet...
Call(uint64_t ParamNo, ValueInfo Callee, const ConstantRange &Offsets)
Describes the uses of a parameter by the function.
ParamAccess(uint64_t ParamNo, const ConstantRange &Use)
std::vector< Call > Calls
In the per-module summary, it summarizes the byte offset applied to each pointer parameter before pas...
static constexpr uint32_t RangeWidth
All type identifier related information.
std::vector< ConstVCall > TypeCheckedLoadConstVCalls
std::vector< VFuncId > TypeCheckedLoadVCalls
std::vector< ConstVCall > TypeTestAssumeConstVCalls
List of virtual calls made by this function using (respectively) llvm.assume(llvm....
std::vector< GlobalValue::GUID > TypeTests
List of type identifiers used by this function in llvm.type.test intrinsics referenced by something o...
std::vector< VFuncId > TypeTestAssumeVCalls
List of virtual calls made by this function using (respectively) llvm.assume(llvm....
An "identifier" for a virtual function.
GlobalValueSummaryList SummaryList
List of global value summary structures for a particular value held in the GlobalValueMap.
GlobalValueSummaryInfo(bool HaveGVs)
union llvm::GlobalValueSummaryInfo::NameOrGV U
Group flags (Linkage, NotEligibleToImport, etc.) as a bitfield.
GVFlags(GlobalValue::LinkageTypes Linkage, GlobalValue::VisibilityTypes Visibility, bool NotEligibleToImport, bool Live, bool IsLocal, bool CanAutoHide, ImportKind ImportType)
Convenience Constructors.
unsigned DSOLocal
Indicates that the linker resolved the symbol to a definition from within the same linkage unit.
unsigned CanAutoHide
In the per-module summary, indicates that the global value is linkonce_odr and global unnamed addr (s...
unsigned ImportType
This field is written by the ThinLTO indexing step to postlink combined summary.
unsigned NotEligibleToImport
Indicate if the global value cannot be imported (e.g.
unsigned Linkage
The linkage type of the associated global value.
unsigned Visibility
Indicates the visibility.
unsigned Live
In per-module summary, indicate that the global value must be considered a live root for index-based ...
GVarFlags(bool ReadOnly, bool WriteOnly, bool Constant, GlobalObject::VCallVisibility Vis)
static NodeRef getEntryNode(ModuleSummaryIndex *I)
static NodeRef valueInfoFromEdge(FunctionSummary::EdgeTy &P)
static ChildIteratorType child_begin(NodeRef N)
static ChildEdgeIteratorType child_edge_begin(NodeRef N)
static NodeRef edge_dest(EdgeRef E)
static NodeRef getEntryNode(ValueInfo V)
static ChildIteratorType child_end(NodeRef N)
static ChildEdgeIteratorType child_edge_end(NodeRef N)
FunctionSummary::EdgeTy & EdgeRef
Summary of a single MIB in a memprof metadata on allocations.
MIBInfo(AllocationType AllocType, SmallVector< unsigned > StackIdIndices)
SmallVector< unsigned > StackIdIndices
The following data structures summarize type metadata information.
TypeIdOffsetVtableInfo(uint64_t Offset, ValueInfo VI)
uint64_t AddressPointOffset
std::map< uint64_t, WholeProgramDevirtResolution > WPDRes
Mapping from byte offset to whole-program devirt resolution for that (typeid, byte offset) pair.
Kind
Specifies which kind of type check we should emit for this byte array.
@ Unknown
Unknown (analysis not performed, don't lower)
@ Single
Single element (last example in "Short Inline Bit Vectors")
@ Inline
Inlined bit vector ("Short Inline Bit Vectors")
@ Unsat
Unsatisfiable type (i.e. no global has this type metadata)
@ AllOnes
All-ones bit vector ("Eliminating Bit Vector Checks for All-Ones Bit Vectors")
@ ByteArray
Test a byte array (first example)
unsigned SizeM1BitWidth
Range of size-1 expressed as a bit width.
enum llvm::TypeTestResolution::Kind TheKind
Struct that holds a reference to a particular GUID in a global value summary.
PointerIntPair< const GlobalValueSummaryMapTy::value_type *, 3, int > RefAndFlags
GlobalValue::VisibilityTypes getELFVisibility() const
Returns the most constraining visibility among summaries.
bool isValidAccessSpecifier() const
const GlobalValueSummaryMapTy::value_type * getRef() const
ArrayRef< std::unique_ptr< GlobalValueSummary > > getSummaryList() const
const GlobalValue * getValue() const
ValueInfo(bool HaveGVs, const GlobalValueSummaryMapTy::value_type *R)
bool canAutoHide() const
Checks if all copies are eligible for auto-hiding (have flag set).
unsigned getAccessSpecifier() const
bool isDSOLocal(bool WithDSOLocalPropagation=false) const
Checks if all summaries are DSO local (have the flag set).
GlobalValue::GUID getGUID() const
The ValueInfo and offset for a function within a vtable definition initializer array.
VirtFuncOffset(ValueInfo VI, uint64_t Offset)
@ UniformRetVal
Uniform return value optimization.
@ VirtualConstProp
Virtual constant propagation.
@ UniqueRetVal
Unique return value optimization.
@ Indir
Just do a regular virtual call.
uint64_t Info
Additional information for the resolution:
enum llvm::WholeProgramDevirtResolution::ByArg::Kind TheKind
enum llvm::WholeProgramDevirtResolution::Kind TheKind
std::map< std::vector< uint64_t >, ByArg > ResByArg
Resolutions for calls with all constant integer arguments (excluding the first argument,...
std::string SingleImplName
@ SingleImpl
Single implementation devirtualization.
@ Indir
Just do a regular virtual call.
@ BranchFunnel
When retpoline mitigation is enabled, use a branch funnel that is defined in the merged module.
const GlobalValue * GV
The GlobalValue corresponding to this summary.
StringRef Name
Summary string representation.