summaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/ScheduleDAG.cpp
AgeCommit message (Collapse)Author
2025-06-05MachineScheduler: Improve instruction clustering (#137784)Ruiling, Song
The existing way of managing clustered nodes was done through adding weak edges between the neighbouring cluster nodes, which is a sort of ordered queue. And this will be later recorded as `NextClusterPred` or `NextClusterSucc` in `ScheduleDAGMI`. But actually the instruction may be picked not in the exact order of the queue. For example, we have a queue of cluster nodes A B C. But during scheduling, node B might be picked first, then it will be very likely that we only cluster B and C for Top-Down scheduling (leaving A alone). Another issue is: ``` if (!ReorderWhileClustering && SUa->NodeNum > SUb->NodeNum) std::swap(SUa, SUb); if (!DAG->addEdge(SUb, SDep(SUa, SDep::Cluster))) ``` may break the cluster queue. For example, we want to cluster nodes (order as in `MemOpRecords`): 1 3 2. 1(SUa) will be pred of 3(SUb) normally. But when it comes to (3, 2), As 3(SUa) > 2(SUb), we would reorder the two nodes, which makes 2 be pred of 3. This makes both 1 and 2 become preds of 3, but there is no edge between 1 and 2. Thus we get a broken cluster chain. To fix both issues, we introduce an unordered set in the change. This could help improve clustering in some hard case. One key reason the change causes so many test check changes is: As the cluster candidates are not ordered now, the candidates might be picked in different order from before. The most affected targets are: AMDGPU, AArch64, RISCV. For RISCV, it seems to me most are just minor instruction reorder, don't see obvious regression. For AArch64, there were some combining of ldr into ldp being affected. With two cases being regressed and two being improved. This has more deeper reason that machine scheduler cannot cluster them well both before and after the change, and the load combine algorithm later is also not smart enough. For AMDGPU, some cases have more v_dual instructions used while some are regressed. It seems less critical. Seems like test `v_vselect_v32bf16` gets more buffer_load being claused.
2024-08-20[ScheduleDAG] Dirty height/depth in addPred/removePred even for latency zero ↵Björn Pettersson
(#102915) A long time ago (back in 2009) there was a commit 52d4d8244b7c39c5cd that changed the scheduler to not dirty height/depth when adding or removing SUnit predecessors when the latency on the edge was zero. That commit message is claiming that the depth or height isn't affected when the latency is zero. As a matter of fact, the depth/height can change even with a zero latency on the edge. If for example adding a new SUnit A, with zero latency, but as a predecessor to a SUnit B, then both height of A and depth of B should be marked as dirty. If for example B has a greater height than A, then the height of A needs to be adjusted even if the latency is zero. I think this has been wrong for many years. Downstream we have had commit 52d4d8244b7c39c5cd reverted since back in 2016. There is no motivating lit test for 52d4d8244b7c39c5cd (only an incomplete C level reproducer in https://github.com/llvm/llvm-project/issues/3613). After commit 13d04fa560e156797c21f1 there finally appeared an upstream lit test that shows that we get better code if marking height/depth as dirty (llvm/test/CodeGen/AArch64/abds.ll).
2024-05-23[llvm][ScheduleDAG] SUnit::biasCriticalPath() does not find the critical ↵csstormq
path consistently (#93001) Patch co-authored by AtariDreams (gfunni234@gmail.com). Fixes #38037. [AMDGPU] Update test results to fix build (#92982)
2024-05-21Revert "[llvm][ScheduleDAG] SUnit::biasCriticalPath() does not find the ↵csstormq
critical path consistently (#92368)" (#92992) This reverts commit f0d1ae83b046ff0eeffc72a103f7c8b01ad33787. This commit breaks tests: http://45.33.8.238/linux/138572/step_11.txt
2024-05-22[llvm][ScheduleDAG] SUnit::biasCriticalPath() does not find the critical ↵csstormq
path consistently (#92368) Fix https://github.com/llvm/llvm-project/issues/38037
2023-10-22[llvm] Stop including llvm/ADT/iterator_range.h (NFC)Kazu Hirata
Identified with misc-include-cleaner.
2023-09-27[ScheduleDAG] Fix false assert targetlennyxiao
In SUnit::removePred, N->WeakSuccsLeft is reduced but WeakSuccsLeft is checked. Reviewed By: kerbowa Differential Revision: https://reviews.llvm.org/D151311
2023-05-08Reapply [Coverity] Fix explicit null dereferencesAkshay Khadse
This change fixes static code analysis errors Reviewed By: skan Differential Revision: https://reviews.llvm.org/D149506
2023-04-24Revert "[Coverity] Fix explicit null dereferences"Tom Weaver
This reverts commit 22b23a5213b57ce1834f5b50fbbf8a50297efc8a. This commit caused the following two build bots to start failing: https://lab.llvm.org/buildbot/#/builders/216/builds/20322 https://lab.llvm.org/buildbot/#/builders/123/builds/18511
2023-04-23[Coverity] Fix explicit null dereferencesAkshay Khadse
This change fixes static code analysis errors Reviewed By: skan Differential Revision: https://reviews.llvm.org/D148912
2023-01-25[ScheduleDAG] Fix removing edges with weak depsAustin Kerbow
In SUnit::removePred edges are removed from the Preds and Succs lists before updating the bookkeeping. This could result in incorrect values for NumPreds/SuccsLeft and cause WeakPreds/SuccsLeft to underflow, since the incorrect SDep will be used to update these values. Reviewed By: rampitec Differential Revision: https://reviews.llvm.org/D142325
2021-12-12[llvm] Use llvm::reverse (NFC)Kazu Hirata
2021-11-06[llvm] Use llvm::reverse (NFC)Kazu Hirata
2020-09-21Revert "[NFC][ScheduleDAG] Remove unused EntrySU SUnit"Alexander Belyaev
This reverts commit 0345d88de654259ae90494bf9b015416e2cccacb. Google internal backend uses EntrySU, we are looking into removing dependency on it. Differential Revision: https://reviews.llvm.org/D88018
2020-09-18[NFC][ScheduleDAG] Remove unused EntrySU SUnitFrancis Visoiu Mistrih
EntrySU doesn't seem to be used at all when building the ScheduleDAG. Differential Revision: https://reviews.llvm.org/D87867
2020-05-31[ScheduleDAG] Avoid unnecessary recomputation of topological order.Florian Hahn
In some cases ScheduleDAGRRList has to add new nodes to resolve problems with interfering physical registers. When new nodes are added, it completely re-computes the topological order, which can take a long time, but is unnecessary. We only add nodes one by one, and initially they do not have any predecessors. So we can just insert them at the end of the vector. Later we add predecessors, but the helper function properly updates the topological order much more efficiently. With this change, the compile time for the program below drops from 300s to 30s on my machine. define i11129 @test1() { %L1 = load i11129, i11129* undef %B30 = ashr i11129 %L1, %L1 store i11129 %B30, i11129* undef ret i11129 %L1 } This should be generally beneficial, as we can skip a large amount of work. Theoretically there are some scenarios where we might not safe much, e.g. when we add a dependency between the first and last node. Then we would have to shift all nodes. But we still do not have to spend the time re-computing the initial order. Reviewers: MatzeB, atrick, efriedma, niravd, paquette Reviewed By: paquette Differential Revision: https://reviews.llvm.org/D59722
2019-04-17[ScheduleDAGRRList] Recompute topological ordering on demand.Florian Hahn
Currently there is a single point in ScheduleDAGRRList, where we actually query the topological order (besides init code). Currently we are recomputing the order after adding a node (which does not have predecessors) and then we add predecessors edge-by-edge. We can avoid adding edges one-by-one after we added a new node. In that case, we can just rebuild the order from scratch after adding the edges to the DAG and avoid all the updates to the ordering. Also, we can delay updating the DAG until we query the DAG, if we keep a list of added edges. Depending on the number of updates, we can either apply them when needed or recompute the order from scratch. This brings down the geomean compile time for of CTMark with -O1 down 0.3% on X86, with no regressions. Reviewers: MatzeB, atrick, efriedma, niravd, paquette Reviewed By: efriedma Differential Revision: https://reviews.llvm.org/D60125 llvm-svn: 358583
2019-04-10[ScheduleDAG] Add statistics for maintaining the topological order.Florian Hahn
This is helpful to measure the impact of D60125 on maintaining topological orders. Reviewers: MatzeB, atrick, efriedma, niravd Reviewed By: efriedma Differential Revision: https://reviews.llvm.org/D60187 llvm-svn: 358058
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
2018-09-19ScheduleDAG: Cleanup dumping code; NFCMatthias Braun
- Instead of having both `SUnit::dump(ScheduleDAG*)` and `ScheduleDAG::dumpNode(ScheduleDAG*)`, just keep the latter around. - Add `ScheduleDAG::dump()` and avoid code duplication in several places. Implement it for different ScheduleDAG variants. - Add `ScheduleDAG::dumpNodeName()` in favor of the `SUnit::print()` functions. They were only ever used for debug dumping and putting the function into ScheduleDAG is consistent with the `dumpNode()` change. llvm-svn: 342520
2018-04-30IWYU for llvm-config.h in llvm, additions.Nico Weber
See r331124 for how I made a list of files missing the include. I then ran this Python script: for f in open('filelist.txt'): f = f.strip() fl = open(f).readlines() found = False for i in xrange(len(fl)): p = '#include "llvm/' if not fl[i].startswith(p): continue if fl[i][len(p):] > 'Config': fl.insert(i, '#include "llvm/Config/llvm-config.h"\n') found = True break if not found: print 'not found', f else: open(f, 'w').write(''.join(fl)) and then looked through everything with `svn diff | diffstat -l | xargs -n 1000 gvim -p` and tried to fix include ordering and whatnot. No intended behavior change. llvm-svn: 331184
2017-11-28[CodeGen] Rename functions PrintReg* to printReg*Francis Visoiu Mistrih
LLVM Coding Standards: Function names should be verb phrases (as they represent actions), and command-like function should be imperative. The name should be camel case, and start with a lower case letter (e.g. openFile() or isFoo()). Differential Revision: https://reviews.llvm.org/D40416 llvm-svn: 319168
2017-11-17Fix a bunch more layering of CodeGen headers that are in TargetDavid Blaikie
All these headers already depend on CodeGen headers so moving them into CodeGen fixes the layering (since CodeGen depends on Target, not the other way around). llvm-svn: 318490
2017-11-08Target/TargetInstrInfo.h -> CodeGen/TargetInstrInfo.h to match layeringDavid Blaikie
This header includes CodeGen headers, and is not, itself, included by any Target headers, so move it into CodeGen to match the layering of its implementation. llvm-svn: 317647
2017-10-15Reverting r315590; it did not include changes for llvm-tblgen, which is ↵Aaron Ballman
causing link errors for several people. Error LNK2019 unresolved external symbol "public: void __cdecl `anonymous namespace'::MatchableInfo::dump(void)const " (?dump@MatchableInfo@?A0xf4f1c304@@QEBAXXZ) referenced in function "public: void __cdecl `anonymous namespace'::AsmMatcherEmitter::run(class llvm::raw_ostream &)" (?run@AsmMatcherEmitter@?A0xf4f1c304@@QEAAXAEAVraw_ostream@llvm@@@Z) llvm-tblgen D:\llvm\2017\utils\TableGen\AsmMatcherEmitter.obj 1 llvm-svn: 315854
2017-10-12[dump] Remove NDEBUG from test to enable dump methods [NFC]Don Hinton
Summary: Add LLVM_FORCE_ENABLE_DUMP cmake option, and use it along with LLVM_ENABLE_ASSERTIONS to set LLVM_ENABLE_DUMP. Remove NDEBUG and only use LLVM_ENABLE_DUMP to enable dump methods. Move definition of LLVM_ENABLE_DUMP from config.h to llvm-config.h so it'll be picked up by public headers. Differential Revision: https://reviews.llvm.org/D38406 llvm-svn: 315590
2017-07-12[CodeGen] Add dependency printerEvandro Menezes
Add SDep printer to make debugging sessions more productive. Differential revision: https://reviews.llvm.org/D35144 llvm-svn: 307799
2017-06-06Sort the remaining #include lines in include/... and lib/....Chandler Carruth
I did this a long time ago with a janky python script, but now clang-format has built-in support for this. I fed clang-format every line with a #include and let it re-sort things according to the precise LLVM rules for include ordering baked into clang-format these days. I've reverted a number of files where the results of sorting includes isn't healthy. Either places where we have legacy code relying on particular include ordering (where possible, I'll fix these separately) or where we have particular formatting around #include lines that I didn't want to disturb in this patch. This patch is *entirely* mechanical. If you get merge conflicts or anything, just ignore the changes in this patch and run clang-format over your #include lines in the files. Sorry for any noise here, but it is important to keep these things stable. I was seeing an increasing number of patches with irrelevant re-ordering of #include lines because clang-format was used. This patch at least isolates that churn, makes it easy to skip when resolving conflicts, and gets us to a clean baseline (again). llvm-svn: 304787
2017-03-28MachineScheduler/ScheduleDAG: Add support for GetSubGraphValery Pykhtin
Patch by Axel Davy (axel.davy@normalesup.org) Differential revision: https://reviews.llvm.org/D30626 llvm-svn: 298896
2017-02-22[CodeGen] Fix some Clang-tidy modernize and Include What You Use warnings; ↵Eugene Zelenko
other minor fixes (NFC). llvm-svn: 295893
2017-02-21ScheduleDAG: Cleanup; NFCMatthias Braun
- Fix doxygen comments (do not repeat documented name, remove definition comment if there is already one at the declaration, add \p, ...) - Add some const modifiers - Use range based for llvm-svn: 295688
2017-01-28Cleanup dump() functions.Matthias Braun
We had various variants of defining dump() functions in LLVM. Normalize them (this should just consistently implement the things discussed in http://lists.llvm.org/pipermail/cfe-dev/2014-January/034323.html For reference: - Public headers should just declare the dump() method but not use LLVM_DUMP_METHOD or #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) - The definition of a dump method should look like this: #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) LLVM_DUMP_METHOD void MyClass::dump() { // print stuff to dbgs()... } #endif llvm-svn: 293359
2017-01-10[CodeGen] Implement the SUnit::print() methodEvandro Menezes
This method seems to have had a troubled life. This patch proposes that it replaces the recently added helper function dumpSUIdentifier. This way, the method can be used in other files using the SUnit class. Differential revision: https://reviews.llvm.org/D28488 llvm-svn: 291520
2016-11-11Revert "(origin/master, origin/HEAD) MachineScheduler/ScheduleDAG: Add ↵Matthias Braun
support to skipping a node." Revert accidentally committed change. This reverts commit r286655. llvm-svn: 286656
2016-11-11MachineScheduler/ScheduleDAG: Add support to skipping a node.Matthias Braun
The DAG mutators in the scheduler cannot really remove DAG nodes as additional anlysis information such as ScheduleDAGToplogicalSort are already computed at this point and rely on a fixed number of DAG nodes. Alleviate the missing removal with a new flag: Setting the new skip flag on a node ignores it during scheduling. llvm-svn: 286655
2016-11-11ScheduleDAG: Identify EntrySU/ExitSU when dumping node idsMatthias Braun
llvm-svn: 286652
2016-09-23ScheduleDAG: Match enum names when printing sdep kindsMatthias Braun
It is less confusing to have the same names in the debug print as the enum members. llvm-svn: 282273
2016-08-12Use the range variant of find/find_if instead of unpacking begin/endDavid Majnemer
If the result of the find is only used to compare against end(), just use is_contained instead. No functionality change is intended. llvm-svn: 278469
2015-11-06MachineScheduler: Add regpressure information to debug dumpMatthias Braun
llvm-svn: 252340
2015-01-27Replace some uses of getSubtargetImpl with the cached versionEric Christopher
off of the MachineFunction or with the version that takes a Function reference as an argument. llvm-svn: 227185
2014-08-04Remove the TargetMachine forwards for TargetSubtargetInfo basedEric Christopher
information and update all callers. No functional change. llvm-svn: 214781
2014-04-22[Modules] Remove potential ODR violations by sinking the DEBUG_TYPEChandler Carruth
define below all header includes in the lib/CodeGen/... tree. While the current modules implementation doesn't check for this kind of ODR violation yet, it is likely to grow support for it in the future. It also removes one layer of macro pollution across all the included headers. Other sub-trees will follow. llvm-svn: 206837
2014-04-14[C++11] More 'nullptr' conversion. In some cases just using a boolean check ↵Craig Topper
instead of comparing to nullptr. llvm-svn: 206142
2014-03-02[C++11] Replace llvm::next and llvm::prior with std::next and std::prev.Benjamin Kramer
Remove the old functions. llvm-svn: 202636
2014-01-24Fix known typosAlp Toker
Sweep the codebase for common typos. Includes some changes to visible function names that were misspelt. llvm-svn: 200018
2013-07-03Use SmallVectorImpl instead of SmallVector for iterators and references to ↵Craig Topper
avoid specifying the vector size unnecessarily. llvm-svn: 185512
2013-03-01Scheduler diagnostics. Print the register name.Andrew Trick
llvm-svn: 176316
2013-03-01Instructions schedulers should report correct height/depth.Andrew Trick
We avoided computing DAG height/depth during Node printing because it shouldn't depend on an otherwise valid DAG. But this has become far too annoying for the common case of a valid DAG where we want to see valid values. If doing the computation on-the-fly turns out to be a problem in practice, then I'll add a mode to the diagnostics to only force it when we're likely to have a valid DAG, otherwise explicitly print INVALID instead of bogus numbers. For now, just go for it all the time. llvm-svn: 176314
2013-02-16Replace loop with std::find.Benjamin Kramer
No functionality change. llvm-svn: 175366
2013-01-24MIsched: Added biasCriticalPath.Andrew Trick
Allow schedulers to order DAG edges by critical path. This makes DFS-based heuristics more stable and effective. llvm-svn: 173317