aboutsummaryrefslogtreecommitdiffstats
path: root/include/llvm/Analysis/InlineCost.h
Commit message (Collapse)AuthorAgeFilesLines
* Update aosp/master LLVM for rebase to r235153Pirama Arumuga Nainar2015-05-181-1/+1
| | | | | Change-Id: I9bf53792f9fc30570e81a8d80d296c681d005ea7 (cherry picked from commit 0c7f116bb6950ef819323d855415b2f2b0aad987)
* Update aosp/master LLVM for rebase to r230699.Stephen Hines2015-03-231-5/+5
| | | | Change-Id: I2b5be30509658cb8266be782de0ab24f9099f9b9
* Update aosp/master LLVM for rebase to r222494.Stephen Hines2014-12-021-0/+2
| | | | Change-Id: Ic787f5e0124df789bd26f3f24680f45e678eef2d
* Update to LLVM 3.5a.Stephen Hines2014-04-241-3/+2
| | | | Change-Id: Ifadecab779f128e62e430c2b4f6ddd84953ed617
* Remove unneeded #include.Jakub Staszak2013-06-061-1/+0
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183460 91177308-0d34-0410-b5e6-96231b3b80d8
* Use only explicit bool conversion operatorsDavid Blaikie2013-05-151-1/+1
| | | | | | | | | | | | | | | | | | | | | | | BitVector/SmallBitVector::reference::operator bool remain implicit since they model more exactly a bool, rather than something else that can be boolean tested. The most common (non-buggy) case are where such objects are used as return expressions in bool-returning functions or as boolean function arguments. In those cases I've used (& added if necessary) a named function to provide the equivalent (or sometimes negative, depending on convenient wording) test. One behavior change (YAMLParser) was made, though no test case is included as I'm not sure how to reach that code path. Essentially any comparison of llvm::yaml::document_iterators would be invalid if neither iterator was at the end. This helped uncover a couple of bugs in Clang - test cases provided for those in a separate commit along with similar changes to `operator bool` instances in Clang. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@181868 91177308-0d34-0410-b5e6-96231b3b80d8
* Now that the inline cost analysis is a pass, we can easily have itChandler Carruth2013-01-211-0/+2
| | | | | | | | | | | depend on and use other analyses (as long as they're either immutable passes or CGSCC passes of course -- nothing in the pass manager has been fixed here). Leverage this to thread TargetTransformInfo down through the inline cost analysis. No functionality changed here, this just threads things through. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@173031 91177308-0d34-0410-b5e6-96231b3b80d8
* Make the inline cost a proper analysis pass. This remains essentiallyChandler Carruth2013-01-211-4/+12
| | | | | | | | | | | | | | | | a dynamic analysis done on each call to the routine. However, now it can use the standard pass infrastructure to reference other analyses, instead of a silly setter method. This will become more interesting as I teach it about more analysis passes. This updates the two inliner passes to use the inline cost analysis. Doing so highlights how utterly redundant these two passes are. Either we should find a cheaper way to do always inlining, or we should merge the two and just fiddle with the thresholds to get the desired behavior. I'm leaning increasingly toward the latter as it would also remove the Inliner sub-class split. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@173030 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix an old-style doxygen comment.Chandler Carruth2013-01-211-1/+1
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@173027 91177308-0d34-0410-b5e6-96231b3b80d8
* Cleanup the formatting of this header. This removes the namespace indentChandler Carruth2013-01-211-105/+104
| | | | | | | and reformats a few constructors using clang-format. Only whitespace changes here. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@173018 91177308-0d34-0410-b5e6-96231b3b80d8
* Remove unneeded #includes.Jakub Staszak2013-01-101-5/+1
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@172118 91177308-0d34-0410-b5e6-96231b3b80d8
* Move all of the header files which are involved in modelling the LLVM IRChandler Carruth2013-01-021-1/+1
| | | | | | | | | | | | | | | | | | | | | into their new header subdirectory: include/llvm/IR. This matches the directory structure of lib, and begins to correct a long standing point of file layout clutter in LLVM. There are still more header files to move here, but I wanted to handle them in separate commits to make tracking what files make sense at each layer easier. The only really questionable files here are the target intrinsic tablegen files. But that's a battle I'd rather not fight today. I've updated both CMake and Makefile build systems (I think, and my tests think, but I may have missed something). I've also re-sorted the includes throughout the project. I'll be committing updates to Clang, DragonEgg, and Polly momentarily. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171366 91177308-0d34-0410-b5e6-96231b3b80d8
* Sort the #include lines for the include/... tree with the script.Chandler Carruth2012-12-031-1/+1
| | | | | | | | | | AKA: Recompile *ALL* the source code! This one went much better. No manual edits here. I spot-checked for silliness and grep-checked for really broken edits and everything seemed good. It all still compiles. Yell if you see something that looks goofy. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@169133 91177308-0d34-0410-b5e6-96231b3b80d8
* Clean up handling of always-inline functions in the inliner.Bob Wilson2012-11-191-0/+3
| | | | | | | | | This patch moves the isInlineViable function from the InlineAlways pass into the InlineCostAnalyzer and then changes the InlineCost computation to use that simple check for always-inline functions. All the special-case checks for AlwaysInline in the CallAnalyzer can then go away. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@168300 91177308-0d34-0410-b5e6-96231b3b80d8
* Some comment fixes.Bob Wilson2012-11-191-5/+5
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@168299 91177308-0d34-0410-b5e6-96231b3b80d8
* Move TargetData to DataLayout.Micah Villmow2012-10-081-4/+4
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@165402 91177308-0d34-0410-b5e6-96231b3b80d8
* InlineCost: Make TotalAllocaSizeRecursiveCaller unsigned to avoid ↵Benjamin Kramer2012-09-191-1/+1
| | | | | | | | sign-compare warnings. It's a size, not a cost. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@164219 91177308-0d34-0410-b5e6-96231b3b80d8
* Prevent inlining of callees which allocate lots of memory into a recursive ↵Nadav Rotem2012-09-191-0/+3
| | | | | | | | | | | | | | | | | | | | caller. Example: void foo() { ... foo(); // I'm recursive! bar(); } bar() { int a[1000]; // large stack size } rdar://10853263 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@164207 91177308-0d34-0410-b5e6-96231b3b80d8
* A pile of long over-due refactorings here. There are some very, *very*Chandler Carruth2012-05-041-4/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | minor behavior changes with this, but nothing I have seen evidence of in the wild or expect to be meaningful. The real goal is unifying our logic and simplifying the interfaces. A summary of the changes follows: - Make 'callIsSmall' actually accept a callsite so it can handle intrinsics, and simplify callers appropriately. - Nuke a completely bogus declaration of 'callIsSmall' that was still lurking in InlineCost.h... No idea how this got missed. - Teach the 'isInstructionFree' about the various more intelligent 'free' heuristics that got added to the inline cost analysis during review and testing. This mostly surrounds int->ptr and ptr->int casts. - Switch most of the interesting parts of the inline cost analysis that were essentially computing 'is this instruction free?' to use the code metrics routine instead. This way we won't keep duplicating logic. All of this is motivated by the desire to allow other passes to compute a roughly equivalent 'cost' metric for a particular basic block as the inline cost analysis. Sadly, re-using the same analysis for both is really messy because only the actual inline cost analysis is ever going to go to the contortions required for simplification, SROA analysis, etc. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@156140 91177308-0d34-0410-b5e6-96231b3b80d8
* Reintroduce InlineCostAnalyzer::getInlineCost() variant with explicit calleeDavid Chisnall2012-04-061-0/+9
| | | | | | | | | | parameter until we have a more sensible API for doing the same thing. Reviewed by Chandler. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@154180 91177308-0d34-0410-b5e6-96231b3b80d8
* Start cleaning up the InlineCost class. This switches to sentinel valuesChandler Carruth2012-04-011-25/+20
| | | | | | | | | | | rather than a bitfield, a great suggestion by Chris during code review. There is still quite a bit of cruft in the interface, but that requires sorting out some awkward uses of the cost inside the actual inliner. No functionality changed intended here. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153853 91177308-0d34-0410-b5e6-96231b3b80d8
* Remove a bunch of empty, dead, and no-op methods from all of theseChandler Carruth2012-03-311-12/+0
| | | | | | | | | | 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153813 91177308-0d34-0410-b5e6-96231b3b80d8
* Initial commit for the rewrite of the inline cost analysis to operateChandler Carruth2012-03-311-117/+61
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153812 91177308-0d34-0410-b5e6-96231b3b80d8
* Start removing the use of an ad-hoc 'never inline' set and insteadChandler Carruth2012-03-161-5/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@152903 91177308-0d34-0410-b5e6-96231b3b80d8
* Remove all remnants of partial specialization in the cost computationChandler Carruth2012-03-151-12/+0
| | | | | | side of things. This is all dead code. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@152759 91177308-0d34-0410-b5e6-96231b3b80d8
* Extend the inline cost calculation to account for bonuses due toChandler Carruth2012-03-141-0/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | correlated pairs of pointer arguments at the callsite. This is designed to recognize the common C++ idiom of begin/end pointer pairs when the end pointer is a constant offset from the begin pointer. With the C-based idiom of a pointer and size, the inline cost saw the constant size calculation, and this provides the same level of information for begin/end pairs. In order to propagate this information we have to search for candidate operations on a pair of pointer function arguments (or derived from them) which would be simplified if the pointers had a known constant offset. Then the callsite analysis looks for such pointer pairs in the argument list, and applies the appropriate bonus. This helps LLVM detect that half of bounds-checked STL algorithms (such as hash_combine_range, and some hybrid sort implementations) disappear when inlined with a constant size input. However, it's not a complete fix due the inaccuracy of our cost metric for constants in general. I'm looking into that next. Benchmarks showed no significant code size change, and very minor performance changes. However, specific code such as hashing is showing significantly cleaner inlining decisions. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@152752 91177308-0d34-0410-b5e6-96231b3b80d8
* Rotate two of the functions used to count bonuses for the inline costChandler Carruth2012-03-081-0/+12
| | | | | | | | | | | | | analysis to be methods on the cost analysis's function info object instead of the code metrics object. These really are just users of the code metrics, they're building the information for the function's analysis. This is the first step of growing the amount of information we collect about a function in order to cope with pair-wise simplifications due to allocas. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@152283 91177308-0d34-0410-b5e6-96231b3b80d8
* Make headers standalone.Benjamin Kramer2011-11-141-6/+4
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@144537 91177308-0d34-0410-b5e6-96231b3b80d8
* Inlining and unrolling heuristics should be aware of free truncs.Andrew Trick2011-10-011-1/+8
| | | | | | | | | | | We want heuristics to be based on accurate data, but more importantly we don't want llvm to behave randomly. A benign trunc inserted by an upstream pass should not cause a wild swings in optimization level. See PR11034. It's a general problem with threshold-based heuristics, but we can make it less bad. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@140919 91177308-0d34-0410-b5e6-96231b3b80d8
* Fix a ton of comment typos found by codespell. Patch byChris Lattner2011-04-151-1/+1
| | | | | | | | Luis Felipe Strano Moraes! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@129558 91177308-0d34-0410-b5e6-96231b3b80d8
* Rewrite how the indirect call bonus is handled. This now works by:Eric Christopher2011-02-051-2/+5
| | | | | | | | | | | | | | | | | | a) Making it a per call site bonus for functions that we can move from indirect to direct calls. b) Reduces the bonus from 500 to 100 per call site. c) Subtracts the size of the possible newly inlineable call from the bonus to only add a bonus if we can inline a small function to devirtualize it. Also changes the bonus from a positive that's subtracted to a negative that's added. Fixes the remainder of rdar://8546196 by reducing the object file size after inlining by 84%. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@124916 91177308-0d34-0410-b5e6-96231b3b80d8
* Reapply 124275 since the Dragonegg failure was unreproducible.Eric Christopher2011-02-011-3/+3
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@124641 91177308-0d34-0410-b5e6-96231b3b80d8
* Temporarily revert 124275 to see if it brings the dragonegg buildbot back.Eric Christopher2011-01-261-3/+3
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@124312 91177308-0d34-0410-b5e6-96231b3b80d8
* Separate out the constant bonus from the size reduction metrics. ReworkEric Christopher2011-01-261-3/+3
| | | | | | | | | | a few loops accordingly. Should be no functional change. This is a step for more accurate cost/benefit analysis of devirt/inlining bonuses. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@124275 91177308-0d34-0410-b5e6-96231b3b80d8
* Perhaps a bit too much vertical whitespace.Eric Christopher2011-01-241-2/+0
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@124148 91177308-0d34-0410-b5e6-96231b3b80d8
* Now using a variant of the existing inlining heuristics to decide whether to ↵Kenneth Uildriks2010-10-091-0/+12
| | | | | | create a given specialization of a function in PartialSpecialization. If the total performance bonus across all callsites passing the same constant exceeds the specialization cost, we create the specialization. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@116158 91177308-0d34-0410-b5e6-96231b3b80d8
* Start separating out code metrics into code size metrics and code ↵Kenneth Uildriks2010-10-081-2/+4
| | | | | | performance metrics. Partial Specialization will apply the former to function specializations, and the latter to all callsites that can use a specialization, in order to decide whether to create a specialization git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@116057 91177308-0d34-0410-b5e6-96231b3b80d8
* Refactor code-size reduction estimation methods out of InlineCostAnalyzer ↵Owen Anderson2010-09-091-10/+1
| | | | | | | | | | | | and into CodeMetrics. They don't use any InlineCostAnalyzer state, and are useful for other clients who don't necessarily want to use all of InlineCostAnalyzer's logic, some of which is fairly inlining-specific. No intended functionality change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@113499 91177308-0d34-0410-b5e6-96231b3b80d8
* Pulled CodeMetrics out of InlineCost.h and made it a bit more general, so it ↵Kenneth Uildriks2010-06-091-40/+5
| | | | | | can be reused from PartialSpecializationCost git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@105725 91177308-0d34-0410-b5e6-96231b3b80d8
* Clear CachedFunctionInfo upon Pass::releaseMemory. Because ValueMap will abortNick Lewycky2010-05-121-0/+3
| | | | | | | | | | | on RAUW of functions, this is a correctness issue instead of a mere memory usage problem. No testcase until the new MergeFunctions can land. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@103653 91177308-0d34-0410-b5e6-96231b3b80d8
* Added a variant of InlineCostAnalyzer::getInlineCost() that takes the called ↵David Chisnall2010-05-011-0/+8
| | | | | | function as an explicit argument, for use when inlining function pointers. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@102841 91177308-0d34-0410-b5e6-96231b3b80d8
* fix file header.Chris Lattner2010-04-221-1/+1
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@102049 91177308-0d34-0410-b5e6-96231b3b80d8
* Add comment (lost when reverting and reapplying 101503).Dale Johannesen2010-04-171-0/+2
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@101664 91177308-0d34-0410-b5e6-96231b3b80d8
* Reapply 101503+101520. These are "obviously correct" [Chris]Dale Johannesen2010-04-171-2/+2
| | | | | | | | and don't cause any problems on Darwin. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@101584 91177308-0d34-0410-b5e6-96231b3b80d8
* Revert 101520, which depended on 101503, which was reverted.Dan Gohman2010-04-161-0/+1
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@101528 91177308-0d34-0410-b5e6-96231b3b80d8
* Revert commit 101503 (johannes), in the hope of fixing the dragonegg build,Duncan Sands2010-04-161-4/+1
| | | | | | | | | | | see http://google1.osuosl.org:8011/builders/dragonegg-x86_64-linux/builds/693 Original commit text: Use a ValueMap not a std::map for the reason indicated in the comment. This was causing nondeterministic changes in inlining decisions. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@101525 91177308-0d34-0410-b5e6-96231b3b80d8
* Trim a #include.Dan Gohman2010-04-161-1/+0
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@101520 91177308-0d34-0410-b5e6-96231b3b80d8
* Use a ValueMap not a std::map for the reason indicatedDale Johannesen2010-04-161-1/+4
| | | | | | | | | in the comment. This was causing nondeterministic changes in inlining decisions. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@101503 91177308-0d34-0410-b5e6-96231b3b80d8
* Make callIsSmall accessible as a utility function.Dan Gohman2010-04-161-0/+4
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@101463 91177308-0d34-0410-b5e6-96231b3b80d8
* Remove extra parameter.Devang Patel2010-03-131-1/+1
| | | | git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@98403 91177308-0d34-0410-b5e6-96231b3b80d8