Index: clang/lib/CodeGen/BackendUtil.cpp =================================================================== --- clang/lib/CodeGen/BackendUtil.cpp +++ clang/lib/CodeGen/BackendUtil.cpp @@ -718,7 +718,7 @@ if (CodeGenOpts.OptimizationLevel > 0) CodeGenPasses.add(createObjCARCContractPass()); - if (TM->addPassesToEmitFile(CodeGenPasses, OS, CGFT, + if (TM->addPassesToEmitFile(CodeGenPasses, OS, nullptr, CGFT, /*DisableVerify=*/!CodeGenOpts.VerifyModule)) { Diags.Report(diag::err_fe_unable_to_interface_with_target); return false; Index: llvm/include/llvm/Target/TargetMachine.h =================================================================== --- llvm/include/llvm/Target/TargetMachine.h +++ llvm/include/llvm/Target/TargetMachine.h @@ -252,7 +252,7 @@ /// \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 @@ /// \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 @@ /// 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 Index: llvm/lib/CodeGen/LLVMTargetMachine.cpp =================================================================== --- llvm/lib/CodeGen/LLVMTargetMachine.cpp +++ llvm/lib/CodeGen/LLVMTargetMachine.cpp @@ -121,8 +121,10 @@ } 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 @@ Triple T(getTargetTriple().str()); AsmStreamer.reset(getTarget().createMCObjectStreamer( T, Context, std::unique_ptr(MAB), - MAB->createObjectWriter(Out), std::unique_ptr(MCE), STI, - Options.MCOptions.MCRelaxAll, + DwoOut ? MAB->createDwoObjectWriter(Out, *DwoOut) + : MAB->createObjectWriter(Out), + std::unique_ptr(MCE), STI, Options.MCOptions.MCRelaxAll, Options.MCOptions.MCIncrementalLinkerCompatible, /*DWARFMustBeAtTheEnd*/ true)); break; @@ -193,6 +196,7 @@ bool LLVMTargetMachine::addPassesToEmitFile(PassManagerBase &PM, raw_pwrite_stream &Out, + raw_pwrite_stream *DwoOut, CodeGenFileType FileType, bool DisableVerify, MachineModuleInfo *MMI) { @@ -203,7 +207,8 @@ if (!Context) return true; - if (WillCompleteCodeGenPipeline && addAsmPrinter(PM, Out, FileType, *Context)) + if (WillCompleteCodeGenPipeline && + addAsmPrinter(PM, Out, DwoOut, FileType, *Context)) return true; PM.add(createFreeMachineFunctionPass()); Index: llvm/lib/CodeGen/ParallelCG.cpp =================================================================== --- llvm/lib/CodeGen/ParallelCG.cpp +++ llvm/lib/CodeGen/ParallelCG.cpp @@ -30,7 +30,7 @@ TargetMachine::CodeGenFileType FileType) { std::unique_ptr 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); } Index: llvm/lib/LTO/LTOBackend.cpp =================================================================== --- llvm/lib/LTO/LTOBackend.cpp +++ llvm/lib/LTO/LTOBackend.cpp @@ -304,7 +304,7 @@ 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 @@ 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); } Index: llvm/lib/LTO/ThinLTOCodeGenerator.cpp =================================================================== --- llvm/lib/LTO/ThinLTOCodeGenerator.cpp +++ llvm/lib/LTO/ThinLTOCodeGenerator.cpp @@ -268,7 +268,7 @@ 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"); Index: llvm/lib/Target/TargetMachineC.cpp =================================================================== --- llvm/lib/Target/TargetMachineC.cpp +++ llvm/lib/Target/TargetMachineC.cpp @@ -196,7 +196,7 @@ 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; Index: llvm/test/CodeGen/X86/dwarf-headers.ll =================================================================== --- llvm/test/CodeGen/X86/dwarf-headers.ll +++ llvm/test/CodeGen/X86/dwarf-headers.ll @@ -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 +; O-4: .debug_info contents: +; O-4: 0x00000000: Compile Unit: {{.*}} version = 0x0004 abbr_offset +; O-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 +; DWO-4: .debug_info.dwo contents: +; DWO-4: 0x00000000: Compile Unit: {{.*}} version = 0x0004 abbr_offset +; DWO-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 +; 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 +; 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 ; -; 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 +; 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' Index: llvm/test/CodeGen/X86/dwarf-split-line-1.ll =================================================================== --- llvm/test/CodeGen/X86/dwarf-split-line-1.ll +++ llvm/test/CodeGen/X86/dwarf-split-line-1.ll @@ -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 Index: llvm/test/CodeGen/X86/dwarf-split-line-2.ll =================================================================== --- llvm/test/CodeGen/X86/dwarf-split-line-2.ll +++ llvm/test/CodeGen/X86/dwarf-split-line-2.ll @@ -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. Index: llvm/tools/llc/llc.cpp =================================================================== --- llvm/tools/llc/llc.cpp +++ llvm/tools/llc/llc.cpp @@ -66,6 +66,11 @@ static cl::opt OutputFilename("o", cl::desc("Output filename"), cl::value_desc("filename")); +static cl::opt + SplitDwarfOutputFile("split-dwarf-output", + cl::desc(".dwo output filename"), + cl::value_desc("filename")); + static cl::opt TimeCompilations("time-compilations", cl::Hidden, cl::init(1u), cl::value_desc("N"), @@ -463,6 +468,17 @@ GetOutputStream(TheTarget->getName(), TheTriple.getOS(), argv[0]); if (!Out) return 1; + std::unique_ptr DwoOut; + if (!SplitDwarfOutputFile.empty()) { + std::error_code EC; + DwoOut = llvm::make_unique(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 @@ 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 @@ // Declare success. Out->keep(); + if (DwoOut) + DwoOut->keep(); return 0; } Index: llvm/tools/llvm-exegesis/lib/Assembler.cpp =================================================================== --- llvm/tools/llvm-exegesis/lib/Assembler.cpp +++ llvm/tools/llvm-exegesis/lib/Assembler.cpp @@ -167,8 +167,8 @@ 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 Index: llvm/tools/llvm-isel-fuzzer/llvm-isel-fuzzer.cpp =================================================================== --- llvm/tools/llvm-isel-fuzzer/llvm-isel-fuzzer.cpp +++ llvm/tools/llvm-isel-fuzzer/llvm-isel-fuzzer.cpp @@ -99,7 +99,7 @@ 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; Index: polly/lib/CodeGen/PPCGCodeGeneration.cpp =================================================================== --- polly/lib/CodeGen/PPCGCodeGeneration.cpp +++ polly/lib/CodeGen/PPCGCodeGeneration.cpp @@ -2369,8 +2369,9 @@ PM.add(createTargetTransformInfoWrapperPass(TargetM->getTargetIRAnalysis())); - if (TargetM->addPassesToEmitFile( - PM, ASMStream, TargetMachine::CGFT_AssemblyFile, true /* verify */)) { + if (TargetM->addPassesToEmitFile(PM, ASMStream, nullptr, + TargetMachine::CGFT_AssemblyFile, + true /* verify */)) { errs() << "The target does not support generation of this file type!\n"; return ""; }