1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-21 20:12:56 +02:00
llvm-mirror/lib/IR/FunctionInfo.cpp
Teresa Johnson 2b4369dd03 [ThinLTO] Handle bitcode without function summary sections gracefully
Summary:
Several fixes to the handling of bitcode files without function summary
sections so that they are skipped during ThinLTO processing in llvm-lto
and the gold plugin when appropriate instead of aborting.

1 Don't assert when trying to add a FunctionInfo that doesn't have
  a summary attached.
2 Skip FunctionInfo structures that don't have attached function summary
  sections when trying to create the combined function summary.
3 In both llvm-lto and gold-plugin, check whether a bitcode file has
  a function summary section before trying to parse the index, and skip
  the bitcode file if it does not.
4 Fix hasFunctionSummaryInMemBuffer in BitcodeReader, which had a bug
  where we returned to early while looking for the summary section.

Also added llvm-lto and gold-plugin based tests for cases where we
don't have function summaries in the bitcode file. I verified that
either the first couple fixes described above are enough to avoid the
crashes, or fixes 1,3,4. But have combined them all here for added
robustness.

Reviewers: joker.eph

Subscribers: llvm-commits, joker.eph

Differential Revision: http://reviews.llvm.org/D14903

llvm-svn: 253796
2015-11-21 21:55:48 +00:00

68 lines
2.6 KiB
C++

//===-- FunctionInfo.cpp - Function Info 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 function info index and summary classes for the
// IR library.
//
//===----------------------------------------------------------------------===//
#include "llvm/IR/FunctionInfo.h"
#include "llvm/ADT/StringMap.h"
using namespace llvm;
// Create the combined function index/summary from multiple
// per-module instances.
void FunctionInfoIndex::mergeFrom(std::unique_ptr<FunctionInfoIndex> Other,
uint64_t NextModuleId) {
StringRef ModPath;
for (auto &OtherFuncInfoLists : *Other) {
std::string FuncName = OtherFuncInfoLists.getKey();
FunctionInfoList &List = OtherFuncInfoLists.second;
// Assert that the func 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<FunctionInfo> Info = std::move(List.front());
// Skip if there was no function summary section.
if (!Info->functionSummary())
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->functionSummary()->modulePath(), NextModuleId);
else
assert(ModPath == Info->functionSummary()->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->functionSummary()->setModulePath(ModPath);
// If it is a local function, rename it.
if (Info->functionSummary()->isLocalFunction()) {
// Any local functions are virtually renamed when being added to the
// combined index map, to disambiguate from other functions with
// the same name. The symbol table created for the combined index
// file should contain the renamed symbols.
FuncName =
FunctionInfoIndex::getGlobalNameForLocal(FuncName, NextModuleId);
}
// Add new function info to existing list. There may be duplicates when
// combining FunctionMap entries, due to COMDAT functions. Any local
// functions were virtually renamed above.
addFunctionInfo(FuncName, std::move(Info));
}
}