Skip to content

Commit

Permalink
[ThinLTO] Emit individual index files for distributed backends
Browse files Browse the repository at this point in the history
Summary:
When launching ThinLTO backends in a distributed build (currently
supported in gold via the thinlto-index-only plugin option), emit
an individual index file for each backend process as described here:
http://lists.llvm.org/pipermail/llvm-dev/2016-April/098272.html

The individual index file encodes the summary and module information
required for implementing the importing/exporting decisions made
for a given module in the thin link step.
This is in place of the current mechanism that uses the combined index
to make importing decisions in each back end independently. It is an
enabler for doing global summary based optimizations in the thin link
step (which will be recorded in the individual index files), and reduces
the size of the index that must be sent to each backend process, and
the amount of work to scan it in the backends.

Rather than create entirely new ModuleSummaryIndex structures (and all
the included unique_ptrs) for each backend index file, a map is created
to record all of the GUID and summary pointers needed for a particular
index file. The IndexBitcodeWriter walks this map instead of the full
index (hiding the details of managing the appropriate summary iteration
in a new iterator subclass). This is more efficient than walking the
entire combined index and filtering out just the needed summaries during
each backend bitcode index write.

Depends on D19481.

Reviewers: joker.eph

Subscribers: llvm-commits, joker.eph

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

llvm-svn: 268627
  • Loading branch information
teresajohnson committed May 5, 2016
1 parent 21c3fde commit 9254ebe
Show file tree
Hide file tree
Showing 11 changed files with 482 additions and 104 deletions.
8 changes: 6 additions & 2 deletions llvm/include/llvm/Bitcode/ReaderWriter.h
Expand Up @@ -97,8 +97,12 @@ namespace llvm {

/// Write the specified module summary index to the given raw output stream,
/// where it will be written in a new bitcode block. This is used when
/// writing the combined index file for ThinLTO.
void WriteIndexToFile(const ModuleSummaryIndex &Index, raw_ostream &Out);
/// writing the combined index file for ThinLTO. When writing a subset of the
/// index for a distributed backend, provide the \p ModuleToSummariesForIndex
/// map.
void WriteIndexToFile(const ModuleSummaryIndex &Index, raw_ostream &Out,
std::map<std::string, GVSummaryMapTy>
*ModuleToSummariesForIndex = nullptr);

/// isBitcodeWrapper - Return true if the given bytes are the magic bytes
/// for an LLVM IR bitcode wrapper.
Expand Down
9 changes: 8 additions & 1 deletion llvm/include/llvm/LTO/ThinLTOCodeGenerator.h
Expand Up @@ -19,6 +19,7 @@
#include "llvm-c/lto.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/ADT/Triple.h"
#include "llvm/IR/ModuleSummaryIndex.h"
#include "llvm/Support/CodeGen.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Target/TargetOptions.h"
Expand All @@ -27,7 +28,6 @@

namespace llvm {
class StringRef;
class ModuleSummaryIndex;
class LLVMContext;
class TargetMachine;

Expand Down Expand Up @@ -200,6 +200,13 @@ class ThinLTOCodeGenerator {
*/
void crossModuleImport(Module &Module, ModuleSummaryIndex &Index);

/**
* Compute the list of summaries needed for importing into module.
*/
static void gatherImportedSummariesForModule(
StringRef ModulePath, ModuleSummaryIndex &Index,
std::map<std::string, GVSummaryMapTy> &ModuleToSummariesForIndex);

/**
* Perform internalization.
*/
Expand Down
16 changes: 16 additions & 0 deletions llvm/include/llvm/Transforms/IPO/FunctionImport.h
Expand Up @@ -87,6 +87,22 @@ void ComputeCrossModuleImport(
void ComputeCrossModuleImportForModule(
StringRef ModulePath, const ModuleSummaryIndex &Index,
FunctionImporter::ImportMapTy &ImportList);

/// Compute the set of summaries needed for a ThinLTO backend compilation of
/// \p ModulePath.
//
/// This includes summaries from that module (in case any global summary based
/// optimizations were recorded) and from any definitions in other modules that
/// should be imported.
//
/// \p ModuleToSummariesForIndex will be populated with the needed summaries
/// from each required module path. Use a std::map instead of StringMap to get
/// stable order for bitcode emission.
void gatherImportedSummariesForModule(
StringRef ModulePath,
const StringMap<GVSummaryMapTy> &ModuleToDefinedGVSummaries,
const StringMap<FunctionImporter::ImportMapTy> &ImportLists,
std::map<std::string, GVSummaryMapTy> &ModuleToSummariesForIndex);
}

#endif // LLVM_FUNCTIONIMPORT_H

0 comments on commit 9254ebe

Please sign in to comment.