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. mergeFrom(std::unique_ptr<FunctionInfoIndex> Other,uint64_t NextModuleId)21void FunctionInfoIndex::mergeFrom(std::unique_ptr<FunctionInfoIndex> Other, 22 uint64_t NextModuleId) { 23 24 StringRef ModPath; 25 for (auto &OtherFuncInfoLists : *Other) { 26 std::string 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 // Skip if there was no function summary section. 35 if (!Info->functionSummary()) 36 continue; 37 38 // Add the module path string ref for this module if we haven't already 39 // saved a reference to it. 40 if (ModPath.empty()) 41 ModPath = 42 addModulePath(Info->functionSummary()->modulePath(), NextModuleId); 43 else 44 assert(ModPath == Info->functionSummary()->modulePath() && 45 "Each module in the combined map should have a unique ID"); 46 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); 51 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. 58 FuncName = 59 FunctionInfoIndex::getGlobalNameForLocal(FuncName, NextModuleId); 60 } 61 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)); 66 } 67 } 68