<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">The patch I recently attached to bug <span class="Apple-style-span" style="font-family: sans-serif; -webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px; "><a href="http://llvm.org/bugs/show_bug.cgi?id=2606" style="color: rgb(102, 51, 102); ">2606</a>, reproduced here, is my first attempt to solve this issue</span><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;">as represented by the attached test cases. To solve the foreign Module GlobalVariable problem,</span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;">I modified JIT::getOrEmitGlobalVariable(...) to directly attempt to map a found "external" GlobalVariable.</span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;">To solve the foreign Module Function problem, I modified both JIT.{h,cpp} and JITEmitter.cpp to emit</span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;">a stub for a found "external" Function instance, when that foreign Module defined Function has not</span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;">yet been compiled.</span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;"><br></span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;">All areas of interest are marked with // GMV Mod:</span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;"><br></span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;">As I've taken liberties with existing code, and thereby may have touched test cases that will fail, I would like</span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;">to have those members of the list that have time, review this proposal for comments/changes.</span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;"><br></span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;">Major mods:</span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;"><br></span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;">JIT.{h,cpp}:</span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;"><br></span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;">1)<span class="Apple-tab-span" style="white-space:pre"> </span>I included Module.h.</span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;"><br></span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;">2)<span class="Apple-tab-span" style="white-space:pre"> </span>JIT::<span class="Apple-tab-span" style="white-space:pre">getPointerToFunction</span>(...) was modified to search for a non-mapped function in all "other" modules.</span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;"><span class="Apple-tab-span" style="white-space:pre"> </span>If found a stub is emitted, which will lazily emit the real function at runtime.</span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;"><br></span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;"><span class="Apple-tab-span" style="white-space:pre"> </span>One issue here is that functions that are external to all modules, have their mappings delayed by the</span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;"><span class="Apple-tab-span" style="white-space:pre"> </span>above loop. I also kept the hasAvailableExternallyLinkage() the same as before, as I'm not sure if this</span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;"><span class="Apple-tab-span" style="white-space:pre"> </span>should also go through the same module procedure. The stub emission will only take place for function</span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;"><span class="Apple-tab-span" style="white-space:pre"> </span>definitions that are marked with external linkage. Should other cases be allowed? Should visibility also </span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;"><span class="Apple-tab-span" style="white-space:pre"> </span>be considered?</span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;"><br></span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;">3)<span class="Apple-tab-span" style="white-space:pre"> JIT::getOrEmitGlobalVariable</span>(...) was modified to search for non-mapped global variables in all "other"</span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;"><span class="Apple-tab-span" style="white-space:pre"> </span>modules. If found, the address of the foreign global variable is requested, and mapped. There is no</span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;"><span class="Apple-tab-span" style="white-space:pre"> </span>delay here.</span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;"><br></span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;"><span class="Apple-tab-span" style="white-space:pre"> </span>An attempt is first made to find the global outside of all modules, before attempting to find the function</span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;"><span class="Apple-tab-span" style="white-space:pre"> </span>in the known modules. This is the reverse logic used in #2. On searching, unlike for functions, a linkage </span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;"><span class="Apple-tab-span" style="white-space:pre"> </span>check was not made. Also the global variable declaration and definition must have the exact same type. </span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;"><span class="Apple-tab-span" style="white-space:pre"> </span>Is this the correct approach?</span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;"><br></span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;">4) The declaration of void* forceEmitFunctionStub(Function *F) was added to the class JIT. This is </span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;"><span class="Apple-tab-span" style="white-space:pre"> </span>implemented in JITEmitter.cpp.</span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;"><br></span></font></div><div><span class="Apple-style-span" style="font-family: sans-serif; -webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px; ">JITEmitter.cpp:</span></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;"><br></span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;">1)<span class="Apple-tab-span" style="white-space:pre"> JIT::forceEmitFunctionStub</span>(...) was added. It turns around and calls JITResolver::<span class="Apple-style-span" style="font-family: Helvetica; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; "><span class="Apple-style-span" style="font-family: sans-serif; -webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px; "><span class="Apple-tab-span" style="white-space: pre; ">forceEmitFunctionStub</span>(...).</span></span></span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;"><br></span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;"><span class="Apple-tab-span" style="white-space:pre"> </span>Is the JIT:getPointerToFunction(...) code path sensitive to such call overhead?</span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;"><br></span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;">2)<span class="Apple-tab-span" style="white-space:pre"> JITResolver::forceEmitFunctionStub(Function *F)</span> was added. It is a simplified version of JITResolver::getLazyFunctionStub(...),</span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;"><span class="Apple-tab-span" style="white-space:pre"> </span>which does not add to pending. It uses the same JITResolver::JITCompilerFn(...) for runtime emission that </span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;"><span class="Apple-tab-span" style="white-space:pre"> </span>the lazy compilation system uses.</span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;"><br></span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;"><span class="Apple-tab-span" style="white-space:pre"> </span>Outside of the goal, I'm not sure what code is unnecessary here. Notice that the hasAvailableExternallyLinkage</span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;"><span class="Apple-tab-span" style="white-space:pre"> </span>case is dealt with here even though <span class="Apple-tab-span" style="white-space: pre; ">forceEmitFunctionStub</span>(...) would not be entered for this case. I'm forced to </span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;"><span class="Apple-tab-span" style="white-space:pre"> </span>use JITResolver::JITCompilerFn(...) as there is a static relationship between JITResolver and say X86JITInfo. See</span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;"><span class="Apple-tab-span" style="white-space:pre"> </span>implementation of X86JITInfo::getLazyResolverFunction(...) (X86JITInfo.cpp). Should a new JITCompilerFn like </span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;"><span class="Apple-tab-span" style="white-space:pre"> </span>function be created for the purposes of resolving this issue? This would of course require modifications to the </span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;"><span class="Apple-tab-span" style="white-space:pre"> </span>subclasses of TargetJITInfo.</span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;"><br></span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;">3)<span class="Apple-tab-span" style="white-space:pre"> JITResolver::JITCompilerFn</span>(...) was modified to no longer exit on being used for non-lazy compilation scenarios.</span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;"><br></span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;"><span class="Apple-tab-span" style="white-space:pre"> </span>This means of course that the error test path behavior for this function has been modified. See #2 above.</span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;"><br></span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;">Beyond any issues with the patch, there is a question, in my mind, as to whether <a href="http://llvm.org/bugs/show_bug.cgi?id=2606" style="color: rgb(102, 51, 102); ">2606</a> is really a bug. Sure its resolution makes </span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;">using the JIT simpler for cross module behavior, but current manual solutions may be more fined grained in their approach. </span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;">If so a fix to <a href="http://llvm.org/bugs/show_bug.cgi?id=2606" style="color: rgb(102, 51, 102); ">2606</a> would circumvent such handling.</span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;"><br></span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;">Thanks for any time spent on this</span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px; "><br></span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;">Garrison</span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;"><br></span></font></div><div><font class="Apple-style-span" face="sans-serif"><span class="Apple-style-span" style="-webkit-border-horizontal-spacing: 1px; -webkit-border-vertical-spacing: 1px;"></span></font></div></body></html>