16 #ifndef LLVM_IR_MODULESUMMARYINDEX_H
17 #define LLVM_IR_MODULESUMMARYINDEX_H
67 class GlobalValueSummary;
89 std::map<GlobalValue::GUID, GlobalValueSummaryInfo>;
94 const GlobalValueSummaryMapTy::value_type *
Ref =
nullptr;
97 ValueInfo(
const GlobalValueSummaryMapTy::value_type *
Ref) : Ref(Ref) {}
105 return Ref->second.SummaryList;
111 return ValueInfo((GlobalValueSummaryMapTy::value_type *)-1);
115 return ValueInfo((GlobalValueSummaryMapTy::value_type *)-2);
154 : Linkage(Linkage), NotEligibleToImport(NotEligibleToImport),
182 std::vector<ValueInfo> RefEdgeList;
184 bool isLive()
const {
return Flags.
Live; }
188 : Kind(K), Flags(Flags), RefEdgeList(std::move(Refs)) {}
256 assert(AliaseeSummary &&
"Unexpected missing aliasee summary");
257 return *AliaseeSummary;
271 using EdgeTy = std::pair<ValueInfo, CalleeInfo>;
296 std::vector<EdgeTy> CallGraphEdgeList;
303 std::vector<GlobalValue::GUID> TypeTests;
308 std::vector<VFuncId> TypeTestAssumeVCalls, TypeCheckedLoadVCalls;
313 std::vector<ConstVCall> TypeTestAssumeConstVCalls,
314 TypeCheckedLoadConstVCalls;
317 std::unique_ptr<TypeIdInfo> TIdInfo;
321 std::vector<EdgeTy> CGEdges,
322 std::vector<GlobalValue::GUID> TypeTests,
323 std::vector<VFuncId> TypeTestAssumeVCalls,
324 std::vector<VFuncId> TypeCheckedLoadVCalls,
325 std::vector<ConstVCall> TypeTestAssumeConstVCalls,
326 std::vector<ConstVCall> TypeCheckedLoadConstVCalls)
328 InstCount(NumInsts), CallGraphEdgeList(std::move(CGEdges)) {
329 if (!TypeTests.empty() || !TypeTestAssumeVCalls.empty() ||
330 !TypeCheckedLoadVCalls.empty() || !TypeTestAssumeConstVCalls.empty() ||
331 !TypeCheckedLoadConstVCalls.empty())
332 TIdInfo = llvm::make_unique<TypeIdInfo>(TypeIdInfo{
333 std::move(TypeTests), std::move(TypeTestAssumeVCalls),
334 std::move(TypeCheckedLoadVCalls),
335 std::move(TypeTestAssumeConstVCalls),
336 std::move(TypeCheckedLoadConstVCalls)});
355 return TIdInfo->TypeTests;
364 return TIdInfo->TypeTestAssumeVCalls;
373 return TIdInfo->TypeCheckedLoadVCalls;
382 return TIdInfo->TypeTestAssumeConstVCalls;
390 return TIdInfo->TypeCheckedLoadConstVCalls;
398 TIdInfo = llvm::make_unique<TypeIdInfo>();
399 TIdInfo->TypeTests.push_back(Guid);
407 return {0, uint64_t(-2)};
419 return {{0, uint64_t(-1)}, {}};
423 return {{0, uint64_t(-2)}, {}};
508 std::map<uint64_t, WholeProgramDevirtResolution>
WPDRes;
541 std::map<std::string, TypeIdSummary> TypeIdMap;
545 std::map<GlobalValue::GUID, GlobalValue::GUID> OidGuidMap;
550 bool WithGlobalValueDeadStripping =
false;
552 std::set<std::string> CfiFunctionDefs;
553 std::set<std::string> CfiFunctionDecls;
558 GlobalValueSummaryMapTy::value_type *
568 size_t size()
const {
return GlobalValueMap.size(); }
571 return WithGlobalValueDeadStripping;
574 WithGlobalValueDeadStripping =
true;
578 return !WithGlobalValueDeadStripping || GVS->isLive();
584 auto I = GlobalValueMap.find(GUID);
585 return ValueInfo(
I == GlobalValueMap.end() ?
nullptr : &*
I);
590 return ValueInfo(getOrInsertValuePtr(GUID));
595 auto VP = getOrInsertValuePtr(GV->
getGUID());
602 const auto I = OidGuidMap.find(OriginalID);
603 return I == OidGuidMap.end() ? 0 :
I->second;
614 std::unique_ptr<GlobalValueSummary> Summary) {
621 std::unique_ptr<GlobalValueSummary> Summary) {
625 const_cast<GlobalValueSummaryMapTy::value_type *
>(VI.
Ref)
626 ->
second.SummaryList.push_back(std::move(Summary));
632 if (OrigGUID == 0 || ValueGUID == OrigGUID)
634 if (OidGuidMap.count(OrigGUID) && OidGuidMap[OrigGUID] != ValueGUID)
635 OidGuidMap[OrigGUID] = 0;
637 OidGuidMap[OrigGUID] = ValueGUID;
650 [&](
const std::unique_ptr<GlobalValueSummary> &Summary) {
651 return Summary->modulePath() == ModuleId;
653 if (Summary ==
CalleeInfo.getSummaryList().end())
655 return Summary->get();
661 bool PerModuleIndex =
true)
const {
662 assert(GV.
hasName() &&
"Can't get GlobalValueSummary for GV with no name");
671 bool PerModuleIndex =
true)
const;
675 return ModulePathStringTable;
680 return ModulePathStringTable;
685 return ModulePathStringTable.lookup(ModPath).first;
690 auto It = ModulePathStringTable.find(ModPath);
691 assert(It != ModulePathStringTable.end() &&
"Module not registered");
692 return It->second.second;
701 return NewName.
str();
707 std::pair<StringRef, StringRef> Pair = Name.
split(
".llvm.");
717 return &*ModulePathStringTable.insert({ModPath, {ModId,
Hash}}).
first;
727 const std::map<std::string, TypeIdSummary> &
typeIds()
const {
734 return TypeIdMap[TypeId];
740 auto I = TypeIdMap.find(TypeId);
741 if (
I == TypeIdMap.end())
759 #endif // LLVM_IR_MODULESUMMARYINDEX_H
static FunctionSummary::ConstVCall getEmptyKey()
unsigned Live
In per-module summary, indicate that the global value must be considered a live root for index-based ...
const GlobalValueSummaryMapTy::value_type * Ref
void setNotEligibleToImport()
Flag that this global value cannot be imported.
static bool classof(const GlobalValueSummary *GVS)
Check if this is an alias summary.
static FunctionSummary::ConstVCall getTombstoneKey()
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
uint64_t GUID
Declare a type to represent a global unique identifier for a global value.
const ModuleHash & getModuleHash(const StringRef ModPath) const
Get the module SHA1 hash recorded for the given module path.
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
unsigned Linkage
The linkage type of the associated global value.
ValueInfo getValueInfo(GlobalValue::GUID GUID) const
Return a ValueInfo for GUID if it exists, otherwise return ValueInfo().
A Module instance is used to store all the information related to an LLVM module. ...
GUID getGUID() const
Return a 64-bit global unique ID constructed from global value name (i.e.
Global variable summary information to aid decisions and implementation of importing.
ArrayRef< ConstVCall > type_test_assume_const_vcalls() const
Returns the list of virtual calls made by this function using llvm.assume(llvm.type.test) intrinsics with all constant integer arguments.
Unsatisfiable type (i.e. no global has this type metadata)
Implements a dense probed hash-table based set.
void addTypeTest(GlobalValue::GUID Guid)
Add a type test to the summary.
bool withGlobalValueDeadStripping() const
ValueInfo(const GlobalValueSummaryMapTy::value_type *Ref)
uint64_t Info
Additional information for the resolution:
GlobalValueSummaryMapTy::iterator gvsummary_iterator
static StringRef getOriginalNameBeforePromote(StringRef Name)
Helper to obtain the unpromoted name for a global value (or the original name if not promoted)...
bool isGlobalValueLive(const GlobalValueSummary *GVS) const
const GlobalValue * getValue() const
Kind
Specifies which kind of type check we should emit for this byte array.
static unsigned getHashValue(ValueInfo I)
Virtual constant propagation.
std::map< uint64_t, WholeProgramDevirtResolution > WPDRes
Mapping from byte offset to whole-program devirt resolution for that (typeid, byte offset) pair...
StringMap< std::pair< uint64_t, ModuleHash > > & modulePaths()
Table of modules, containing hash and id.
GlobalValue::GUID getOriginalName()
Returns the hash of the original name, it is identical to the GUID for externally visible symbols...
StringRef getName() const
Return a constant reference to the value's name.
void addOriginalName(GlobalValue::GUID ValueGUID, GlobalValue::GUID OrigGUID)
Add an original name for the value of the given GUID.
static bool isEqual(ValueInfo L, ValueInfo R)
FunctionSummary(GVFlags Flags, unsigned NumInsts, std::vector< ValueInfo > Refs, std::vector< EdgeTy > CGEdges, std::vector< GlobalValue::GUID > TypeTests, std::vector< VFuncId > TypeTestAssumeVCalls, std::vector< VFuncId > TypeCheckedLoadVCalls, std::vector< ConstVCall > TypeTestAssumeConstVCalls, std::vector< ConstVCall > TypeCheckedLoadConstVCalls)
unsigned NotEligibleToImport
Indicate if the global value cannot be imported (e.g.
static unsigned getHashValue(FunctionSummary::VFuncId I)
GVFlags flags()
Get the flags for this GlobalValue (see struct GVFlags).
ArrayRef< ConstVCall > type_checked_load_const_vcalls() const
Returns the list of virtual calls made by this function using llvm.type.checked.load intrinsics with ...
static std::string getGlobalNameForLocal(StringRef Name, ModuleHash ModHash)
Convenience method for creating a promoted global name for the given value name of a local...
std::array< uint32_t, 5 > ModuleHash
160 bits SHA1
Just do a regular virtual call.
StringMap< std::pair< uint64_t, ModuleHash >> ModulePathStringTableTy
String table to hold/own module path strings, which additionally holds the module ID assigned to each...
std::map< GlobalValue::GUID, GlobalValueSummaryInfo > GlobalValueSummaryMapTy
Map from global value GUID to corresponding summary structures.
const std::string & getModuleIdentifier() const
Get the module identifier which is, essentially, the name of the module.
std::vector< std::unique_ptr< GlobalValueSummary >> GlobalValueSummaryList
void setWithGlobalValueDeadStripping()
enum llvm::WholeProgramDevirtResolution::Kind TheKind
const GlobalValueSummary & getAliasee() const
uint64_t getModuleId(const StringRef ModPath) const
Get the module ID recorded for the given module path.
Uniform return value optimization.
unsigned instCount() const
Get the instruction count recorded for this function.
ArrayRef< VFuncId > type_checked_load_vcalls() const
Returns the list of virtual calls made by this function using llvm.type.checked.load intrinsics that ...
This class should be specialized by any type that needs to be converted to/from a YAML mapping...
static bool isEqual(const Function &Caller, const Function &Callee)
std::pair< ValueInfo, CalleeInfo > EdgeTy
<CalleeValueInfo, CalleeInfo> call edge pair.
friend void computeDeadSymbols(class ModuleSummaryIndex &, const DenseSet< GlobalValue::GUID > &)
Compute all the symbols that are "dead": i.e these that can't be reached in the graph from any of t...
const StringMap< std::pair< uint64_t, ModuleHash > > & modulePaths() const
Table of modules, containing module hash and id.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
TypeIdSummary & getOrInsertTypeIdSummary(StringRef TypeId)
This accessor should only be used when exporting because it can mutate the map.
const std::set< std::string > & cfiFunctionDecls() const
ModulePathStringTableTy::value_type ModuleInfo
Class to hold module path string table and global value map, and encapsulate methods for operating on...
static bool isEqual(FunctionSummary::VFuncId L, FunctionSummary::VFuncId R)
StringRef modulePath() const
Get the path to the module containing this function.
ArrayRef< VFuncId > type_test_assume_vcalls() const
Returns the list of virtual calls made by this function using llvm.assume(llvm.type.test) intrinsics that do not have all constant integer arguments.
bool notEligibleToImport() const
Return true if this global value can't be imported.
CalleeInfo(HotnessType Hotness)
static unsigned getHashValue(FunctionSummary::ConstVCall I)
GlobalValueSummaryMapTy::const_iterator const_gvsummary_iterator
Type used for iterating through the global value summary map.
void collectDefinedFunctionsForModule(StringRef ModulePath, GVSummaryMapTy &GVSummaryMap) const
Collect for the given module the list of function it defines (GUID -> Summary).
ArrayRef< EdgeTy > calls() const
Return the list of <CalleeValueInfo, CalleeInfo> pairs.
static FunctionSummary::VFuncId getEmptyKey()
AliasSummary(GVFlags Flags, std::vector< ValueInfo > Refs)
static bool classof(const GlobalValueSummary *GVS)
Check if this is a global variable summary.
const GlobalValue * GV
The GlobalValue corresponding to this summary.
std::vector< uint64_t > Args
static ValueInfo getEmptyKey()
SummaryKind getSummaryKind() const
Which kind of summary subclass this is.
Class to accumulate and hold information about a callee.
Single element (last example in "Short Inline Bit Vectors")
bool hasExportedFunctions(const Module &M) const
Check if the given Module has any functions available for exporting in the index. ...
enum llvm::WholeProgramDevirtResolution::ByArg::Kind TheKind
ValueInfo getOrInsertValueInfo(const GlobalValue *GV)
Return a ValueInfo for GV and mark it as belonging to GV.
GlobalValue::GUID getGUIDFromOriginalID(GlobalValue::GUID OriginalID) const
Return the GUID for OriginalId in the OidGuidMap.
Function and variable summary information to aid decisions and implementation of importing.
static GUID getGUID(StringRef GlobalName)
Return a 64-bit global unique ID constructed from global value name (i.e.
static ValueInfo getTombstoneKey()
void addGlobalValueSummary(StringRef ValueName, std::unique_ptr< GlobalValueSummary > Summary)
Add a global value summary for a value of the given name.
An "identifier" for a virtual function.
void addGlobalValueSummary(ValueInfo VI, std::unique_ptr< GlobalValueSummary > Summary)
Add a global value summary for the given ValueInfo.
Struct that holds a reference to a particular GUID in a global value summary.
void updateHotness(const HotnessType OtherHotness)
ModuleInfo * addModule(StringRef ModPath, uint64_t ModId, ModuleHash Hash=ModuleHash{{0}})
Add a new module with the given Hash, mapped to the given ModID, and return a reference to the module...
static bool classof(const GlobalValueSummary *GVS)
Check if this is a function summary.
Module.h This file contains the declarations for the Module class.
ArrayRef< GlobalValue::GUID > type_tests() const
Returns the list of type identifiers used by this function in llvm.type.test intrinsics other than by...
Single implementation devirtualization.
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 ...
Alias summary information.
virtual ~GlobalValueSummary()=default
GlobalValueSummary * findSummaryInModule(GlobalValue::GUID ValueGUID, StringRef ModuleId) const
Find the summary for global GUID in module ModuleId, or nullptr if not found.
std::string SingleImplName
enum llvm::TypeTestResolution::Kind TheKind
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
GlobalValue::LinkageTypes linkage() const
Return linkage type recorded for this global value.
A specification for a virtual function call with all constant integer arguments.
StringRef str() const
Explicit conversion to StringRef.
LinkageTypes
An enumeration for the kinds of linkage for global values.
LLVM_NODISCARD std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
void collectDefinedGVSummariesPerModule(StringMap< GVSummaryMapTy > &ModuleToDefinedGVSummaries) const
Collect for each module the list of Summaries it defines (GUID -> Summary).
SummaryKind
Sububclass discriminator (for dyn_cast<> et al.)
ValueInfo getOrInsertValueInfo(GlobalValue::GUID GUID)
Return a ValueInfo for GUID.
GlobalValueSummary(SummaryKind K, GVFlags Flags, std::vector< ValueInfo > Refs)
std::set< std::string > & cfiFunctionDefs()
Test a byte array (first example)
const_gvsummary_iterator end() const
GlobalVarSummary(GVFlags Flags, std::vector< ValueInfo > Refs)
std::map< std::vector< uint64_t >, ByArg > ResByArg
Resolutions for calls with all constant integer arguments (excluding the first argument, "this"), where the key is the argument vector.
void setLinkage(GlobalValue::LinkageTypes Linkage)
Sets the linkage to the value determined by global summary-based optimization.
All-ones bit vector ("Eliminating Bit Vector Checks for All-Ones Bit Vectors") ...
bool isGUIDLive(GlobalValue::GUID GUID) const
const_gvsummary_iterator begin() const
void setOriginalName(GlobalValue::GUID Name)
Initialize the original name hash in this summary.
ArrayRef< std::unique_ptr< GlobalValueSummary > > getSummaryList() const
GVFlags(GlobalValue::LinkageTypes Linkage, bool NotEligibleToImport, bool Live)
Convenience Constructors.
Inlined bit vector ("Short Inline Bit Vectors")
unsigned SizeM1BitWidth
Range of size-1 expressed as a bit width.
Function summary information to aid decisions and implementation of importing.
GlobalValueSummary & getAliasee()
void setModulePath(StringRef ModPath)
Set the path to the module containing this function, for use in the combined index.
GlobalValue::GUID getGUID() const
static std::string utohexstr(uint64_t X, bool LowerCase=false)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
std::set< std::string > & cfiFunctionDecls()
static FunctionSummary::VFuncId getTombstoneKey()
Just do a regular virtual call.
void setAliasee(GlobalValueSummary *Aliasee)
GlobalValueSummary * getGlobalValueSummary(const GlobalValue &GV, bool PerModuleIndex=true) const
Returns the first GlobalValueSummary for GV, asserting that there is only one if PerModuleIndex.
Group flags (Linkage, NotEligibleToImport, etc.) as a bitfield.
ArrayRef< ValueInfo > refs() const
Return the list of values referenced by this global value definition.
std::string Hash(const Unit &U)
gvsummary_iterator begin()
StringRef - Represent a constant reference to a string, i.e.
const std::set< std::string > & cfiFunctionDefs() const
static bool isEqual(FunctionSummary::ConstVCall L, FunctionSummary::ConstVCall R)
auto find_if(R &&Range, UnaryPredicate P) -> decltype(std::begin(Range))
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly...
const std::map< std::string, TypeIdSummary > & typeIds() const
GlobalValueSummaryList SummaryList
List of global value summary structures for a particular value held in the GlobalValueMap.
Unique return value optimization.