[patch] opt: Initialize asm printers to avoid DCE

Tobias Grosser tobias at grosser.es
Tue May 27 15:17:12 PDT 2014


On 21/05/2014 06:57, Rafael EspĂ­ndola wrote:
>> Right. This could probably be "fixed" but it seems the improvements in terms
>> of code size are rather small.
>>
>>
>>> What is the plugin doing with the asm printer? Could it plugin in llc?
>>
>>
>> It is a LLVM-IR optimizer that extracts parts of the LLVM IR, translates
>> them to PTX, stores the PTX in a global variable and generates calls to the
>> CUDA run-time to load and run this code instead of the original code.
>>
>> Do you think it would be better to immediately restructure opt's linking to
>> not link the asm printers? I looked into this briefly, but it seems to be a
>> larger refactoring that adds a lot of complexity.
>
> I am honestly not sure. There were some discussions about what should
> be in opt or in llc in the future. I remember proposals ranging from
> opt not linking to CodeGen to just merging the two. I don't have a
> strong opinion on the direction, but it would be nice to know that
> this patch is pointing the right way.
>
> Chandler, do you know what the current consensus is?

Copying Nadav.

Nadav, it seem you added the target dependences to 'opt'. Could you have 
a look at the following issue and my proposed solution?

The problem is that since your patch, opt links to the assembly 
printers, but only in case LLVM is built with BUILD_SHARED_LIBS. 
Otherwise this library is dead code eliminated. This causes 
inconsistencies that cause trouble when testing LLVM modules that
would like to use this functionality.

Here a proposed solution:

"To avoid dead code elimination of the assembly printers, this patch 
calls InitializeAllAsmPrinters() from opt. This increases the static 
binary size of 'opt' from 50MB -> 52MB on my system (all backends 
compiled) and causes no measurable increase in the time needed to run 
'make check'.

Without initialising 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 problematic for plugins
that use assembly printers, 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.

As the impact is rather minor and for platforms where even a tiny binary 
size increase matters 'opt' is commonly not provided, I don't expect any 
problems. Still, I would like to ask for other opinions."

Thanks,
Tobias
-------------- 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) {
 
   InitializeAllTargets();
   InitializeAllTargetMCs();
+  InitializeAllAsmPrinters();
 
   // Initialize passes
   PassRegistry &Registry = *PassRegistry::getPassRegistry();
-- 
1.8.3.2



More information about the llvm-commits mailing list