]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/IR/ModuleSummaryIndex.cpp
Merge ^/head r318658 through r318963.
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / IR / ModuleSummaryIndex.cpp
1 //===-- ModuleSummaryIndex.cpp - Module Summary Index ---------------------===//
2 //
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
15 #include "llvm/IR/ModuleSummaryIndex.h"
16 #include "llvm/ADT/StringMap.h"
17 using namespace llvm;
18
19 // Collect for the given module the list of function it defines
20 // (GUID -> Summary).
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());
27       if (!Summary)
28         // Ignore global variable, focus on functions
29         continue;
30       // Ignore summaries from other modules.
31       if (Summary->modulePath() != ModulePath)
32         continue;
33       GVSummaryMap[GUID] = Summary;
34     }
35   }
36 }
37
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();
45     }
46   }
47 }
48
49 GlobalValueSummary *
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];
57   return Summary.get();
58 }