[cfe-commits] Use enum to set size of debug info generated by Clang" (issue 6114059)

samsonov at google.com samsonov at google.com
Fri Apr 27 00:25:03 PDT 2012


Reviewers: echristo, chandlerc,

Message:
Commited as r155697, thank you!


http://codereview.appspot.com/6114059/diff/1/lib/CodeGen/CGClass.cpp
File lib/CodeGen/CGClass.cpp (right):

http://codereview.appspot.com/6114059/diff/1/lib/CodeGen/CGClass.cpp#newcode1231
lib/CodeGen/CGClass.cpp:1231: CodeGenOptions::LimitedDebugInfo) {
On 2012/04/26 17:10:54, chandlerc wrote:
> Style nit: wrap this in parens if you want unusual indentation like
this...

Done (moved CGM.getCodeGenOpts()... to next line).

http://codereview.appspot.com/6114059/diff/1/lib/CodeGen/CGExprScalar.cpp
File lib/CodeGen/CGExprScalar.cpp (right):

http://codereview.appspot.com/6114059/diff/1/lib/CodeGen/CGExprScalar.cpp#newcode805
lib/CodeGen/CGExprScalar.cpp:805: CodeGenOptions::LimitedDebugInfo) {
On 2012/04/26 17:10:54, chandlerc wrote:
> Same comment here.

ditto

http://codereview.appspot.com/6114059/diff/1/lib/CodeGen/CGExprScalar.cpp#newcode809
lib/CodeGen/CGExprScalar.cpp:809:
DI->getOrCreateRecordType(PTy->getPointeeType(),
On 2012/04/26 17:10:54, chandlerc wrote:
> Please try to avoid trimming trailing whitespace from lines you're not
> changing... I only see the two here in this file, but wanted to
mention it for
> future reference.

Ack.

http://codereview.appspot.com/6114059/diff/1/lib/Frontend/CompilerInvocation.cpp
File lib/Frontend/CompilerInvocation.cpp (right):

http://codereview.appspot.com/6114059/diff/1/lib/Frontend/CompilerInvocation.cpp#newcode1100
lib/Frontend/CompilerInvocation.cpp:1100:
Args.hasArg(OPT_flimit_debug_info))
On 2012/04/26 17:10:54, chandlerc wrote:
> There is a helper designed for this pattern: Args.hasFlag

Done.

Description:
This patch follows clattner's advice and introduces enum (instead of
bool flags) that defines the size of debug info generated by Clang. This
patch doesn't change the behavior and is a first step to introducing
-gline-tables-only flag
(http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20120423/056674.html).

Please review this at http://codereview.appspot.com/6114059/

Affected files:
   M     include/clang/Frontend/CodeGenOptions.h
   M     lib/CodeGen/BackendUtil.cpp
   M     lib/CodeGen/CGClass.cpp
   M     lib/CodeGen/CGDebugInfo.cpp
   M     lib/CodeGen/CGExprCXX.cpp
   M     lib/CodeGen/CGExprScalar.cpp
   M     lib/CodeGen/CodeGenModule.cpp
   M     lib/Frontend/CompilerInvocation.cpp


Index: include/clang/Frontend/CodeGenOptions.h
===================================================================
--- include/clang/Frontend/CodeGenOptions.h	(revision 155625)
+++ include/clang/Frontend/CodeGenOptions.h	(working copy)
@@ -35,6 +35,13 @@
      Mixed = 2
    };

+  enum DebugInfoKind {
+    NoDebugInfo,          // Don't generate debug info.
+    LimitedDebugInfo,     // Limit generated debug info to reduce size
+                          // (-flimit-debug-info).
+    FullDebugInfo         // Generate complete debug info.
+  };
+
    unsigned AsmVerbose        : 1; /// -dA, -fverbose-asm.
    unsigned ObjCAutoRefCountExceptions : 1; /// Whether ARC should be  
EH-safe.
    unsigned CUDAIsDevice      : 1; /// Set when compiling for CUDA device.
@@ -42,8 +49,6 @@
    unsigned CXXCtorDtorAliases: 1; /// Emit complete ctors/dtors as linker
                                    /// aliases to base ctors when possible.
    unsigned DataSections      : 1; /// Set when -fdata-sections is enabled
-  unsigned DebugInfo         : 1; /// Should generate debug info (-g).
-  unsigned LimitDebugInfo    : 1; /// Limit generated debug info to reduce  
size.
    unsigned DisableFPElim     : 1; /// Set when -fomit-frame-pointer is  
