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 StringRef 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 // Add the module path string ref for this module if we haven't already
35 // saved a reference to it.
38 addModulePath(Info->functionSummary()->modulePath(), NextModuleId);
40 assert(ModPath == Info->functionSummary()->modulePath() &&
41 "Each module in the combined map should have a unique ID");
43 // Note the module path string ref was copied above and is still owned by
44 // the original per-module index. Reset it to the new module path
45 // string reference owned by the combined index.
46 Info->functionSummary()->setModulePath(ModPath);
48 // If it is a local function, rename it.
49 if (Info->functionSummary()->isLocalFunction()) {
50 // Any local functions are virtually renamed when being added to the
51 // combined index map, to disambiguate from other functions with
52 // the same name. The symbol table created for the combined index
53 // file should contain the renamed symbols.
55 FunctionInfoIndex::getGlobalNameForLocal(FuncName, NextModuleId);
58 // Add new function info to existing list. There may be duplicates when
59 // combining FunctionMap entries, due to COMDAT functions. Any local
60 // functions were virtually renamed above.
61 addFunctionInfo(FuncName, std::move(Info));