<div dir="ltr">(+Lang, ORC leader)<br><br>I don't know much about most of the questions myself, though for (5) - Clang does map between code and mangled names, but it doesn't provide a simple entry-point to that. (mostly because it's not often useful in isolation) - you can compile "const int foo;" to LLVM IR and you'll see the mangled name there. The narrowest piece of code that gives just the mangled name would accept the Clang AST as input and operate on that, not on a string of source code.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Sep 25, 2019 at 2:37 AM Gaier, Bjoern via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">





<div lang="EN-US">
<div class="gmail-m_4167565712451321212WordSection1">
<p class="MsoNormal">Hello LLVM people,<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">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.<u></u><u></u></p>
<p class="MsoNormal">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<<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">---<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">1.) Resolving undefined references<u></u><u></u></p>
<p class="MsoNormal">I wonder what the best practice is to resolve symbols that are not defined in my llvm::Module.
<u></u><u></u></p>
<p class="MsoNormal">For that purpose I created "CM_ExternalConstant", that is using "extern const int planschiValue;" and compiled it with Clang. (See CM_ExternalConstant.cpp)<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">"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:<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">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)<u></u><u></u></p>
<p class="MsoNormal">2.) I set my own GeneratorFunction and provided addresses for the symbols (See PlanschbeckenJIT.cpp:95)<u></u><u></u></p>
<p class="MsoNormal">3.) I can use this->es.getMainJITDylib().define<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">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?<u></u><u></u></p>
<p class="MsoNormal">Is it possible to have multiple GeneratorFunctions? I would like to use the 'default' DynamicLibrarySearchGenerator plus my own lookup function.<u></u><u></u></p>
<p class="MsoNormal">Would it also be possible to replace the uses of "?planschiValue@@3HB" directly with the actuall value of "plaschiValue"? Because it is a constant?<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">2.) Loading multiple modules<u></u><u></u></p>
<p class="MsoNormal">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:<u></u><u></u></p>
<p class="MsoNormal">"Failure value returned from cantFail wrapped call<u></u><u></u></p>
<p class="MsoNormal">UNREACHABLE executed at c:\program files\llvm\include\llvm\support\error.h:708!"<u></u><u></u></p>
<p class="MsoNormal">I always thought that in this situation, one of the functions would be renamed...<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">3.) Loading multiple modules - controlled resolving<u></u><u></u></p>
<p class="MsoNormal">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:<u></u><u></u></p>
<p class="MsoNormal">"const int planschiValue = 543210;"<u></u><u></u></p>
<p class="MsoNormal">Clang would not generate code for it.<u></u><u></u></p>
<p class="MsoNormal">But when writing:<u></u><u></u></p>
<p class="MsoNormal">"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!<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">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?<u></u><u></u></p>
<p class="MsoNormal">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.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">4.) Clang and JIT optimization<u></u><u></u></p>
<p class="MsoNormal">If I compile my modules with Clang and all optimizations turned on - do I still need the TransformLayer in my JIT?<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">5.) Mangling names<u></u><u></u></p>
<p class="MsoNormal">Does Clang or the LLVM provide a function to mangle from the string "const int planschiValue;" to "?planschiValue@@3HB"? Or vice versa?<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">---<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">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.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Kind greetings and many thanks<u></u><u></u></p>
<p class="MsoNormal">Björn<u></u><u></u></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
</div>

_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>