enabled.
    unsigned DisableLLVMOpts   : 1; /// Don't run any optimizations, for use  
in
                                    /// getting .bc files that correspond to  
the
@@ -127,6 +132,9 @@
    /// The string to embed in debug information as the current working  
directory.
    std::string DebugCompilationDir;

+  /// The kind of generated debug info.
+  DebugInfoKind DebugInfo;
+
    /// The string to embed in the debug information for the compile unit, if
    /// non-empty.
    std::string DwarfDebugFlags;
@@ -169,8 +177,6 @@
      CXAAtExit = 1;
      CXXCtorDtorAliases = 0;
      DataSections = 0;
-    DebugInfo = 0;
-    LimitDebugInfo = 0;
      DisableFPElim = 0;
      DisableLLVMOpts = 0;
      DisableRedZone = 0;
@@ -217,6 +223,7 @@
      StackRealignment = 0;
      StackAlignment = 0;

+    DebugInfo = NoDebugInfo;
      Inlining = NoInlining;
      RelocationModel = "pic";
    }
Index: lib/Frontend/CompilerInvocation.cpp
===================================================================
--- lib/Frontend/CompilerInvocation.cpp	(revision 155625)
+++ lib/Frontend/CompilerInvocation.cpp	(working copy)
@@ -181,8 +181,17 @@
  }

  static void CodeGenOptsToArgs(const CodeGenOptions &Opts, ToArgsList &Res)  
{
-  if (Opts.DebugInfo)
-    Res.push_back("-g");
+  switch (Opts.DebugInfo) {
+    case CodeGenOptions::NoDebugInfo:
+      break;
+    case CodeGenOptions::LimitedDebugInfo:
+      Res.push_back("-g");
+      Res.push_back("-flimit-debug-info");
+      break;
+    case CodeGenOptions::FullDebugInfo:
+      Res.push_back("-g");
+      break;
+  }
    if (Opts.DisableLLVMOpts)
      Res.push_back("-disable-llvm-optzns");
    if (Opts.DisableRedZone)
@@ -1083,12 +1092,17 @@
      : CodeGenOptions::OnlyAlwaysInlining;
    // -fno-inline-functions overrides OptimizationLevel > 1.
    Opts.NoInline = Args.hasArg(OPT_fno_inline);
-  Opts.Inlining = Args.hasArg(OPT_fno_inline_functions) ?
+  Opts.Inlining = Args.hasArg(OPT_fno_inline_functions) ?
      CodeGenOptions::OnlyAlwaysInlining : Opts.Inlining;

-  Opts.DebugInfo = Args.hasArg(OPT_g);
-  Opts.LimitDebugInfo = !Args.hasArg(OPT_fno_limit_debug_info)
-    || Args.hasArg(OPT_flimit_debug_info);
+  if (Args.hasArg(OPT_g)) {
+    if (!Args.hasArg(OPT_fno_limit_debug_info) ||
+        Args.hasArg(OPT_flimit_debug_info))
+      Opts.DebugInfo = CodeGenOptions::LimitedDebugInfo;
+    else
+      Opts.DebugInfo = CodeGenOptions::FullDebugInfo;
+  }
+
    Opts.DisableLLVMOpts = Args.hasArg(OPT_disable_llvm_optzns);
    Opts.DisableRedZone = Args.hasArg(OPT_disable_red_zone);
    Opts.ForbidGuardVariables = Args.hasArg(OPT_fforbid_guard_variables);
Index: lib/CodeGen/CGExprScalar.cpp
===================================================================
--- lib/CodeGen/CGExprScalar.cpp	(revision 155625)
+++ lib/CodeGen/CGExprScalar.cpp	(working copy)
@@ -798,14 +798,15 @@
      return Builder.getInt(Value);
    }

-  // Emit debug info for aggregate now, if it was delayed to reduce
+  // Emit debug info for aggregate now, if it was delayed to reduce
    // debug info size.
    CGDebugInfo *DI = CGF.getDebugInfo();
