mirror of
https://github.com/RPCS3/llvm.git
synced 2026-01-31 01:25:19 +01:00
Summary: The cumulative size of the bitcode files for a very large application can be huge, particularly with -g. In a distributed build environment, all of these files must be sent to the remote build node that performs the thin link step, and this can exceed size limits. The thin link actually only needs the summary along with a bitcode symbol table. Until we have a proper bitcode symbol table, simply stripping the debug metadata results in significant size reduction. Add support for an option to additionally emit minimized bitcode modules, just for use in the thin link step, which for now just strips all debug metadata. I plan to add a cc1 option so this can be invoked easily during the compile step. However, care must be taken to ensure that these minimized thin link bitcode files produce the same index as with the original bitcode files, as these original bitcode files will be used in the backends. Specifically: 1) The module hash used for caching is typically produced by hashing the written bitcode, and we want to include the hash that would correspond to the original bitcode file. This is because we want to ensure that changes in the stripped portions affect caching. Added plumbing to emit the same module hash in the minimized thin link bitcode file. 2) The module paths in the index are constructed from the module ID of each thin linked bitcode, and typically is automatically generated from the input file path. This is the path used for finding the modules to import from, and obviously we need this to point to the original bitcode files. Added gold-plugin support to take a suffix replacement during the thin link that is used to override the identifier on the MemoryBufferRef constructed from the loaded thin link bitcode file. The assumption is that the build system can specify that the minimized bitcode file has a name that is similar but uses a different suffix (e.g. out.thinlink.bc instead of out.o). Added various tests to ensure that we get identical index files out of the thin link step. Reviewers: mehdi_amini, pcc Subscribers: Prazek, llvm-commits Differential Revision: https://reviews.llvm.org/D31027 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@298638 91177308-0d34-0410-b5e6-96231b3b80d8
96 lines
4.0 KiB
C++
96 lines
4.0 KiB
C++
//===-- llvm/Bitcode/BitcodeWriter.h - Bitcode writers ----*- C++ -*-===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This header defines interfaces to write LLVM bitcode files/streams.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef LLVM_BITCODE_BITCODEWRITER_H
|
|
#define LLVM_BITCODE_BITCODEWRITER_H
|
|
|
|
#include "llvm/IR/ModuleSummaryIndex.h"
|
|
#include <string>
|
|
|
|
namespace llvm {
|
|
class BitstreamWriter;
|
|
class Module;
|
|
class raw_ostream;
|
|
|
|
class BitcodeWriter {
|
|
SmallVectorImpl<char> &Buffer;
|
|
std::unique_ptr<BitstreamWriter> Stream;
|
|
|
|
public:
|
|
/// Create a BitcodeWriter that writes to Buffer.
|
|
BitcodeWriter(SmallVectorImpl<char> &Buffer);
|
|
|
|
~BitcodeWriter();
|
|
|
|
/// Write the specified module to the buffer specified at construction time.
|
|
///
|
|
/// If \c ShouldPreserveUseListOrder, encode the use-list order for each \a
|
|
/// Value in \c M. These will be reconstructed exactly when \a M is
|
|
/// deserialized.
|
|
///
|
|
/// If \c Index is supplied, the bitcode will contain the summary index
|
|
/// (currently for use in ThinLTO optimization).
|
|
///
|
|
/// \p GenerateHash enables hashing the Module and including the hash in the
|
|
/// bitcode (currently for use in ThinLTO incremental build).
|
|
///
|
|
/// If \p ModHash is non-null, when GenerateHash is true, the resulting
|
|
/// hash is written into ModHash. When GenerateHash is false, that value
|
|
/// is used as the hash instead of computing from the generated bitcode.
|
|
/// Can be used to produce the same module hash for a minimized bitcode
|
|
/// used just for the thin link as in the regular full bitcode that will
|
|
/// be used in the backend.
|
|
void writeModule(const Module *M, bool ShouldPreserveUseListOrder = false,
|
|
const ModuleSummaryIndex *Index = nullptr,
|
|
bool GenerateHash = false, ModuleHash *ModHash = nullptr);
|
|
};
|
|
|
|
/// \brief Write the specified module to the specified raw output stream.
|
|
///
|
|
/// For streams where it matters, the given stream should be in "binary"
|
|
/// mode.
|
|
///
|
|
/// If \c ShouldPreserveUseListOrder, encode the use-list order for each \a
|
|
/// Value in \c M. These will be reconstructed exactly when \a M is
|
|
/// deserialized.
|
|
///
|
|
/// If \c Index is supplied, the bitcode will contain the summary index
|
|
/// (currently for use in ThinLTO optimization).
|
|
///
|
|
/// \p GenerateHash enables hashing the Module and including the hash in the
|
|
/// bitcode (currently for use in ThinLTO incremental build).
|
|
///
|
|
/// If \p ModHash is non-null, when GenerateHash is true, the resulting
|
|
/// hash is written into ModHash. When GenerateHash is false, that value
|
|
/// is used as the hash instead of computing from the generated bitcode.
|
|
/// Can be used to produce the same module hash for a minimized bitcode
|
|
/// used just for the thin link as in the regular full bitcode that will
|
|
/// be used in the backend.
|
|
void WriteBitcodeToFile(const Module *M, raw_ostream &Out,
|
|
bool ShouldPreserveUseListOrder = false,
|
|
const ModuleSummaryIndex *Index = nullptr,
|
|
bool GenerateHash = false,
|
|
ModuleHash *ModHash = nullptr);
|
|
|
|
/// 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. When writing a subset of the
|
|
/// index for a distributed backend, provide the \p ModuleToSummariesForIndex
|
|
/// map.
|
|
void WriteIndexToFile(const ModuleSummaryIndex &Index, raw_ostream &Out,
|
|
const std::map<std::string, GVSummaryMapTy>
|
|
*ModuleToSummariesForIndex = nullptr);
|
|
} // End llvm namespace
|
|
|
|
#endif
|