LLVM  5.0.0
ModuleSummaryIndex.cpp
Go to the documentation of this file.
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 
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).
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).
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 
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 }
59 
61  auto VI = getValueInfo(GUID);
62  if (!VI)
63  return true;
64  const auto &SummaryList = VI.getSummaryList();
65  if (SummaryList.empty())
66  return true;
67  for (auto &I : SummaryList)
68  if (isGlobalValueLive(I.get()))
69  return true;
70  return false;
71 }
uint64_t GUID
Declare a type to represent a global unique identifier for a global value.
Definition: GlobalValue.h:472
ValueInfo getValueInfo(GlobalValue::GUID GUID) const
Return a ValueInfo for GUID if it exists, otherwise return ValueInfo().
bool isGlobalValueLive(const GlobalValueSummary *GVS) const
void collectDefinedFunctionsForModule(StringRef ModulePath, GVSummaryMapTy &GVSummaryMap) const
Collect for the given module the list of function it defines (GUID -> Summary).
Function and variable summary information to aid decisions and implementation of importing.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
Definition: StringMap.h:220
void collectDefinedGVSummariesPerModule(StringMap< GVSummaryMapTy > &ModuleToDefinedGVSummaries) const
Collect for each module the list of Summaries it defines (GUID -> Summary).
#define I(x, y, z)
Definition: MD5.cpp:58
bool isGUIDLive(GlobalValue::GUID GUID) const
ModuleSummaryIndex.h This file contains the declarations the classes that hold the module index and s...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
GlobalValueSummary * getGlobalValueSummary(const GlobalValue &GV, bool PerModuleIndex=true) const
Returns the first GlobalValueSummary for GV, asserting that there is only one if PerModuleIndex.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49