Teresa Johnson | 26ab577 | 2016-03-15 00:04:37 +0000 | [diff] [blame] | 1 | //===-- ModuleSummaryIndex.cpp - Module Summary Index ---------------------===// |
Teresa Johnson | cec0cae | 2016-03-14 21:18:10 +0000 | [diff] [blame] | 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 | |
Teresa Johnson | 26ab577 | 2016-03-15 00:04:37 +0000 | [diff] [blame] | 15 | #include "llvm/IR/ModuleSummaryIndex.h" |
Teresa Johnson | cec0cae | 2016-03-14 21:18:10 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/StringMap.h" |
| 17 | using namespace llvm; |
| 18 | |
Teresa Johnson | c86af33 | 2016-04-12 21:13:11 +0000 | [diff] [blame] | 19 | // Collect for the given module the list of function it defines |
| 20 | // (GUID -> Summary). |
| 21 | void ModuleSummaryIndex::collectDefinedFunctionsForModule( |
Teresa Johnson | c851d21 | 2016-04-25 21:09:51 +0000 | [diff] [blame] | 22 | StringRef ModulePath, GVSummaryMapTy &GVSummaryMap) const { |
Teresa Johnson | c86af33 | 2016-04-12 21:13:11 +0000 | [diff] [blame] | 23 | for (auto &GlobalList : *this) { |
| 24 | auto GUID = GlobalList.first; |
Eric Liu | f6039f2 | 2017-05-04 11:49:39 +0000 | [diff] [blame^] | 25 | for (auto &GlobSummary : GlobalList.second) { |
Teresa Johnson | 28e457b | 2016-04-24 14:57:11 +0000 | [diff] [blame] | 26 | auto *Summary = dyn_cast_or_null<FunctionSummary>(GlobSummary.get()); |
Teresa Johnson | c86af33 | 2016-04-12 21:13:11 +0000 | [diff] [blame] | 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; |
Teresa Johnson | 28e457b | 2016-04-24 14:57:11 +0000 | [diff] [blame] | 33 | GVSummaryMap[GUID] = Summary; |
Teresa Johnson | c86af33 | 2016-04-12 21:13:11 +0000 | [diff] [blame] | 34 | } |
| 35 | } |
| 36 | } |
| 37 | |
Mehdi Amini | 1aafabf | 2016-04-16 07:02:16 +0000 | [diff] [blame] | 38 | // Collect for each module the list of function it defines (GUID -> Summary). |
| 39 | void ModuleSummaryIndex::collectDefinedGVSummariesPerModule( |
Teresa Johnson | c851d21 | 2016-04-25 21:09:51 +0000 | [diff] [blame] | 40 | StringMap<GVSummaryMapTy> &ModuleToDefinedGVSummaries) const { |
Mehdi Amini | 1aafabf | 2016-04-16 07:02:16 +0000 | [diff] [blame] | 41 | for (auto &GlobalList : *this) { |
| 42 | auto GUID = GlobalList.first; |
Eric Liu | f6039f2 | 2017-05-04 11:49:39 +0000 | [diff] [blame^] | 43 | for (auto &Summary : GlobalList.second) { |
Teresa Johnson | 28e457b | 2016-04-24 14:57:11 +0000 | [diff] [blame] | 44 | ModuleToDefinedGVSummaries[Summary->modulePath()][GUID] = Summary.get(); |
Mehdi Amini | 1aafabf | 2016-04-16 07:02:16 +0000 | [diff] [blame] | 45 | } |
| 46 | } |
| 47 | } |
| 48 | |
Teresa Johnson | 28e457b | 2016-04-24 14:57:11 +0000 | [diff] [blame] | 49 | GlobalValueSummary * |
| 50 | ModuleSummaryIndex::getGlobalValueSummary(uint64_t ValueGUID, |
| 51 | bool PerModuleIndex) const { |
Eric Liu | f6039f2 | 2017-05-04 11:49:39 +0000 | [diff] [blame^] | 52 | auto SummaryList = findGlobalValueSummaryList(ValueGUID); |
| 53 | assert(SummaryList != end() && "GlobalValue not found in index"); |
| 54 | assert((!PerModuleIndex || SummaryList->second.size() == 1) && |
Haojian Wu | 591ae46 | 2016-04-05 09:07:47 +0000 | [diff] [blame] | 55 | "Expected a single entry per global value in per-module index"); |
Eric Liu | f6039f2 | 2017-05-04 11:49:39 +0000 | [diff] [blame^] | 56 | auto &Summary = SummaryList->second[0]; |
Teresa Johnson | 28e457b | 2016-04-24 14:57:11 +0000 | [diff] [blame] | 57 | return Summary.get(); |
Teresa Johnson | fb7c764 | 2016-04-05 00:40:16 +0000 | [diff] [blame] | 58 | } |