Stream: git-wasmtime

Topic: wasmtime / issue #6437 Confused about the StackSlot, when...


view this post on Zulip Wasmtime GitHub notifications bot (May 23 2023 at 03:26):

YjyJeff opened issue #6437:

After reading the Overall Structure section in IR, I found the sum variable is explicitly placed in the stack with ss0 = explicit_slot 32. However, the loop induction variable i is not placed explicitly placed in the stack. The document said:

Such variables can also be presented to Cranelift as [stack slot]s. Stack slots are accessed with the stack_store and stack_load instructions, and can have their address taken with stack_addr, which supports C-like programming languages where local variables can have their address taken.

I am confused about when should we create a StackSlot. What is the advantage of StackSlot over Variable like i in the above? In my view, all of them are in the stack, there is no difference here. I searched a lot and did not find the answer. Could anyone explain it?

Thanks in advance.

view this post on Zulip Wasmtime GitHub notifications bot (May 23 2023 at 04:59):

cfallin commented on issue #6437:

I think the main point of confusion is

In my view, all of them are in the stack

which is not quite true: in the example you linked, i is never stored on the stack; it exists only as SSA values. That is exactly the difference: StackSlot is an allocation of memory, and you can load and store to it whenever you like; Variable is an abstraction in cranelift_frontend that builds Values, which are values computed in your program that may only live in registers. You can load a stack-slot to get a value, and you can store a value to a stack-slot; but a stack-slot itself is not a value.

view this post on Zulip Wasmtime GitHub notifications bot (May 23 2023 at 05:50):

cfallin edited a comment on issue #6437:

I think the main point of confusion is

In my view, all of them are in the stack

which is not quite true: in the example you linked, i is never stored on the stack; it exists only as SSA values. That is exactly the difference: StackSlot is an allocation of memory, and you can load and store to it whenever you like; Variable is an abstraction in cranelift_frontend that builds Values, which are values computed in your program that might only live in registers (the register allocator might also "spill" them to the stack but that's transparent to you). You can load a stack-slot to get a value, and you can store a value to a stack-slot; but a stack-slot itself is not a value.

view this post on Zulip Wasmtime GitHub notifications bot (May 23 2023 at 06:08):

YjyJeff closed issue #6437:

After reading the Overall Structure section in IR, I found the sum variable is explicitly placed in the stack with ss0 = explicit_slot 32. However, the loop induction variable i is not placed explicitly placed in the stack. The document said:

Such variables can also be presented to Cranelift as [stack slot]s. Stack slots are accessed with the stack_store and stack_load instructions, and can have their address taken with stack_addr, which supports C-like programming languages where local variables can have their address taken.

I am confused about when should we create a StackSlot. What is the advantage of StackSlot over Variable like i in the above? In my view, all of them are in the stack, there is no difference here. I searched a lot and did not find the answer. Could anyone explain it?

Thanks in advance.


Last updated: Nov 22 2024 at 16:03 UTC