<div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div>Hi Dibyendu,</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">> What do you see if you dump the modules before/after running the pass manager on them, like this:<br>><br>> dbgs() << "Before optimization:\n" << *M << "\n";<br>> for (auto &F : *M)<br>> FPM->run(F);<br>> dbgs() << "Before optimization:\n" << *M << "\n";<br>><br>> I expect that output to be the same for both ORC and ORCv2. If not something is going wrong with IR optimization.<br>Well for ORCV2 there is no change before and after.</blockquote><div><br></div><div>What about for ORCv1? There is nothing ORCv2 specific about this code snippet, so that seems to indicate a misconfigured function pass manager, but your pass manager config (at first glance) didn't look like it was different between the two.</div><div><br></div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">I also get this message:<br>JIT session error: Symbols not found: { raise_error }</blockquote></div><div><br></div><div>Ahh -- I see the problem. The DynamicLibrarySearchGenerator is using the getAddressOfSymbol method, which (under the hood) is basically issuing an appropriate dlsym lookup, and that does not find explicitly added symbols. To find explicitly added symbols you need to call DynamicLibrary::SearchForAddressOfSymbol instead, but unfortunately that method's behavior is not a good fit for what DynamicLibrarySearchGenerator is trying to do. </div><div><br></div><div>There are two ways you could tackle this:</div><div>(1) Write your own generator that calls sys::DynamicLibrary::SearchforAddressOfSymbol, or</div><div>(2) Add the symbols up-front using the absoluteSymbols function.</div><div><br></div><div>I would be inclined to do the latter: it's more explicit, and easier to limit searches to exactly the symbols you want.</div><div><br></div><div><div>> CodeGen optimization seems a more likely culprit: JITTargetMachineBuilder and ExecutionEngineBuilder have different defaults for their CodeGen opt-level. JITTargetMachineBuilder defaults to CodeGenOpt::None, and ExecutionEngineBuilder default to CodeGenOpt::Default.</div><div>></div><div>> What happens if you make the following modification to your setup?</div><div>></div><div>> auto JTMB = llvm::orc::JITTargetMachineBuilder::detectHost();</div><div>> JTMB->setCodeGenOptLevel(CodeGenOpt::Default); // <-- Explicitly set Codegen opt level</div><div>> auto dataLayout = JTMB->getDefaultDataLayoutForTarget();</div><div><br></div></div><div>I am not sure what to make of that. What happens if you print TM->getOptLevel() right before running CodeGen? Once your have explicitly set it I would expect them to be the same for ORCv1 and ORCv2. If they're not then it's a plumbing issue.</div><div><br></div><div>-- Lang.</div><div><br></div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Aug 13, 2019 at 2:58 PM Dibyendu Majumdar <<a href="mailto:mobile@majumdar.org.uk">mobile@majumdar.org.uk</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">Hi Lang,<br>
<br>
On Tue, 13 Aug 2019 at 22:03, Lang Hames <<a href="mailto:lhames@gmail.com" target="_blank">lhames@gmail.com</a>> wrote:<br>
> When you say your code is not getting optimized, do you mean that IR optimizations are not being applied, or that codegen optimizations are not being applied?<br>
><br>
> What do you see if you dump the modules before/after running the pass manager on them, like this:<br>
><br>
> dbgs() << "Before optimization:\n" << *M << "\n";<br>
> for (auto &F : *M)<br>
> FPM->run(F);<br>
> dbgs() << "Before optimization:\n" << *M << "\n";<br>
><br>
> I expect that output to be the same for both ORC and ORCv2. If not something is going wrong with IR optimization.<br>
<br>
Well for ORCV2 there is no change before and after.<br>
I also get this message:<br>
<br>
JIT session error: Symbols not found: { raise_error }<br>
<br>
Yes raise_error and all other extern functions are explicitly added as<br>
global symbols.<br>
<br>
><br>
> CodeGen optimization seems a more likely culprit: JITTargetMachineBuilder and ExecutionEngineBuilder have different defaults for their CodeGen opt-level. JITTargetMachineBuilder defaults to CodeGenOpt::None, and ExecutionEngineBuilder default to CodeGenOpt::Default.<br>
><br>
> What happens if you make the following modification to your setup?<br>
><br>
> auto JTMB = llvm::orc::JITTargetMachineBuilder::detectHost();<br>
> JTMB->setCodeGenOptLevel(CodeGenOpt::Default); // <-- Explicitly set Codegen opt level<br>
> auto dataLayout = JTMB->getDefaultDataLayoutForTarget();<br>
><br>
<br>
No change.<br>
<br>
Regards<br>
</blockquote></div></div></div></div></div></div>