[PATCH] D30904: Allow suppressing host and target info in VersionPrinter

Peter Ammon via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 13 11:19:45 PDT 2017


pammon created this revision.

VersionPrinter by default outputs information about the Host CPU
and Default target. Printing this information requires linking in
a large amount of data, such as supported target triples (as C
strings), which in turn bloats the binary size.

Enable a new CMake define LLVM_VERSION_PRINTER_NO_HOST_TARGET_INFO
which suppresses printing of the host and target info. This allows
the target triple names to be dead-code stripped. This is a nice
win for LLVM clients that wish to minimize their binary size, such
as graphics drivers.

A test app on Linux that uses ParseCommandLineOptions() shows a binary
size reduction of 23KB (from 149K to 126K) for a Release build, and 24KB
(from 135K to 111K) in a MinSizeRel build.


Repository:
  rL LLVM

https://reviews.llvm.org/D30904

Files:
  include/llvm/Config/config.h.cmake
  lib/Support/CommandLine.cpp


Index: lib/Support/CommandLine.cpp
===================================================================
--- lib/Support/CommandLine.cpp
+++ lib/Support/CommandLine.cpp
@@ -2072,12 +2072,15 @@
 #ifndef NDEBUG
     OS << " with assertions";
 #endif
+#ifndef LLVM_VERSION_PRINTER_NO_HOST_TARGET_INFO
     std::string CPU = sys::getHostCPUName();
     if (CPU == "generic")
       CPU = "(unknown)";
     OS << ".\n"
        << "  Default target: " << sys::getDefaultTargetTriple() << '\n'
-       << "  Host CPU: " << CPU << '\n';
+       << "  Host CPU: " << CPU;
+#endif
+    OS << '\n';
   }
   void operator=(bool OptionWasSpecified) {
     if (!OptionWasSpecified)
Index: include/llvm/Config/config.h.cmake
===================================================================
--- include/llvm/Config/config.h.cmake
+++ include/llvm/Config/config.h.cmake
@@ -435,4 +435,8 @@
 /* Define to a function implementing strdup */
 #cmakedefine strdup ${strdup}
 
+/* Define to 1 to disable printing target and host info in the VersionPrinter,
+   which can reduce your binary size. */
+#cmakedefine LLVM_VERSION_PRINTER_NO_HOST_TARGET_INFO ${LLVM_VERSION_PRINTER_NO_HOST_TARGET_INFO}
+
 #endif


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30904.91595.patch
Type: text/x-patch
Size: 1186 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170313/0c8c410a/attachment.bin>


More information about the llvm-commits mailing list