diff options
author | weiguozhi <57237827+weiguozhi@users.noreply.github.com> | 2024-08-06 16:18:20 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-06 16:18:20 -0700 |
commit | 0d471b3f64d3116bd57c79d872f7384fff80daa5 (patch) | |
tree | 076910e4a920b2d27abd31d2c3cf1f2c0c219323 /llvm/lib/CodeGen/PrologEpilogInserter.cpp | |
parent | ce2a3d9042c95630f12b790bf201c4daf8941afb (diff) | |
download | llvm-0d471b3f64d3116bd57c79d872f7384fff80daa5.zip llvm-0d471b3f64d3116bd57c79d872f7384fff80daa5.tar.gz llvm-0d471b3f64d3116bd57c79d872f7384fff80daa5.tar.bz2 |
Spill/restore FP/BP around instructions in which they are clobbered (#81048)
This patch fixes https://github.com/llvm/llvm-project/issues/17204.
If a base pointer is used in a function, and it is clobbered by an
instruction (typically an inline asm), current register allocator can't
handle this situation, so BP becomes garbage after those instructions.
It can also occur to FP in theory.
We can spill and reload FP/BP registers around those instructions. But
normal spill/reload instructions also use FP/BP, so we can't spill them
into normal spill slots, instead we spill them into the top of stack by
using SP register.
Diffstat (limited to 'llvm/lib/CodeGen/PrologEpilogInserter.cpp')
-rw-r--r-- | llvm/lib/CodeGen/PrologEpilogInserter.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/llvm/lib/CodeGen/PrologEpilogInserter.cpp b/llvm/lib/CodeGen/PrologEpilogInserter.cpp index f449087..ee03eaa 100644 --- a/llvm/lib/CodeGen/PrologEpilogInserter.cpp +++ b/llvm/lib/CodeGen/PrologEpilogInserter.cpp @@ -228,6 +228,11 @@ bool PEI::runOnMachineFunction(MachineFunction &MF) { FrameIndexVirtualScavenging = TRI->requiresFrameIndexScavenging(MF); ORE = &getAnalysis<MachineOptimizationRemarkEmitterPass>().getORE(); + // Spill frame pointer and/or base pointer registers if they are clobbered. + // It is placed before call frame instruction elimination so it will not mess + // with stack arguments. + TFI->spillFPBP(MF); + // Calculate the MaxCallFrameSize value for the function's frame // information. Also eliminates call frame pseudo instructions. calculateCallFrameInfo(MF); |