[llvm] r332881 - CodeGen: Add a dwo output file argument to addPassesToEmitFile and hook it up to dwo output.

Peter Collingbourne via llvm-commits llvm-commits at lists.llvm.org
Mon May 21 13:16:41 PDT 2018


Author: pcc
Date: Mon May 21 13:16:41 2018
New Revision: 332881

URL: http://llvm.org/viewvc/llvm-project?rev=332881&view=rev
Log:
CodeGen: Add a dwo output file argument to addPassesToEmitFile and hook it up to dwo output.

Part of PR37466.

Differential Revision: https://reviews.llvm.org/D47089

Modified:
    llvm/trunk/include/llvm/Target/TargetMachine.h
    llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp
    llvm/trunk/lib/CodeGen/ParallelCG.cpp
    llvm/trunk/lib/LTO/LTOBackend.cpp
    llvm/trunk/lib/LTO/ThinLTOCodeGenerator.cpp
    llvm/trunk/lib/Target/TargetMachineC.cpp
    llvm/trunk/test/CodeGen/X86/dwarf-headers.ll
    llvm/trunk/test/CodeGen/X86/dwarf-split-line-1.ll
    llvm/trunk/test/CodeGen/X86/dwarf-split-line-2.ll
    llvm/trunk/tools/llc/llc.cpp
    llvm/trunk/tools/llvm-exegesis/lib/Assembler.cpp
    llvm/trunk/tools/llvm-isel-fuzzer/llvm-isel-fuzzer.cpp

Modified: llvm/trunk/include/llvm/Target/TargetMachine.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetMachine.h?rev=332881&r1=332880&r2=332881&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Target/TargetMachine.h (original)
+++ llvm/trunk/include/llvm/Target/TargetMachine.h Mon May 21 13:16:41 2018
@@ -252,7 +252,7 @@ public:
   /// \p MMI is an optional parameter that, if set to non-nullptr,
   /// will be used to set the MachineModuloInfo for this PM.
   virtual bool addPassesToEmitFile(PassManagerBase &, raw_pwrite_stream &,
-                                   CodeGenFileType,
+                                   raw_pwrite_stream *, CodeGenFileType,
                                    bool /*DisableVerify*/ = true,
                                    MachineModuleInfo *MMI = nullptr) {
     return true;
@@ -321,7 +321,8 @@ public:
   /// \p MMI is an optional parameter that, if set to non-nullptr,
   /// will be used to set the MachineModuloInfofor this PM.
   bool addPassesToEmitFile(PassManagerBase &PM, raw_pwrite_stream &Out,
-                           CodeGenFileType FileType, bool DisableVerify = true,
+                           raw_pwrite_stream *DwoOut, CodeGenFileType FileType,
+                           bool DisableVerify = true,
                            MachineModuleInfo *MMI = nullptr) override;
 
   /// Add passes to the specified pass manager to get machine code emitted with
@@ -341,7 +342,8 @@ public:
   /// Adds an AsmPrinter pass to the pipeline that prints assembly or
   /// machine code from the MI representation.
   bool addAsmPrinter(PassManagerBase &PM, raw_pwrite_stream &Out,
-                     CodeGenFileType FileTYpe, MCContext &Context);
+                     raw_pwrite_stream *DwoOut, CodeGenFileType FileTYpe,
+                     MCContext &Context);
 };
 
 } // end namespace llvm

