aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/PrologEpilogInserter.cpp
AgeCommit message (Collapse)AuthorFilesLines
2024-05-15Fix typo "indicies" (#92232)Jay Foad1-1/+1
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-20Revert "Move assertion for AdjustsStack from PEI to MachineVerifier. (#85698)"Jonas Paulsson1-0/+2
This reverts commit 05bde30585710a51592eee0a6cf6df8184d09c92. Reverting due to verifier complaints with expensive checks on build-bot.
2024-03-20Move assertion for AdjustsStack from PEI to MachineVerifier. (#85698)Jonas Paulsson1-2/+0
Have the verifier report a missing AdjustsStack flag rather than waiting until PEI asserts.
2024-03-18[CodeGen] Fix -Wunused-variable in PrologEpilogInserter.cpp (NFC)Jie Fu1-1/+1
llvm-project/llvm/lib/CodeGen/PrologEpilogInserter.cpp:369:12: error: unused variable 'MaxCFSIn' [-Werror,-Wunused-variable] uint32_t MaxCFSIn = ^ 1 error generated.
2024-03-18[MachineFrameInfo] Refactoring around computeMaxcallFrameSize() (NFC) (#78001)Jonas Paulsson1-28/+12
- Use computeMaxCallFrameSize() in PEI::calculateCallFrameInfo() instead of duplicating the code. - Set AdjustsStack in FinalizeISel instead of in computeMaxCallFrameSize().
2023-11-08[RegScavenger] Simplify state tracking for backwards scavenging (#71202)Jay Foad1-6/+1
Track the live register state immediately before, instead of after, MBBI. This makes it simple to track the state at the start or end of a basic block without a separate (and poorly named) Tracking flag. This changes the API of the backward(MachineBasicBlock::iterator I) method, which now recedes to the state just before, instead of just after, *I. Some clients are simplified by this change. There is one small functional change shown in the lit tests where multiple spilled registers all need to be reloaded before the same instruction. The reloads will now be inserted in the opposite order. This should not affect correctness.
2023-10-22[CodeGen][Remarks] Add the function name to the stack size remark (#69346)Jon Roelofs1-1/+3
It is already present in the yaml, but missing from the printed diagnostics.
2023-09-14[NFC][CodeGen] Change CodeGenOpt::Level/CodeGenFileType into enum classes ↵Arthur Eubanks1-2/+2
(#66295) This will make it easy for callers to see issues with and fix up calls to createTargetMachine after a future change to the params of TargetMachine. This matches other nearby enums. For downstream users, this should be a fairly straightforward replacement, e.g. s/CodeGenOpt::Aggressive/CodeGenOptLevel::Aggressive or s/CGFT_/CodeGenFileType::
2023-09-08[PEI][PowerPC] Fix false alarm of stack size limit (#65559)bzEq1-1/+1
PPC64 allows stack size up to ((2^63)-1) bytes. Currently llc reports ``` warning: stack frame size (4294967568) exceeds limit (4294967295) in function 'main' ``` if the stack allocated is larger than 4G.
2023-08-04[PEI] Remove support for register scavenging during forwards frame index ↵Jay Foad1-10/+3
elimination All targets that require register scavenging now use backwards frame index elimination. Differential Revision: https://reviews.llvm.org/D156986
2023-08-03[PEI] Switch to backwards frame index elimination by defaultJay Foad1-1/+1
Also rename the flag from supportsBackwardScavenger to eliminateFrameIndicesBackwards to reflect what it actually does. X86 is the only target still using forwards frame index elimination. This will not block removing support for forwards register scavenging, because X86 does not use the register scavenger. Differential Revision: https://reviews.llvm.org/D156983
2023-08-01[PEI][PowerPC] Switch to backwards frame index eliminationJay Foad1-15/+17
This adds support for reprocessing new instructions that were generated by the target's eliminateFrameIndex. Backwards frame index elimination uses backwards register scavenging, which is preferred because it does not rely on accurate kill flags. Differential Revision: https://reviews.llvm.org/D156690
2023-07-28[PEI] Don't zero out noreg operandsArthur Eubanks1-2/+7
A tail call may have $noreg operands. Fixes a crash. Reviewed By: xgupta Differential Revision: https://reviews.llvm.org/D156485
2023-07-28[PEI][ARM] Switch to backwards frame index eliminationJay Foad1-18/+44
This adds better support for call frame pseudos that adjust SP in PEI::replaceFrameIndicesBackward. Running frame index elimination backwards is preferred because it can do backwards register scavenging (on targets that require scavenging) which does not rely on accurate kill flags. Differential Revision: https://reviews.llvm.org/D156434
2023-07-27[CodeGen] Store call frame size in MachineBasicBlockJay Foad1-30/+16
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-10/+28
This reverts commit 58d1eaa3b6ce4f7285c51f83faff7a3ac374c746.
2023-07-12[CodeGen] Fix -Wunused-variable in -DLLVM_ENABLE_ASSERTIONS=off builds after ↵Fangrui Song1-1/+1
D154281
2023-07-12[CodeGen] Store SP adjustment in MachineBasicBlock. NFCI.Jay Foad1-28/+10
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-07-07[PEI][Mips] Switch to backwards frame index eliminationJay Foad1-5/+18
This adds support for running PEI::replaceFrameIndicesBackward with no RegisterScavenger, and basic support for eliminating call frame pseudo instructions. Differential Revision: https://reviews.llvm.org/D154347
2023-07-07[PEI] Simplify iterator handling in replaceFrameIndicesBackward. NFCI.Jay Foad1-40/+8
Differential Revision: https://reviews.llvm.org/D154346
2023-07-05Weaken MFI Max Call Frame Size AssertionOskar Wirga1-2/+2
A year ago when I was not invested at all into compilers, I found an assertion error when building an AArch64 debug build with LTO + CFI, among other combinations. It was posted as a github issue here: https://github.com/llvm/llvm-project/issues/54088 I took it upon myself to revisit the issue now that I have spent some more time working on LLVM. Reviewed By: MatzeB Differential Revision: https://reviews.llvm.org/D151276
2023-06-16[MC] Add MCRegisterInfo::regunits for iteration over register unitsSergei Barannikov1-2/+2
Reviewed By: foad Differential Revision: https://reviews.llvm.org/D152098
2023-05-09PrologEpilogInserter: Fix -Wunused-variable in -DLLVM_ENABLE_ASSERTIONS=off ↵Fangrui Song1-9/+9
builds
2023-05-09Wrap debug code with the LLVM_DEBUG macro; NFCAaron Ballman1-5/+6
While investigating a bug in Clang, I noticed that -Wframe-larger-than was emitting extra debug information along with the diagnostic. It turns out that 2e1e2f52f357768186ecfcc5ac53d5fa53d1b094 fixed an issue with the diagnostic, but accidentally left in some debug code that was exposed in all builds. So now we no longer emit things like: 8/4294967304 (0.00%) spills, 4294967296/4294967304 (100.00%) variables along with the diagnostic
2023-04-20Fix uninitialized class membersAkshay Khadse1-2/+2
Reviewed By: LuoYuanke Differential Revision: https://reviews.llvm.org/D148692
2023-04-17Fix uninitialized pointer members in CodeGenAkshay Khadse1-1/+1
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-09Revert "HHVM calling conventions."Amir Aupov1-21/+16
This reverts commit cce239c45d6ef3865a017b5b3f935964e0348734. HHVM calling conventions are unused. Remove them by partially reverting the commit. Reviewed By: MaskRay, MatzeB Differential Revision: https://reviews.llvm.org/D124330
2023-01-25[zero-call-used-regs] Mark only non-debug instruction's register as usedShivam Gupta1-1/+6
zero-call-used-regs pass generate an xor instruction to help mitigate return-oriented programming exploits via zeroing out used registers. But in this below test case with -g option there is dbg.value instruction associating the register with the debug-info description of the formal parameter d, which makes the register appear used, therefore it zero the register edi in -g case and makes binary different from without -g option. The pass should be looking only at the non-debug uses. $ cat test.c char a[]; int b; __attribute__((zero_call_used_regs("used"))) char c(int d) { *a = ({ int e = d; b; }); } This fixes https://github.com/llvm/llvm-project/issues/57962. Differential Revision: https://reviews.llvm.org/D138757
2022-12-17[CodeGen] Additional Register argument to ↵Christudasan Devadasan1-2/+3
storeRegToStackSlot/loadRegFromStackSlot With D134950, targets get notified when a virtual register is created and/or cloned. Targets can do the needful with the delegate callback. AMDGPU propagates the virtual register flags maintained in the target file itself. They are useful to identify a certain type of machine operands while inserting spill stores and reloads. Since RegAllocFast spills the physical register itself, there is no way its virtual register can be mapped back to retrieve the flags. It can be solved by passing the virtual register as an additional argument. This argument has no use when the spill interfaces are called during the greedy allocator or even the PrologEpilogInserter and can pass a null register in such cases. Reviewed By: arsenm Differential Revision: https://reviews.llvm.org/D138656
2022-12-13[X86] Don't zero out %eax if both %al and %ah are usedBill Wendling1-1/+7
The iterator over super and sub registers doesn't include both 8-bit registers in its list. So if both registers are used and only one of them is live on return, then we need to make sure that the other 8-bit register is also marked as live and not zeroed out. Reviewed By: nickdesaulniers Differential Revision: https://reviews.llvm.org/D139679
2022-11-18PEI should be able to use backward walk in replaceFrameIndicesBackward.Alexander Timofeev1-3/+77
The backward register scavenger has correct register liveness information. PEI should leverage the backward register scavenger. Reviewed By: arsenm Differential Revision: https://reviews.llvm.org/D137574
2022-11-15Revert D137574 "PEI should be able to use backward walk in ↵Fangrui Song1-75/+3
replaceFrameIndicesBackward." This reverts commit e05ce03cfa0b36e9b99149e21afcb1fc039df813. Caused asan use-after-poison to 4 DebugInfo/AMDGPU/ tests. Triggered in PEI::replaceFrameIndicesBackward called llvm::MachineInstr::getNumOperands
2022-11-15PEI should be able to use backward walk in replaceFrameIndicesBackward.Alexander Timofeev1-3/+75
The backward register scavenger has correct register liveness information. PEI should leverage the backward register scavenger. Reviewed By: arsenm Differential Revision: https://reviews.llvm.org/D137574
2022-11-10[PEI][NFC] Refactoring of the debug instructions frame index replacementAlexander Timofeev1-73/+86
This is required for the upcoming backward PEI::replaceFrameIndices version. Both forward and backward versions will use same code for debug instruction processing. Reviewed By: arsenm Differential Revision: https://reviews.llvm.org/D137741
2022-10-27[CodeGen] Improve large stack frame diagnosticPaul Kirth1-3/+26
Add statistics about how much memory is used, in variables, spills, and unsafestack. Issue #58168 describes some of the difficulty diagnosing stack size issues identified by -Wframe-larger-than. D135488 addresses some of those issues by giving developers a method to view the stack layout and thereby understand where and how stack memory is used. However, that solution requires an additional pass, when a short summary about how the compiler has allocated stack memory can inform developers about where they should investigate. When they need the complete context, D135488 can provide them with a more comprehensive set of diagnostics. Reviewed By: nickdesaulniers Differential Revision: https://reviews.llvm.org/D136484
2022-09-16[CodeGen] Don't zero callee-save registers with zero-call-used-regs (PR57692)Nikita Popov1-3/+4
Callee save registers must be preserved, so -fzero-call-used-regs should not be zeroing them. The previous implementation only did not zero callee save registers that were saved&restored inside the function, but we need preserve all of them. Fixes https://github.com/llvm/llvm-project/issues/57692. Differential Revision: https://reviews.llvm.org/D133946
2022-08-19[X86][AArch64][NFC] Simplify querying used argument registersBill Wendling1-2/+13
Registers used for arguments are listed as "live-ins" into the starting basic block. This means we don't have to go through a potentially expensive search through all possible argument registers when we only care about used argument registers. Differential Revision: https://reviews.llvm.org/D132181
2022-07-05[NFC] Fix wrong comment.Thomas Symalla1-1/+1
2022-05-12[CodeGen][NFC] Move some comments from the end of lines to above themFraser Cormack1-6/+6
This avoids wrapping the line itself awkwardly when it exceeds 80 chars. It also better matches our style most other places.
2022-04-27[X86] Move target-generic code into CodeGen [NFC]Bill Wendling1-1/+26
This code is the same for all platforms. Differential Revision: https://reviews.llvm.org/D124566
2022-04-20[safestack] Support safestack in stack size diagnosticsPaul Kirth1-0/+3
Current stack size diagnostics ignore the size of the unsafe stack. This patch attaches the size of the static portion of the unsafe stack to the function as metadata, which can be used by the backend to emit diagnostics regarding stack usage. Reviewed By: phosek, mcgrathr Differential Revision: https://reviews.llvm.org/D119996
2022-04-20MachineModuleInfo: Move HasSplitStack handling to AsmPrinterMatt Arsenault1-5/+1
This is used to emit one field in doFinalization for the module. We can accumulate this when emitting all individual functions directly in the AsmPrinter, rather than accumulating additional state in MachineModuleInfo. Move the special case behavior predicate into MachineFrameInfo to share it. This now promotes it to generic behavior. I'm assuming this is fine because no other target implements adjustForSegmentedStacks, or has tests using the split-stack attribute.
2022-03-16Cleanup codegen includesserge-sans-paille1-2/+0
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 Weber1-0/+2
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-paille1-2/+0
after: 1061034926 before: 1063332844 Differential Revision: https://reviews.llvm.org/D121169
2022-03-02[CodeGen] Use AdjustStackOffset for Callee Saved Registers in ↵Daniel McIntosh1-28/+15
PEI::calculateFrameObjectOffsets Also, changes how the CSR loop is indexed, which should avoid bugs like the one fixed by rG4a57bb5a3b74bdad9b0518009a7d7ac7ca2ac650 Reviewed By: arsenm Differential Revision: https://reviews.llvm.org/D120668
2022-02-08[X86] Implement -fzero-call-used-regs optionBill Wendling1-0/+93
The "-fzero-call-used-regs" option tells the compiler to zero out certain registers before the function returns. It's also available as a function attribute: zero_call_used_regs. The two upper categories are: - "used": Zero out used registers. - "all": Zero out all registers, whether used or not. The individual options are: - "skip": Don't zero out any registers. This is the default. - "used": Zero out all used registers. - "used-arg": Zero out used registers that are used for arguments. - "used-gpr": Zero out used registers that are GPRs. - "used-gpr-arg": Zero out used GPRs that are used as arguments. - "all": Zero out all registers. - "all-arg": Zero out all registers used for arguments. - "all-gpr": Zero out all GPRs. - "all-gpr-arg": Zero out all GPRs used for arguments. This is used to help mitigate Return-Oriented Programming exploits. Reviewed By: nickdesaulniers Differential Revision: https://reviews.llvm.org/D110869
2021-12-14[AArch64][SVE] Fix handling of stack protection with SVEJohn Brawn1-2/+12
Fix a couple of things that were causing stack protection to not work correctly in functions that have scalable vectors on the stack: * Use TypeSize when determining if accesses to a variable are considered out-of-bounds so that the behaviour is correct for scalable vectors. * When stack protection is enabled move the stack protector location to the top of the SVE locals, so that any overflow in them (or the other locals which are below that) will be detected. Fixes: https://github.com/llvm/llvm-project/issues/51137 Differential Revision: https://reviews.llvm.org/D111631