ModuleSummaryIndex.cpp 2.6 KB

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