Index: llvm/include/llvm/CodeGen/MachineModuleInfo.h =================================================================== --- llvm/include/llvm/CodeGen/MachineModuleInfo.h +++ llvm/include/llvm/CodeGen/MachineModuleInfo.h @@ -186,7 +186,6 @@ /// Returns true if valid debug info is present. bool hasDebugInfo() const { return DbgInfoAvailable; } - void setDebugInfoAvailability(bool avail) { DbgInfoAvailable = avail; } bool usesMorestackAddr() const { return UsesMorestackAddr; Index: llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp =================================================================== --- llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -126,11 +126,6 @@ #define DEBUG_TYPE "asm-printer" -// FIXME: this option currently only applies to DWARF, and not CodeView, tables -static cl::opt - DisableDebugInfoPrinting("disable-debug-info-print", cl::Hidden, - cl::desc("Disable debug info printing")); - const char DWARFGroupName[] = "dwarf"; const char DWARFGroupDescription[] = "DWARF Emission"; const char DbgTimerName[] = "emit"; @@ -274,9 +269,6 @@ OutStreamer->initSections(false, *TM.getMCSubtargetInfo()); - if (DisableDebugInfoPrinting) - MMI->setDebugInfoAvailability(false); - // Emit the version-min deployment target directive if needed. // // FIXME: If we end up with a collection of these sorts of Darwin-specific @@ -344,7 +336,7 @@ CodeViewLineTablesGroupDescription); } if (!EmitCodeView || M.getDwarfVersion()) { - if (!DisableDebugInfoPrinting) { + if (MMI->hasDebugInfo()) { DD = new DwarfDebug(this); Handlers.emplace_back(std::unique_ptr(DD), DbgTimerName, DbgTimerDescription, DWARFGroupName, Index: llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp =================================================================== --- llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp +++ llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp @@ -608,18 +608,16 @@ void CodeViewDebug::beginModule(Module *M) { // If module doesn't have named metadata anchors or COFF debug section // is not available, skip any debug info related stuff. - NamedMDNode *CUs = M->getNamedMetadata("llvm.dbg.cu"); - if (!CUs || !Asm->getObjFileLowering().getCOFFDebugSymbolsSection()) { + if (!MMI->hasDebugInfo() || + !Asm->getObjFileLowering().getCOFFDebugSymbolsSection()) { Asm = nullptr; return; } - // Tell MMI that we have and need debug info. - MMI->setDebugInfoAvailability(true); TheCPU = mapArchToCVCPUType(Triple(M->getTargetTriple()).getArch()); // Get the current source language. - const MDNode *Node = *CUs->operands().begin(); + const MDNode *Node = *M->debug_compile_units_begin(); const auto *CU = cast(Node); CurrentSourceLanguage = MapDWLangToCVLang(CU->getSourceLanguage()); Index: llvm/lib/CodeGen/MachineModuleInfo.cpp =================================================================== --- llvm/lib/CodeGen/MachineModuleInfo.cpp +++ llvm/lib/CodeGen/MachineModuleInfo.cpp @@ -24,6 +24,7 @@ #include "llvm/MC/MCSymbol.h" #include "llvm/Pass.h" #include "llvm/Support/Casting.h" +#include "llvm/Support/CommandLine.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Target/TargetLoweringObjectFile.h" #include "llvm/Target/TargetMachine.h" @@ -36,6 +37,10 @@ using namespace llvm; using namespace llvm::dwarf; +static cl::opt + DisableDebugInfoPrinting("disable-debug-info-print", cl::Hidden, + cl::desc("Disable debug info printing")); + // Out of line virtual method. MachineModuleInfoImpl::~MachineModuleInfoImpl() = default; @@ -195,6 +200,7 @@ NextFnNum = 0; UsesMorestackAddr = false; AddrLabelSymbols = nullptr; + DbgInfoAvailable = false; } void MachineModuleInfo::finalize() { @@ -401,7 +407,8 @@ Ctx.diagnose( DiagnosticInfoSrcMgr(SMD, M.getName(), IsInlineAsm, LocCookie)); }); - MMI.DbgInfoAvailable = !M.debug_compile_units().empty(); + MMI.DbgInfoAvailable = !DisableDebugInfoPrinting && + !M.debug_compile_units().empty(); return false; } @@ -416,6 +423,7 @@ ModuleAnalysisManager &) { MachineModuleInfo MMI(TM); MMI.TheModule = &M; - MMI.DbgInfoAvailable = !M.debug_compile_units().empty(); + MMI.DbgInfoAvailable = !DisableDebugInfoPrinting && + !M.debug_compile_units().empty(); return MMI; } Index: llvm/test/CodeGen/X86/disable-debug-info-print-codeview.ll =================================================================== --- /dev/null +++ llvm/test/CodeGen/X86/disable-debug-info-print-codeview.ll @@ -0,0 +1,19 @@ +; RUN: llc -disable-debug-info-print -o - %s | FileCheck %s + +; Check that debug info isn't emitted for CodeView with +; -disable-debug-info-print. + +; CHECK-NOT: CodeViewTypes +; CHECK-NOT: CodeViewDebugInfo + +source_filename = "empty" +target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-pc-windows-msvc19.0.24215" + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!2, !3} + +!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "clang", emissionKind: FullDebug) +!1 = !DIFile(filename: "empty", directory: "path/to") +!2 = !{i32 2, !"CodeView", i32 1} +!3 = !{i32 2, !"Debug Info Version", i32 3} Index: llvm/test/DebugInfo/COFF/emission-kind-no-debug.ll =================================================================== --- /dev/null +++ llvm/test/DebugInfo/COFF/emission-kind-no-debug.ll @@ -0,0 +1,17 @@ +; RUN: llc -filetype=obj -o - < %s | llvm-readobj --codeview - | FileCheck %s +; Check that debug info isn't emitted for CodeView with emissionKind NoDebug + +; CHECK-NOT: CodeViewTypes +; CHECK-NOT: CodeViewDebugInfo + +source_filename = "empty" +target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-pc-windows-msvc19.0.24215" + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!2, !3} + +!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "clang", emissionKind: NoDebug) +!1 = !DIFile(filename: "empty", directory: "path/to") +!2 = !{i32 2, !"CodeView", i32 1} +!3 = !{i32 2, !"Debug Info Version", i32 3} Index: llvm/test/DebugInfo/COFF/language.ll =================================================================== --- llvm/test/DebugInfo/COFF/language.ll +++ llvm/test/DebugInfo/COFF/language.ll @@ -64,7 +64,7 @@ !llvm.dbg.cu = !{!0} !llvm.module.flags = !{!2, !3} -!0 = distinct !DICompileUnit(language: , file: !1, producer: "clang") +!0 = distinct !DICompileUnit(language: , file: !1, producer: "clang", emissionKind: FullDebug) !1 = !DIFile(filename: "empty", directory: "path/to") !2 = !{i32 2, !"CodeView", i32 1} !3 = !{i32 2, !"Debug Info Version", i32 3}