15#ifndef LLVM_IR_MODULESUMMARYINDEX_H
16#define LLVM_IR_MODULESUMMARYINDEX_H
115class GlobalValueSummary;
152 inline void addSummary(std::unique_ptr<GlobalValueSummary> Summary);
204 std::deque<value_type> Storage;
207 template <
typename... Ts>
209 auto Res = Map.try_emplace(
Key, Storage.size());
211 Storage.emplace_back(std::piecewise_construct, std::forward_as_tuple(
Key),
212 std::forward_as_tuple(std::forward<Ts>(Args)...));
213 return {std::prev(Storage.end()),
true};
215 return {Storage.begin() + Res.first->second,
false};
219 auto It = Map.find(
Key);
220 return It == Map.end() ? Storage.end() : Storage.begin() + It->second;
224 auto It = Map.find(
Key);
225 return It == Map.end() ? Storage.end() : Storage.begin() + It->second;
233 bool empty()
const {
return Storage.empty(); }
238 SortedEntriesVec Entries;
244 : Entries(
std::
move(Entries)) {}
248 size_t size()
const {
return Entries.size(); }
249 bool empty()
const {
return Entries.empty(); }
260 SortedEntriesVec getSortedEntries()
const {
261 SortedEntriesVec Sorted;
262 Sorted.
reserve(Storage.size());
263 for (
const auto &
E : Storage)
264 Sorted.push_back(&
E);
266 return A->first <
B->first;
292 return getRef()->second.U.GV;
296 return getRef()->second.getSummaryList();
310 :
getRef()->second.U.Name;
328 return (
RefAndFlags.getInt() & BadAccessMask) != BadAccessMask;
360 if (!VI.name().empty())
361 OS <<
" (" << VI.name() <<
")";
367 "Need ValueInfo with non-null Ref for comparison");
368 return A.getRef() ==
B.getRef();
373 "Need ValueInfo with non-null Ref for comparison");
374 return A.getRef() !=
B.getRef();
379 "Need ValueInfo with non-null Ref to compare GUIDs");
380 return A.getGUID() <
B.getGUID();
387 assert(L.haveGVs() == R.haveGVs());
388 return L.getRef() == R.getRef();
431 OS <<
"Callee: " << SNI.
Callee;
506 for (
auto &M : AE.
MIBs)
507 OS <<
"\t\t" << M <<
"\n";
509 OS <<
"\tContextSizeInfo per MIB:\n";
513 for (
auto [FullStackId, TotalSize] : Infos)
514 OS << InfoLS <<
"{ " << FullStackId <<
", " << TotalSize <<
" }";
636 : Kind(K), Flags(Flags), RefEdgeList(
std::
move(Refs)) {
638 "Expect no references for AliasSummary");
673 "unexpected (re-)promotion of non-local symbol");
675 Flags.Promoted =
true;
694 bool isLive()
const {
return Flags.Live; }
696 void setLive(
bool Live) { Flags.Live = Live; }
713 Flags.NoRenameOnPromotion = NoRenameOnPromotion;
719 return static_cast<ImportKind>(Flags.ImportType);
744 :
U(HaveGVs), HasLocal(
false) {}
747 std::unique_ptr<GlobalValueSummary> Summary) {
750 return SummaryList.push_back(std::move(Summary));
756 [](
const std::unique_ptr<GlobalValueSummary> &Summary) {
781 AliaseeValueInfo = AliaseeVI;
782 AliaseeSummary = Aliasee;
786 assert(!!AliaseeSummary == (AliaseeValueInfo &&
787 !AliaseeValueInfo.getSummaryList().empty()) &&
788 "Expect to have both aliasee summary and summary list or neither");
789 return !!AliaseeSummary;
793 assert(AliaseeSummary &&
"Unexpected missing aliasee summary");
794 return *AliaseeSummary;
802 assert(AliaseeValueInfo &&
"Unexpected missing aliasee");
803 return AliaseeValueInfo;
806 assert(AliaseeValueInfo &&
"Unexpected missing aliasee");
807 return AliaseeValueInfo.getGUID();
813 return &AS->getAliasee();
819 return &AS->getAliasee();
828 using EdgeTy = std::pair<ValueInfo, CalleeInfo>;
924 operator std::string() {
927 OS <<
"funcFlags: (";
928 OS <<
"readNone: " << this->
ReadNone;
929 OS <<
", readOnly: " << this->
ReadOnly;
930 OS <<
", noRecurse: " << this->
NoRecurse;
932 OS <<
", noInline: " << this->
NoInline;
934 OS <<
", noUnwind: " << this->
NoUnwind;
935 OS <<
", mayThrow: " << this->
MayThrow;
989 std::move(Edges), std::vector<GlobalValue::GUID>(),
990 std::vector<FunctionSummary::VFuncId>(),
991 std::vector<FunctionSummary::VFuncId>(),
992 std::vector<FunctionSummary::ConstVCall>(),
993 std::vector<FunctionSummary::ConstVCall>(),
994 std::vector<FunctionSummary::ParamAccess>(),
995 std::vector<CallsiteInfo>(), std::vector<AllocInfo>());
1014 std::unique_ptr<TypeIdInfo> TIdInfo;
1017 using ParamAccessesTy = std::vector<ParamAccess>;
1018 std::unique_ptr<ParamAccessesTy> ParamAccesses;
1026 using CallsitesTy = std::vector<CallsiteInfo>;
1027 std::unique_ptr<CallsitesTy> Callsites;
1036 using AllocsTy = std::vector<AllocInfo>;
1037 std::unique_ptr<AllocsTy> Allocs;
1043 std::vector<GlobalValue::GUID> TypeTests,
1044 std::vector<VFuncId> TypeTestAssumeVCalls,
1045 std::vector<VFuncId> TypeCheckedLoadVCalls,
1046 std::vector<ConstVCall> TypeTestAssumeConstVCalls,
1047 std::vector<ConstVCall> TypeCheckedLoadConstVCalls,
1048 std::vector<ParamAccess> Params, CallsitesTy CallsiteList,
1051 InstCount(NumInsts), FunFlags(FunFlags),
1052 CallGraphEdgeList(
std::
move(CGEdges)) {
1053 if (!TypeTests.empty() || !TypeTestAssumeVCalls.empty() ||
1054 !TypeCheckedLoadVCalls.empty() || !TypeTestAssumeConstVCalls.empty() ||
1055 !TypeCheckedLoadConstVCalls.empty())
1056 TIdInfo = std::make_unique<TypeIdInfo>(
1057 TypeIdInfo{std::move(TypeTests), std::move(TypeTestAssumeVCalls),
1058 std::move(TypeCheckedLoadVCalls),
1059 std::move(TypeTestAssumeConstVCalls),
1060 std::move(TypeCheckedLoadConstVCalls)});
1061 if (!Params.empty())
1062 ParamAccesses = std::make_unique<ParamAccessesTy>(std::move(Params));
1063 if (!CallsiteList.empty())
1064 Callsites = std::make_unique<CallsitesTy>(std::move(CallsiteList));
1065 if (!AllocList.empty())
1066 Allocs = std::make_unique<AllocsTy>(std::move(AllocList));
1098 return TIdInfo->TypeTests;
1107 return TIdInfo->TypeTestAssumeVCalls;
1116 return TIdInfo->TypeCheckedLoadVCalls;
1125 return TIdInfo->TypeTestAssumeConstVCalls;
1133 return TIdInfo->TypeCheckedLoadConstVCalls;
1140 return *ParamAccesses;
1146 if (NewParams.empty())
1147 ParamAccesses.reset();
1148 else if (ParamAccesses)
1149 *ParamAccesses = std::move(NewParams);
1151 ParamAccesses = std::make_unique<ParamAccessesTy>(std::move(NewParams));
1158 TIdInfo = std::make_unique<TypeIdInfo>();
1159 TIdInfo->TypeTests.push_back(
Guid);
1177 Callsites = std::make_unique<CallsitesTy>();
1178 Callsites->push_back(std::move(Callsite));
1189 Allocs = std::make_unique<AllocsTy>();
1190 Allocs->push_back(std::move(
Alloc));
1203 return L.GUID == R.GUID && L.Offset == R.Offset;
1217 return I.VFunc.GUID;
1246 std::unique_ptr<VTableFuncList> VTableFuncs;
1304 VTableFuncs = std::make_unique<VTableFuncList>(std::move(Funcs));
1309 return *VTableFuncs;
1387 std::map<uint64_t, WholeProgramDevirtResolution>
WPDRes;
1421 std::vector<std::pair<StringRef, GlobalValue::GUID>>
1423 std::vector<std::pair<StringRef, GlobalValue::GUID>> Symbols;
1424 for (
auto &[GUID, Names] : ThinLTOToNamesIndex)
1425 for (
auto Name : Names)
1426 Symbols.emplace_back(Name, GUID);
1434 return map_range(ThinLTOToNamesIndex, [](
auto I) {
return I.first; });
1441 auto I = ThinLTOToNamesIndex.find(GUID);
1442 if (
I == ThinLTOToNamesIndex.end())
1443 return make_range(NestedIterator{}, NestedIterator{});
1449 auto [Iter,
_] = Names.insert(Name);
1450 ThinLTOToNamesIndex[GUID].insert(Iter->first());
1454 return Names.find(Name) != Names.end();
1458 assert(Names.empty() == ThinLTOToNamesIndex.empty());
1459 return Names.empty();
1481 std::map<std::string, GVSummaryMapTy, std::less<>>;
1489 std::multimap<GlobalValue::GUID, std::pair<StringRef, TypeIdSummary>>;
1536 std::map<StringRef, TypeIdCompatibleVtableInfo, std::less<>>
1537 TypeIdCompatibleVtableMap;
1546 bool WithGlobalValueDeadStripping =
false;
1551 bool WithAttributePropagation =
false;
1555 bool WithDSOLocalPropagation =
false;
1558 bool WithInternalizeAndPromote =
false;
1561 bool WithWholeProgramVisibility =
false;
1564 bool HasSyntheticEntryCounts =
false;
1567 bool WithSupportsHotColdNew =
false;
1574 bool SkipModuleByDistributedBackend =
false;
1583 bool EnableSplitLTOUnit;
1590 bool PartiallySplitLTOUnits =
false;
1593 bool HasParamAccess =
false;
1616 std::vector<uint64_t> StackIds;
1634 bool UnifiedLTO =
false)
1635 : TypeIdSaver(TypeIdSaverAlloc), HaveGVs(HaveGVs),
1636 EnableSplitLTOUnit(EnableSplitLTOUnit), UnifiedLTO(UnifiedLTO),
1648 return "[Regular LTO]";
1664 size_t size()
const {
return GlobalValueMap.size(); }
1668 return GlobalValueMap.sortedRange();
1671 const std::vector<uint64_t> &
stackIds()
const {
return StackIds; }
1674 auto Inserted = StackIdToIndex.insert({StackId, StackIds.size()});
1675 if (Inserted.second)
1676 StackIds.push_back(StackId);
1677 return Inserted.first->second;
1681 assert(StackIds.size() > Index);
1682 return StackIds[Index];
1691 assert(StackIdToIndex.size() == StackIds.size());
1692 StackIdToIndex.clear();
1693 StackIds.shrink_to_fit();
1699 std::map<ValueInfo, bool> &FunctionHasParent) {
1700 if (!V.getSummaryList().size())
1704 auto S = FunctionHasParent.emplace(V,
false);
1712 assert(
F !=
nullptr &&
"Expected FunctionSummary node");
1714 for (
const auto &
C :
F->calls()) {
1716 auto S = FunctionHasParent.emplace(
C.first,
true);
1719 if (!S.second && S.first->second)
1725 S.first->second =
true;
1734 std::map<ValueInfo, bool> FunctionHasParent;
1736 for (
auto &S : *
this) {
1738 if (!S.second.getSummaryList().size() ||
1746 for (
auto &
P : FunctionHasParent) {
1755 return WithGlobalValueDeadStripping;
1758 WithGlobalValueDeadStripping =
true;
1763 WithAttributePropagation =
true;
1786 return SkipModuleByDistributedBackend;
1789 SkipModuleByDistributedBackend =
true;
1804 return !WithGlobalValueDeadStripping || GVS->
isLive();
1816 auto I = GlobalValueMap.find(GUID);
1817 return ValueInfo(HaveGVs,
I == GlobalValueMap.end() ?
nullptr : &*
I);
1822 return ValueInfo(HaveGVs, getOrInsertValuePtr(GUID));
1833 auto VP = getOrInsertValuePtr(GUID);
1834 VP->second.U.Name = Name;
1843 auto VP = getOrInsertValuePtr(GUID);
1844 VP->second.U.GV = GV;
1855 const auto I = OidGuidMap.find(OriginalID);
1856 return I == OidGuidMap.end() ? 0 :
I->second;
1867 std::unique_ptr<GlobalValueSummary> Summary) {
1873 std::unique_ptr<GlobalValueSummary> Summary) {
1877 std::move(Summary));
1882 std::unique_ptr<GlobalValueSummary> Summary) {
1884 HasParamAccess |= !FS->paramAccesses().empty();
1889 ->second.addSummary(std::move(Summary));
1895 if (OrigGUID == 0 || ValueGUID == OrigGUID)
1897 auto [It, Inserted] = OidGuidMap.try_emplace(OrigGUID, ValueGUID);
1898 if (!Inserted && It->second != ValueGUID)
1905 auto SummaryList = VI.getSummaryList();
1908 [&](
const std::unique_ptr<GlobalValueSummary> &Summary) {
1909 return Summary->modulePath() == ModuleId;
1911 if (Summary == SummaryList.end())
1913 return Summary->get();
1929 bool PerModuleIndex =
true)
const {
1930 assert(GV.
hasName() &&
"Can't get GlobalValueSummary for GV with no name");
1939 bool PerModuleIndex =
true)
const;
1943 return ModulePathStringTable;
1951 auto It = ModulePathStringTable.find(ModPath);
1952 assert(It != ModulePathStringTable.end() &&
"Module not registered");
1966 NewName +=
".llvm.";
1968 return std::string(NewName);
1976 std::pair<StringRef, StringRef> Pair = Name.rsplit(
".llvm.");
1985 return &*ModulePathStringTable.
insert({ModPath, Hash}).first;
1990 auto It = ModulePathStringTable.find(ModPath);
1991 assert(It != ModulePathStringTable.end() &&
"Module not registered");
1997 auto It = ModulePathStringTable.find(ModPath);
1998 assert(It != ModulePathStringTable.end() &&
"Module not registered");
2006 return ModulePathStringTable.count(M.getModuleIdentifier());
2015 auto TidIter = TypeIdMap.equal_range(
2017 for (
auto &[GUID, TypeIdPair] :
make_range(TidIter))
2018 if (TypeIdPair.first == TypeId)
2019 return TypeIdPair.second;
2023 return It->second.second;
2029 auto TidIter = TypeIdMap.equal_range(
2031 for (
const auto &[GUID, TypeIdPair] :
make_range(TidIter))
2032 if (TypeIdPair.first == TypeId)
2033 return &TypeIdPair.second;
2044 return TypeIdCompatibleVtableMap;
2052 return TypeIdCompatibleVtableMap[TypeIdSaver.save(TypeId)];
2057 std::optional<TypeIdCompatibleVtableInfo>
2059 auto I = TypeIdCompatibleVtableMap.find(TypeId);
2060 if (
I == TypeIdCompatibleVtableMap.end())
2061 return std::nullopt;
2073 template <
class Map>
2076 for (
const auto &GlobalList : *
this) {
2077 auto GUID = GlobalList.first;
2078 for (
const auto &Summary : GlobalList.second.getSummaryList()) {
2079 ModuleToDefinedGVSummaries[Summary->modulePath()][GUID] = Summary.get();
2104 bool AnalyzeRefs)
const;
2109 bool AnalyzeRefs,
bool &CanImportDecl)
const;
2130 if (!
N.getSummaryList().size())
2140 if (!
N.getSummaryList().size())
2150 if (!
N.getSummaryList().size())
2155 return F->CallGraphEdgeList.begin();
2159 if (!
N.getSummaryList().size())
2164 return F->CallGraphEdgeList.end();
2173 std::unique_ptr<GlobalValueSummary> Root =
2174 std::make_unique<FunctionSummary>(
I->calculateCallGraphRoot());
2176 G.addSummary(std::move(Root));
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the StringMap class.
This file defines the BumpPtrAllocator interface.
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_PREFERRED_TYPE(T)
\macro LLVM_PREFERRED_TYPE Adjust type of bit-field in debug info.
This file defines the DenseMap class.
Module.h This file contains the declarations for the Module class.
This file implements a set that has insertion order iteration characteristics.
This file defines the SmallPtrSet class.
This file defines the SmallString class.
This file defines the SmallVector class.
StringSet - A set-like wrapper for the StringMap.
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)
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Encapsulate the names of CFI target functions.
std::vector< std::pair< StringRef, GlobalValue::GUID > > getSortedSymbols() const
API used for serialization, e.g. YAML.
auto getExportedThinLTOGUIDs() const
get the set of GUIDs that should also be exported because they are the GUIDs of the cfi functions enc...
CfiFunctionIndex(CfiFunctionIndex &&)=default
auto getNamesForGUID(GlobalValue::GUID GUID) const
get the name(s) associated with a given ThinLTO GUID.
void addSymbolWithThinLTOGUID(StringRef Name, GlobalValue::GUID GUID)
Add the function name and the GUID that ThinLTO uses for it.
bool contains(StringRef Name) const
CfiFunctionIndex()=default
CfiFunctionIndex(const CfiFunctionIndex &)=delete
This class represents a range of values.
Implements a dense probed hash-table based set.
Function summary information to aid decisions and implementation of importing.
static LLVM_ABI FunctionSummary ExternalNode
A dummy node to reference external functions that aren't in the index.
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()
void addCallsite(CallsiteInfo &&Callsite)
ArrayRef< ConstVCall > type_test_assume_const_vcalls() const
Returns the list of virtual calls made by this function using llvm.assume(llvm.type....
std::pair< ValueInfo, CalleeInfo > EdgeTy
<CalleeValueInfo, CalleeInfo> call edge pair.
LLVM_ABI std::pair< unsigned, unsigned > specialRefCounts() const
SmallVector< EdgeTy, 0 > & mutableCalls()
ArrayRef< AllocInfo > allocs() const
ArrayRef< CallsiteInfo > callsites() const
void addAlloc(AllocInfo &&Alloc)
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.
An owning range over the entries sorted by key, yielding each entry by reference.
pointee_iterator< SortedEntriesVec::const_iterator > iterator
SortedEntriesRange(SortedEntriesVec Entries)
Map from global value GUID to corresponding summary structures.
iterator find(key_type Key)
std::pair< iterator, bool > try_emplace(key_type Key, Ts &&...Args)
const_iterator end() const
std::pair< key_type, mapped_type > value_type
GlobalValueSummaryInfo mapped_type
const_iterator begin() const
std::deque< value_type >::size_type size_type
SortedEntriesRange sortedRange() const
Return an owning range over the entries sorted by key.
GlobalValue::GUID key_type
const_iterator find(key_type Key) const
std::deque< value_type >::iterator iterator
std::deque< value_type >::const_iterator const_iterator
Function and variable summary information to aid decisions and implementation of importing.
SummaryKind
Sububclass discriminator (for dyn_cast<> et al.)
void setExternalLinkageForTest()
friend class ModuleSummaryIndex
GVFlags flags() const
Get the flags for this GlobalValue (see struct GVFlags).
void setDSOLocal(bool Local)
bool noRenameOnPromotion() const
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 setNoRenameOnPromotion(bool NoRenameOnPromotion)
void setModulePath(StringRef ModPath)
Set the path to the module containing this function, for use in the combined index.
void setNotEligibleToImport()
Flag that this global value cannot be imported.
void setCanAutoHide(bool CanAutoHide)
GlobalValueSummary(SummaryKind K, GVFlags Flags, SmallVectorImpl< ValueInfo > &&Refs)
GlobalValue::LinkageTypes linkage() const
Return linkage type recorded for this global value.
bool notEligibleToImport() const
Return true if this global value can't be imported.
void setImportKind(ImportKind IK)
void setOriginalName(GlobalValue::GUID Name)
Initialize the original name hash in this summary.
static LLVM_ABI GUID getGUIDAssumingExternalLinkage(StringRef GlobalName)
Return a 64-bit global unique ID constructed from the name of a global symbol.
static bool isLocalLinkage(LinkageTypes Linkage)
uint64_t GUID
Declare a type to represent a global unique identifier for a global value.
LLVM_ABI GUID getGUID() const
Return a 64-bit global unique ID for this value.
static bool isExternalLinkage(LinkageTypes Linkage)
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.
@ ExternalLinkage
Externally visible function.
@ 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)
A helper class to return the specified delimiter string after the first invocation of operator String...
Class to hold module path string table and global value map, and encapsulate methods for operating on...
bool withAttributePropagation() const
bool withInternalizeAndPromote() 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.
static constexpr uint64_t BitcodeSummaryVersion
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 ...
LLVM_ABI bool isGUIDLive(GlobalValue::GUID GUID) const
gvsummary_iterator begin()
const_gvsummary_iterator end() const
bool isReadOnly(const GlobalVarSummary *GVS) const
LLVM_ABI void setFlags(uint64_t Flags)
const_gvsummary_iterator begin() const
CfiFunctionIndex & cfiFunctionDecls()
bool isWriteOnly(const GlobalVarSummary *GVS) const
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()
const CfiFunctionIndex & cfiFunctionDefs() const
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
LLVM_ABI void collectDefinedFunctionsForModule(StringRef ModulePath, GVSummaryMapTy &GVSummaryMap) const
Collect for the given module the list of functions it defines (GUID -> Summary).
const auto & typeIdCompatibleVtableMap() const
LLVM_ABI void dumpSCCs(raw_ostream &OS)
Print out strongly connected components for debugging.
bool isGlobalValueLive(const GlobalValueSummary *GVS) const
bool enableSplitLTOUnit() const
void setWithSupportsHotColdNew()
const ModuleInfo * getModule(StringRef ModPath) const
Return module entry for module with the given ModPath.
LLVM_ABI void propagateAttributes(const DenseSet< GlobalValue::GUID > &PreservedSymbols)
Do the access attribute and DSOLocal propagation in combined index.
void setSkipModuleByDistributedBackend()
ValueInfo getOrInsertValueInfo(const GlobalValue *GV, GlobalValue::GUID GUID)
Return a ValueInfo for GV with GUID GUID and mark it as belonging to GV.
void setWithAttributePropagation()
const StringMap< ModuleHash > & modulePaths() const
Table of modules, containing module hash and id.
bool withSupportsHotColdNew() const
LLVM_ABI 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.
static std::string getGlobalNameForLocal(StringRef Name, ModuleHash ModHash)
Convenience method for creating a promoted global name for the given value name of a local,...
GlobalValueSummaryMapTy::SortedEntriesRange sortedGlobalValueSummariesRange() const
bool withDSOLocalPropagation() const
LLVM_ABI 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 setWithInternalizeAndPromote()
LLVM_ABI void print(raw_ostream &OS, bool IsForDebug=false) const
Print to an output stream.
bool skipModuleByDistributedBackend() const
CfiFunctionIndex & cfiFunctionDefs()
ValueInfo getOrInsertValueInfo(const GlobalValue *GV)
Return a ValueInfo for GV and mark it as belonging to GV.
GlobalValueSummary * findSummaryInModule(ValueInfo VI, StringRef ModuleId) const
Find the summary for ValueInfo VI in module ModuleId, or nullptr if not found.
ValueInfo getValueInfo(GlobalValue::GUID GUID) const
Return a ValueInfo for GUID if it exists, otherwise return ValueInfo().
LLVM_ABI uint64_t getFlags() const
unsigned addOrGetStackIdIndex(uint64_t StackId)
GlobalValue::GUID getGUIDFromOriginalID(GlobalValue::GUID OriginalID) const
Return the GUID for OriginalId in the OidGuidMap.
GlobalValueSummary * getGlobalValueSummary(const GlobalValue &GV, bool PerModuleIndex=true) const
Returns the first GlobalValueSummary for GV, asserting that there is only one if PerModuleIndex.
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()
LLVM_ABI bool canImportGlobalVar(const GlobalValueSummary *S, bool AnalyzeRefs) const
Checks if we can import global variable from another module.
static std::string getGlobalNameForLocal(StringRef Name, StringRef Suffix)
void addOriginalName(GlobalValue::GUID ValueGUID, GlobalValue::GUID OrigGUID)
Add an original name for the value of the given GUID.
FunctionSummary calculateCallGraphRoot()
const CfiFunctionIndex & cfiFunctionDecls() const
TypeIdSummary * getTypeIdSummary(StringRef TypeId)
TypeIdCompatibleVtableInfo & getOrInsertTypeIdCompatibleVtableSummary(StringRef TypeId)
Return an existing or new TypeIdCompatibleVtableMap entry for TypeId.
A Module instance is used to store all the information related to an LLVM module.
PointerIntPair - This class implements a pair of a pointer and small integer.
A vector that has set insertion semantics.
typename vector_type::const_iterator const_iterator
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
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 reserve(size_type N)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
StringMapEntry< ModuleHash > value_type
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
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.
StringSet - A wrapper for StringMap that provides set-like functionality.
Saves strings in the provided stable storage and returns a StringRef with a stable character pointer.
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.
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
bool operator<(int64_t V1, const APSInt &V2)
StringMapEntry< Value * > ValueName
std::vector< VirtFuncOffset > VTableFuncList
List of functions referenced by a particular vtable definition.
hash_code hash_value(const FixedPointSemantics &Val)
std::vector< std::unique_ptr< GlobalValueSummary > > GlobalValueSummaryList
@ Unknown
Not known to have no common set bits.
InterleavedRange< Range > interleaved(const Range &R, StringRef Separator=", ", StringRef Prefix="", StringRef Suffix="")
Output range R as a sequence of interleaved elements.
const char * getHotnessName(CalleeInfo::HotnessType HT)
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
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).
std::array< uint32_t, 5 > ModuleHash
160 bits SHA1
bool operator!=(uint64_t V1, const APInt &V2)
DenseMap< GlobalValue::GUID, GlobalValueSummary * > GVSummaryMapTy
Map of global value GUID to its summary, used to identify values defined in a particular module,...
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
std::string utostr(uint64_t X, bool isNeg=false)
bool operator==(const AddressRangeValuePair &LHS, const AddressRangeValuePair &RHS)
auto map_range(ContainerTy &&C, FuncTy F)
Return a range that applies F to the elements of C.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
constexpr detail::StaticCastFunc< To > StaticCastTo
Function objects corresponding to the Cast types defined above.
GlobalValueSummaryMapTy::iterator gvsummary_iterator
void sort(IteratorTy Start, IteratorTy End)
GlobalValueSummaryMap GlobalValueSummaryMapTy
std::map< std::string, GVSummaryMapTy, std::less<> > ModuleToSummariesForIndexTy
Map of a module name to the GUIDs and summaries we will import from that module.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
StringMap< ModuleHash > ModulePathStringTableTy
String table to hold/own module path strings, as well as a hash of the module.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
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::vector< TypeIdOffsetVtableInfo > TypeIdCompatibleVtableInfo
List of vtable definitions decorated by a particular type identifier, and their corresponding offsets...
GlobalValueSummaryMapTy::const_iterator const_gvsummary_iterator
Type used for iterating through the global value summary map.
BumpPtrAllocatorImpl<> BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
SmallPtrSet< GlobalValueSummary *, 0 > GVSummaryPtrSet
A set of global value summary pointers.
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.
CalleeInfo(HotnessType Hotness, bool HasTC)
void updateHotness(const HotnessType OtherHotness)
HotnessType getHotness() const
void setHasTailCall(const bool HasTC)
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 unsigned getHashValue(FunctionSummary::ConstVCall I)
static bool isEqual(FunctionSummary::ConstVCall L, FunctionSummary::ConstVCall R)
static bool isEqual(FunctionSummary::VFuncId L, FunctionSummary::VFuncId R)
static unsigned getHashValue(FunctionSummary::VFuncId I)
static bool isEqual(ValueInfo L, ValueInfo R)
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
Call(uint64_t ParamNo, ValueInfo Callee, const ConstantRange &Offsets)
ParamAccess(uint64_t ParamNo, const ConstantRange &Use)
static constexpr uint32_t RangeWidth
std::vector< Call > Calls
In the per-module summary, it summarizes the byte offset applied to each pointer parameter before pas...
ConstantRange Use
The range contains byte offsets from the parameter pointer which accessed by the function.
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.
void addSummary(std::unique_ptr< GlobalValueSummary > Summary)
Add a summary corresponding to a global value definition in a module with the corresponding GUID.
void verifyLocal() const
Verify that the HasLocal flag is consistent with the SummaryList.
ArrayRef< std::unique_ptr< GlobalValueSummary > > getSummaryList() const
Access a read-only list of global value summary structures for a particular value held in the GlobalV...
GlobalValueSummaryInfo(bool HaveGVs)
union llvm::GlobalValueSummaryInfo::NameOrGV U
Group flags (Linkage, NotEligibleToImport, etc.) as a bitfield.
unsigned NoRenameOnPromotion
This field is written by the ThinLTO prelink stage to decide whether a particular static global value...
unsigned DSOLocal
Indicates that the linker resolved the symbol to a definition from within the same linkage unit.
unsigned Promoted
This symbol was promoted.
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.
GVFlags(GlobalValue::LinkageTypes Linkage, GlobalValue::VisibilityTypes Visibility, bool NotEligibleToImport, bool Live, bool IsLocal, bool CanAutoHide, ImportKind ImportType, bool NoRenameOnPromotion)
Convenience Constructors.
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)
SmallVector< FunctionSummary::EdgeTy, 0 >::iterator ChildEdgeIteratorType
mapped_iterator< SmallVector< FunctionSummary::EdgeTy, 0 >::iterator, decltype(&valueInfoFromEdge)> ChildIteratorType
static NodeRef getEntryNode(ValueInfo V)
static ChildIteratorType child_end(NodeRef N)
static ChildEdgeIteratorType child_edge_end(NodeRef N)
FunctionSummary::EdgeTy & EdgeRef
typename ModuleSummaryIndex *::UnknownGraphTypeError NodeRef
Summary of a single MIB in a memprof metadata on allocations.
MIBInfo(AllocationType AllocType, SmallVector< unsigned > StackIdIndices)
SmallVector< unsigned > StackIdIndices
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
LLVM_ABI GlobalValue::VisibilityTypes getELFVisibility() const
Returns the most constraining visibility among summaries.
bool isValidAccessSpecifier() const
const GlobalValueSummaryMapTy::value_type * getRef() const
ArrayRef< std::unique_ptr< GlobalValueSummary > > getSummaryList() const
const GlobalValue * getValue() const
ValueInfo(bool HaveGVs, const GlobalValueSummaryMapTy::value_type *R)
LLVM_ABI bool canAutoHide() const
Checks if all copies are eligible for auto-hiding (have flag set).
unsigned getAccessSpecifier() const
LLVM_ABI bool isDSOLocal(bool WithDSOLocalPropagation=false) const
Checks if all summaries are DSO local (have the flag set).
GlobalValue::GUID getGUID() const
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::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.
An iterator type that allows iterating over the pointees via some other iterator.
This class should be specialized by any type that needs to be converted to/from a YAML mapping.
const GlobalValue * GV
The GlobalValue corresponding to this summary.
StringRef Name
Summary string representation.