aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-06-18[RemoveDIs][NFC] Remove dbg intrinsic handling code from SelectionDAG ISel ↵Orlando Cazalet-Hyams1-1/+0
(#144702)
2025-03-02[SelectionDAG] Use Register and MCRegister. NFCCraig Topper1-2/+2
Add operators to Register to supporting adding an offset to get another Register.
2025-02-27[SelectionDAG] Avoid repeated hash lookups (NFC) (#128999)Kazu Hirata1-2/+2
2025-01-24[NFC][DebugInfo] Use iterator-flavour getFirstNonPHI at many call-sites ↵Jeremy Morse1-3/+3
(#123737) As part of the "RemoveDIs" project, BasicBlock::iterator now carries a debug-info bit that's needed when getFirstNonPHI and similar feed into instruction insertion positions. Call-sites where that's necessary were updated a year ago; but to ensure some type safety however, we'd like to have all calls to getFirstNonPHI use the iterator-returning version. This patch changes a bunch of call-sites calling getFirstNonPHI to use getFirstNonPHIIt, which returns an iterator. All these call sites are where it's obviously safe to fetch the iterator then dereference it. A follow-up patch will contain less-obviously-safe changes. We'll eventually deprecate and remove the instruction-pointer getFirstNonPHI, but not before adding concise documentation of what considerations are needed (very few). --------- Co-authored-by: Stephen Tozer <Melamoto@gmail.com>
2025-01-20[Mips] Fix compiler crash when returning fp128 after calling a functi… ↵yingopq1-1/+1
(#117525) …on returning { i8, i128 } Fixes https://github.com/llvm/llvm-project/issues/96432.
2024-11-03[SelectionDAG] Remove unused includes (NFC) (#114697)Kazu Hirata1-1/+0
Identified with misc-include-cleaner.
2024-10-11[CodeGen] Simplify code with *Map::operator[] (NFC) (#112075)Kazu Hirata1-2/+1
2024-10-04[LLVM] Add HasFakeUses to MachineFunction (#110097)Stephen Tozer1-4/+15
Following the addition of the llvm.fake.use intrinsic and corresponding MIR instruction, two further changes are planned: to add an -fextend-lifetimes flag to Clang that emits these intrinsics, and to have -Og enable this flag by default. Currently, some logic for handling fake uses is gated by the optdebug attribute, which is intended to be switched on by -fextend-lifetimes (and by extension -Og later on). However, the decision was made that a general optdebug attribute should be incompatible with other opt_ attributes (e.g. optsize, optnone), since they all express different intents for how to optimize the program. We would still like to allow -fextend-lifetimes with optsize however (i.e. -Os -fextend-lifetimes should be legal), since it may be a useful configuration and there is no technical reason to not allow it. This patch resolves this by tracking MachineFunctions that have fake uses, allowing us to run passes that interact with them and skip passes that clash with them.
2024-08-06[CodeGen] Use BasicBlock numbers to map to MBBs (#101883)Alexis Engelke1-1/+2
Now that basic blocks have numbers, we can replace the BB-to-MBB maps and the visited set during ISel with vectors for faster lookup.
2024-08-04[CodeGen][NFC] Add wrapper method for MBBMap (#101893)Alexis Engelke1-14/+10
This is a preparation for changing the data structure of MBBMap.
2024-06-28[IR] Add getDataLayout() helpers to Function and GlobalValue (#96919)Nikita Popov1-2/+2
Similar to https://github.com/llvm/llvm-project/pull/96902, this adds `getDataLayout()` helpers to Function and GlobalValue, replacing the current `getParent()->getDataLayout()` pattern.
2024-05-19[CodeGen][SDAG] Track returntwice in lowering info (#92640)aengelke1-0/+4
This saves an extra iteration over the all instructions of the function.
2024-05-19[CodeGen][SDAG] Skip preferred extend at O0 (#92643)aengelke1-2/+4
This is a pure optimization to avoid redundant extensions, but iterating over all users is expensive, so don't do this at -O0.
2024-03-19[RemoveDIs][NFC] Rename DPValue -> DbgVariableRecord (#85216)Stephen Tozer1-1/+1
This is the major rename patch that prior patches have built towards. The DPValue class is being renamed to DbgVariableRecord, which reflects the updated terminology for the "final" implementation of the RemoveDI feature. This is a pure string substitution + clang-format patch. The only manual component of this patch was determining where to perform these string substitutions: `DPValue` and `DPV` are almost exclusively used for DbgRecords, *except* for: - llvm/lib/target, where 'DP' is used to mean double-precision, and so appears as part of .td files and in variable names. NB: There is a single existing use of `DPValue` here that refers to debug info, which I've manually updated. - llvm/tools/gold, where 'LDPV' is used as a prefix for symbol visibility enums. Outside of these places, I've applied several basic string substitutions, with the intent that they only affect DbgRecord-related identifiers; I've checked them as I went through to verify this, with reasonable confidence that there are no unintended changes that slipped through the cracks. The substitutions applied are all case-sensitive, and are applied in the order shown: ``` DPValue -> DbgVariableRecord DPVal -> DbgVarRec DPV -> DVR ``` Following the previous rename patches, it should be the case that there are no instances of any of these strings that are meant to refer to the general case of DbgRecords, or anything other than the DPValue class. The idea behind this patch is therefore that pure string substitution is correct in all cases as long as these assumptions hold.
2024-03-06Restore "Implement convergence control in MIR using SelectionDAG (#71785)"Sameer Sahasrabuddhe1-0/+10
This restores commit c7fdd8c11e54585dc9d15d63de9742067e0506b9. Previously reverted in f010b1bef4dda2c7082cbb41dbabf1f149cce306. LLVM function calls carry convergence control tokens as operand bundles, where the tokens themselves are produced by convergence control intrinsics. This patch implements convergence control tokens in MIR as follows: 1. Introduce target-independent ISD opcodes and MIR opcodes for convergence control intrinsics. 2. Model token values as untyped virtual registers in MIR. The change also introduces an additional ISD opcode CONVERGENCECTRL_GLUE and a corresponding machine opcode with the same spelling. This glues the convergence control token to SDNodes that represent calls to intrinsics. The glued token is later translated to an implicit argument in the MIR. The lowering of calls to user-defined functions is target-specific. On AMDGPU, the convergence control operand bundle at a non-intrinsic call is translated to an explicit argument to the SI_CALL_ISEL instruction. Post-selection adjustment converts this explicit argument to an implicit argument on the SI_CALL instruction.
2024-03-04Revert "Restore "Implement convergence control in MIR using SelectionDAG ↵Mitch Phillips1-10/+0
(#71785)"" This reverts commit c7fdd8c11e54585dc9d15d63de9742067e0506b9. Reason: Broke the sanitizer buildbots. See the comments at https://github.com/llvm/llvm-project/pull/71785 for more information.
2024-03-04Restore "Implement convergence control in MIR using SelectionDAG (#71785)"Sameer Sahasrabuddhe1-0/+10
Original commit 79889734b940356ab3381423c93ae06f22e772c9. Perviously reverted in commit a2afcd5721869d1d03c8146bae3885b3385ba15e. LLVM function calls carry convergence control tokens as operand bundles, where the tokens themselves are produced by convergence control intrinsics. This patch implements convergence control tokens in MIR as follows: 1. Introduce target-independent ISD opcodes and MIR opcodes for convergence control intrinsics. 2. Model token values as untyped virtual registers in MIR. The change also introduces an additional ISD opcode CONVERGENCECTRL_GLUE and a corresponding machine opcode with the same spelling. This glues the convergence control token to SDNodes that represent calls to intrinsics. The glued token is later translated to an implicit argument in the MIR. The lowering of calls to user-defined functions is target-specific. On AMDGPU, the convergence control operand bundle at a non-intrinsic call is translated to an explicit argument to the SI_CALL_ISEL instruction. Post-selection adjustment converts this explicit argument to an implicit argument on the SI_CALL instruction.
2024-02-21Revert "Implement convergence control in MIR using SelectionDAG (#71785)"Sameer Sahasrabuddhe1-10/+0
This reverts commit 79889734b940356ab3381423c93ae06f22e772c9. Encountered multiple buildbot failures.
2024-02-21Implement convergence control in MIR using SelectionDAG (#71785)Sameer Sahasrabuddhe1-0/+10
LLVM function calls carry convergence control tokens as operand bundles, where the tokens themselves are produced by convergence control intrinsics. This patch implements convergence control tokens in MIR as follows: 1. Introduce target-independent ISD opcodes and MIR opcodes for convergence control intrinsics. 2. Model token values as untyped virtual registers in MIR. The change also introduces an additional ISD opcode CONVERGENCECTRL_GLUE and a corresponding machine opcode with the same spelling. This glues the convergence control token to SDNodes that represent calls to intrinsics. The glued token is later translated to an implicit argument in the MIR. The lowering of calls to user-defined functions is target-specific. On AMDGPU, the convergence control operand bundle at a non-intrinsic call is translated to an explicit argument to the SI_CALL_ISEL instruction. Post-selection adjustment converts this explicit argument to an implicit argument on the SI_CALL instruction.
2024-02-13[WebAssembly] Demote PHIs in catchswitch BB only (#81570)Heejin Ahn1-1/+2
`DemoteCatchSwitchPHIOnly` option in `WinEHPrepare` pass was added in https://github.com/llvm/llvm-project/commit/99d60e0dabcf20f4db683da83cde905b7a1373de, because Wasm EH uses `WinEHPrepare`, but it doesn't need to demote all PHIs. PHIs in `catchswitch` BBs have to be removed (= demoted) because `catchswitch`s are removed in ISel and `catchswitch` BBs are removed as well, so they can't have other instructions. But because Wasm EH doesn't use funclets, so PHIs in `catchpad` or `cleanuppad` BBs don't need to be demoted. That was the reason `DemoteCatchSwitchPHIOnly` option was added, in order not to demote more instructions unnecessarily. The problem is it should have been set to `true` for Wasm EH. (Its default value is `false` for WinEH) And I mistakenly set it to `false` and wasn't aware about this for more than 5 years. This was not the end of the world; it just means we've been demoting more instructions than we should, possibly huting code size. In practice I think it would've had hardly any effect in real performance given that the occurrence of PHIs in `catchpad` or `cleanuppad` BBs are not very frequent and many people run other optimizers like Binaryen anyway.
2024-02-06[SelectionDAG] Use getRegisterType instead of getTypeToTransformTo in ↵Craig Topper1-1/+1
ComputePHILiveOutRegInfo. (#80773) Since we used getNumRegisters right before this, I think this is the correct interface we should be using here. I'm experimenting with making i32 legal on RISC-V 64, but using i64 for the register type between basic blocks. This was one of the first issues I found trying to do that.
2023-12-24[CodeGen] Use range-based for loops (NFC)Kazu Hirata1-2/+1
2023-12-12[DebugInfo][RemoveDIs] Handle dbg.declares in SelectionDAGISel (#73496)Orlando Cazalet-Hyams1-0/+1
This is a boring mechanical update to support DPValues that look like dbg.declares in SelectionDAG. The tests will become "live" once #74090 lands (see for more info).
2023-12-05[SDAG] Count call argument attributes to reduce unnecessary extension (#73501)ZengZhijin1-2/+9
Count how often the value is with signext/zeroext calls when determining the preferred extension type.
2023-05-19[1/11][IR] Permit load/store/alloca for struct of the same scalable vector typeeopXD1-3/+4
This patch-set aims to simplify the existing RVV segment load/store intrinsics to use a type that represents a tuple of vectors instead. To achieve this, first we need to relax the current limitation for an aggregate type to be a target of load/store/alloca when the aggregate type contains homogeneous scalable vector types. Then to adjust the prolog of an LLVM function during lowering to clang. Finally we re-define the RVV segment load/store intrinsics to use the tuple types. The pull request under the RVV intrinsic specification is riscv-non-isa/rvv-intrinsic-doc#198 --- This is the 1st patch of the patch-set. This patch is originated from D98169. This patch allows aggregate type (StructType) that contains homogeneous scalable vector types to be a target of load/store/alloca. The RFC of this patch was posted in LLVM Discourse. https://discourse.llvm.org/t/rfc-ir-permit-load-store-alloca-for-struct-of-the-same-scalable-vector-type/69527 The main changes in this patch are: Extend `StructLayout::StructSize` from `uint64_t` to `TypeSize` to accommodate an expression of scalable size. Allow `StructType:isSized` to also return true for homogeneous scalable vector types. Let `Type::isScalableTy` return true when `Type` is `StructType` and contains scalable vectors Extra description is added in the LLVM Language Reference Manual on the relaxation of this patch. Authored-by: Hsiangkai Wang <kai.wang@sifive.com> Co-Authored-by: eop Chen <eop.chen@sifive.com> Reviewed By: craig.topper, nikic Differential Revision: https://reviews.llvm.org/D146872
2023-05-16[KnownBits] Define and use intersectWith and unionWithJay Foad1-1/+1
Define intersectWith and unionWith as two complementary ways of combining KnownBits. The names are chosen for consistency with ConstantRange. Deprecate commonBits as a synonym for intersectWith. Differential Revision: https://reviews.llvm.org/D150443
2023-05-03[SelectionDAG][NFCI] Use common logic for identifying MMI varsFelipe de Azevedo Piovezan1-0/+1
After function argument lowering, but prior to instruction selection, dbg declares pointing to function arguments are lowered using special logic. Later, during instruction selection (both "fast" and regular ISel), this logic is "repeated" in order to identify which intrinsics have already been lowered. This is bad for two reasons: 1. The logic is not _really_ repeated, the code is different, which could lead to duplicate lowering of the intrinsic. 2. Even if the logic were repeated properly, this is still code duplication. This patch addresses these issues by storing all preprocessed dbg.declare intrinsics in a set inside FuncInfo; the set is queried upon instruction selection. Differential Revision: https://reviews.llvm.org/D149682
2023-04-17[nfc][llvm] Replace pointer cast functions in PointerUnion by llvm casting ↵Shraiysh Vaishay1-8/+8
functions. This patch replaces the uses of PointerUnion.is function by llvm::isa, PointerUnion.get function by llvm::cast, and PointerUnion.dyn_cast by llvm::dyn_cast_if_present. This is according to the FIXME in the definition of the class PointerUnion. This patch does not remove them as they are being used in other subprojects. Reviewed By: mehdi_amini Differential Revision: https://reviews.llvm.org/D148449
2023-03-14Reland: [DAG/AMDGPU] Use UniformityAnalysis in DAGISelpvanhout1-4/+4
Switch DAGISel over to UniformityAnalysis, which was one of the last remaining users of the DivergenceAnalysis. No explosions seen during internal testing so this looks like a smooth transition. Reviewed By: sameerds Differential Revision: https://reviews.llvm.org/D145918
2023-03-14Revert "[DAG/AMDGPU] Use UniformityAnalysis in DAGISel"pvanhout1-4/+4
This reverts commit 0022b5803fd4f5a4e9fcf233267c0ffa1b88f763.
2023-03-14[DAG/AMDGPU] Use UniformityAnalysis in DAGISelpvanhout1-4/+4
Switch DAGISel over to UniformityAnalysis, which was one of the last remaining users of the DivergenceAnalysis. No explosions seen during internal testing so this looks like a smooth transition. Reviewed By: sameerds Differential Revision: https://reviews.llvm.org/D145918
2023-02-09[SelectionDAG] Do not second-guess alignment for allocaAndrew Savonichev1-14/+1
Alignment of an alloca in IR can be lower than the preferred alignment on purpose, but this override essentially treats the preferred alignment as the minimum alignment. The patch changes this behavior to always use the specified alignment. If alignment is not set explicitly in LLVM IR, it is set to DL.getPrefTypeAlign(Ty) in computeAllocaDefaultAlign. Tests are changed as well: explicit alignment is increased to match the preferred alignment if it changes output, or omitted when it is hard to determine the right value (e.g. for pointers, some structs, or weird types). Differential Revision: https://reviews.llvm.org/D135462
2023-01-13[CodeGen] Remove uses of Register::isPhysicalRegister/isVirtualRegister. NFCCraig Topper1-2/+2
Use isPhysical/isVirtual methods. Reviewed By: foad Differential Revision: https://reviews.llvm.org/D141715
2023-01-11[NFC] Use TypeSize::getKnownMinValue() instead of TypeSize::getKnownMinSize()Guillaume Chatelet1-1/+1
This change is one of a series to implement the discussion from https://reviews.llvm.org/D141134.
2022-12-15Revert "[SelectionDAG] Do not second-guess alignment for alloca"Ron Lieberman1-1/+14
Breaks amdgpu buildbot https://lab.llvm.org/buildbot/#/builders/193 23491 This reverts commit ffedf47d8b793e07317f82f9c2a5f5425ebb71ad.
2022-12-15[SelectionDAG] Do not second-guess alignment for allocaAndrew Savonichev1-14/+1
Alignment of an alloca in IR can be lower than the preferred alignment on purpose, but this override essentially treats the preferred alignment as the minimum alignment. The patch changes this behavior to always use the specified alignment. If alignment is not set explicitly in LLVM IR, it is set to DL.getPrefTypeAlign(Ty) in computeAllocaDefaultAlign. Tests are changed as well: explicit alignment is increased to match the preferred alignment if it changes output, or omitted when it is hard to determine the right value (e.g. for pointers, some structs, or weird types). Differential Revision: https://reviews.llvm.org/D135462
2022-11-02WebAssembly: Move exception handling code togetherMatt Arsenault1-7/+3
2022-11-02FunctionLoweringInfo: Use TLI member instead of finding itMatt Arsenault1-4/+1
2022-10-25[SelectionDAG] Add missing semicolon after return.Craig Topper1-1/+1
I'm unsure what the code does without the semicolon. On the surface it seems like the assert below it would be considered part of the if and thus the assert would only execute if DestReg is 0. But 0 isn't considered a virtual register so the assert should fail. Found by PVS Studio. Reported https://pvs-studio.com/en/blog/posts/cpp/1003/ (N7)
2022-08-16Untangle the mess which is MachineBasicBlock::hasAddressTaken().Eli Friedman1-1/+1
There are two different senses in which a block can be "address-taken". There can be a BlockAddress involved, which means we need to map the IR-level value to some specific block of machine code. Or there can be constructs inside a function which involve using the address of a basic block to implement certain kinds of control flow. Mixing these together causes a problem: if target-specific passes are marking random blocks "address-taken", if we have a BlockAddress, we can't actually tell which MachineBasicBlock corresponds to the BlockAddress. So split this into two separate bits: one for BlockAddress, and one for the machine-specific bits. Discovered while trying to sort out related stuff on D102817. Differential Revision: https://reviews.llvm.org/D124697
2022-05-19[APInt] Remove all uses of zextOrSelf, sextOrSelf and truncOrSelfJay Foad1-4/+4
Most clients only used these methods because they wanted to be able to extend or truncate to the same bit width (which is a no-op). Now that the standard zext, sext and trunc allow this, there is no reason to use the OrSelf versions. The OrSelf versions additionally have the strange behaviour of allowing extending to a *smaller* width, or truncating to a *larger* width, which are also treated as no-ops. A small amount of client code relied on this (ConstantRange::castOp and MicrosoftCXXNameMangler::mangleNumber) and needed rewriting. Differential Revision: https://reviews.llvm.org/D125557
2022-04-11[RISCV][SelectionDAG] Add a hook to sign extend i32 ConstantInt operands of ↵Craig Topper1-2/+10
phis on RV64. Materializing constants on RISCV is simpler if the constant is sign extended from i32. By default i32 constant operands of phis are zero extended. This patch adds a hook to allow RISCV to override this for i32. We have an existing isSExtCheaperThanZExt, but it operates on EVT which we don't have at these places in the code. Reviewed By: efriedma Differential Revision: https://reviews.llvm.org/D122951
2022-03-23[SelectionDAG] Don't create entries in ValueMap in ComputePHILiveOutRegInfoCraig Topper1-2/+7
Instead of using operator[], use DenseMap::find to prevent default constructing an entry if it isn't already in the map. Also simplify a condition to check for 0 instead of a virtual register. I'm pretty sure we can only get 0 or a virtual register out of the value map.
2022-03-22Revert "[SelectionDAG] Don't create entries in ValueMap in ↵Craig Topper1-7/+2
ComputePHILiveOutRegInfo" This reverts commit 1a9b55b63a6e18a4692eeb795697cb61ca1b002f. Causing build bot failures
2022-03-22[SelectionDAG] Don't create entries in ValueMap in ComputePHILiveOutRegInfoCraig Topper1-2/+7
Instead of using operator[], use DenseMap::find to prevent default constructing an entry if it isn't already in the map.
2022-03-21[SelectionDAG] Make getPreferredExtendForValue take a Instruction * instead ↵Craig Topper1-2/+2
of Value *. This is only called for instructions and the caller is already holding an Instruction *. This makes the code more explicit and makes it obvious the code doesn't make decisions about constants.
2022-03-18[SelectionDAG] Use APInt::zextOrSelf instead of zextOrTrunc in ↵Craig Topper1-2/+2
ComputePHILiveOutRegInfo The width never decreases here.
2022-03-12Cleanup includes: DebugInfo & CodeGenserge-sans-paille1-3/+0
Discourse thread: https://discourse.llvm.org/t/include-what-you-use-include-cleanup Differential Revision: https://reviews.llvm.org/D121332
2021-08-19Revert "[SelectionDAGBuilder] Compute and cache PreferredExtendType on demand."Craig Topper1-0/+25
This reverts commit add08c874147638e52d89eb07e40797dbc98d73b. There was a compile time jump on tramp3d-v4 on https://llvm-compile-time-tracker.com/ Want to see if it goes away with this reverted.
2021-08-19[SelectionDAGBuilder] Compute and cache PreferredExtendType on demand.Craig Topper1-25/+0
Previously we pre-calculated this and cached it for every instruction in the function. Most of the calculated results will never be used. So instead calculate it only on the first use, and then cache it. The cache was originally added to fix a compile time issue which caused r216066 to be reverted. This change exposed that we weren't pre-computing the Value for Arguments. I've explicitly disabled that for now as it seemed to regress some tests on AArch64 which has sext built into its compare instructions. Spotted while investigating how to improve heuristics to work better with RISCV preferring sign extend for unsigned compares for i32 on RV64. Reviewed By: RKSimon Differential Revision: https://reviews.llvm.org/D107976