[patch] opt: Initialize asm printers to avoid DCE

Tobias Grosser tobias at grosser.es
Tue Jun 10 00:46:45 PDT 2014

On 28/05/2014 00:46, Chandler Carruth wrote:
> On Tue, May 27, 2014 at 3:36 PM, Tobias Grosser <tobias at grosser.es> wrote:
>> Right, I believe dumping asm e.g. to do some kind of code-size or register
>> allocation auto-tuning might also be interesting. However, many of such use
>> case may be more interesting for experiments or debugging that for actual
>> production work.
>> Was this some kind of 'LGTM' or would you like to have further discussions
>> on this topic?
> This was an LGTM for the idea of keeping the asm printers (and any other
> useful LLVM libraries for plugins) live and available in the opt binary. I
> haven't looked at the patch, but I don't really see any risks or downsides
> to making plugins able to do cool things or even crazy things. If the patch
> looks good to someone, carry on.

Rafael, you looked at this patch. In the context of Chandlers comments 
and no further feedback from Reid, do you think it looks good?


-------------- next part --------------
>From 2a2c58518446da43c23a3263244d056f6cdd0fca Mon Sep 17 00:00:00 2001
From: Tobias Grosser <tobias at grosser.es>
Date: Thu, 15 May 2014 08:33:53 +0200
Subject: [PATCH] opt: Initialize asm printers

Without initializing the assembly printers a shared library build of opt is
linked with these libraries whereas for a static build these libraries are dead
code eliminated. This is unfortunate for plugins in case they want to use them,
as they neither can rely on opt to provide this functionality nor can they link
the printers in themselves as this breaks with a shared object build of opt.

This patch calls InitializeAllAsmPrinters() from opt, which increases the static
binary size from 50MB -> 52MB on my system (all backends compiled) and causes no
measurable increase in the time needed to run 'make check'.
 tools/opt/opt.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp
index 6f0fbf6..6ba6340 100644
--- a/tools/opt/opt.cpp
+++ b/tools/opt/opt.cpp
@@ -336,6 +336,7 @@ int main(int argc, char **argv) {
+  InitializeAllAsmPrinters();
   // Initialize passes
   PassRegistry &Registry = *PassRegistry::getPassRegistry();

More information about the llvm-commits mailing list