<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:DengXian;
panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Consolas;
panose-1:2 11 6 9 2 2 4 3 2 4;}
@font-face
{font-family:"\@DengXian";
panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
h1
{mso-style-priority:9;
mso-style-link:"Heading 1 Char";
mso-margin-top-alt:auto;
margin-right:0in;
mso-margin-bottom-alt:auto;
margin-left:0in;
font-size:24.0pt;
font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
pre
{mso-style-priority:99;
mso-style-link:"HTML Preformatted Char";
margin:0in;
margin-bottom:.0001pt;
font-size:10.0pt;
font-family:"Courier New";}
p.msonormal0, li.msonormal0, div.msonormal0
{mso-style-name:msonormal;
mso-margin-top-alt:auto;
margin-right:0in;
mso-margin-bottom-alt:auto;
margin-left:0in;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
span.EmailStyle18
{mso-style-type:personal;
font-family:"Calibri",sans-serif;
color:#1F497D;}
span.EmailStyle19
{mso-style-type:personal-compose;
font-family:"Calibri",sans-serif;
color:windowtext;}
p.solution, li.solution, div.solution
{mso-style-name:solution;
mso-margin-top-alt:auto;
margin-right:0in;
mso-margin-bottom-alt:auto;
margin-left:0in;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
span.HTMLPreformattedChar
{mso-style-name:"HTML Preformatted Char";
mso-style-priority:99;
mso-style-link:"HTML Preformatted";
font-family:"Courier New";}
span.Heading1Char
{mso-style-name:"Heading 1 Char";
mso-style-priority:9;
mso-style-link:"Heading 1";
font-family:"Times New Roman",serif;
font-weight:bold;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri",sans-serif;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'>Hello </span><span style='color:#1F497D'>paulr,<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>>> </span>I think Yonggang might be looking for a refactoring/source modification, rather than an optimization, but I'm not sure.<o:p></o:p></p><p class=MsoNormal><span style='color:#1F497D'>Yes, you are right. That’s what I meant. I’m looking for a refactoring modification.<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal style='mso-margin-top-alt:12.0pt;margin-right:0in;margin-bottom:12.0pt;margin-left:0in;background:white;vertical-align:baseline'><span style='color:#1F497D'>Put the method's body into the body of its callers and remove the method.<o:p></o:p></span></p><p class=MsoNormal style='vertical-align:baseline'><span style='font-size:11.0pt;font-family:"Courier New";color:#303633;background:silver;mso-highlight:silver'>int getRating() {<o:p></o:p></span></p><p class=MsoNormal style='vertical-align:baseline'><span style='font-size:11.0pt;font-family:"Courier New";color:#303633;background:silver;mso-highlight:silver'> return (moreThanFiveLateDeliveries()) ? 2 : 1;<o:p></o:p></span></p><p class=MsoNormal style='vertical-align:baseline'><span style='font-size:11.0pt;font-family:"Courier New";color:#303633;background:silver;mso-highlight:silver'>}<o:p></o:p></span></p><p class=MsoNormal style='vertical-align:baseline'><span style='font-size:11.0pt;font-family:"Courier New";color:#303633;background:silver;mso-highlight:silver'>boolean moreThanFiveLateDeliveries() {<o:p></o:p></span></p><p class=MsoNormal style='vertical-align:baseline'><span style='font-size:11.0pt;font-family:"Courier New";color:#303633;background:silver;mso-highlight:silver'> return _numberOfLateDeliveries > 5;<o:p></o:p></span></p><p class=MsoNormal style='vertical-align:baseline'><span style='font-size:11.0pt;font-family:"Courier New";color:#303633;background:silver;mso-highlight:silver'>}</span><span style='font-size:11.0pt;font-family:"Courier New";color:#303633'><o:p></o:p></span></p><p class=MsoNormal style='vertical-align:baseline'><span style='font-size:11.0pt;font-family:"Courier New";color:#303633'><o:p> </o:p></span></p><p class=MsoNormal style='vertical-align:baseline'><span style='color:#1F497D'>Then, the source code becomes the following:<o:p></o:p></span></p><p class=MsoNormal style='vertical-align:baseline'><span style='font-size:11.0pt;font-family:"Courier New";color:#303633;background:silver;mso-highlight:silver'>int getRating() {<o:p></o:p></span></p><p class=MsoNormal style='vertical-align:baseline'><span style='font-size:11.0pt;font-family:"Courier New";color:#303633;background:silver;mso-highlight:silver'> return (_numberOfLateDeliveries > 5) ? 2 : 1;<o:p></o:p></span></p><p class=MsoNormal style='vertical-align:baseline'><span style='font-size:11.0pt;font-family:"Courier New";color:#303633;background:silver;mso-highlight:silver'>}</span><span style='font-size:11.0pt;font-family:"Courier New";color:#303633'><o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>And it seems someone had achieved this, please check this link:<o:p></o:p></span></p><p class=MsoNormal style='line-height:19.5pt;background:#FAFBFC'><span style='color:#1F497D'><a href="https://github.com/goldsborough/clang-expand"><span style='color:#1F497D;text-decoration:none'>clang-expand</span></a><o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><a href="https://github.com/goldsborough/clang-expand">https://github.com/goldsborough/clang-expand</a><o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>Best regards<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'>Yonggang Chen</span><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'><o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><b><span style='font-size:11.0pt;font-family:"Calibri",sans-serif'>From:</span></b><span style='font-size:11.0pt;font-family:"Calibri",sans-serif'> David Blaikie [mailto:dblaikie@gmail.com] <br><b>Sent:</b> Sunday, June 25, 2017 12:36 AM<br><b>To:</b> Robinson, Paul <paul.robinson@sony.com>; Yonggang Chen <cyg19891102@163.com><br><b>Cc:</b> cfe-dev@lists.llvm.org<br><b>Subject:</b> Re: [cfe-dev] how to replace function call with actual code of function body?<o:p></o:p></span></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal style='margin-bottom:12.0pt'><o:p> </o:p></p><div><div><p class=MsoNormal>On Fri, Jun 23, 2017, 12:52 PM Robinson, Paul via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>> wrote:<o:p></o:p></p></div><blockquote style='border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in'><div><div><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='color:#1F497D'>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.</span><o:p></o:p></p></div></div></blockquote></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>I think Yonggang might be looking for a refactoring/source modification, rather than an optimization, but I'm not sure.<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><blockquote style='border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in'><div><div><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span style='color:#1F497D'>--paulr</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><a name="m_1602229529789429866__MailEndCompose"><span style='color:#1F497D'> </span></a><o:p></o:p></p><div style='border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt'><div><div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in'><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><b><span style='font-size:10.0pt;font-family:"Tahoma",sans-serif'>From:</span></b><span style='font-size:10.0pt;font-family:"Tahoma",sans-serif'> cfe-dev [mailto:<a href="mailto:cfe-dev-bounces@lists.llvm.org" target="_blank">cfe-dev-bounces@lists.llvm.org</a>] <b>On Behalf Of </b>Yonggang Chen via cfe-dev<br><b>Sent:</b> Thursday, June 22, 2017 9:03 PM<br><b>To:</b> <a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br><b>Subject:</b> [cfe-dev] how to replace function call with actual code of function body?<br><b>Importance:</b> High</span><o:p></o:p></p></div></div></div></div></div><div><div><div style='border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt'><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'> <o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas;color:#0D0D0D'>Hello all,</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas;color:#0D0D0D'> </span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas;color:#0D0D0D;background:silver'>int main()</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas;color:#0D0D0D;background:silver'>{</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas;color:#0D0D0D;background:silver'> auto n = 9;</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas;color:#0D0D0D;background:silver'> auto x = cacul(n);</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-indent:21.0pt;text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas;color:#0D0D0D;background:silver'>return 0;<br></span><span style='font-size:10.5pt;color:#0D0D0D;background:silver'>}</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-autospace:none'><span style='font-size:10.5pt;color:#0D0D0D'> </span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-autospace:none'><span style='font-size:10.5pt;color:#0D0D0D;background:silver'>int cacul(int x)</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-autospace:none'><span style='font-size:10.5pt;color:#0D0D0D;background:silver'>{</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-autospace:none'><span style='font-size:10.5pt;color:#0D0D0D;background:silver'> return x * x + 3;</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-autospace:none'><span style='font-size:10.5pt;color:#0D0D0D;background:silver'>}</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas;color:#0D0D0D'> </span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas;color:#0D0D0D'>Suppose I have function <span style='background:silver'>main()</span>, in which <span style='background:silver'>cacul(int x)</span> is called.</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas;color:#0D0D0D'>Now I want Clang help me do this:</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas;color:#0D0D0D'> </span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas;color:#0D0D0D;background:silver'>int main()</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas;color:#0D0D0D;background:silver'>{</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas;color:#0D0D0D;background:silver'> auto n = 9;</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas;color:#0D0D0D;background:silver'> auto x = n * n + 3;</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-indent:21.0pt;text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas;color:#0D0D0D;background:silver'>return 0;<br></span><span style='font-size:10.5pt;color:#0D0D0D;background:silver'>}</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-autospace:none'><span style='font-size:10.5pt;color:#0D0D0D;background:silver'> </span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-autospace:none'><span style='font-size:10.5pt;color:#0D0D0D;background:silver'>int cacul(int x)</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-autospace:none'><span style='font-size:10.5pt;color:#0D0D0D;background:silver'>{</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-autospace:none'><span style='font-size:10.5pt;color:#0D0D0D;background:silver'> return x * x + 3;</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-autospace:none'><span style='font-size:10.5pt;color:#0D0D0D;background:silver'>}</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas;color:#0D0D0D'> </span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-autospace:none'><span style='font-size:9.5pt;font-family:Consolas;color:#0D0D0D'>That’s to say, remove reference to <span style='background:silver'>cacul</span>. Can Clang help me do that? If so, how to do it?</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-autospace:none'><span style='font-size:10.5pt;color:#0D0D0D'> </span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-autospace:none'><span style='font-size:10.5pt;color:#0D0D0D'>Best regards</span><o:p></o:p></p><p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-autospace:none'><span style='font-size:10.5pt;color:#0D0D0D'>Yonggang Chen</span><o:p></o:p></p></div></div></div><p class=MsoNormal>_______________________________________________<br>cfe-dev mailing list<br><a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><o:p></o:p></p></blockquote></div></div></body></html>