From 26ab5772b058fcddabfecb6736a3b78c67bc1751 Mon Sep 17 00:00:00 2001 From: Teresa Johnson Date: Tue, 15 Mar 2016 00:04:37 +0000 Subject: [ThinLTO] Renaming of function index to module summary index (NFC) (Resubmitting after fixing missing file issue) With the changes in r263275, there are now more than just functions in the summary. Completed the renaming of data structures (started in r263275) to reflect the wider scope. In particular, changed the FunctionIndex* data structures to ModuleIndex*, and renamed related variables and comments. Also renamed the files to reflect the changes. A companion clang patch will immediately succeed this patch to reflect this renaming. llvm-svn: 263513 --- llvm/lib/IR/ModuleSummaryIndex.cpp | 68 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 llvm/lib/IR/ModuleSummaryIndex.cpp (limited to 'llvm/lib/IR/ModuleSummaryIndex.cpp') diff --git a/llvm/lib/IR/ModuleSummaryIndex.cpp b/llvm/lib/IR/ModuleSummaryIndex.cpp new file mode 100644 index 00000000000..16b58ddbeff --- /dev/null +++ b/llvm/lib/IR/ModuleSummaryIndex.cpp @@ -0,0 +1,68 @@ +//===-- ModuleSummaryIndex.cpp - Module Summary Index ---------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file implements the module index and summary classes for the +// IR library. +// +//===----------------------------------------------------------------------===// + +#include "llvm/IR/ModuleSummaryIndex.h" +#include "llvm/ADT/StringMap.h" +using namespace llvm; + +// Create the combined module index/summary from multiple +// per-module instances. +void ModuleSummaryIndex::mergeFrom(std::unique_ptr Other, + uint64_t NextModuleId) { + + StringRef ModPath; + for (auto &OtherGlobalValInfoLists : *Other) { + uint64_t ValueGUID = OtherGlobalValInfoLists.first; + GlobalValueInfoList &List = OtherGlobalValInfoLists.second; + + // Assert that the value info list only has one entry, since we shouldn't + // have duplicate names within a single per-module index. + assert(List.size() == 1); + std::unique_ptr Info = std::move(List.front()); + + // Skip if there was no summary section. + if (!Info->summary()) + continue; + + // Add the module path string ref for this module if we haven't already + // saved a reference to it. + if (ModPath.empty()) + ModPath = addModulePath(Info->summary()->modulePath(), NextModuleId); + else + assert(ModPath == Info->summary()->modulePath() && + "Each module in the combined map should have a unique ID"); + + // Note the module path string ref was copied above and is still owned by + // the original per-module index. Reset it to the new module path + // string reference owned by the combined index. + Info->summary()->setModulePath(ModPath); + + // Add new value info to existing list. There may be duplicates when + // combining GlobalValueMap entries, due to COMDAT values. Any local + // values were given unique global IDs. + addGlobalValueInfo(ValueGUID, std::move(Info)); + } +} + +void ModuleSummaryIndex::removeEmptySummaryEntries() { + for (auto MI = begin(), MIE = end(); MI != MIE;) { + // Only expect this to be called on a per-module index, which has a single + // entry per value entry list. + assert(MI->second.size() == 1); + if (!MI->second[0]->summary()) + MI = GlobalValueMap.erase(MI); + else + ++MI; + } +} -- cgit v1.2.3