LCOV - code coverage report
Current view: top level - lib/IR - ModuleSummaryIndex.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 28 28 100.0 %
Date: 2017-09-14 15:23:50 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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          21 : void ModuleSummaryIndex::collectDefinedFunctionsForModule(
      22             :     StringRef ModulePath, GVSummaryMapTy &GVSummaryMap) const {
      23         221 :   for (auto &GlobalList : *this) {
      24         158 :     auto GUID = GlobalList.first;
      25         790 :     for (auto &GlobSummary : GlobalList.second.SummaryList) {
      26         310 :       auto *Summary = dyn_cast_or_null<FunctionSummary>(GlobSummary.get());
      27           6 :       if (!Summary)
      28             :         // Ignore global variable, focus on functions
      29           6 :         continue;
      30             :       // Ignore summaries from other modules.
      31         281 :       if (Summary->modulePath() != ModulePath)
      32         129 :         continue;
      33          23 :       GVSummaryMap[GUID] = Summary;
      34             :     }
      35             :   }
      36          21 : }
      37             : 
      38             : // Collect for each module the list of function it defines (GUID -> Summary).
      39         179 : void ModuleSummaryIndex::collectDefinedGVSummariesPerModule(
      40             :     StringMap<GVSummaryMapTy> &ModuleToDefinedGVSummaries) const {
      41        1323 :   for (auto &GlobalList : *this) {
      42         786 :     auto GUID = GlobalList.first;
      43        3983 :     for (auto &Summary : GlobalList.second.SummaryList) {
      44        3356 :       ModuleToDefinedGVSummaries[Summary->modulePath()][GUID] = Summary.get();
      45             :     }
      46             :   }
      47         179 : }
      48             : 
      49             : GlobalValueSummary *
      50         228 : ModuleSummaryIndex::getGlobalValueSummary(uint64_t ValueGUID,
      51             :                                           bool PerModuleIndex) const {
      52         228 :   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         228 :   auto &Summary = VI.getSummaryList()[0];
      57         228 :   return Summary.get();
      58             : }
      59             : 
      60         249 : bool ModuleSummaryIndex::isGUIDLive(GlobalValue::GUID GUID) const {
      61         249 :   auto VI = getValueInfo(GUID);
      62         249 :   if (!VI)
      63             :     return true;
      64         237 :   const auto &SummaryList = VI.getSummaryList();
      65         237 :   if (SummaryList.empty())
      66             :     return true;
      67         475 :   for (auto &I : SummaryList)
      68         249 :     if (isGlobalValueLive(I.get()))
      69             :       return true;
      70             :   return false;
      71             : }

Generated by: LCOV version 1.13