diff options
-rw-r--r-- | llvm/include/llvm/Target/TargetOptions.h | 8 | ||||
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp | 6 | ||||
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp | 15 | ||||
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h | 2 | ||||
-rw-r--r-- | llvm/lib/Target/TargetMachine.cpp | 6 | ||||
-rw-r--r-- | llvm/test/DebugInfo/Generic/gmlt.test | 1 | ||||
-rw-r--r-- | llvm/test/DebugInfo/Inputs/gmlt.ll | 6 |
7 files changed, 34 insertions, 10 deletions
diff --git a/llvm/include/llvm/Target/TargetOptions.h b/llvm/include/llvm/Target/TargetOptions.h index f5134d99b03..f73afb4706e 100644 --- a/llvm/include/llvm/Target/TargetOptions.h +++ b/llvm/include/llvm/Target/TargetOptions.h @@ -108,7 +108,7 @@ namespace llvm { DisableIntegratedAS(false), CompressDebugSections(false), RelaxELFRelocations(false), FunctionSections(false), DataSections(false), UniqueSectionNames(true), TrapUnreachable(false), - EmulatedTLS(false), EnableIPRA(false), + EmulatedTLS(false), EnableIPRA(false), DebugInfoForProfiling(false), FloatABIType(FloatABI::Default), AllowFPOpFusion(FPOpFusion::Standard), ThreadModel(ThreadModel::POSIX), @@ -225,6 +225,9 @@ namespace llvm { /// This flag enables InterProcedural Register Allocation (IPRA). unsigned EnableIPRA : 1; + /// This flag enables emitting extra debug info for sample profiling. + unsigned DebugInfoForProfiling : 1; + /// FloatABIType - This setting is set by -float-abi=xxx option is specfied /// on the command line. This setting may either be Default, Soft, or Hard. /// Default selects the target's default behavior. Soft selects the ABI for @@ -299,7 +302,8 @@ inline bool operator==(const TargetOptions &LHS, ARE_EQUAL(FPDenormalMode) && ARE_EQUAL(ExceptionModel) && ARE_EQUAL(MCOptions) && - ARE_EQUAL(EnableIPRA); + ARE_EQUAL(EnableIPRA) && + ARE_EQUAL(DebugInfoForProfiling); #undef ARE_EQUAL } diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp index b465b98f368..8e2f4f2551a 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp @@ -1211,8 +1211,10 @@ void DwarfDebug::endFunction(const MachineFunction *MF) { TheCU.addRange(RangeSpan(Asm->getFunctionBegin(), Asm->getFunctionEnd())); // Under -gmlt, skip building the subprogram if there are no inlined - // subroutines inside it. - if (TheCU.getCUNode()->getEmissionKind() == DICompileUnit::LineTablesOnly && + // 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 && + TheCU.getCUNode()->getEmissionKind() == DICompileUnit::LineTablesOnly && LScopes.getAbstractScopesList().empty() && !IsDarwin) { assert(InfoHolder.getScopeVariables().empty()); assert(DbgValues.empty()); diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp index 2a866c071f5..4269bb672a9 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp @@ -1180,8 +1180,12 @@ bool DwarfUnit::applySubprogramDefinitionAttributes(const DISubprogram *SP, } void DwarfUnit::applySubprogramAttributes(const DISubprogram *SP, DIE &SPDie, - bool Minimal) { - if (!Minimal) + bool SkipSPAttributes) { + // If -fdebug-info-for-profiling is enabled, need to emit the subprogram + // and its source location. + bool SkipSPSourceLocation = SkipSPAttributes && + !Asm->TM.Options.DebugInfoForProfiling; + if (!SkipSPSourceLocation) if (applySubprogramDefinitionAttributes(SP, SPDie)) return; @@ -1189,12 +1193,13 @@ void DwarfUnit::applySubprogramAttributes(const DISubprogram *SP, DIE &SPDie, if (!SP->getName().empty()) addString(SPDie, dwarf::DW_AT_name, SP->getName()); + if (!SkipSPSourceLocation) + addSourceLine(SPDie, SP); + // Skip the rest of the attributes under -gmlt to save space. - if (Minimal) + if (SkipSPAttributes) return; - addSourceLine(SPDie, SP); - // Add the prototype if we have a prototype and we have a C like // language. uint16_t Language = getLanguage(); diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h index 8654d6f0caf..a4646eca7a6 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.h @@ -256,7 +256,7 @@ public: DIE *getOrCreateSubprogramDIE(const DISubprogram *SP, bool Minimal = false); void applySubprogramAttributes(const DISubprogram *SP, DIE &SPDie, - bool Minimal = false); + bool SkipSPAttributes = false); /// Find existing DIE or create new DIE for the given type. DIE *getOrCreateTypeDIE(const MDNode *N); diff --git a/llvm/lib/Target/TargetMachine.cpp b/llvm/lib/Target/TargetMachine.cpp index f2c30a583e1..2b3f282f363 100644 --- a/llvm/lib/Target/TargetMachine.cpp +++ b/llvm/lib/Target/TargetMachine.cpp @@ -35,6 +35,10 @@ cl::opt<bool> EnableIPRA("enable-ipra", cl::init(false), cl::Hidden, cl::desc("Enable interprocedural register allocation " "to reduce load/store at procedure calls.")); +cl::opt<bool> DebugInfoForProfiling( + "debug-info-for-profiling", cl::init(false), cl::Hidden, + cl::desc("Emit extra debug info to make sample profile more accurate.")); + //--------------------------------------------------------------------------- // TargetMachine Class // @@ -47,6 +51,8 @@ TargetMachine::TargetMachine(const Target &T, StringRef DataLayoutString, RequireStructuredCFG(false), DefaultOptions(Options), Options(Options) { if (EnableIPRA.getNumOccurrences()) this->Options.EnableIPRA = EnableIPRA; + if (DebugInfoForProfiling.getNumOccurrences()) + this->Options.DebugInfoForProfiling = DebugInfoForProfiling; } TargetMachine::~TargetMachine() { diff --git a/llvm/test/DebugInfo/Generic/gmlt.test b/llvm/test/DebugInfo/Generic/gmlt.test index e36a3bdea35..d098d1e9125 100644 --- a/llvm/test/DebugInfo/Generic/gmlt.test +++ b/llvm/test/DebugInfo/Generic/gmlt.test @@ -1,5 +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 ; There's a darwin specific test in X86/gmlt, so it's okay to XFAIL this here. ; XFAIL: darwin diff --git a/llvm/test/DebugInfo/Inputs/gmlt.ll b/llvm/test/DebugInfo/Inputs/gmlt.ll index dc02e77909f..b6df50109ff 100644 --- a/llvm/test/DebugInfo/Inputs/gmlt.ll +++ b/llvm/test/DebugInfo/Inputs/gmlt.ll @@ -76,6 +76,12 @@ ; 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: |