2016-03-15 01:04:37 +01:00
|
|
|
//===-- llvm/ModuleSummaryIndex.h - Module Summary Index --------*- C++ -*-===//
|
2016-03-14 22:18:10 +01:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
/// @file
|
2016-03-15 01:04:37 +01:00
|
|
|
/// ModuleSummaryIndex.h This file contains the declarations the classes that
|
|
|
|
/// hold the module index and summary for function importing.
|
2016-03-14 22:18:10 +01:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2016-03-15 01:04:37 +01:00
|
|
|
#ifndef LLVM_IR_MODULESUMMARYINDEX_H
|
|
|
|
#define LLVM_IR_MODULESUMMARYINDEX_H
|
2016-03-14 22:18:10 +01:00
|
|
|
|
|
|
|
#include "llvm/ADT/DenseMap.h"
|
|
|
|
#include "llvm/ADT/DenseSet.h"
|
2016-04-11 15:58:45 +02:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2016-03-14 22:18:10 +01:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
2016-04-12 01:26:46 +02:00
|
|
|
#include "llvm/ADT/StringExtras.h"
|
2016-03-14 22:18:10 +01:00
|
|
|
#include "llvm/ADT/StringMap.h"
|
|
|
|
#include "llvm/IR/Module.h"
|
|
|
|
|
2016-04-01 07:33:11 +02:00
|
|
|
#include <array>
|
|
|
|
|
2016-03-14 22:18:10 +01:00
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
/// \brief Class to accumulate and hold information about a callee.
|
|
|
|
struct CalleeInfo {
|
|
|
|
/// The static number of callsites calling corresponding function.
|
|
|
|
unsigned CallsiteCount;
|
|
|
|
/// The cumulative profile count of calls to corresponding function
|
|
|
|
/// (if using PGO, otherwise 0).
|
|
|
|
uint64_t ProfileCount;
|
|
|
|
CalleeInfo() : CallsiteCount(0), ProfileCount(0) {}
|
|
|
|
CalleeInfo(unsigned CallsiteCount, uint64_t ProfileCount)
|
|
|
|
: CallsiteCount(CallsiteCount), ProfileCount(ProfileCount) {}
|
|
|
|
CalleeInfo &operator+=(uint64_t RHSProfileCount) {
|
|
|
|
CallsiteCount++;
|
|
|
|
ProfileCount += RHSProfileCount;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-04-11 15:58:45 +02:00
|
|
|
/// Struct to hold value either by GUID or Value*, depending on whether this
|
|
|
|
/// is a combined or per-module index, respectively.
|
|
|
|
struct ValueInfo {
|
|
|
|
/// The value representation used in this instance.
|
|
|
|
enum ValueInfoKind {
|
|
|
|
VI_GUID,
|
|
|
|
VI_Value,
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Union of the two possible value types.
|
|
|
|
union ValueUnion {
|
|
|
|
GlobalValue::GUID Id;
|
|
|
|
const Value *V;
|
|
|
|
ValueUnion(GlobalValue::GUID Id) : Id(Id) {}
|
|
|
|
ValueUnion(const Value *V) : V(V) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
/// The value being represented.
|
|
|
|
ValueUnion TheValue;
|
|
|
|
/// The value representation.
|
|
|
|
ValueInfoKind Kind;
|
|
|
|
/// Constructor for a GUID value
|
|
|
|
ValueInfo(GlobalValue::GUID Id = 0) : TheValue(Id), Kind(VI_GUID) {}
|
|
|
|
/// Constructor for a Value* value
|
|
|
|
ValueInfo(const Value *V) : TheValue(V), Kind(VI_Value) {}
|
|
|
|
/// Accessor for GUID value
|
|
|
|
GlobalValue::GUID getGUID() const {
|
|
|
|
assert(Kind == VI_GUID && "Not a GUID type");
|
|
|
|
return TheValue.Id;
|
|
|
|
}
|
|
|
|
/// Accessor for Value* value
|
|
|
|
const Value *getValue() const {
|
|
|
|
assert(Kind == VI_Value && "Not a Value type");
|
|
|
|
return TheValue.V;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-03-14 22:18:10 +01:00
|
|
|
/// \brief Function and variable summary information to aid decisions and
|
|
|
|
/// implementation of importing.
|
|
|
|
class GlobalValueSummary {
|
|
|
|
public:
|
|
|
|
/// \brief Sububclass discriminator (for dyn_cast<> et al.)
|
2016-04-16 08:56:44 +02:00
|
|
|
enum SummaryKind { AliasKind, FunctionKind, GlobalVarKind };
|
2016-03-14 22:18:10 +01:00
|
|
|
|
2016-04-24 05:18:18 +02:00
|
|
|
/// Group flags (Linkage, hasSection, isOptSize, etc.) as a bitfield.
|
|
|
|
struct GVFlags {
|
|
|
|
/// \brief The linkage type of the associated global value.
|
|
|
|
///
|
|
|
|
/// One use is to flag values that have local linkage types and need to
|
|
|
|
/// have module identifier appended before placing into the combined
|
|
|
|
/// index, to disambiguate from other values with the same name.
|
|
|
|
/// In the future this will be used to update and optimize linkage
|
|
|
|
/// types based on global summary-based analysis.
|
2016-04-24 16:25:37 +02:00
|
|
|
unsigned Linkage : 4;
|
2016-04-24 05:18:18 +02:00
|
|
|
|
2016-04-24 07:31:43 +02:00
|
|
|
/// Indicate if the global value is located in a specific section.
|
|
|
|
unsigned HasSection : 1;
|
|
|
|
|
2016-04-24 05:18:18 +02:00
|
|
|
/// Convenience Constructors
|
2016-04-24 07:31:43 +02:00
|
|
|
explicit GVFlags(GlobalValue::LinkageTypes Linkage, bool HasSection)
|
|
|
|
: Linkage(Linkage), HasSection(HasSection) {}
|
|
|
|
GVFlags(const GlobalValue &GV)
|
|
|
|
: Linkage(GV.getLinkage()), HasSection(GV.hasSection()) {}
|
2016-04-24 05:18:18 +02:00
|
|
|
};
|
|
|
|
|
2016-03-14 22:18:10 +01:00
|
|
|
private:
|
|
|
|
/// Kind of summary for use in dyn_cast<> et al.
|
|
|
|
SummaryKind Kind;
|
|
|
|
|
2016-04-24 01:38:17 +02:00
|
|
|
/// This is the hash of the name of the symbol in the original file. It is
|
|
|
|
/// identical to the GUID for global symbols, but differs for local since the
|
|
|
|
/// GUID includes the module level id in the hash.
|
|
|
|
GlobalValue::GUID OriginalName;
|
|
|
|
|
2016-03-14 22:18:10 +01:00
|
|
|
/// \brief Path of module IR containing value's definition, used to locate
|
|
|
|
/// module during importing.
|
|
|
|
///
|
|
|
|
/// This is only used during parsing of the combined index, or when
|
2016-03-15 01:04:37 +01:00
|
|
|
/// parsing the per-module index for creation of the combined summary index,
|
2016-03-14 22:18:10 +01:00
|
|
|
/// not during writing of the per-module index which doesn't contain a
|
|
|
|
/// module path string table.
|
|
|
|
StringRef ModulePath;
|
|
|
|
|
2016-04-24 05:18:18 +02:00
|
|
|
GVFlags Flags;
|
2016-03-14 22:18:10 +01:00
|
|
|
|
2016-04-11 15:58:45 +02:00
|
|
|
/// List of values referenced by this global value's definition
|
2016-03-14 22:18:10 +01:00
|
|
|
/// (either by the initializer of a global variable, or referenced
|
|
|
|
/// from within a function). This does not include functions called, which
|
|
|
|
/// are listed in the derived FunctionSummary object.
|
2016-04-11 15:58:45 +02:00
|
|
|
std::vector<ValueInfo> RefEdgeList;
|
2016-03-14 22:18:10 +01:00
|
|
|
|
|
|
|
protected:
|
|
|
|
/// GlobalValueSummary constructor.
|
2016-04-24 05:18:18 +02:00
|
|
|
GlobalValueSummary(SummaryKind K, GVFlags Flags) : Kind(K), Flags(Flags) {}
|
2016-03-14 22:18:10 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
virtual ~GlobalValueSummary() = default;
|
|
|
|
|
2016-04-24 01:38:17 +02:00
|
|
|
/// Returns the hash of the original name, it is identical to the GUID for
|
|
|
|
/// externally visible symbols, but not for local ones.
|
|
|
|
GlobalValue::GUID getOriginalName() { return OriginalName; }
|
|
|
|
|
|
|
|
/// Initialize the original name hash in this summary.
|
|
|
|
void setOriginalName(GlobalValue::GUID Name) { OriginalName = Name; }
|
|
|
|
|
2016-03-14 22:18:10 +01:00
|
|
|
/// Which kind of summary subclass this is.
|
|
|
|
SummaryKind getSummaryKind() const { return Kind; }
|
|
|
|
|
|
|
|
/// Set the path to the module containing this function, for use in
|
|
|
|
/// the combined index.
|
|
|
|
void setModulePath(StringRef ModPath) { ModulePath = ModPath; }
|
|
|
|
|
|
|
|
/// Get the path to the module containing this function.
|
|
|
|
StringRef modulePath() const { return ModulePath; }
|
|
|
|
|
2016-04-24 05:18:18 +02:00
|
|
|
/// Get the flags for this GlobalValue (see \p struct GVFlags).
|
|
|
|
GVFlags flags() { return Flags; }
|
|
|
|
|
2016-03-14 22:18:10 +01:00
|
|
|
/// Return linkage type recorded for this global value.
|
2016-04-24 16:25:37 +02:00
|
|
|
GlobalValue::LinkageTypes linkage() const {
|
|
|
|
return static_cast<GlobalValue::LinkageTypes>(Flags.Linkage);
|
|
|
|
}
|
2016-03-14 22:18:10 +01:00
|
|
|
|
2016-04-24 07:31:43 +02:00
|
|
|
/// Return true if this global value is located in a specific section.
|
|
|
|
bool hasSection() const { return Flags.HasSection; }
|
|
|
|
|
2016-03-14 22:18:10 +01:00
|
|
|
/// Record a reference from this global value to the global value identified
|
|
|
|
/// by \p RefGUID.
|
2016-04-02 07:07:53 +02:00
|
|
|
void addRefEdge(GlobalValue::GUID RefGUID) { RefEdgeList.push_back(RefGUID); }
|
2016-03-14 22:18:10 +01:00
|
|
|
|
2016-04-11 15:58:45 +02:00
|
|
|
/// Record a reference from this global value to the global value identified
|
|
|
|
/// by \p RefV.
|
|
|
|
void addRefEdge(const Value *RefV) { RefEdgeList.push_back(RefV); }
|
|
|
|
|
2016-03-14 22:18:10 +01:00
|
|
|
/// Record a reference from this global value to each global value identified
|
|
|
|
/// in \p RefEdges.
|
2016-04-11 15:58:45 +02:00
|
|
|
void addRefEdges(DenseSet<const Value *> &RefEdges) {
|
2016-03-14 22:18:10 +01:00
|
|
|
for (auto &RI : RefEdges)
|
|
|
|
addRefEdge(RI);
|
|
|
|
}
|
|
|
|
|
2016-04-11 15:58:45 +02:00
|
|
|
/// Return the list of values referenced by this global value definition.
|
|
|
|
std::vector<ValueInfo> &refs() { return RefEdgeList; }
|
|
|
|
const std::vector<ValueInfo> &refs() const { return RefEdgeList; }
|
2016-03-14 22:18:10 +01:00
|
|
|
};
|
|
|
|
|
2016-04-16 08:56:44 +02:00
|
|
|
/// \brief Alias summary information.
|
|
|
|
class AliasSummary : public GlobalValueSummary {
|
|
|
|
GlobalValueSummary *AliaseeSummary;
|
|
|
|
|
|
|
|
public:
|
|
|
|
/// Summary constructors.
|
2016-04-24 05:18:18 +02:00
|
|
|
AliasSummary(GVFlags Flags) : GlobalValueSummary(AliasKind, Flags) {}
|
2016-04-16 08:56:44 +02:00
|
|
|
|
|
|
|
/// Check if this is an alias summary.
|
|
|
|
static bool classof(const GlobalValueSummary *GVS) {
|
|
|
|
return GVS->getSummaryKind() == AliasKind;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setAliasee(GlobalValueSummary *Aliasee) { AliaseeSummary = Aliasee; }
|
|
|
|
|
|
|
|
const GlobalValueSummary &getAliasee() const {
|
|
|
|
return const_cast<AliasSummary *>(this)->getAliasee();
|
|
|
|
}
|
|
|
|
|
|
|
|
GlobalValueSummary &getAliasee() {
|
|
|
|
assert(AliaseeSummary && "Unexpected missing aliasee summary");
|
|
|
|
return *AliaseeSummary;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-03-14 22:18:10 +01:00
|
|
|
/// \brief Function summary information to aid decisions and implementation of
|
|
|
|
/// importing.
|
|
|
|
class FunctionSummary : public GlobalValueSummary {
|
|
|
|
public:
|
2016-04-11 15:58:45 +02:00
|
|
|
/// <CalleeValueInfo, CalleeInfo> call edge pair.
|
|
|
|
typedef std::pair<ValueInfo, CalleeInfo> EdgeTy;
|
2016-03-14 22:18:10 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
/// Number of instructions (ignoring debug instructions, e.g.) computed
|
2016-03-15 01:04:37 +01:00
|
|
|
/// during the initial compile step when the summary index is first built.
|
2016-03-14 22:18:10 +01:00
|
|
|
unsigned InstCount;
|
|
|
|
|
2016-04-11 15:58:45 +02:00
|
|
|
/// List of <CalleeValueInfo, CalleeInfo> call edge pairs from this function.
|
2016-03-14 22:18:10 +01:00
|
|
|
std::vector<EdgeTy> CallGraphEdgeList;
|
|
|
|
|
|
|
|
public:
|
|
|
|
/// Summary constructors.
|
2016-04-24 05:18:18 +02:00
|
|
|
FunctionSummary(GVFlags Flags, unsigned NumInsts)
|
|
|
|
: GlobalValueSummary(FunctionKind, Flags), InstCount(NumInsts) {}
|
2016-03-14 22:18:10 +01:00
|
|
|
|
|
|
|
/// Check if this is a function summary.
|
|
|
|
static bool classof(const GlobalValueSummary *GVS) {
|
|
|
|
return GVS->getSummaryKind() == FunctionKind;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Get the instruction count recorded for this function.
|
|
|
|
unsigned instCount() const { return InstCount; }
|
|
|
|
|
|
|
|
/// Record a call graph edge from this function to the function identified
|
|
|
|
/// by \p CalleeGUID, with \p CalleeInfo including the cumulative profile
|
|
|
|
/// count (across all calls from this function) or 0 if no PGO.
|
2016-04-02 07:07:53 +02:00
|
|
|
void addCallGraphEdge(GlobalValue::GUID CalleeGUID, CalleeInfo Info) {
|
2016-03-14 22:18:10 +01:00
|
|
|
CallGraphEdgeList.push_back(std::make_pair(CalleeGUID, Info));
|
|
|
|
}
|
|
|
|
|
2016-04-11 15:58:45 +02:00
|
|
|
/// Record a call graph edge from this function to the function identified
|
|
|
|
/// by \p CalleeV, with \p CalleeInfo including the cumulative profile
|
|
|
|
/// count (across all calls from this function) or 0 if no PGO.
|
|
|
|
void addCallGraphEdge(const Value *CalleeV, CalleeInfo Info) {
|
|
|
|
CallGraphEdgeList.push_back(std::make_pair(CalleeV, Info));
|
|
|
|
}
|
|
|
|
|
2016-03-14 22:18:10 +01:00
|
|
|
/// Record a call graph edge from this function to each function recorded
|
|
|
|
/// in \p CallGraphEdges.
|
2016-04-11 15:58:45 +02:00
|
|
|
void addCallGraphEdges(DenseMap<const Value *, CalleeInfo> &CallGraphEdges) {
|
2016-03-14 22:18:10 +01:00
|
|
|
for (auto &EI : CallGraphEdges)
|
|
|
|
addCallGraphEdge(EI.first, EI.second);
|
|
|
|
}
|
|
|
|
|
2016-04-11 15:58:45 +02:00
|
|
|
/// Return the list of <CalleeValueInfo, CalleeInfo> pairs.
|
2016-03-25 19:59:13 +01:00
|
|
|
std::vector<EdgeTy> &calls() { return CallGraphEdgeList; }
|
|
|
|
const std::vector<EdgeTy> &calls() const { return CallGraphEdgeList; }
|
2016-03-14 22:18:10 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/// \brief Global variable summary information to aid decisions and
|
|
|
|
/// implementation of importing.
|
|
|
|
///
|
|
|
|
/// Currently this doesn't add anything to the base \p GlobalValueSummary,
|
|
|
|
/// but is a placeholder as additional info may be added to the summary
|
|
|
|
/// for variables.
|
|
|
|
class GlobalVarSummary : public GlobalValueSummary {
|
|
|
|
|
|
|
|
public:
|
|
|
|
/// Summary constructors.
|
2016-04-24 05:18:18 +02:00
|
|
|
GlobalVarSummary(GVFlags Flags) : GlobalValueSummary(GlobalVarKind, Flags) {}
|
2016-03-14 22:18:10 +01:00
|
|
|
|
|
|
|
/// Check if this is a global variable summary.
|
|
|
|
static bool classof(const GlobalValueSummary *GVS) {
|
|
|
|
return GVS->getSummaryKind() == GlobalVarKind;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-04-01 07:33:11 +02:00
|
|
|
/// 160 bits SHA1
|
|
|
|
typedef std::array<uint32_t, 5> ModuleHash;
|
|
|
|
|
2016-04-24 16:57:11 +02:00
|
|
|
/// List of global value summary structures for a particular value held
|
2016-03-14 22:18:10 +01:00
|
|
|
/// in the GlobalValueMap. Requires a vector in the case of multiple
|
|
|
|
/// COMDAT values of the same name.
|
2016-04-24 16:57:11 +02:00
|
|
|
typedef std::vector<std::unique_ptr<GlobalValueSummary>> GlobalValueSummaryList;
|
2016-03-14 22:18:10 +01:00
|
|
|
|
2016-04-24 16:57:11 +02:00
|
|
|
/// Map from global value GUID to corresponding summary structures.
|
2016-03-14 22:18:10 +01:00
|
|
|
/// Use a std::map rather than a DenseMap since it will likely incur
|
|
|
|
/// less overhead, as the value type is not very small and the size
|
|
|
|
/// of the map is unknown, resulting in inefficiencies due to repeated
|
|
|
|
/// insertions and resizing.
|
2016-04-24 16:57:11 +02:00
|
|
|
typedef std::map<GlobalValue::GUID, GlobalValueSummaryList>
|
|
|
|
GlobalValueSummaryMapTy;
|
2016-03-14 22:18:10 +01:00
|
|
|
|
2016-04-24 16:57:11 +02:00
|
|
|
/// Type used for iterating through the global value summary map.
|
|
|
|
typedef GlobalValueSummaryMapTy::const_iterator const_gvsummary_iterator;
|
|
|
|
typedef GlobalValueSummaryMapTy::iterator gvsummary_iterator;
|
2016-03-14 22:18:10 +01:00
|
|
|
|
|
|
|
/// String table to hold/own module path strings, which additionally holds the
|
2016-04-01 07:33:11 +02:00
|
|
|
/// module ID assigned to each module during the plugin step, as well as a hash
|
|
|
|
/// of the module. The StringMap makes a copy of and owns inserted strings.
|
|
|
|
typedef StringMap<std::pair<uint64_t, ModuleHash>> ModulePathStringTableTy;
|
2016-03-14 22:18:10 +01:00
|
|
|
|
2016-04-25 23:09:51 +02:00
|
|
|
/// Map of global value GUID to its summary, used to identify values defined in
|
|
|
|
/// a particular module, and provide efficient access to their summary.
|
|
|
|
typedef std::map<GlobalValue::GUID, GlobalValueSummary *> GVSummaryMapTy;
|
|
|
|
|
2016-03-14 22:18:10 +01:00
|
|
|
/// Class to hold module path string table and global value map,
|
|
|
|
/// and encapsulate methods for operating on them.
|
2016-03-15 01:04:37 +01:00
|
|
|
class ModuleSummaryIndex {
|
2016-03-14 22:18:10 +01:00
|
|
|
private:
|
2016-04-24 16:57:11 +02:00
|
|
|
/// Map from value name to list of summary instances for values of that
|
2016-03-14 22:18:10 +01:00
|
|
|
/// name (may be duplicates in the COMDAT case, e.g.).
|
2016-04-24 16:57:11 +02:00
|
|
|
GlobalValueSummaryMapTy GlobalValueMap;
|
2016-03-14 22:18:10 +01:00
|
|
|
|
|
|
|
/// Holds strings for combined index, mapping to the corresponding module ID.
|
|
|
|
ModulePathStringTableTy ModulePathStringTable;
|
|
|
|
|
|
|
|
public:
|
2016-03-15 01:04:37 +01:00
|
|
|
ModuleSummaryIndex() = default;
|
2016-03-14 22:18:10 +01:00
|
|
|
|
|
|
|
// Disable the copy constructor and assignment operators, so
|
|
|
|
// no unexpected copying/moving occurs.
|
2016-03-15 01:04:37 +01:00
|
|
|
ModuleSummaryIndex(const ModuleSummaryIndex &) = delete;
|
|
|
|
void operator=(const ModuleSummaryIndex &) = delete;
|
2016-03-14 22:18:10 +01:00
|
|
|
|
2016-04-24 16:57:11 +02:00
|
|
|
gvsummary_iterator begin() { return GlobalValueMap.begin(); }
|
|
|
|
const_gvsummary_iterator begin() const { return GlobalValueMap.begin(); }
|
|
|
|
gvsummary_iterator end() { return GlobalValueMap.end(); }
|
|
|
|
const_gvsummary_iterator end() const { return GlobalValueMap.end(); }
|
2016-03-14 22:18:10 +01:00
|
|
|
|
2016-04-24 16:57:11 +02:00
|
|
|
/// Get the list of global value summary objects for a given value name.
|
|
|
|
const GlobalValueSummaryList &getGlobalValueSummaryList(StringRef ValueName) {
|
2016-03-15 03:13:19 +01:00
|
|
|
return GlobalValueMap[GlobalValue::getGUID(ValueName)];
|
2016-03-14 22:18:10 +01:00
|
|
|
}
|
|
|
|
|
2016-04-24 16:57:11 +02:00
|
|
|
/// Get the list of global value summary objects for a given value name.
|
|
|
|
const const_gvsummary_iterator
|
|
|
|
findGlobalValueSummaryList(StringRef ValueName) const {
|
2016-03-15 03:13:19 +01:00
|
|
|
return GlobalValueMap.find(GlobalValue::getGUID(ValueName));
|
2016-03-14 22:18:10 +01:00
|
|
|
}
|
|
|
|
|
2016-04-24 16:57:11 +02:00
|
|
|
/// Get the list of global value summary objects for a given value GUID.
|
|
|
|
const const_gvsummary_iterator
|
|
|
|
findGlobalValueSummaryList(GlobalValue::GUID ValueGUID) const {
|
2016-03-14 22:18:10 +01:00
|
|
|
return GlobalValueMap.find(ValueGUID);
|
|
|
|
}
|
|
|
|
|
2016-04-24 16:57:11 +02:00
|
|
|
/// Add a global value summary for a value of the given name.
|
|
|
|
void addGlobalValueSummary(StringRef ValueName,
|
|
|
|
std::unique_ptr<GlobalValueSummary> Summary) {
|
|
|
|
GlobalValueMap[GlobalValue::getGUID(ValueName)].push_back(
|
|
|
|
std::move(Summary));
|
2016-03-14 22:18:10 +01:00
|
|
|
}
|
|
|
|
|
2016-04-24 16:57:11 +02:00
|
|
|
/// Add a global value summary for a value of the given GUID.
|
|
|
|
void addGlobalValueSummary(GlobalValue::GUID ValueGUID,
|
|
|
|
std::unique_ptr<GlobalValueSummary> Summary) {
|
|
|
|
GlobalValueMap[ValueGUID].push_back(std::move(Summary));
|
2016-03-14 22:18:10 +01:00
|
|
|
}
|
|
|
|
|
2016-04-24 16:57:11 +02:00
|
|
|
/// Returns the first GlobalValueSummary for \p GV, asserting that there
|
2016-04-05 02:40:16 +02:00
|
|
|
/// is only one if \p PerModuleIndex.
|
2016-04-24 16:57:11 +02:00
|
|
|
GlobalValueSummary *getGlobalValueSummary(const GlobalValue &GV,
|
|
|
|
bool PerModuleIndex = true) const {
|
|
|
|
assert(GV.hasName() && "Can't get GlobalValueSummary for GV with no name");
|
|
|
|
return getGlobalValueSummary(GlobalValue::getGUID(GV.getName()),
|
|
|
|
PerModuleIndex);
|
2016-04-05 02:40:16 +02:00
|
|
|
}
|
|
|
|
|
2016-04-24 16:57:11 +02:00
|
|
|
/// Returns the first GlobalValueSummary for \p ValueGUID, asserting that
|
|
|
|
/// there
|
2016-04-05 02:40:16 +02:00
|
|
|
/// is only one if \p PerModuleIndex.
|
2016-04-24 16:57:11 +02:00
|
|
|
GlobalValueSummary *getGlobalValueSummary(GlobalValue::GUID ValueGUID,
|
|
|
|
bool PerModuleIndex = true) const;
|
2016-04-05 02:40:16 +02:00
|
|
|
|
2016-04-01 07:33:11 +02:00
|
|
|
/// Table of modules, containing module hash and id.
|
|
|
|
const StringMap<std::pair<uint64_t, ModuleHash>> &modulePaths() const {
|
2016-03-26 04:35:38 +01:00
|
|
|
return ModulePathStringTable;
|
2016-03-14 22:18:10 +01:00
|
|
|
}
|
|
|
|
|
2016-04-01 07:33:11 +02:00
|
|
|
/// Table of modules, containing hash and id.
|
|
|
|
StringMap<std::pair<uint64_t, ModuleHash>> &modulePaths() {
|
|
|
|
return ModulePathStringTable;
|
|
|
|
}
|
2016-03-26 04:35:38 +01:00
|
|
|
|
2016-03-14 22:18:10 +01:00
|
|
|
/// Get the module ID recorded for the given module path.
|
|
|
|
uint64_t getModuleId(const StringRef ModPath) const {
|
2016-04-01 07:33:11 +02:00
|
|
|
return ModulePathStringTable.lookup(ModPath).first;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Get the module SHA1 hash recorded for the given module path.
|
|
|
|
const ModuleHash &getModuleHash(const StringRef ModPath) const {
|
|
|
|
auto It = ModulePathStringTable.find(ModPath);
|
|
|
|
assert(It != ModulePathStringTable.end() && "Module not registered");
|
|
|
|
return It->second.second;
|
2016-03-14 22:18:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Add the given per-module index into this module index/summary,
|
|
|
|
/// assigning it the given module ID. Each module merged in should have
|
|
|
|
/// a unique ID, necessary for consistent renaming of promoted
|
|
|
|
/// static (local) variables.
|
2016-03-15 01:04:37 +01:00
|
|
|
void mergeFrom(std::unique_ptr<ModuleSummaryIndex> Other,
|
2016-03-14 22:18:10 +01:00
|
|
|
uint64_t NextModuleId);
|
|
|
|
|
|
|
|
/// Convenience method for creating a promoted global name
|
|
|
|
/// for the given value name of a local, and its original module's ID.
|
2016-04-12 01:26:46 +02:00
|
|
|
static std::string getGlobalNameForLocal(StringRef Name, ModuleHash ModHash) {
|
2016-03-14 22:18:10 +01:00
|
|
|
SmallString<256> NewName(Name);
|
|
|
|
NewName += ".llvm.";
|
2016-04-12 01:26:46 +02:00
|
|
|
NewName += utohexstr(ModHash[0]); // Take the first 32 bits
|
2016-03-14 22:18:10 +01:00
|
|
|
return NewName.str();
|
|
|
|
}
|
|
|
|
|
2016-04-01 07:33:11 +02:00
|
|
|
/// Add a new module path with the given \p Hash, mapped to the given \p
|
|
|
|
/// ModID, and return an iterator to the entry in the index.
|
|
|
|
ModulePathStringTableTy::iterator
|
|
|
|
addModulePath(StringRef ModPath, uint64_t ModId,
|
|
|
|
ModuleHash Hash = ModuleHash{{0}}) {
|
|
|
|
return ModulePathStringTable.insert(std::make_pair(
|
|
|
|
ModPath,
|
|
|
|
std::make_pair(ModId, Hash))).first;
|
2016-03-14 22:18:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Check if the given Module has any functions available for exporting
|
|
|
|
/// in the index. We consider any module present in the ModulePathStringTable
|
|
|
|
/// to have exported functions.
|
|
|
|
bool hasExportedFunctions(const Module &M) const {
|
|
|
|
return ModulePathStringTable.count(M.getModuleIdentifier());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Remove entries in the GlobalValueMap that have empty summaries due to the
|
|
|
|
/// eager nature of map entry creation during VST parsing. These would
|
|
|
|
/// also be suppressed during combined index generation in mergeFrom(),
|
|
|
|
/// but if there was only one module or this was the first module we might
|
|
|
|
/// not invoke mergeFrom.
|
|
|
|
void removeEmptySummaryEntries();
|
2016-04-12 23:13:11 +02:00
|
|
|
|
|
|
|
/// Collect for the given module the list of function it defines
|
|
|
|
/// (GUID -> Summary).
|
2016-04-25 23:09:51 +02:00
|
|
|
void collectDefinedFunctionsForModule(StringRef ModulePath,
|
|
|
|
GVSummaryMapTy &GVSummaryMap) const;
|
2016-04-16 09:02:16 +02:00
|
|
|
|
|
|
|
/// Collect for each module the list of Summaries it defines (GUID ->
|
|
|
|
/// Summary).
|
|
|
|
void collectDefinedGVSummariesPerModule(
|
2016-04-25 23:09:51 +02:00
|
|
|
StringMap<GVSummaryMapTy> &ModuleToDefinedGVSummaries) const;
|
2016-03-14 22:18:10 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
} // End llvm namespace
|
|
|
|
|
|
|
|
#endif
|