2016-03-15 08:04:37 +08:00
|
|
|
//===-- ModuleSummaryIndex.cpp - Module Summary Index ---------------------===//
|
2016-03-15 05:18:10 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the module index and summary classes for the
|
|
|
|
// IR library.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2016-03-15 08:04:37 +08:00
|
|
|
#include "llvm/IR/ModuleSummaryIndex.h"
|
2016-03-15 05:18:10 +08:00
|
|
|
#include "llvm/ADT/StringMap.h"
|
|
|
|
using namespace llvm;
|
|
|
|
|
2016-04-13 05:13:11 +08:00
|
|
|
// Collect for the given module the list of function it defines
|
|
|
|
// (GUID -> Summary).
|
|
|
|
void ModuleSummaryIndex::collectDefinedFunctionsForModule(
|
2016-04-26 05:09:51 +08:00
|
|
|
StringRef ModulePath, GVSummaryMapTy &GVSummaryMap) const {
|
2016-04-13 05:13:11 +08:00
|
|
|
for (auto &GlobalList : *this) {
|
|
|
|
auto GUID = GlobalList.first;
|
2017-05-04 19:49:39 +08:00
|
|
|
for (auto &GlobSummary : GlobalList.second) {
|
2016-04-24 22:57:11 +08:00
|
|
|
auto *Summary = dyn_cast_or_null<FunctionSummary>(GlobSummary.get());
|
2016-04-13 05:13:11 +08:00
|
|
|
if (!Summary)
|
|
|
|
// Ignore global variable, focus on functions
|
|
|
|
continue;
|
|
|
|
// Ignore summaries from other modules.
|
|
|
|
if (Summary->modulePath() != ModulePath)
|
|
|
|
continue;
|
2016-04-24 22:57:11 +08:00
|
|
|
GVSummaryMap[GUID] = Summary;
|
2016-04-13 05:13:11 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-16 15:02:16 +08:00
|
|
|
// Collect for each module the list of function it defines (GUID -> Summary).
|
|
|
|
void ModuleSummaryIndex::collectDefinedGVSummariesPerModule(
|
2016-04-26 05:09:51 +08:00
|
|
|
StringMap<GVSummaryMapTy> &ModuleToDefinedGVSummaries) const {
|
2016-04-16 15:02:16 +08:00
|
|
|
for (auto &GlobalList : *this) {
|
|
|
|
auto GUID = GlobalList.first;
|
2017-05-04 19:49:39 +08:00
|
|
|
for (auto &Summary : GlobalList.second) {
|
2016-04-24 22:57:11 +08:00
|
|
|
ModuleToDefinedGVSummaries[Summary->modulePath()][GUID] = Summary.get();
|
2016-04-16 15:02:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-24 22:57:11 +08:00
|
|
|
GlobalValueSummary *
|
|
|
|
ModuleSummaryIndex::getGlobalValueSummary(uint64_t ValueGUID,
|
|
|
|
bool PerModuleIndex) const {
|
2017-05-04 19:49:39 +08:00
|
|
|
auto SummaryList = findGlobalValueSummaryList(ValueGUID);
|
|
|
|
assert(SummaryList != end() && "GlobalValue not found in index");
|
|
|
|
assert((!PerModuleIndex || SummaryList->second.size() == 1) &&
|
2016-04-05 17:07:47 +08:00
|
|
|
"Expected a single entry per global value in per-module index");
|
2017-05-04 19:49:39 +08:00
|
|
|
auto &Summary = SummaryList->second[0];
|
2016-04-24 22:57:11 +08:00
|
|
|
return Summary.get();
|
2016-04-05 08:40:16 +08:00
|
|
|
}
|