diff --git a/llvm/test/Assembler/multi-mod-disassemble.ll b/llvm/test/Assembler/multi-mod-disassemble.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Assembler/multi-mod-disassemble.ll @@ -0,0 +1,15 @@ +; RUN: llvm-as %s -o %t.o +; RUN: llvm-cat -b -o %t2.o %t.o %t.o +; RUN: llvm-dis -o %t3 %t2.o +; RUN: llvm-as -o %t4.o %t3.0 +; RUN: llvm-as -o %t5.o %t3.1 +; RUN: diff -b %t4.o %t5.o +; RUN: llvm-cat -b -o %t6.o %t5.o %t4.o +; RUN: llvm-dis -o %t7.o %t6.o +; RUN: diff %t7.o.0 %t7.o.1 +; RUN: FileCheck < %t7.o.0 %s +; RUN: FileCheck < %t7.o.1 %s + +; CHECK: source_filename = "{{.*}}multi-mod-disassemble.ll" +target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" diff --git a/llvm/test/Assembler/multi-summary-disassemble.ll b/llvm/test/Assembler/multi-summary-disassemble.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Assembler/multi-summary-disassemble.ll @@ -0,0 +1,18 @@ +; RUN: llvm-as %s -o %t.o +; RUN: llvm-cat -b -o %t2.o %t.o %t.o +; RUN: llvm-dis -o %t3 %t2.o +; RUN: llvm-as -o %t4.o %t3.0 +; RUN: llvm-as -o %t5.o %t3.1 +; RUN: diff -b %t4.o %t5.o +; RUN: llvm-cat -b -o %t6.o %t5.o %t4.o +; RUN: llvm-dis -o %t7.o %t6.o +; RUN: diff %t7.o.0 %t7.o.1 +; RUN: FileCheck < %t7.o.0 %s +; RUN: FileCheck < %t7.o.1 %s + +; ModuleID = 'multi-summary-disassemble.o' + +^0 = module: (path: "multi-summary-disassemble.ll", hash: (1369602428, 2747878711, 259090915, 2507395659, 1141468049)) +^1 = gv: (guid: 3, summaries: (function: (module: ^0, flags: (linkage: internal, notEligibleToImport: 0, live: 0, dsoLocal: 1), insts: 1))) +; CHECK: ^0 = module: (path: +; CHECK: ^1 = gv: (guid: 3, summaries: (function: (module: ^0, diff --git a/llvm/test/Bitcode/invalid.test b/llvm/test/Bitcode/invalid.test --- a/llvm/test/Bitcode/invalid.test +++ b/llvm/test/Bitcode/invalid.test @@ -66,11 +66,6 @@ INSERT-STRUCT: INSERTVAL: Invalid struct index INSERT-IDXS: INSERTVAL: Invalid type -RUN: not llvm-dis -disable-output %p/Inputs/invalid-no-proper-module.bc 2>&1 | \ -RUN: FileCheck --check-prefix=NO-MODULE %s - -NO-MODULE: Expected a single module - RUN: not llvm-dis -disable-output %p/Inputs/invalid-fp-shift.bc 2>&1 | \ RUN: FileCheck --check-prefix=FP-SHIFT %s diff --git a/llvm/test/Bitcode/multi-module.ll b/llvm/test/Bitcode/multi-module.ll --- a/llvm/test/Bitcode/multi-module.ll +++ b/llvm/test/Bitcode/multi-module.ll @@ -1,6 +1,4 @@ ; RUN: llvm-cat -o %t %s %S/Inputs/multi-module.ll -; RUN: not llvm-dis -o - %t 2>&1 | FileCheck --check-prefix=ERROR %s -; ERROR: Expected a single module ; RUN: llvm-bcanalyzer -dump %t | FileCheck --check-prefix=BCA %s @@ -10,18 +8,15 @@ ; RUN: llvm-as -o %t1 %s ; RUN: llvm-as -o %t2 %S/Inputs/multi-module.ll ; RUN: llvm-cat -o %t %t1 %t2 -; RUN: not llvm-dis -o - %t 2>&1 | FileCheck --check-prefix=ERROR %s ; RUN: llvm-bcanalyzer -dump %t | FileCheck --check-prefix=BCA %s ; RUN: llvm-cat -b -o %t %t1 %t2 -; RUN: not llvm-dis -o - %t 2>&1 | FileCheck --check-prefix=ERROR %s ; RUN: llvm-bcanalyzer -dump %t | FileCheck --check-prefix=BCA %s ; RUN: llvm-modextract -n 0 -o - %t | llvm-dis | FileCheck --check-prefix=IR1 %s ; RUN: llvm-modextract -n 1 -o - %t | llvm-dis | FileCheck --check-prefix=IR2 %s ; RUN: llvm-cat -b -o %t3 %t %t -; RUN: not llvm-dis -o - %t3 2>&1 | FileCheck --check-prefix=ERROR %s ; RUN: llvm-bcanalyzer -dump %t3 | FileCheck --check-prefix=BCA4 %s ; RUN: llvm-modextract -n 0 -o - %t3 | llvm-dis | FileCheck --check-prefix=IR1 %s diff --git a/llvm/tools/llvm-dis/llvm-dis.cpp b/llvm/tools/llvm-dis/llvm-dis.cpp --- a/llvm/tools/llvm-dis/llvm-dis.cpp +++ b/llvm/tools/llvm-dis/llvm-dis.cpp @@ -158,53 +158,71 @@ std::unique_ptr MB = ExitOnErr(errorOrToExpected(MemoryBuffer::getFileOrSTDIN(InputFilename))); - std::unique_ptr M = ExitOnErr(getLazyBitcodeModule( - *MB, Context, /*ShouldLazyLoadMetadata=*/true, SetImporting)); - if (MaterializeMetadata) - ExitOnErr(M->materializeMetadata()); - else - ExitOnErr(M->materializeAll()); - - BitcodeLTOInfo LTOInfo = ExitOnErr(getBitcodeLTOInfo(*MB)); - std::unique_ptr Index; - if (LTOInfo.HasSummary) - Index = ExitOnErr(getModuleSummaryIndex(*MB)); - - // Just use stdout. We won't actually print anything on it. - if (DontPrint) - OutputFilename = "-"; - - if (OutputFilename.empty()) { // Unspecified output, infer it. - if (InputFilename == "-") { - OutputFilename = "-"; + + BitcodeFileContents IF = ExitOnErr(llvm::getBitcodeFileContents(*MB)); + + const size_t N = IF.Mods.size(); + + if (OutputFilename == "-" && N > 1) + errs() << "only single module bitcode files can be written to stdout\n"; + + for (size_t i = 0; i < N; ++i) { + BitcodeModule MB = IF.Mods[i]; + std::unique_ptr M = ExitOnErr(MB.getLazyModule(Context, MaterializeMetadata, + SetImporting)); + if (MaterializeMetadata) + ExitOnErr(M->materializeMetadata()); + else + ExitOnErr(M->materializeAll()); + + BitcodeLTOInfo LTOInfo = ExitOnErr(MB.getLTOInfo()); + std::unique_ptr Index; + if (LTOInfo.HasSummary) + Index = ExitOnErr(MB.getSummary()); + + std::string FinalFilename(OutputFilename); + + // Just use stdout. We won't actually print anything on it. + if (DontPrint) + FinalFilename = "-"; + + if (OutputFilename.empty()) { // Unspecified output, infer it. + if (InputFilename == "-") { + FinalFilename = "-"; + } else { + StringRef IFN = InputFilename; + FinalFilename = (IFN.endswith(".bc") ? IFN.drop_back(3) : IFN).str(); + if (N > 1) + FinalFilename += std::string(".") + std::to_string(i); + FinalFilename += ".ll"; + } } else { - StringRef IFN = InputFilename; - OutputFilename = (IFN.endswith(".bc") ? IFN.drop_back(3) : IFN).str(); - OutputFilename += ".ll"; + if (N > 1) + FinalFilename += std::string(".") + std::to_string(i); } - } - std::error_code EC; - std::unique_ptr Out( - new ToolOutputFile(OutputFilename, EC, sys::fs::OF_Text)); - if (EC) { - errs() << EC.message() << '\n'; - return 1; - } + std::error_code EC; + std::unique_ptr Out( + new ToolOutputFile(FinalFilename, EC, sys::fs::OF_Text)); + if (EC) { + errs() << EC.message() << '\n'; + return 1; + } - std::unique_ptr Annotator; - if (ShowAnnotations) - Annotator.reset(new CommentWriter()); + std::unique_ptr Annotator; + if (ShowAnnotations) + Annotator.reset(new CommentWriter()); - // All that llvm-dis does is write the assembly to a file. - if (!DontPrint) { - M->print(Out->os(), Annotator.get(), PreserveAssemblyUseListOrder); - if (Index) - Index->print(Out->os()); - } + // All that llvm-dis does is write the assembly to a file. + if (!DontPrint) { + M->print(Out->os(), Annotator.get(), PreserveAssemblyUseListOrder); + if (Index) + Index->print(Out->os()); + } - // Declare success. - Out->keep(); + // Declare success. + Out->keep(); + } return 0; }