[PATCH] D143463: [X86] Use the CFA when appropriate for better variable locations around calls.

Kyle Huey via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 6 22:18:36 PST 2023


khuey created this revision.
khuey added a reviewer: MaskRay.
Herald added subscribers: pengfei, hiraditya, dschuff.
Herald added a project: All.
khuey requested review of this revision.
Herald added subscribers: llvm-commits, aheejin.
Herald added a project: LLVM.

Without frame pointers, the locations of variables on the stack are emitted
relative to the stack pointer (via the stack pointer being the value of
DW_AT_frame_base on the subprogram). If a call modifies the stack pointer
this results in the locations being wrong and the debugger displaying the
wrong values for variables.

By using DW_OP_call_frame_cfa in these situations the emitted location for
the variable will automatically handle changes in the stack pointer
(provided LLVM is emitting the correct CFI directives elsewhere, of course).
The CFA needs to be adjusted for the size of the stack frame (including the
return address) to allow the variable locations themselves to remain
unchanged by this patch.

There is an implicit heuristic that triggers this new behavior: the emission
of cfi_adjust_cfa_offset directives. It's possible that this should be
expanded further but it seems to cover the cases I am aware of.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D143463

Files:
  llvm/include/llvm/CodeGen/TargetFrameLowering.h
  llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
  llvm/lib/CodeGen/CFIInstrInserter.cpp
  llvm/lib/Target/X86/X86FrameLowering.cpp
  llvm/lib/Target/X86/X86FrameLowering.h
  llvm/lib/Target/X86/X86MCInstLower.cpp
  llvm/lib/Target/X86/X86MachineFunctionInfo.h
  llvm/test/DebugInfo/X86/stack_adjustments_trigger_cfa_frame_base.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D143463.495380.patch
Type: text/x-patch
Size: 19502 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230207/d4a91376/attachment.bin>


More information about the llvm-commits mailing list