diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2015-12-30 11:46:15 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2015-12-30 11:46:15 +0000 |
| commit | dd58ef019b700900793a1eb48b52123db01b654e (patch) | |
| tree | fcfbb4df56a744f4ddc6122c50521dd3f1c5e196 /tools/llvm-split | |
| parent | 2fe5752e3a7c345cdb59e869278d36af33c13fa4 (diff) | |
Notes
Diffstat (limited to 'tools/llvm-split')
| -rw-r--r-- | tools/llvm-split/CMakeLists.txt | 11 | ||||
| -rw-r--r-- | tools/llvm-split/LLVMBuild.txt | 22 | ||||
| -rw-r--r-- | tools/llvm-split/Makefile | 17 | ||||
| -rw-r--r-- | tools/llvm-split/llvm-split.cpp | 67 |
4 files changed, 117 insertions, 0 deletions
diff --git a/tools/llvm-split/CMakeLists.txt b/tools/llvm-split/CMakeLists.txt new file mode 100644 index 000000000000..6e22a7236714 --- /dev/null +++ b/tools/llvm-split/CMakeLists.txt @@ -0,0 +1,11 @@ +set(LLVM_LINK_COMPONENTS + TransformUtils + BitWriter + Core + IRReader + Support + ) + +add_llvm_tool(llvm-split + llvm-split.cpp + ) diff --git a/tools/llvm-split/LLVMBuild.txt b/tools/llvm-split/LLVMBuild.txt new file mode 100644 index 000000000000..780c76afa41c --- /dev/null +++ b/tools/llvm-split/LLVMBuild.txt @@ -0,0 +1,22 @@ +;===- ./tools/llvm-split/LLVMBuild.txt -------------------------*- Conf -*--===; +; +; The LLVM Compiler Infrastructure +; +; This file is distributed under the University of Illinois Open Source +; License. See LICENSE.TXT for details. +; +;===------------------------------------------------------------------------===; +; +; This is an LLVMBuild description file for the components in this subdirectory. +; +; For more information on the LLVMBuild system, please see: +; +; http://llvm.org/docs/LLVMBuild.html +; +;===------------------------------------------------------------------------===; + +[component_0] +type = Tool +name = llvm-split +parent = Tools +required_libraries = TransformUtils BitWriter Core IRReader Support diff --git a/tools/llvm-split/Makefile b/tools/llvm-split/Makefile new file mode 100644 index 000000000000..ef1243dbf1ff --- /dev/null +++ b/tools/llvm-split/Makefile @@ -0,0 +1,17 @@ +##===- tools/llvm-split/Makefile ---------------------------*- Makefile -*-===## +# +# The LLVM Compiler Infrastructure +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +##===----------------------------------------------------------------------===## + +LEVEL := ../.. +TOOLNAME := llvm-split +LINK_COMPONENTS := transformutils bitwriter core irreader support + +# This tool has no plugins, optimize startup time. +TOOL_NO_EXPORTS := 1 + +include $(LEVEL)/Makefile.common diff --git a/tools/llvm-split/llvm-split.cpp b/tools/llvm-split/llvm-split.cpp new file mode 100644 index 000000000000..059770fbf4ac --- /dev/null +++ b/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; +} |
