<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jan 20, 2016 at 10:19 AM, Andy Ayers <span dir="ltr"><<a href="mailto:andya@microsoft.com" target="_blank">andya@microsoft.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div lang="EN-US" link="blue" vlink="purple">
<div>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Thanks. Our use case is pretty simple:<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Create a function with some placeholder type.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Figure out the actual function type and create some IR that calls the function with that type. Update function’s type via mutateType.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">Dump the module. The function’s “declaration” still shows it has the placeholder type.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">This doesn’t cause us any problems because the IR is what matters and it’s got the right description.</span></p></div></div></blockquote><div><br></div><div>Hrm. It'd be nice to be able to demonstrate the problem with some usage inside the LLVM project. I've tried adding an assertion in llvm::Function::getFunctionType (& tried in GlobalValue::getValueType too) that asserts that the pointee type of the type matches the value type - but it does not fire anywhere in the test suite.<br><br>Perhaps you could think of other places in the code where we could check this property and demonstrate that it gets out of sync (the main place where it could get out of sync is the LTO linker - but also I think the vectorizer uses mutateType too)?</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div lang="EN-US" link="blue" vlink="purple"><div><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d">FWIW we do this because the transformation from an MSIL signature to an ABI-level signature is somewhat involved, and we’ve intertwined the code to generate the
right call sequence with the code that figures out what type you end up with once you’ve done all the various transformations, so to start things off, we need a way to refer to the function without knowing precisely what type it will end up with.</span></p></div></div></blockquote><div><br>Interesting to understand - thanks for the context.<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div lang="EN-US" link="blue" vlink="purple"><div><p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1f497d"><u></u> <u></u></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:<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>]
<br>
<b>Sent:</b> Tuesday, January 19, 2016 3:36 PM<br>
<b>To:</b> Andy Ayers <<a href="mailto:andya@microsoft.com" target="_blank">andya@microsoft.com</a>><br>
<b>Cc:</b> <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<b>Subject:</b> Re: [llvm-dev] Functions have two types, one can be mutated but not the other<u></u><u></u></span></p><div><div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal">On Tue, Nov 24, 2015 at 9:25 AM, Andy Ayers via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<u></u><u></u></p>
<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">Function has its own FunctionType* member as well as a Type* member that it inherits from GlobalValue. The latter can be mutated but not the former, leading to potential strange
inconsistencies.<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">While I realize using mutateType is probably going to trigger a bunch of “you’re doing it wrong” replies, it seems like mutateType, as a necessary evil, should be virtual and do
the right wrong thing for Functions too.<u></u><u></u></p>
<p class="MsoNormal"> <u></u><u></u></p>
<p class="MsoNormal">Thoughts?<u></u><u></u></p>
</div>
</div>
</blockquote>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">I've been perpetrating some of this for the typeless/opaque pointer IR stuff (some details here:
<a href="https://na01.safelinks.protection.outlook.com/?url=https%3a%2f%2fwww.youtube.com%2fwatch%3fv%3dOWgWDx_gB1I&data=01%7c01%7candya%40microsoft.com%7c692fcbd2bdf147a7a2fb08d321293eef%7c72f988bf86f141af91ab2d7cd011db47%7c1&sdata=VWuobdaqbGrRzX0N7VrZw6UubBarZThFRpTl9aoe%2fFc%3d" target="_blank">
https://www.youtube.com/watch?v=OWgWDx_gB1I</a> - or on a few threads on llvm-dev).<br>
<br>
I got rid of that extra one in Function - thanks for noticing.<br>
<br>
If I recall correctly, even before my work, it wasn't possible to rely solely on mutateType of the operands so various special cases have been added (ValueMapper.cpp is a good example of some of these special cases)<br>
<br>
I'm not sure why those issues might not have come up when dealing with Globals. Perhaps you have some examples (eg: linking bitcode with globals - where the value type gets out of sync with the pointer type? Maybe if we add some more assertions in to check
the two values are in sync we'd find cases where they've gotten out of sync?)<u></u><u></u></p>
</div>
</div>
</div>
</div>
</div></div></div>
</div>
</blockquote></div><br></div></div>