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 | |
| 19 | // Create the combined module index/summary from multiple |
| 20 | // per-module instances. |
Teresa Johnson | 26ab577 | 2016-03-15 00:04:37 +0000 | [diff] [blame] | 21 | void ModuleSummaryIndex::mergeFrom(std::unique_ptr<ModuleSummaryIndex> Other, |
| 22 | uint64_t NextModuleId) { |
Teresa Johnson | cec0cae | 2016-03-14 21:18:10 +0000 | [diff] [blame] | 23 | |
| 24 | StringRef ModPath; |
| 25 | for (auto &OtherGlobalValInfoLists : *Other) { |
| 26 | uint64_t ValueGUID = OtherGlobalValInfoLists.first; |
| 27 | GlobalValueInfoList &List = OtherGlobalValInfoLists.second; |
| 28 | |
| 29 | // Assert that the value info list only has one entry, since we shouldn't |
| 30 | // have duplicate names within a single per-module index. |
| 31 | assert(List.size() == 1); |
| 32 | std::unique_ptr<GlobalValueInfo> Info = std::move(List.front()); |
| 33 | |
| 34 | // Skip if there was no summary section. |
| 35 | if (!Info->summary()) |
| 36 | continue; |
| 37 | |
| 38 | // Add the module path string ref for this module if we haven't already |
| 39 | // saved a reference to it. |
Mehdi Amini | 85fb9e0 | 2016-04-01 03:03:21 +0000 | [diff] [blame] | 40 | if (ModPath.empty()) |
| 41 | ModPath = addModulePath(Info->summary()->modulePath(), NextModuleId); |
| 42 | else |
Teresa Johnson | cec0cae | 2016-03-14 21:18:10 +0000 | [diff] [blame] | 43 | assert(ModPath == Info->summary()->modulePath() && |
| 44 | "Each module in the combined map should have a unique ID"); |
| 45 | |
| 46 | // Note the module path string ref was copied above and is still owned by |
| 47 | // the original per-module index. Reset it to the new module path |
| 48 | // string reference owned by the combined index. |
| 49 | Info->summary()->setModulePath(ModPath); |
| 50 | |
| 51 | // Add new value info to existing list. There may be duplicates when |
| 52 | // combining GlobalValueMap entries, due to COMDAT values. Any local |
| 53 | // values were given unique global IDs. |
| 54 | addGlobalValueInfo(ValueGUID, std::move(Info)); |
| 55 | } |
| 56 | } |
| 57 | |
Teresa Johnson | 26ab577 | 2016-03-15 00:04:37 +0000 | [diff] [blame] | 58 | void ModuleSummaryIndex::removeEmptySummaryEntries() { |
Teresa Johnson | cec0cae | 2016-03-14 21:18:10 +0000 | [diff] [blame] | 59 | for (auto MI = begin(), MIE = end(); MI != MIE;) { |
| 60 | // Only expect this to be called on a per-module index, which has a single |
| 61 | // entry per value entry list. |
| 62 | assert(MI->second.size() == 1); |
| 63 | if (!MI->second[0]->summary()) |
| 64 | MI = GlobalValueMap.erase(MI); |
| 65 | else |
| 66 | ++MI; |
| 67 | } |
| 68 | } |