1 //===-- ModuleSummaryIndex.cpp - Module Summary Index ---------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the module index and summary classes for the
13 //===----------------------------------------------------------------------===//
15 #include "llvm/IR/ModuleSummaryIndex.h"
16 #include "llvm/ADT/StringMap.h"
19 // Collect for the given module the list of function it defines
21 void ModuleSummaryIndex::collectDefinedFunctionsForModule(
22 StringRef ModulePath, GVSummaryMapTy &GVSummaryMap) const {
23 for (auto &GlobalList : *this) {
24 auto GUID = GlobalList.first;
25 for (auto &GlobSummary : GlobalList.second.SummaryList) {
26 auto *Summary = dyn_cast_or_null<FunctionSummary>(GlobSummary.get());
28 // Ignore global variable, focus on functions
30 // Ignore summaries from other modules.
31 if (Summary->modulePath() != ModulePath)
33 GVSummaryMap[GUID] = Summary;
38 // Collect for each module the list of function it defines (GUID -> Summary).
39 void ModuleSummaryIndex::collectDefinedGVSummariesPerModule(
40 StringMap<GVSummaryMapTy> &ModuleToDefinedGVSummaries) const {
41 for (auto &GlobalList : *this) {
42 auto GUID = GlobalList.first;
43 for (auto &Summary : GlobalList.second.SummaryList) {
44 ModuleToDefinedGVSummaries[Summary->modulePath()][GUID] = Summary.get();
50 ModuleSummaryIndex::getGlobalValueSummary(uint64_t ValueGUID,
51 bool PerModuleIndex) const {
52 auto VI = getValueInfo(ValueGUID);
53 assert(VI && "GlobalValue not found in index");
54 assert((!PerModuleIndex || VI.getSummaryList().size() == 1) &&
55 "Expected a single entry per global value in per-module index");
56 auto &Summary = VI.getSummaryList()[0];