Modified: llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp?rev=332881&r1=332880&r2=332881&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp (original)
+++ llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp Mon May 21 13:16:41 2018
@@ -121,8 +121,10 @@ addPassesToGenerateCode(LLVMTargetMachin
 }
 
 bool LLVMTargetMachine::addAsmPrinter(PassManagerBase &PM,
-    raw_pwrite_stream &Out, CodeGenFileType FileType,
-    MCContext &Context) {
+                                      raw_pwrite_stream &Out,
+                                      raw_pwrite_stream *DwoOut,
+                                      CodeGenFileType FileType,
+                                      MCContext &Context) {
   if (Options.MCOptions.MCSaveTempLabels)
     Context.setAllowTemporaryLabels(false);
 
@@ -168,8 +170,9 @@ bool LLVMTargetMachine::addAsmPrinter(Pa
     Triple T(getTargetTriple().str());
     AsmStreamer.reset(getTarget().createMCObjectStreamer(
         T, Context, std::unique_ptr<MCAsmBackend>(MAB),
-        MAB->createObjectWriter(Out), std::unique_ptr<MCCodeEmitter>(MCE), STI,
-        Options.MCOptions.MCRelaxAll,
+        DwoOut ? MAB->createDwoObjectWriter(Out, *DwoOut)
+               : MAB->createObjectWriter(Out),
+        std::unique_ptr<MCCodeEmitter>(MCE), STI, Options.MCOptions.MCRelaxAll,
         Options.MCOptions.MCIncrementalLinkerCompatible,
         /*DWARFMustBeAtTheEnd*/ true));
     break;
@@ -193,6 +196,7 @@ bool LLVMTargetMachine::addAsmPrinter(Pa
 
 bool LLVMTargetMachine::addPassesToEmitFile(PassManagerBase &PM,
                                             raw_pwrite_stream &Out,
+                                            raw_pwrite_stream *DwoOut,
                                             CodeGenFileType FileType,
                                             bool DisableVerify,
                                             MachineModuleInfo *MMI) {
@@ -203,7 +207,8 @@ bool LLVMTargetMachine::addPassesToEmitF
   if (!Context)
     return true;
 
-  if (WillCompleteCodeGenPipeline && addAsmPrinter(PM, Out, FileType, *Context))
+  if (WillCompleteCodeGenPipeline &&
+      addAsmPrinter(PM, Out, DwoOut, FileType, *Context))
     return true;
 
   PM.add(createFreeMachineFunctionPass());

Modified: llvm/trunk/lib/CodeGen/ParallelCG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/ParallelCG.cpp?rev=332881&r1=332880&r2=332881&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/ParallelCG.cpp (original)
+++ llvm/trunk/lib/CodeGen/ParallelCG.cpp Mon May 21 13:16:41 2018
@@ -30,7 +30,7 @@ static void codegen(Module *M, llvm::raw
                     TargetMachine::CodeGenFileType FileType) {
   std::unique_ptr<TargetMachine> TM = TMFactory();
   legacy::PassManager CodeGenPasses;
-  if (TM->addPassesToEmitFile(CodeGenPasses, OS, FileType))
+  if (TM->addPassesToEmitFile(CodeGenPasses, OS, nullptr, FileType))
     report_fatal_error("Failed to setup codegen");
   CodeGenPasses.run(*M);
 }

Modified: llvm/trunk/lib/LTO/LTOBackend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/LTOBackend.cpp?rev=332881&r1=332880&r2=332881&view=diff
==============================================================================
--- llvm/trunk/lib/LTO/LTOBackend.cpp (original)
+++ llvm/trunk/lib/LTO/LTOBackend.cpp Mon May 21 13:16:41 2018
@@ -304,7 +304,7 @@ void codegenWithSplitDwarf(Config &Conf,
   TM->Options.MCOptions.SplitDwarfFile = DwarfFile.str().str();
 
   legacy::PassManager CodeGenPasses;
-  if (TM->addPassesToEmitFile(CodeGenPasses, OS, Conf.CGFileType))
+  if (TM->addPassesToEmitFile(CodeGenPasses, OS, nullptr, Conf.CGFileType))
     report_fatal_error("Failed to setup codegen");
   CodeGenPasses.run(Mod);
 
@@ -355,7 +355,8 @@ void codegen(Config &Conf, TargetMachine
 
   auto Stream = AddStream(Task);
   legacy::PassManager CodeGenPasses;
-  if (TM->addPassesToEmitFile(CodeGenPasses, *Stream->OS, Conf.CGFileType))
+  if (TM->addPassesToEmitFile(CodeGenPasses, *Stream->OS, nullptr,
+                              Conf.CGFileType))
     report_fatal_error("Failed to setup codegen");
   CodeGenPasses.run(Mod);
 }

Modified: llvm/trunk/lib/LTO/ThinLTOCodeGenerator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LTO/ThinLTOCodeGenerator.cpp?rev=332881&r1=332880&r2=332881&view=diff
==============================================================================
--- llvm/trunk/lib/LTO/ThinLTOCodeGenerator.cpp (original)
+++ llvm/trunk/lib/LTO/ThinLTOCodeGenerator.cpp Mon May 21 13:16:41 2018
@@ -268,7 +268,7 @@ std::unique_ptr<MemoryBuffer> codegenMod
     PM.add(createObjCARCContractPass());
 
     // Setup the codegen now.
-    if (TM.addPassesToEmitFile(PM, OS, TargetMachine::CGFT_ObjectFile,
+    if (TM.addPassesToEmitFile(PM, OS, nullptr, TargetMachine::CGFT_ObjectFile,
                                /* DisableVerify */ true))
       report_fatal_error("Failed to setup codegen");
 

Modified: llvm/trunk/lib/Target/TargetMachineC.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/TargetMachineC.cpp?rev=332881&r1=332880&r2=332881&view=diff
==============================================================================
--- llvm/trunk/lib/Target/TargetMachineC.cpp (original)
+++ llvm/trunk/lib/Target/TargetMachineC.cpp Mon May 21 13:16:41 2018
@@ -196,7 +196,7 @@ static LLVMBool LLVMTargetMachineEmit(LL
       ft = TargetMachine::CGFT_ObjectFile;
       break;
   }
-  if (TM->addPassesToEmitFile(pass, OS, ft)) {
+  if (TM->addPassesToEmitFile(pass, OS, nullptr, ft)) {
     error = "TargetMachine can't emit a file of this type";
     *ErrorMessage = strdup(error.c_str());
     return true;

Modified: llvm/trunk/test/CodeGen/X86/dwarf-headers.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/dwarf-headers.ll?rev=332881&r1=332880&r2=332881&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/dwarf-headers.ll (original)
+++ llvm/trunk/test/CodeGen/X86/dwarf-headers.ll Mon May 21 13:16:41 2018
@@ -2,17 +2,21 @@
 ; RUN:     -filetype=obj -O0 -mtriple=x86_64-unknown-linux-gnu < %s \
 ; RUN:     | llvm-dwarfdump -v - | FileCheck %s --check-prefix=SINGLE-4
 
-; RUN: llc -split-dwarf-file=foo.dwo -dwarf-version=4 -generate-type-units \
+; RUN: llc -split-dwarf-file=foo.dwo -split-dwarf-output=%t.dwo \
+; RUN:     -dwarf-version=4 -generate-type-units \
 ; RUN:     -filetype=obj -O0 -mtriple=x86_64-unknown-linux-gnu < %s \
-; RUN:     | llvm-dwarfdump -v - | FileCheck %s --check-prefix=SPLIT-4
+; RUN:     | llvm-dwarfdump -v - | FileCheck %s --check-prefix=O-4
+; RUN: llvm-dwarfdump -v %t.dwo | FileCheck %s --check-prefix=DWO-4
 
 ; RUN: llc -dwarf-version=5 -generate-type-units \
 ; RUN:     -filetype=obj -O0 -mtriple=x86_64-unknown-linux-gnu < %s \
 ; RUN:     | llvm-dwarfdump -v - | FileCheck %s --check-prefix=SINGLE-5
 
-; RUN: llc -split-dwarf-file=foo.dwo -dwarf-version=5 -generate-type-units \
+; RUN: llc -split-dwarf-file=foo.dwo -split-dwarf-output=%t.dwo \
+; RUN:     -dwarf-version=5 -generate-type-units \
 ; RUN:     -filetype=obj -O0 -mtriple=x86_64-unknown-linux-gnu < %s \
-; RUN:     | llvm-dwarfdump -v - | FileCheck %s --check-prefix=SPLIT-5
+; RUN:     | llvm-dwarfdump -v - | FileCheck %s --check-prefix=O-5
+; RUN: llvm-dwarfdump -v %t.dwo | FileCheck %s --check-prefix=DWO-5
 
 ; Looking for DWARF headers to be generated correctly.
 ; There are 7 variants: v4 CU, v4 TU, v5 (normal/skeleton/split) CU,
@@ -42,17 +46,17 @@
 
 ; Verify the v4 split headers.
 ;
-; SPLIT-4: .debug_info contents:
-; SPLIT-4: 0x00000000: Compile Unit: {{.*}} version = 0x0004 abbr_offset
-; SPLIT-4: 0x0000000b: DW_TAG_compile_unit
-;
-; SPLIT-4: .debug_info.dwo contents:
-; SPLIT-4: 0x00000000: Compile Unit: {{.*}} version = 0x0004 abbr_offset
-; SPLIT-4: 0x0000000b: DW_TAG_compile_unit
-;
-; SPLIT-4: .debug_types.dwo contents:
-; SPLIT-4: 0x00000000: Type Unit: {{.*}} version = 0x0004 abbr_offset
-; SPLIT-4: 0x00000017: DW_TAG_type_unit
+; O-4: .debug_info contents:
+; O-4: 0x00000000: Compile Unit: {{.*}} version = 0x0004 abbr_offset
+; O-4: 0x0000000b: DW_TAG_compile_unit
+;
+; DWO-4: .debug_info.dwo contents:
+; DWO-4: 0x00000000: Compile Unit: {{.*}} version = 0x0004 abbr_offset
+; DWO-4: 0x0000000b: DW_TAG_compile_unit
+;
+; DWO-4: .debug_types.dwo contents:
+; DWO-4: 0x00000000: Type Unit: {{.*}} version = 0x0004 abbr_offset
+; DWO-4: 0x00000017: DW_TAG_type_unit
 
 ; Verify the v5 non-split headers.
 ;
@@ -67,18 +71,18 @@
 
 ; Verify the v5 split headers.
 ;
-; SPLIT-5: .debug_info contents:
-; SPLIT-5: 0x00000000: Compile Unit: {{.*}} version = 0x0005 unit_type = DW_UT_skeleton abbr_offset
-; SPLIT-5: 0x0000000c: DW_TAG_compile_unit
-;
-; SPLIT-5: .debug_info.dwo contents:
-; SPLIT-5: 0x00000000: Compile Unit: {{.*}} version = 0x0005 unit_type = DW_UT_split_compile abbr_offset
-; SPLIT-5: 0x0000000c: DW_TAG_compile_unit
+; O-5: .debug_info contents:
+; O-5: 0x00000000: Compile Unit: {{.*}} version = 0x0005 unit_type = DW_UT_skeleton abbr_offset
+; O-5: 0x0000000c: DW_TAG_compile_unit
+;
+; DWO-5: .debug_info.dwo contents:
+; DWO-5: 0x00000000: Compile Unit: {{.*}} version = 0x0005 unit_type = DW_UT_split_compile abbr_offset
+; DWO-5: 0x0000000c: DW_TAG_compile_unit
 ;
 ; FIXME: V5 wants type units in .debug_info.dwo not .debug_types.dwo.
-; SPLIT-5: .debug_types.dwo contents:
-; SPLIT-5: 0x00000000: Type Unit: {{.*}} version = 0x0005 unit_type = DW_UT_split_type abbr_offset
-; SPLIT-5: 0x00000018: DW_TAG_type_unit
+; DWO-5: .debug_types.dwo contents:
+; DWO-5: 0x00000000: Type Unit: {{.*}} version = 0x0005 unit_type = DW_UT_split_type abbr_offset
+; DWO-5: 0x00000018: DW_TAG_type_unit
 
 
 ; ModuleID = 't.cpp'

Modified: llvm/trunk/test/CodeGen/X86/dwarf-split-line-1.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/dwarf-split-line-1.ll?rev=332881&r1=332880&r2=332881&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/dwarf-split-line-1.ll (original)
+++ llvm/trunk/test/CodeGen/X86/dwarf-split-line-1.ll Mon May 21 13:16:41 2018
@@ -1,9 +1,10 @@
 ; Verify that split type units with no source locations don't have a
 ; DW_AT_stmt_list attribute, and the .debug_line.dwo section is suppressed.
 
-; RUN: llc -split-dwarf-file=foo.dwo -dwarf-version=5 -generate-type-units \
-; RUN:     -filetype=obj -O0 -mtriple=x86_64-unknown-linux-gnu < %s \
-; RUN:     | llvm-dwarfdump -v - | FileCheck %s
+; RUN: llc -split-dwarf-file=foo.dwo -split-dwarf-output=%t.dwo \
+; RUN:     -dwarf-version=5 -generate-type-units \
+; RUN:     -filetype=obj -O0 -mtriple=x86_64-unknown-linux-gnu < %s
+; RUN: llvm-dwarfdump -v %t.dwo | FileCheck %s
 
 ; FIXME: V5 wants type units in .debug_info.dwo not .debug_types.dwo.
 ; CHECK-NOT: .debug_line.dwo

Modified: llvm/trunk/test/CodeGen/X86/dwarf-split-line-2.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/dwarf-split-line-2.ll?rev=332881&r1=332880&r2=332881&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/dwarf-split-line-2.ll (original)
+++ llvm/trunk/test/CodeGen/X86/dwarf-split-line-2.ll Mon May 21 13:16:41 2018
@@ -2,9 +2,10 @@
 ; one without, the one without locations doesn't have a DW_AT_stmt_list
 ; attribute, but the other one does and the .debug_line.dwo section is present.
 
-; RUN: llc -split-dwarf-file=foo.dwo -dwarf-version=5 -generate-type-units \
-; RUN:     -filetype=obj -O0 -mtriple=x86_64-unknown-linux-gnu < %s \
-; RUN:     | llvm-dwarfdump -v - | FileCheck %s
+; RUN: llc -split-dwarf-file=foo.dwo -split-dwarf-output=%t.dwo \
+; RUN:     -dwarf-version=5 -generate-type-units \
+; RUN:     -filetype=obj -O0 -mtriple=x86_64-unknown-linux-gnu < %s
+; RUN: llvm-dwarfdump -v %t.dwo | FileCheck %s
 
 ; Currently the no-source-location type comes out first.
 ; FIXME: V5 wants type units in .debug_info.dwo not .debug_types.dwo.

Modified: llvm/trunk/tools/llc/llc.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llc/llc.cpp?rev=332881&r1=332880&r2=332881&view=diff
==============================================================================
--- llvm/trunk/tools/llc/llc.cpp (original)
+++ llvm/trunk/tools/llc/llc.cpp Mon May 21 13:16:41 2018
@@ -66,6 +66,11 @@ InputLanguage("x", cl::desc("Input langu
 static cl::opt<std::string>
 OutputFilename("o", cl::desc("Output filename"), cl::value_desc("filename"));
 
+static cl::opt<std::string>
+    SplitDwarfOutputFile("split-dwarf-output",
+                         cl::desc(".dwo output filename"),
+                         cl::value_desc("filename"));
+
 static cl::opt<unsigned>
 TimeCompilations("time-compilations", cl::Hidden, cl::init(1u),
                  cl::value_desc("N"),
@@ -463,6 +468,17 @@ static int compileModule(char **argv, LL
       GetOutputStream(TheTarget->getName(), TheTriple.getOS(), argv[0]);
   if (!Out) return 1;
 
+  std::unique_ptr<ToolOutputFile> DwoOut;
+  if (!SplitDwarfOutputFile.empty()) {
+    std::error_code EC;
+    DwoOut = llvm::make_unique<ToolOutputFile>(SplitDwarfOutputFile, EC,
+                                               sys::fs::F_None);
+    if (EC) {
+      errs() << EC.message() << '\n';
+      return 1;
+    }
+  }
+
   // Build up all of the passes that we want to do to the module.
   legacy::PassManager PM;
 
@@ -541,7 +557,9 @@ static int compileModule(char **argv, LL
       TPC.setInitialized();
       PM.add(createPrintMIRPass(*OS));
       PM.add(createFreeMachineFunctionPass());
-    } else if (Target->addPassesToEmitFile(PM, *OS, FileType, NoVerify, MMI)) {
+    } else if (Target->addPassesToEmitFile(PM, *OS,
+                                           DwoOut ? &DwoOut->os() : nullptr,
+                                           FileType, NoVerify, MMI)) {
       errs() << argv0 << ": target does not support generation of this"
              << " file type!\n";
       return 1;
@@ -598,6 +616,8 @@ static int compileModule(char **argv, LL
 
   // Declare success.
   Out->keep();
+  if (DwoOut)
+    DwoOut->keep();
 
   return 0;
 }

Modified: llvm/trunk/tools/llvm-exegesis/lib/Assembler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/Assembler.cpp?rev=332881&r1=332880&r2=332881&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/Assembler.cpp (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/Assembler.cpp Mon May 21 13:16:41 2018
@@ -167,8 +167,8 @@ void assembleToStream(std::unique_ptr<ll
   TPC->setInitialized();
 
   // AsmPrinter is responsible for generating the assembly into AsmBuffer.
-  if (TM->addAsmPrinter(PM, AsmStream, llvm::TargetMachine::CGFT_ObjectFile,
-                        MCContext))
+  if (TM->addAsmPrinter(PM, AsmStream, nullptr,
+                        llvm::TargetMachine::CGFT_ObjectFile, MCContext))
     llvm::report_fatal_error("Cannot add AsmPrinter passes");
 
   PM.run(*Module); // Run all the passes

Modified: llvm/trunk/tools/llvm-isel-fuzzer/llvm-isel-fuzzer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-isel-fuzzer/llvm-isel-fuzzer.cpp?rev=332881&r1=332880&r2=332881&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-isel-fuzzer/llvm-isel-fuzzer.cpp (original)
+++ llvm/trunk/tools/llvm-isel-fuzzer/llvm-isel-fuzzer.cpp Mon May 21 13:16:41 2018
@@ -99,7 +99,7 @@ extern "C" int LLVMFuzzerTestOneInput(co
   TargetLibraryInfoImpl TLII(TM->getTargetTriple());
   PM.add(new TargetLibraryInfoWrapperPass(TLII));
   raw_null_ostream OS;
-  TM->addPassesToEmitFile(PM, OS, TargetMachine::CGFT_Null);
+  TM->addPassesToEmitFile(PM, OS, nullptr, TargetMachine::CGFT_Null);
   PM.run(*M);
 
   return 0;




More information about the llvm-commits mailing list