Changeset View
Changeset View
Standalone View
Standalone View
include/llvm/IR/ModuleSummaryIndex.h
Show All 19 Lines | |||||
#include "llvm/ADT/DenseSet.h" | #include "llvm/ADT/DenseSet.h" | ||||
#include "llvm/ADT/SmallString.h" | #include "llvm/ADT/SmallString.h" | ||||
#include "llvm/ADT/StringMap.h" | #include "llvm/ADT/StringMap.h" | ||||
#include "llvm/IR/Function.h" | #include "llvm/IR/Function.h" | ||||
#include "llvm/IR/Module.h" | #include "llvm/IR/Module.h" | ||||
#include "llvm/Support/MemoryBuffer.h" | #include "llvm/Support/MemoryBuffer.h" | ||||
#include "llvm/Support/raw_ostream.h" | #include "llvm/Support/raw_ostream.h" | ||||
#include <array> | |||||
namespace llvm { | namespace llvm { | ||||
/// \brief Class to accumulate and hold information about a callee. | /// \brief Class to accumulate and hold information about a callee. | ||||
struct CalleeInfo { | struct CalleeInfo { | ||||
/// The static number of callsites calling corresponding function. | /// The static number of callsites calling corresponding function. | ||||
unsigned CallsiteCount; | unsigned CallsiteCount; | ||||
/// The cumulative profile count of calls to corresponding function | /// The cumulative profile count of calls to corresponding function | ||||
/// (if using PGO, otherwise 0). | /// (if using PGO, otherwise 0). | ||||
▲ Show 20 Lines • Show All 187 Lines • ▼ Show 20 Lines | public: | ||||
/// Get the bitcode index recorded for this value symbol table entry. | /// Get the bitcode index recorded for this value symbol table entry. | ||||
uint64_t bitcodeIndex() const { return BitcodeIndex; } | uint64_t bitcodeIndex() const { return BitcodeIndex; } | ||||
/// Set the bitcode index recorded for this value symbol table entry. | /// Set the bitcode index recorded for this value symbol table entry. | ||||
void setBitcodeIndex(uint64_t Offset) { BitcodeIndex = Offset; } | void setBitcodeIndex(uint64_t Offset) { BitcodeIndex = Offset; } | ||||
}; | }; | ||||
/// 160 bits SHA1 | |||||
typedef std::array<uint32_t, 5> ModuleHash; | |||||
tejohnson: Why not use uint32_t? That seems to be what is used in SHA1.h. | |||||
/// List of global value info structures for a particular value held | /// List of global value info structures for a particular value held | ||||
/// in the GlobalValueMap. Requires a vector in the case of multiple | /// in the GlobalValueMap. Requires a vector in the case of multiple | ||||
/// COMDAT values of the same name. | /// COMDAT values of the same name. | ||||
typedef std::vector<std::unique_ptr<GlobalValueInfo>> GlobalValueInfoList; | typedef std::vector<std::unique_ptr<GlobalValueInfo>> GlobalValueInfoList; | ||||
/// Map from global value GUID to corresponding info structures. | /// Map from global value GUID to corresponding info structures. | ||||
/// Use a std::map rather than a DenseMap since it will likely incur | /// 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 | /// less overhead, as the value type is not very small and the size | ||||
/// of the map is unknown, resulting in inefficiencies due to repeated | /// of the map is unknown, resulting in inefficiencies due to repeated | ||||
/// insertions and resizing. | /// insertions and resizing. | ||||
typedef std::map<uint64_t, GlobalValueInfoList> GlobalValueInfoMapTy; | typedef std::map<uint64_t, GlobalValueInfoList> GlobalValueInfoMapTy; | ||||
/// Type used for iterating through the global value info map. | /// Type used for iterating through the global value info map. | ||||
typedef GlobalValueInfoMapTy::const_iterator const_globalvalueinfo_iterator; | typedef GlobalValueInfoMapTy::const_iterator const_globalvalueinfo_iterator; | ||||
typedef GlobalValueInfoMapTy::iterator globalvalueinfo_iterator; | typedef GlobalValueInfoMapTy::iterator globalvalueinfo_iterator; | ||||
/// String table to hold/own module path strings, which additionally holds the | /// String table to hold/own module path strings, which additionally holds the | ||||
/// module ID assigned to each module during the plugin step. The StringMap | /// module ID assigned to each module during the plugin step, as well as a hash | ||||
/// makes a copy of and owns inserted strings. | /// of the module. The StringMap makes a copy of and owns inserted strings. | ||||
typedef StringMap<uint64_t> ModulePathStringTableTy; | typedef StringMap<std::pair<uint64_t, ModuleHash>> ModulePathStringTableTy; | ||||
/// Class to hold module path string table and global value map, | /// Class to hold module path string table and global value map, | ||||
/// and encapsulate methods for operating on them. | /// and encapsulate methods for operating on them. | ||||
class ModuleSummaryIndex { | class ModuleSummaryIndex { | ||||
private: | private: | ||||
/// Map from value name to list of information instances for values of that | /// Map from value name to list of information instances for values of that | ||||
/// name (may be duplicates in the COMDAT case, e.g.). | /// name (may be duplicates in the COMDAT case, e.g.). | ||||
GlobalValueInfoMapTy GlobalValueMap; | GlobalValueInfoMapTy GlobalValueMap; | ||||
Show All 39 Lines | void addGlobalValueInfo(StringRef ValueName, | ||||
GlobalValueMap[GlobalValue::getGUID(ValueName)].push_back(std::move(Info)); | GlobalValueMap[GlobalValue::getGUID(ValueName)].push_back(std::move(Info)); | ||||
} | } | ||||
/// Add a global value info for a value of the given GUID. | /// Add a global value info for a value of the given GUID. | ||||
void addGlobalValueInfo(uint64_t ValueGUID, | void addGlobalValueInfo(uint64_t ValueGUID, | ||||
std::unique_ptr<GlobalValueInfo> Info) { | std::unique_ptr<GlobalValueInfo> Info) { | ||||
GlobalValueMap[ValueGUID].push_back(std::move(Info)); | GlobalValueMap[ValueGUID].push_back(std::move(Info)); | ||||
} | } | ||||
/// Table of modules, containing an id. | /// Table of modules, containing module hash and id. | ||||
No longer returning an iterator. Ditto for non-const method below. tejohnson: No longer returning an iterator. Ditto for non-const method below. | |||||
const StringMap<uint64_t> &modulePaths() const { | const StringMap<std::pair<uint64_t, ModuleHash>> &modulePaths() const { | ||||
return ModulePathStringTable; | return ModulePathStringTable; | ||||
s/Table of module/Table of modules/ (here and below) tejohnson: s/Table of module/Table of modules/ (here and below) | |||||
} | } | ||||
/// Table of modules, containing an id. | /// Table of modules, containing hash and id. | ||||
StringMap<uint64_t> &modulePaths() { return ModulePathStringTable; } | StringMap<std::pair<uint64_t, ModuleHash>> &modulePaths() { | ||||
return ModulePathStringTable; | |||||
} | |||||
/// Get the module ID recorded for the given module path. | /// Get the module ID recorded for the given module path. | ||||
uint64_t getModuleId(const StringRef ModPath) const { | uint64_t getModuleId(const StringRef ModPath) const { | ||||
return ModulePathStringTable.lookup(ModPath); | 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; | |||||
} | } | ||||
/// Add the given per-module index into this module index/summary, | /// Add the given per-module index into this module index/summary, | ||||
/// assigning it the given module ID. Each module merged in should have | /// assigning it the given module ID. Each module merged in should have | ||||
/// a unique ID, necessary for consistent renaming of promoted | /// a unique ID, necessary for consistent renaming of promoted | ||||
/// static (local) variables. | /// static (local) variables. | ||||
void mergeFrom(std::unique_ptr<ModuleSummaryIndex> Other, | void mergeFrom(std::unique_ptr<ModuleSummaryIndex> Other, | ||||
uint64_t NextModuleId); | uint64_t NextModuleId); | ||||
/// Convenience method for creating a promoted global name | /// Convenience method for creating a promoted global name | ||||
/// for the given value name of a local, and its original module's ID. | /// for the given value name of a local, and its original module's ID. | ||||
static std::string getGlobalNameForLocal(StringRef Name, uint64_t ModId) { | static std::string getGlobalNameForLocal(StringRef Name, uint64_t ModId) { | ||||
SmallString<256> NewName(Name); | SmallString<256> NewName(Name); | ||||
NewName += ".llvm."; | NewName += ".llvm."; | ||||
raw_svector_ostream(NewName) << ModId; | raw_svector_ostream(NewName) << ModId; | ||||
return NewName.str(); | return NewName.str(); | ||||
} | } | ||||
/// Add a new module path, mapped to the given module Id, and return StringRef | /// Add a new module path with the given \p Hash, mapped to the given \p | ||||
/// owned by string table map. | /// ModID, and return an iterator to the entry in the index. | ||||
Now returns iterator not StringRef. tejohnson: Now returns iterator not StringRef. | |||||
StringRef addModulePath(StringRef ModPath, uint64_t ModId) { | ModulePathStringTableTy::iterator | ||||
return ModulePathStringTable.insert(std::make_pair(ModPath, ModId)) | addModulePath(StringRef ModPath, uint64_t ModId, | ||||
.first->first(); | ModuleHash Hash = ModuleHash{{0}}) { | ||||
return ModulePathStringTable.insert(std::make_pair( | |||||
ModPath, | |||||
Comment needs update: "with the given Hash". Also, is it possible to combine this with the above using a default argument value of {{0}}? tejohnson: Comment needs update: "with the given Hash". Also, is it possible to combine this with the… | |||||
std::make_pair(ModId, Hash))).first; | |||||
} | } | ||||
/// Check if the given Module has any functions available for exporting | /// Check if the given Module has any functions available for exporting | ||||
/// in the index. We consider any module present in the ModulePathStringTable | /// in the index. We consider any module present in the ModulePathStringTable | ||||
/// to have exported functions. | /// to have exported functions. | ||||
bool hasExportedFunctions(const Module &M) const { | bool hasExportedFunctions(const Module &M) const { | ||||
return ModulePathStringTable.count(M.getModuleIdentifier()); | return ModulePathStringTable.count(M.getModuleIdentifier()); | ||||
} | } | ||||
Show All 12 Lines |
Why not use uint32_t? That seems to be what is used in SHA1.h.