FunctionInfo.cpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //===-- FunctionInfo.cpp - Function Info 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 function info index and summary classes for the
  11. // IR library.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. #include "llvm/IR/FunctionInfo.h"
  15. #include "llvm/ADT/StringMap.h"
  16. using namespace llvm;
  17. // Create the combined function index/summary from multiple
  18. // per-module instances.
  19. void FunctionInfoIndex::mergeFrom(std::unique_ptr<FunctionInfoIndex> Other,
  20. uint64_t NextModuleId) {
  21. StringRef ModPath;
  22. for (auto &OtherFuncInfoLists : *Other) {
  23. std::string FuncName = OtherFuncInfoLists.getKey();
  24. FunctionInfoList &List = OtherFuncInfoLists.second;
  25. // Assert that the func 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<FunctionInfo> Info = std::move(List.front());
  29. // Skip if there was no function summary section.
  30. if (!Info->functionSummary())
  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 =
  36. addModulePath(Info->functionSummary()->modulePath(), NextModuleId);
  37. else
  38. assert(ModPath == Info->functionSummary()->modulePath() &&
  39. "Each module in the combined map should have a unique ID");
  40. // Note the module path string ref was copied above and is still owned by
  41. // the original per-module index. Reset it to the new module path
  42. // string reference owned by the combined index.
  43. Info->functionSummary()->setModulePath(ModPath);
  44. // If it is a local function, rename it.
  45. if (Info->functionSummary()->isLocalFunction()) {
  46. // Any local functions are virtually renamed when being added to the
  47. // combined index map, to disambiguate from other functions with
  48. // the same name. The symbol table created for the combined index
  49. // file should contain the renamed symbols.
  50. FuncName =
  51. FunctionInfoIndex::getGlobalNameForLocal(FuncName, NextModuleId);
  52. }
  53. // Add new function info to existing list. There may be duplicates when
  54. // combining FunctionMap entries, due to COMDAT functions. Any local
  55. // functions were virtually renamed above.
  56. addFunctionInfo(FuncName, std::move(Info));
  57. }
  58. }