[llvm] [WebAssembly] Enable a limited amount of stackification for debug code (PR #136510)
Heejin Ahn via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 23 02:31:28 PDT 2025
================
@@ -0,0 +1,89 @@
+; RUN: llc < %s -O0 --filetype=obj -o - | llvm-dwarfdump - | FileCheck %s --check-prefixes DBG_USE
+
+target triple = "wasm32-unknown-unknown"
+
+declare i32 @extern_func(i32, i32)
+
+; We want to produce local DW_OP_WASM_locations in debug code instead
+; of operand stack locations since local locations are more widely
+; supported and can cover the entirety of the method.
+; DBG_USE: DW_TAG_subprogram
+; DBG_USE: DW_AT_name ("single_non_dbg_use")
+; DBG_USE: DW_TAG_variable
+; DBG_USE: DW_AT_location
+; DBG_USE: DW_OP_WASM_location 0x0
+; DBG_USE: DW_AT_name ("call_value")
+; DBG_USE: DW_TAG_variable
+; DBG_USE: DW_AT_location
+; DBG_USE: DW_OP_WASM_location 0x0
+; DBG_USE: DW_AT_name ("sub_value")
+define i32 @single_non_dbg_use(i32 %0, i32 %1) !dbg !6 {
+ %call_value = call i32 @extern_func(i32 1, i32 2), !dbg !20
+ call void @llvm.dbg.value(metadata i32 %call_value, metadata !11, metadata !DIExpression()), !dbg !20
+ %div = udiv i32 %0, %1, !dbg !21
+ %sub = sub i32 %call_value, %div, !dbg !22
+ call void @llvm.dbg.value(metadata i32 %sub, metadata !12, metadata !DIExpression()), !dbg !22
+ ret i32 %sub, !dbg !23
+}
+
+!6 = distinct !DISubprogram(name: "single_non_dbg_use", scope: !1, file: !1, type: !7, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0)
+!7 = !DISubroutineType(types: !8)
+!8 = !{!9, !9, !9}
+!9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!11 = !DILocalVariable(name: "call_value", scope: !6, type: !9)
+!12 = !DILocalVariable(name: "sub_value", scope: !6, type: !9)
+!20 = !DILocation(line: 20, scope: !6)
+!21 = !DILocation(line: 21, scope: !6)
+!22 = !DILocation(line: 22, scope: !6)
+!23 = !DILocation(line: 23, scope: !6)
+
+; Similarly for a singly-used frame base.
+; DBG_USE: DW_TAG_subprogram
+; DBG_USE: DW_AT_frame_base (DW_OP_WASM_location 0x0
+; DBG_USE: DW_AT_name ("single_use_frame_base")
+; DBG_USE: DW_TAG_variable
+; DBG_USE: DW_AT_location (DW_OP_fbreg +12)
+; DBG_USE: DW_AT_name ("arg_value")
+define i32 @single_use_frame_base(i32 %0, i32 %1) !dbg !13 {
+ %arg_loc = alloca i32, !dbg !24
+ store i32 %1, ptr %arg_loc, !dbg !25
+ call void @llvm.dbg.declare(metadata ptr %arg_loc, metadata !14, metadata !DIExpression()), !dbg !25
+ ret i32 %0, !dbg !26
+}
+
+!13 = distinct !DISubprogram(name: "single_use_frame_base", scope: !1, file: !1, type: !7, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0)
+!14 = !DILocalVariable(name: "arg_value", scope: !13, type: !9)
+!24 = !DILocation(line: 24, scope: !13)
+!25 = !DILocation(line: 25, scope: !13)
+!26 = !DILocation(line: 26, scope: !13)
+
+; Similarly for multivalue defs... But we can't really test
+; it due to https://github.com/llvm/llvm-project/issues/136506.
----------------
aheejin wrote:
I'd like to fix #136506 sometime. I'll link #136506 for the reverse reference here so this can be fixed once #136506 is fixed.
https://github.com/llvm/llvm-project/pull/136510
More information about the llvm-commits
mailing list