[llvm] 141bb5f - Add support for multi-module bitcode files to llvm-dis

Richard Smith via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 14 12:14:18 PST 2019


Hi Matthew,

A recent change (I strongly suspect it was this change) has broken the
-disable-output flag for llvm-dis: it now (sometimes) creates the output
file, but leaves it empty, when that flag is passed. This breaks two tests
if the source tree is checked out into a read-only filesystem. Please can
you take a look?

On Thu, 14 Nov 2019 at 10:42, Matthew Voss via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

>
> Author: Matthew Voss
> Date: 2019-11-14T10:40:41-08:00
> New Revision: 141bb5f308fa108045400622889a21a12c4ed41c
>
> URL:
> https://github.com/llvm/llvm-project/commit/141bb5f308fa108045400622889a21a12c4ed41c
> DIFF:
> https://github.com/llvm/llvm-project/commit/141bb5f308fa108045400622889a21a12c4ed41c.diff
>
> LOG: Add support for multi-module bitcode files to llvm-dis
>
> Summary:
> This change allows llvm-dis to disassemble multi-module bitcode
> files, including the associated module summary.
>
> Reviewers: tejohnson, pcc, mehdi_amini
>
> Subscribers: llvm-commits
>
> Tags: #llvm
>
> Differential Revision: https://reviews.llvm.org/D70153
>
> Added:
>     llvm/test/Assembler/multi-mod-disassemble.ll
>     llvm/test/Assembler/multi-summary-disassemble.ll
>
> Modified:
>     llvm/test/Bitcode/invalid.test
>     llvm/test/Bitcode/multi-module.ll
>     llvm/tools/llvm-dis/llvm-dis.cpp
>
> Removed:
>
>
>
>
> ################################################################################
> diff  --git a/llvm/test/Assembler/multi-mod-disassemble.ll
> b/llvm/test/Assembler/multi-mod-disassemble.ll
> new file mode 100644
> index 000000000000..58773b644572
> --- /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: cmp %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
> index 000000000000..d49ca35beece
> --- /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: cmp %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
> index d1f9d7c08745..8260ac862576 100644
> --- a/llvm/test/Bitcode/invalid.test
> +++ b/llvm/test/Bitcode/invalid.test
> @@ -66,11 +66,6 @@ INSERT-ARRAY: INSERTVAL: Invalid array index
>  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
> index 5f73240e8a02..b320bf1bfd32 100644
> --- 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
> index d66299cbf767..a0d9996da860 100644
> --- a/llvm/tools/llvm-dis/llvm-dis.cpp
> +++ b/llvm/tools/llvm-dis/llvm-dis.cpp
> @@ -158,53 +158,71 @@ int main(int argc, char **argv) {
>
>    std::unique_ptr<MemoryBuffer> MB =
>
>  ExitOnErr(errorOrToExpected(MemoryBuffer::getFileOrSTDIN(InputFilename)));
> -  std::unique_ptr<Module> 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<ModuleSummaryIndex> 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<Module> M = ExitOnErr(MB.getLazyModule(Context,
> MaterializeMetadata,
> +                                          SetImporting));
> +    if (MaterializeMetadata)
> +      ExitOnErr(M->materializeMetadata());
> +    else
> +      ExitOnErr(M->materializeAll());
> +
> +    BitcodeLTOInfo LTOInfo = ExitOnErr(MB.getLTOInfo());
> +    std::unique_ptr<ModuleSummaryIndex> 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<ToolOutputFile> Out(
> -      new ToolOutputFile(OutputFilename, EC, sys::fs::OF_Text));
> -  if (EC) {
> -    errs() << EC.message() << '\n';
> -    return 1;
> -  }
> +    std::error_code EC;
> +    std::unique_ptr<ToolOutputFile> Out(
> +        new ToolOutputFile(FinalFilename, EC, sys::fs::OF_Text));
> +    if (EC) {
> +      errs() << EC.message() << '\n';
> +      return 1;
> +    }
>
> -  std::unique_ptr<AssemblyAnnotationWriter> Annotator;
> -  if (ShowAnnotations)
> -    Annotator.reset(new CommentWriter());
> +    std::unique_ptr<AssemblyAnnotationWriter> 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;
>  }
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191114/0fd18e65/attachment.html>


More information about the llvm-commits mailing list