aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Target/ARM/ARMFrameLowering.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-09-12CodeGen: Remove MachineFunction argument from getRegClass (#158188)Matt Arsenault1-1/+1
This is a low level utility to parse the MCInstrInfo and should not depend on the state of the function.
2025-07-15Remove Native Client support (#133661)Brad Smith1-3/+1
Remove the Native Client support now that it has finally reached end of life.
2025-06-28[Target] Prevent copying in loop variables (NFC)Jie Fu1-1/+1
/llvm-project/llvm/lib/Target/ARM/ARMISelLowering.cpp:2769:19: error: loop variable '[Reg, N]' creates a copy from type 'std::pair<unsigned int, llvm::SDValue> const' [-Werror,-Wrange-loop-construct] for (const auto [Reg, N] : RegsToPass) { ^ /llvm-project/llvm/lib/Target/ARM/ARMISelLowering.cpp:2769:8: note: use reference type 'std::pair<unsigned int, llvm::SDValue> const &' to prevent copying for (const auto [Reg, N] : RegsToPass) { ^~~~~~~~~~~~~~~~~~~~~ & /llvm-project/llvm/lib/Target/ARM/ARMISelLowering.cpp:2954:19: error: loop variable '[Reg, N]' creates a copy from type 'std::pair<unsigned int, llvm::SDValue> const' [-Werror,-Wrange-loop-construct] for (const auto [Reg, N] : RegsToPass) ^ /llvm-project/llvm/lib/Target/ARM/ARMISelLowering.cpp:2954:8: note: use reference type 'std::pair<unsigned int, llvm::SDValue> const &' to prevent copying for (const auto [Reg, N] : RegsToPass) ^~~~~~~~~~~~~~~~~~~~~ & 2 errors generated.
2025-06-27[Target] Use range-based for loops (NFC) (#146198)Kazu Hirata1-2/+2
2025-05-24[ARM] Remove unused includes (NFC) (#141377)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-04[Target] Remove unused local variables (NFC) (#138443)Kazu Hirata1-1/+0
2025-04-22[ARM][Thumb] Save FPSCR + FPEXC for save-vfp attributeBenson Chu1-10/+154
FPSCR and FPEXC will be stored in FPStatusRegs, after GPRCS2 has been saved. - GPRCS1 - GPRCS2 - FPStatusRegs (new) - DPRCS - GPRCS3 - DPRCS2 FPSCR is present on all targets with a VFP, but the FPEXC register is not present on Cortex-M devices, so different amounts of bytes are being pushed onto the stack depending on our target, which would affect alignment for subsequent saves. DPRCS1 will sum up all previous bytes that were saved, and will emit extra instructions to ensure that its alignment is correct. My assumption is that if DPRCS1 is able to correct its alignment to be correct, then all subsequent saves will also have correct alignment. Avoid annotating the saving of FPSCR and FPEXC for functions marked with the interrupt_save_fp attribute, even though this is done as part of frame setup. Since these are status registers, there really is no viable way of annotating this. Since these aren't GPRs or DPRs, they can't be used with .save or .vsave directives. Instead, just record that the intermediate registers r4 and r5 are saved to the stack again. Co-authored-by: Jake Vossen <jake@vossen.dev> Co-authored-by: Alan Phipps <a-phipps@ti.com>
2025-04-17[ARM] Use helper class for emitting CFI instructions into MIR (#135994)Sergei Barannikov1-76/+28
Similar to #135845. PR: https://github.com/llvm/llvm-project/pull/135994
2025-03-24[Target] Use *Set::insert_range (NFC) (#132879)Kazu Hirata1-2/+1
We can use *Set::insert_range to collapse: for (auto Elem : Range) Set.insert(E); down to: Set.insert_range(Range); In some cases, we can further fold that into the set declaration.
2025-03-10Revert "[ARM][Thumb] Save FPSCR + FPEXC for save-vfp attribute"Benson Chu1-147/+9
This reverts commit 1f05703176d43a339b41a474f51c0e8b1a83c9bb.
2025-03-10[ARM][Thumb] Save FPSCR + FPEXC for save-vfp attributeBenson Chu1-9/+147
FPSCR and FPEXC will be stored in FPStatusRegs, after GPRCS2 has been saved. - GPRCS1 - GPRCS2 - FPStatusRegs (new) - DPRCS - GPRCS3 - DPRCS2 FPSCR is present on all targets with a VFP, but the FPEXC register is not present on Cortex-M devices, so different amounts of bytes are being pushed onto the stack depending on our target, which would affect alignment for subsequent saves. DPRCS1 will sum up all previous bytes that were saved, and will emit extra instructions to ensure that its alignment is correct. My assumption is that if DPRCS1 is able to correct its alignment to be correct, then all subsequent saves will also have correct alignment. Avoid annotating the saving of FPSCR and FPEXC for functions marked with the interrupt_save_fp attribute, even though this is done as part of frame setup. Since these are status registers, there really is no viable way of annotating this. Since these aren't GPRs or DPRs, they can't be used with .save or .vsave directives. Instead, just record that the intermediate registers r4 and r5 are saved to the stack again. Co-authored-by: Jake Vossen <jake@vossen.dev> Co-authored-by: Alan Phipps <a-phipps@ti.com>
2025-02-20[FrameLowering] Use MCRegister instead of Register in CalleeSavedInfo. NFC ↵Craig Topper1-7/+7
(#128095) Callee saved registers should always be phyiscal registers. They are often passed directly to other functions that take MCRegister like getMinimalPhysRegClass or TargetRegisterClass::contains. Unfortunately, sometimes the MCRegister is compared to a Register which gave an ambiguous comparison error when the MCRegister is on the LHS. Adding a MCRegister==Register comparison operator created more ambiguous comparison errors elsewhere. These cases were usually comparing against a base or frame pointer register that is a physical register in a Register. For those I added an explicit conversion of Register to MCRegister to fix the error.
2025-01-20[ARM] Use MCRegister instead of unsigned. NFCCraig Topper1-12/+12
Primarily around uses of getSubReg/getSuperReg.
2025-01-14[llvm] Mark scavenging spill-slots as *spilled* stack objects. (#122673)Guy David1-1/+1
This seems like an oversight when copying code from other backends.
2024-11-19[ARM] Fix a warningKazu Hirata1-0/+2
This patch fixes: llvm/lib/Target/ARM/ARMFrameLowering.cpp:1404:39: error: unused variable 'PushPopSplit' [-Werror,-Wunused-variable]
2024-11-19[ARM] Specifically delineate between different GPRCS2 positionsBenson Chu1-75/+86
Currently, the relative position of GPRCS2 (with respect to other instructions in the prologue of a function) can be different depending on the type of ARMSubtarget::PushPopSplitVariant. When the PushPopSpiltVariant is SplitR11WindowsSEH, GPRCS2 comes after both GPRCS1 and DPRCS2: GPRCS1 DPRCS1 GPRCS2 However, in all other cases, GPRCS2 comes before DPRCS1, like so: GPRCS1 GPRCS2 DPRCS1 This makes the MI walking code in ARMFrameLowering::emitPrologue a bit confusing. If GPRCS2Size is non-zero, we also have to check the PushPopSplitVariant to know if we will encounter the DPRCS1 push instruction first or the GPRCS2 push instruction first. This commit changes to SplitR11WindowsSEH such that the spill area is as follows: GPRCS1 DPRCS1 GPRCS3 This disambiguates a lot of the ARMFrameLowering.cpp MI traversal code.
2024-11-12[ARM] Remove unused includes (NFC) (#115995)Kazu Hirata1-1/+0
Identified with misc-include-cleaner.
2024-10-28[ARM] Optimise non-ABI frame pointers (#110286)Oliver Stannard1-0/+11
With -fomit-frame-pointer, even if we set up a frame pointer for other reasons (e.g. variable-sized or over-aligned stack allocations), we don't need to create an ABI-compliant frame record. This means that we can save all of the general-purpose registers in one push, instead of splitting it to ensure that the frame pointer and link register are adjacent on the stack, saving two instructions per function.
2024-10-24Re-land: [ARM] Fix frame chains with M-profile PACBTI (#110285)Oliver Stannard1-48/+97
When using AAPCS-compliant frame chains with PACBTI return address signing, there ware a number of bugs in the generation of the frame pointer and function prologues. The most obvious was that we sometimes would modify r11 before pushing it to the stack, so it wasn't preserved as required by the PCS. We also sometimes did not push R11 and LR adjacent to one another on the stack, or used R11 as a frame pointer without pointing it at the saved value of R11, both of which are required to have an AAPCS compliant frame chain. The original work of this patch was done by James Westwood, reviewed as #82801 and #81249, with some tidy-ups done by Mark Murray and myself.
2024-10-18Revert "[ARM] Fix frame chains with M-profile PACBTI (#110285)"Oliver Stannard1-97/+48
Reverting because this is causing failures with MSan: https://lab.llvm.org/buildbot/#/builders/169/builds/4378 This reverts commit e1f8f84acec05997893c305c78fbf7feecf44dd7.
2024-10-18[llvm] Consistently respect `naked` fn attribute in ↵Alex Rønne Petersen1-4/+4
`TargetFrameLowering::hasFP()` (#106014) Some targets (e.g. PPC and Hexagon) already did this. I think it's best to do this consistently so that frontend authors don't run into inconsistent results when they emit `naked` functions. For example, in Zig, we had to change our emit code to also set `frame-pointer=none` to get reliable results across targets. Note: I don't have commit access.
2024-10-17[ARM] Fix -mno-omit-leaf-frame-pointer flag doesn't works on 32-bit ARM ↵gxlayer1-1/+6
(#109628) The -mno-omit-leaf-frame-pointer flag works on 32-bit ARM architectures and addresses the bug reported in #108019
2024-10-17[ARM] Fix -Wunused-variable in ARMFrameLowering.cpp (NFC)Jie Fu1-1/+1
/llvm-project/llvm/lib/Target/ARM/ARMFrameLowering.cpp:1028:9: error: unused variable 'FPOffset' [-Werror,-Wunused-variable] int FPOffset = MFI.getObjectOffset(FramePtrSpillFI); ^ 1 error generated.
2024-10-17[ARM] Fix frame chains with M-profile PACBTI (#110285)Oliver Stannard1-48/+97
When using AAPCS-compliant frame chains with PACBTI return address signing, there ware a number of bugs in the generation of the frame pointer and function prologues. The most obvious was that we sometimes would modify r11 before pushing it to the stack, so it wasn't preserved as required by the PCS. We also sometimes did not push R11 and LR adjacent to one another on the stack, or used R11 as a frame pointer without pointing it at the saved value of R11, both of which are required to have an AAPCS compliant frame chain. The original work of this patch was done by James Westwood, reviewed as #82801 and #81249, with some tidy-ups done by Mark Murray and myself.
2024-10-09[ARM] Add debug dump for StackAdjustingInsts (NFC) (#110283)Oliver Stannard1-1/+23
2024-10-09[ARM] Refactor generation of push/pop instructions (NFC) (#110283)Oliver Stannard1-42/+57
These used a set of callback functions to check which callee-save area a register is in, refactor them to use the same data as other parts of ARMFrameLowering. This will make it easier to add a new variant to the register splitting.
2024-10-09[ARM] Factor out code to determine spill areas (NFC) (#110283)Oliver Stannard1-144/+183
There were multiple loops in ARMFrameLowering which sort the callee saved registers into spill areas, which were hard to understand and modify. This splits the information about which register is in which save area into a separate function.
2024-10-09[ARM] Tidy up stack frame strategy code (NFC) (#110283)Oliver Stannard1-25/+46
We have two different ways of splitting the pushes of callee-saved registers onto the stack, controlled by the confusingly similar names STI.splitFramePushPop() and STI.splitFramePointerPush(). This removes those functions and replaces them with a single function which returns an enum. This is in preparation for adding another value to that enum. The original work of this patch was done by James Westwood, reviewed as #82801 and #81249, with some tidy-ups done by Mark Murray and myself.
2024-07-23[LLVM] [MC] Update frame layout & CFI generation to handle frames larger ↵Wesley Wiser1-2/+2
than 2gb (#99263) Rebase of #84114. I've only included the core changes to frame layout calculation & CFI generation which sidesteps the regressions found after merging #84114. Since these changes are a necessary precursor to the overall fix and are themselves slightly beneficial as CFI is now generated correctly, I think it is reasonable to merge this first step. --- For very large stack frames, the offset from the stack pointer to a local can be more than 2^31 which overflows various `int` offsets in the frame lowering code. This patch updates the frame lowering code to calculate the offsets as 64-bit values and fixes CFI to use the corrected sizes. After this patch, additional work is needed to fix offset truncations in each target's codegen.
2024-07-19CodeGen: Avoid some references to MachineFunction's getMMI (#99652)Matt Arsenault1-4/+2
MachineFunction's probably should not include a backreference to the owning MachineModuleInfo. Most of these references were used just to query the MCContext, which MachineFunction already directly stores. Other contexts are using it to query the LLVMContext, which can already be accessed through the IR function reference.
2024-07-17Rapply "[Target] Use range-based for loops (NFC) (#98844)"Kazu Hirata1-2/+2
This iteration drops hunks where the loop body adds more elements.
2024-07-15Revert "[Target] Use range-based for loops (NFC) (#98844)"Kazu Hirata1-2/+2
This reverts commit 3614f65a7ba9d925010e3316a1d93bcebc632178. fixupImmediateBr seems to resize ImmBranches.
2024-07-15[Target] Use range-based for loops (NFC) (#98844)Kazu Hirata1-2/+2
2024-06-07[ARM] r11 is reserved when using -mframe-chain=aapcs (#86951)Oliver Stannard1-4/+4
When using the -mframe-chain=aapcs or -mframe-chain=aapcs-leaf options, we cannot use r11 as an allocatable register, even if -fomit-frame-pointer is also used. This is so that r11 will always point to a valid frame record, even if we don't create one in every function.
2024-04-30Do not use R12 for indirect tail calls with PACBTI (#82661)Eleanor Bonnici1-2/+6
When compiling for thumbv8.1m with +pacbti and making an indirect tail call, the compiler was free to put the function pointer into R12. This is incorrect because R12 is restored to contain authentication code for the caller's return address. This patch excludes R12 from the set of registers the compiler can put the function pointer in. Fixes https://github.com/llvm/llvm-project/issues/75998
2024-04-24[CodeGen] Make the parameter TRI required in some functions. (#85968)Xu Zhang1-1/+1
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`.
2024-03-27Revert rG58de1e2c5eee548a9b365e3b1554d87317072ad9 "Fix stack layout for ↵Simon Pilgrim1-2/+2
frames larger than 2gb (#84114)" This is failing on some EXPENSIVE_CHECKS buildbots
2024-03-27Fix stack layout for frames larger than 2gb (#84114)Wesley Wiser1-2/+2
For very large stack frames, the offset from the stack pointer to a local can be more than 2^31 which overflows various `int` offsets in the frame lowering code. This patch updates the frame lowering code to calculate the offsets as 64-bit values and resolves the overflows, resulting in the correct codegen for very large frames. Fixes #48911
2024-03-05Revert "[ARM] R11 not pushed adjacent to link register with PAC-M and… ↵James Westwood1-155/+60
(#84019) … AAPCS frame chain fix (#82801)" This reverts commit 00e4a4197137410129d4725ffb82bae9ce44bdde. This patch was found to cause miscompilations and compilation failures.
2024-03-04[ARM] R11 not pushed adjacent to link register with PAC-M and AAPCS frame ↵James Westwood1-60/+155
chain fix (#82801) When code for M class architecture was compiled with AAPCS and PAC enabled, the frame pointer, r11, was not pushed to the stack adjacent to the link register. Due to PAC being enabled, r12 was placed between r11 and lr. This patch fixes this by adding an extra case to the already existing code that splits the GPR push in two when R11 is the frame pointer and certain paremeters are met. The differential revision for this previous change can be found here: https://reviews.llvm.org/D125649. This now ensures that r11 and lr are pushed in a separate push instruction to the other GPRs when PAC and AAPCS are enabled, meaning the frame pointer and link register are now pushed onto the stack adjacent to each other.
2024-02-26[ARM] Update IsRestored for LR based on all returns (#82745)ostannard1-4/+7
PR #75527 fixed ARMFrameLowering to set the IsRestored flag for LR based on all of the return instructions in the function, not just one. However, there is also code in ARMLoadStoreOptimizer which changes return instructions, but it set IsRestored based on the one instruction it changed, not the whole function. The fix is to factor out the code added in #75527, and also call it from ARMLoadStoreOptimizer if it made a change to return instructions. Fixes #80287.
2023-12-24[Target] Use range-based for loops (NFC)Kazu Hirata1-2/+1
2023-12-20[ARM] Check all terms in emitPopInst when clearing Restored for LR. (#75527)Florian Hahn1-3/+27
emitPopInst checks a single function exit MBB. If other paths also exit the function and any of there terminators uses LR implicitly, it is not save to clear the Restored bit. Check all terminators for the function before clearing Restored. This fixes a mis-compile in outlined-fn-may-clobber-lr-in-caller.ll where the machine-outliner previously introduced BLs that clobbered LR which in turn is used by the tail call return. Alternative to #73553
2023-09-04[ARM] Fix prologue/epilogue for pacbti-m leaf functionsJohn Brawn1-0/+4
R12 is callee-saved in functions with pacbti-m enabled, but this is done in assignCalleeSavedSpillSlots, meaning that in determineCalleeSaves we have to manually set CanEliminateFrame. This fixes a bug where in leaf functions with no other callee-saved registers the aut instruction wouldn't be emitted and stack offsets of arguments passed on the stack would be incorrect. Differential Revision: https://reviews.llvm.org/D157865
2023-08-24[ARM] Save and restore CPSR around tMOVimm32Oliver Stannard1-19/+31
When resolving a frame index with a large offset for v6M execute-only, we emit a tMOVimm32 pseudo-instruction, which later gets lowered to a sequence of instructions, all of which are flag-setting. However, a frame index may be generated for a register spill or reload instruction, which can be inserted at a point where CPSR is live. This patch inserts MRS and MSR instructions around the tMOVimm32 to save and restore the value of CPSR, if CPSR is live at that point. This may need up to two virtual registers (one to build the immediate value, one to save CPSR) during frame index lowering, which happens after register allocation, so we need to ensure two spill slots are avilable to the register scavenger to ensure it can free up enough registers for this. There is no test for the emission (or not) of the MRS/MSR pair, because it requires a spill or reload to be inserted at a point where CPSR is live, which requires a large, complex function and is fragile enough that any optimisation changes will break the test. This bug was easily found by csmith with -verify-machineinstrs, which I now run regularly on v6M execute-only (and many other combinations). Patch by John Brawn and myself. Reviewed By: stuij Differential Revision: https://reviews.llvm.org/D158404
2023-07-28[ARM] Correctly handle combining segmented stacks with execute-onlyJohn Brawn1-16/+22
Using segmented stacks with execute-only mostly works, but we need to use the correct movi32 opcode in 6-M, and there's one place where for thumb1 (i.e. 6-M and 8-M.base) a constant pool was unconditionally used which needed to be fixed. Differential Revision: https://reviews.llvm.org/D156339
2023-05-02[ARM] Don't allocate memory if free space in segmented stack is just enoughZhiyao Ma1-5/+5
Assuming that the stack grows downwards, it is fine if the stack pointer is exactly at the stacklet boundary. We should use less-or-equal condition when deciding whether to skip new memory allocation. Differential Revision: https://reviews.llvm.org/D149315
2023-04-15[Target] Use range-based for loops (NFC)Kazu Hirata1-4/+3
2023-03-31ARMFrameLowering.cpp - fix MSVC "result of 32-bit shift implicitly converted ↵Simon Pilgrim1-2/+2
to 64 bits" warning. NFC.
2023-03-31[ARM] Handle generating SEH unwind info for t2STR_PRE/t2LDR_POSTMartin Storsjö1-0/+28
This fixes compiling some uncommon cases. Differential Revision: https://reviews.llvm.org/D147212