how to replace function call with actual code of function body?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

how to replace function call with actual code of function body?

Xin Wang via cfe-dev

Hello all,

 

int main()

{

    auto n = 9;

    auto x = cacul(n);

return 0;
}

 

int cacul(int x)

{

         return x * x + 3;

}

 

Suppose I have function main(), in which cacul(int x) is called.

Now I want Clang help me do this:

 

int main()

{

    auto n = 9;

    auto x = n * n + 3;

return 0;
}

 

int cacul(int x)

{

         return x * x + 3;

}

 

That’s to say, remove reference to cacul. Can Clang help me do that? If so, how to do it?

 

Best regards

Yonggang Chen


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

Re: how to replace function call with actual code of function body?

Xin Wang via cfe-dev

You are describing "function inlining" which is an optimization done by LLVM.  This optimization is performed on the intermediate representation (IR), not at the source level, if that's what you need to know.

--paulr

 

From: cfe-dev [mailto:[hidden email]] On Behalf Of Yonggang Chen via cfe-dev
Sent: Thursday, June 22, 2017 9:03 PM
To: [hidden email]
Subject: [cfe-dev] how to replace function call with actual code of function body?
Importance: High

 

Hello all,

 

int main()

{

    auto n = 9;

    auto x = cacul(n);

return 0;
}

 

int cacul(int x)

{

         return x * x + 3;

}

 

Suppose I have function main(), in which cacul(int x) is called.

Now I want Clang help me do this:

 

int main()

{

    auto n = 9;

    auto x = n * n + 3;

return 0;
}

 

int cacul(int x)

{

         return x * x + 3;

}

 

That’s to say, remove reference to cacul. Can Clang help me do that? If so, how to do it?

 

Best regards

Yonggang Chen


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

Re: how to replace function call with actual code of function body?

Xin Wang via cfe-dev


On Fri, Jun 23, 2017, 12:52 PM Robinson, Paul via cfe-dev <[hidden email]> wrote:

You are describing "function inlining" which is an optimization done by LLVM.  This optimization is performed on the intermediate representation (IR), not at the source level, if that's what you need to know.


I think Yonggang might be looking for a refactoring/source modification, rather than an optimization, but I'm not sure.

--paulr

 

From: cfe-dev [mailto:[hidden email]] On Behalf Of Yonggang Chen via cfe-dev
Sent: Thursday, June 22, 2017 9:03 PM
To: [hidden email]
Subject: [cfe-dev] how to replace function call with actual code of function body?
Importance: High

 

Hello all,

 

int main()

{

    auto n = 9;

    auto x = cacul(n);

return 0;
}

 

int cacul(int x)

{

         return x * x + 3;

}

 

Suppose I have function main(), in which cacul(int x) is called.

Now I want Clang help me do this:

 

int main()

{

    auto n = 9;

    auto x = n * n + 3;

return 0;
}

 

int cacul(int x)

{

         return x * x + 3;

}

 

That’s to say, remove reference to cacul. Can Clang help me do that? If so, how to do it?

 

Best regards

Yonggang Chen

_______________________________________________
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
|  
Report Content as Inappropriate

Re: how to replace function call with actual code of function body?

Xin Wang via cfe-dev

Hello paulr,

 

>> I think Yonggang might be looking for a refactoring/source modification, rather than an optimization, but I'm not sure.

Yes, you are right. That’s what I meant. I’m looking for a refactoring modification.

 

Put the method's body into the body of its callers and remove the method.

int getRating() {

  return (moreThanFiveLateDeliveries()) ? 2 : 1;

}

boolean moreThanFiveLateDeliveries() {

  return _numberOfLateDeliveries > 5;

}

 

Then, the source code becomes the following:

int getRating() {

  return (_numberOfLateDeliveries > 5) ? 2 : 1;

}

 

And it seems someone had achieved this, please check this link:

clang-expand

https://github.com/goldsborough/clang-expand

 

Best regards

Yonggang Chen

 

From: David Blaikie [mailto:[hidden email]]
Sent: Sunday, June 25, 2017 12:36 AM
To: Robinson, Paul <[hidden email]>; Yonggang Chen <[hidden email]>
Cc: [hidden email]
Subject: Re: [cfe-dev] how to replace function call with actual code of function body?

 

 

On Fri, Jun 23, 2017, 12:52 PM Robinson, Paul via cfe-dev <[hidden email]> wrote:

You are describing "function inlining" which is an optimization done by LLVM.  This optimization is performed on the intermediate representation (IR), not at the source level, if that's what you need to know.

 

I think Yonggang might be looking for a refactoring/source modification, rather than an optimization, but I'm not sure.

 

--paulr

 

From: cfe-dev [mailto:[hidden email]] On Behalf Of Yonggang Chen via cfe-dev
Sent: Thursday, June 22, 2017 9:03 PM
To: [hidden email]
Subject: [cfe-dev] how to replace function call with actual code of function body?
Importance: High

 

Hello all,

 

int main()

{

    auto n = 9;

    auto x = cacul(n);

return 0;
}

 

int cacul(int x)

{

         return x * x + 3;

}

 

Suppose I have function main(), in which cacul(int x) is called.

Now I want Clang help me do this:

 

int main()

{

    auto n = 9;

    auto x = n * n + 3;

return 0;
}

 

int cacul(int x)

{

         return x * x + 3;

}

 

That’s to say, remove reference to cacul. Can Clang help me do that? If so, how to do it?

 

Best regards

Yonggang Chen

_______________________________________________
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
Loading...