summaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/LoopInfo.cpp
AgeCommit message (Collapse)Author
2024-02-03[Analysis] Use range-based for loops (NFC)Kazu Hirata
2024-01-26[Analysis] Use llvm::succ_empty and llvm::successors (NFC)Kazu Hirata
2024-01-03[LoopInfo][NewPM] Print function name in LoopPrinterPass (#76527)Björn Pettersson
The legacy pass manager printed the function name when printing loop info (via -analyze option). Like this: Printing analysis 'Natural Loop Information' for function 'func': Loop at depth 1 containing: ... Loop at depth 2 containing: ... Make sure we print such a first line including the function name also when using the new pass manager version of LoopPrinterPass. The format of the string is changed slightly, so now we say: Loop info for function 'func': Loop at depth 1 containing: ... Loop at depth 2 containing: ... This was originally requested in https://discourse.llvm.org/t/need-usage-help-w-new-pass-manager-for-opt-analysis-natural-loop-information/75874/7 and also mentioned in https://github.com/llvm/llvm-project/issues/76762
2023-12-11[llvm] Use StringRef::{starts,ends}_with (NFC) (#74956)Kazu Hirata
This patch replaces uses of StringRef::{starts,ends}with with StringRef::{starts,ends}_with for consistency with std::{string,string_view}::{starts,ends}_with in C++20. I'm planning to deprecate and eventually remove StringRef::{starts,ends}with.
2023-09-27[LoopIterator] Add const qualifier to LoopInfo (NFC)Nikita Popov
Loop iteration utilities do not change LoopInfo.
2023-04-24[LoopInfo] Move generic LoopInfo into own filesChristian Ulmann
This commit splits the generic part of `LoopInfo` into separate files. These new `GenericLoopInfo` files are located in `llvm/Support` to be inline with `GenericDomTree`. Furthermore, this change ensures that MLIR's Bazel build does not have to link against `LLVMAnalysis` just to use these template headers. Depends on D148219 Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D148235
2022-12-14[Analysis] llvm::Optional => std::optionalFangrui Song
2022-12-02[Analysis] Use std::nullopt instead of None (NFC)Kazu Hirata
This patch mechanically replaces None with std::nullopt where the compiler would warn if None were deprecated. The intent is to reduce the amount of manual work required in migrating from Optional to std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-11-19[Analysis] Teach getOptionalIntLoopAttribute to return std::optional (NFC)Kazu Hirata
This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-10-14[Loop] Move block and loop dispo invalidation to makeLoopInvariant.Florian Hahn
makeLoopInvariant may recursively move its operands to make them invariant, before moving the passed in instruction. Those recursively moved instructions are currently missed when invalidating block and loop dispositions. To address this, move the invalidation code to Loop::makeLoopInvariant. Fixes #58314. Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D135909
2022-07-19[LoopInfo] Allow cloning of callbrNikita Popov
After D129288, callbr is safe to clone without special handling. This permits optimizations like loop unroll and loop unswitch on loops containing callbrs. Fixes https://github.com/llvm/llvm-project/issues/41834. Differential Revision: https://reviews.llvm.org/D129993
2022-07-19[NFC] Introduce API to detect tokens penetrating LCSSA formMax Kazantsev
Following discussion in PR56243, we need to somehow detect the situation when token values penetrate LCSSA form for transforms that require that it is maintained by all values (for example, to sustain use-def dominance invarians). This patch introduces a parameter to LCSSA checkers to control their ignorance about tokens. Differential Revision: https://reviews.llvm.org/D129983 Reviewed By: efriedma
2022-06-18[llvm] Use value_or instead of getValueOr (NFC)Kazu Hirata
2022-04-06Fix warnings about variables that are set but only used in debug modeMartin Storsjö
Add void casts to mark the variables used, next to the places where they are used in assert or `LLVM_DEBUG()` expressions. Differential Revision: https://reviews.llvm.org/D123117
2022-03-01Cleanup includes: LLVMAnalysisserge-sans-paille
Number of lines output by preprocessor: before: 1065940348 after: 1065307662 Discourse thread: https://discourse.llvm.org/t/include-what-you-use-include-cleanup Differential Revision: https://reviews.llvm.org/D120659
2022-01-28[ScalarEvolution] Mark a loop as finite if in a willreturn functionWilliam S. Moses
A limited version of (https://reviews.llvm.org/D118090) that only marks a loop as finite if in a willreturn function. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D118429
2022-01-23[Analysis] Use default member initialization (NFC)Kazu Hirata
Identified with modernize-use-default-member-init.
2021-11-11[LoopInfo] Fix function getInductionVariableduanbo.db
The way function gets the induction variable is by judging whether StepInst or IndVar in the phi statement is one of the operands of CMP. But if the LatchCmpOp0/LatchCmpOp1 is a constant, the subsequent comparison may result in null == null, which is meaningless. This patch fixes the typo. Reviewed By: Whitney Differential Revision: https://reviews.llvm.org/D112980
2021-09-04[OpenMP][OpenMPIRBuilder] Implement loop unrolling.Michael Kruse
Recommit of 707ce34b06190e275572c3c46843036db1bab6d1. Don't introduce a dependency to the LLVMPasses component, instead register the required passes individually. Add methods for loop unrolling to the OpenMPIRBuilder class and use them in Clang if `-fopenmp-enable-irbuilder` is enabled. The unrolling methods are: * `unrollLoopFull` * `unrollLoopPartial` * `unrollLoopHeuristic` `unrollLoopPartial` and `unrollLoopHeuristic` can use compiler heuristics to automatically determine the unroll factor. If possible, that is if no CanonicalLoopInfo is required to pass to another method, metadata for LLVM's LoopUnrollPass is added. Otherwise the unroll factor is determined using the same heurstics as user by LoopUnrollPass. Not requiring a CanonicalLoopInfo, especially with `unrollLoopHeuristic` allows greater flexibility. With full unrolling and partial unrolling with known unroll factor, instead of duplicating instructions by the OpenMPIRBuilder, the full unroll is still delegated to the LoopUnrollPass. In case of partial unrolling the loop is first tiled using the existing `tileLoops` methods, then the inner loop fully unrolled using the same mechanism. Reviewed By: jdoerfert, kiranchandramohan Differential Revision: https://reviews.llvm.org/D107764
2021-09-02Revert "[OpenMP][OpenMPIRBuilder] Implement loop unrolling."Roman Lebedev
Breaks build with -DBUILD_SHARED_LIBS=ON ``` CMake Error: The inter-target dependency graph contains the following strongly connected component (cycle): "LLVMFrontendOpenMP" of type SHARED_LIBRARY depends on "LLVMPasses" (weak) "LLVMipo" of type SHARED_LIBRARY depends on "LLVMFrontendOpenMP" (weak) "LLVMCoroutines" of type SHARED_LIBRARY depends on "LLVMipo" (weak) "LLVMPasses" of type SHARED_LIBRARY depends on "LLVMCoroutines" (weak) depends on "LLVMipo" (weak) At least one of these targets is not a STATIC_LIBRARY. Cyclic dependencies are allowed only among static libraries. CMake Generate step failed. Build files cannot be regenerated correctly. ``` This reverts commit 707ce34b06190e275572c3c46843036db1bab6d1.
2021-09-02[OpenMP][OpenMPIRBuilder] Implement loop unrolling.Michael Kruse
Add methods for loop unrolling to the OpenMPIRBuilder class and use them in Clang if `-fopenmp-enable-irbuilder` is enabled. The unrolling methods are: * `unrollLoopFull` * `unrollLoopPartial` * `unrollLoopHeuristic` `unrollLoopPartial` and `unrollLoopHeuristic` can use compiler heuristics to automatically determine the unroll factor. If possible, that is if no CanonicalLoopInfo is required to pass to another method, metadata for LLVM's LoopUnrollPass is added. Otherwise the unroll factor is determined using the same heurstics as user by LoopUnrollPass. Not requiring a CanonicalLoopInfo, especially with `unrollLoopHeuristic` allows greater flexibility. With full unrolling and partial unrolling with known unroll factor, instead of duplicating instructions by the OpenMPIRBuilder, the full unroll is still delegated to the LoopUnrollPass. In case of partial unrolling the loop is first tiled using the existing `tileLoops` methods, then the inner loop fully unrolled using the same mechanism. Reviewed By: jdoerfert, kiranchandramohan Differential Revision: https://reviews.llvm.org/D107764
2021-07-21[LoopFlatten][LoopInfo] Use Loop to identify latch compare instructionRosie Sumpter
Make getLatchCmpInst non-static and use it in LoopFlatten as a more robust way of identifying the compare. Differential Revision: https://reviews.llvm.org/D106256
2021-06-10[LI] Add a cover function for checking if a loop is mustprogress [nfc]Philip Reames
Essentially, the cover function simply combines the loop level check and the function level scope into one call. This simplifies several callers and is (subjectively) less error prone.
2021-06-10Move code for checking loop metadata into Analysis [nfc]Philip Reames
I need the mustprogress loop metadata in ScalarEvolution and it makes sense to keep all the accessors for quering loop metadate together.
2021-05-07[LoopNest] Consider loop nest with inner loop guard using outer loopWhitney Tsang
induction variable to be perfect This patch allow more conditional branches to be considered as loop guard, and so more loop nests can be considered perfect. Reviewed By: bmahjour, sidbav Differential Revision: https://reviews.llvm.org/D94717
2021-04-15[NewPM] Cleanup IR printing instrumentationArthur Eubanks
Being lazy with printing the banner seems hard to reason with, we should print it unconditionally first (it could also lead to duplicate banners if we have multiple functions in -filter-print-funcs). The printIR() functions were doing too many things. I separated out the call from PrintPassInstrumentation since we were essentially doing two completely separate things in printIR() from different callers. There were multiple ways to generate the name of some IR. That's all been moved to getIRName(). The printing of the IR name was also inconsistent, now it's always "IR Dump on $foo" where "$foo" is the name. For a function, it's the function name. For a loop, it's what's printed by Loop::print(), which is more detailed. For an SCC, it's the list of functions in parentheses. For a module it's "[module]", to differentiate between a possible SCC with a function called "module". To preserve D74814, we have to check if we're going to print anything at all first. This is unfortunate, but I would consider this a special case that shouldn't be handled in the core logic. Reviewed By: jamieschmeiser Differential Revision: https://reviews.llvm.org/D100231
2021-03-17[LCSSA] Extract a utility for deciding if a new use requires a new lcssa phi ↵Philip Reames
[NFC] (Triggered by a review comment on D98728, but otherwise unrelated.)
2021-02-22[Analysis] Use range-based for loops (NFC)Kazu Hirata
2021-02-14[llvm] Use llvm::is_contained (NFC)Kazu Hirata
2021-02-06[Analysis] Use range-based for loops (NFC)Kazu Hirata
2021-01-18[llvm] Use the default value of drop_begin (NFC)Kazu Hirata
2020-12-03[NewPM] Support --print-before/after in NPMArthur Eubanks
This changes --print-before/after to be a list of strings rather than legacy passes. (this also has the effect of not showing the entire list of passes in --help-hidden after --print-before/after, which IMO is great for making it less verbose). Currently PrintIRInstrumentation passes the class name rather than pass name to llvm::shouldPrintBeforePass(), meaning llvm::shouldPrintBeforePass() never functions as intended in the NPM. There is no easy way of converting class names to pass names outside of within an instance of PassBuilder. This adds a map of pass class names to their short names in PassRegistry.def within PassInstrumentationCallbacks. It is populated inside the constructor of PassBuilder, which takes a PassInstrumentationCallbacks. Add a pointer to PassInstrumentationCallbacks inside PrintIRInstrumentation and use the newly created map. This is a bit hacky, but I can't think of a better way since the short id to class name only exists within PassRegistry.def. This also doesn't handle passes not in PassRegistry.def but rather added via PassBuilder::registerPipelineParsingCallback(). llvm/test/CodeGen/Generic/print-after.ll doesn't seem very useful now with this change. Reviewed By: ychen, jamieschmeiser Differential Revision: https://reviews.llvm.org/D87216
2020-11-04[LangRef] Adds llvm.loop.mustprogress loop metadataAtmn Patel
This patch adds the llvm.loop.mustprogress loop metadata. This is to be added to loops where the frontend language requires that the loop makes observable interactions with the environment. This is the loop-level equivalent to the function attribute `mustprogress` defined in D86233. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D88464
2020-10-29[LCSSA] Doc for special treatment of PHIsStefanos Baziotis
Differential Revision: https://reviews.llvm.org/D89739
2020-10-26Avoid unnecessary uses of `MDNode::getTemporary`, NFCDuncan P. N. Exon Smith
This is a long-delayed follow-up to 5e5b85098dbeaea2cfa5d01695b5d2982634d7dd. `TempMDNode` includes a bunch of machinery for RAUW, and should only be used when necessary. RAUW wasn't being used in any of these cases... it was just a placeholder for a self-reference. Where the real node was using `MDNode::getDistinct`, just replace the temporary argument with `nullptr`. Where the real node was using `MDNode::get`, the `replaceOperandWith` call was "promoting" the node to a distinct one implicitly due to self-reference detection in `MDNode::handleChangedOperand`. The `TempMDNode` was serving a purpose by delaying uniquing, but it's way simpler to just call `MDNode::getDistinct` in the first place. Note that using a self-reference at all in these places is a hold-over from before `distinct` metadata existed. It was an old trick to create distinct nodes. It would be intrusive to change, including bitcode upgrades, etc., and it's harmless so I'm not sure there's much value in removing it from existing schemas. After this commit it still has a tiny memory cost (in the extra metadata operand) but no more overhead in construction. Differential Revision: https://reviews.llvm.org/D90079
2020-09-22[LoopInfo] empty() -> isInnermost(), add isOutermost()Stefanos Baziotis
Differential Revision: https://reviews.llvm.org/D82895
2020-04-17[NFC] Add missing 'const' notion to LCSSA-related functionsMax Kazantsev
These functions don't really do any changes to loop info or dominator tree. We should state this explicitly using 'const'.
2020-04-14[llvm][NFC][CallSite] Remove Implementation uses of CallSiteMircea Trofin
Reviewers: dblaikie, davidxl, craig.topper Subscribers: arsenm, dschuff, nemanjai, jvesely, nhaehnle, sbc100, jgravelle-google, hiraditya, aheejin, kbarton, kerbowa, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D78142
2019-12-12Rename LoopInfo::isRotated() to LoopInfo::isRotatedForm().Kit Barton
This patch renames the LoopInfo::isRotated() method to LoopInfo::isRotatedForm() to make it clear that the method checks whether the loop is in rotated form, not whether the loop has been rotated by the LoopRotation pass.
2019-12-11Fix -Wunused-variable in -DLLVM_ENABLE_ASSERTIONS=Off builds after D65958 ↵Fangrui Song
and D70450
2019-12-11[Loop] Add isRotated method to Loop class.Kit Barton
Summary: This patch adds a method to determine if a loop is in rotated form (the latch is an exiting block). It also modifies the getLoopGuardBranch method to use this new method. This method can also be used in Loopfusion. Once this patch lands I will make the corresponding changes there. Reviewers: jdoerfert, Meinersbur, dmgreen, etiotto, Whitney, fhahn, hfinkel Reviewed By: Meinersbur Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D65958
2019-11-20[MemorySSA] Moving at the end often means before terminator.Alina Sbirlea
Moving accesses in MemorySSA at InsertionPlace::End, when an instruction is moved into a block, almost always means insert at the end of the block, but before the block terminator. This matters when the block terminator is a MemoryAccess itself (an invoke), and the insertion must be done before the terminator for the update to be correct. Insert an additional position: InsertionPlace:BeforeTerminator and update current usages where this applies. Resolves PR44027.
2019-11-13Sink all InitializePasses.h includesReid Kleckner
This file lists every pass in LLVM, and is included by Pass.h, which is very popular. Every time we add, remove, or rename a pass in LLVM, it caused lots of recompilation. I found this fact by looking at this table, which is sorted by the number of times a file was changed over the last 100,000 git commits multiplied by the number of object files that depend on it in the current checkout: recompiles touches affected_files header 342380 95 3604 llvm/include/llvm/ADT/STLExtras.h 314730 234 1345 llvm/include/llvm/InitializePasses.h 307036 118 2602 llvm/include/llvm/ADT/APInt.h 213049 59 3611 llvm/include/llvm/Support/MathExtras.h 170422 47 3626 llvm/include/llvm/Support/Compiler.h 162225 45 3605 llvm/include/llvm/ADT/Optional.h 158319 63 2513 llvm/include/llvm/ADT/Triple.h 140322 39 3598 llvm/include/llvm/ADT/StringRef.h 137647 59 2333 llvm/include/llvm/Support/Error.h 131619 73 1803 llvm/include/llvm/Support/FileSystem.h Before this change, touching InitializePasses.h would cause 1345 files to recompile. After this change, touching it only causes 550 compiles in an incremental rebuild. Reviewers: bkramer, asbirlea, bollu, jdoerfert Differential Revision: https://reviews.llvm.org/D70211
2019-10-06[LOOPGUARD] Remove asserts in getLoopGuardBranchWhitney Tsang
Summary: The assertion in getLoopGuardBranch can be a 'return nullptr' under if condition. Authored By: DTharun Reviewer: Whitney, fhahn Reviewed By: Whitney, fhahn Subscribers: fhahn, llvm-commits Tag: LLVM Differential Revision: https://reviews.llvm.org/D66084 llvm-svn: 373857
2019-09-27Revert "[LoopInfo] Limit the iterations to check whether a loop has dedicatedWei Mi
exits" Get a better approach in https://reviews.llvm.org/D68107 to solve the problem. Revert the initial patch and will commit the new one soon. This reverts commit rL372990. llvm-svn: 373044
2019-09-26[LOOPGUARD] Disable loop with multiple loop exiting blocks.Whitney Tsang
Summary: As discussed in the loop group meeting. With the current definition of loop guard, we should not allow multiple loop exiting blocks. For loops that has multiple loop exiting blocks, we can simply unable to find the loop guard. When getUniqueExitBlock() obtains a vector size not equals to one, that means there is either no exit blocks or there exists more than one unique block the loop exit to. If we don't disallow loop with multiple loop exit blocks, then with our current implementation, there can exist exit blocks don't post dominated by the non pre-header successor of the guard block. Reviewer: reames, Meinersbur, kbarton, etiotto, bmahjour Reviewed By: Meinersbur, kbarton Subscribers: fhahn, hiraditya, llvm-commits Tag: LLVM Differential Revision: https://reviews.llvm.org/D66529 llvm-svn: 373011
2019-09-26[LoopInfo] Limit the iterations to check whether a loop has dedicated exitsWei Mi
for extreme large case. We had a case that a single loop which has 4000 exits and the average number of predecessors of each exit is > 1000, and we found compiling the case spent a significant amount of time on checking whether a loop has dedicated exits. This patch adds a limit for the iterations to the check. With the patch, the time to compile our testcase reduced from 1000s to 200s (clang release build). Differential Revision: https://reviews.llvm.org/D67359 llvm-svn: 372990
2019-07-25[LOOPINFO] Introduce the loop guard API.Whitney Tsang
Summary: This is the first patch for the loop guard. We introduced getLoopGuardBranch() and isGuarded(). This currently only works on simplified loop, as it requires a preheader and a latch to identify the guard. It will work on loops of the form: /// GuardBB: /// br cond1, Preheader, ExitSucc <== GuardBranch /// Preheader: /// br Header /// Header: /// ... /// br Latch /// Latch: /// br cond2, Header, ExitBlock /// ExitBlock: /// br ExitSucc /// ExitSucc: Prior discussions leading upto the decision to introduce the loop guard API: http://lists.llvm.org/pipermail/llvm-dev/2019-May/132607.html Reviewer: reames, kbarton, hfinkel, jdoerfert, Meinersbur, dmgreen Reviewed By: reames Subscribers: wuzish, hiraditya, jsji, llvm-commits, bmahjour, etiotto Tag: LLVM Differential Revision: https://reviews.llvm.org/D63885 llvm-svn: 367033
2019-07-17Make DT a transitive dependency of LI.Evgeniy Stepanov
Summary: LoopInfoWrapperPass::verify uses DT, which means DT must be alive even if it has no direct users. Fixes a crash in expensive checks mode. Reviewers: pcc, leonardchan Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D64896 llvm-svn: 366388
2019-07-15[LoopUnroll+LoopUnswitch] do not transform loops containing callbrNick Desaulniers
Summary: There is currently a correctness issue when unrolling loops containing callbr's where their indirect targets are being updated correctly to the newly created labels, but their operands are not. This manifests in unrolled loops where the second and subsequent copies of callbr instructions have blockaddresses of the label from the first instance of the unrolled loop, which would result in nonsensical runtime control flow. For now, conservatively do not unroll the loop. In the future, I think we can pursue unrolling such loops provided we transform the cloned callbr's operands correctly. Such a transform and its legalities are being discussed in: https://reviews.llvm.org/D64101 Link: https://bugs.llvm.org/show_bug.cgi?id=42489 Link: https://groups.google.com/forum/#!topic/clang-built-linux/z-hRWP9KqPI Reviewers: fhahn, hfinkel, efriedma Reviewed By: fhahn, hfinkel, efriedma Subscribers: efriedma, hiraditya, zzheng, dmgreen, llvm-commits, pirama, kees, nathanchance, E5ten, craig.topper, chandlerc, glider, void, srhines Tags: #llvm Differential Revision: https://reviews.llvm.org/D64368 llvm-svn: 366130