-  if (DI && CGF.CGM.getCodeGenOpts().LimitDebugInfo) {
+  if (DI && CGF.CGM.getCodeGenOpts().DebugInfo ==
+            CodeGenOptions::LimitedDebugInfo) {
      QualType PQTy = E->getBase()->IgnoreParenImpCasts()->getType();
      if (const PointerType * PTy = dyn_cast<PointerType>(PQTy))
        if (FieldDecl *M = dyn_cast<FieldDecl>(E->getMemberDecl()))
-        DI->getOrCreateRecordType(PTy->getPointeeType(),
+        DI->getOrCreateRecordType(PTy->getPointeeType(),
                                    M->getParent()->getLocation());
    }
    return EmitLoadOfLValue(E);
Index: lib/CodeGen/CodeGenModule.cpp
===================================================================
--- lib/CodeGen/CodeGenModule.cpp	(revision 155625)
+++ lib/CodeGen/CodeGenModule.cpp	(working copy)
@@ -110,7 +110,8 @@

    // If debug info or coverage generation is enabled, create the  
CGDebugInfo
    // object.
-  if (CodeGenOpts.DebugInfo || CodeGenOpts.EmitGcovArcs ||
+  if (CodeGenOpts.DebugInfo != CodeGenOptions::NoDebugInfo ||
+      CodeGenOpts.EmitGcovArcs ||
        CodeGenOpts.EmitGcovNotes)
      DebugInfo = new CGDebugInfo(*this);

Index: lib/CodeGen/CGExprCXX.cpp
===================================================================
--- lib/CodeGen/CGExprCXX.cpp	(revision 155625)
+++ lib/CodeGen/CGExprCXX.cpp	(working copy)
@@ -179,7 +179,7 @@
    const CXXMethodDecl *MD = cast<CXXMethodDecl>(ME->getMemberDecl());

    CGDebugInfo *DI = getDebugInfo();
-  if (DI && CGM.getCodeGenOpts().LimitDebugInfo
+  if (DI && CGM.getCodeGenOpts().DebugInfo ==  
CodeGenOptions::LimitedDebugInfo
        && !isa<CallExpr>(ME->getBase())) {
      QualType PQTy = ME->getBase()->IgnoreParenImpCasts()->getType();
      if (const PointerType * PTy = dyn_cast<PointerType>(PQTy)) {
Index: lib/CodeGen/CGDebugInfo.cpp
===================================================================
--- lib/CodeGen/CGDebugInfo.cpp	(revision 155625)
+++ lib/CodeGen/CGDebugInfo.cpp	(working copy)
@@ -546,7 +546,7 @@
  /// then emit record's fwd if debug info size reduction is enabled.
  llvm::DIType CGDebugInfo::CreatePointeeType(QualType PointeeTy,
                                              llvm::DIFile Unit) {
-  if (!CGM.getCodeGenOpts().LimitDebugInfo)
+  if (CGM.getCodeGenOpts().DebugInfo != CodeGenOptions::LimitedDebugInfo)
      return getOrCreateType(PointeeTy, Unit);

    // Limit debug info for the pointee type.
@@ -1823,7 +1823,7 @@
    StringRef RDName = RD->getName();

    llvm::DIDescriptor RDContext;
-  if (CGM.getCodeGenOpts().LimitDebugInfo)
+  if (CGM.getCodeGenOpts().DebugInfo == CodeGenOptions::LimitedDebugInfo)
      RDContext = createContextChain(cast<Decl>(RD->getDeclContext()));
    else
      RDContext = getContextDescriptor(cast<Decl>(RD->getDeclContext()));
Index: lib/CodeGen/CGClass.cpp
===================================================================
--- lib/CodeGen/CGClass.cpp	(revision 155625)
+++ lib/CodeGen/CGClass.cpp	(working copy)
@@ -1227,7 +1227,8 @@
                                          CallExpr::const_arg_iterator  
ArgEnd) {

    CGDebugInfo *DI = getDebugInfo();
-  if (DI && CGM.getCodeGenOpts().LimitDebugInfo) {
+  if (DI && CGM.getCodeGenOpts().DebugInfo ==
+            CodeGenOptions::LimitedDebugInfo) {
      // If debug info for this class has not been emitted then this is the
      // right time to do so.
      const CXXRecordDecl *Parent = D->getParent();
Index: lib/CodeGen/BackendUtil.cpp
===================================================================
--- lib/CodeGen/BackendUtil.cpp	(revision 155625)
+++ lib/CodeGen/BackendUtil.cpp	(working copy)
@@ -219,7 +219,7 @@
                                      CodeGenOpts.EmitGcovArcs,
                                      TargetTriple.isMacOSX()));

-    if (!CodeGenOpts.DebugInfo)
+    if (CodeGenOpts.DebugInfo == CodeGenOptions::NoDebugInfo)
        MPM->add(createStripSymbolsPass(true));
    }






More information about the cfe-commits mailing list