<div><div dir="auto">I think the O(N^2) behavior is probably the worst culprit, but I don’t really know anything about Tablegen to fix it.  And I think that speaks to another problem: not many people do.  It would be great if someone knowledgeable about Tablegen could look at it with the specific aim of improving the algorithmic complexity </div></div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jul 2, 2019 at 1:31 AM Simon Pilgrim 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:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  
    
  
  <div text="#000000" bgcolor="#FFFFFF">
    <p>Much of this has been discussed (over many, many years) on
      <a class="m_2461551453453941787moz-txt-link-freetext" href="https://bugs.llvm.org/show_bug.cgi?id=28222" target="_blank">https://bugs.llvm.org/show_bug.cgi?id=28222</a></p>
    <p>Some of the issues that were identified included:</p>
    <p>1 - Poor tablegen dependency handling leading to unexpected
      rebuilds.</p>
    <p>2 - Debug STL iterator checks taking an insane amount of time
      (might be MSVC specific).</p>
    <p>3 - Lack of parallelization of custom commands (XCode and VS
      builds) - VS at least has a recent (VS2017+?) 'build custom tools
      in parallel' option that can be enabled per project file - we
      should investigate setting that automatically. <br>
    </p>
    <p>4 - A lot of O(N^2), or worse, code that has built up over the
      years.</p>
    <p>5 - Poor STL type selection resulting it excessive
      iteration/access times.</p>
    <p>Running a profiler every so often helps find some quick
      improvements but its not really fixing these core problems.</p></div><div text="#000000" bgcolor="#FFFFFF"><p><br>
    </p>
    <p>Simon.<br>
    </p>
    <p>On 01/07/2019 21:05, Chris Bieneman via llvm-dev wrote:<br>
    </p>
    <blockquote type="cite">
      
      In CMake 3.7 and later the Ninja generator can handle depfiles
      which gives us correct and accurate dependencies for tablegen, and
      we do use that support if it is available.
      <div><br>
      </div>
      <div>I'm surprised CMake has never extended that support
        to the Makefile generator, but unsurprised it isn't supported in
        the IDE generators. I'm reasonably confident that you can't add
        that support to Xcode without treating tablegen as an extra
        compiler, which (I believe) requires an Xcode plugin. Even if
        that isn't the case the Xcode build system's extensibility is
        largely undocumented and I'm sure it would be very challenging
        to extend it in this way.</div>
      <div><br>
      </div>
      <div>I think it would be possible to add that support to
        CMake's MSBuild generator for Visual Studio, but I'm not sure
        why you would. It seems like Microsoft's preferred approach to
        using CMake with Visual Studio is with ninja as the build tool
        via the CMake Server integration.</div>
      <div><br>
      </div>
      <div>-Chris<br>
        <div><br>
          <blockquote type="cite">
            <div>On Jul 1, 2019, at 2:57 PM, David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>> wrote:</div>
            <br class="m_2461551453453941787Apple-interchange-newline">
            <div>
              <div dir="ltr">If someone can manage it, it
                wouldn't be a bad thing - obviously open up more
                parallelism (I don't know how much of LLVM can be built
                before you hit everything that needs tblgen run - I
                guess libSupport and some other bits)</div>
              <br>
              <div class="gmail_quote">
                <div dir="ltr" class="gmail_attr">On Mon, Jul 1, 2019 at
                  12:54 PM Zakharin, Vyacheslav P via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">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="RU">
                    <div class="m_2461551453453941787gmail-m_7961363046099572722WordSection1">
                      <p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)" lang="EN-US">[resending to the whole
                          list]</span></p>
                      <p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)" lang="EN-US"> </span></p>
                      <p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)" lang="EN-US">I wonder if we can stop
                          rebuilding TD files unconditionally, i.e.
                          generate dependencies for TD files based on
                          include directives and just allow the build
                          system do its job?  Would that solve most of
                          the build time issues?</span></p>
                      <p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)" lang="EN-US"> </span></p>
                      <p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)" lang="EN-US">Thanks,</span></p>
                      <p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)" lang="EN-US">Slava</span></p>
                      <p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"> </span></p>
                      <p class="MsoNormal"><a name="m_2461551453453941787_m_7961363046099572722__MailEndCompose"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"> </span></a></p>
                      <div>
                        <div style="border-right:none;border-bottom:none;border-left:none;border-top:1pt solid rgb(225,225,225);padding:3pt 0in 0in">
                          <p class="MsoNormal"><a name="m_2461551453453941787_m_7961363046099572722______replyseparator"></a><b><span style="font-size:11pt;font-family:Calibri,sans-serif" lang="EN-US">From:</span></b><span style="font-size:11pt;font-family:Calibri,sans-serif" lang="EN-US"> llvm-dev [mailto:<a href="mailto:llvm-dev-bounces@lists.llvm.org" target="_blank">llvm-dev-bounces@lists.llvm.org</a>]
                              <b>On Behalf Of </b>Chris
                              Bieneman via llvm-dev<br>
                              <b>Sent:</b> Monday, July 1, 2019
                              10:35 AM<br>
                              <b>To:</b> Joan Lluch <<a href="mailto:joan.lluch@icloud.com" target="_blank">joan.lluch@icloud.com</a>><br>
                              <b>Cc:</b> llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>><br>
                              <b>Subject:</b> Re: [llvm-dev]
                              Tablegen ridiculously slow when compiling
                              for Debug</span></p>
                        </div>
                      </div>
                      <p class="MsoNormal"> </p>
                      <div>
                        <p class="MsoNormal">Hey Joan,</p>
                      </div>
                      <div>
                        <p class="MsoNormal"> </p>
                      </div>
                      <div>
                        <p class="MsoNormal">When looking for build
                          support it is really useful to include a bunch
                          of information about your build up front.
                          Knowing that you are on macOS, and using the
                          Xcode generator are really useful.</p>
                      </div>
                      <div>
                        <p class="MsoNormal"> </p>
                      </div>
                      <div>
                        <p class="MsoNormal">On macOS, BUILD_SHARED_LIBS
                          won’t really help much because the default
                          linker (ld64) is pretty good. Using an IDE
                          generator and setting
                          LLVM_USE_OPTIMIZED_TABLEGEN will kill your
                          release builds.</p>
                      </div>
                      <div>
                        <p class="MsoNormal"> </p>
                      </div>
                      <div>
                        <p class="MsoNormal">In general Xcode takes
                          2x-3x longer than Ninja for incremental
                          builds, and 1.5x-2x as long for clean builds.
                          Lots of people use the Xcode generator to
                          create a project file for navigation and
                          editing, but most people I know doing LLVM
                          development on macOS use Ninja for their
                          builds.</p>
                      </div>
                      <div>
                        <p class="MsoNormal"> </p>
                      </div>
                      <div>
                        <p class="MsoNormal">-Chris</p>
                      </div>
                      <div>
                        <p class="MsoNormal" style="margin-bottom:12pt"><br>
                          On Jun 30, 2019, at 12:18 PM, Joan Lluch via
                          llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>>
                          wrote:</p>
                      </div>
                      <blockquote style="margin-top:5pt;margin-bottom:5pt">
                        <div>
                          <p class="MsoNormal">Hi Greg,</p>
                          <div>
                            <p class="MsoNormal"> </p>
                          </div>
                          <div>
                            <p class="MsoNormal">I tried to setup Ninja
                              before on my mac but I mush have done
                              something wrong and I didn’t manage to get
                              it work. I’m not familiarised at all with
                              the procedures involved. I may try that
                              again to see If I have some luck though.
                              It’s a pity that LLVM is not particularly
                              friendly with familiar IDEs such as xCode
                              on macs and Visual Studio on windows.</p>
                          </div>
                          <div>
                            <p class="MsoNormal"> </p>
                          </div>
                          <div>
                            <p class="MsoNormal">John</p>
                          </div>
                          <div>
                            <p class="MsoNormal"> </p>
                            <div>
                              <blockquote style="margin-top:5pt;margin-bottom:5pt">
                                <div>
                                  <p class="MsoNormal">On 30 Jun 2019,
                                    at 17:43, Greg Bedwell <<a href="mailto:gregbedwell@gmail.com" target="_blank">gregbedwell@gmail.com</a>>
                                    wrote:</p>
                                </div>
                                <p class="MsoNormal"> </p>
                                <div>
                                  <div>
                                    <div>
                                      <p class="MsoNormal">This is also
                                        the case with the Visual Studio
                                        generators. Custom commands in a
                                        single cmake file essentially
                                        get written out line by line
                                        into a single batch file that
                                        gets processed as a custom build
                                        step. In the VS case this means
                                        that it can, for example, run
                                        X86 and Aarch64 tablegen steps
                                        in parallel with each other but
                                        all of the individual X86
                                        invocations get processed
                                        serially. I can well imagine
                                        that the Xcode situation is
                                        similar although I've no
                                        experience with it myself to
                                        know for sure.</p>
                                    </div>
                                  </div>
                                  <div>
                                    <p class="MsoNormal"> </p>
                                  </div>
                                  <div>
                                    <p class="MsoNormal">As previously
                                      mentioned, the best solution is
                                      probably to try to adjust your
                                      workflow to use the Ninja (
                                    </p>
                                    <div>
                                      <p class="MsoNormal"><a href="https://ninja-build.org/" target="_blank">https://ninja-build.org</a></p>
                                    </div>
                                    <p class="MsoNormal"> ) CMake
                                      generator if at all possible. 
                                      It's a bit of an adjustment but it
                                      does work very nicely with the
                                      LLVM build system.</p>
                                  </div>
                                  <div>
                                    <p class="MsoNormal"> </p>
                                  </div>
                                  <div>
                                    <p class="MsoNormal">-Greg</p>
                                  </div>
                                  <div>
                                    <p class="MsoNormal"> </p>
                                  </div>
                                  <div>
                                    <p class="MsoNormal"> </p>
                                  </div>
                                  <div>
                                    <div>
                                      <div>
                                        <p class="MsoNormal">On Sun, 30
                                          Jun 2019 at 12:08, Nicolai
                                          Hähnle via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>>
                                          wrote:</p>
                                      </div>
                                      <blockquote style="border-top:none;border-right:none;border-bottom:none;border-left:1pt solid rgb(204,204,204);padding:0in 0in 0in 6pt;margin-left:4.8pt;margin-right:0in">
                                        <p class="MsoNormal">Are you
                                          saying that the TableGen
                                          execution isn't parallelized?
                                          That
                                          <br>
                                          seems like an obvious
                                          Xcode-specific problem...<br>
                                          <br>
                                          The TableGen executions are
                                          parallelized with cmake/ninja
                                          just fine.<br>
                                          <br>
                                          Cheers,<br>
                                          Nicolai<br>
                                          <br>
                                          On 30.06.19 11:28, Joan Lluch
                                          via llvm-dev wrote:<br>
                                          > Hi Praveen,<br>
                                          > <br>
                                          > Thanks for the tip, but
                                          Xcode seems to spend all the
                                          time running <br>
                                          > tablegen "custom shell
                                          scripts", one by one at a
                                          time, not linking. <br>
                                          > Linking is actually very
                                          fast, possibly less than a
                                          second. The <br>
                                          > “scripts” that take
                                          longer are
                                           “AArch64CommonTableGen" and <br>
                                          > “AMDGPUCommonTableGen”. 
                                          As said this is on LLVM 9.0.<br>
                                          > <br>
                                          > However, on LLVM 7.0.1,
                                          the same process takes just
                                          5-6 seconds in <br>
                                          > total, with individual
                                          “scripts” taking significantly
                                          less than 1 second <br>
                                          > each. There must be some
                                          difference between LLVM 9.0
                                          and LLVM 7.0 that <br>
                                          > might cause this (?)<br>
                                          > <br>
                                          > John<br>
                                          > <br>
                                          > <br>
                                          >> On 30 Jun 2019, at
                                          11:17, Praveen Velliengiri <br>
                                          >> <<a href="mailto:praveenvelliengiri@gmail.com" target="_blank">praveenvelliengiri@gmail.com</a>
                                          <mailto:<a href="mailto:praveenvelliengiri@gmail.com" target="_blank">praveenvelliengiri@gmail.com</a>>>
                                          <br>
                                          >> wrote:<br>
                                          >><br>
                                          >> *<br>
                                          >> *<br>
                                          >> cmake
                                          *BUILD_SHARED_LIBS* option, it
                                          builds llvm as .so not as .a.
                                          It <br>
                                          >> will use less memory
                                          during linking so you can
                                          increase the link <br>
                                          >> threads and your
                                          build time will be lesser.<br>
                                          >> Check this in : <a href="https://llvm.org/docs/CMake.html" target="_blank">https://llvm.org/docs/CMake.html</a><br>
                                          >><br>
                                          >> **<br>
                                          >> **<br>
                                          >><br>
                                          >> On Sun, 30 Jun 2019
                                          at 14:42, Joan Lluch <<a href="mailto:joan.lluch@icloud.com" target="_blank">joan.lluch@icloud.com</a>
                                          <br>
                                          >> <mailto:<a href="mailto:joan.lluch@icloud.com" target="_blank">joan.lluch@icloud.com</a>>>
                                          wrote:<br>
                                          >><br>
                                          >>     Hi Praveen,<br>
                                          >><br>
                                          >>     Please, can you
                                          elaborate on this?. What do do
                                          mean by “building<br>
                                          >>     as shared
                                          objects”.<br>
                                          >><br>
                                          >>     Thanks,<br>
                                          >><br>
                                          >>     John<br>
                                          >><br>
                                          >><br>
                                          >><br>
                                          >>>     On 30 Jun
                                          2019, at 07:32, Praveen
                                          Velliengiri<br>
                                          >>>     <<a href="mailto:praveenvelliengiri@gmail.com" target="_blank">praveenvelliengiri@gmail.com</a><br>
                                          >>>     <mailto:<a href="mailto:praveenvelliengiri@gmail.com" target="_blank">praveenvelliengiri@gmail.com</a>>>
                                          wrote:<br>
                                          >>><br>
                                          >>>     Maybe try
                                          building llvm as a shared
                                          objects..<br>
                                          >>><br>
                                          >>>     On Jun 30,
                                          2019 1:30 AM, "Joan Lluch via
                                          llvm-dev"<br>
                                          >>>     <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>
                                          <mailto:<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>>>
                                          wrote:<br>
                                          >>><br>
                                          >>>         Hi
                                          Florian,<br>
                                          >>><br>
                                          >>>         Ok, I ran
                                          this:<br>
                                          >>><br>
                                          >>>         cmake -S
                                          LLVM
                                          -DCMAKE_INSTALL_PREFIX=INSTALL<br>
                                          >>>       
                                           -DLLVM_OPTIMIZED_TABLEGEN=On
                                          -G Xcode<br>
                                          >>><br>
                                          >>>         Compiled
                                          it again from clean, and the
                                          situation is worse than<br>
                                          >>>         before.
                                          Incremental builds take an
                                          incredible amount of time<br>
                                          >>>         stuck in
                                          running Tablegen scripts for
                                          all targets. Now this<br>
                                          >>>         happens
                                          both in Release and Debug
                                          configurations. Just before<br>
                                          >>>         this, at
                                          least Release compiled fine,
                                          but that’s no longer<br>
                                          >>>         the case.<br>
                                          >>><br>
                                          >>>         Any other
                                          suggestions?  What could
                                          actually cause this?<br>
                                          >>><br>
                                          >>>         Thanks<br>
                                          >>>         John<br>
                                          >>><br>
                                          >>><br>
                                          >>><br>
                                          >>>>         On 29
                                          Jun 2019, at 19:37, Florian
                                          Hahn<br>
                                          >>>>         <<a href="mailto:florian_hahn@apple.com" target="_blank">florian_hahn@apple.com</a>
                                          <mailto:<a href="mailto:florian_hahn@apple.com" target="_blank">florian_hahn@apple.com</a>>>
                                          wrote:<br>
                                          >>>><br>
                                          >>>>         Hi,<br>
                                          >>>><br>
                                          >>>>>       
                                           On Jun 29, 2019, at 18:26,
                                          Joan Lluch via llvm-dev<br>
                                          >>>>>       
                                           <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>
                                          <mailto:<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>>><br>
                                          >>>>>       
                                           wrote:<br>
                                          >>>>><br>
                                          >>>>>       
                                           Hi all,<br>
                                          >>>>><br>
                                          >>>>>       
                                           On LLVM version 7.0.1,
                                          incremental builds are very
                                          fast for<br>
                                          >>>>>       
                                           both Release and Debug. I’m
                                          compiling with Xcode<br>
                                          >>>>><br>
                                          >>>>>         I
                                          recently downloaded LLVM 9.0
                                          from the LLVM-mirror Github<br>
                                          >>>>>       
                                           repository and found that
                                          Incremental "Debug” builds
                                          take a<br>
                                          >>>>>       
                                           ridiculously long time due to
                                          Tablegen taking ages<br>
                                          >>>>>       
                                           (literally more than 10
                                          minutes) to generate files.
                                          This<br>
                                          >>>>>       
                                           makes it totally unusable for
                                          debug purposes. However,<br>
                                          >>>>>       
                                           incremental ‘Release’ builds
                                          only take a few seconds.<br>
                                          >>>>><br>
                                          >>>>>       
                                           Why is that?. Any
                                          suggestions?.<br>
                                          >>>><br>
                                          >>>><br>
                                          >>>><br>
                                          >>>>         You
                                          could give setting
                                          LLVM_OPTIMIZED_TABLEGEN a try<br>
                                          >>>>         (<a href="https://llvm.org/docs/CMake.html" target="_blank">https://llvm.org/docs/CMake.html</a>).<br>
                                          >>>><br>
                                          >>>>       
                                           Cheers,<br>
                                          >>>>       
                                           Florian<br>
                                          >>><br>
                                          >>><br>
                                          >>>       
                                           _______________________________________________<br>
                                          >>>         LLVM
                                          Developers mailing list<br>
                                          >>>         <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>
                                          <mailto:<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" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
                                          >>><br>
                                          >><br>
                                          > <br>
                                          > <br>
                                          >
                                          _______________________________________________<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" target="_blank">
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
                                          > <br>
                                          <br>
                                          -- <br>
                                          Lerne, wie die Welt wirklich
                                          ist,<br>
                                          Aber vergiss niemals, wie sie
                                          sein sollte.<br>
_______________________________________________<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" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a></p>
                                      </blockquote>
                                    </div>
                                  </div>
                                </div>
                              </blockquote>
                            </div>
                            <p class="MsoNormal"> </p>
                          </div>
                        </div>
                      </blockquote>
                      <blockquote style="margin-top:5pt;margin-bottom:5pt">
                        <div>
                          <p class="MsoNormal">_______________________________________________<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" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a></p>
                        </div>
                      </blockquote>
                    </div>
                  </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>
            </div>
          </blockquote>
        </div>
        <br>
      </div>
      <br>
      <fieldset class="m_2461551453453941787mimeAttachmentHeader"></fieldset>
      <pre class="m_2461551453453941787moz-quote-pre">_______________________________________________
LLVM Developers mailing list
<a class="m_2461551453453941787moz-txt-link-abbreviated" href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>
<a class="m_2461551453453941787moz-txt-link-freetext" href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a>
</pre>
    </blockquote>
  </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></div>