[LLVMdev] Function code size estimation

Kenneth Uildriks kennethuil at gmail.com
Fri Jun 4 08:06:48 PDT 2010


On Fri, Jun 4, 2010 at 8:59 AM, Gregory Petrosyan
<gregory.petrosyan at gmail.com> wrote:
> On Fri, Jun 4, 2010 at 3:47 PM, Eli Friedman <eli.friedman at gmail.com> wrote:
>> On Fri, Jun 4, 2010 at 2:46 AM, Gregory Petrosyan
>> <gregory.petrosyan at gmail.com> wrote:
>>> Hello,
>>>
>>> I am working on a pass that finds identical basic blocks and abstracts
>>> them into functions, in order to reduce code size.
>>>
>>> To decide, whether particular basic block group is worth factoring
>>> out, I want to estimate code size of some function that uses one of
>>> basic blocks in question 'as is', and after factoring the basic block
>>> into a new function.
>>>
>>> Can you please suggest a proper way to do this?
>>
>> You could just count the number of Instructions as an extremely rough
>> estimate.  llvm/Analysis/InlineCost.h has the functions used by the
>> inliner and other similar transforms to estimate the cost of a basic
>> block or function, which are somewhat more accurate.
>
> Thanks Eli,
>
> The thing that worries me in this approach is that it is really rough,
> and to make it work I need to introduce and tune some target-specific
> coefficients. I thought that if there is a way to just generate real
> code and measure it's size, it would be simpler as well as more
> accurate.

I don't know the current state of the MC project
(http://blog.llvm.org/2010/04/intro-to-llvm-mc-project.html#more), but
it could be used to measure the size of the native version of a
function assuming you can JIT it.




More information about the llvm-dev mailing list