diff options
author | Peter Collingbourne <peter@pcc.me.uk> | 2015-08-21 02:48:20 +0000 |
---|---|---|
committer | Peter Collingbourne <peter@pcc.me.uk> | 2015-08-21 02:48:20 +0000 |
commit | 1dc6a8d1797086c630de2da3249dbcafb7157e27 (patch) | |
tree | 6fe3199373e4518779716bdf20aae61ab1356bd2 /llvm/tools/llvm-split/llvm-split.cpp | |
parent | cf61aae163542877e71c1c193829df0366793d8f (diff) | |
download | bcm5719-llvm-1dc6a8d1797086c630de2da3249dbcafb7157e27.tar.gz bcm5719-llvm-1dc6a8d1797086c630de2da3249dbcafb7157e27.zip |
TransformUtils: Introduce module splitter.
The module splitter splits a module into linkable partitions. It will
be used to implement parallel LTO code generation.
This initial version of the splitter does not attempt to deal with the
somewhat subtle symbol visibility issues around module splitting. These
will be dealt with in a future change.
Differential Revision: http://reviews.llvm.org/D12132
llvm-svn: 245662
Diffstat (limited to 'llvm/tools/llvm-split/llvm-split.cpp')
-rw-r--r-- | llvm/tools/llvm-split/llvm-split.cpp | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/llvm/tools/llvm-split/llvm-split.cpp b/llvm/tools/llvm-split/llvm-split.cpp new file mode 100644 index 00000000000..059770fbf4a --- /dev/null +++ b/llvm/tools/llvm-split/llvm-split.cpp @@ -0,0 +1,67 @@ +//===-- llvm-split: command line tool for testing module splitter ---------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This program can be used to test the llvm::SplitModule function. +// +//===----------------------------------------------------------------------===// + +#include "llvm/ADT/StringExtras.h" +#include "llvm/Bitcode/ReaderWriter.h" +#include "llvm/IR/LLVMContext.h" +#include "llvm/IRReader/IRReader.h" +#include "llvm/Support/CommandLine.h" +#include "llvm/Support/FileSystem.h" +#include "llvm/Support/SourceMgr.h" +#include "llvm/Support/ToolOutputFile.h" +#include "llvm/Support/raw_ostream.h" +#include "llvm/Transforms/Utils/SplitModule.h" + +using namespace llvm; + +static cl::opt<std::string> +InputFilename(cl::Positional, cl::desc("<input bitcode file>"), + cl::init("-"), cl::value_desc("filename")); + +static cl::opt<std::string> +OutputFilename("o", cl::desc("Override output filename"), + cl::value_desc("filename")); + +static cl::opt<unsigned> NumOutputs("j", cl::Prefix, cl::init(2), + cl::desc("Number of output files")); + +int main(int argc, char **argv) { + LLVMContext &Context = getGlobalContext(); + SMDiagnostic Err; + cl::ParseCommandLineOptions(argc, argv, "LLVM module splitter\n"); + + std::unique_ptr<Module> M = parseIRFile(InputFilename, Err, Context); + + if (!M) { + Err.print(argv[0], errs()); + return 1; + } + + unsigned I = 0; + SplitModule(std::move(M), NumOutputs, [&](std::unique_ptr<Module> MPart) { + std::error_code EC; + std::unique_ptr<tool_output_file> Out(new tool_output_file( + OutputFilename + utostr(I++), EC, sys::fs::F_None)); + if (EC) { + errs() << EC.message() << '\n'; + exit(1); + } + + WriteBitcodeToFile(MPart.get(), Out->os()); + + // Declare success. + Out->keep(); + }); + + return 0; +} |