blob: 01e1b8168afa6dd8d82c97d20e3c6b94ccf1b221 [file] [log] [blame]
Teresa Johnson26ab5772016-03-15 00:04:37 +00001//===-- ModuleSummaryIndex.cpp - Module Summary Index ---------------------===//
Teresa Johnsoncec0cae2016-03-14 21:18:10 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the module index and summary classes for the
11// IR library.
12//
13//===----------------------------------------------------------------------===//
14
Teresa Johnson26ab5772016-03-15 00:04:37 +000015#include "llvm/IR/ModuleSummaryIndex.h"
Teresa Johnsoncec0cae2016-03-14 21:18:10 +000016#include "llvm/ADT/StringMap.h"
17using namespace llvm;
18
Teresa Johnsonc86af332016-04-12 21:13:11 +000019// Collect for the given module the list of function it defines
20// (GUID -> Summary).
21void ModuleSummaryIndex::collectDefinedFunctionsForModule(
Teresa Johnsonc851d212016-04-25 21:09:51 +000022 StringRef ModulePath, GVSummaryMapTy &GVSummaryMap) const {
Teresa Johnsonc86af332016-04-12 21:13:11 +000023 for (auto &GlobalList : *this) {
24 auto GUID = GlobalList.first;
Eric Liuf6039f22017-05-04 11:49:39 +000025 for (auto &GlobSummary : GlobalList.second) {
Teresa Johnson28e457b2016-04-24 14:57:11 +000026 auto *Summary = dyn_cast_or_null<FunctionSummary>(GlobSummary.get());
Teresa Johnsonc86af332016-04-12 21:13:11 +000027 if (!Summary)
28 // Ignore global variable, focus on functions
29 continue;
30 // Ignore summaries from other modules.
31 if (Summary->modulePath() != ModulePath)
32 continue;
Teresa Johnson28e457b2016-04-24 14:57:11 +000033 GVSummaryMap[GUID] = Summary;
Teresa Johnsonc86af332016-04-12 21:13:11 +000034 }
35 }
36}
37
Mehdi Amini1aafabf2016-04-16 07:02:16 +000038// Collect for each module the list of function it defines (GUID -> Summary).
39void ModuleSummaryIndex::collectDefinedGVSummariesPerModule(
Teresa Johnsonc851d212016-04-25 21:09:51 +000040 StringMap<GVSummaryMapTy> &ModuleToDefinedGVSummaries) const {
Mehdi Amini1aafabf2016-04-16 07:02:16 +000041 for (auto &GlobalList : *this) {
42 auto GUID = GlobalList.first;
Eric Liuf6039f22017-05-04 11:49:39 +000043 for (auto &Summary : GlobalList.second) {
Teresa Johnson28e457b2016-04-24 14:57:11 +000044 ModuleToDefinedGVSummaries[Summary->modulePath()][GUID] = Summary.get();
Mehdi Amini1aafabf2016-04-16 07:02:16 +000045 }
46 }
47}
48
Teresa Johnson28e457b2016-04-24 14:57:11 +000049GlobalValueSummary *
50ModuleSummaryIndex::getGlobalValueSummary(uint64_t ValueGUID,
51 bool PerModuleIndex) const {
Eric Liuf6039f22017-05-04 11:49:39 +000052 auto SummaryList = findGlobalValueSummaryList(ValueGUID);
53 assert(SummaryList != end() && "GlobalValue not found in index");
54 assert((!PerModuleIndex || SummaryList->second.size() == 1) &&
Haojian Wu591ae462016-04-05 09:07:47 +000055 "Expected a single entry per global value in per-module index");
Eric Liuf6039f22017-05-04 11:49:39 +000056 auto &Summary = SummaryList->second[0];
Teresa Johnson28e457b2016-04-24 14:57:11 +000057 return Summary.get();
Teresa Johnsonfb7c7642016-04-05 00:40:16 +000058}