aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/MachineBasicBlock.cpp
AgeCommit message (Collapse)AuthorFilesLines
4 days[CodeGen] Ignore requiresStructuredCFG check in canSplitCriticalEdge if ↵Wenju He1-4/+13
successor is loop header (#154063) This addresses a performance issue for our downstream GPU target that sets requiresStructuredCFG to true. The issue is that EarlyMachineLICM pass does not hoist loop invariants because a critical edge is not split. The critical edge's destination a loop header. Splitting the critical edge will not break structured CFG. Add a nvptx test to demonstrate the issue since the target also requires structured CFG. --------- Co-authored-by: Matt Arsenault <arsenm2@gmail.com>
5 days[MachineSink] Remove subrange of live-ins from super register as well. (#159145)Pete Chou1-0/+20
Post-RA machine sinking could sink a copy of sub-register into a successor. However, the sub-register might not be removed from the live-in bitmask of its super register in successor and then a later pass, e.g, if-converter, may add an implicit use of the register from live-in resulting in an use of an undefined register. This change makes sure subrange of live-ins from super register could be removed as well.
6 days[CodeGen] Extract copy-paste on PHI MachineInstr income removal. (#158634)Afanasyev Ivan1-0/+6
2025-08-21[LiveRegUnits] Exclude runtime defined liveins when computing liveouts (#154325)Benjamin Maxwell1-3/+0
These liveins are not defined by predecessors, so should not be considered as liveouts in predecessor blocks. This resolves: - https://github.com/llvm/llvm-project/pull/149062#discussion_r2285072001 - https://github.com/llvm/llvm-project/pull/153417#issuecomment-3199972351
2025-06-16[llvm] Remove unused includes (NFC) (#144293)Kazu Hirata1-1/+0
These are identified by misc-include-cleaner. I've filtered out those that break builds. Also, I'm staying away from llvm-config.h, config.h, and Compiler.h, which likely cause platform- or compiler-specific build failures.
2025-06-12[DLCov][NFC] Propagate annotated DebugLocs through transformations (#138047)Stephen Tozer1-1/+1
Part of the coverage-tracking feature, following #107279. In order for DebugLoc coverage testing to work, we firstly have to set annotations for intentionally-empty DebugLocs, and secondly we have to ensure that we do not drop these annotations as we propagate DebugLocs throughout compilation. As the annotations exist as part of the DebugLoc class, and not the underlying DILocation, they will not survive a DebugLoc->DILocation->DebugLoc roundtrip. Therefore this patch modifies a number of places in the compiler to propagate DebugLocs directly rather than via the underlying DILocation. This has no effect on the output of normal builds; it only ensures that during coverage builds, we do not drop incorrectly annotations and therefore create false positives. The bulk of these changes are in replacing DILocation::getMergedLocation(s) with a DebugLoc equivalent, and in changing the IRBuilder to store a DebugLoc directly rather than storing DILocations in its general Metadata array. We also use a new function, `DebugLoc::orElse`, which selects the "best" DebugLoc out of a pair (valid location > annotated > empty), preferring the current DebugLoc on a tie - this encapsulates the existing behaviour at a few sites where we _may_ assign a DebugLoc to an existing instruction, while extending the logic to handle annotation DebugLocs at the same time.
2025-05-24[CodeGen] Remove unused includes (NFC) (#141320)Kazu Hirata1-1/+0
These are identified by misc-include-cleaner. I've filtered out those that break builds. Also, I'm staying away from llvm-config.h, config.h, and Compiler.h, which likely cause platform- or compiler-specific build failures.
2025-05-22[LLVM][CodeGen] Add convenience accessors for MachineFunctionProperties ↵users/pcc/spr/main.elf-add-branch-to-branch-optimizationRahul Joshi1-6/+4
(#140002) Add per-property has<Prop>/set<Prop>/reset<Prop> functions to MachineFunctionProperties.
2025-05-01[NFC][LLVM][CodeGen] Refactor MIR Printer (#137361)Rahul Joshi1-13/+29
- Move `MIPrinter` class to anonymous namespace, and remove it as a friend of `MachineBasicBlock`. - Move `canPredictBranchProbabilities` to `MachineBasicBlock` and change it to use the new `BranchProbability::normalizeProbabilities` function that accepts a range, and also to use `llvm::equal()` to check equality of the two vectors. - Use `ListSeparator` to print comma separate lists instead of manual code to do that.
2025-03-06[win] NFC: Rename `EHCatchret` to `EHCont` to allow for EH Continuation ↵Daniel Paoliello1-4/+4
targets that aren't `catchret` instructions (#129953) This change splits out the renaming and comment updates from #129612 as a non-functional change.
2025-03-02[CodeGen] Use MCRegister and Register. NFCCraig Topper1-1/+1
2025-02-25[MachineBasicBlock][NFC] Decouple SplitCriticalEdges from pass manager (#128151)Akshat Oke1-11/+20
New clients should use this overload that accepts analyses directly.
2025-01-18[CodeGen] Use Register/MCRegister::isPhysical. NFCCraig Topper1-1/+1
2024-12-13Reapply "[DomTreeUpdater] Move critical edge splitting code to updater" ↵paperchalice1-3/+5
(#119547) This relands commit #115111. Use traditional way to update post dominator tree, i.e. break critical edge splitting into insert, insert, delete sequence. When splitting critical edges, the post dominator tree may change its root node, and `setNewRoot` only works in normal dominator tree... See https://github.com/llvm/llvm-project/blob/6c7e5827eda26990e872eb7c3f0d7866ee3c3171/llvm/include/llvm/Support/GenericDomTree.h#L684-L687
2024-12-11Revert "[DomTreeUpdater] Move critical edge splitting code to updater" (#119512)paperchalice1-5/+3
Reverts llvm/llvm-project#115111 Causes #119511
2024-12-11[DomTreeUpdater] Move critical edge splitting code to updater (#115111)paperchalice1-3/+5
Support critical edge splitting in dominator tree updater. Continue the work in #100856. Compile time check: https://llvm-compile-time-tracker.com/compare.php?from=87c35d782795b54911b3e3a91a5b738d4d870e55&to=42b3e5623a9ab4c3648564dc0926b36f3b438a3a&stat=instructions%3Au
2024-08-24[CodeGen] Replace MCPhysReg with MCRegister in ↵Craig Topper1-2/+2
MachineBasicBlock::isLiveIn/removeLiveIn. NFC We already used it for addLiveIn.
2024-07-17[CodeGen][NewPM] Port `phi-node-elimination` to new pass manager (#98867)paperchalice1-12/+17
- Add `PHIEliminationPass `. - Support new pass manager in `MachineBasicBlock:: SplitCriticalEdge `
2024-07-12[CodeGen] Use range-based for loops (NFC) (#98459)Kazu Hirata1-4/+3
2024-07-11Revert "[CodeGen] Remove `applySplitCriticalEdges` in `MachineDominatorTree` ↵Nikita Popov1-13/+3
(#97055)" This reverts commit c5e5088033fed170068d818c54af6862e449b545. Causes large compile-time regressions.
2024-07-11[CodeGen] Remove `applySplitCriticalEdges` in `MachineDominatorTree` (#97055)paperchalice1-3/+13
Summary: - Remove wrappers in `MachineDominatorTree`. - Remove `MachineDominatorTree` update code in `MachineBasicBlock::SplitCriticalEdge`. - Use `MachineDomTreeUpdater` in passes which call `MachineBasicBlock::SplitCriticalEdge` and preserve `MachineDominatorTreeWrapperPass` or CFG analyses. Commit abea99f65a97248974c02a5544eaf25fc4240056 introduced related methods in 2014. Now we have SemiNCA based dominator tree in 2017 and dominator tree updater, the solution adopted here seems a bit outdated.
2024-07-10[CodeGen][NewPM] Port `LiveIntervals` to new pass manager (#98118)paperchalice1-1/+2
- Add `LiveIntervalsAnalysis`. - Add `LiveIntervalsPrinterPass`. - Use `LiveIntervalsWrapperPass` in legacy pass manager. - Use `std::unique_ptr` instead of raw pointer for `LICalc`, so destructor and default move constructor can handle it correctly. This would be the last analysis required by `PHIElimination`.
2024-07-09[CodeGen][NewPM] Port `SlotIndexes` to new pass manager (#97941)paperchalice1-1/+2
- Add `SlotIndexesAnalysis`. - Add `SlotIndexesPrinterPass`. - Use `SlotIndexesWrapperPass` in legacy pass.
2024-07-09[CodeGen][NewPM] Port `LiveVariables` to new pass manager (#97880)paperchalice1-1/+2
- Port `LiveVariables` to new pass manager. - Convert to `LiveVariablesWrapperPass` in legacy pass manager.
2024-07-09[CodeGen][NewPM] Port `machine-loops` to new pass manager (#97793)paperchalice1-5/+6
- Add `MachineLoopAnalysis`. - Add `MachineLoopPrinterPass`. - Convert to `MachineLoopInfoWrapperPass` in legacy pass manager.
2024-06-28Reapply "[CodeGen] Introduce `MachineDomTreeUpdater`" (#96846) (#96851)paperchalice1-0/+6
This reverts commit 0f8849349ae3d3f2f537ad6ab233a586fb39d375. Resolve conflict in `MachinePostDominators.h` There is a conflict after merging #96378, resolved in #96852. Both PRs modified `MachinePostDominators.h` and triggered build failure.
2024-06-27Revert "[CodeGen] Introduce `MachineDomTreeUpdater`" (#96846)paperchalice1-6/+0
Reverts llvm/llvm-project#95369 Many build bots failed
2024-06-27[CodeGen] Introduce `MachineDomTreeUpdater` (#95369)paperchalice1-0/+6
This commit converts most of `DomTreeUpdater` into `GenericDomTreeUpdater` class template, so IR and MIR can reuse some codes. There are some differences between interfaces of `BasicBlock` and `MachineBasicBlock`, so subclasses still need to implement some functions, like `forceFlushDeletedBB`.
2024-06-20[CodeGen] Use temp symbol for MBBs (#95031)Alexis Engelke1-8/+8
Internal label names never occur in the symbol table, so when using an object streamer, there's no point in constructing these names and then adding them to hash tables -- they are never visible in the output. It's not possible to reuse createTempSymbol, because on BPF has a different prefix for globals and basic blocks right now.
2024-06-11[CodeGen][NewPM] Split `MachineDominatorTree` into a concrete analysis ↵paperchalice1-3/+3
result (#94571) Prepare for new pass manager version of `MachineDominatorTreeAnalysis`. We may need a machine dominator tree version of `DomTreeUpdater` to handle `SplitCriticalEdge` in some CodeGen passes.
2024-04-17[LiveIns] Improve recomputeLiveIns() (#88951)Kai Nacke1-0/+6
Some small changes to recomputeLiveIns() to improve performance: - Instead of copying the list of old live-ins, and then clearing them, a new method swaps the list for an empty one. - getLiveIns() now returns a constant reference to the list As result, the list-data is never copied. Depending on the implementation details of the vector container, it can also save calls to allocate and deallocate memory. I see a small improvement on CTMark with these changes. --------- Co-authored-by: Nikita Popov <github@npopov.com>
2024-04-08[CodeGen][DebugInfo] Add missing DebugLoc for SplitCriticalEdge (#72192)Haohai Wen1-1/+9
In SplitCriticalEdge, DebugLoc of the branch instruction in new created MBB was set to empty. It should be set and we can find proper DebugLoc for it in most cases. This patch set it to non empty merged DebugLoc of current MBB branches.
2023-11-16[AMDGPU] RA inserted scalar instructions can be at the BB top (#72140)Christudasan Devadasan1-2/+2
We adjust the insertion point at the BB top for spills/copies during RA to ensure they are placed after the exec restore instructions required for the divergent control flow execution. This is, however, required only for the vector operations. The insertions for scalar registers can still go to the BB top.
2023-11-13[PHIElimination] Handle subranges in LiveInterval updates (#69429)Carl Ritson1-0/+10
Add subrange tracking and handling for LiveIntervals during PHI elimination. This requires extending MachineBasicBlock::SplitCriticalEdge to also update subrange intervals.
2023-10-27[BasicBlockSections] Apply path cloning with -basic-block-sections. (#68860)Rahman Lavaee1-2/+4
https://github.com/llvm/llvm-project/commit/28b912687900bc0a67cd61c374fce296b09963c4 introduced the path cloning format in the basic-block-sections profile. This PR validates and applies path clonings. A path cloning is valid if all of these conditions hold: 1. All bb ids in the path are mapped to existing blocks. 2. Each two consecutive bb ids in the path have a successor relationship in the CFG. 3. The path does not include a block with indirect branches, except possibly as the last block. Applying a path cloning involves cloning all blocks in the path (except the first one) and setting up their branches. Once all clonings are applied, the cluster information is used to guide block layout in the modified function.
2023-10-21[MachineBasicBlock] Fix SlotIndexUpdater for insertion order (#69424)Carl Ritson1-3/+9
Follow up fix for #68786 to address that MachineFunction handleInsertion is actually called before a new instruction has been inserted into the block. Hence new instructions must be recorded and SlotIndex updates performed after the delegate call.
2023-10-15[MachineBasicBlock] Fix use after free in SplitCriticalEdge (#68786)Carl Ritson1-31/+27
Remove use after free when attempting to update SlotIndexes in MachineBasicBlock::SplitCriticalEdge. Use MachineFunction delegate mechanism to capture target specific manipulations of branch instructions and update SlotIndexes.
2023-10-06AMDGPU: Fix temporal divergence introduced by machine-sink (#67456)Petar Avramovic1-0/+4
Temporal divergence that was present in input or introduced in IR transforms, like code-sinking or LICM, is handled in SIFixSGPRCopies by changing sgpr source instr to vgpr instr. After 5b657f5, that moved LICM after AMDGPUCodeGenPrepare, machine-sinking can introduce temporal divergence by sinking instructions outside of the cycle. Add isSafeToSink callback in TargetInstrInfo.
2023-09-11Revert "[PHIElimination] Handle subranges in LiveInterval updates"Vitaly Buka1-12/+0
Leaks memory. This reverts commit 3bff611068ae70e3273a46bbc72bc66b66f98c1c.
2023-09-11[PHIElimination] Handle subranges in LiveInterval updatesCarl Ritson1-0/+12
Add handling for subrange updates in LiveInterval preservation. This requires extending MachineBasicBlock::SplitCriticalEdge to also update subrange intervals. Reviewed By: arsenm Differential Revision: https://reviews.llvm.org/D158144
2023-08-20[Propeller] Deprecate Codegen paths for SHT_LLVM_BB_ADDR_MAP version 1.Rahman Lavaee1-5/+0
This patch removes the `getBBIDOrNumber` which was introduced to allow emitting version 1. Reviewed By: shenhan Differential Revision: https://reviews.llvm.org/D158299
2023-07-27[CodeGen] Store call frame size in MachineBasicBlockJay Foad1-0/+6
Record the call frame size on entry to each basic block. This is usually zero except when a basic block has been split in the middle of a call sequence. This simplifies PEI::replaceFrameIndices which previously had to visit basic blocks in a specific order and had special handling for unreachable blocks. More importantly it paves the way for an equally simple implementation of a backwards version of replaceFrameIndices, which is required to fully convert PrologEpilogInserter to backwards register scavenging, which is preferred because it does not rely on accurate kill flags. Differential Revision: https://reviews.llvm.org/D156113
2023-07-13Revert "[CodeGen] Store SP adjustment in MachineBasicBlock. NFCI."Oliver Stannard1-5/+0
This reverts commit 58d1eaa3b6ce4f7285c51f83faff7a3ac374c746.
2023-07-12[CodeGen] Store SP adjustment in MachineBasicBlock. NFCI.Jay Foad1-0/+5
Record the SP adjustment on entry to each basic block. This is almost always zero except on targets like ARM which can split a basic block in the middle of a call sequence. This simplifies PEI::replaceFrameIndices which previously had to visit basic blocks in a specific order and had special handling for unreachable blocks. More importantly it paves the way for an equally simple implementation of a backwards version of replaceFrameIndices, which is required to fully convert PrologEpilogInserter to backwards register scavenging, which is preferred because it does not rely on accurate kill flags. Differential Revision: https://reviews.llvm.org/D154281
2023-06-25[llvm] Add missing StringExtras.h includesElliot Goodrich1-0/+1
In preparation for removing the `#include "llvm/ADT/StringExtras.h"` from the header to source file of `llvm/Support/Error.h`, first add in all the missing includes that were previously included transitively through this header.
2023-06-01[CodeGen] Make use of MachineInstr::all_defs and all_uses. NFCI.Jay Foad1-3/+2
Differential Revision: https://reviews.llvm.org/D151424
2023-05-25[CodeGen] Fix for MachineBasicBlock::rfindDebugLoc(instr_rend())Bjorn Pettersson1-0/+2
Make sure we do not crash in rfindDebugLoc when starting at instr_rend(). Solution is to see it as we start one MI before the first MI, so we can start searching forward at instr_begin() instead. This behavior is similar to how findPrevDebugLoc(instr_end()) works. Differential Revision: https://reviews.llvm.org/D150577
2023-05-25[CodeGen] Add unittest for findDebugLoc, rfindDebugLoc, findPrevDebugLoc and ↵Bjorn Pettersson1-4/+6
rfindPrevDebugLoc. NFC - Add some unittests for the findDebugLoc, rfindDebugLoc, findPrevDebugLoc and rfindPrevDebugLoc helpers in MachineBasicBlock. - Clean up code comments and code formatting related to the functions mentioned above. This was extracted as a pre-commit to D150577, adn some of the tests are commented out since they would crash/assert in a rather uncontrolled way.
2023-05-10Support critical edge splitting for jump tablesMatthias Braun1-2/+73
Add support for splitting critical edges coming from an indirect jump using a jump table ("switch jumps"). This introduces the `TargetInstrInfo::getJumpTableIndex` callback to allows targets to return an index into `MachineJumpTableInfo` for a given indirect jump. It also updates to `MachineBasicBlock::SplitCriticalEdge` to allow splitting of critical edges by rewriting jump table entries. This is largely based on work done by Zhixuan Huan in D132202. Differential Revision: https://reviews.llvm.org/D140975
2023-04-12[BranchRelaxation] Correct JumpToFT valueAnshil Gandhi1-2/+2
Toggle true/false values of the JumpToFallThrough parameter to simplify code and make it consistent with the documentation for the `getFallThrough(..)` method. Reviewed By: bcahoon Differential Revision: https://reviews.llvm.org/D148139