Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ISLE rule for heap offset symbol #196

Merged
merged 2 commits into from
Jan 26, 2024
Merged

Add ISLE rule for heap offset symbol #196

merged 2 commits into from
Jan 26, 2024

Conversation

aborg-dev
Copy link

This removes the hacky implementation using LoadExtName in favor of a more targeted rule.

Note, that this is also an example where a rule for immediate addition would be useful and where the basic constant folding pass would not work. So #105 actually becomes quite appealing.

@aborg-dev aborg-dev requested review from nagisa and mooori January 23, 2024 13:43
(lower (symbol_value (symbol_value_data name _ offset)))
(load_ext_name name offset))
(lower (symbol_value (zkasm_base ZkasmBase.Heap)))
(imm $I32 0))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The TODO that was removed from emit.rs mentions having at most one external constant. Hardcoding 0 here means that still at most one external constant is expected?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite. The TODO was out of date, as we support 3 types of external constants now:

fn zkasm_base(&mut self, global_value: GlobalValue) -> Option<generated_code::ZkasmBase> {

But these constants appear in slightly different contexts:

  • For Heap, we use RegOffset addressing mode
  • For Globals, we use Global addressing mode
  • Table is currently not implemented
    I looked for a way to handle the Heap and Globals access similarly, but haven't found it because the generated CLIF code for them is slightly different.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the context. I'm struggling to understand why there is a hardcoded 0 on the right hand side of this ISLE rule (instead of any other number)?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps I should add why I’m struggling: In the previous ISLE rule (that was replaced) name and offset parameters were passed on to load_ext_name. So to see what happens for the symbol_value lowering it was possible to look at how MInst::LoadExtName is handled.

With the new right hand side (imm $I32 0) for the ZkasmBase.Heap case, it’s not clear to me why the hardcoded value is 0 and how this 0 ends up in RegOffset.

Copy link
Author

@aborg-dev aborg-dev Jan 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see. We use 0 here as the memory region that we use on ZKASM machine starts at offset 0. The offset in global value is populated by us in zkasm.rs Environment

offset: Imm64::new(0),
and is used to identify which memory region we want to access (Heap, Globals, Table). Does this make sense?

@aborg-dev aborg-dev force-pushed the fix_frame_setup branch 2 times, most recently from 8fc13d1 to e52d6b3 Compare January 24, 2024 09:38
This removes the hacky implementation using LoadExtName in favor of a more targeted rule.
@aborg-dev aborg-dev changed the base branch from fix_frame_setup to main January 24, 2024 09:40
@aborg-dev aborg-dev requested a review from mooori January 24, 2024 09:40
@aborg-dev aborg-dev enabled auto-merge January 24, 2024 11:53
@mooori mooori disabled auto-merge January 25, 2024 12:00
Copy link

@mooori mooori left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I think a comment on the ISLE rule would be helpful. For example somehting like:

;; Having an `offset` of 0 in a `GlobalValue` signalizes it is stored on the heap, see
;; cranelift_wasm::environ::zkasm::ZkasmFuncEnvironment::heap_base

I’ve disabled auto-merge just for the case that you’d like to add a comment.

@aborg-dev
Copy link
Author

LGTM. I think a comment on the ISLE rule would be helpful. For example somehting like:

;; Having an `offset` of 0 in a `GlobalValue` signalizes it is stored on the heap, see
;; cranelift_wasm::environ::zkasm::ZkasmFuncEnvironment::heap_base

I’ve disabled auto-merge just for the case that you’d like to add a comment.

Good idea, I've added the comments to clarify this.

@aborg-dev aborg-dev enabled auto-merge January 26, 2024 09:10
@aborg-dev aborg-dev added this pull request to the merge queue Jan 26, 2024
Merged via the queue into main with commit ca0d6dc Jan 26, 2024
21 checks passed
@aborg-dev aborg-dev deleted the heap_offset branch January 26, 2024 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants