Index: include/llvm/IR/Module.h =================================================================== --- include/llvm/IR/Module.h +++ include/llvm/IR/Module.h @@ -726,6 +726,9 @@ /// @name Utility functions for querying Debug information. /// @{ + /// \brief Returns whether emit debug info for profiling. + bool getDebugInfoForProfiling() const; + /// \brief Returns the Dwarf Version by checking module flags. unsigned getDwarfVersion() const; Index: lib/CodeGen/AsmPrinter/DwarfDebug.h =================================================================== --- lib/CodeGen/AsmPrinter/DwarfDebug.h +++ lib/CodeGen/AsmPrinter/DwarfDebug.h @@ -263,6 +263,9 @@ bool HasAppleExtensionAttributes; bool HasSplitDwarf; + /// Emit debug info for profiling + bool HasDebugInfoForProfiling; + /// Separated Dwarf Variables /// In general these will all be for bits that are left in the /// original object file, rather than things that are meant @@ -513,6 +516,9 @@ /// split dwarf proposal support. bool useSplitDwarf() const { return HasSplitDwarf; } + /// Returns whether or not to emit debug info for profiling. + bool useDebugInfoForProfiling() const { return HasDebugInfoForProfiling; } + /// Returns the Dwarf Version. uint16_t getDwarfVersion() const; Index: lib/CodeGen/AsmPrinter/DwarfDebug.cpp =================================================================== --- lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -245,6 +245,8 @@ else HasSplitDwarf = SplitDwarf == Enable; + HasDebugInfoForProfiling = M->getDebugInfoForProfiling(); + // Pubnames/pubtypes on by default for GDB. if (DwarfPubSections == Default) HasDwarfPubSections = tuneForGDB(); @@ -1213,7 +1215,7 @@ // Under -gmlt, skip building the subprogram if there are no inlined // subroutines inside it. But with -fdebug-info-for-profiling, the subprogram // is still needed as we need its source location. - if (!Asm->TM.Options.DebugInfoForProfiling && + if (!HasDebugInfoForProfiling && TheCU.getCUNode()->getEmissionKind() == DICompileUnit::LineTablesOnly && LScopes.getAbstractScopesList().empty() && !IsDarwin) { assert(InfoHolder.getScopeVariables().empty()); Index: lib/CodeGen/AsmPrinter/DwarfUnit.cpp =================================================================== --- lib/CodeGen/AsmPrinter/DwarfUnit.cpp +++ lib/CodeGen/AsmPrinter/DwarfUnit.cpp @@ -1184,7 +1184,7 @@ // If -fdebug-info-for-profiling is enabled, need to emit the subprogram // and its source location. bool SkipSPSourceLocation = SkipSPAttributes && - !Asm->TM.Options.DebugInfoForProfiling; + !DD->useDebugInfoForProfiling(); if (!SkipSPSourceLocation) if (applySubprogramDefinitionAttributes(SP, SPDie)) return; Index: lib/IR/Module.cpp =================================================================== --- lib/IR/Module.cpp +++ lib/IR/Module.cpp @@ -465,6 +465,14 @@ GIF.dropAllReferences(); } +bool Module::getDebugInfoForProfiling() const { + auto *Val = + cast_or_null(getModuleFlag("DebugInfoForProfiling")); + if (!Val) + return false; + return cast(Val->getValue())->getZExtValue(); +} + unsigned Module::getDwarfVersion() const { auto *Val = cast_or_null(getModuleFlag("Dwarf Version")); if (!Val) Index: test/DebugInfo/Generic/gmlt.test =================================================================== --- test/DebugInfo/Generic/gmlt.test +++ test/DebugInfo/Generic/gmlt.test @@ -1,6 +1,6 @@ ; REQUIRES: object-emission ; RUN: %llc_dwarf -O0 -filetype=obj < %S/../Inputs/gmlt.ll | llvm-dwarfdump - | FileCheck %S/../Inputs/gmlt.ll -; RUN: %llc_dwarf -O0 -filetype=obj -debug-info-for-profiling < %S/../Inputs/gmlt.ll | llvm-dwarfdump - | FileCheck %S/../Inputs/gmlt.ll --check-prefixes=PROFILING +; RUN: %llc_dwarf -O0 -filetype=obj < %S/../Inputs/gmlt_profiling.ll | llvm-dwarfdump - | FileCheck %S/../Inputs/gmlt_profiling.ll ; There's a darwin specific test in X86/gmlt, so it's okay to XFAIL this here. ; XFAIL: darwin Index: test/DebugInfo/Inputs/gmlt.ll =================================================================== --- test/DebugInfo/Inputs/gmlt.ll +++ test/DebugInfo/Inputs/gmlt.ll @@ -76,13 +76,6 @@ ; CHECK-NOT: {{DW_TAG|DW_AT}} ; CHECK: NULL -; PROFILING: DW_TAG_subprogram -; PROFILING: DW_AT_name {{.*}} "f1" -; With -debug-info-for-profiling, we need to emit decl_file a-nd decl_line -; of the subprogram. -; PROFILING: DW_AT_decl_file -; PROFILING: DW_AT_decl_line - ; CHECK: .debug_ranges contents: ; ... some addresses (depends on platform (such as platforms with function Index: test/DebugInfo/Inputs/gmlt_profiling.ll =================================================================== --- /dev/null +++ test/DebugInfo/Inputs/gmlt_profiling.ll @@ -0,0 +1,30 @@ +; REQUIRES: object-emission + +; CHECK: DW_TAG_subprogram +; CHECK: DW_AT_name {{.*}} "f1" +; With debug-info-for-profiling attribute, we need to emit decl_file and +; decl_line of the subprogram. +; CHECK-NEXT: DW_AT_decl_file +; CHECK-NEXT: DW_AT_decl_line + +; Function Attrs: nounwind uwtable +define void @_Z2f1v() !dbg !4 { +entry: + ret void, !dbg !14 +} + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!10, !11, !12} +!llvm.ident = !{!13} + +!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, producer: "clang version 3.6.0 ", isOptimized: false, emissionKind: LineTablesOnly, file: !1, enums: !2, retainedTypes: !2, globals: !2, imports: !2) +!1 = !DIFile(filename: "gmlt.cpp", directory: "/tmp/dbginfo") +!2 = !{} +!4 = distinct !DISubprogram(name: "f1", line: 1, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !0, scopeLine: 1, file: !1, scope: !5, type: !6, variables: !2) +!5 = !DIFile(filename: "gmlt.cpp", directory: "/tmp/dbginfo") +!6 = !DISubroutineType(types: !2) +!10 = !{i32 2, !"Dwarf Version", i32 4} +!11 = !{i32 2, !"Debug Info Version", i32 3} +!12 = !{i32 2, !"DebugInfoForProfiling", i32 1} +!13 = !{!"clang version 3.6.0 "} +!14 = !DILocation(line: 1, column: 12, scope: !4)