1 //===-- FunctionInfo.cpp - Function Info Index ----------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the function info index and summary classes for the
13 //===----------------------------------------------------------------------===//
15 #include "llvm/IR/FunctionInfo.h"
16 #include "llvm/ADT/StringMap.h"
19 // Create the combined function index/summary from multiple
20 // per-module instances.
21 void FunctionInfoIndex::mergeFrom(std::unique_ptr<FunctionInfoIndex> Other,
22 uint64_t NextModuleId) {
25 for (auto &OtherFuncInfoLists : *Other) {
26 std::string FuncName = OtherFuncInfoLists.getKey();
27 FunctionInfoList &List = OtherFuncInfoLists.second;
29 // Assert that the func 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<FunctionInfo> Info = std::move(List.front());
34 // Skip if there was no function summary section.
35 if (!Info->functionSummary())
38 // Add the module path string ref for this module if we haven't already
39 // saved a reference to it.
42 addModulePath(Info->functionSummary()->modulePath(), NextModuleId);
44 assert(ModPath == Info->functionSummary()->modulePath() &&
45 "Each module in the combined map should have a unique ID");
47 // Note the module path string ref was copied above and is still owned by
48 // the original per-module index. Reset it to the new module path
49 // string reference owned by the combined index.
50 Info->functionSummary()->setModulePath(ModPath);
52 // If it is a local function, rename it.
53 if (Info->functionSummary()->isLocalFunction()) {
54 // Any local functions are virtually renamed when being added to the
55 // combined index map, to disambiguate from other functions with
56 // the same name. The symbol table created for the combined index
57 // file should contain the renamed symbols.
59 FunctionInfoIndex::getGlobalNameForLocal(FuncName, NextModuleId);
62 // Add new function info to existing list. There may be duplicates when
63 // combining FunctionMap entries, due to COMDAT functions. Any local
64 // functions were virtually renamed above.
65 addFunctionInfo(FuncName, std::move(Info));