<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=us-ascii"><meta name=Generator content="Microsoft Word 14 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
{font-family:Helvetica;
panose-1:2 11 6 4 2 2 2 2 2 4;}
@font-face
{font-family:Courier;
panose-1:2 7 4 9 2 2 5 2 4 4;}
@font-face
{font-family:Courier;
panose-1:2 7 4 9 2 2 5 2 4 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@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";
color:black;}
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;}
p
{mso-style-priority:99;
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";
color:black;}
span.apple-tab-span
{mso-style-name:apple-tab-span;}
span.EmailStyle19
{mso-style-type:personal-reply;
font-family:"Calibri","sans-serif";
color:#1F497D;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@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 bgcolor=white 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'>“</span>The addPreserved<>() functionality is only there so that the LLVM compiler can cache the results of analysis passes for efficiency.”<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><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>The addPreserved() function only tells the compiler to cache it? I was under the impression from the code that it was an indication that a transformation pass doesn’t invalidate whatever analysis pass it says it preserves. If it is only an indication that the compiler should cache it, how does the compiler know if a particular analysis pass should be re-run?<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><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>I’m going through the LegacyPassManager now and there definitely are some parts I don’t understand what they are for.<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><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Daniel<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><div><div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in'><p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:windowtext'>From:</span></b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:windowtext'> llvmdev-bounces@cs.uiuc.edu [mailto:llvmdev-bounces@cs.uiuc.edu] <b>On Behalf Of </b>John Criswell<br><b>Sent:</b> Friday, April 04, 2014 6:27 PM<br><b>To:</b> Hanbing Li; llvmdev@cs.uiuc.edu<br><b>Subject:</b> Re: [LLVMdev] Add a new information and preserve it in LLVM<o:p></o:p></span></p></div></div><p class=MsoNormal><o:p> </o:p></p><div><p class=MsoNormal>On 4/4/14 3:02 PM, Hanbing Li wrote:<o:p></o:p></p></div><blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><div><div><p style='margin:0in;margin-bottom:.0001pt'><span style='font-size:9.0pt;font-family:"Helvetica","sans-serif"'>Hello,<o:p></o:p></span></p><p style='margin:0in;margin-bottom:.0001pt;min-height: 14px'><span style='font-size:9.0pt;font-family:"Helvetica","sans-serif"'><o:p> </o:p></span></p><p style='margin:0in;margin-bottom:.0001pt'><span class=apple-tab-span><span style='font-size:9.0pt;font-family:"Helvetica","sans-serif"'> </span></span><span style='font-size:9.0pt;font-family:"Helvetica","sans-serif"'>I am trying to add some thing into LLVM, while I encountered some problems.<o:p></o:p></span></p><p style='margin:0in;margin-bottom:.0001pt;min-height: 14px'><span style='font-size:9.0pt;font-family:"Helvetica","sans-serif"'><o:p> </o:p></span></p><p style='margin:0in;margin-bottom:.0001pt'><span class=apple-tab-span><span style='font-size:9.0pt;font-family:"Helvetica","sans-serif"'> </span></span><span style='font-size:9.0pt;font-family:"Helvetica","sans-serif"'>So my situation is that I have some information W, some transform passes may change it, after these passes, I need the new W. What I did is to create an analysis pass similar to scalar-evolution or loopinfo, I can get the information by using getAnalysis<W>(); and preserve this information W by using AU.addPreserved<W>();. Then the problem came, for the module pass, the information can’t be preserved. (I found this: </span><span style='font-size:10.0pt;font-family:Courier'>To the best of my knowledge, the LLVM pass manager never preserves a FunctionPass analysis that is requested by a ModulePass; every time you call getAnalysis for a function, the FunctionPass is re-run. <a href="http://lists.cs.uiuc.edu/pipermail/llvmdev/2012-March/048139.html">http://lists.cs.uiuc.edu/pipermail/llvmdev/2012-March/048139.html</a></span><span style='font-size:9.0pt;font-family:"Helvetica","sans-serif"'>) So this means that I can’t update W when some module passes changed it?<o:p></o:p></span></p><p style='margin:0in;margin-bottom:.0001pt;min-height: 14px'><span style='font-size:9.0pt;font-family:"Helvetica","sans-serif"'><o:p> </o:p></span></p><p style='margin:0in;margin-bottom:.0001pt'><span style='font-size:9.0pt;font-family:"Helvetica","sans-serif"'>My questions are:<o:p></o:p></span></p><p style='margin:0in;margin-bottom:.0001pt'><span style='font-size:9.0pt;font-family:"Helvetica","sans-serif"'>1, Module pass really can’t preserve the W?<o:p></o:p></span></p></div></div></blockquote><p class=MsoNormal style='margin-bottom:12.0pt'><br>If W is a FunctionPass, then I believe you are correct: a ModulePass will re-run the FunctionPass every time it uses the FunctionPass.<br><br>I get the impression that you're using the PassManager infrastructure improperly, and that is probably why you're not getting the results you want.<br><br>First, the ability to preserve a pass's results with addPreserved<W>() is an optimization. A FunctionPass or ModulePass() that analyzes the LLVM IR should work whether it is run one time or a hundred times. The addPreserved<>() functionality is only there so that the LLVM compiler can cache the results of analysis passes for efficiency.<br><br>Second, the way to fix your problem depends on what you want to do. If you want pass W to analyze the LLVM IR of a program and cache its results (because the analysis it does is expensive), then make it a ModulePass. That way, other ModulePass'es can update and preserve its results.<br><br>If you are just using W as a container in which to record information that transform passes are doing, then you might want to make W an ImmutablePass. ImmutablePasses are only run once and are never invalidated; other passes can use them to record information about what they do. ImmutablePasses, I think, were not really designed for this purpose, but they'll get the job done.<br><br>Regards,<br><br>John Criswell<o:p></o:p></p></div></body></html>