015f1235f6df7552f5bf1110d60a87d078363a83
[oota-llvm.git] / lib / IR / FunctionInfo.cpp
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
15 #include "llvm/IR/FunctionInfo.h"
16 #include "llvm/ADT/StringMap.h"
17 using namespace llvm;
18
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) {
23
24   StringRef ModPath;
25   for (auto &OtherFuncInfoLists : *Other) {
26     StringRef FuncName = OtherFuncInfoLists.getKey();
27     FunctionInfoList &List = OtherFuncInfoLists.second;
28
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());
33
34     // Add the module path string ref for this module if we haven't already
35     // saved a reference to it.
36     if (ModPath.empty())
37       ModPath =
38           addModulePath(Info->functionSummary()->modulePath(), NextModuleId);
39     else
40       assert(ModPath == Info->functionSummary()->modulePath() &&
41              "Each module in the combined map should have a unique ID");
42
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);
47
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.
54       FuncName =
55           FunctionInfoIndex::getGlobalNameForLocal(FuncName, NextModuleId);
56     }
57
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));
62   }
63 }