mirror of
https://github.com/RPCSX/llvm.git
synced 2024-12-29 07:53:31 +00:00
a547919737
Summary: Split ReaderWriter.h which contains the APIs into both the BitReader and BitWriter libraries into BitcodeReader.h and BitcodeWriter.h. This is to address Chandler's concern about sharing the same API header between multiple libraries (BitReader and BitWriter). That concern is why we create a single bitcode library in our downstream build of clang, which led to r286297 being reverted as it added a dependency that created a cycle only when there is a single bitcode library (not two as in upstream). Reviewers: mehdi_amini Subscribers: dlj, mehdi_amini, llvm-commits Differential Revision: https://reviews.llvm.org/D26502 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286566 91177308-0d34-0410-b5e6-96231b3b80d8
74 lines
2.2 KiB
C++
74 lines
2.2 KiB
C++
//===-- 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/BitcodeWriter.h"
|
|
#include "llvm/IR/LLVMContext.h"
|
|
#include "llvm/IR/Verifier.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"));
|
|
|
|
static cl::opt<bool>
|
|
PreserveLocals("preserve-locals", cl::Prefix, cl::init(false),
|
|
cl::desc("Split without externalizing locals"));
|
|
|
|
int main(int argc, char **argv) {
|
|
LLVMContext Context;
|
|
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);
|
|
}
|
|
|
|
verifyModule(*MPart);
|
|
WriteBitcodeToFile(MPart.get(), Out->os());
|
|
|
|
// Declare success.
|
|
Out->keep();
|
|
}, PreserveLocals);
|
|
|
|
return 0;
|
|
}
|