diff options
| author | Tobias Edler von Koch <tobias@codeaurora.org> | 2015-11-20 00:13:05 +0000 |
|---|---|---|
| committer | Tobias Edler von Koch <tobias@codeaurora.org> | 2015-11-20 00:13:05 +0000 |
| commit | 49c9a6e802148ac3e3510cf3b69c8a0a0fc62b93 (patch) | |
| tree | dc3705934ac98a6687a8bc2263d9f455aeeae1e3 | |
| parent | 257da8ea5046e2e78a5e3e030d31eebeb9ec8106 (diff) | |
| download | bcm5719-llvm-49c9a6e802148ac3e3510cf3b69c8a0a0fc62b93.tar.gz bcm5719-llvm-49c9a6e802148ac3e3510cf3b69c8a0a0fc62b93.zip | |
[LTO] Add options to llvm-lto to select output format and dump merged module
This introduces two new options:
- "llvm-lto -save-merged-module -o outfile" dumps the LTO Module to
outfile.merged.bc prior to CodeGen and after LTO optimizations have been run.
- "llvm-lto -filetype=asm -o outfile" makes llvm-lto emit assembly instead of
object code in outfile.
Both are intended for use in lit tests.
llvm-svn: 253624
| -rw-r--r-- | llvm/test/LTO/X86/llvm-lto-output.ll | 21 | ||||
| -rw-r--r-- | llvm/tools/llvm-lto/llvm-lto.cpp | 23 |
2 files changed, 44 insertions, 0 deletions
diff --git a/llvm/test/LTO/X86/llvm-lto-output.ll b/llvm/test/LTO/X86/llvm-lto-output.ll new file mode 100644 index 00000000000..56a9a5284b1 --- /dev/null +++ b/llvm/test/LTO/X86/llvm-lto-output.ll @@ -0,0 +1,21 @@ +; Test the various output formats of the llvm-lto utility +; +; RUN: llvm-as < %s > %t1 +; +; RUN: llvm-lto -exported-symbol=main -save-merged-module -filetype=asm -o %t2 %t1 +; RUN: llvm-dis -o - %t2.merged.bc | FileCheck %s +; CHECK: @main() + +; RUN: FileCheck --check-prefix=ASM %s < %t2 +; RUN: llvm-lto -exported-symbol=main -filetype=obj -o %t2 %t1 +; RUN: llvm-objdump -d %t2 | FileCheck --check-prefix=ASM %s +; ASM: main: +; + +target triple = "x86_64-unknown-linux-gnu" + +define i32 @main() { +entry: + ret i32 23 +} + diff --git a/llvm/tools/llvm-lto/llvm-lto.cpp b/llvm/tools/llvm-lto/llvm-lto.cpp index cdf91f9e377..aac82d31a36 100644 --- a/llvm/tools/llvm-lto/llvm-lto.cpp +++ b/llvm/tools/llvm-lto/llvm-lto.cpp @@ -64,6 +64,10 @@ static cl::opt<bool> ThinLTO("thinlto", cl::init(false), cl::desc("Only write combined global index for ThinLTO backends")); +static cl::opt<bool> +SaveModuleFile("save-merged-module", cl::init(false), + cl::desc("Write merged LTO module to file before CodeGen")); + static cl::list<std::string> InputFilenames(cl::Positional, cl::OneOrMore, cl::desc("<input bitcode files>")); @@ -343,6 +347,9 @@ int main(int argc, char **argv) { if (!attrs.empty()) CodeGen.setAttr(attrs.c_str()); + if (FileType.getNumOccurrences()) + CodeGen.setFileType(FileType); + if (!OutputFilename.empty()) { if (!CodeGen.optimize(DisableVerify, DisableInline, DisableGVNLoadPRE, DisableLTOVectorization)) { @@ -351,6 +358,17 @@ int main(int argc, char **argv) { return 1; } + if (SaveModuleFile) { + std::string ModuleFilename = OutputFilename; + ModuleFilename += ".merged.bc"; + std::string ErrMsg; + + if (!CodeGen.writeMergedModules(ModuleFilename.c_str())) { + errs() << argv[0] << ": writing merged module failed.\n"; + return 1; + } + } + std::list<tool_output_file> OSs; std::vector<raw_pwrite_stream *> OSPtrs; for (unsigned I = 0; I != Parallelism; ++I) { @@ -381,6 +399,11 @@ int main(int argc, char **argv) { return 1; } + if (SaveModuleFile) { + errs() << argv[0] << ": -save-merged-module must be specified with -o\n"; + return 1; + } + const char *OutputName = nullptr; if (!CodeGen.compile_to_file(&OutputName, DisableVerify, DisableInline, DisableGVNLoadPRE, DisableLTOVectorization)) { |

