[PATCH] D40508: Replace long type names in IR with hashes

Serge Pavlov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Nov 27 10:00:13 PST 2017


sepavloff created this revision.
Herald added a subscriber: JDevlieghere.

If a source file extensively uses templates, resulting LLVM IR may have
types with huge names. It may occur if a record type is defined in a class.
In this case its type name contains all declaration contexts and, if a
declaration context is a class specialization, it is specified with
template parameters.

This change implements transformation of long IR type names. If name length
exceeds some limit, it is truncated and SHA1 hash of its full name is
appended to the obtained abbreviated name. Such solution could reduce memory
footprint and still keep names usable for identification.

To implement this algorithm functions PrintTemplateArgumentList were changed.
They try to make their output a valid C++ code. For this purpose they ensure
that digraph '<:' and tokens '>>' are not formed by inserting space between
characters. The implementation prints template arguments into a separate
stream and then put its content into 'uplevel' stream adding space before
and/or after the text if necessary. Such implementation prevents from using
special stream implementations because the intermediate stream is always of
the same type. To cope with this problem, a new flag in PrintingPolicy is
introduced, which turns off checks for undesirable character sequences. In
this case the intermediate stream becomes unneeded and printing occurs into
the same stream.


https://reviews.llvm.org/D40508

Files:
  include/clang/AST/PrettyPrinter.h
  include/clang/AST/Type.h
  lib/AST/ASTContext.cpp
  lib/AST/Decl.cpp
  lib/AST/DeclTemplate.cpp
  lib/AST/NestedNameSpecifier.cpp
  lib/AST/StmtPrinter.cpp
  lib/AST/TypePrinter.cpp
  lib/CodeGen/CGDebugInfo.cpp
  lib/CodeGen/CodeGenTypes.cpp
  lib/Sema/SemaTemplateInstantiate.cpp
  test/CodeGenCXX/template-types.cpp
  tools/libclang/CIndex.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D40508.124413.patch
Type: text/x-patch
Size: 24166 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171127/439f9bb8/attachment-0001.bin>


More information about the cfe-commits mailing list