[PATCH] D123534: [dwarf] Emit a DIGlobalVariable for constant strings.

Mitch Phillips via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 21 13:31:10 PDT 2022

hctim added a comment.

I just did an experiment with the following patch that punts everything to `const char*` types to try and get better folding onto a single type:

The change didn't make a significant difference, with the clang binary size of 1263433512 (126384B reduction, or 1.224% -> 1.214%). I think it's better to keep the extra size diagnostic.

  diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
  index f82c0e357bc3..175a5fec2989 100644
  --- a/clang/lib/CodeGen/CGDebugInfo.cpp
  +++ b/clang/lib/CodeGen/CGDebugInfo.cpp
  @@ -5454,11 +5454,23 @@ void CGDebugInfo::AddStringLiteralDebugInfo(llvm::GlobalVariable *GV,
     if (!PLoc.isValid())
  +  // Official type of the StringLiteral is `char[N]`. This means for each
  +  // compilation unit, we have multiple DW_*_type entries, one set for each size
  +  // of constant string. This level of precision isn't necessary, so simply
  +  // synthesize a `const char*` type so it can be reused across all constant
  +  // strings.
  +  const auto &Context = CGM.getContext();
  +  QualType Type = Context.CharTy;
  +  Type.addConst();
  +  Type = Context.getPointerType(Type);
  +  // Similar to above, elide the name variables (as there isn't really anything
  +  // useful we can add) to save binary size.
     llvm::DIFile *File = getOrCreateFile(Loc);
     llvm::DIGlobalVariableExpression *Debug =
             nullptr, StringRef(), StringRef(), getOrCreateFile(Loc),
  -          getLineNumber(Loc), getOrCreateType(S->getType(), File), true);
  +          getLineNumber(Loc), getOrCreateType(Type, File), true);

  rG LLVM Github Monorepo



More information about the cfe-commits mailing list