This is an archive of the discontinued LLVM Phabricator instance.

[WebAssembly] Track frame/stack pointer local for debug information
AbandonedPublic

Authored by yurydelendik on Nov 4 2019, 9:23 AM.

Details

Reviewers
None
Summary

Uses global.set as a reference point to track which local is used
for storing a WebAssembly frame pointer in the function.

Event Timeline

yurydelendik created this revision.Nov 4 2019, 9:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 4 2019, 9:23 AM

I think the general idea here makes sense, although as-is I'm afraid it might be brittle. I think for this to work, we'd need to ensure that the frame base stays in the designated local for the whole function, correct? i.e. we'd have to ensure it never gets stackified, which it currently could, right?

Come to think of it, do we know that the CFA is always correct in that case ? IIUC if SP gets stackified, we'd need to emit CFA definition instructions to ensure that the debugger could follow it from the local to the stack, possibly to another local, etc. I think that could work (e.g. we could use DW_CFA_def_cfa_expression) but I don't know that it would work out of the box. How are you handling this with wasmtime right now?

we'd need to ensure that the frame base stays in the designated local for the whole function, correct? i.e. we'd have to ensure it never gets stackified, which it currently could, right?

Ideally, that's correct. Though we need to take in account Philosophy behind LLVM debugging information . If producing a "stable" frame base location is a trade-off for producing an optimized code, the latter has to be favored.

Come to think of it, do we know that the CFA is always correct in that case ? IIUC if SP gets stackified, we'd need to emit CFA definition instructions to ensure that the debugger could follow it from the local to the stack, possibly to another local, etc.

Right, the moving/spilling (between registers) is not handled as this moment. :/ TODO

How are you handling this with wasmtime right now?

wasmtime, when transforms wasm DWARF into "native" DWARF, is able to process DW_AT_frame_base as a list that can define noncontinuous/different frame base locations for a single function. It is worth to note that during transform/compilation WebAssembly FP/SP abstraction will disappear as result of JIT/AOT compiler's work -- the wasm DWARF DW_AT_frame_base will be inlined into "native" DWARF expressions as transformed operators to match native instructions.

yurydelendik marked an inline comment as done.Dec 2 2019, 1:05 PM
yurydelendik added inline comments.
llvm/lib/Target/WebAssembly/WebAssemblyFrameLowering.cpp
221

needsSPWriteback(MF) is false when there is no calls -- we need different "anchor" than set_global

yurydelendik abandoned this revision.Jan 15 2020, 12:15 PM

Closing in favor of D71681