[llvm] [WebAssembly] Enable a limited amount of stackification for debug code (PR #136510)

Heejin Ahn via llvm-commits llvm-commits at lists.llvm.org
Thu May 29 02:13:03 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")
----------------
aheejin wrote:

Does 
> instead of operand stack locations since local locations are more widely

mean the stack locations due to RegStackify, or unoptimized code that uses stack for every variable? If the latter, this bitcode does not contain any loads or stores and uses `dbg.value`, so the only differences in dwarfdump results are just the local numbers and this test (and the tests below as well) passes even without this PR.

- Without this PR:
```wat
  (func $single_non_dbg_use (type 0) (param i32 i32) (result i32)
    (local i32 i32 i32 i32 i32)
    i32.const 1
    local.set 2
    i32.const 2
    local.set 3
    local.get 2
    local.get 3
    call 0
    local.set 4
    local.get 0
    local.get 1
    i32.div_u
    local.set 5
    local.get 4
    local.get 5
    i32.sub
    local.set 6
    local.get 6
    return)
```
dwarfdump result for `call_value`:
```
0x0000003b:     DW_TAG_variable
                  DW_AT_location  (0x00000000: 
                     [0x00000019, 0x0000002b): DW_OP_WASM_location 0x0 0x4, DW_OP_stack_value)
                  DW_AT_name  ("call_value")
                  DW_AT_type  (0x00000079 "int")
```

- With this PR:
```wat
  (func $single_non_dbg_use (type 0) (param i32 i32) (result i32)
    (local i32 i32)
    i32.const 1
    i32.const 2
    call 0
    local.set 2
    local.get 2
    local.get 0
    local.get 1
    i32.div_u
    i32.sub
    local.set 3
    local.get 3
    return)
```
dwarfdump result for `call_value`:
```
0x0000003b:     DW_TAG_variable
                  DW_AT_location  (0x00000000: 
                     [0x00000011, 0x0000001f): DW_OP_WASM_location 0x0 0x2, DW_OP_stack_value)
                  DW_AT_name  ("call_value")
                  DW_AT_type  (0x00000079 "int")

```

Both of them are `DW_OP_WASM_location 0x0 offset` form.

https://github.com/llvm/llvm-project/pull/136510


More information about the llvm-commits mailing list