1 //===-- llvm-split: command line tool for testing module splitter ---------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This program can be used to test the llvm::SplitModule function.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/ADT/StringExtras.h"
15 #include "llvm/Bitcode/BitcodeWriter.h"
16 #include "llvm/IR/LLVMContext.h"
17 #include "llvm/IR/Verifier.h"
18 #include "llvm/IRReader/IRReader.h"
19 #include "llvm/Support/CommandLine.h"
20 #include "llvm/Support/FileSystem.h"
21 #include "llvm/Support/SourceMgr.h"
22 #include "llvm/Support/ToolOutputFile.h"
23 #include "llvm/Support/raw_ostream.h"
24 #include "llvm/Transforms/Utils/SplitModule.h"
28 static cl::opt
<std::string
>
29 InputFilename(cl::Positional
, cl::desc("<input bitcode file>"),
30 cl::init("-"), cl::value_desc("filename"));
32 static cl::opt
<std::string
>
33 OutputFilename("o", cl::desc("Override output filename"),
34 cl::value_desc("filename"));
36 static cl::opt
<unsigned> NumOutputs("j", cl::Prefix
, cl::init(2),
37 cl::desc("Number of output files"));
40 PreserveLocals("preserve-locals", cl::Prefix
, cl::init(false),
41 cl::desc("Split without externalizing locals"));
43 int main(int argc
, char **argv
) {
46 cl::ParseCommandLineOptions(argc
, argv
, "LLVM module splitter\n");
48 std::unique_ptr
<Module
> M
= parseIRFile(InputFilename
, Err
, Context
);
51 Err
.print(argv
[0], errs());
56 SplitModule(std::move(M
), NumOutputs
, [&](std::unique_ptr
<Module
> MPart
) {
58 std::unique_ptr
<tool_output_file
> Out(new tool_output_file(
59 OutputFilename
+ utostr(I
++), EC
, sys::fs::F_None
));
61 errs() << EC
.message() << '\n';
66 WriteBitcodeToFile(MPart
.get(), Out
->os());