[codegen] Add StackFrameLayoutAnalysisPass
authorPaul Kirth <paulkirth@google.com>
Tue, 20 Dec 2022 00:25:21 +0000 (00:25 +0000)
committerPaul Kirth <paulkirth@google.com>
Fri, 13 Jan 2023 20:52:48 +0000 (20:52 +0000)
commit0a652c540556a118bbd9386ed3ab7fd9e60a9754
tree4469de8ef6f025cac560d449d5b66e7a76f21d22
parente0f3a95f9d999b526a9e82bb1a4012fdcb09b364
[codegen] Add StackFrameLayoutAnalysisPass

Issue #58168 describes the difficulty diagnosing stack size issues
identified by -Wframe-larger-than. For simple code, its easy to
understand the stack layout and where space is being allocated, but in
more complex programs, where code may be heavily inlined, unrolled, and
have duplicated code paths, it is no longer easy to manually inspect the
source program and understand where stack space can be attributed.

This patch implements a machine function pass that emits remarks with a
textual representation of stack slots, and also outputs any available
debug information to map source variables to those slots.

The new behavior can be used by adding `-Rpass-analysis=stack-frame-layout`
to the compiler invocation. Like other remarks the diagnostic
information can be saved to a file in a machine readable format by
adding -fsave-optimzation-record.

Fixes: #58168

Reviewed By: nickdesaulniers, thegameg

Differential Revision: https://reviews.llvm.org/D135488
23 files changed:
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticGroups.td
clang/test/Frontend/stack-layout-remark.c [new file with mode: 0644]
llvm/include/llvm/CodeGen/Passes.h
llvm/include/llvm/InitializePasses.h
llvm/lib/CodeGen/CMakeLists.txt
llvm/lib/CodeGen/CodeGen.cpp
llvm/lib/CodeGen/StackFrameLayoutAnalysisPass.cpp [new file with mode: 0644]
llvm/lib/CodeGen/TargetPassConfig.cpp
llvm/test/CodeGen/AArch64/O0-pipeline.ll
llvm/test/CodeGen/AArch64/O3-pipeline.ll
llvm/test/CodeGen/AArch64/arm64-opt-remarks-lazy-bfi.ll
llvm/test/CodeGen/AMDGPU/llc-pipeline.ll
llvm/test/CodeGen/ARM/O3-pipeline.ll
llvm/test/CodeGen/ARM/stack-frame-layout-remarks.ll [new file with mode: 0644]
llvm/test/CodeGen/Generic/llc-start-stop.ll
llvm/test/CodeGen/PowerPC/O0-pipeline.ll
llvm/test/CodeGen/PowerPC/O3-pipeline.ll
llvm/test/CodeGen/RISCV/O0-pipeline.ll
llvm/test/CodeGen/RISCV/O3-pipeline.ll
llvm/test/CodeGen/X86/O0-pipeline.ll
llvm/test/CodeGen/X86/opt-pipeline.ll
llvm/test/CodeGen/X86/stack-frame-layout-remarks.ll [new file with mode: 0644]