summaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/EarlyIfConversion.cpp
AgeCommit message (Collapse)Author
2025-11-16[CodeGen] Turn MCRegUnit into an enum class (NFC) (#167943)Sergei Barannikov
This changes `MCRegUnit` type from `unsigned` to `enum class : unsigned` and inserts necessary casts. The added `MCRegUnitToIndex` functor is used with `SparseSet`, `SparseMultiSet` and `IndexedMap` in a few places. `MCRegUnit` is opaque to users, so it didn't seem worth making it a full-fledged class like `Register`. Static type checking has detected one issue in `PrologueEpilogueInserter.cpp`, where `BitVector` created for `MCRegister` is indexed by both `MCRegister` and `MCRegUnit`. The number of casts could be reduced by using `IndexedMap` in more places and/or adding a `BitVector` adaptor, but the number of casts *per file* is still small and `IndexedMap` has limitations, so it didn't seem worth the effort. Pull Request: https://github.com/llvm/llvm-project/pull/167943
2025-11-12[CodeGen] Use MCRegUnit in more places (NFC) (#167578)Sergei Barannikov
2025-04-01[EarlyIfConverter] Fix reg killed twice after early-if-predicator and ifcvt ↵Afanasyev Ivan
(#133554) Bug relates to `early-if-predicator` and `early-ifcvt` passes. If virtual register has "killed" flag in both basic blocks to be merged into head, both instructions in head basic block will have "killed" flag for this register. It makes MIR incorrect. Example: ``` bb.0: ; if ... %0:intregs = COPY $r0 J2_jumpf %2, %bb.2, implicit-def dead $pc J2_jump %bb.1, implicit-def dead $pc bb.1: ; if.then ... S4_storeiri_io killed %0, 0, 1 J2_jump %bb.3, implicit-def dead $pc bb.2: ; if.else ... S4_storeiri_io killed %0, 0, 1 J2_jump %bb.3, implicit-def dead $pc ``` After early-if-predicator will become: ``` bb.0: %0:intregs = COPY $r0 S4_storeirif_io %1, killed %0, 0, 1 S4_storeirit_io %1, killed %0, 0, 1 ``` Having `killed` flag set twice in bb.0 for `%0` is an incorrect MIR.
2025-03-02[CodeGen] Use MCRegister and Register. NFCCraig Topper
2025-02-20Revert "[CodeGen] Remove static member function Register::isVirtualRegister. ↵Christopher Di Bella
NFC (#127968)" This reverts commit ff99af7ea03b3be46bec7203bd2b74048d29a52a.
2025-02-20[CodeGen] Remove static member function Register::isVirtualRegister. NFC ↵Craig Topper
(#127968) Use nonstatic member instead. This requires explicit conversions, but many will go away as we continue converting unsigned to Register. In a few places where it was simple, I changed unsigned to Register.
2025-01-18[CodeGen] Use Register/MCRegister::isPhysical. NFCCraig Topper
2024-11-09[Instrumentation] Support `MachineFunction` in `OptNoneInstrumentation` ↵paperchalice
(#115471) Support `MachineFunction` in `OptNoneInstrumentation`, also add `isRequired` to all necessary passes.
2024-10-16[CodeGen][NewPM] Port EarlyIfConversion pass to NPM. (#108508)Christudasan Devadasan
2024-10-16[CodeGen][NewPM] Port machine trace metrics analysis to new pass manager. ↵Christudasan Devadasan
(#108507)
2024-10-08[NFC][EarlyIfConverter] Rename SSAIfConv::runOnMachineFunction to ↵Juan Manuel Martinez Caamaño
SSAIfConv::init (#111500)
2024-10-08Revert "[NFC][EarlyIfConverter] Turn SSAIfConv into a local variable ↵Juan Manuel Martinez Caamaño
(#107390)" (#111385) This reverts commit 09a4c23eb410d4be52202bed21c967a3653c3544.
2024-10-07Revert "[NFC][EarlyIfConverter] Replace boolean Predicate for a class ↵Juan Manuel Martinez Caamaño
(#108519)" (#111372) This reverts commit 9e7315912656628b606e884e39cdeb261b476f16.
2024-10-07Revert "[NFC][EarlyIfConverter] Remove unused member variables"Juan Manuel Martinez Caamaño
This reverts commit 3c83102f0615c7d66f6df698ca472ddbf0e9483d.
2024-09-22[CodeGen] Construct SmallVector with ArrayRef (NFC) (#109566)Kazu Hirata
2024-09-20[NFC][EarlyIfConverter] Remove unused member variablesJuan Manuel Martinez Caamaño
2024-09-20[NFC][EarlyIfConverter] Replace boolean Predicate for a class (#108519)Juan Manuel Martinez Caamaño
Currently SSAIfConv is used in 2 scenarios. Generalize them to support more scenarios.
2024-09-13[NFC][EarlyIfConverter] Turn SSAIfConv into a local variable (#107390)Juan Manuel Martinez Caamaño
2024-07-31[Support] Erase blocks after DomTree::eraseNode (#101195)Alexis Engelke
Change eraseNode to require that the basic block is still contained inside the function. This is a preparation for using numbers of basic blocks inside the dominator tree, which are invalid for blocks that are not inside a function.
2024-07-26[CodeGen] Remove AA parameter of isSafeToMove (#100691)Pengcheng Wang
This `AA` parameter is not used and for most uses they just pass a nullptr. The use of `AA` was removed since 8d0383e.
2024-07-09[CodeGen][NewPM] Port `machine-loops` to new pass manager (#97793)paperchalice
- Add `MachineLoopAnalysis`. - Add `MachineLoopPrinterPass`. - Convert to `MachineLoopInfoWrapperPass` in legacy pass manager.
2024-06-28Reapply "[CodeGen][NewPM] Port machine-branch-prob to new pass manager" ↵paperchalice
(#96858) (#96869) This reverts commit ab58b6d58edf6a7c8881044fc716ca435d7a0156. In `CodeGen/Generic/MachineBranchProb.ll`, `llc` crashed with dumped MIR when targeting PowerPC. Move test to `llc/new-pm`, which is X86 specific.
2024-06-27Revert "[CodeGen][NewPM] Port machine-branch-prob to new pass manager" (#96858)paperchalice
Reverts llvm/llvm-project#96389 Some ppc bots failed.
2024-06-27[CodeGen][NewPM] Port machine-branch-prob to new pass manager (#96389)paperchalice
Like IR version `print<branch-prob>`, there is also a `print<machine-branch-prob>`.
2024-06-26[CodeGen] Use range-based for loops (NFC) (#96777)Kazu Hirata
2024-06-11[CodeGen][NewPM] Split `MachineDominatorTree` into a concrete analysis ↵paperchalice
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-24[CodeGen] Make the parameter TRI required in some functions. (#85968)Xu Zhang
Fixes #82659 There are some functions, such as `findRegisterDefOperandIdx` and `findRegisterDefOperand`, that have too many default parameters. As a result, we have encountered some issues due to the lack of TRI parameters, as shown in issue #82411. Following @RKSimon 's suggestion, this patch refactors 9 functions, including `{reads, kills, defines, modifies}Register`, `registerDefIsDead`, and `findRegister{UseOperandIdx, UseOperand, DefOperandIdx, DefOperand}`, adjusting the order of the TRI parameter and making it required. In addition, all the places that call these functions have also been updated correctly to ensure no additional impact. After this, the caller of these functions should explicitly know whether to pass the `TargetRegisterInfo` or just a `nullptr`.
2023-10-11[EarlyIfConversion] Simplify condition after #65729Jay Foad
2023-10-11Clean up strange uses of getAnalysisIfAvailable (#65729)Jay Foad
After a pass calls addRequired<X>() it is strange to call getAnalysisIfAvailable<X>() because analysis X should always be available. Use getAnalysis<X>() instead.
2023-06-16[MC] Add MCRegisterInfo::regunits for iteration over register unitsSergei Barannikov
Reviewed By: foad Differential Revision: https://reviews.llvm.org/D152098
2023-05-12[EarlyIfCvt] Don't if-convert if condition has only loop-invariant ops.Florian Hahn
This patch adds a heuristic to skip if-conversion if the condition has a high chance of being predictable. If the condition is in a loop, consider it predictable if the condition itself or all its operands are loop-invariant. E.g. this considers a load from a loop-invariant address predictable; we were unable to prove that it doesn't alias any of the memory-writes in the loop, but it is likely to read to same value multiple times. This is a relatively crude heuristic, but it helps to prevent excessive if-conversion in multiple workloads in practice. Reviewed By: apostolakis Differential Revision: https://reviews.llvm.org/D141639
2023-05-02[Coverity] Fix unchecked return value, NFCPhoebe Wang
The `ReversePredicate` should have made sure the reverse predicate is supported by target, but the check comes from early function and might be invalid by any mistake. So it's better to double confirm it here. Differential Revision: https://reviews.llvm.org/D149586
2023-04-17Fix uninitialized pointer members in CodeGenAkshay Khadse
This change initializes the members TSI, LI, DT, PSI, and ORE pointer feilds of the SelectOptimize class to nullptr. Reviewed By: LuoYuanke Differential Revision: https://reviews.llvm.org/D148303
2023-02-14[MachineTraceMetrics][NFC] Move Strategy enum out of the classAnton Sidorenko
Make forward declaration possible to reduce amount of dependencies and reduce re-compilation burden caused by further patches. Reviewed By: spatel Differential Revision: https://reviews.llvm.org/D140539
2023-01-13[CodeGen] Remove uses of Register::isPhysicalRegister/isVirtualRegister. NFCCraig Topper
Use isPhysical/isVirtual methods. Reviewed By: foad Differential Revision: https://reviews.llvm.org/D141715
2022-12-14[EarlyIfConversion] Add target hook to allow for multiple ifcvt iterations.Hendrik Greving
Adds a target hook canPredicatePredicatedInstr(const MachineInstr&) that assumes an instruction is already predicated and returns true if it can be predicated again, used by the early if-conversion pass in order to iterate multiple times on architectures supporting predicate logic. No test added since there is no upstream target that can take advantage. Differential Revision: https://reviews.llvm.org/D139981
2022-07-18CodeGen: Remove AliasAnalysis from regallocMatt Arsenault
This was stored in LiveIntervals, but not actually used for anything related to LiveIntervals. It was only used in one check for if a load instruction is rematerializable. I also don't think this was entirely correct, since it was implicitly assuming constant loads are also dereferenceable. Remove this and rely only on the invariant+dereferenceable flags in the memory operand. Set the flag based on the AA query upfront. This should have the same net benefit, but has the possible disadvantage of making this AA query nonlazy. Preserve the behavior of assuming pointsToConstantMemory implying dereferenceable for now, but maybe this should be changed.
2022-07-17[CodeGen] Qualify auto variables in for loops (NFC)Kazu Hirata
2022-03-16[NFC][CodeGen] Rename some functions in MachineInstr.h and remove duplicated ↵Shengchen Kan
comments
2022-03-16Cleanup codegen includesserge-sans-paille
This is a (fixed) recommit of https://reviews.llvm.org/D121169 after: 1061034926 before: 1063332844 Discourse thread: https://discourse.llvm.org/t/include-what-you-use-include-cleanup Differential Revision: https://reviews.llvm.org/D121681
2022-03-10Revert "Cleanup codegen includes"Nico Weber
This reverts commit 7f230feeeac8a67b335f52bd2e900a05c6098f20. Breaks CodeGenCUDA/link-device-bitcode.cu in check-clang, and many LLVM tests, see comments on https://reviews.llvm.org/D121169
2022-03-10Cleanup codegen includesserge-sans-paille
after: 1061034926 before: 1063332844 Differential Revision: https://reviews.llvm.org/D121169
2022-01-30[CodeGen] Use default member initialization (NFC)Kazu Hirata
Identified with modernize-use-default-member-init.
2021-12-05[llvm] Use range-based for loops (NFC)Kazu Hirata
2021-04-30[EarlyIfConversion] Avoid producing selects with identical operandsJon Roelofs
This extends the early-ifcvt pass to avoid a few more cases where the resulting select instructions would have matching operands. Additionally, we now use TII to determine "sameness" of the operands so that as TII gets smarter, so too will ifcvt. The attached test case was bugpoint-reduced down from CINT2000/252.eon in the test-suite. See: https://clang.godbolt.org/z/WvnrcrGEn Differential Revision: https://reviews.llvm.org/D101508
2021-04-30Revert "[EarlyIfConversion] Avoid producing selects with identical operands"Jon Roelofs
This reverts commit 3d27b5d28aabf8516aa1fefc78a6878b89a992f0. Broke one of the PPC tests, which I didn't see because I usually build with only the x86/AARch64 targets enabled... oops. https://lab.llvm.org/buildbot#builders/109/builds/13834 llvm/test/CodeGen/PowerPC/expand-foldable-isel.ll
2021-04-30[EarlyIfConversion] Avoid producing selects with identical operandsJon Roelofs
This extends the early-ifcvt pass to avoid a few more cases where the resulting select instructions would have matching operands. Additionally, we now use TII to determine "sameness" of the operands so that as TII gets smarter, so too will ifcvt. The attached test case was bugpoint-reduced down from CINT2000/252.eon in the test-suite. See: https://clang.godbolt.org/z/WvnrcrGEn Differential Revision: https://reviews.llvm.org/D101508
2021-02-13[CodeGen] Use range-based for loops (NFC)Kazu Hirata
2020-10-06[NFC][MC] Type uses of MCRegUnitIterator as MCRegisterMircea Trofin
This is one of many subsequent similar changes. Note that we're ok with the parameter being typed as MCPhysReg, as MCPhysReg -> MCRegister is a correct conversion; Register -> MCRegister assumes the former is indeed physical, so we stop relying on the implicit conversion and use the explicit, value-asserting asMCReg(). Differential Revision: https://reviews.llvm.org/D88862
2020-09-03Fix Wdocumentation trailing comments warnings. NFCI.Simon Pilgrim