<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=iso-8859-1">
<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:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
p.msonormal0, li.msonormal0, div.msonormal0
{mso-style-name:msonormal;
mso-margin-top-alt:auto;
margin-right:0cm;
mso-margin-bottom-alt:auto;
margin-left:0cm;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
span.EmailStyle18
{mso-style-type:personal;
font-family:"Calibri",sans-serif;
color:windowtext;}
span.EmailStyle19
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:70.85pt 70.85pt 2.0cm 70.85pt;}
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="DE" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal"><span lang="EN-GB" style="mso-fareast-language:EN-US">Heyho,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="mso-fareast-language:EN-US">I resend this mail, including the attachments to mark the questions that were answered, but also to append a new question. I hope to keep track about the questions – and not to spam…<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="mso-fareast-language:EN-US"><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US">From:</span></b><span lang="EN-US"> Gaier, Bjoern
<br>
<b>Sent:</b> 25 September 2019 11:37<br>
<b>To:</b> llvm-dev <llvm-dev@lists.llvm.org><br>
<b>Subject:</b> Questions after playing around with KaleidoscopeJIT (With source files)<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span lang="EN-US">Hello LLVM people,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">after finishing Chapter 1 and 2 of the KaleidoscopeJIT tutorial, I started to play around with the code and now, I have even more questions than before. I hope that the people reading this could help me with it, to improve
my understanding about the LLVM and the JIT.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">I have also the source code and binaries (Windows) available but because I don't know how the mailing list treats attachments (like .zip) I decided to only attach the source files - hoping it will help >o<<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">---<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">1.) Resolving undefined references<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">I wonder what the best practice is to resolve symbols that are not defined in my llvm::Module.
<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">For that purpose I created "CM_ExternalConstant", that is using "extern const int planschiValue;" and compiled it with Clang. (See CM_ExternalConstant.cpp)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">"planschiValue" is not defined in the module, so it will be unreferenced when I jit it. What is the best way to do this? I used 3 different ways:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">1.) I went over the llvm::Module before adding it to the layers. I searched for the symbol "?planschiValue@@3HB" and called "replaceAllUsesWith" to replace the symbol with the correct address. (See PlanschbeckenJIT.cpp:31)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">2.) I set my own GeneratorFunction and provided addresses for the symbols (See PlanschbeckenJIT.cpp:95)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">3.) I can use this->es.getMainJITDylib().define<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Each way worked fine. But I felt that way 2.) was the most annoying way, because I had to provide many other addresses. So what way is the best? Or can I 'freely' choose?<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Is it possible to have multiple GeneratorFunctions? I would like to use the 'default' DynamicLibrarySearchGenerator plus my own lookup function.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Would it also be possible to replace the uses of "?planschiValue@@3HB" directly with the actuall value of "plaschiValue"? Because it is a constant?<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">2.) Loading multiple modules<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">I created "CM_Orc", which has a function "int helloOrc()" - "CM_ExternalConstant" has the same function, but a different implementation. (See CM_Orc.cpp and CM_ExternalConstant.cpp) Adding both modules to the JIT will
lead to an error message:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">"Failure value returned from cantFail wrapped call<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">UNREACHABLE executed at c:\program files\llvm\include\llvm\support\error.h:708!"<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">I always thought that in this situation, one of the functions would be renamed...<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">3.) Loading multiple modules - controlled resolving<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Finally I created "CM_PlanschiValue" this file defines a value for "planschiValue" that was referenced in "CM_ExternalConstant". (See CM_ PlanschiValue.cpp and CM_ExternalConstant.cpp) Surprisingly, if I wrote:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">"const int planschiValue = 543210;"<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Clang would not generate code for it.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">But when writing:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">"extern const int planschiValue = 543210;" it worked. Why? Why can Clang optimize away the code, when it could be referenced by a different module? Like it was!<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">I loaded "CM_ExternalConstant" and "CM_PlanschiValue" together, while using my own GeneratorFunction. But there was no need any more to provide an address for "?planschiValue@@3HB". Obviously, the two modules where linked
- which is correct. But what, if I don't want that for whatever reason? Would I have to rename the referenced value in the llvm::Module before adding the second module? Or should I run instead two different JITs?<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">The idea behind this is... what should I do if I have multiple modules, that are not meant to be used together but should run in the same process.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">[Answered] <s>4.) Clang and JIT optimization<o:p></o:p></s></span></p>
<p class="MsoNormal"><s><span lang="EN-US">If I compile my modules with Clang and all optimizations turned on - do I still need the TransformLayer in my JIT?<o:p></o:p></span></s></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">[Answered] <s>5.) Mangling names<o:p></o:p></s></span></p>
<p class="MsoNormal"><s><span lang="EN-US">Does Clang or the LLVM provide a function to mangle from the string "const int planschiValue;" to "?planschiValue@@3HB"? Or vice versa?</span></s><span lang="EN-US"><o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">6.) Delayed resolving<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">This question goes along with question 1.) – I wondered if there is a way, when emitting code for my module, if I can resolve the undefined values with a “don’t know yet value”. The idea is to still create code for the
module, so that I can already use some functions of it – at a later point I would like to revisit the “don’t know values” to resolve them.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Only because function “foo” is missing a certain reference, why shouldn’t I be allowed to already use “bar” which is fully resolved? That is the basic idea behind my question.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">---<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">I know that this are a lot questions and that I'm not good in explaining stuff - but I really hope you guys can help me to understand everything better.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Kind greetings and many thanks<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Björn<o:p></o:p></span></p>
</div>
Als GmbH eingetragen im Handelsregister Bad Homburg v.d.H. HRB 9816, USt.ID-Nr. DE 114 165 789 Geschäftsführer: Dr. Hiroshi Nakamura, Dr. Robert Plank, Markus Bode, Heiko Lampert, Takashi Nagano, Takeshi Fukushima. Junichi Tajika
</body>
</html>