[LLVMdev] Marking a function prototype as being "persistent"

Duncan Sands baldrick at free.fr
Thu Jan 6 16:00:53 PST 2011


Hi Christophe,

>>> Apparently, this depends on the oddly-named UnitAtATime parameter. Set it to false. Try again. Suggestion: what about a comment explaining what "UnitAtATime" means :-)
>>
>> If UnitAtATime is false this means that you are optimizing functions as you are
>> generating them, rather than first generating all functions and other globals
>> and only then optimizing.  It's basically a historical anachronism coming from
>> the way GCC used to work.
>
> Thanks for explaining.
>
> Why not redefine it from historical anachronism to architectural flag, that indicates you may generate more code with the same functions and globals later? And then, you could pass the same flag to createStandardLTOPasses, and that would skip the GlobalDCE passes.

LTO is for doing optimizations that are only valid when the module contains
everything that is needed to build the final executable.  So adding a flag to
say "not everything is there after all" makes no sense to me.

>>> Even then, my runtime function prorotypes are still being stripped away by the GlobalDCE added by createStandardLTOPasses.
>>
>> Sure, and why not?  Unused prototypes are not used for anything, they won't
>> turn up in the generated code for example.
>
> They are not used this time. But why can't I generate additional code in the same module after having run LTO?

Because by definition LTO is for when everything is there!  Why don't you
create your own sequence of passes that does what you want rather than calling
createStandardLTOPasses?  One of the nice features of LLVM is that you can
run any passes you choose in any order you like.  That said, probably the reason
you are getting improved optimization is due to running the "internalize" pass.
If so be warned that it is not safe to run internalize unless all functions and
their bodies are present in the module.  If you run internalize, optimize, and
then later add a few more functions to the module all kinds of nasty subtle
things can go wrong, not just those you saw with GlobalDCE.

Ciao, Duncan.



More information about the llvm-dev mailing list