outlining in llvm

Hi,

I have some questions regarding outlining (extracting piece of code into a function):

  1. Is there an outlining pass in llvm (IR)? I’ve found out CodeExtractor pass, but I’m not sure it’s exactly the same idea.

  2. How do I set the function name?

And another question:

Where do I control the execution of my pass? I’m writing a pass that first works on loops, than on a function (outlined from the loop) and then again on loops.

How can I do that?

Thanks and happy new year,

Tehila.

Hi,

I have some questions regarding outlining (extracting piece of code into a function):

  1. Is there an outlining pass in llvm (IR)? I’ve found out CodeExtractor pass, but I’m not sure it’s exactly the same idea.

Hi,

Hi,

I have some questions regarding outlining (extracting piece of code into a
function):
1. Is there an outlining pass in llvm (IR)? I've found out CodeExtractor
pass, but I'm not sure it’s exactly the same idea.
To my knowledge, there is not an existing outlining pass in tree. Most of the
functionality to write one could probably be found in various places, but the
profitability heuristics are entirely missing. One reasonable starting point
might be the MergeFunctions pass.

Appart from this, the CodeExtractor class is the basic block you're
looking for.

     2. How do I set the function name?

That's the `twine' parameter in the Create call. Function inherits from
Value, so the setName method works fine too.

     And another question:
     Where do I control the execution of my pass? I'm writing a pass that
     first works on loops, than on a function (outlined from the loop) and
     then again on loops.
     How can I do that?
This ordering isn't a natural thing to express in LLVM's pass structure.
You'll probably need to use a Module pass since that's the only type allowed to
modify other functions. (A loop pass will not work for this.)

Another way to do this would be to mark the outlined functions with a
specific metadata, and process only these one in the function pass.

hop,

Hi Tehila,
You can try to use function outlining implemented in clang. It is based on class CapturedStmt.
You can try it with the the following construct:

#pragma clang __debug captured
<Code to be outlined>

Implementation is in clang/lib/Parse/ParsePragma.cpp, StmtResult Parser::HandlePragmaCaptured()

Best regards,
Alexey Bataev

Hi Alexey,

Thanks a lot. I’ll try it.

Tehila.

Hi Tehila,

You can use CodeExtractor to do function outlining.

It provide you facility to extract following to a function:

  1. single block 2) Series of block

  2. Region node 4) Loop

First it identify input and output to outlined function.

Then it does actual outlining on the specified blocks.

It sets input and output to functions as parameter.

Also it take cares of adding a callsite.

Hope this helps you.

Regards,

Ashutosh