<html><head><style>body{font-family:Helvetica,Arial;font-size:13px}</style></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;"><br></div><p style="color:#000;">On April 25, 2014 at 12:16:05 PM, Eric Christopher (<a href="mailto:echristo@gmail.com">echristo@gmail.com</a>) wrote:</p> <div><blockquote type="cite" class="clean_bq" style="color: rgb(0, 0, 0); font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);"><span><div><div></div><div>><span class="Apple-converted-space"> </span><br>> This is patently false except for the single cpu that changed.<span class="Apple-converted-space"> </span><br><br>(On a separate note it seems that Mail is being weird about quoting,<span class="Apple-converted-space"> </span><br>it works sometimes, it doesn't otherwise, anyhow :)...<span class="Apple-converted-space"> </span><br><br>><span class="Apple-converted-space"> </span><br>> I think it would be useful if you were more specific about what is false<span class="Apple-converted-space"> </span><br>> about the above statement. I think this is worth clearing up.<span class="Apple-converted-space"> </span><br><br>Fair enough.<span class="Apple-converted-space"> </span><br><br>><span class="Apple-converted-space"> </span><br>> The MCJIT doesn't require the module to have a target set, and it doesn't<span class="Apple-converted-space"> </span><br>> require the caller to set the target of the ExecutionEngine. It also<span class="Apple-converted-space"> </span><br>> doesn't require the client to set Arch or CPU. This is true both in the C<span class="Apple-converted-space"> </span><br>> and C++ APIs. EngineBuilder will set these things for you to sensible<span class="Apple-converted-space"> </span><br>> defaults on all platforms *except* ARM64, where things get murky. For<span class="Apple-converted-space"> </span><br>> example on X86, even if you don't explicitly set the CPU the MCJIT will<span class="Apple-converted-space"> </span><br>> figure out what CPU you're running on along with all of its relevant<span class="Apple-converted-space"> </span><br>> features (whether it has AVX, etc) and it will generate code accordingly.<span class="Apple-converted-space"> </span><br>> Also, the C API currently only lets you set the target on the module, not<span class="Apple-converted-space"> </span><br>> the ExecutionEngine, and so this prevents you from setting the Arch+CPU.<span class="Apple-converted-space"> </span><br>><span class="Apple-converted-space"> </span><br>> The MCJIT has explicit code to set the target/CPU/etc to a sensible default<span class="Apple-converted-space"> </span><br>> that is appropriate for JITing code into the process in which the JIT itself<span class="Apple-converted-space"> </span><br>> runs.<span class="Apple-converted-space"> </span><br><br>Actually, it'll use the module if you don't set anything:<span class="Apple-converted-space"> </span><br><br>TargetMachine *EngineBuilder::selectTarget() {<span class="Apple-converted-space"> </span><br>Triple TT;<span class="Apple-converted-space"> </span><br><br>// MCJIT can generate code for remote targets, but the old JIT and Interpreter<span class="Apple-converted-space"> </span><br>// must use the host architecture.<span class="Apple-converted-space"> </span><br>if (UseMCJIT && WhichEngine != EngineKind::Interpreter && M)<span class="Apple-converted-space"> </span><br>TT.setTriple(M->getTargetTriple());<span class="Apple-converted-space"> </span><br><br>return selectTarget(TT, MArch, MCPU, MAttrs);<span class="Apple-converted-space"> </span><br>}<span class="Apple-converted-space"> </span><br><br>which seems to be what you'd want?<span class="Apple-converted-space"> </span></div></div></span></blockquote></div><p>If you don't set the target on the module, then it gets the process triple.  Hence, you get target := host if your code never says anything about the target triple in either the module creation or MCJIT initialization.</p><p>And that's probably a good thing since currently the LLVM C API doesn't expose getting the process triple, so if we required C API clients to set the target triple without giving them a way of getting the right one, then the whole C API would become a kind of cruel joke.</p><div><div><blockquote type="cite" class="clean_bq" style="color: rgb(0, 0, 0); font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);"><span><div><div>I'm not sure in your use case how<span class="Apple-converted-space"> </span><br>things aren't working out. The backend code now looks the same for<span class="Apple-converted-space"> </span><br>both X86, arm, and arm64 so why it's failing should probably be looked<span class="Apple-converted-space"> </span><br>at. This change merely exposed something else.<span class="Apple-converted-space"> </span></div></div></span></blockquote></div><p>I'm not totally clear on what the deal is on ARM64 other than things get murky because not all of the bits in MCJIT and elsewhere know that CPU/Arch/Attrs are things that should be inferred to match the host, and failing to set those things causes weirdness.  I'm annoyed that it went from "works for me" to "busted for me" but I'm not interested in pushing that point further.</p><p>To me the purpose of this thread is to try to establish protocol for changes that affect MCJIT going forward.  It's good that you agree that the MCJIT C API shouldn't require the client to ever set the CPU/Attrs/Arch as a prerequisite to using it and that we shouldn't change the API to require that.  I also think that we should continue to allow the client to not even set the target on the module, allowing MCJIT to infer it to be the process triple.  That should all Just Work.</p><div><div><blockquote type="cite" class="clean_bq" style="color: rgb(0, 0, 0); font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);"><span><div><div><br><br>> It would be useful if you were more specific about what you think is false<span class="Apple-converted-space"> </span><br>> about any of this.<span class="Apple-converted-space"> </span><br><br>^ :)<span class="Apple-converted-space"> </span><br><br>><span class="Apple-converted-space"> </span><br>> Anyway, I would be against any change to the C API that would require JIT<span class="Apple-converted-space"> </span><br>> clients to set the CPU, Arch, or target triple as a prerequisite to using<span class="Apple-converted-space"> </span><br>> the MCJIT. This would be a breaking change to stable API and the MCJIT<span class="Apple-converted-space"> </span><br>> should continue to do as it always did: target the host by default.<span class="Apple-converted-space"> </span><br>><span class="Apple-converted-space"> </span><br><br>Agreed. (I know this suprises you).<span class="Apple-converted-space"> </span><br><br>> It's only stable between releases. Anything else is anything goes. As<span class="Apple-converted-space"> </span><br>> I don't believe it was in 3.4...<span class="Apple-converted-space"> </span><br>><span class="Apple-converted-space"> </span><br>> MCJIT C API was in 3.4.<span class="Apple-converted-space"> </span><br>><span class="Apple-converted-space"> </span><br><br>All of it or parts? Either way, good to know.<span class="Apple-converted-space"> </span></div></div></span></blockquote></div><p>Basically all.  There were changes since then to clean things up in a non-breaking way, like adding enums for some of the gnarly C function types in the memory management callbacks.</p><p>-Filip</p><p><br></p><div><blockquote type="cite" class="clean_bq" style="color: rgb(0, 0, 0); font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255);"><span><div><div><br><br>-eric<span class="Apple-converted-space"> </span><br></div></div></span></blockquote></div></div></div></body></html>