[LLVMdev] outlining in llvm

743 views
Skip to first unread message

Tehila Mayzels

unread,
Dec 31, 2014, 3:52:41 PM12/31/14
to llv...@cs.uiuc.edu

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.

Philip Reames

unread,
Jan 2, 2015, 3:18:08 PM1/2/15
to Tehila Mayzels, llv...@cs.uiuc.edu
On 12/31/2014 12:49 PM, Tehila Mayzels wrote:

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.

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?

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.)

 

Thanks and happy new year,

Tehila.



_______________________________________________
LLVM Developers mailing list
LLV...@cs.uiuc.edu         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

Serge Guelton

unread,
Jan 2, 2015, 4:06:49 PM1/2/15
to Philip Reames, llv...@cs.uiuc.edu
Hi,

On Fri, Jan 02, 2015 at 12:15:18PM -0800, Philip Reames wrote:
> On 12/31/2014 12:49 PM, Tehila Mayzels wrote:
>
> 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,

Bataev, Alexey

unread,
Jan 13, 2015, 12:09:54 AM1/13/15
to Tehila Mayzels, llv...@cs.uiuc.edu
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
=============
Software Engineer
Intel Compiler Team
Intel Corp. 
31.12.2014 23:49, Tehila Mayzels пишет:

Tehila Mayzels

unread,
Jan 13, 2015, 12:50:14 AM1/13/15
to Bataev, Alexey, llv...@cs.uiuc.edu

Hi Alexey,

 

Thanks a lot. I'll try it.

 

Tehila.

Nema, Ashutosh

unread,
Jan 28, 2015, 5:42:40 AM1/28/15
to Tehila Mayzels, llv...@cs.uiuc.edu

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

3) 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

Reply all
Reply to author
Forward
0 new messages