2016-03-15 08:04:37 +08:00
|
|
|
//===-- ModuleSummaryIndex.cpp - Module Summary Index ---------------------===//
|
2016-03-15 05:18:10 +08:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2016-03-15 08:04:37 +08:00
|
|
|
#include "llvm/IR/ModuleSummaryIndex.h"
|
2016-03-15 05:18:10 +08:00
|
|
|
#include "llvm/ADT/StringMap.h"
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
// Create the combined module index/summary from multiple
|
|
|
|
// per-module instances.
|
2016-03-15 08:04:37 +08:00
|
|
|
void ModuleSummaryIndex::mergeFrom(std::unique_ptr<ModuleSummaryIndex> Other,
|
|
|
|
uint64_t NextModuleId) {
|
2016-03-15 05:18:10 +08:00
|
|
|
|
|
|
|
StringRef ModPath;
|
|
|
|
for (auto &OtherGlobalValInfoLists : *Other) {
|
2016-04-02 13:07:53 +08:00
|
|
|
GlobalValue::GUID ValueGUID = OtherGlobalValInfoLists.first;
|
2016-03-15 05:18:10 +08:00
|
|
|
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<GlobalValueInfo> 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.
|
2016-04-01 13:33:11 +08:00
|
|
|
if (ModPath.empty()) {
|
|
|
|
auto Path = Info->summary()->modulePath();
|
|
|
|
ModPath = addModulePath(Path, NextModuleId, Other->getModuleHash(Path))
|
|
|
|
->first();
|
|
|
|
} else
|
2016-03-15 05:18:10 +08:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-15 08:04:37 +08:00
|
|
|
void ModuleSummaryIndex::removeEmptySummaryEntries() {
|
2016-03-15 05:18:10 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2016-04-05 08:40:16 +08:00
|
|
|
|
|
|
|
GlobalValueInfo *
|
|
|
|
ModuleSummaryIndex::getGlobalValueInfo(uint64_t ValueGUID,
|
|
|
|
bool PerModuleIndex) const {
|
|
|
|
auto InfoList = findGlobalValueInfoList(ValueGUID);
|
|
|
|
assert(InfoList != end() && "GlobalValue not found in index");
|
|
|
|
assert(!PerModuleIndex ||
|
|
|
|
InfoList->second.size() == 1 &&
|
|
|
|
"Expected a single entry per global value in per-module index");
|
|
|
|
auto &Info = InfoList->second[0];
|
|
|
|
return Info.get();
|
|
|
|
}
|