Skip to content
  1. Dec 19, 2012
  2. Dec 13, 2012
    • Quentin Colombet's avatar
      Take into account minimize size attribute in the inliner. · c0dba203
      Quentin Colombet authored
      Better controls the inlining of functions when the caller function has MinSize attribute.
      Basically, when the caller function has this attribute, we do not "force" the inlining
      of callee functions carrying the InlineHint attribute (i.e., functions defined with
      inline keyword)
      
      llvm-svn: 170065
      c0dba203
  3. Dec 03, 2012
    • Chandler Carruth's avatar
      Use the new script to sort the includes of every file under lib. · ed0881b2
      Chandler Carruth authored
      Sooooo many of these had incorrect or strange main module includes.
      I have manually inspected all of these, and fixed the main module
      include to be the nearest plausible thing I could find. If you own or
      care about any of these source files, I encourage you to take some time
      and check that these edits were sensible. I can't have broken anything
      (I strictly added headers, and reordered them, never removed), but they
      may not be the headers you'd really like to identify as containing the
      API being implemented.
      
      Many forward declarations and missing includes were added to a header
      files to allow them to parse cleanly when included first. The main
      module rule does in fact have its merits. =]
      
      llvm-svn: 169131
      ed0881b2
  4. Oct 10, 2012
  5. Oct 09, 2012
  6. Oct 08, 2012
  7. Sep 26, 2012
  8. Sep 13, 2012
  9. Aug 29, 2012
    • Benjamin Kramer's avatar
      Make MemoryBuiltins aware of TargetLibraryInfo. · 8bcc9711
      Benjamin Kramer authored
      This disables malloc-specific optimization when -fno-builtin (or -ffreestanding)
      is specified. This has been a problem for a long time but became more severe
      with the recent memory builtin improvements.
      
      Since the memory builtin functions are used everywhere, this required passing
      TLI in many places. This means that functions that now have an optional TLI
      argument, like RecursivelyDeleteTriviallyDeadFunctions, won't remove dead
      mallocs anymore if the TLI argument is missing. I've updated most passes to do
      the right thing.
      
      Fixes PR13694 and probably others.
      
      llvm-svn: 162841
      8bcc9711
  10. Jun 02, 2012
  11. May 23, 2012
  12. Apr 11, 2012
  13. Apr 01, 2012
  14. Mar 31, 2012
    • Chandler Carruth's avatar
      Remove a bunch of empty, dead, and no-op methods from all of these · edd2826f
      Chandler Carruth authored
      interfaces. These methods were used in the old inline cost system where
      there was a persistent cache that had to be updated, invalidated, and
      cleared. We're now doing more direct computations that don't require
      this intricate dance. Even if we resume some level of caching, it would
      almost certainly have a simpler and more narrow interface than this.
      
      llvm-svn: 153813
      edd2826f
    • Chandler Carruth's avatar
      Initial commit for the rewrite of the inline cost analysis to operate · 0539c071
      Chandler Carruth authored
      on a per-callsite walk of the called function's instructions, in
      breadth-first order over the potentially reachable set of basic blocks.
      
      This is a major shift in how inline cost analysis works to improve the
      accuracy and rationality of inlining decisions. A brief outline of the
      algorithm this moves to:
      
      - Build a simplification mapping based on the callsite arguments to the
        function arguments.
      - Push the entry block onto a worklist of potentially-live basic blocks.
      - Pop the first block off of the *front* of the worklist (for
        breadth-first ordering) and walk its instructions using a custom
        InstVisitor.
      - For each instruction's operands, re-map them based on the
        simplification mappings available for the given callsite.
      - Compute any simplification possible of the instruction after
        re-mapping, and store that back int othe simplification mapping.
      - Compute any bonuses, costs, or other impacts of the instruction on the
        cost metric.
      - When the terminator is reached, replace any conditional value in the
        terminator with any simplifications from the mapping we have, and add
        any successors which are not proven to be dead from these
        simplifications to the worklist.
      - Pop the next block off of the front of the worklist, and repeat.
      - As soon as the cost of inlining exceeds the threshold for the
        callsite, stop analyzing the function in order to bound cost.
      
      The primary goal of this algorithm is to perfectly handle dead code
      paths. We do not want any code in trivially dead code paths to impact
      inlining decisions. The previous metric was *extremely* flawed here, and
      would always subtract the average cost of two successors of
      a conditional branch when it was proven to become an unconditional
      branch at the callsite. There was no handling of wildly different costs
      between the two successors, which would cause inlining when the path
      actually taken was too large, and no inlining when the path actually
      taken was trivially simple. There was also no handling of the code
      *path*, only the immediate successors. These problems vanish completely
      now. See the added regression tests for the shiny new features -- we
      skip recursive function calls, SROA-killing instructions, and high cost
      complex CFG structures when dead at the callsite being analyzed.
      
      Switching to this algorithm required refactoring the inline cost
      interface to accept the actual threshold rather than simply returning
      a single cost. The resulting interface is pretty bad, and I'm planning
      to do lots of interface cleanup after this patch.
      
      Several other refactorings fell out of this, but I've tried to minimize
      them for this patch. =/ There is still more cleanup that can be done
      here. Please point out anything that you see in review.
      
      I've worked really hard to try to mirror at least the spirit of all of
      the previous heuristics in the new model. It's not clear that they are
      all correct any more, but I wanted to minimize the change in this single
      patch, it's already a bit ridiculous. One heuristic that is *not* yet
      mirrored is to allow inlining of functions with a dynamic alloca *if*
      the caller has a dynamic alloca. I will add this back, but I think the
      most reasonable way requires changes to the inliner itself rather than
      just the cost metric, and so I've deferred this for a subsequent patch.
      The test case is XFAIL-ed until then.
      
      As mentioned in the review mail, this seems to make Clang run about 1%
      to 2% faster in -O0, but makes its binary size grow by just under 4%.
      I've looked into the 4% growth, and it can be fixed, but requires
      changes to other parts of the inliner.
      
      llvm-svn: 153812
      0539c071
  15. Mar 27, 2012
    • Chandler Carruth's avatar
      Make a seemingly tiny change to the inliner and fix the generated code · b9e35fbc
      Chandler Carruth authored
      size bloat. Unfortunately, I expect this to disable the majority of the
      benefit from r152737. I'm hopeful at least that it will fix PR12345. To
      explain this requires... quite a bit of backstory I'm afraid.
      
      TL;DR: The change in r152737 actually did The Wrong Thing for
      linkonce-odr functions. This change makes it do the right thing. The
      benefits we saw were simple luck, not any actual strategy. Benchmark
      numbers after a mini-blog-post so that I've written down my thoughts on
      why all of this works and doesn't work...
      
      To understand what's going on here, you have to understand how the
      "bottom-up" inliner actually works. There are two fundamental modes to
      the inliner:
      
      1) Standard fixed-cost bottom-up inlining. This is the mode we usually
         think about. It walks from the bottom of the CFG up to the top,
         looking at callsites, taking information about the callsite and the
         called function and computing th expected cost of inlining into that
         callsite. If the cost is under a fixed threshold, it inlines. It's
         a touch more complicated than that due to all the bonuses, weights,
         etc. Inlining the last callsite to an internal function gets higher
         weighth, etc. But essentially, this is the mode of operation.
      
      2) Deferred bottom-up inlining (a term I just made up). This is the
         interesting mode for this patch an r152737. Initially, this works
         just like mode #1, but once we have the cost of inlining into the
         callsite, we don't just compare it with a fixed threshold. First, we
         check something else. Let's give some names to the entities at this
         point, or we'll end up hopelessly confused. We're considering
         inlining a function 'A' into its callsite within a function 'B'. We
         want to check whether 'B' has any callers, and whether it might be
         inlined into those callers. If so, we also check whether inlining 'A'
         into 'B' would block any of the opportunities for inlining 'B' into
         its callers. We take the sum of the costs of inlining 'B' into its
         callers where that inlining would be blocked by inlining 'A' into
         'B', and if that cost is less than the cost of inlining 'A' into 'B',
         then we skip inlining 'A' into 'B'.
      
      Now, in order for #2 to make sense, we have to have some confidence that
      we will actually have the opportunity to inline 'B' into its callers
      when cheaper, *and* that we'll be able to revisit the decision and
      inline 'A' into 'B' if that ever becomes the correct tradeoff. This
      often isn't true for external functions -- we can see very few of their
      callers, and we won't be able to re-consider inlining 'A' into 'B' if
      'B' is external when we finally see more callers of 'B'. There are two
      cases where we believe this to be true for C/C++ code: functions local
      to a translation unit, and functions with an inline definition in every
      translation unit which uses them. These are represented as internal
      linkage and linkonce-odr (resp.) in LLVM. I enabled this logic for
      linkonce-odr in r152737.
      
      Unfortunately, when I did that, I also introduced a subtle bug. There
      was an implicit assumption that the last caller of the function within
      the TU was the last caller of the function in the program. We want to
      bonus the last caller of the function in the program by a huge amount
      for inlining because inlining that callsite has very little cost.
      Unfortunately, the last caller in the TU of a linkonce-odr function is
      *not* the last caller in the program, and so we don't want to apply this
      bonus. If we do, we can apply it to one callsite *per-TU*. Because of
      the way deferred inlining works, when it sees this bonus applied to one
      callsite in the TU for 'B', it decides that inlining 'B' is of the
      *utmost* importance just so we can get that final bonus. It then
      proceeds to essentially force deferred inlining regardless of the actual
      cost tradeoff.
      
      The result? PR12345: code bloat, code bloat, code bloat. Another result
      is getting *damn* lucky on a few benchmarks, and the over-inlining
      exposing critically important optimizations. I would very much like
      a list of benchmarks that regress after this change goes in, with
      bitcode before and after. This will help me greatly understand what
      opportunities the current cost analysis is missing.
      
      Initial benchmark numbers look very good. WebKit files that exhibited
      the worst of PR12345 went from growing to shrinking compared to Clang
      with r152737 reverted.
      
      - Bootstrapped Clang is 3% smaller with this change.
      - Bootstrapped Clang -O0 over a single-source-file of lib/Lex is 4%
        faster with this change.
      
      Please let me know about any other performance impact you see. Thanks to
      Nico for reporting and urging me to actually fix, Richard Smith, Duncan
      Sands, Manuel Klimek, and Benjamin Kramer for talking through the issues
      today.
      
      llvm-svn: 153506
      b9e35fbc
  16. Mar 25, 2012
    • Chandler Carruth's avatar
      Move the instruction simplification of callsite arguments in the inliner · 21211992
      Chandler Carruth authored
      to instead rely on much more generic and powerful instruction
      simplification in the function cloner (and thus inliner).
      
      This teaches the pruning function cloner to use instsimplify rather than
      just the constant folder to fold values during cloning. This can
      simplify a large number of things that constant folding alone cannot
      begin to touch. For example, it will realize that 'or' and 'and'
      instructions with certain constant operands actually become constants
      regardless of what their other operand is. It also can thread back
      through the caller to perform simplifications that are only possible by
      looking up a few levels. In particular, GEPs and pointer testing tend to
      fold much more heavily with this change.
      
      This should (in some cases) have a positive impact on compile times with
      optimizations on because the inliner itself will simply avoid cloning
      a great deal of code. It already attempted to prune proven-dead code,
      but now it will be use the stronger simplifications to prove more code
      dead.
      
      llvm-svn: 153403
      21211992
  17. Mar 16, 2012
    • Chandler Carruth's avatar
      Start removing the use of an ad-hoc 'never inline' set and instead · d7a5f2ad
      Chandler Carruth authored
      directly query the function information which this set was representing.
      This simplifies the interface of the inline cost analysis, and makes the
      always-inline pass significantly more efficient.
      
      Previously, always-inline would first make a single set of every
      function in the module *except* those marked with the always-inline
      attribute. It would then query this set at every call site to see if the
      function was a member of the set, and if so, refuse to inline it. This
      is quite wasteful. Instead, simply check the function attribute directly
      when looking at the callsite.
      
      The normal inliner also had similar redundancy. It added every function
      in the module with the noinline attribute to its set to ignore, even
      though inside the cost analysis function we *already tested* the
      noinline attribute and produced the same result.
      
      The only tricky part of removing this is that we have to be able to
      correctly remove only the functions inlined by the always-inline pass
      when finalizing, which requires a bit of a hack. Still, much less of
      a hack than the set of all non-always-inline functions was. While I was
      touching this function, I switched a heavy-weight set to a vector with
      sort+unique. The algorithm already had a two-phase insert and removal
      pattern, we were just needlessly paying the uniquing cost on every
      insert.
      
      This probably speeds up some compiles by a small amount (-O0 compiles
      with lots of always-inline, so potentially heavy libc++ users), but I've
      not tried to measure it.
      
      I believe there is no functional change here, but yell if you spot one.
      None are intended.
      
      Finally, the direction this is going in is to greatly simplify the
      inline cost query interface so that we can replace its implementation
      with a much more clever one. Along the way, all the APIs get simplified,
      so it seems incrementally good.
      
      llvm-svn: 152903
      d7a5f2ad
  18. Mar 14, 2012
    • Chandler Carruth's avatar
      Change where we enable the heuristic that delays inlining into functions · 30b8416d
      Chandler Carruth authored
      which are small enough to themselves be inlined. Delaying in this manner
      can be harmful if the function is inelligible for inlining in some (or
      many) contexts as it pessimizes the code of the function itself in the
      event that inlining does not eventually happen.
      
      Previously the check was written to only do this delaying of inlining
      for static functions in the hope that they could be entirely deleted and
      in the knowledge that all callers of static functions will have the
      opportunity to inline if it is in fact profitable. However, with C++ we
      get two other important sources of functions where the definition is
      always available for inlining: inline functions and templated functions.
      This patch generalizes the inliner to allow linkonce-ODR (the linkage
      such C++ routines receive) to also qualify for this delay-based
      inlining.
      
      Benchmarking across a range of large real-world applications shows
      roughly 2% size increase across the board, but an average speedup of
      about 0.5%. Some benhcmarks improved over 2%, and the 'clang' binary
      itself (when bootstrapped with this feature) shows a 1% -O0 performance
      improvement when run over all Sema, Lex, and Parse source code smashed
      into a single file. A clean re-build of Clang+LLVM with a bootstrapped
      Clang shows approximately 2% improvement, but that measurement is often
      noisy.
      
      llvm-svn: 152737
      30b8416d
  19. Mar 12, 2012
    • Chandler Carruth's avatar
      When inlining a function and adding its inner call sites to the · 595fda84
      Chandler Carruth authored
      candidate set for subsequent inlining, try to simplify the arguments to
      the inner call site now that inlining has been performed.
      
      The goal here is to propagate and fold constants through deeply nested
      call chains. Without doing this, we loose the inliner bonus that should
      be applied because the arguments don't match the exact pattern the cost
      estimator uses.
      
      Reviewed on IRC by Benjamin Kramer.
      
      llvm-svn: 152556
      595fda84
  20. Feb 25, 2012
  21. Oct 20, 2011
    • Eli Friedman's avatar
      Refactor code from inlining and globalopt that checks whether a function... · 1923a330
      Eli Friedman authored
      Refactor code from inlining and globalopt that checks whether a function definition is unused, and enhance it so it can tell that functions which are only used by a blockaddress are in fact dead.  This probably doesn't happen much on most code, but the Linux kernel's _THIS_IP_ can trigger this issue with blockaddress.  (GlobalDCE can also handle the given tescase, but we only run that at -O3.)  Found while looking at PR11180.
      
      llvm-svn: 142572
      1923a330
  22. Jul 18, 2011
  23. Apr 23, 2011
  24. Jan 04, 2011
    • Dale Johannesen's avatar
      Improve the accuracy of the inlining heuristic looking for the · a71d2cc8
      Dale Johannesen authored
      case where a static caller is itself inlined everywhere else, and
      thus may go away if it doesn't get too big due to inlining other
      things into it.  If there are references to the caller other than
      calls, it will not be removed; account for this.
      This results in same-day completion of the case in PR8853.
      
      llvm-svn: 122821
      a71d2cc8
  25. Dec 06, 2010
    • Chris Lattner's avatar
      Fix PR8735, a really terrible problem in the inliner's "alloca merging" · fb212de0
      Chris Lattner authored
      optimization.
      
      Consider:
      static void foo() {
        A = alloca
        ...
      }
      
      static void bar() {
        B = alloca
        ...
        call foo();
      }
      
      void main() {
        bar()
      }
      
      The inliner proceeds bottom up, but lets pretend it decides not to inline foo
      into bar.  When it gets to main, it inlines bar into main(), and says "hey, I
      just inlined an alloca "B" into main, lets remember that.  Then it keeps going
      and finds that it now contains a call to foo.  It decides to inline foo into
      main, and says "hey, foo has an alloca A, and I have an alloca B from another
      inlined call site, lets reuse it".  The problem with this of course, is that 
      the lifetime of A and B are nested, not disjoint.
      
      Unfortunately I can't create a reasonable testcase for this: the one in the
      PR is both huge and extremely sensitive, because you minor tweaks end up
      causing foo to get inlined into bar too early.  We already have tests for the
      basic alloca merging optimization and this does not break them.
      
      llvm-svn: 120995
      fb212de0
    • Chris Lattner's avatar
      improve -debug output and comments a little. · 5b6a865f
      Chris Lattner authored
      llvm-svn: 120993
      5b6a865f
  26. Nov 03, 2010
  27. Aug 06, 2010
  28. Jul 29, 2010
  29. Jul 13, 2010
  30. May 31, 2010
  31. May 01, 2010
  32. Apr 25, 2010
  33. Apr 23, 2010
Loading