[llvm] 557a5bc - [codegen] Add StackFrameLayoutAnalysisPass
Paul Kirth via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 18 17:51:25 PST 2023
Author: Paul Kirth
Date: 2023-01-19T01:51:14Z
New Revision: 557a5bc336ffb9b03c53d4d13fd8f0bc9418ec96
URL: https://github.com/llvm/llvm-project/commit/557a5bc336ffb9b03c53d4d13fd8f0bc9418ec96
DIFF: https://github.com/llvm/llvm-project/commit/557a5bc336ffb9b03c53d4d13fd8f0bc9418ec96.diff
LOG: [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
Added:
clang/test/Frontend/stack-layout-remark.c
llvm/lib/CodeGen/StackFrameLayoutAnalysisPass.cpp
llvm/test/CodeGen/ARM/stack-frame-layout-remarks.ll
llvm/test/CodeGen/X86/stack-frame-layout-remarks.ll
Modified:
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticGroups.td
llvm/include/llvm/CodeGen/Passes.h
llvm/include/llvm/InitializePasses.h
llvm/lib/CodeGen/CMakeLists.txt
llvm/lib/CodeGen/CodeGen.cpp
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/Generic/llc-start-stop.ll
llvm/test/CodeGen/LoongArch/O0-pipeline.ll
llvm/test/CodeGen/LoongArch/opt-pipeline.ll
llvm/test/CodeGen/M68k/pipeline.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
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 288904b023863..21960ab69ceab 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -547,6 +547,11 @@ New Compiler Flags
`Standard C++ Modules <https://clang.llvm.org/docs/StandardCPlusPlusModules.html>`_
for more information.
+- Added ``-Rpass-analysis=stack-frame-layout`` which will emit new diagnostic
+ information about the layout of stack frames through the remarks
+ infrastructure. Since it uses remarks the diagnostic information is available
+ both on the CLI, and in a machine readable format.
+
Deprecated Compiler Flags
-------------------------
- ``-enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang``
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td
index d754fdb594c02..6c997c37cc5cd 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1269,7 +1269,25 @@ def OpenMP : DiagGroup<"openmp", [
// Backend warnings.
def BackendInlineAsm : DiagGroup<"inline-asm">;
def BackendSourceMgr : DiagGroup<"source-mgr">;
-def BackendFrameLargerThan : DiagGroup<"frame-larger-than">;
+def BackendFrameLargerThan : DiagGroup<"frame-larger-than">{
+ code Documentation = [{
+More fine grained information about the stack layout is available by adding the
+`-Rpass-analysis=stack-frame-layout` command-line flag to the compiler
+invocation.
+
+The diagnostic information can be saved to a file in a machine readable format,
+like YAML by adding the `-foptimization-record-file=<file>` command-line flag.
+
+Results can be filtered by function name by passing
+`-mllvm -filter-print-funcs=foo`, where `foo` is the target function's name.
+
+ .. code-block: console
+ clang -c a.cpp -Rpass-analysis=stack-frame-layout -mllvm -filter-print-funcs=foo
+
+ .. code-block: console
+ clang -c a.cpp -Rpass-analysis=stack-frame-layout -foptimization-record-file=<file>
+}];
+}
// Compatibility flag name from old versions of Clang.
def : DiagGroup<"frame-larger-than=", [BackendFrameLargerThan]>;
def BackendPlugin : DiagGroup<"backend-plugin">;
diff --git a/clang/test/Frontend/stack-layout-remark.c b/clang/test/Frontend/stack-layout-remark.c
new file mode 100644
index 0000000000000..b0ed03c80f24a
--- /dev/null
+++ b/clang/test/Frontend/stack-layout-remark.c
@@ -0,0 +1,308 @@
+// Check that backend stack layout diagnostics are working correctly with and
+// without debug information, and when optimizations are enabled
+//
+// REQUIRES: x86-registered-target
+//
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: %clang_cc1 %s -emit-codegen-only -triple x86_64-unknown-linux-gnu -target-cpu corei7 -Rpass-analysis=stack-frame-layout -o /dev/null -O0 2>&1 | FileCheck %s --check-prefix=O0-NODEBUG
+// RUN: %clang_cc1 %s -emit-codegen-only -triple x86_64-unknown-linux-gnu -target-cpu corei7 -Rpass-analysis=stack-frame-layout -o /dev/null -O0 -debug-info-kind=constructor -dwarf-version=5 -debugger-tuning=gdb 2>&1 | FileCheck %s --check-prefix=O0-DEBUG
+// RUN: %clang_cc1 %s -emit-codegen-only -triple x86_64-unknown-linux-gnu -target-cpu corei7 -funwind-tables=2 -O3 -Rpass-analysis=stack-frame-layout -debug-info-kind=constructor -dwarf-version=5 -debugger-tuning=gdb -opt-record-file %t/stack-layout-remark.c.yml -opt-record-passes stack-frame-layout 2>&1 | FileCheck %s --check-prefix=O3-DEBUG
+// RUN: cat %t/stack-layout-remark.c.yml | FileCheck %s --check-prefix=YAML
+
+#define NULL (void*)0
+
+extern void* allocate(unsigned size);
+extern void deallocate(void* ptr);
+extern int work(char *ary, int size);
+extern int rand(void);
+
+// Test YAML Ouput
+// YAML: --- !Analysis
+// YAML: Pass: stack-frame-layout
+// YAML: Name: StackLayout
+// YAML: DebugLoc: { File: '{{.*}}stack-layout-remark.c',{{[[:space:]]*}}Line: [[# @LINE + 24]],
+// YAML: Function: foo
+// YAML: Args:
+// YAML: - Offset: '-40'
+// YAML: - Type: Variable
+// YAML: - Align: '16'
+// YAML: - Size: '32'
+// YAML: - DataLoc: 'a @ {{.*}}stack-layout-remark.c:[[# @LINE + 19]]'
+// YAML: - DataLoc: 'f @ {{.*}}stack-layout-remark.c:[[# @LINE + 21]]'
+
+// O0-NODEBUG: Function: foo
+// O0-NODEBUG-NEXT: Offset: [SP-40], Type: Variable, Align: 16, Size: 32
+// O0-NODEBUG-NEXT: Offset: [SP-72], Type: Variable, Align: 16, Size: 32
+//
+// O0-DEBUG: Function: foo
+// O0-DEBUG-NEXT: Offset: [SP-40], Type: Variable, Align: 16, Size: 32
+// O0-DEBUG-NEXT: a @ {{.*}}stack-layout-remark.c:[[# @LINE + 10]]
+// O0-DEBUG-NEXT: Offset: [SP-72], Type: Variable, Align: 16, Size: 32
+// O0-DEBUG-NEXT: f @ {{.*}}stack-layout-remark.c:[[# @LINE + 11]]
+
+// O3-DEBUG: Function: foo
+// O3-DEBUG-NEXT: Offset: [SP-40], Type: Variable, Align: 16, Size: 32
+// O3-DEBUG-NEXT: a @ {{.*}}stack-layout-remark.c:[[# @LINE + 4]]
+// O3-DEBUG-NEXT: f @ {{.*}}stack-layout-remark.c:[[# @LINE + 6]]
+void foo() {
+ {
+ char a[32] = {0};
+ work(a, sizeof(a));
+ }
+ char f[32] = {0};
+ work(f, sizeof(f));
+}
+// O0-NODEBUG: Function: bar
+// O0-NODEBUG-NEXT: Offset: [SP-40], Type: Variable, Align: 16, Size: 32
+// O0-NODEBUG-NEXT: Offset: [SP-72], Type: Variable, Align: 16, Size: 32
+
+// O0-DEBUG: Function: bar
+// O0-DEBUG-NEXT: Offset: [SP-40], Type: Variable, Align: 16, Size: 32
+// O0-DEBUG-NEXT: f @ {{.*}}stack-layout-remark.c:[[# @LINE + 10]]
+// O0-DEBUG-NEXT: Offset: [SP-72], Type: Variable, Align: 16, Size: 32
+// O0-DEBUG-NEXT: a @ {{.*}}stack-layout-remark.c:[[# @LINE + 10]]
+
+// O3-DEBUG: Function: bar
+// O3-DEBUG-NEXT: Offset: [SP-40], Type: Variable, Align: 16, Size: 32
+// O3-DEBUG-NEXT: f @ {{.*}}stack-layout-remark.c:[[# @LINE + 4]]
+// O3-DEBUG-NEXT: Offset: [SP-72], Type: Variable, Align: 16, Size: 32
+// O3-DEBUG-NEXT: a @ {{.*}}stack-layout-remark.c:[[# @LINE + 4]]
+void bar() {
+ char f[32] = {0};
+ {
+ char a[32] = {0};
+ work(a, sizeof(a));
+ }
+ work(f, sizeof(f));
+}
+
+struct Array {
+ int *data;
+ int size;
+};
+
+struct Result {
+ struct Array *data;
+ int sum;
+};
+
+// O0-NODEBUG: Function: cleanup_array
+// O0-NODEBUG-NEXT: Offset: [SP-8], Type: Variable, Align: 8, Size: 8
+
+// O0-DEBUG: Function: cleanup_array
+// O0-DEBUG-NEXT: Offset: [SP-8], Type: Variable, Align: 8, Size: 8
+// O0-DEBUG-NEXT: a @ {{.*}}stack-layout-remark.c:[[# @LINE + 5]]
+
+// O3-DEBUG: Function: cleanup_array
+// O3-DEBUG: Function: cleanup_result
+// O3-DEBUG-NEXT: Offset: [SP-8], Type: Spill, Align: 16, Size: 8
+void cleanup_array(struct Array *a) {
+ if (!a)
+ return;
+ if (!a->data)
+ return;
+ deallocate(a->data);
+}
+
+// O0-NODEBUG: Function: cleanup_result
+// O0-NODEBUG-NEXT: Offset: [SP-8], Type: Variable, Align: 8, Size: 8
+
+// O0-DEBUG: Function: cleanup_result
+// O0-DEBUG-NEXT: Offset: [SP-8], Type: Variable, Align: 8, Size: 8
+// O0-DEBUG-NEXT: res @ {{.*}}stack-layout-remark.c:[[# @LINE + 1]]
+void cleanup_result(struct Result *res) {
+ if (!res)
+ return;
+ if (!res->data)
+ return;
+ cleanup_array(res->data);
+ deallocate(res->data);
+}
+
+extern void use_dot_vector(struct Array *data);
+
+// O0-NODEBUG: Function: do_work
+// O0-NODEBUG-NEXT: Offset: [SP-4], Type: Variable, Align: 4, Size: 4
+// O0-NODEBUG-NEXT: Offset: [SP-16], Type: Variable, Align: 8, Size: 8
+// O0-NODEBUG-NEXT: Offset: [SP-24], Type: Variable, Align: 8, Size: 8
+// O0-NODEBUG-NEXT: Offset: [SP-32], Type: Variable, Align: 8, Size: 8
+// O0-NODEBUG-NEXT: Offset: [SP-36], Type: Variable, Align: 4, Size: 4
+// O0-NODEBUG-NEXT: Offset: [SP-48], Type: Variable, Align: 8, Size: 8
+// O0-NODEBUG-NEXT: Offset: [SP-52], Type: Variable, Align: 4, Size: 4
+// O0-NODEBUG-NEXT: Offset: [SP-56], Type: Variable, Align: 4, Size: 4
+
+// O0-DEBUG: Function: do_work
+// O0-DEBUG-NEXT: Offset: [SP-4], Type: Variable, Align: 4, Size: 4
+// O0-DEBUG-NEXT: Offset: [SP-16], Type: Variable, Align: 8, Size: 8
+// O0-DEBUG-NEXT: A @ {{.*}}stack-layout-remark.c:[[# @LINE + 20]]
+// O0-DEBUG-NEXT: Offset: [SP-24], Type: Variable, Align: 8, Size: 8
+// O0-DEBUG-NEXT: B @ {{.*}}stack-layout-remark.c:[[# @LINE + 18]]
+// O0-DEBUG-NEXT: Offset: [SP-32], Type: Variable, Align: 8, Size: 8
+// O0-DEBUG-NEXT: out @ {{.*}}stack-layout-remark.c:[[# @LINE + 16]]
+// O0-DEBUG-NEXT: Offset: [SP-36], Type: Variable, Align: 4, Size: 4
+// O0-DEBUG-NEXT: len @ {{.*}}stack-layout-remark.c:[[# @LINE + 19]]
+// O0-DEBUG-NEXT: Offset: [SP-48], Type: Variable, Align: 8, Size: 8
+// O0-DEBUG-NEXT: AB @ {{.*}}stack-layout-remark.c:[[# @LINE + 18]]
+// O0-DEBUG-NEXT: Offset: [SP-52], Type: Variable, Align: 4, Size: 4
+// O0-DEBUG-NEXT: sum @ {{.*}}stack-layout-remark.c:[[# @LINE + 32]]
+// O0-DEBUG-NEXT: Offset: [SP-56], Type: Variable, Align: 4, Size: 4
+// O0-DEBUG-NEXT: i @ {{.*}}stack-layout-remark.c:[[# @LINE + 31]]
+
+// O3-DEBUG: Function: do_work
+// O3-DEBUG-NEXT: Offset: [SP-8], Type: Spill, Align: 16, Size: 8
+// O3-DEBUG-NEXT: Offset: [SP-16], Type: Spill, Align: 8, Size: 8
+// O3-DEBUG-NEXT: Offset: [SP-24], Type: Spill, Align: 16, Size: 8
+// O3-DEBUG-NEXT: Offset: [SP-32], Type: Spill, Align: 8, Size: 8
+// O3-DEBUG-NEXT: Offset: [SP-40], Type: Spill, Align: 16, Size: 8
+int do_work(struct Array *A, struct Array *B, struct Result *out) {
+ if (!A || !B)
+ return -1;
+ if (A->size != B->size)
+ return -1;
+ const int len = A->size;
+ struct Array *AB;
+ if (out->data == NULL) {
+ AB = (struct Array *)allocate(sizeof(struct Array));
+ AB->data = NULL;
+ AB->size = 0;
+ out->data = AB;
+ } else {
+ AB = out->data;
+ }
+
+ if (AB->data)
+ deallocate(AB->data);
+
+ AB->data = (int *)allocate(len * sizeof(int));
+ AB->size = len;
+
+ int sum = 0;
+ for (int i = 0; i < len; ++i) {
+ AB->data[i] = A->data[i] * B->data[i];
+ sum += AB->data[i];
+ }
+ return sum;
+}
+
+// O0-NODEBUG: Function: gen_array
+// O0-NODEBUG-NEXT: Offset: [SP-8], Type: Variable, Align: 8, Size: 8
+// O0-NODEBUG-NEXT: Offset: [SP-12], Type: Variable, Align: 4, Size: 4
+// O0-NODEBUG-NEXT: Offset: [SP-24], Type: Variable, Align: 8, Size: 8
+// O0-NODEBUG-NEXT: Offset: [SP-28], Type: Variable, Align: 4, Size: 4
+
+// O0-DEBUG: Function: gen_array
+// O0-DEBUG-NEXT: Offset: [SP-8], Type: Variable, Align: 8, Size: 8
+// O0-DEBUG-NEXT: Offset: [SP-12], Type: Variable, Align: 4, Size: 4
+// O0-DEBUG-NEXT: size @ {{.*}}stack-layout-remark.c:[[# @LINE + 10]]
+// O0-DEBUG-NEXT: Offset: [SP-24], Type: Variable, Align: 8, Size: 8
+// O0-DEBUG-NEXT: res @ {{.*}}stack-layout-remark.c:[[# @LINE + 11]]
+// O0-DEBUG-NEXT: Offset: [SP-28], Type: Variable, Align: 4, Size: 4
+// O0-DEBUG-NEXT: i @ {{.*}}stack-layout-remark.c:[[# @LINE + 13]]
+
+// O3-DEBUG: Function: gen_array
+// O3-DEBUG-NEXT: Offset: [SP-8], Type: Spill, Align: 16, Size: 8
+// O3-DEBUG-NEXT: Offset: [SP-16], Type: Spill, Align: 8, Size: 8
+// O3-DEBUG-NEXT: Offset: [SP-24], Type: Spill, Align: 16, Size: 8
+struct Array *gen_array(int size) {
+ if (size < 0)
+ return NULL;
+ struct Array *res = (struct Array *)allocate(sizeof(struct Array));
+ res->size = size;
+ res->data = (int *)allocate(size * sizeof(int));
+
+ for (int i = 0; i < size; ++i) {
+ res->data[i] = rand();
+ }
+
+ return res;
+}
+
+// YAML: --- !Analysis
+// YAML: Pass: stack-frame-layout
+// YAML: Name: StackLayout
+// YAML: DebugLoc: { File: '{{.*}}stack-layout-remark.c',{{[[:space:]]*}}Line: [[# @LINE + 59]],
+// YAML: Function: caller
+// YAML: Args:
+// YAML: - Offset: '-8'
+// YAML: - Type: Spill
+// YAML: - Align: '16'
+// YAML: - Size: '8'
+// YAML: - Offset: '-16'
+// YAML: - Type: Spill
+// YAML: - Align: '8'
+// YAML: - Size: '8'
+// YAML: - Offset: '-24'
+// YAML: - Type: Spill
+// YAML: - Align: '16'
+// YAML: - Size: '8'
+// YAML: - Offset: '-32'
+// YAML: - Type: Spill
+// YAML: - Align: '8'
+// YAML: - Size: '8'
+// YAML: - Offset: '-40'
+// YAML: - Type: Spill
+// YAML: - Align: '16'
+// YAML: - Size: '8'
+// YAML: - Offset: '-48'
+// YAML: - Type: Spill
+// YAML: - Align: '8'
+// YAML: - Size: '8'
+
+// O0-NODEBUG: Function: caller
+// O0-NODEBUG-NEXT: Offset: [SP-4], Type: Variable, Align: 4, Size: 4
+// O0-NODEBUG-NEXT: Offset: [SP-8], Type: Variable, Align: 4, Size: 4
+// O0-NODEBUG-NEXT: Offset: [SP-16], Type: Variable, Align: 8, Size: 8
+// O0-NODEBUG-NEXT: Offset: [SP-24], Type: Variable, Align: 8, Size: 8
+// O0-NODEBUG-NEXT: Offset: [SP-32], Type: Variable, Align: 8, Size: 8
+// O0-NODEBUG-NEXT: Offset: [SP-36], Type: Variable, Align: 4, Size: 4
+// O0-NODEBUG-NEXT: Offset: [SP-40], Type: Variable, Align: 4, Size: 4
+
+// O0-DEBUG: Function: caller
+// O0-DEBUG-NEXT: Offset: [SP-4], Type: Variable, Align: 4, Size: 4
+// O0-DEBUG-NEXT: Offset: [SP-8], Type: Variable, Align: 4, Size: 4
+// O0-DEBUG-NEXT: size @ {{.*}}stack-layout-remark.c:[[# @LINE + 20]]
+// O0-DEBUG-NEXT: Offset: [SP-16], Type: Variable, Align: 8, Size: 8
+// O0-DEBUG-NEXT: A @ {{.*}}stack-layout-remark.c:[[# @LINE + 19]]
+// O0-DEBUG-NEXT: Offset: [SP-24], Type: Variable, Align: 8, Size: 8
+// O0-DEBUG-NEXT: B @ {{.*}}stack-layout-remark.c:[[# @LINE + 18]]
+// O0-DEBUG-NEXT: Offset: [SP-32], Type: Variable, Align: 8, Size: 8
+// O0-DEBUG-NEXT: res @ {{.*}}stack-layout-remark.c:[[# @LINE + 17]]
+// O0-DEBUG-NEXT: Offset: [SP-36], Type: Variable, Align: 4, Size: 4
+// O0-DEBUG-NEXT: ret @ {{.*}}stack-layout-remark.c:[[# @LINE + 16]]
+// O0-DEBUG-NEXT: Offset: [SP-40], Type: Variable, Align: 4, Size: 4
+// O0-DEBUG-NEXT: err @ {{.*}}stack-layout-remark.c:[[# @LINE + 16]]
+
+// O3-DEBUG: Function: caller
+// O3-DEBUG-NEXT: Offset: [SP-8], Type: Spill, Align: 16, Size: 8
+// O3-DEBUG-NEXT: Offset: [SP-16], Type: Spill, Align: 8, Size: 8
+// O3-DEBUG-NEXT: Offset: [SP-24], Type: Spill, Align: 16, Size: 8
+// O3-DEBUG-NEXT: Offset: [SP-32], Type: Spill, Align: 8, Size: 8
+// O3-DEBUG-NEXT: Offset: [SP-40], Type: Spill, Align: 16, Size: 8
+// O3-DEBUG-NEXT: Offset: [SP-48], Type: Spill, Align: 8, Size: 8
+int caller() {
+ const int size = 100;
+ struct Array *A = gen_array(size);
+ struct Array *B = gen_array(size);
+ struct Result *res = (struct Result *)allocate(sizeof(struct Result));
+ int ret = -1;
+
+ int err = do_work(A, B, res);
+ if (err == -1) {
+ goto cleanup;
+ }
+
+ ret = res->sum;
+ if (ret == -1)
+ return caller();
+
+ use_dot_vector(res->data);
+
+cleanup:
+ cleanup_array(A);
+ cleanup_array(B);
+ cleanup_result(res);
+
+ return ret;
+}
+
diff --git a/llvm/include/llvm/CodeGen/Passes.h b/llvm/include/llvm/CodeGen/Passes.h
index 3f79ce379212d..b331c9a19fd12 100644
--- a/llvm/include/llvm/CodeGen/Passes.h
+++ b/llvm/include/llvm/CodeGen/Passes.h
@@ -63,6 +63,10 @@ namespace llvm {
createMachineFunctionPrinterPass(raw_ostream &OS,
const std::string &Banner ="");
+ /// StackFramePrinter pass - This pass prints out the machine function's
+ /// stack frame to the given stream as a debugging tool.
+ MachineFunctionPass *createStackFrameLayoutAnalysisPass();
+
/// MIRPrinting pass - this pass prints out the LLVM IR into the given stream
/// using the MIR serialization format.
MachineFunctionPass *createPrintMIRPass(raw_ostream &OS);
@@ -264,6 +268,10 @@ namespace llvm {
/// It merges disjoint allocas to reduce the stack size.
extern char &StackColoringID;
+ /// StackFramePrinter - This pass prints the stack frame layout and variable
+ /// mappings.
+ extern char &StackFrameLayoutAnalysisPassID;
+
/// IfConverter - This pass performs machine code if conversion.
extern char &IfConverterID;
diff --git a/llvm/include/llvm/InitializePasses.h b/llvm/include/llvm/InitializePasses.h
index 8494692f2a94e..1164cd872eb96 100644
--- a/llvm/include/llvm/InitializePasses.h
+++ b/llvm/include/llvm/InitializePasses.h
@@ -378,6 +378,7 @@ void initializeSlotIndexesPass(PassRegistry&);
void initializeSpeculativeExecutionLegacyPassPass(PassRegistry&);
void initializeSpillPlacementPass(PassRegistry&);
void initializeStackColoringPass(PassRegistry&);
+void initializeStackFrameLayoutAnalysisPassPass(PassRegistry &);
void initializeStackMapLivenessPass(PassRegistry&);
void initializeStackProtectorPass(PassRegistry&);
void initializeStackSafetyGlobalInfoWrapperPassPass(PassRegistry &);
diff --git a/llvm/lib/CodeGen/CMakeLists.txt b/llvm/lib/CodeGen/CMakeLists.txt
index 275ee8019b14e..cac16e59a51d1 100644
--- a/llvm/lib/CodeGen/CMakeLists.txt
+++ b/llvm/lib/CodeGen/CMakeLists.txt
@@ -213,6 +213,7 @@ add_llvm_component_library(LLVMCodeGen
SpillPlacement.cpp
SplitKit.cpp
StackColoring.cpp
+ StackFrameLayoutAnalysisPass.cpp
StackMapLivenessAnalysis.cpp
StackMaps.cpp
StackProtector.cpp
diff --git a/llvm/lib/CodeGen/CodeGen.cpp b/llvm/lib/CodeGen/CodeGen.cpp
index b1f080a2a9300..398ff56f737c4 100644
--- a/llvm/lib/CodeGen/CodeGen.cpp
+++ b/llvm/lib/CodeGen/CodeGen.cpp
@@ -122,6 +122,7 @@ void llvm::initializeCodeGen(PassRegistry &Registry) {
initializeSjLjEHPreparePass(Registry);
initializeSlotIndexesPass(Registry);
initializeStackColoringPass(Registry);
+ initializeStackFrameLayoutAnalysisPassPass(Registry);
initializeStackMapLivenessPass(Registry);
initializeStackProtectorPass(Registry);
initializeStackSlotColoringPass(Registry);
diff --git a/llvm/lib/CodeGen/StackFrameLayoutAnalysisPass.cpp b/llvm/lib/CodeGen/StackFrameLayoutAnalysisPass.cpp
new file mode 100644
index 0000000000000..ddac093423fa6
--- /dev/null
+++ b/llvm/lib/CodeGen/StackFrameLayoutAnalysisPass.cpp
@@ -0,0 +1,256 @@
+//===-- StackFrameLayoutAnalysisPass.cpp
+//------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// StackFrameLayoutAnalysisPass implementation. Outputs information about the
+// layout of the stack frame, using the remarks interface. On the CLI it prints
+// a textual representation of the stack frame. When possible it prints the
+// values that occupy a stack slot using any available debug information. Since
+// output is remarks based, it is also available in a machine readable file
+// format, such as YAML.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Analysis/OptimizationRemarkEmitter.h"
+#include "llvm/CodeGen/MachineFrameInfo.h"
+#include "llvm/CodeGen/MachineFunction.h"
+#include "llvm/CodeGen/MachineFunctionPass.h"
+#include "llvm/CodeGen/MachineOptimizationRemarkEmitter.h"
+#include "llvm/CodeGen/Passes.h"
+#include "llvm/CodeGen/SlotIndexes.h"
+#include "llvm/CodeGen/StackProtector.h"
+#include "llvm/CodeGen/TargetFrameLowering.h"
+#include "llvm/CodeGen/TargetSubtargetInfo.h"
+#include "llvm/IR/DebugInfoMetadata.h"
+#include "llvm/IR/PrintPasses.h"
+#include "llvm/InitializePasses.h"
+#include "llvm/Support/Debug.h"
+#include "llvm/Support/FormatVariadic.h"
+#include "llvm/Support/raw_ostream.h"
+
+#include <sstream>
+
+using namespace llvm;
+
+#define DEBUG_TYPE "stack-frame-layout"
+
+namespace {
+
+/// StackFrameLayoutAnalysisPass - This is a pass to dump the stack frame of a
+/// MachineFunction.
+///
+struct StackFrameLayoutAnalysisPass : public MachineFunctionPass {
+ using SlotDbgMap =
+ SmallDenseMap<int, SmallPtrSet<const DILocalVariable *, 4>>;
+ static char ID;
+
+ enum SlotType {
+ Spill, // a Spill slot
+ StackProtector, // Stack Protector slot
+ Variable, // a slot used to store a local data (could be a tmp)
+ Invalid // It's an error for a slot to have this type
+ };
+
+ struct SlotData {
+ int Slot;
+ int Size;
+ int Align;
+ int Offset;
+ SlotType SlotTy;
+
+ SlotData(const MachineFrameInfo &MFI, const int ValOffset, const int Idx)
+ : Slot(Idx), Size(MFI.getObjectSize(Idx)),
+ Align(MFI.getObjectAlign(Idx).value()),
+ Offset(MFI.getObjectOffset(Idx) - ValOffset), SlotTy(Invalid) {
+ if (MFI.isSpillSlotObjectIndex(Idx))
+ SlotTy = SlotType::Spill;
+ else if (Idx == MFI.getStackProtectorIndex())
+ SlotTy = SlotType::StackProtector;
+ else
+ SlotTy = SlotType::Variable;
+ }
+
+ // we use this to sort in reverse order, so that the layout is displayed
+ // correctly
+ bool operator<(const SlotData &Rhs) const { return Offset > Rhs.Offset; }
+ };
+
+ StackFrameLayoutAnalysisPass() : MachineFunctionPass(ID) {}
+
+ StringRef getPassName() const override {
+ return "Stack Frame Layout Analysis";
+ }
+
+ void getAnalysisUsage(AnalysisUsage &AU) const override {
+ AU.setPreservesAll();
+ MachineFunctionPass::getAnalysisUsage(AU);
+ AU.addRequired<MachineOptimizationRemarkEmitterPass>();
+ }
+
+ bool runOnMachineFunction(MachineFunction &MF) override {
+ // TODO: We should implement a similar filter for remarks:
+ // -Rpass-func-filter=<regex>
+ if (!isFunctionInPrintList(MF.getName()))
+ return false;
+
+ LLVMContext &Ctx = MF.getFunction().getContext();
+ if (!Ctx.getDiagHandlerPtr()->isAnalysisRemarkEnabled(DEBUG_TYPE))
+ return false;
+
+ MachineOptimizationRemarkAnalysis Rem(DEBUG_TYPE, "StackLayout",
+ MF.getFunction().getSubprogram(),
+ &MF.front());
+ Rem << ("\nFunction: " + MF.getName()).str();
+ emitStackFrameLayoutRemarks(MF, Rem);
+ getAnalysis<MachineOptimizationRemarkEmitterPass>().getORE().emit(Rem);
+ return false;
+ }
+
+ std::string getTypeString(SlotType Ty) {
+ switch (Ty) {
+ case SlotType::Spill:
+ return "Spill";
+ case SlotType::StackProtector:
+ return "Protector";
+ case SlotType::Variable:
+ return "Variable";
+ default:
+ llvm_unreachable("bad slot type for stack layout");
+ }
+ }
+
+ void emitStackSlotRemark(const MachineFunction &MF, const SlotData &D,
+ MachineOptimizationRemarkAnalysis &Rem) {
+ // To make it easy to understand the stack layout from the CLI, we want to
+ // print each slot like the following:
+ //
+ // Offset: [SP+8], Type: Spill, Align: 8, Size: 16
+ // foo @ /path/to/file.c:25
+ // bar @ /path/to/file.c:35
+ //
+ // Which prints the size, alignment, and offset from the SP at function
+ // entry.
+ //
+ // But we also want the machine readable remarks data to be nicely
+ // organized. So we print some additional data as strings for the CLI
+ // output, but maintain more structured data for the YAML.
+ //
+ // For example we store the Offset in YAML as:
+ // ...
+ // - Offset: -8
+ //
+ // But we print it to the CLI as
+ // Offset: [SP-8]
+
+ // Negative offsets will print a leading `-`, so only add `+`
+ std::string Prefix =
+ formatv("\nOffset: [SP{0}", (D.Offset < 0) ? "" : "+").str();
+ Rem << Prefix << ore::NV("Offset", D.Offset)
+ << "], Type: " << ore::NV("Type", getTypeString(D.SlotTy))
+ << ", Align: " << ore::NV("Align", D.Align)
+ << ", Size: " << ore::NV("Size", D.Size);
+ }
+
+ void emitSourceLocRemark(const MachineFunction &MF, const DILocalVariable *N,
+ MachineOptimizationRemarkAnalysis &Rem) {
+ std::string Loc =
+ formatv("{0} @ {1}:{2}", N->getName(), N->getFilename(), N->getLine())
+ .str();
+ Rem << "\n " << ore::NV("DataLoc", Loc);
+ }
+
+ void emitStackFrameLayoutRemarks(MachineFunction &MF,
+ MachineOptimizationRemarkAnalysis &Rem) {
+ const MachineFrameInfo &MFI = MF.getFrameInfo();
+ if (!MFI.hasStackObjects())
+ return;
+
+ // ValOffset is the offset to the local area from the SP at function entry.
+ // To display the true offset from SP, we need to subtract ValOffset from
+ // MFI's ObjectOffset.
+ const TargetFrameLowering *FI = MF.getSubtarget().getFrameLowering();
+ const int ValOffset = (FI ? FI->getOffsetOfLocalArea() : 0);
+
+ LLVM_DEBUG(dbgs() << "getStackProtectorIndex =="
+ << MFI.getStackProtectorIndex() << "\n");
+
+ std::vector<SlotData> SlotInfo;
+ SmallDenseMap<int, int> SlotOffsetMap;
+
+ const unsigned int NumObj = MFI.getNumObjects();
+ SlotInfo.reserve(NumObj);
+ SlotOffsetMap.reserve(NumObj);
+ // initialize slot info
+ for (int Idx = MFI.getObjectIndexBegin(), EndIdx = MFI.getObjectIndexEnd();
+ Idx != EndIdx; ++Idx) {
+ if (MFI.isDeadObjectIndex(Idx))
+ continue;
+ auto &Inserted = SlotInfo.emplace_back(MFI, ValOffset, Idx);
+ SlotOffsetMap[Inserted.Slot] = Inserted.Offset;
+ }
+
+ // sort the ordering, to match the actual layout in memory
+ llvm::sort(SlotInfo);
+
+ SlotDbgMap SlotMap = genSlotDbgMapping(MF);
+
+ for (const SlotData &Info : SlotInfo) {
+ emitStackSlotRemark(MF, Info, Rem);
+ for (const DILocalVariable *N : SlotMap[Info.Slot])
+ emitSourceLocRemark(MF, N, Rem);
+ }
+ }
+
+ // We need to generate a mapping of slots to the values that are stored to
+ // them. This information is lost by the time we need to print out the frame,
+ // so we reconstruct it here by walking the CFG, and generating the mapping.
+ SlotDbgMap genSlotDbgMapping(MachineFunction &MF) {
+ SlotDbgMap SlotDebugMap;
+
+ // add variables to the map
+ for (MachineFunction::VariableDbgInfo &DI : MF.getVariableDbgInfo())
+ SlotDebugMap[DI.Slot].insert(DI.Var);
+
+ // Then add all the spills that have debug data
+ for (MachineBasicBlock &MBB : MF) {
+ for (MachineInstr &MI : MBB) {
+ for (MachineMemOperand *MO : MI.memoperands()) {
+ if (!MO->isStore())
+ continue;
+ auto *FI = dyn_cast_or_null<FixedStackPseudoSourceValue>(
+ MO->getPseudoValue());
+ if (!FI)
+ continue;
+ int FrameIdx = FI->getFrameIndex();
+ SmallVector<MachineInstr *> Dbg;
+ MI.collectDebugValues(Dbg);
+
+ for (MachineInstr *MI : Dbg)
+ SlotDebugMap[FrameIdx].insert(MI->getDebugVariable());
+ }
+ }
+ }
+
+ return SlotDebugMap;
+ }
+};
+
+char StackFrameLayoutAnalysisPass::ID = 0;
+} // namespace
+
+char &llvm::StackFrameLayoutAnalysisPassID = StackFrameLayoutAnalysisPass::ID;
+INITIALIZE_PASS(StackFrameLayoutAnalysisPass, "stack-frame-layout",
+ "Stack Frame Layout", false, false)
+
+namespace llvm {
+/// Returns a newly-created StackFrameLayout pass.
+MachineFunctionPass *createStackFrameLayoutAnalysisPass() {
+ return new StackFrameLayoutAnalysisPass();
+}
+
+} // namespace llvm
diff --git a/llvm/lib/CodeGen/TargetPassConfig.cpp b/llvm/lib/CodeGen/TargetPassConfig.cpp
index 115f266a71506..3127328c363e8 100644
--- a/llvm/lib/CodeGen/TargetPassConfig.cpp
+++ b/llvm/lib/CodeGen/TargetPassConfig.cpp
@@ -1270,6 +1270,8 @@ void TargetPassConfig::addMachinePasses() {
if (!DisableCFIFixup && TM->Options.EnableCFIFixup)
addPass(createCFIFixup());
+ PM->add(createStackFrameLayoutAnalysisPass());
+
// Add passes that directly emit MI after all other MI passes.
addPreEmitPass2();
diff --git a/llvm/test/CodeGen/AArch64/O0-pipeline.ll b/llvm/test/CodeGen/AArch64/O0-pipeline.ll
index 8d4556c6bda1c..f1779086dbaf3 100644
--- a/llvm/test/CodeGen/AArch64/O0-pipeline.ll
+++ b/llvm/test/CodeGen/AArch64/O0-pipeline.ll
@@ -73,6 +73,9 @@
; CHECK-NEXT: Live DEBUG_VALUE analysis
; CHECK-NEXT: Machine Sanitizer Binary Metadata
; CHECK-NEXT: Insert CFI remember/restore state instructions
+; CHECK-NEXT: Lazy Machine Block Frequency Analysis
+; CHECK-NEXT: Machine Optimization Remark Emitter
+; CHECK-NEXT: Stack Frame Layout Analysis
; CHECK-NEXT: Unpack machine instruction bundles
; CHECK-NEXT: Lazy Machine Block Frequency Analysis
; CHECK-NEXT: Machine Optimization Remark Emitter
diff --git a/llvm/test/CodeGen/AArch64/O3-pipeline.ll b/llvm/test/CodeGen/AArch64/O3-pipeline.ll
index 1e77970721f65..704352ee291e7 100644
--- a/llvm/test/CodeGen/AArch64/O3-pipeline.ll
+++ b/llvm/test/CodeGen/AArch64/O3-pipeline.ll
@@ -224,6 +224,9 @@
; CHECK-NEXT: Machine Outliner
; CHECK-NEXT: FunctionPass Manager
; CHECK-NEXT: Insert CFI remember/restore state instructions
+; CHECK-NEXT: Lazy Machine Block Frequency Analysis
+; CHECK-NEXT: Machine Optimization Remark Emitter
+; CHECK-NEXT: Stack Frame Layout Analysis
; CHECK-NEXT: Unpack machine instruction bundles
; CHECK-NEXT: Lazy Machine Block Frequency Analysis
; CHECK-NEXT: Machine Optimization Remark Emitter
diff --git a/llvm/test/CodeGen/AArch64/arm64-opt-remarks-lazy-bfi.ll b/llvm/test/CodeGen/AArch64/arm64-opt-remarks-lazy-bfi.ll
index 755025ecb692f..9295897dd22d3 100644
--- a/llvm/test/CodeGen/AArch64/arm64-opt-remarks-lazy-bfi.ll
+++ b/llvm/test/CodeGen/AArch64/arm64-opt-remarks-lazy-bfi.ll
@@ -38,6 +38,12 @@
; HOTNESS-NEXT: Freeing Pass 'Insert CFI remember/restore state instructions' on Function 'empty_func'
; HOTNESS-NEXT: Executing Pass 'Verify generated machine code'
; HOTNESS-NEXT: Freeing Pass 'Verify generated machine code'
+; HOTNESS-NEXT: Executing Pass 'Lazy Machine Block Frequency Analysis'
+; HOTNESS-NEXT: Executing Pass 'Machine Optimization Remark Emitter'
+; HOTNESS: Executing Pass 'Stack Frame Layout Analysis'
+; HOTNESS-NEXT: Freeing Pass 'Machine Optimization Remark Emitter'
+; HOTNESS-NEXT: Freeing Pass 'Lazy Machine Block Frequency Analysis'
+; HOTNESS-NEXT: Freeing Pass 'Stack Frame Layout Analysis'
; HOTNESS-NEXT: Executing Pass 'Unpack machine instruction bundles'
; HOTNESS-NEXT: Freeing Pass 'Unpack machine instruction bundles'
; HOTNESS-NEXT: Executing Pass 'Verify generated machine code'
@@ -63,6 +69,12 @@
; NO_HOTNESS-NEXT: Freeing Pass 'Insert CFI remember/restore state instructions' on Function 'empty_func'
; NO_HOTNESS-NEXT: Executing Pass 'Verify generated machine code'
; NO_HOTNESS-NEXT: Freeing Pass 'Verify generated machine code'
+; NO_HOTNESS-NEXT: Executing Pass 'Lazy Machine Block Frequency Analysis'
+; NO_HOTNESS-NEXT: Executing Pass 'Machine Optimization Remark Emitter'
+; NO_HOTNESS: Executing Pass 'Stack Frame Layout Analysis'
+; NO_HOTNESS-NEXT: Freeing Pass 'Machine Optimization Remark Emitter'
+; NO_HOTNESS-NEXT: Freeing Pass 'Lazy Machine Block Frequency Analysis'
+; NO_HOTNESS-NEXT: Freeing Pass 'Stack Frame Layout Analysis'
; NO_HOTNESS-NEXT: Executing Pass 'Unpack machine instruction bundles'
; NO_HOTNESS-NEXT: Freeing Pass 'Unpack machine instruction bundles'
; NO_HOTNESS-NEXT: Executing Pass 'Verify generated machine code'
diff --git a/llvm/test/CodeGen/AMDGPU/llc-pipeline.ll b/llvm/test/CodeGen/AMDGPU/llc-pipeline.ll
index 6710668b9ebb2..90088e4ad16c6 100644
--- a/llvm/test/CodeGen/AMDGPU/llc-pipeline.ll
+++ b/llvm/test/CodeGen/AMDGPU/llc-pipeline.ll
@@ -143,6 +143,9 @@
; GCN-O0-NEXT: Register Usage Information Collector Pass
; GCN-O0-NEXT: Live DEBUG_VALUE analysis
; GCN-O0-NEXT: Machine Sanitizer Binary Metadata
+; GCN-O0-NEXT: Lazy Machine Block Frequency Analysis
+; GCN-O0-NEXT: Machine Optimization Remark Emitter
+; GCN-O0-NEXT: Stack Frame Layout Analysis
; GCN-O0-NEXT: Function register usage analysis
; GCN-O0-NEXT: FunctionPass Manager
; GCN-O0-NEXT: Lazy Machine Block Frequency Analysis
@@ -411,6 +414,9 @@
; GCN-O1-NEXT: Register Usage Information Collector Pass
; GCN-O1-NEXT: Live DEBUG_VALUE analysis
; GCN-O1-NEXT: Machine Sanitizer Binary Metadata
+; GCN-O1-NEXT: Lazy Machine Block Frequency Analysis
+; GCN-O1-NEXT: Machine Optimization Remark Emitter
+; GCN-O1-NEXT: Stack Frame Layout Analysis
; GCN-O1-NEXT: Function register usage analysis
; GCN-O1-NEXT: FunctionPass Manager
; GCN-O1-NEXT: Lazy Machine Block Frequency Analysis
@@ -711,6 +717,9 @@
; GCN-O1-OPTS-NEXT: Register Usage Information Collector Pass
; GCN-O1-OPTS-NEXT: Live DEBUG_VALUE analysis
; GCN-O1-OPTS-NEXT: Machine Sanitizer Binary Metadata
+; GCN-O1-OPTS-NEXT: Lazy Machine Block Frequency Analysis
+; GCN-O1-OPTS-NEXT: Machine Optimization Remark Emitter
+; GCN-O1-OPTS-NEXT: Stack Frame Layout Analysis
; GCN-O1-OPTS-NEXT: Function register usage analysis
; GCN-O1-OPTS-NEXT: FunctionPass Manager
; GCN-O1-OPTS-NEXT: Lazy Machine Block Frequency Analysis
@@ -1014,6 +1023,9 @@
; GCN-O2-NEXT: Register Usage Information Collector Pass
; GCN-O2-NEXT: Live DEBUG_VALUE analysis
; GCN-O2-NEXT: Machine Sanitizer Binary Metadata
+; GCN-O2-NEXT: Lazy Machine Block Frequency Analysis
+; GCN-O2-NEXT: Machine Optimization Remark Emitter
+; GCN-O2-NEXT: Stack Frame Layout Analysis
; GCN-O2-NEXT: Function register usage analysis
; GCN-O2-NEXT: FunctionPass Manager
; GCN-O2-NEXT: Lazy Machine Block Frequency Analysis
@@ -1327,6 +1339,9 @@
; GCN-O3-NEXT: Register Usage Information Collector Pass
; GCN-O3-NEXT: Live DEBUG_VALUE analysis
; GCN-O3-NEXT: Machine Sanitizer Binary Metadata
+; GCN-O3-NEXT: Lazy Machine Block Frequency Analysis
+; GCN-O3-NEXT: Machine Optimization Remark Emitter
+; GCN-O3-NEXT: Stack Frame Layout Analysis
; GCN-O3-NEXT: Function register usage analysis
; GCN-O3-NEXT: FunctionPass Manager
; GCN-O3-NEXT: Lazy Machine Block Frequency Analysis
diff --git a/llvm/test/CodeGen/ARM/O3-pipeline.ll b/llvm/test/CodeGen/ARM/O3-pipeline.ll
index 2031158017d6b..24c47c2674a5f 100644
--- a/llvm/test/CodeGen/ARM/O3-pipeline.ll
+++ b/llvm/test/CodeGen/ARM/O3-pipeline.ll
@@ -194,6 +194,9 @@
; CHECK-NEXT: Machine Sanitizer Binary Metadata
; CHECK-NEXT: Machine Outliner
; CHECK-NEXT: FunctionPass Manager
+; CHECK-NEXT: Lazy Machine Block Frequency Analysis
+; CHECK-NEXT: Machine Optimization Remark Emitter
+; CHECK-NEXT: Stack Frame Layout Analysis
; CHECK-NEXT: ReachingDefAnalysis
; CHECK-NEXT: ARM fix for Cortex-A57 AES Erratum 1742098
; CHECK-NEXT: ARM Branch Targets
diff --git a/llvm/test/CodeGen/ARM/stack-frame-layout-remarks.ll b/llvm/test/CodeGen/ARM/stack-frame-layout-remarks.ll
new file mode 100644
index 0000000000000..ead889f300660
--- /dev/null
+++ b/llvm/test/CodeGen/ARM/stack-frame-layout-remarks.ll
@@ -0,0 +1,329 @@
+; Test remark output for stack-frame-layout
+
+; ensure basic output works
+; RUN: llc -mtriple=arm-eabi -O1 -pass-remarks-analysis=stack-frame-layout < %s 2>&1 >/dev/null | FileCheck %s
+
+; check additional slots are displayed when stack is not optimized
+; RUN: llc -mtriple=arm-eabi -O0 -pass-remarks-analysis=stack-frame-layout < %s 2>&1 >/dev/null | FileCheck %s --check-prefix=NO_COLORING
+
+; check more complex cases
+; RUN: llc %s -pass-remarks-analysis=stack-frame-layout -o /dev/null --march=arm -mcpu=cortex-m1 2>&1 | FileCheck %s --check-prefix=BOTH --check-prefix=DEBUG
+
+; check output without debug info
+; RUN: opt %s -passes=strip -S | llc -pass-remarks-analysis=stack-frame-layout -o /dev/null --march=arm -mcpu=cortex-m1 2>&1 | FileCheck %s --check-prefix=BOTH --check-prefix=STRIPPED
+
+target triple = "x86_64-unknown-linux-gnu"
+
+ at .str = private unnamed_addr constant [4 x i8] c"%s\0A\00", align 1
+declare i32 @printf(ptr, ...)
+
+; CHECK: Function: stackSizeWarning
+; CHECK: [SP-4]{{.*}}Spill{{.*}}4{{.*}}4
+; CHECK: [SP-96]{{.*}}16{{.*}}80
+; CHECK: buffer @ frame-diags.c:30
+; NO_COLORING: [SP-176]{{.*}}16{{.*}}80
+; CHECK: buffer2 @ frame-diags.c:33
+
+; BOTH: Function: stackSizeWarning
+; BOTH: [SP-4]{{.*}}Spill{{.*}}4{{.*}}4
+; BOTH: [SP-8]{{.*}}Spill{{.*}}4{{.*}}4
+; BOTH: [SP-12]{{.*}}Spill{{.*}}4{{.*}}4
+; BOTH: [SP-16]{{.*}}Spill{{.*}}4{{.*}}4
+; BOTH: [SP-96]{{.*}}16{{.*}}80
+; DEBUG: buffer @ frame-diags.c:30
+; STRIPPED-NOT: buffer @ frame-diags.c:30
+; BOTH: [SP-176]{{.*}}16{{.*}}80
+; DEBUG: buffer2 @ frame-diags.c:33
+; STRIPPED-NOT: buffer2 @ frame-diags.c:33
+define void @stackSizeWarning() {
+entry:
+ %buffer = alloca [80 x i8], align 16
+ %buffer2 = alloca [80 x i8], align 16
+ call void @llvm.dbg.declare(metadata ptr %buffer, metadata !25, metadata !DIExpression()), !dbg !39
+ call void @llvm.dbg.declare(metadata ptr %buffer2, metadata !31, metadata !DIExpression()), !dbg !40
+ ret void
+}
+
+; Function Attrs: nocallback nofree nosync nounwind readnone speculatable willreturn
+declare void @llvm.dbg.declare(metadata, metadata, metadata) #0
+
+; BOTH: Function: cleanup_array
+; BOTH: [SP-8]{{.+}}8{{.+}}4
+; DEBUG: a @ dot.c:13
+; STRIPPED-NOT: a @ dot.c:13
+define void @cleanup_array(ptr %0) #1 {
+ %2 = alloca ptr, align 8
+ store ptr %0, ptr %2, align 8
+ call void @llvm.dbg.declare(metadata ptr %2, metadata !41, metadata !DIExpression()), !dbg !46
+ ret void
+}
+
+; BOTH: Function: cleanup_result
+; BOTH: [SP-8]{{.+}}8{{.+}}4
+; DEBUG: res @ dot.c:21
+; STRIPPED-NOT: res @ dot.c:21
+define void @cleanup_result(ptr %0) #1 {
+ %2 = alloca ptr, align 8
+ store ptr %0, ptr %2, align 8
+ call void @llvm.dbg.declare(metadata ptr %2, metadata !47, metadata !DIExpression()), !dbg !51
+ ret void
+}
+
+; BOTH: Function: do_work
+; BOTH: [SP-4]{{.+}}4{{.+}}4
+; BOTH: [SP-8]{{.+}}8{{.+}}4
+; DEBUG: A @ dot.c:32
+; STRIPPED-NOT: A @ dot.c:32
+; BOTH: [SP-16]{{.+}}8{{.+}}4
+; DEBUG: B @ dot.c:32
+; STRIPPED-NOT: B @ dot.c:32
+; BOTH: [SP-24]{{.+}}8{{.+}}4
+; DEBUG: out @ dot.c:32
+; STRIPPED-NOT: out @ dot.c:32
+; BOTH: [SP-28]{{.+}}4{{.+}}4
+; DEBUG: len @ dot.c:37
+; STRIPPED-NOT: len @ dot.c:37
+; BOTH: [SP-32]{{.+}}8{{.+}}4
+; DEBUG: AB @ dot.c:38
+; STRIPPED-NOT: AB @ dot.c:38
+; BOTH: [SP-36]{{.+}}4{{.+}}4
+; DEBUG: sum @ dot.c:54
+; STRIPPED-NOT: sum @ dot.c:54
+; BOTH: [SP-40]{{.+}}4{{.+}}4
+; DEBUG: i @ dot.c:55
+; STRIPPED-NOT: i @ dot.c:55
+define i32 @do_work(ptr %0, ptr %1, ptr %2) #1 {
+ %4 = alloca i32, align 4
+ %5 = alloca ptr, align 8
+ %6 = alloca ptr, align 8
+ %7 = alloca ptr, align 8
+ %8 = alloca i32, align 4
+ %9 = alloca ptr, align 8
+ %10 = alloca i32, align 4
+ %11 = alloca i32, align 4
+ store ptr %0, ptr %5, align 8
+ call void @llvm.dbg.declare(metadata ptr %5, metadata !52, metadata !DIExpression()), !dbg !56
+ call void @llvm.dbg.declare(metadata ptr %6, metadata !57, metadata !DIExpression()), !dbg !58
+ store ptr %2, ptr %7, align 8
+ call void @llvm.dbg.declare(metadata ptr %7, metadata !59, metadata !DIExpression()), !dbg !60
+ call void @llvm.dbg.declare(metadata ptr %8, metadata !61, metadata !DIExpression()), !dbg !63
+ call void @llvm.dbg.declare(metadata ptr %9, metadata !64, metadata !DIExpression()), !dbg !65
+ store ptr null, ptr %9, align 8
+ store ptr null, ptr null, align 8
+ store i32 0, ptr %9, align 8
+ %12 = load i32, ptr %8, align 4
+ store i32 %12, ptr null, align 8
+ call void @llvm.dbg.declare(metadata ptr %10, metadata !66, metadata !DIExpression()), !dbg !67
+ call void @llvm.dbg.declare(metadata ptr %11, metadata !68, metadata !DIExpression()), !dbg !70
+ store i32 0, ptr %11, align 4
+ br label %13
+
+13: ; preds = %16, %3
+ %14 = load i32, ptr %11, align 4
+ %15 = icmp slt i32 %14, 0
+ br i1 %15, label %16, label %18
+
+16: ; preds = %13
+ %17 = load i32, ptr %6, align 4
+ store i32 %17, ptr null, align 4
+ br label %13
+
+18: ; preds = %13
+ store i32 0, ptr %4, align 4
+ ret i32 0
+}
+
+; BOTH: Function: gen_array
+; BOTH: [SP-8]{{.+}}8{{.+}}4
+; BOTH: [SP-12]{{.+}}4{{.+}}4
+; DEBUG: size @ dot.c:62
+; STRIPPED-NOT: size @ dot.c:65
+; BOTH: [SP-16]{{.+}}8{{.+}}4
+; DEBUG: res @ dot.c:65
+; STRIPPED-NOT: res @ dot.c:65
+; BOTH: [SP-20]{{.+}}4{{.*}}4
+; DEBUG: i @ dot.c:69
+; STRIPPED-NOT: i @ dot.c:69
+define ptr @gen_array(i32 %0) #1 {
+ %2 = alloca ptr, align 8
+ %3 = alloca i32, align 4
+ %4 = alloca ptr, align 8
+ %5 = alloca i32, align 4
+ store i32 %0, ptr %3, align 4
+ call void @llvm.dbg.declare(metadata ptr %3, metadata !71, metadata !DIExpression()), !dbg !75
+ call void @llvm.dbg.declare(metadata ptr %4, metadata !76, metadata !DIExpression()), !dbg !77
+ store ptr null, ptr %4, align 8
+ call void @llvm.dbg.declare(metadata ptr %5, metadata !78, metadata !DIExpression()), !dbg !80
+ store i32 0, ptr %5, align 4
+ ret ptr null
+}
+
+
+; BOTH: Function: caller
+; BOTH: [SP-4]{{.*}}Spill{{.*}}4{{.*}}4
+; BOTH: [SP-8]{{.*}}Spill{{.*}}4{{.*}}4
+; BOTH: [SP-12]{{.*}}Spill{{.*}}4{{.*}}4
+; BOTH: [SP-16]{{.*}}Spill{{.*}}4{{.*}}4
+; BOTH: [SP-20]{{.*}}4{{.*}}4
+; BOTH: [SP-24]{{.*}}4{{.*}}4
+; DEBUG: size @ dot.c:77
+; STRIPPED-NOT: size @ dot.c:77
+; BOTH: [SP-32]{{.*}}8{{.*}}4
+; DEBUG: A @ dot.c:78
+; STRIPPED-NOT: A @ dot.c:78
+; BOTH: [SP-40]{{.*}}8{{.*}}4
+; DEBUG: B @ dot.c:79
+; STRIPPED-NOT: B @ dot.c:79
+; BOTH: [SP-48]{{.*}}8{{.*}}4
+; DEBUG: res @ dot.c:80
+; STRIPPED-NOT: res @ dot.c:80
+; BOTH: [SP-52]{{.*}}4{{.*}}4
+; DEBUG: ret @ dot.c:81
+; STRIPPED-NOT: ret @ dot.c:81
+; BOTH: [SP-56]{{.*}}4{{.*}}4
+; DEBUG: err @ dot.c:83
+; STRIPPED-NOT: err @ dot.c:83
+define i32 @caller() #1 {
+ %1 = alloca i32, align 4
+ %2 = alloca i32, align 4
+ %3 = alloca ptr, align 8
+ %4 = alloca ptr, align 8
+ %5 = alloca ptr, align 8
+ %6 = alloca i32, align 4
+ %7 = alloca i32, align 4
+ call void @llvm.dbg.declare(metadata ptr %2, metadata !81, metadata !DIExpression()), !dbg !85
+ call void @llvm.dbg.declare(metadata ptr %3, metadata !86, metadata !DIExpression()), !dbg !87
+ call void @llvm.dbg.declare(metadata ptr %4, metadata !88, metadata !DIExpression()), !dbg !89
+ store ptr null, ptr %4, align 8
+ call void @llvm.dbg.declare(metadata ptr %5, metadata !90, metadata !DIExpression()), !dbg !91
+ call void @llvm.dbg.declare(metadata ptr %6, metadata !92, metadata !DIExpression()), !dbg !93
+ call void @llvm.dbg.declare(metadata ptr %7, metadata !94, metadata !DIExpression()), !dbg !95
+ %8 = call i32 @do_work(ptr %3, ptr null, ptr null)
+ store i32 0, ptr %6, align 4
+ store i32 0, ptr %1, align 4
+ call void @cleanup_result(ptr %5)
+ ret i32 0
+}
+
+; test29b: An array of [5 x i8] and a requested ssp-buffer-size of 5.
+; Requires protector.
+; Function Attrs: ssp stack-protector-buffer-size=5
+; BOTH: Function: test29b
+; BOTH: [SP-4]{{.+}}Spill{{.*}}4{{.+}}4
+; BOTH: [SP-8]{{.+}}Spill{{.*}}4{{.+}}4
+; BOTH: [SP-12]{{.+}}Protector{{.*}}4{{.+}}4
+; BOTH: [SP-20]{{.+}}4{{.+}}5
+define i32 @test29b() #2 {
+entry:
+ %test = alloca [5 x i8], align 1
+ %call = call i32 (ptr, ...) @printf(ptr @.str, ptr %test)
+ ret i32 %call
+}
+
+
+; uselistorder directives
+uselistorder ptr @llvm.dbg.declare, { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 19, 18 }
+
+attributes #0 = { nocallback nofree nosync nounwind readnone speculatable willreturn }
+attributes #1 = { "frame-pointer"="all" }
+attributes #2 = { ssp "stack-protector-buffer-size"="5" "frame-pointer"="all" }
+
+!llvm.dbg.cu = !{!0, !2}
+!llvm.module.flags = !{!18, !19, !20, !21, !22, !23, !24}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
+!1 = !DIFile(filename: "frame-diags.c", directory: "")
+!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, retainedTypes: !4, splitDebugInlining: false, nameTableKind: None)
+!3 = !DIFile(filename: "dot.c", directory: "")
+!4 = !{!5, !6, !10, !13}
+!5 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64)
+!6 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !7, size: 64)
+!7 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Array", file: !3, line: 3, size: 128, elements: !8)
+!8 = !{!9, !12}
+!9 = !DIDerivedType(tag: DW_TAG_member, name: "data", scope: !7, file: !3, line: 4, baseType: !10, size: 64)
+!10 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !11, size: 64)
+!11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!12 = !DIDerivedType(tag: DW_TAG_member, name: "size", scope: !7, file: !3, line: 5, baseType: !11, size: 32, offset: 64)
+!13 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !14, size: 64)
+!14 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Result", file: !3, line: 8, size: 128, elements: !15)
+!15 = !{!16, !17}
+!16 = !DIDerivedType(tag: DW_TAG_member, name: "data", scope: !14, file: !3, line: 9, baseType: !6, size: 64)
+!17 = !DIDerivedType(tag: DW_TAG_member, name: "sum", scope: !14, file: !3, line: 10, baseType: !11, size: 32, offset: 64)
+!18 = !{i32 7, !"Dwarf Version", i32 5}
+!19 = !{i32 2, !"Debug Info Version", i32 3}
+!20 = !{i32 1, !"wchar_size", i32 4}
+!21 = !{i32 8, !"PIC Level", i32 2}
+!22 = !{i32 7, !"PIE Level", i32 2}
+!23 = !{i32 7, !"uwtable", i32 2}
+!24 = !{i32 7, !"frame-pointer", i32 2}
+!25 = !DILocalVariable(name: "buffer", scope: !26, file: !1, line: 30, type: !32)
+!26 = distinct !DILexicalBlock(scope: !27, file: !1, line: 29, column: 3)
+!27 = distinct !DISubprogram(name: "stackSizeWarning", scope: !1, file: !1, line: 28, type: !28, scopeLine: 28, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !30)
+!28 = !DISubroutineType(types: !29)
+!29 = !{null}
+!30 = !{!25, !31, !36, !37}
+!31 = !DILocalVariable(name: "buffer2", scope: !27, file: !1, line: 33, type: !32)
+!32 = !DICompositeType(tag: DW_TAG_array_type, baseType: !33, size: 640, elements: !34)
+!33 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
+!34 = !{!35}
+!35 = !DISubrange(count: 80)
+!36 = !DILocalVariable(name: "a", scope: !27, file: !1, line: 34, type: !11)
+!37 = !DILocalVariable(name: "b", scope: !27, file: !1, line: 35, type: !38)
+!38 = !DIBasicType(name: "long", size: 64, encoding: DW_ATE_signed)
+!39 = !DILocation(line: 30, column: 10, scope: !26)
+!40 = !DILocation(line: 33, column: 8, scope: !27)
+!41 = !DILocalVariable(name: "a", arg: 1, scope: !42, file: !3, line: 13, type: !6)
+!42 = distinct !DISubprogram(name: "cleanup_array", scope: !3, file: !3, line: 13, type: !43, scopeLine: 13, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !45)
+!43 = !DISubroutineType(types: !44)
+!44 = !{null, !6}
+!45 = !{}
+!46 = !DILocation(line: 13, column: 34, scope: !42)
+!47 = !DILocalVariable(name: "res", arg: 1, scope: !48, file: !3, line: 21, type: !13)
+!48 = distinct !DISubprogram(name: "cleanup_result", scope: !3, file: !3, line: 21, type: !49, scopeLine: 21, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !45)
+!49 = !DISubroutineType(types: !50)
+!50 = !{null, !13}
+!51 = !DILocation(line: 21, column: 36, scope: !48)
+!52 = !DILocalVariable(name: "A", arg: 1, scope: !53, file: !3, line: 32, type: !6)
+!53 = distinct !DISubprogram(name: "do_work", scope: !3, file: !3, line: 32, type: !54, scopeLine: 32, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !45)
+!54 = !DISubroutineType(types: !55)
+!55 = !{!11, !6, !6, !13}
+!56 = !DILocation(line: 32, column: 27, scope: !53)
+!57 = !DILocalVariable(name: "B", arg: 2, scope: !53, file: !3, line: 32, type: !6)
+!58 = !DILocation(line: 32, column: 44, scope: !53)
+!59 = !DILocalVariable(name: "out", arg: 3, scope: !53, file: !3, line: 32, type: !13)
+!60 = !DILocation(line: 32, column: 62, scope: !53)
+!61 = !DILocalVariable(name: "len", scope: !53, file: !3, line: 37, type: !62)
+!62 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !11)
+!63 = !DILocation(line: 37, column: 13, scope: !53)
+!64 = !DILocalVariable(name: "AB", scope: !53, file: !3, line: 38, type: !6)
+!65 = !DILocation(line: 38, column: 17, scope: !53)
+!66 = !DILocalVariable(name: "sum", scope: !53, file: !3, line: 54, type: !11)
+!67 = !DILocation(line: 54, column: 7, scope: !53)
+!68 = !DILocalVariable(name: "i", scope: !69, file: !3, line: 55, type: !11)
+!69 = distinct !DILexicalBlock(scope: !53, file: !3, line: 55, column: 3)
+!70 = !DILocation(line: 55, column: 12, scope: !69)
+!71 = !DILocalVariable(name: "size", arg: 1, scope: !72, file: !3, line: 62, type: !11)
+!72 = distinct !DISubprogram(name: "gen_array", scope: !3, file: !3, line: 62, type: !73, scopeLine: 62, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !45)
+!73 = !DISubroutineType(types: !74)
+!74 = !{!6, !11}
+!75 = !DILocation(line: 62, column: 29, scope: !72)
+!76 = !DILocalVariable(name: "res", scope: !72, file: !3, line: 65, type: !6)
+!77 = !DILocation(line: 65, column: 17, scope: !72)
+!78 = !DILocalVariable(name: "i", scope: !79, file: !3, line: 69, type: !11)
+!79 = distinct !DILexicalBlock(scope: !72, file: !3, line: 69, column: 3)
+!80 = !DILocation(line: 69, column: 12, scope: !79)
+!81 = !DILocalVariable(name: "size", scope: !82, file: !3, line: 77, type: !62)
+!82 = distinct !DISubprogram(name: "caller", scope: !3, file: !3, line: 76, type: !83, scopeLine: 76, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !45)
+!83 = !DISubroutineType(types: !84)
+!84 = !{!11}
+!85 = !DILocation(line: 77, column: 13, scope: !82)
+!86 = !DILocalVariable(name: "A", scope: !82, file: !3, line: 78, type: !6)
+!87 = !DILocation(line: 78, column: 17, scope: !82)
+!88 = !DILocalVariable(name: "B", scope: !82, file: !3, line: 79, type: !6)
+!89 = !DILocation(line: 79, column: 17, scope: !82)
+!90 = !DILocalVariable(name: "res", scope: !82, file: !3, line: 80, type: !13)
+!91 = !DILocation(line: 80, column: 18, scope: !82)
+!92 = !DILocalVariable(name: "ret", scope: !82, file: !3, line: 81, type: !11)
+!93 = !DILocation(line: 81, column: 7, scope: !82)
+!94 = !DILocalVariable(name: "err", scope: !82, file: !3, line: 83, type: !11)
+!95 = !DILocation(line: 83, column: 7, scope: !82)
diff --git a/llvm/test/CodeGen/Generic/llc-start-stop.ll b/llvm/test/CodeGen/Generic/llc-start-stop.ll
index db5146d4cba5c..b02472473a00c 100644
--- a/llvm/test/CodeGen/Generic/llc-start-stop.ll
+++ b/llvm/test/CodeGen/Generic/llc-start-stop.ll
@@ -8,6 +8,9 @@
; STOP-AFTER: Dominator Tree Construction
; STOP-AFTER: Loop Strength Reduction
; STOP-AFTER-NEXT: Verify generated machine code
+; STOP-AFTER-NEXT: Lazy Machine Block Frequency Analysis
+; STOP-AFTER-NEXT: Machine Optimization Remark Emitter
+; STOP-AFTER-NEXT: Stack Frame Layout Analysis
; STOP-AFTER-NEXT: MIR Printing Pass
; RUN: llc < %s -debug-pass=Structure -stop-before=loop-reduce -o /dev/null 2>&1 | FileCheck %s -check-prefix=STOP-BEFORE
diff --git a/llvm/test/CodeGen/LoongArch/O0-pipeline.ll b/llvm/test/CodeGen/LoongArch/O0-pipeline.ll
index df7c7b54033d5..744980b74ea8c 100644
--- a/llvm/test/CodeGen/LoongArch/O0-pipeline.ll
+++ b/llvm/test/CodeGen/LoongArch/O0-pipeline.ll
@@ -64,6 +64,9 @@
; CHECK-NEXT: StackMap Liveness Analysis
; CHECK-NEXT: Live DEBUG_VALUE analysis
; CHECK-NEXT: Machine Sanitizer Binary Metadata
+; CHECK-NEXT: Lazy Machine Block Frequency Analysis
+; CHECK-NEXT: Machine Optimization Remark Emitter
+; CHECK-NEXT: Stack Frame Layout Analysis
; CHECK-NEXT: LoongArch atomic pseudo instruction expansion pass
; CHECK-NEXT: Lazy Machine Block Frequency Analysis
; CHECK-NEXT: Machine Optimization Remark Emitter
diff --git a/llvm/test/CodeGen/LoongArch/opt-pipeline.ll b/llvm/test/CodeGen/LoongArch/opt-pipeline.ll
index e9349b873a8b9..4c62c40eddf8d 100644
--- a/llvm/test/CodeGen/LoongArch/opt-pipeline.ll
+++ b/llvm/test/CodeGen/LoongArch/opt-pipeline.ll
@@ -160,6 +160,9 @@
; CHECK-NEXT: StackMap Liveness Analysis
; CHECK-NEXT: Live DEBUG_VALUE analysis
; CHECK-NEXT: Machine Sanitizer Binary Metadata
+; CHECK-NEXT: Lazy Machine Block Frequency Analysis
+; CHECK-NEXT: Machine Optimization Remark Emitter
+; CHECK-NEXT: Stack Frame Layout Analysis
; CHECK-NEXT: LoongArch atomic pseudo instruction expansion pass
; CHECK-NEXT: Lazy Machine Block Frequency Analysis
; CHECK-NEXT: Machine Optimization Remark Emitter
diff --git a/llvm/test/CodeGen/M68k/pipeline.ll b/llvm/test/CodeGen/M68k/pipeline.ll
index 93c1e102ebfaf..bc80b763351f7 100644
--- a/llvm/test/CodeGen/M68k/pipeline.ll
+++ b/llvm/test/CodeGen/M68k/pipeline.ll
@@ -134,5 +134,6 @@
; CHECK-NEXT: Machine Sanitizer Binary Metadata
; CHECK-NEXT: Lazy Machine Block Frequency Analysis
; CHECK-NEXT: Machine Optimization Remark Emitter
+; CHECK-NEXT: Stack Frame Layout Analysis
; CHECK-NEXT: M68k Assembly Printer
; CHECK-NEXT: Free MachineFunction
diff --git a/llvm/test/CodeGen/PowerPC/O0-pipeline.ll b/llvm/test/CodeGen/PowerPC/O0-pipeline.ll
index 08340b9f95f9a..2f37b69bc3ef9 100644
--- a/llvm/test/CodeGen/PowerPC/O0-pipeline.ll
+++ b/llvm/test/CodeGen/PowerPC/O0-pipeline.ll
@@ -63,6 +63,9 @@
; CHECK-NEXT: StackMap Liveness Analysis
; CHECK-NEXT: Live DEBUG_VALUE analysis
; CHECK-NEXT: Machine Sanitizer Binary Metadata
+; CHECK-NEXT: Lazy Machine Block Frequency Analysis
+; CHECK-NEXT: Machine Optimization Remark Emitter
+; CHECK-NEXT: Stack Frame Layout Analysis
; CHECK-NEXT: PowerPC Expand Atomic
; CHECK-NEXT: PowerPC Branch Selector
; CHECK-NEXT: Lazy Machine Block Frequency Analysis
diff --git a/llvm/test/CodeGen/PowerPC/O3-pipeline.ll b/llvm/test/CodeGen/PowerPC/O3-pipeline.ll
index b4419e629bd2a..c6445e345de3d 100644
--- a/llvm/test/CodeGen/PowerPC/O3-pipeline.ll
+++ b/llvm/test/CodeGen/PowerPC/O3-pipeline.ll
@@ -209,6 +209,9 @@
; CHECK-NEXT: StackMap Liveness Analysis
; CHECK-NEXT: Live DEBUG_VALUE analysis
; CHECK-NEXT: Machine Sanitizer Binary Metadata
+; CHECK-NEXT: Lazy Machine Block Frequency Analysis
+; CHECK-NEXT: Machine Optimization Remark Emitter
+; CHECK-NEXT: Stack Frame Layout Analysis
; CHECK-NEXT: PowerPC Expand Atomic
; CHECK-NEXT: PowerPC Branch Selector
; CHECK-NEXT: Lazy Machine Block Frequency Analysis
diff --git a/llvm/test/CodeGen/RISCV/O0-pipeline.ll b/llvm/test/CodeGen/RISCV/O0-pipeline.ll
index beb2ace4b809e..befa17be8c0c7 100644
--- a/llvm/test/CodeGen/RISCV/O0-pipeline.ll
+++ b/llvm/test/CodeGen/RISCV/O0-pipeline.ll
@@ -58,6 +58,9 @@
; CHECK-NEXT: StackMap Liveness Analysis
; CHECK-NEXT: Live DEBUG_VALUE analysis
; CHECK-NEXT: Machine Sanitizer Binary Metadata
+; CHECK-NEXT: Lazy Machine Block Frequency Analysis
+; CHECK-NEXT: Machine Optimization Remark Emitter
+; CHECK-NEXT: Stack Frame Layout Analysis
; CHECK-NEXT: RISCV pseudo instruction expansion pass
; CHECK-NEXT: RISCV atomic pseudo instruction expansion pass
; CHECK-NEXT: Lazy Machine Block Frequency Analysis
diff --git a/llvm/test/CodeGen/RISCV/O3-pipeline.ll b/llvm/test/CodeGen/RISCV/O3-pipeline.ll
index 76173bf8bc92d..5a0f78bc125cd 100644
--- a/llvm/test/CodeGen/RISCV/O3-pipeline.ll
+++ b/llvm/test/CodeGen/RISCV/O3-pipeline.ll
@@ -169,6 +169,9 @@
; CHECK-NEXT: Machine Sanitizer Binary Metadata
; CHECK-NEXT: Machine Outliner
; CHECK-NEXT: FunctionPass Manager
+; CHECK-NEXT: Lazy Machine Block Frequency Analysis
+; CHECK-NEXT: Machine Optimization Remark Emitter
+; CHECK-NEXT: Stack Frame Layout Analysis
; CHECK-NEXT: RISCV pseudo instruction expansion pass
; CHECK-NEXT: RISCV atomic pseudo instruction expansion pass
; CHECK-NEXT: Lazy Machine Block Frequency Analysis
diff --git a/llvm/test/CodeGen/X86/O0-pipeline.ll b/llvm/test/CodeGen/X86/O0-pipeline.ll
index 959add648245f..3e7bb90d46239 100644
--- a/llvm/test/CodeGen/X86/O0-pipeline.ll
+++ b/llvm/test/CodeGen/X86/O0-pipeline.ll
@@ -73,6 +73,9 @@
; CHECK-NEXT: StackMap Liveness Analysis
; CHECK-NEXT: Live DEBUG_VALUE analysis
; CHECK-NEXT: Machine Sanitizer Binary Metadata
+; CHECK-NEXT: Lazy Machine Block Frequency Analysis
+; CHECK-NEXT: Machine Optimization Remark Emitter
+; CHECK-NEXT: Stack Frame Layout Analysis
; CHECK-NEXT: X86 Speculative Execution Side Effect Suppression
; CHECK-NEXT: X86 Indirect Thunks
; CHECK-NEXT: X86 Return Thunks
diff --git a/llvm/test/CodeGen/X86/opt-pipeline.ll b/llvm/test/CodeGen/X86/opt-pipeline.ll
index 144c2da7afb29..2ebe9ee0f309d 100644
--- a/llvm/test/CodeGen/X86/opt-pipeline.ll
+++ b/llvm/test/CodeGen/X86/opt-pipeline.ll
@@ -208,6 +208,9 @@
; CHECK-NEXT: StackMap Liveness Analysis
; CHECK-NEXT: Live DEBUG_VALUE analysis
; CHECK-NEXT: Machine Sanitizer Binary Metadata
+; CHECK-NEXT: Lazy Machine Block Frequency Analysis
+; CHECK-NEXT: Machine Optimization Remark Emitter
+; CHECK-NEXT: Stack Frame Layout Analysis
; CHECK-NEXT: X86 Speculative Execution Side Effect Suppression
; CHECK-NEXT: X86 Indirect Thunks
; CHECK-NEXT: X86 Return Thunks
diff --git a/llvm/test/CodeGen/X86/stack-frame-layout-remarks.ll b/llvm/test/CodeGen/X86/stack-frame-layout-remarks.ll
new file mode 100644
index 0000000000000..d32a37efcb5a4
--- /dev/null
+++ b/llvm/test/CodeGen/X86/stack-frame-layout-remarks.ll
@@ -0,0 +1,315 @@
+; Test remark output for stack-frame-layout
+
+; ensure basic output works
+; RUN: llc -mcpu=corei7 -O1 -pass-remarks-analysis=stack-frame-layout < %s 2>&1 >/dev/null | FileCheck %s
+
+; check additional slots are displayed when stack is not optimized
+; RUN: llc -mcpu=corei7 -O0 -pass-remarks-analysis=stack-frame-layout < %s 2>&1 >/dev/null | FileCheck %s --check-prefix=NO_COLORING
+
+; check more complex cases
+; RUN: llc %s -pass-remarks-analysis=stack-frame-layout -o /dev/null --march=x86 -mcpu=i386 2>&1 | FileCheck %s --check-prefix=BOTH --check-prefix=DEBUG
+
+; check output without debug info
+; RUN: opt %s -passes=strip -S | llc -pass-remarks-analysis=stack-frame-layout -o /dev/null --march=x86 -mcpu=i386 2>&1 | FileCheck %s --check-prefix=BOTH --check-prefix=STRIPPED
+
+target triple = "x86_64-unknown-linux-gnu"
+
+ at .str = private unnamed_addr constant [4 x i8] c"%s\0A\00", align 1
+declare i32 @printf(ptr, ...)
+
+; CHECK: Function: stackSizeWarning
+; CHECK: Offset: [SP-88], Type: Variable, Align: 16, Size: 80
+; CHECK: buffer @ frame-diags.c:30
+; NO_COLORING: Offset: [SP-168], Type: Variable, Align: 16, Size: 80
+; CHECK: buffer2 @ frame-diags.c:33
+define void @stackSizeWarning() {
+entry:
+ %buffer = alloca [80 x i8], align 16
+ %buffer2 = alloca [80 x i8], align 16
+ call void @llvm.dbg.declare(metadata ptr %buffer, metadata !25, metadata !DIExpression()), !dbg !39
+ call void @llvm.dbg.declare(metadata ptr %buffer2, metadata !31, metadata !DIExpression()), !dbg !40
+ ret void
+}
+
+; Function Attrs: nocallback nofree nosync nounwind readnone speculatable willreturn
+declare void @llvm.dbg.declare(metadata, metadata, metadata) #0
+
+; BOTH: Function: cleanup_array
+; BOTH-Next: Offset: [SP+4], Type: Protector, Align: 16, Size: 4
+; DEBUG: a @ dot.c:13
+; STRIPPED-NOT: a @ dot.c:13
+; BOTH: Offset: [SP-4], Type: Spill, Align: 8, Size: 4
+define void @cleanup_array(ptr %0) #1 {
+ %2 = alloca ptr, align 8
+ store ptr %0, ptr %2, align 8
+ call void @llvm.dbg.declare(metadata ptr %2, metadata !41, metadata !DIExpression()), !dbg !46
+ ret void
+}
+
+; BOTH: Function: cleanup_result
+; BOTH: Offset: [SP+4], Type: Protector, Align: 16, Size: 4
+; DEBUG: res @ dot.c:21
+; STRIPPED-NOT: res @ dot.c:21
+; BOTH: Offset: [SP-4], Type: Spill, Align: 8, Size: 4
+define void @cleanup_result(ptr %0) #1 {
+ %2 = alloca ptr, align 8
+ store ptr %0, ptr %2, align 8
+ call void @llvm.dbg.declare(metadata ptr %2, metadata !47, metadata !DIExpression()), !dbg !51
+ ret void
+}
+
+; BOTH: Function: do_work
+; BOTH: Offset: [SP+12], Type: Variable, Align: 8, Size: 4
+; DEBUG: out @ dot.c:32
+; STRIPPED-NOT: out @ dot.c:32
+; BOTH: Offset: [SP+8], Type: Variable, Align: 4, Size: 4
+; BOTH: Offset: [SP+4], Type: Protector, Align: 16, Size: 4
+; DEBUG: A @ dot.c:32
+; STRIPPED-NOT: A @ dot.c:32
+; BOTH: Offset: [SP-4], Type: Spill, Align: 8, Size: 4
+; BOTH: Offset: [SP-12], Type: Variable, Align: 8, Size: 4
+; DEBUG: AB @ dot.c:38
+; STRIPPED-NOT: AB @ dot.c:38
+; BOTH: Offset: [SP-16], Type: Variable, Align: 4, Size: 4
+; DEBUG: i @ dot.c:55
+; STRIPPED-NOT: i @ dot.c:55
+; BOTH: Offset: [SP-20], Type: Variable, Align: 8, Size: 4
+; DEBUG: B @ dot.c:32
+; STRIPPED-NOT: B @ dot.c:32
+; BOTH: Offset: [SP-24], Type: Variable, Align: 4, Size: 4
+; DEBUG: len @ dot.c:37
+; STRIPPED-NOT: len @ dot.c:37
+; BOTH: Offset: [SP-28], Type: Variable, Align: 4, Size: 4
+; BOTH: Offset: [SP-32], Type: Variable, Align: 4, Size: 4
+; DEBUG: sum @ dot.c:54
+; STRIPPED-NOT: sum @ dot.c:54
+define i32 @do_work(ptr %0, ptr %1, ptr %2) #2 {
+ %4 = alloca i32, align 4
+ %5 = alloca ptr, align 8
+ %6 = alloca ptr, align 8
+ %7 = alloca ptr, align 8
+ %8 = alloca i32, align 4
+ %9 = alloca ptr, align 8
+ %10 = alloca i32, align 4
+ %11 = alloca i32, align 4
+ store ptr %0, ptr %5, align 8
+ call void @llvm.dbg.declare(metadata ptr %5, metadata !52, metadata !DIExpression()), !dbg !56
+ call void @llvm.dbg.declare(metadata ptr %6, metadata !57, metadata !DIExpression()), !dbg !58
+ store ptr %2, ptr %7, align 8
+ call void @llvm.dbg.declare(metadata ptr %7, metadata !59, metadata !DIExpression()), !dbg !60
+ call void @llvm.dbg.declare(metadata ptr %8, metadata !61, metadata !DIExpression()), !dbg !63
+ call void @llvm.dbg.declare(metadata ptr %9, metadata !64, metadata !DIExpression()), !dbg !65
+ store ptr null, ptr %9, align 8
+ store ptr null, ptr null, align 8
+ store i32 0, ptr %9, align 8
+ %12 = load i32, ptr %8, align 4
+ store i32 %12, ptr null, align 8
+ call void @llvm.dbg.declare(metadata ptr %10, metadata !66, metadata !DIExpression()), !dbg !67
+ call void @llvm.dbg.declare(metadata ptr %11, metadata !68, metadata !DIExpression()), !dbg !70
+ store i32 0, ptr %11, align 4
+ br label %13
+
+13: ; preds = %16, %3
+ %14 = load i32, ptr %11, align 4
+ %15 = icmp slt i32 %14, 0
+ br i1 %15, label %16, label %18
+
+16: ; preds = %13
+ %17 = load i32, ptr %6, align 4
+ store i32 %17, ptr null, align 4
+ br label %13
+
+18: ; preds = %13
+ store i32 0, ptr %4, align 4
+ ret i32 0
+}
+
+; BOTH: Function: gen_array
+; BOTH: Offset: [SP+4], Type: Protector, Align: 16, Size: 4
+; DEBUG: size @ dot.c:62
+; STRIPPED-NOT: size @ dot.c:62
+; BOTH: Offset: [SP-4], Type: Spill, Align: 8, Size: 4
+; BOTH: Offset: [SP-12], Type: Variable, Align: 8, Size: 4
+; DEBUG: res @ dot.c:65
+; STRIPPED-NOT: res @ dot.c:65
+; BOTH: Offset: [SP-16], Type: Variable, Align: 4, Size: 4
+; DEBUG: i @ dot.c:69
+; STRIPPED-NOT: i @ dot.c:69
+; BOTH: Offset: [SP-20], Type: Variable, Align: 8, Size: 4
+define ptr @gen_array(i32 %0) #1 {
+ %2 = alloca ptr, align 8
+ %3 = alloca i32, align 4
+ %4 = alloca ptr, align 8
+ %5 = alloca i32, align 4
+ store i32 %0, ptr %3, align 4
+ call void @llvm.dbg.declare(metadata ptr %3, metadata !71, metadata !DIExpression()), !dbg !75
+ call void @llvm.dbg.declare(metadata ptr %4, metadata !76, metadata !DIExpression()), !dbg !77
+ store ptr null, ptr %4, align 8
+ call void @llvm.dbg.declare(metadata ptr %5, metadata !78, metadata !DIExpression()), !dbg !80
+ store i32 0, ptr %5, align 4
+ ret ptr null
+}
+
+; BOTH: Function: caller
+; BOTH: Offset: [SP-4], Type: Spill, Align: 8, Size: 4
+; BOTH: Offset: [SP-12], Type: Variable, Align: 8, Size: 4
+; DEBUG: res @ dot.c:80
+; STRIPPED-NOT: res @ dot.c:80
+; BOTH: Offset: [SP-20], Type: Variable, Align: 8, Size: 4
+; DEBUG: B @ dot.c:79
+; STRIPPED-NOT: B @ dot.c:79
+; BOTH: Offset: [SP-28], Type: Variable, Align: 8, Size: 4
+; DEBUG: A @ dot.c:78
+; STRIPPED-NOT: A @ dot.c:78
+; BOTH: Offset: [SP-32], Type: Variable, Align: 4, Size: 4
+; DEBUG: ret @ dot.c:81
+; STRIPPED-NOT: ret @ dot.c:81
+; BOTH: Offset: [SP-36], Type: Variable, Align: 4, Size: 4
+; BOTH: Offset: [SP-40], Type: Variable, Align: 4, Size: 4
+; DEBUG: err @ dot.c:83
+; STRIPPED-NOT: err @ dot.c:83
+; BOTH: Offset: [SP-44], Type: Variable, Align: 4, Size: 4
+; DEBUG: size @ dot.c:77
+; STRIPPED-NOT: size @ dot.c:77
+define i32 @caller() #1 {
+ %1 = alloca i32, align 4
+ %2 = alloca i32, align 4
+ %3 = alloca ptr, align 8
+ %4 = alloca ptr, align 8
+ %5 = alloca ptr, align 8
+ %6 = alloca i32, align 4
+ %7 = alloca i32, align 4
+ call void @llvm.dbg.declare(metadata ptr %2, metadata !81, metadata !DIExpression()), !dbg !85
+ call void @llvm.dbg.declare(metadata ptr %3, metadata !86, metadata !DIExpression()), !dbg !87
+ call void @llvm.dbg.declare(metadata ptr %4, metadata !88, metadata !DIExpression()), !dbg !89
+ store ptr null, ptr %4, align 8
+ call void @llvm.dbg.declare(metadata ptr %5, metadata !90, metadata !DIExpression()), !dbg !91
+ call void @llvm.dbg.declare(metadata ptr %6, metadata !92, metadata !DIExpression()), !dbg !93
+ call void @llvm.dbg.declare(metadata ptr %7, metadata !94, metadata !DIExpression()), !dbg !95
+ %8 = call i32 @do_work(ptr %3, ptr null, ptr null)
+ store i32 0, ptr %6, align 4
+ store i32 0, ptr %1, align 4
+ call void @cleanup_result(ptr %5)
+ ret i32 0
+}
+
+; test29b: An array of [5 x i8] and a requested ssp-buffer-size of 5.
+; Requires protector.
+; Function Attrs: ssp stack-protector-buffer-size=5
+; BOTH: Function: test29b
+; BOTH: Offset: [SP-4], Type: Spill, Align: 8, Size: 4
+; BOTH: Offset: [SP-8], Type: Protector, Align: 4, Size: 4
+; BOTH: Offset: [SP-13], Type: Variable, Align: 1, Size: 5
+define i32 @test29b() #2 {
+entry:
+ %test = alloca [5 x i8], align 1
+ %call = call i32 (ptr, ...) @printf(ptr @.str, ptr %test)
+ ret i32 %call
+}
+
+; uselistorder directives
+uselistorder ptr @llvm.dbg.declare, { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 19, 18 }
+
+attributes #0 = { nocallback nofree nosync nounwind readnone speculatable willreturn }
+attributes #1 = { "frame-pointer"="all" }
+attributes #2 = { ssp "stack-protector-buffer-size"="5" "frame-pointer"="all" }
+
+!llvm.dbg.cu = !{!0, !2}
+!llvm.module.flags = !{!18, !19, !20, !21, !22, !23, !24}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
+!1 = !DIFile(filename: "frame-diags.c", directory: "")
+!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, retainedTypes: !4, splitDebugInlining: false, nameTableKind: None)
+!3 = !DIFile(filename: "dot.c", directory: "")
+!4 = !{!5, !6, !10, !13}
+!5 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64)
+!6 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !7, size: 64)
+!7 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Array", file: !3, line: 3, size: 128, elements: !8)
+!8 = !{!9, !12}
+!9 = !DIDerivedType(tag: DW_TAG_member, name: "data", scope: !7, file: !3, line: 4, baseType: !10, size: 64)
+!10 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !11, size: 64)
+!11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!12 = !DIDerivedType(tag: DW_TAG_member, name: "size", scope: !7, file: !3, line: 5, baseType: !11, size: 32, offset: 64)
+!13 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !14, size: 64)
+!14 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Result", file: !3, line: 8, size: 128, elements: !15)
+!15 = !{!16, !17}
+!16 = !DIDerivedType(tag: DW_TAG_member, name: "data", scope: !14, file: !3, line: 9, baseType: !6, size: 64)
+!17 = !DIDerivedType(tag: DW_TAG_member, name: "sum", scope: !14, file: !3, line: 10, baseType: !11, size: 32, offset: 64)
+!18 = !{i32 7, !"Dwarf Version", i32 5}
+!19 = !{i32 2, !"Debug Info Version", i32 3}
+!20 = !{i32 1, !"wchar_size", i32 4}
+!21 = !{i32 8, !"PIC Level", i32 2}
+!22 = !{i32 7, !"PIE Level", i32 2}
+!23 = !{i32 7, !"uwtable", i32 2}
+!24 = !{i32 7, !"frame-pointer", i32 2}
+!25 = !DILocalVariable(name: "buffer", scope: !26, file: !1, line: 30, type: !32)
+!26 = distinct !DILexicalBlock(scope: !27, file: !1, line: 29, column: 3)
+!27 = distinct !DISubprogram(name: "stackSizeWarning", scope: !1, file: !1, line: 28, type: !28, scopeLine: 28, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !30)
+!28 = !DISubroutineType(types: !29)
+!29 = !{null}
+!30 = !{!25, !31, !36, !37}
+!31 = !DILocalVariable(name: "buffer2", scope: !27, file: !1, line: 33, type: !32)
+!32 = !DICompositeType(tag: DW_TAG_array_type, baseType: !33, size: 640, elements: !34)
+!33 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
+!34 = !{!35}
+!35 = !DISubrange(count: 80)
+!36 = !DILocalVariable(name: "a", scope: !27, file: !1, line: 34, type: !11)
+!37 = !DILocalVariable(name: "b", scope: !27, file: !1, line: 35, type: !38)
+!38 = !DIBasicType(name: "long", size: 64, encoding: DW_ATE_signed)
+!39 = !DILocation(line: 30, column: 10, scope: !26)
+!40 = !DILocation(line: 33, column: 8, scope: !27)
+!41 = !DILocalVariable(name: "a", arg: 1, scope: !42, file: !3, line: 13, type: !6)
+!42 = distinct !DISubprogram(name: "cleanup_array", scope: !3, file: !3, line: 13, type: !43, scopeLine: 13, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !45)
+!43 = !DISubroutineType(types: !44)
+!44 = !{null, !6}
+!45 = !{}
+!46 = !DILocation(line: 13, column: 34, scope: !42)
+!47 = !DILocalVariable(name: "res", arg: 1, scope: !48, file: !3, line: 21, type: !13)
+!48 = distinct !DISubprogram(name: "cleanup_result", scope: !3, file: !3, line: 21, type: !49, scopeLine: 21, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !45)
+!49 = !DISubroutineType(types: !50)
+!50 = !{null, !13}
+!51 = !DILocation(line: 21, column: 36, scope: !48)
+!52 = !DILocalVariable(name: "A", arg: 1, scope: !53, file: !3, line: 32, type: !6)
+!53 = distinct !DISubprogram(name: "do_work", scope: !3, file: !3, line: 32, type: !54, scopeLine: 32, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !45)
+!54 = !DISubroutineType(types: !55)
+!55 = !{!11, !6, !6, !13}
+!56 = !DILocation(line: 32, column: 27, scope: !53)
+!57 = !DILocalVariable(name: "B", arg: 2, scope: !53, file: !3, line: 32, type: !6)
+!58 = !DILocation(line: 32, column: 44, scope: !53)
+!59 = !DILocalVariable(name: "out", arg: 3, scope: !53, file: !3, line: 32, type: !13)
+!60 = !DILocation(line: 32, column: 62, scope: !53)
+!61 = !DILocalVariable(name: "len", scope: !53, file: !3, line: 37, type: !62)
+!62 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !11)
+!63 = !DILocation(line: 37, column: 13, scope: !53)
+!64 = !DILocalVariable(name: "AB", scope: !53, file: !3, line: 38, type: !6)
+!65 = !DILocation(line: 38, column: 17, scope: !53)
+!66 = !DILocalVariable(name: "sum", scope: !53, file: !3, line: 54, type: !11)
+!67 = !DILocation(line: 54, column: 7, scope: !53)
+!68 = !DILocalVariable(name: "i", scope: !69, file: !3, line: 55, type: !11)
+!69 = distinct !DILexicalBlock(scope: !53, file: !3, line: 55, column: 3)
+!70 = !DILocation(line: 55, column: 12, scope: !69)
+!71 = !DILocalVariable(name: "size", arg: 1, scope: !72, file: !3, line: 62, type: !11)
+!72 = distinct !DISubprogram(name: "gen_array", scope: !3, file: !3, line: 62, type: !73, scopeLine: 62, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !45)
+!73 = !DISubroutineType(types: !74)
+!74 = !{!6, !11}
+!75 = !DILocation(line: 62, column: 29, scope: !72)
+!76 = !DILocalVariable(name: "res", scope: !72, file: !3, line: 65, type: !6)
+!77 = !DILocation(line: 65, column: 17, scope: !72)
+!78 = !DILocalVariable(name: "i", scope: !79, file: !3, line: 69, type: !11)
+!79 = distinct !DILexicalBlock(scope: !72, file: !3, line: 69, column: 3)
+!80 = !DILocation(line: 69, column: 12, scope: !79)
+!81 = !DILocalVariable(name: "size", scope: !82, file: !3, line: 77, type: !62)
+!82 = distinct !DISubprogram(name: "caller", scope: !3, file: !3, line: 76, type: !83, scopeLine: 76, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !45)
+!83 = !DISubroutineType(types: !84)
+!84 = !{!11}
+!85 = !DILocation(line: 77, column: 13, scope: !82)
+!86 = !DILocalVariable(name: "A", scope: !82, file: !3, line: 78, type: !6)
+!87 = !DILocation(line: 78, column: 17, scope: !82)
+!88 = !DILocalVariable(name: "B", scope: !82, file: !3, line: 79, type: !6)
+!89 = !DILocation(line: 79, column: 17, scope: !82)
+!90 = !DILocalVariable(name: "res", scope: !82, file: !3, line: 80, type: !13)
+!91 = !DILocation(line: 80, column: 18, scope: !82)
+!92 = !DILocalVariable(name: "ret", scope: !82, file: !3, line: 81, type: !11)
+!93 = !DILocation(line: 81, column: 7, scope: !82)
+!94 = !DILocalVariable(name: "err", scope: !82, file: !3, line: 83, type: !11)
+!95 = !DILocation(line: 83, column: 7, scope: !82)
More information about the llvm-commits
mailing list