Serializing conflicting replacements

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Serializing conflicting replacements

David Chisnall via cfe-dev
Hi all,
I need to write a tool that will convert stackful coroutine to stackless. One of the required refactorings is inlining all functions that call yield into a coroutine body. 

Here is an example of required refactoring:

Input source code:

void foo() { /*foo*/ yield(); }

void bar() { /*bar*/  foo(); }

void coroutine_body() { 
  bar();
}

Expected output code from tool:

void coroutine_body() {
   /*bar*/ 
   /*foo*/
   yield();
}


So when I run the tool it will create two conflicting replacements:  
  • inline foo into bar
  • inline bar into coroutine_body

Is it possible to apply them one after another using current Clang libraries?  Or it is not supported out-of-the-box and I should better run tool N times to inline all functions one-by-one without generating conflicting replacements? 

Thanks,
Roman

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Serializing conflicting replacements

David Chisnall via cfe-dev
On Wed, Sep 27, 2017 at 8:06 PM Roman Popov via cfe-dev <[hidden email]> wrote:
Hi all,
I need to write a tool that will convert stackful coroutine to stackless. One of the required refactorings is inlining all functions that call yield into a coroutine body. 

Here is an example of required refactoring:

Input source code:

void foo() { /*foo*/ yield(); }

void bar() { /*bar*/  foo(); }

void coroutine_body() { 
  bar();
}

Expected output code from tool:

void coroutine_body() {
   /*bar*/ 
   /*foo*/
   yield();
}


So when I run the tool it will create two conflicting replacements:  
  • inline foo into bar
  • inline bar into coroutine_body

Is it possible to apply them one after another using current Clang libraries?  Or it is not supported out-of-the-box and I should better run tool N times to inline all functions one-by-one without generating conflicting replacements? 

We do have Replacements::merge(), but the merged replacements need to be relative to the new code after applying the original replacements, so that's not fully helping.
I think running the tool multiple times is probably simplest, but it's also possible to build up the dependency chain of your replacements yourself, and then creating one large replacement in the end from the dep tree.
 

Thanks,
Roman
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Serializing conflicting replacements

David Chisnall via cfe-dev
Thanks for response!
Yes, this was my impression that I will have to track dependencies and merge them myself.   

So I will start with simplest option of running a tool multiple times.  And If it works will later look on single-pass solution.


2017-09-28 1:10 GMT-07:00 Manuel Klimek <[hidden email]>:
On Wed, Sep 27, 2017 at 8:06 PM Roman Popov via cfe-dev <[hidden email]> wrote:
Hi all,
I need to write a tool that will convert stackful coroutine to stackless. One of the required refactorings is inlining all functions that call yield into a coroutine body. 

Here is an example of required refactoring:

Input source code:

void foo() { /*foo*/ yield(); }

void bar() { /*bar*/  foo(); }

void coroutine_body() { 
  bar();
}

Expected output code from tool:

void coroutine_body() {
   /*bar*/ 
   /*foo*/
   yield();
}


So when I run the tool it will create two conflicting replacements:  
  • inline foo into bar
  • inline bar into coroutine_body

Is it possible to apply them one after another using current Clang libraries?  Or it is not supported out-of-the-box and I should better run tool N times to inline all functions one-by-one without generating conflicting replacements? 

We do have Replacements::merge(), but the merged replacements need to be relative to the new code after applying the original replacements, so that's not fully helping.
I think running the tool multiple times is probably simplest, but it's also possible to build up the dependency chain of your replacements yourself, and then creating one large replacement in the end from the dep tree.
 

Thanks,
Roman
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev