ModuleSummaryIndex.cpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. ModPath = addModulePath(Info->summary()->modulePath(), NextModuleId);
  36. else
  37. assert(ModPath == Info->summary()->modulePath() &&
  38. "Each module in the combined map should have a unique ID");
  39. // Note the module path string ref was copied above and is still owned by
  40. // the original per-module index. Reset it to the new module path
  41. // string reference owned by the combined index.
  42. Info->summary()->setModulePath(ModPath);
  43. // Add new value info to existing list. There may be duplicates when
  44. // combining GlobalValueMap entries, due to COMDAT values. Any local
  45. // values were given unique global IDs.
  46. addGlobalValueInfo(ValueGUID, std::move(Info));
  47. }
  48. }
  49. void ModuleSummaryIndex::removeEmptySummaryEntries() {
  50. for (auto MI = begin(), MIE = end(); MI != MIE;) {
  51. // Only expect this to be called on a per-module index, which has a single
  52. // entry per value entry list.
  53. assert(MI->second.size() == 1);
  54. if (!MI->second[0]->summary())
  55. MI = GlobalValueMap.erase(MI);
  56. else
  57. ++MI;
  58. }
  59. }