<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div><div></div><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><div class=""><br class=""></div></div></div><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><div class=""><br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><div class=""><div class="">(although I find this a little revolting ;-) that is passed to the CompilerInstance, which then hands it down to GenerateModuleAction/GeneratePCHAction, which asks the Factory to generate an new ModuleContainerGenerator instance which is actually an LLVModuleContainerGenerator. This way Frontend only needs to link against whereever the ModuleContainerGenerator base class is defined and each tool can decide which backend to use.</div><span class=""><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><div class=""><br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">
> If not, I don't think we have any other option than to grow a Frontend->CodeGen dependency, which in turn will be terrible for people who want to use our frontend with a different backend...<br class="">
<br class="">
</span>Is that a hypothetical scenario or are there any such users out there?</blockquote><div class=""><br class=""></div><div class="">I don't have concrete knowledge of anyone doing this today, but enough people have asked about this that it's not unreasonable to think that someone might have actually done it.</div><div class=""> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I understand there are tools like clang-format/modernize/... which after this change have to link against the LLVM targets in order to generate clang-compatible modules; but are there any non-LLVM compilers that use clang as a frontend?</blockquote><div class=""><br class=""></div><div class="">I think there are, but I'm not sure if they all do this by converting LLVM IR to their own IR or whether some of them go straight from a Clang AST. Whether or not such compilers exist today, we should try to avoid creating barriers for people who want to do this in the future.</div><div class=""><br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">
> Here is a graph of (a simplified subset of) the dependencies after this commit:<br class="">
> - Pretty much all of CodeGen depends on CodeGenOptions, which is currently part of Frontend.<br class="">
> - BackendUtil and CodeGenAction depend on both CodeGen and Frontend.<br class="">
> - CodeGenModuleContainer introduces a cyclic dependency between Frontend and CodeGen.<br class="">
><br class="">
</span>> <before.png><br class="">
<span class="">><br class="">
> The above cycle can be resolved by reversing the CodeGen->Frontend dependency and splitting out the common dependencies CodeGenOptions and frontend::utils::BuryPointer into a separate library that I’m calling FrontendSupport for lack of a better name.<br class="">
><br class="">
> The right place for CodeGenOptions is probably Basic, alongside LangOptions, TargetOptions, CommentOptions, etc.<br class="">
<br class="">
</span>That sounds like a good idea; I might also be able to move it into CodeGen itself.<br class="">
<span class="">><br class="">
> After this, the only remaining CodeGen->Frontend dependencies are CodeGen/BackendUtil.cpp and CodeGen/CodeGenAction.cpp:<br class="">
> - CodeGenAction looks like it could safely be moved into FrontendTool, which is its only user.<br class="">
><br class="">
> I don't think that's necessarily a good idea: CodeGenAction is tightly coupled to CodeGen and only very loosely coupled to the frontend.<br class="">
<br class="">
</span>I agree that it is tightly coupled to CodeGen, but it is also tightly coupled to CompilerInstance, which has its tentacles all over Frontend so it needs to move somewhere to break the cycle. Do you see any specific problems with having CodeGenAction in FrontendTool?<br class=""></blockquote><div class=""><br class=""></div><div class="">No specific problem, only a general malaise: we deliberately isolate all the parts of Clang that touch LLVM IR in lib/CodeGen; this change would violate that notional encapsulation.</div></div></div></div></div></blockquote><div class=""><br class=""></div></span><div class="">Okay, separating out everything that touches IR that makes sense. I think it should be possible to remove all references to CompilerInstance from CodeGenAction; it appears to be only used as a holder of the various options and the DiagnosticsEngine, which would allow us to leave it in CodeGen.</div><div class=""><br class=""></div><div class="">I’ll try that.</div></div></div></blockquote><div class=""><br class=""></div><div class="">Thanks!</div><div class=""> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><div class=""><span class="HOEnZb"><font color="#888888" class=""><div class="">-- adrian</div></font></span><span class=""><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><div class=""><br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
thanks for the feedback!<br class="">
adrian<br class="">
<span class="">><br class="">
> - BackendUtil can stay were it is, it is needed by CodeGenAction and (via CodeGenModuleContainer) by Frontend. The dependency on Frontend can be eliminated by splitting BuryPointer out from Utils.<br class="">
> The new picture then looks like this:<br class="">
><br class="">
</span>> <after.png><br class="">
<div class=""><div class="">><br class="">
> I’ll try and implement it this way; hopefully I didn’t miss any other edges in the graph.<br class="">
> -- adrian<br class="">
><br class="">
>><br class="">
>> thanks for noticing!<br class="">
>> -- adrian<br class="">
><br class="">
><br class="">
<br class="">
</div></div></blockquote></div><br class=""></div></div>
</div></blockquote></span></div><br class=""></div></blockquote></div><br class=""></div></div>
</div></blockquote></div><br class=""></div></div></blockquote></div><br class=""></body></html>