Adjust the calleeSavedRegs on top frame for LoongArch64/RISCV64 - #100962

Merged
jakobbotsch merged 4 commits into
dotnet:mainfrom
shushanhf:adjust_calleeSavedRegs_offset
Apr 23, 2024
Merged

Adjust the calleeSavedRegs on top frame for LoongArch64/RISCV64#100962
jakobbotsch merged 4 commits into
dotnet:mainfrom
shushanhf:adjust_calleeSavedRegs_offset

Conversation

@shushanhf

@shushanhfshushanhf commented Apr 12, 2024

Copy link
Copy Markdown
Contributor

Adjust the calleeSavedRegs on top frame for LoongArch64/RISCV64 to support the GSCookie.

Theframelayout:
| |
|-----------------------|
| incomingarguments |
+=======================+<----Caller's SP
| Varargsregsspace | // Only for varargs main functions; not used for LA64.
|-----------------------|
| MonitorAcquired | // 8 bytes; for synchronized methods
|-----------------------|
| PSPslot | // 8 bytes (omitted in NativeAOT ABI)
|-----------------------|
|Calleesavedregisters | // multiple of 8 bytes, not including FP/RA
|-----------------------|
| SavedRA | // 8 bytes
|-----------------------|
| SavedFP | // 8 bytes
|-----------------------|
| possibleGScookie |
|-----------------------|
| locals, temps, etc. |
|-----------------------|
| possibleGScookie |
|-----------------------|
| Outgoingargspace | // multiple of 8 bytes; if required (i.e., #outsz != 0)
|-----------------------| <----AmbientSP
| | |
~ | Stackgrows ~
| | downward |

@ghostghost added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Apr 12, 2024
@dotnet-policy-servicedotnet-policy-serviceBot added the community-contribution Indicates that the PR has been added by a community member label Apr 12, 2024
@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch 5 times, most recently from 6ec45e3 to 855fdb3CompareApril 13, 2024 08:01
@am11am11 added arch-loongarch64 arch-riscv Related to the RISC-V architecture labels Apr 13, 2024
@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch 6 times, most recently from f94cc0d to cf69c78CompareApril 15, 2024 10:06
@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch from cf69c78 to 8601cfcCompareApril 16, 2024 00:44
@shushanhf

Copy link
Copy Markdown
ContributorAuthor

@jakobbotsch@clamp03
Could you please review this PR?
Thanks

@clamp03

Copy link
Copy Markdown
Member

@bartlomiejko Can you review and test this PR?
cc @dotnet/samsung

@jakobbotsch

Copy link
Copy Markdown
Member

How is the stack frame layout changed compared to previously? What was the layout before this change? Why didn't it support GS cookie?
Can you show some codegen diffs?

@shushanhf

shushanhf commented Apr 16, 2024

Copy link
Copy Markdown
ContributorAuthor

How is the stack frame layout changed compared to previously? What was the layout before this change?

Only changed the calledSavedRegs, especially the FP/RA for LA64/RV64. The layout liking this PR's first comment description #100962 (comment) .
Before this PR, the FP/RA at bottom of frame which under the GSCookie, the FP/RA can be overwritten.

Why didn't it support GS cookie? Can you show some codegen diffs?

Before this PR, the FP/RA at bottom of frame which under the GSCookie, the FP/RA can be overwritten.

Comment threadsrc/coreclr/jit/codegenloongarch64.cpp
Comment threadsrc/coreclr/jit/lclvars.cpp Outdated
@jakobbotsch

Copy link
Copy Markdown
Member

Only changed the calledSavedRegs, especially the FP/RA for LA64/RV64. The layout liking this PR's first comment description #100962 (comment) .
Before this PR, the FP/RA at bottom of frame which under the GSCookie, the FP/RA can be overwritten.

Where does FP point to in your picture? Where did it point to before?

@shushanhf

Copy link
Copy Markdown
ContributorAuthor

Only changed the calledSavedRegs, especially the FP/RA for LA64/RV64. The layout liking this PR's first comment description #100962 (comment) .
Before this PR, the FP/RA at bottom of frame which under the GSCookie, the FP/RA can be overwritten.

Where does FP point to in your picture? Where did it point to before?

The new FP is pointing to the the old FP saved slot.

Can you show some codegen diffs?

/// this is the Old one.
G_M22522_IG01: ;; offset=0x0000
0xff74a50030 02FDC063 addi.d sp, sp, -144
0xff74a50034 29C00061 st.d ra, sp, 0
0xff74a50038 29C02076 st.d fp, sp, 8
0xff74a5003c 02C02076 addi.d fp, sp, 8
0xff74a50040 02C062CC addi.d t0, fp, 24 0xff74a50044 02801407 addi.w a3, zero, 5
0xff74a50048 29C02180 st.d zero, t0, 8
0xff74a5004c 29C00180 st.d zero, t0, 0
0xff74a50050 02FFFCE7 addi.d a3, a3, -1
0xff74a50054 02C0418C addi.d t0, t0, 16 0xff74a50058 5FFFF0E0 bne a3, zero, 0xff74a50048
0xff74a5005c 29C00180 st.d zero, t0, 0
0xff74a50060 29C202C4 st.d a0, fp, 128
0xff74a50064 29C1E2C5 st.d a1, fp, 120
0xff74a50068 29C1C2C6 st.d a2, fp, 112
;; size=60 bbWeight=1 PerfScore 0.00
G_M22522_IG02: ;; offset=0x003C
/// This is the new ins.
G_M22522_IG01: ;; offset=0x0000
0xff77790030 02FDC063 addi.d sp, sp, -144
0xff77790034 29C20076 st.d fp, sp, 128
0xff77790038 29C22061 st.d ra, sp, 136
0xff7779003c 02C20076 addi.d fp, sp, 128
0xff77790040 02FE42CC addi.d t0, fp, -112
0xff77790044 02801407 addi.w a3, zero, 5
0xff77790048 29C02180 st.d zero, t0, 8
0xff7779004c 29C00180 st.d zero, t0, 0
0xff77790050 02FFFCE7 addi.d a3, a3, -1
0xff77790054 02C0418C addi.d t0, t0, 16 0xff77790058 5FFFF0E0 bne a3, zero, 0xff77790048 /// the upstream's disasm format had been updated.
0xff7779005c 29C00180 st.d zero, t0, 0
0xff77790060 29FFE2C4 st.d a0, fp, -8
0xff77790064 29FFC2C5 st.d a1, fp, -16
0xff77790068 29FFA2C6 st.d a2, fp, -24
;; size=60 bbWeight=1 PerfScore 0.00

@jakobbotsch

Copy link
Copy Markdown
Member

Before this PR, the FP/RA at bottom of frame which under the GSCookie, the FP/RA can be overwritten.

Before this change, the comment in codegenloongarch64.cpp gives the following layout:

* The LoongArch64's frame layout is liking:
*
* | |
* |-----------------------|
* | incoming arguments |
* +=======================+ <---- Caller's SP
* | Arguments Or | // if needed.
* | Varargs regs space | // Only for varargs functions; (varargs not implemented for LoongArch64)
* |-----------------------|
* | MonitorAcquired | // 8 bytes; for synchronized methods
* |-----------------------|
* | PSP slot | // 8 bytes (omitted in NativeAOT ABI)
* |-----------------------|
* | locals, temps, etc. |
* |-----------------------|
* | possible GS cookie |
* |-----------------------|
* | Saved FP | // 8 bytes
* |-----------------------|
* | Saved RA | // 8 bytes
* |-----------------------|
* |Callee saved registers | // not including FP/RA; multiple of 8 bytes
* |-----------------------|
* | Outgoing arg space | // multiple of 8 bytes; if required (i.e., #outsz != 0)
* |-----------------------| <---- Ambient SP
* | | |
* ~ | Stack grows ~
* | | downward |
* V

The GS cookie exists between the locals and FP/RA pair. I do not see how FP/RA can be overwritten without hitting the GS cookie. Was the comment wrong?

Do you mean that the FP/RA of caller's frame can be overwritten?

@jakobbotsch

Copy link
Copy Markdown
Member

If I understand correctly, the change here means you have to use negative offsets from FP to access locals more often. Does LA64/RV64 allow encoding as many negative offsets as it allows positive offsets?

@shushanhf

shushanhf commented Apr 16, 2024

Copy link
Copy Markdown
ContributorAuthor
  •  |Callee saved registers | // not including FP/RA; multiple of 8 bytes
    

The GS cookie exists between the locals and FP/RA pair. I do not see how FP/RA can be overwritten without hitting the GS cookie. Was the comment wrong?
Do you mean that the FP/RA of caller's frame can be overwritten?

The GS Cookie is only used liking the localalloc. After finished the frame allocation, when using the localalloc to allocate a new stack space, the new space maybe overwritten the new real size allocated while the GSCookie is used to recognize this case.
Before this PR which the FP/RA under GS cookie, the FP/RA maybe overwritten while the GS cookie may not recognize this.

@shushanhf

Copy link
Copy Markdown
ContributorAuthor

If I understand correctly, the change here means you have to use negative offsets from FP to access locals more often. Does LA64/RV64 allow encoding as many negative offsets as it allows positive offsets?

yes

@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch from 8601cfc to 23fc354CompareApril 16, 2024 09:22
@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch 2 times, most recently from b78f2e0 to c237762CompareApril 19, 2024 06:39
@shushanhf

Copy link
Copy Markdown
ContributorAuthor

I think the CI went wrong. e.g.

@azure-pipelines
runtime (Build Formatting linux x64) Failing after 4m — Build Formatting linux x64 failed
[Details](https://github.com/dotnet/runtime/pull/100962/checks?check_run_id=24011496326)
@azure-pipelines
runtime (Build Formatting windows x64) Failing after 7m — Build Formatting windows x64 failed

but format-patch is empty.

@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch from c237762 to feaa635CompareApril 19, 2024 09:46
@jakobbotsch

Copy link
Copy Markdown
Member

I think the CI went wrong. e.g.

@azure-pipelines
runtime (Build Formatting linux x64) Failing after 4m — Build Formatting linux x64 failed
[Details](https://github.com/dotnet/runtime/pull/100962/checks?check_run_id=24011496326)
@azure-pipelines
runtime (Build Formatting windows x64) Failing after 7m — Build Formatting windows x64 failed

but format-patch is empty.

You can run jit-format locally, see the docs at https://github.com/dotnet/jitutils and https://github.com/dotnet/jitutils/blob/main/doc/formatting.md.

@am11

am11 commented Apr 19, 2024

Copy link
Copy Markdown
Member

The underlying error shows up on Windows leg:

D:\a_work\1\s\venv\Scripts\python.exe D:\a_work\1\s/src/coreclr/scripts/jitformat.py -r D:\a_work\1\s -o windows -a x64
...
2024-04-19T09:58:48.1997764Z No cdac-build-tool set or does not exist

started happening after #100650 merge. cc @lambdageek

@jakobbotschjakobbotsch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This change looks good to me now. Thanks for addressing all the feedback! I will give RISC-V folks some time to review as well.

@tomeksowitomeksowi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@sirntar, you did more work with stack frames/OSR, could you review when you return on Monday?

@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch from feaa635 to 3092323CompareApril 20, 2024 01:14
Comment threadsrc/coreclr/jit/codegenriscv64.cpp Outdated
Comment threadsrc/coreclr/jit/codegenriscv64.cpp Outdated
to support the GSCookie.
The frame layout:
| |
|-----------------------|
| incoming arguments |
+=======================+ <---- Caller's SP
| Varargs regs space | // Only for varargs main functions; not used for LA64.
|-----------------------|
| MonitorAcquired | // 8 bytes; for synchronized methods
|-----------------------|
| PSP slot | // 8 bytes (omitted in NativeAOT ABI)
|-----------------------|
|Callee saved registers | // multiple of 8 bytes, not includting FP/RA
|-----------------------|
| Saved RA | // 8 bytes
|-----------------------|
| Saved FP | // 8 bytes
|-----------------------|
| possible GS cookie |
|-----------------------|
| locals, temps, etc. |
|-----------------------|
| possible GS cookie |
|-----------------------|
| Outgoing arg space | // multiple of 8 bytes; if required (i.e., #outsz != 0)
|-----------------------| <---- Ambient SP
| | |
~ | Stack grows ~
| | downward |
@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch from 3092323 to e254dd6CompareApril 22, 2024 07:26

@sirntarsirntar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@jakobbotsch

Copy link
Copy Markdown
Member

@shushanhf Can you please avoid amending/force pushing to PRs? It makes it hard for us to see exactly what changed and to review the new changes. If you can push them as new commits that makes it much easier. We squash every PR on merge, so the history will be cleaned up anyway.

@rzsc

rzsc commented Apr 22, 2024

Copy link
Copy Markdown
Contributor

PR tested on riscv64 architecture and ready to be merged. Thanks!

@shushanhf

shushanhf commented Apr 23, 2024

Copy link
Copy Markdown
ContributorAuthor

@shushanhf Can you please avoid amending/force pushing to PRs?

Ok, thanks, I will.

It makes it hard for us to see exactly what changed and to review the new changes. If you can push them as new commits that makes it much easier. We squash every PR on merge, so the history will be cleaned up anyway.

Sorry, I didn't know this.
I thought the github has a new button Update branch which I thought I had to update the PR's base as soon as possible.
And I thought the github reviewing is liking the gerrit which different patches within the same PR are easy to diff where independed of the base.
Maybe the github should add the similar feature.

@jakobbotsch

Copy link
Copy Markdown
Member

Thanks for helping me understand the motivation for the change, and for making LA64/RV64 more similar to ARM64 around OSR.

@jakobbotsch

Copy link
Copy Markdown
Member

@BruceForstall If you have any feedback around this then please feel free to leave it. To sum up the motivation of the change you can see #100962 (comment).

@shushanhf
shushanhf deleted the adjust_calleeSavedRegs_offset branch April 23, 2024 11:53
matouskozak pushed a commit to matouskozak/runtime that referenced this pull request Apr 30, 2024
…et#100962)
The frame layout:
| |
|-----------------------|
| incoming arguments |
+=======================+ <---- Caller's SP
| Varargs regs space | // Only for varargs main functions; not used for LA64.
|-----------------------|
| MonitorAcquired | // 8 bytes; for synchronized methods
|-----------------------|
| PSP slot | // 8 bytes (omitted in NativeAOT ABI)
|-----------------------|
|Callee saved registers | // multiple of 8 bytes, not includting FP/RA
|-----------------------|
| Saved RA | // 8 bytes
|-----------------------|
| Saved FP | // 8 bytes
|-----------------------|
| possible GS cookie |
|-----------------------|
| locals, temps, etc. |
|-----------------------|
| possible GS cookie |
|-----------------------|
| Outgoing arg space | // multiple of 8 bytes; if required (i.e., #outsz != 0)
|-----------------------| <---- Ambient SP
| | |
~ | Stack grows ~
| | downward |
michaelgsharp pushed a commit to michaelgsharp/runtime that referenced this pull request May 9, 2024
…et#100962)
The frame layout:
| |
|-----------------------|
| incoming arguments |
+=======================+ <---- Caller's SP
| Varargs regs space | // Only for varargs main functions; not used for LA64.
|-----------------------|
| MonitorAcquired | // 8 bytes; for synchronized methods
|-----------------------|
| PSP slot | // 8 bytes (omitted in NativeAOT ABI)
|-----------------------|
|Callee saved registers | // multiple of 8 bytes, not includting FP/RA
|-----------------------|
| Saved RA | // 8 bytes
|-----------------------|
| Saved FP | // 8 bytes
|-----------------------|
| possible GS cookie |
|-----------------------|
| locals, temps, etc. |
|-----------------------|
| possible GS cookie |
|-----------------------|
| Outgoing arg space | // multiple of 8 bytes; if required (i.e., #outsz != 0)
|-----------------------| <---- Ambient SP
| | |
~ | Stack grows ~
| | downward |
@github-actionsgithub-actionsBot locked and limited conversation to collaborators May 24, 2024
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

arch-loongarch64arch-riscvRelated to the RISC-V architecturearea-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIcommunity-contributionIndicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants

@shushanhf@clamp03@jakobbotsch@AndyAyersMS@bartlomiejko@am11@rzsc@tomeksowi@sirntar@Bajtazar
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Adjust the calleeSavedRegs on top frame for LoongArch64/RISCV64 - #100962

Merged
jakobbotsch merged 4 commits into
dotnet:mainfrom
shushanhf:adjust_calleeSavedRegs_offset
Apr 23, 2024
Merged

Adjust the calleeSavedRegs on top frame for LoongArch64/RISCV64#100962
jakobbotsch merged 4 commits into
dotnet:mainfrom
shushanhf:adjust_calleeSavedRegs_offset

Conversation

@shushanhf

@shushanhfshushanhf commented Apr 12, 2024

Copy link
Copy Markdown
Contributor

Adjust the calleeSavedRegs on top frame for LoongArch64/RISCV64 to support the GSCookie.

Theframelayout:
| |
|-----------------------|
| incomingarguments |
+=======================+<----Caller's SP
| Varargsregsspace | // Only for varargs main functions; not used for LA64.
|-----------------------|
| MonitorAcquired | // 8 bytes; for synchronized methods
|-----------------------|
| PSPslot | // 8 bytes (omitted in NativeAOT ABI)
|-----------------------|
|Calleesavedregisters | // multiple of 8 bytes, not including FP/RA
|-----------------------|
| SavedRA | // 8 bytes
|-----------------------|
| SavedFP | // 8 bytes
|-----------------------|
| possibleGScookie |
|-----------------------|
| locals, temps, etc. |
|-----------------------|
| possibleGScookie |
|-----------------------|
| Outgoingargspace | // multiple of 8 bytes; if required (i.e., #outsz != 0)
|-----------------------| <----AmbientSP
| | |
~ | Stackgrows ~
| | downward |

@ghostghost added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Apr 12, 2024
@dotnet-policy-servicedotnet-policy-serviceBot added the community-contribution Indicates that the PR has been added by a community member label Apr 12, 2024
@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch 5 times, most recently from 6ec45e3 to 855fdb3CompareApril 13, 2024 08:01
@am11am11 added arch-loongarch64 arch-riscv Related to the RISC-V architecture labels Apr 13, 2024
@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch 6 times, most recently from f94cc0d to cf69c78CompareApril 15, 2024 10:06
@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch from cf69c78 to 8601cfcCompareApril 16, 2024 00:44
@shushanhf

Copy link
Copy Markdown
ContributorAuthor

@jakobbotsch@clamp03
Could you please review this PR?
Thanks

@clamp03

Copy link
Copy Markdown
Member

@bartlomiejko Can you review and test this PR?
cc @dotnet/samsung

@jakobbotsch

Copy link
Copy Markdown
Member

How is the stack frame layout changed compared to previously? What was the layout before this change? Why didn't it support GS cookie?
Can you show some codegen diffs?

@shushanhf

shushanhf commented Apr 16, 2024

Copy link
Copy Markdown
ContributorAuthor

How is the stack frame layout changed compared to previously? What was the layout before this change?

Only changed the calledSavedRegs, especially the FP/RA for LA64/RV64. The layout liking this PR's first comment description #100962 (comment) .
Before this PR, the FP/RA at bottom of frame which under the GSCookie, the FP/RA can be overwritten.

Why didn't it support GS cookie? Can you show some codegen diffs?

Before this PR, the FP/RA at bottom of frame which under the GSCookie, the FP/RA can be overwritten.

Comment threadsrc/coreclr/jit/codegenloongarch64.cpp
Comment threadsrc/coreclr/jit/lclvars.cpp Outdated
@jakobbotsch

Copy link
Copy Markdown
Member

Only changed the calledSavedRegs, especially the FP/RA for LA64/RV64. The layout liking this PR's first comment description #100962 (comment) .
Before this PR, the FP/RA at bottom of frame which under the GSCookie, the FP/RA can be overwritten.

Where does FP point to in your picture? Where did it point to before?

@shushanhf

Copy link
Copy Markdown
ContributorAuthor

Only changed the calledSavedRegs, especially the FP/RA for LA64/RV64. The layout liking this PR's first comment description #100962 (comment) .
Before this PR, the FP/RA at bottom of frame which under the GSCookie, the FP/RA can be overwritten.

Where does FP point to in your picture? Where did it point to before?

The new FP is pointing to the the old FP saved slot.

Can you show some codegen diffs?

/// this is the Old one.
G_M22522_IG01: ;; offset=0x0000
0xff74a50030 02FDC063 addi.d sp, sp, -144
0xff74a50034 29C00061 st.d ra, sp, 0
0xff74a50038 29C02076 st.d fp, sp, 8
0xff74a5003c 02C02076 addi.d fp, sp, 8
0xff74a50040 02C062CC addi.d t0, fp, 24 0xff74a50044 02801407 addi.w a3, zero, 5
0xff74a50048 29C02180 st.d zero, t0, 8
0xff74a5004c 29C00180 st.d zero, t0, 0
0xff74a50050 02FFFCE7 addi.d a3, a3, -1
0xff74a50054 02C0418C addi.d t0, t0, 16 0xff74a50058 5FFFF0E0 bne a3, zero, 0xff74a50048
0xff74a5005c 29C00180 st.d zero, t0, 0
0xff74a50060 29C202C4 st.d a0, fp, 128
0xff74a50064 29C1E2C5 st.d a1, fp, 120
0xff74a50068 29C1C2C6 st.d a2, fp, 112
;; size=60 bbWeight=1 PerfScore 0.00
G_M22522_IG02: ;; offset=0x003C
/// This is the new ins.
G_M22522_IG01: ;; offset=0x0000
0xff77790030 02FDC063 addi.d sp, sp, -144
0xff77790034 29C20076 st.d fp, sp, 128
0xff77790038 29C22061 st.d ra, sp, 136
0xff7779003c 02C20076 addi.d fp, sp, 128
0xff77790040 02FE42CC addi.d t0, fp, -112
0xff77790044 02801407 addi.w a3, zero, 5
0xff77790048 29C02180 st.d zero, t0, 8
0xff7779004c 29C00180 st.d zero, t0, 0
0xff77790050 02FFFCE7 addi.d a3, a3, -1
0xff77790054 02C0418C addi.d t0, t0, 16 0xff77790058 5FFFF0E0 bne a3, zero, 0xff77790048 /// the upstream's disasm format had been updated.
0xff7779005c 29C00180 st.d zero, t0, 0
0xff77790060 29FFE2C4 st.d a0, fp, -8
0xff77790064 29FFC2C5 st.d a1, fp, -16
0xff77790068 29FFA2C6 st.d a2, fp, -24
;; size=60 bbWeight=1 PerfScore 0.00

@jakobbotsch

Copy link
Copy Markdown
Member

Before this PR, the FP/RA at bottom of frame which under the GSCookie, the FP/RA can be overwritten.

Before this change, the comment in codegenloongarch64.cpp gives the following layout:

* The LoongArch64's frame layout is liking:
*
* | |
* |-----------------------|
* | incoming arguments |
* +=======================+ <---- Caller's SP
* | Arguments Or | // if needed.
* | Varargs regs space | // Only for varargs functions; (varargs not implemented for LoongArch64)
* |-----------------------|
* | MonitorAcquired | // 8 bytes; for synchronized methods
* |-----------------------|
* | PSP slot | // 8 bytes (omitted in NativeAOT ABI)
* |-----------------------|
* | locals, temps, etc. |
* |-----------------------|
* | possible GS cookie |
* |-----------------------|
* | Saved FP | // 8 bytes
* |-----------------------|
* | Saved RA | // 8 bytes
* |-----------------------|
* |Callee saved registers | // not including FP/RA; multiple of 8 bytes
* |-----------------------|
* | Outgoing arg space | // multiple of 8 bytes; if required (i.e., #outsz != 0)
* |-----------------------| <---- Ambient SP
* | | |
* ~ | Stack grows ~
* | | downward |
* V

The GS cookie exists between the locals and FP/RA pair. I do not see how FP/RA can be overwritten without hitting the GS cookie. Was the comment wrong?

Do you mean that the FP/RA of caller's frame can be overwritten?

@jakobbotsch

Copy link
Copy Markdown
Member

If I understand correctly, the change here means you have to use negative offsets from FP to access locals more often. Does LA64/RV64 allow encoding as many negative offsets as it allows positive offsets?

@shushanhf

shushanhf commented Apr 16, 2024

Copy link
Copy Markdown
ContributorAuthor
  •  |Callee saved registers | // not including FP/RA; multiple of 8 bytes
    

The GS cookie exists between the locals and FP/RA pair. I do not see how FP/RA can be overwritten without hitting the GS cookie. Was the comment wrong?
Do you mean that the FP/RA of caller's frame can be overwritten?

The GS Cookie is only used liking the localalloc. After finished the frame allocation, when using the localalloc to allocate a new stack space, the new space maybe overwritten the new real size allocated while the GSCookie is used to recognize this case.
Before this PR which the FP/RA under GS cookie, the FP/RA maybe overwritten while the GS cookie may not recognize this.

@shushanhf

Copy link
Copy Markdown
ContributorAuthor

If I understand correctly, the change here means you have to use negative offsets from FP to access locals more often. Does LA64/RV64 allow encoding as many negative offsets as it allows positive offsets?

yes

@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch from 8601cfc to 23fc354CompareApril 16, 2024 09:22
@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch 2 times, most recently from b78f2e0 to c237762CompareApril 19, 2024 06:39
@shushanhf

Copy link
Copy Markdown
ContributorAuthor

I think the CI went wrong. e.g.

@azure-pipelines
runtime (Build Formatting linux x64) Failing after 4m — Build Formatting linux x64 failed
[Details](https://github.com/dotnet/runtime/pull/100962/checks?check_run_id=24011496326)
@azure-pipelines
runtime (Build Formatting windows x64) Failing after 7m — Build Formatting windows x64 failed

but format-patch is empty.

@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch from c237762 to feaa635CompareApril 19, 2024 09:46
@jakobbotsch

Copy link
Copy Markdown
Member

I think the CI went wrong. e.g.

@azure-pipelines
runtime (Build Formatting linux x64) Failing after 4m — Build Formatting linux x64 failed
[Details](https://github.com/dotnet/runtime/pull/100962/checks?check_run_id=24011496326)
@azure-pipelines
runtime (Build Formatting windows x64) Failing after 7m — Build Formatting windows x64 failed

but format-patch is empty.

You can run jit-format locally, see the docs at https://github.com/dotnet/jitutils and https://github.com/dotnet/jitutils/blob/main/doc/formatting.md.

@am11

am11 commented Apr 19, 2024

Copy link
Copy Markdown
Member

The underlying error shows up on Windows leg:

D:\a_work\1\s\venv\Scripts\python.exe D:\a_work\1\s/src/coreclr/scripts/jitformat.py -r D:\a_work\1\s -o windows -a x64
...
2024-04-19T09:58:48.1997764Z No cdac-build-tool set or does not exist

started happening after #100650 merge. cc @lambdageek

@jakobbotschjakobbotsch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This change looks good to me now. Thanks for addressing all the feedback! I will give RISC-V folks some time to review as well.

@tomeksowitomeksowi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@sirntar, you did more work with stack frames/OSR, could you review when you return on Monday?

@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch from feaa635 to 3092323CompareApril 20, 2024 01:14
Comment threadsrc/coreclr/jit/codegenriscv64.cpp Outdated
Comment threadsrc/coreclr/jit/codegenriscv64.cpp Outdated
to support the GSCookie.
The frame layout:
| |
|-----------------------|
| incoming arguments |
+=======================+ <---- Caller's SP
| Varargs regs space | // Only for varargs main functions; not used for LA64.
|-----------------------|
| MonitorAcquired | // 8 bytes; for synchronized methods
|-----------------------|
| PSP slot | // 8 bytes (omitted in NativeAOT ABI)
|-----------------------|
|Callee saved registers | // multiple of 8 bytes, not includting FP/RA
|-----------------------|
| Saved RA | // 8 bytes
|-----------------------|
| Saved FP | // 8 bytes
|-----------------------|
| possible GS cookie |
|-----------------------|
| locals, temps, etc. |
|-----------------------|
| possible GS cookie |
|-----------------------|
| Outgoing arg space | // multiple of 8 bytes; if required (i.e., #outsz != 0)
|-----------------------| <---- Ambient SP
| | |
~ | Stack grows ~
| | downward |
@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch from 3092323 to e254dd6CompareApril 22, 2024 07:26

@sirntarsirntar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@jakobbotsch

Copy link
Copy Markdown
Member

@shushanhf Can you please avoid amending/force pushing to PRs? It makes it hard for us to see exactly what changed and to review the new changes. If you can push them as new commits that makes it much easier. We squash every PR on merge, so the history will be cleaned up anyway.

@rzsc

rzsc commented Apr 22, 2024

Copy link
Copy Markdown
Contributor

PR tested on riscv64 architecture and ready to be merged. Thanks!

@shushanhf

shushanhf commented Apr 23, 2024

Copy link
Copy Markdown
ContributorAuthor

@shushanhf Can you please avoid amending/force pushing to PRs?

Ok, thanks, I will.

It makes it hard for us to see exactly what changed and to review the new changes. If you can push them as new commits that makes it much easier. We squash every PR on merge, so the history will be cleaned up anyway.

Sorry, I didn't know this.
I thought the github has a new button Update branch which I thought I had to update the PR's base as soon as possible.
And I thought the github reviewing is liking the gerrit which different patches within the same PR are easy to diff where independed of the base.
Maybe the github should add the similar feature.

@jakobbotsch

Copy link
Copy Markdown
Member

Thanks for helping me understand the motivation for the change, and for making LA64/RV64 more similar to ARM64 around OSR.

@jakobbotsch

Copy link
Copy Markdown
Member

@BruceForstall If you have any feedback around this then please feel free to leave it. To sum up the motivation of the change you can see #100962 (comment).

@shushanhf
shushanhf deleted the adjust_calleeSavedRegs_offset branch April 23, 2024 11:53
matouskozak pushed a commit to matouskozak/runtime that referenced this pull request Apr 30, 2024
…et#100962)
The frame layout:
| |
|-----------------------|
| incoming arguments |
+=======================+ <---- Caller's SP
| Varargs regs space | // Only for varargs main functions; not used for LA64.
|-----------------------|
| MonitorAcquired | // 8 bytes; for synchronized methods
|-----------------------|
| PSP slot | // 8 bytes (omitted in NativeAOT ABI)
|-----------------------|
|Callee saved registers | // multiple of 8 bytes, not includting FP/RA
|-----------------------|
| Saved RA | // 8 bytes
|-----------------------|
| Saved FP | // 8 bytes
|-----------------------|
| possible GS cookie |
|-----------------------|
| locals, temps, etc. |
|-----------------------|
| possible GS cookie |
|-----------------------|
| Outgoing arg space | // multiple of 8 bytes; if required (i.e., #outsz != 0)
|-----------------------| <---- Ambient SP
| | |
~ | Stack grows ~
| | downward |
michaelgsharp pushed a commit to michaelgsharp/runtime that referenced this pull request May 9, 2024
…et#100962)
The frame layout:
| |
|-----------------------|
| incoming arguments |
+=======================+ <---- Caller's SP
| Varargs regs space | // Only for varargs main functions; not used for LA64.
|-----------------------|
| MonitorAcquired | // 8 bytes; for synchronized methods
|-----------------------|
| PSP slot | // 8 bytes (omitted in NativeAOT ABI)
|-----------------------|
|Callee saved registers | // multiple of 8 bytes, not includting FP/RA
|-----------------------|
| Saved RA | // 8 bytes
|-----------------------|
| Saved FP | // 8 bytes
|-----------------------|
| possible GS cookie |
|-----------------------|
| locals, temps, etc. |
|-----------------------|
| possible GS cookie |
|-----------------------|
| Outgoing arg space | // multiple of 8 bytes; if required (i.e., #outsz != 0)
|-----------------------| <---- Ambient SP
| | |
~ | Stack grows ~
| | downward |
@github-actionsgithub-actionsBot locked and limited conversation to collaborators May 24, 2024
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

arch-loongarch64arch-riscvRelated to the RISC-V architecturearea-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIcommunity-contributionIndicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants

@shushanhf@clamp03@jakobbotsch@AndyAyersMS@bartlomiejko@am11@rzsc@tomeksowi@sirntar@Bajtazar
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Adjust the calleeSavedRegs on top frame for LoongArch64/RISCV64 - #100962

Merged
jakobbotsch merged 4 commits into
dotnet:mainfrom
shushanhf:adjust_calleeSavedRegs_offset
Apr 23, 2024
Merged

Adjust the calleeSavedRegs on top frame for LoongArch64/RISCV64#100962
jakobbotsch merged 4 commits into
dotnet:mainfrom
shushanhf:adjust_calleeSavedRegs_offset

Conversation

@shushanhf

@shushanhfshushanhf commented Apr 12, 2024

Copy link
Copy Markdown
Contributor

Adjust the calleeSavedRegs on top frame for LoongArch64/RISCV64 to support the GSCookie.

Theframelayout:
| |
|-----------------------|
| incomingarguments |
+=======================+<----Caller's SP
| Varargsregsspace | // Only for varargs main functions; not used for LA64.
|-----------------------|
| MonitorAcquired | // 8 bytes; for synchronized methods
|-----------------------|
| PSPslot | // 8 bytes (omitted in NativeAOT ABI)
|-----------------------|
|Calleesavedregisters | // multiple of 8 bytes, not including FP/RA
|-----------------------|
| SavedRA | // 8 bytes
|-----------------------|
| SavedFP | // 8 bytes
|-----------------------|
| possibleGScookie |
|-----------------------|
| locals, temps, etc. |
|-----------------------|
| possibleGScookie |
|-----------------------|
| Outgoingargspace | // multiple of 8 bytes; if required (i.e., #outsz != 0)
|-----------------------| <----AmbientSP
| | |
~ | Stackgrows ~
| | downward |

@ghostghost added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Apr 12, 2024
@dotnet-policy-servicedotnet-policy-serviceBot added the community-contribution Indicates that the PR has been added by a community member label Apr 12, 2024
@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch 5 times, most recently from 6ec45e3 to 855fdb3CompareApril 13, 2024 08:01
@am11am11 added arch-loongarch64 arch-riscv Related to the RISC-V architecture labels Apr 13, 2024
@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch 6 times, most recently from f94cc0d to cf69c78CompareApril 15, 2024 10:06
@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch from cf69c78 to 8601cfcCompareApril 16, 2024 00:44
@shushanhf

Copy link
Copy Markdown
ContributorAuthor

@jakobbotsch@clamp03
Could you please review this PR?
Thanks

@clamp03

Copy link
Copy Markdown
Member

@bartlomiejko Can you review and test this PR?
cc @dotnet/samsung

@jakobbotsch

Copy link
Copy Markdown
Member

How is the stack frame layout changed compared to previously? What was the layout before this change? Why didn't it support GS cookie?
Can you show some codegen diffs?

@shushanhf

shushanhf commented Apr 16, 2024

Copy link
Copy Markdown
ContributorAuthor

How is the stack frame layout changed compared to previously? What was the layout before this change?

Only changed the calledSavedRegs, especially the FP/RA for LA64/RV64. The layout liking this PR's first comment description #100962 (comment) .
Before this PR, the FP/RA at bottom of frame which under the GSCookie, the FP/RA can be overwritten.

Why didn't it support GS cookie? Can you show some codegen diffs?

Before this PR, the FP/RA at bottom of frame which under the GSCookie, the FP/RA can be overwritten.

Comment threadsrc/coreclr/jit/codegenloongarch64.cpp
Comment threadsrc/coreclr/jit/lclvars.cpp Outdated
@jakobbotsch

Copy link
Copy Markdown
Member

Only changed the calledSavedRegs, especially the FP/RA for LA64/RV64. The layout liking this PR's first comment description #100962 (comment) .
Before this PR, the FP/RA at bottom of frame which under the GSCookie, the FP/RA can be overwritten.

Where does FP point to in your picture? Where did it point to before?

@shushanhf

Copy link
Copy Markdown
ContributorAuthor

Only changed the calledSavedRegs, especially the FP/RA for LA64/RV64. The layout liking this PR's first comment description #100962 (comment) .
Before this PR, the FP/RA at bottom of frame which under the GSCookie, the FP/RA can be overwritten.

Where does FP point to in your picture? Where did it point to before?

The new FP is pointing to the the old FP saved slot.

Can you show some codegen diffs?

/// this is the Old one.
G_M22522_IG01: ;; offset=0x0000
0xff74a50030 02FDC063 addi.d sp, sp, -144
0xff74a50034 29C00061 st.d ra, sp, 0
0xff74a50038 29C02076 st.d fp, sp, 8
0xff74a5003c 02C02076 addi.d fp, sp, 8
0xff74a50040 02C062CC addi.d t0, fp, 24 0xff74a50044 02801407 addi.w a3, zero, 5
0xff74a50048 29C02180 st.d zero, t0, 8
0xff74a5004c 29C00180 st.d zero, t0, 0
0xff74a50050 02FFFCE7 addi.d a3, a3, -1
0xff74a50054 02C0418C addi.d t0, t0, 16 0xff74a50058 5FFFF0E0 bne a3, zero, 0xff74a50048
0xff74a5005c 29C00180 st.d zero, t0, 0
0xff74a50060 29C202C4 st.d a0, fp, 128
0xff74a50064 29C1E2C5 st.d a1, fp, 120
0xff74a50068 29C1C2C6 st.d a2, fp, 112
;; size=60 bbWeight=1 PerfScore 0.00
G_M22522_IG02: ;; offset=0x003C
/// This is the new ins.
G_M22522_IG01: ;; offset=0x0000
0xff77790030 02FDC063 addi.d sp, sp, -144
0xff77790034 29C20076 st.d fp, sp, 128
0xff77790038 29C22061 st.d ra, sp, 136
0xff7779003c 02C20076 addi.d fp, sp, 128
0xff77790040 02FE42CC addi.d t0, fp, -112
0xff77790044 02801407 addi.w a3, zero, 5
0xff77790048 29C02180 st.d zero, t0, 8
0xff7779004c 29C00180 st.d zero, t0, 0
0xff77790050 02FFFCE7 addi.d a3, a3, -1
0xff77790054 02C0418C addi.d t0, t0, 16 0xff77790058 5FFFF0E0 bne a3, zero, 0xff77790048 /// the upstream's disasm format had been updated.
0xff7779005c 29C00180 st.d zero, t0, 0
0xff77790060 29FFE2C4 st.d a0, fp, -8
0xff77790064 29FFC2C5 st.d a1, fp, -16
0xff77790068 29FFA2C6 st.d a2, fp, -24
;; size=60 bbWeight=1 PerfScore 0.00

@jakobbotsch

Copy link
Copy Markdown
Member

Before this PR, the FP/RA at bottom of frame which under the GSCookie, the FP/RA can be overwritten.

Before this change, the comment in codegenloongarch64.cpp gives the following layout:

* The LoongArch64's frame layout is liking:
*
* | |
* |-----------------------|
* | incoming arguments |
* +=======================+ <---- Caller's SP
* | Arguments Or | // if needed.
* | Varargs regs space | // Only for varargs functions; (varargs not implemented for LoongArch64)
* |-----------------------|
* | MonitorAcquired | // 8 bytes; for synchronized methods
* |-----------------------|
* | PSP slot | // 8 bytes (omitted in NativeAOT ABI)
* |-----------------------|
* | locals, temps, etc. |
* |-----------------------|
* | possible GS cookie |
* |-----------------------|
* | Saved FP | // 8 bytes
* |-----------------------|
* | Saved RA | // 8 bytes
* |-----------------------|
* |Callee saved registers | // not including FP/RA; multiple of 8 bytes
* |-----------------------|
* | Outgoing arg space | // multiple of 8 bytes; if required (i.e., #outsz != 0)
* |-----------------------| <---- Ambient SP
* | | |
* ~ | Stack grows ~
* | | downward |
* V

The GS cookie exists between the locals and FP/RA pair. I do not see how FP/RA can be overwritten without hitting the GS cookie. Was the comment wrong?

Do you mean that the FP/RA of caller's frame can be overwritten?

@jakobbotsch

Copy link
Copy Markdown
Member

If I understand correctly, the change here means you have to use negative offsets from FP to access locals more often. Does LA64/RV64 allow encoding as many negative offsets as it allows positive offsets?

@shushanhf

shushanhf commented Apr 16, 2024

Copy link
Copy Markdown
ContributorAuthor
  •  |Callee saved registers | // not including FP/RA; multiple of 8 bytes
    

The GS cookie exists between the locals and FP/RA pair. I do not see how FP/RA can be overwritten without hitting the GS cookie. Was the comment wrong?
Do you mean that the FP/RA of caller's frame can be overwritten?

The GS Cookie is only used liking the localalloc. After finished the frame allocation, when using the localalloc to allocate a new stack space, the new space maybe overwritten the new real size allocated while the GSCookie is used to recognize this case.
Before this PR which the FP/RA under GS cookie, the FP/RA maybe overwritten while the GS cookie may not recognize this.

@shushanhf

Copy link
Copy Markdown
ContributorAuthor

If I understand correctly, the change here means you have to use negative offsets from FP to access locals more often. Does LA64/RV64 allow encoding as many negative offsets as it allows positive offsets?

yes

@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch from 8601cfc to 23fc354CompareApril 16, 2024 09:22
@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch 2 times, most recently from b78f2e0 to c237762CompareApril 19, 2024 06:39
@shushanhf

Copy link
Copy Markdown
ContributorAuthor

I think the CI went wrong. e.g.

@azure-pipelines
runtime (Build Formatting linux x64) Failing after 4m — Build Formatting linux x64 failed
[Details](https://github.com/dotnet/runtime/pull/100962/checks?check_run_id=24011496326)
@azure-pipelines
runtime (Build Formatting windows x64) Failing after 7m — Build Formatting windows x64 failed

but format-patch is empty.

@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch from c237762 to feaa635CompareApril 19, 2024 09:46
@jakobbotsch

Copy link
Copy Markdown
Member

I think the CI went wrong. e.g.

@azure-pipelines
runtime (Build Formatting linux x64) Failing after 4m — Build Formatting linux x64 failed
[Details](https://github.com/dotnet/runtime/pull/100962/checks?check_run_id=24011496326)
@azure-pipelines
runtime (Build Formatting windows x64) Failing after 7m — Build Formatting windows x64 failed

but format-patch is empty.

You can run jit-format locally, see the docs at https://github.com/dotnet/jitutils and https://github.com/dotnet/jitutils/blob/main/doc/formatting.md.

@am11

am11 commented Apr 19, 2024

Copy link
Copy Markdown
Member

The underlying error shows up on Windows leg:

D:\a_work\1\s\venv\Scripts\python.exe D:\a_work\1\s/src/coreclr/scripts/jitformat.py -r D:\a_work\1\s -o windows -a x64
...
2024-04-19T09:58:48.1997764Z No cdac-build-tool set or does not exist

started happening after #100650 merge. cc @lambdageek

@jakobbotschjakobbotsch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This change looks good to me now. Thanks for addressing all the feedback! I will give RISC-V folks some time to review as well.

@tomeksowitomeksowi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@sirntar, you did more work with stack frames/OSR, could you review when you return on Monday?

@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch from feaa635 to 3092323CompareApril 20, 2024 01:14
Comment threadsrc/coreclr/jit/codegenriscv64.cpp Outdated
Comment threadsrc/coreclr/jit/codegenriscv64.cpp Outdated
to support the GSCookie.
The frame layout:
| |
|-----------------------|
| incoming arguments |
+=======================+ <---- Caller's SP
| Varargs regs space | // Only for varargs main functions; not used for LA64.
|-----------------------|
| MonitorAcquired | // 8 bytes; for synchronized methods
|-----------------------|
| PSP slot | // 8 bytes (omitted in NativeAOT ABI)
|-----------------------|
|Callee saved registers | // multiple of 8 bytes, not includting FP/RA
|-----------------------|
| Saved RA | // 8 bytes
|-----------------------|
| Saved FP | // 8 bytes
|-----------------------|
| possible GS cookie |
|-----------------------|
| locals, temps, etc. |
|-----------------------|
| possible GS cookie |
|-----------------------|
| Outgoing arg space | // multiple of 8 bytes; if required (i.e., #outsz != 0)
|-----------------------| <---- Ambient SP
| | |
~ | Stack grows ~
| | downward |
@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch from 3092323 to e254dd6CompareApril 22, 2024 07:26

@sirntarsirntar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@jakobbotsch

Copy link
Copy Markdown
Member

@shushanhf Can you please avoid amending/force pushing to PRs? It makes it hard for us to see exactly what changed and to review the new changes. If you can push them as new commits that makes it much easier. We squash every PR on merge, so the history will be cleaned up anyway.

@rzsc

rzsc commented Apr 22, 2024

Copy link
Copy Markdown
Contributor

PR tested on riscv64 architecture and ready to be merged. Thanks!

@shushanhf

shushanhf commented Apr 23, 2024

Copy link
Copy Markdown
ContributorAuthor

@shushanhf Can you please avoid amending/force pushing to PRs?

Ok, thanks, I will.

It makes it hard for us to see exactly what changed and to review the new changes. If you can push them as new commits that makes it much easier. We squash every PR on merge, so the history will be cleaned up anyway.

Sorry, I didn't know this.
I thought the github has a new button Update branch which I thought I had to update the PR's base as soon as possible.
And I thought the github reviewing is liking the gerrit which different patches within the same PR are easy to diff where independed of the base.
Maybe the github should add the similar feature.

@jakobbotsch

Copy link
Copy Markdown
Member

Thanks for helping me understand the motivation for the change, and for making LA64/RV64 more similar to ARM64 around OSR.

@jakobbotsch

Copy link
Copy Markdown
Member

@BruceForstall If you have any feedback around this then please feel free to leave it. To sum up the motivation of the change you can see #100962 (comment).

@shushanhf
shushanhf deleted the adjust_calleeSavedRegs_offset branch April 23, 2024 11:53
matouskozak pushed a commit to matouskozak/runtime that referenced this pull request Apr 30, 2024
…et#100962)
The frame layout:
| |
|-----------------------|
| incoming arguments |
+=======================+ <---- Caller's SP
| Varargs regs space | // Only for varargs main functions; not used for LA64.
|-----------------------|
| MonitorAcquired | // 8 bytes; for synchronized methods
|-----------------------|
| PSP slot | // 8 bytes (omitted in NativeAOT ABI)
|-----------------------|
|Callee saved registers | // multiple of 8 bytes, not includting FP/RA
|-----------------------|
| Saved RA | // 8 bytes
|-----------------------|
| Saved FP | // 8 bytes
|-----------------------|
| possible GS cookie |
|-----------------------|
| locals, temps, etc. |
|-----------------------|
| possible GS cookie |
|-----------------------|
| Outgoing arg space | // multiple of 8 bytes; if required (i.e., #outsz != 0)
|-----------------------| <---- Ambient SP
| | |
~ | Stack grows ~
| | downward |
michaelgsharp pushed a commit to michaelgsharp/runtime that referenced this pull request May 9, 2024
…et#100962)
The frame layout:
| |
|-----------------------|
| incoming arguments |
+=======================+ <---- Caller's SP
| Varargs regs space | // Only for varargs main functions; not used for LA64.
|-----------------------|
| MonitorAcquired | // 8 bytes; for synchronized methods
|-----------------------|
| PSP slot | // 8 bytes (omitted in NativeAOT ABI)
|-----------------------|
|Callee saved registers | // multiple of 8 bytes, not includting FP/RA
|-----------------------|
| Saved RA | // 8 bytes
|-----------------------|
| Saved FP | // 8 bytes
|-----------------------|
| possible GS cookie |
|-----------------------|
| locals, temps, etc. |
|-----------------------|
| possible GS cookie |
|-----------------------|
| Outgoing arg space | // multiple of 8 bytes; if required (i.e., #outsz != 0)
|-----------------------| <---- Ambient SP
| | |
~ | Stack grows ~
| | downward |
@github-actionsgithub-actionsBot locked and limited conversation to collaborators May 24, 2024
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

arch-loongarch64arch-riscvRelated to the RISC-V architecturearea-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIcommunity-contributionIndicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants

@shushanhf@clamp03@jakobbotsch@AndyAyersMS@bartlomiejko@am11@rzsc@tomeksowi@sirntar@Bajtazar
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Adjust the calleeSavedRegs on top frame for LoongArch64/RISCV64 - #100962

Merged
jakobbotsch merged 4 commits into
dotnet:mainfrom
shushanhf:adjust_calleeSavedRegs_offset
Apr 23, 2024
Merged

Adjust the calleeSavedRegs on top frame for LoongArch64/RISCV64#100962
jakobbotsch merged 4 commits into
dotnet:mainfrom
shushanhf:adjust_calleeSavedRegs_offset

Conversation

@shushanhf

@shushanhfshushanhf commented Apr 12, 2024

Copy link
Copy Markdown
Contributor

Adjust the calleeSavedRegs on top frame for LoongArch64/RISCV64 to support the GSCookie.

Theframelayout:
| |
|-----------------------|
| incomingarguments |
+=======================+<----Caller's SP
| Varargsregsspace | // Only for varargs main functions; not used for LA64.
|-----------------------|
| MonitorAcquired | // 8 bytes; for synchronized methods
|-----------------------|
| PSPslot | // 8 bytes (omitted in NativeAOT ABI)
|-----------------------|
|Calleesavedregisters | // multiple of 8 bytes, not including FP/RA
|-----------------------|
| SavedRA | // 8 bytes
|-----------------------|
| SavedFP | // 8 bytes
|-----------------------|
| possibleGScookie |
|-----------------------|
| locals, temps, etc. |
|-----------------------|
| possibleGScookie |
|-----------------------|
| Outgoingargspace | // multiple of 8 bytes; if required (i.e., #outsz != 0)
|-----------------------| <----AmbientSP
| | |
~ | Stackgrows ~
| | downward |

@ghostghost added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Apr 12, 2024
@dotnet-policy-servicedotnet-policy-serviceBot added the community-contribution Indicates that the PR has been added by a community member label Apr 12, 2024
@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch 5 times, most recently from 6ec45e3 to 855fdb3CompareApril 13, 2024 08:01
@am11am11 added arch-loongarch64 arch-riscv Related to the RISC-V architecture labels Apr 13, 2024
@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch 6 times, most recently from f94cc0d to cf69c78CompareApril 15, 2024 10:06
@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch from cf69c78 to 8601cfcCompareApril 16, 2024 00:44
@shushanhf

Copy link
Copy Markdown
ContributorAuthor

@jakobbotsch@clamp03
Could you please review this PR?
Thanks

@clamp03

Copy link
Copy Markdown
Member

@bartlomiejko Can you review and test this PR?
cc @dotnet/samsung

@jakobbotsch

Copy link
Copy Markdown
Member

How is the stack frame layout changed compared to previously? What was the layout before this change? Why didn't it support GS cookie?
Can you show some codegen diffs?

@shushanhf

shushanhf commented Apr 16, 2024

Copy link
Copy Markdown
ContributorAuthor

How is the stack frame layout changed compared to previously? What was the layout before this change?

Only changed the calledSavedRegs, especially the FP/RA for LA64/RV64. The layout liking this PR's first comment description #100962 (comment) .
Before this PR, the FP/RA at bottom of frame which under the GSCookie, the FP/RA can be overwritten.

Why didn't it support GS cookie? Can you show some codegen diffs?

Before this PR, the FP/RA at bottom of frame which under the GSCookie, the FP/RA can be overwritten.

Comment threadsrc/coreclr/jit/codegenloongarch64.cpp
Comment threadsrc/coreclr/jit/lclvars.cpp Outdated
@jakobbotsch

Copy link
Copy Markdown
Member

Only changed the calledSavedRegs, especially the FP/RA for LA64/RV64. The layout liking this PR's first comment description #100962 (comment) .
Before this PR, the FP/RA at bottom of frame which under the GSCookie, the FP/RA can be overwritten.

Where does FP point to in your picture? Where did it point to before?

@shushanhf

Copy link
Copy Markdown
ContributorAuthor

Only changed the calledSavedRegs, especially the FP/RA for LA64/RV64. The layout liking this PR's first comment description #100962 (comment) .
Before this PR, the FP/RA at bottom of frame which under the GSCookie, the FP/RA can be overwritten.

Where does FP point to in your picture? Where did it point to before?

The new FP is pointing to the the old FP saved slot.

Can you show some codegen diffs?

/// this is the Old one.
G_M22522_IG01: ;; offset=0x0000
0xff74a50030 02FDC063 addi.d sp, sp, -144
0xff74a50034 29C00061 st.d ra, sp, 0
0xff74a50038 29C02076 st.d fp, sp, 8
0xff74a5003c 02C02076 addi.d fp, sp, 8
0xff74a50040 02C062CC addi.d t0, fp, 24 0xff74a50044 02801407 addi.w a3, zero, 5
0xff74a50048 29C02180 st.d zero, t0, 8
0xff74a5004c 29C00180 st.d zero, t0, 0
0xff74a50050 02FFFCE7 addi.d a3, a3, -1
0xff74a50054 02C0418C addi.d t0, t0, 16 0xff74a50058 5FFFF0E0 bne a3, zero, 0xff74a50048
0xff74a5005c 29C00180 st.d zero, t0, 0
0xff74a50060 29C202C4 st.d a0, fp, 128
0xff74a50064 29C1E2C5 st.d a1, fp, 120
0xff74a50068 29C1C2C6 st.d a2, fp, 112
;; size=60 bbWeight=1 PerfScore 0.00
G_M22522_IG02: ;; offset=0x003C
/// This is the new ins.
G_M22522_IG01: ;; offset=0x0000
0xff77790030 02FDC063 addi.d sp, sp, -144
0xff77790034 29C20076 st.d fp, sp, 128
0xff77790038 29C22061 st.d ra, sp, 136
0xff7779003c 02C20076 addi.d fp, sp, 128
0xff77790040 02FE42CC addi.d t0, fp, -112
0xff77790044 02801407 addi.w a3, zero, 5
0xff77790048 29C02180 st.d zero, t0, 8
0xff7779004c 29C00180 st.d zero, t0, 0
0xff77790050 02FFFCE7 addi.d a3, a3, -1
0xff77790054 02C0418C addi.d t0, t0, 16 0xff77790058 5FFFF0E0 bne a3, zero, 0xff77790048 /// the upstream's disasm format had been updated.
0xff7779005c 29C00180 st.d zero, t0, 0
0xff77790060 29FFE2C4 st.d a0, fp, -8
0xff77790064 29FFC2C5 st.d a1, fp, -16
0xff77790068 29FFA2C6 st.d a2, fp, -24
;; size=60 bbWeight=1 PerfScore 0.00

@jakobbotsch

Copy link
Copy Markdown
Member

Before this PR, the FP/RA at bottom of frame which under the GSCookie, the FP/RA can be overwritten.

Before this change, the comment in codegenloongarch64.cpp gives the following layout:

* The LoongArch64's frame layout is liking:
*
* | |
* |-----------------------|
* | incoming arguments |
* +=======================+ <---- Caller's SP
* | Arguments Or | // if needed.
* | Varargs regs space | // Only for varargs functions; (varargs not implemented for LoongArch64)
* |-----------------------|
* | MonitorAcquired | // 8 bytes; for synchronized methods
* |-----------------------|
* | PSP slot | // 8 bytes (omitted in NativeAOT ABI)
* |-----------------------|
* | locals, temps, etc. |
* |-----------------------|
* | possible GS cookie |
* |-----------------------|
* | Saved FP | // 8 bytes
* |-----------------------|
* | Saved RA | // 8 bytes
* |-----------------------|
* |Callee saved registers | // not including FP/RA; multiple of 8 bytes
* |-----------------------|
* | Outgoing arg space | // multiple of 8 bytes; if required (i.e., #outsz != 0)
* |-----------------------| <---- Ambient SP
* | | |
* ~ | Stack grows ~
* | | downward |
* V

The GS cookie exists between the locals and FP/RA pair. I do not see how FP/RA can be overwritten without hitting the GS cookie. Was the comment wrong?

Do you mean that the FP/RA of caller's frame can be overwritten?

@jakobbotsch

Copy link
Copy Markdown
Member

If I understand correctly, the change here means you have to use negative offsets from FP to access locals more often. Does LA64/RV64 allow encoding as many negative offsets as it allows positive offsets?

@shushanhf

shushanhf commented Apr 16, 2024

Copy link
Copy Markdown
ContributorAuthor
  •  |Callee saved registers | // not including FP/RA; multiple of 8 bytes
    

The GS cookie exists between the locals and FP/RA pair. I do not see how FP/RA can be overwritten without hitting the GS cookie. Was the comment wrong?
Do you mean that the FP/RA of caller's frame can be overwritten?

The GS Cookie is only used liking the localalloc. After finished the frame allocation, when using the localalloc to allocate a new stack space, the new space maybe overwritten the new real size allocated while the GSCookie is used to recognize this case.
Before this PR which the FP/RA under GS cookie, the FP/RA maybe overwritten while the GS cookie may not recognize this.

@shushanhf

Copy link
Copy Markdown
ContributorAuthor

If I understand correctly, the change here means you have to use negative offsets from FP to access locals more often. Does LA64/RV64 allow encoding as many negative offsets as it allows positive offsets?

yes

@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch from 8601cfc to 23fc354CompareApril 16, 2024 09:22
@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch 2 times, most recently from b78f2e0 to c237762CompareApril 19, 2024 06:39
@shushanhf

Copy link
Copy Markdown
ContributorAuthor

I think the CI went wrong. e.g.

@azure-pipelines
runtime (Build Formatting linux x64) Failing after 4m — Build Formatting linux x64 failed
[Details](https://github.com/dotnet/runtime/pull/100962/checks?check_run_id=24011496326)
@azure-pipelines
runtime (Build Formatting windows x64) Failing after 7m — Build Formatting windows x64 failed

but format-patch is empty.

@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch from c237762 to feaa635CompareApril 19, 2024 09:46
@jakobbotsch

Copy link
Copy Markdown
Member

I think the CI went wrong. e.g.

@azure-pipelines
runtime (Build Formatting linux x64) Failing after 4m — Build Formatting linux x64 failed
[Details](https://github.com/dotnet/runtime/pull/100962/checks?check_run_id=24011496326)
@azure-pipelines
runtime (Build Formatting windows x64) Failing after 7m — Build Formatting windows x64 failed

but format-patch is empty.

You can run jit-format locally, see the docs at https://github.com/dotnet/jitutils and https://github.com/dotnet/jitutils/blob/main/doc/formatting.md.

@am11

am11 commented Apr 19, 2024

Copy link
Copy Markdown
Member

The underlying error shows up on Windows leg:

D:\a_work\1\s\venv\Scripts\python.exe D:\a_work\1\s/src/coreclr/scripts/jitformat.py -r D:\a_work\1\s -o windows -a x64
...
2024-04-19T09:58:48.1997764Z No cdac-build-tool set or does not exist

started happening after #100650 merge. cc @lambdageek

@jakobbotschjakobbotsch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This change looks good to me now. Thanks for addressing all the feedback! I will give RISC-V folks some time to review as well.

@tomeksowitomeksowi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@sirntar, you did more work with stack frames/OSR, could you review when you return on Monday?

@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch from feaa635 to 3092323CompareApril 20, 2024 01:14
Comment threadsrc/coreclr/jit/codegenriscv64.cpp Outdated
Comment threadsrc/coreclr/jit/codegenriscv64.cpp Outdated
to support the GSCookie.
The frame layout:
| |
|-----------------------|
| incoming arguments |
+=======================+ <---- Caller's SP
| Varargs regs space | // Only for varargs main functions; not used for LA64.
|-----------------------|
| MonitorAcquired | // 8 bytes; for synchronized methods
|-----------------------|
| PSP slot | // 8 bytes (omitted in NativeAOT ABI)
|-----------------------|
|Callee saved registers | // multiple of 8 bytes, not includting FP/RA
|-----------------------|
| Saved RA | // 8 bytes
|-----------------------|
| Saved FP | // 8 bytes
|-----------------------|
| possible GS cookie |
|-----------------------|
| locals, temps, etc. |
|-----------------------|
| possible GS cookie |
|-----------------------|
| Outgoing arg space | // multiple of 8 bytes; if required (i.e., #outsz != 0)
|-----------------------| <---- Ambient SP
| | |
~ | Stack grows ~
| | downward |
@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch from 3092323 to e254dd6CompareApril 22, 2024 07:26

@sirntarsirntar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@jakobbotsch

Copy link
Copy Markdown
Member

@shushanhf Can you please avoid amending/force pushing to PRs? It makes it hard for us to see exactly what changed and to review the new changes. If you can push them as new commits that makes it much easier. We squash every PR on merge, so the history will be cleaned up anyway.

@rzsc

rzsc commented Apr 22, 2024

Copy link
Copy Markdown
Contributor

PR tested on riscv64 architecture and ready to be merged. Thanks!

@shushanhf

shushanhf commented Apr 23, 2024

Copy link
Copy Markdown
ContributorAuthor

@shushanhf Can you please avoid amending/force pushing to PRs?

Ok, thanks, I will.

It makes it hard for us to see exactly what changed and to review the new changes. If you can push them as new commits that makes it much easier. We squash every PR on merge, so the history will be cleaned up anyway.

Sorry, I didn't know this.
I thought the github has a new button Update branch which I thought I had to update the PR's base as soon as possible.
And I thought the github reviewing is liking the gerrit which different patches within the same PR are easy to diff where independed of the base.
Maybe the github should add the similar feature.

@jakobbotsch

Copy link
Copy Markdown
Member

Thanks for helping me understand the motivation for the change, and for making LA64/RV64 more similar to ARM64 around OSR.

@jakobbotsch

Copy link
Copy Markdown
Member

@BruceForstall If you have any feedback around this then please feel free to leave it. To sum up the motivation of the change you can see #100962 (comment).

@shushanhf
shushanhf deleted the adjust_calleeSavedRegs_offset branch April 23, 2024 11:53
matouskozak pushed a commit to matouskozak/runtime that referenced this pull request Apr 30, 2024
…et#100962)
The frame layout:
| |
|-----------------------|
| incoming arguments |
+=======================+ <---- Caller's SP
| Varargs regs space | // Only for varargs main functions; not used for LA64.
|-----------------------|
| MonitorAcquired | // 8 bytes; for synchronized methods
|-----------------------|
| PSP slot | // 8 bytes (omitted in NativeAOT ABI)
|-----------------------|
|Callee saved registers | // multiple of 8 bytes, not includting FP/RA
|-----------------------|
| Saved RA | // 8 bytes
|-----------------------|
| Saved FP | // 8 bytes
|-----------------------|
| possible GS cookie |
|-----------------------|
| locals, temps, etc. |
|-----------------------|
| possible GS cookie |
|-----------------------|
| Outgoing arg space | // multiple of 8 bytes; if required (i.e., #outsz != 0)
|-----------------------| <---- Ambient SP
| | |
~ | Stack grows ~
| | downward |
michaelgsharp pushed a commit to michaelgsharp/runtime that referenced this pull request May 9, 2024
…et#100962)
The frame layout:
| |
|-----------------------|
| incoming arguments |
+=======================+ <---- Caller's SP
| Varargs regs space | // Only for varargs main functions; not used for LA64.
|-----------------------|
| MonitorAcquired | // 8 bytes; for synchronized methods
|-----------------------|
| PSP slot | // 8 bytes (omitted in NativeAOT ABI)
|-----------------------|
|Callee saved registers | // multiple of 8 bytes, not includting FP/RA
|-----------------------|
| Saved RA | // 8 bytes
|-----------------------|
| Saved FP | // 8 bytes
|-----------------------|
| possible GS cookie |
|-----------------------|
| locals, temps, etc. |
|-----------------------|
| possible GS cookie |
|-----------------------|
| Outgoing arg space | // multiple of 8 bytes; if required (i.e., #outsz != 0)
|-----------------------| <---- Ambient SP
| | |
~ | Stack grows ~
| | downward |
@github-actionsgithub-actionsBot locked and limited conversation to collaborators May 24, 2024
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

arch-loongarch64arch-riscvRelated to the RISC-V architecturearea-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIcommunity-contributionIndicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants

@shushanhf@clamp03@jakobbotsch@AndyAyersMS@bartlomiejko@am11@rzsc@tomeksowi@sirntar@Bajtazar
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Adjust the calleeSavedRegs on top frame for LoongArch64/RISCV64 - #100962

Merged
jakobbotsch merged 4 commits into
dotnet:mainfrom
shushanhf:adjust_calleeSavedRegs_offset
Apr 23, 2024
Merged

Adjust the calleeSavedRegs on top frame for LoongArch64/RISCV64#100962
jakobbotsch merged 4 commits into
dotnet:mainfrom
shushanhf:adjust_calleeSavedRegs_offset

Conversation

@shushanhf

@shushanhfshushanhf commented Apr 12, 2024

Copy link
Copy Markdown
Contributor

Adjust the calleeSavedRegs on top frame for LoongArch64/RISCV64 to support the GSCookie.

Theframelayout:
| |
|-----------------------|
| incomingarguments |
+=======================+<----Caller's SP
| Varargsregsspace | // Only for varargs main functions; not used for LA64.
|-----------------------|
| MonitorAcquired | // 8 bytes; for synchronized methods
|-----------------------|
| PSPslot | // 8 bytes (omitted in NativeAOT ABI)
|-----------------------|
|Calleesavedregisters | // multiple of 8 bytes, not including FP/RA
|-----------------------|
| SavedRA | // 8 bytes
|-----------------------|
| SavedFP | // 8 bytes
|-----------------------|
| possibleGScookie |
|-----------------------|
| locals, temps, etc. |
|-----------------------|
| possibleGScookie |
|-----------------------|
| Outgoingargspace | // multiple of 8 bytes; if required (i.e., #outsz != 0)
|-----------------------| <----AmbientSP
| | |
~ | Stackgrows ~
| | downward |

@ghostghost added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Apr 12, 2024
@dotnet-policy-servicedotnet-policy-serviceBot added the community-contribution Indicates that the PR has been added by a community member label Apr 12, 2024
@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch 5 times, most recently from 6ec45e3 to 855fdb3CompareApril 13, 2024 08:01
@am11am11 added arch-loongarch64 arch-riscv Related to the RISC-V architecture labels Apr 13, 2024
@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch 6 times, most recently from f94cc0d to cf69c78CompareApril 15, 2024 10:06
@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch from cf69c78 to 8601cfcCompareApril 16, 2024 00:44
@shushanhf

Copy link
Copy Markdown
ContributorAuthor

@jakobbotsch@clamp03
Could you please review this PR?
Thanks

@clamp03

Copy link
Copy Markdown
Member

@bartlomiejko Can you review and test this PR?
cc @dotnet/samsung

@jakobbotsch

Copy link
Copy Markdown
Member

How is the stack frame layout changed compared to previously? What was the layout before this change? Why didn't it support GS cookie?
Can you show some codegen diffs?

@shushanhf

shushanhf commented Apr 16, 2024

Copy link
Copy Markdown
ContributorAuthor

How is the stack frame layout changed compared to previously? What was the layout before this change?

Only changed the calledSavedRegs, especially the FP/RA for LA64/RV64. The layout liking this PR's first comment description #100962 (comment) .
Before this PR, the FP/RA at bottom of frame which under the GSCookie, the FP/RA can be overwritten.

Why didn't it support GS cookie? Can you show some codegen diffs?

Before this PR, the FP/RA at bottom of frame which under the GSCookie, the FP/RA can be overwritten.

Comment threadsrc/coreclr/jit/codegenloongarch64.cpp
Comment threadsrc/coreclr/jit/lclvars.cpp Outdated
@jakobbotsch

Copy link
Copy Markdown
Member

Only changed the calledSavedRegs, especially the FP/RA for LA64/RV64. The layout liking this PR's first comment description #100962 (comment) .
Before this PR, the FP/RA at bottom of frame which under the GSCookie, the FP/RA can be overwritten.

Where does FP point to in your picture? Where did it point to before?

@shushanhf

Copy link
Copy Markdown
ContributorAuthor

Only changed the calledSavedRegs, especially the FP/RA for LA64/RV64. The layout liking this PR's first comment description #100962 (comment) .
Before this PR, the FP/RA at bottom of frame which under the GSCookie, the FP/RA can be overwritten.

Where does FP point to in your picture? Where did it point to before?

The new FP is pointing to the the old FP saved slot.

Can you show some codegen diffs?

/// this is the Old one.
G_M22522_IG01: ;; offset=0x0000
0xff74a50030 02FDC063 addi.d sp, sp, -144
0xff74a50034 29C00061 st.d ra, sp, 0
0xff74a50038 29C02076 st.d fp, sp, 8
0xff74a5003c 02C02076 addi.d fp, sp, 8
0xff74a50040 02C062CC addi.d t0, fp, 24 0xff74a50044 02801407 addi.w a3, zero, 5
0xff74a50048 29C02180 st.d zero, t0, 8
0xff74a5004c 29C00180 st.d zero, t0, 0
0xff74a50050 02FFFCE7 addi.d a3, a3, -1
0xff74a50054 02C0418C addi.d t0, t0, 16 0xff74a50058 5FFFF0E0 bne a3, zero, 0xff74a50048
0xff74a5005c 29C00180 st.d zero, t0, 0
0xff74a50060 29C202C4 st.d a0, fp, 128
0xff74a50064 29C1E2C5 st.d a1, fp, 120
0xff74a50068 29C1C2C6 st.d a2, fp, 112
;; size=60 bbWeight=1 PerfScore 0.00
G_M22522_IG02: ;; offset=0x003C
/// This is the new ins.
G_M22522_IG01: ;; offset=0x0000
0xff77790030 02FDC063 addi.d sp, sp, -144
0xff77790034 29C20076 st.d fp, sp, 128
0xff77790038 29C22061 st.d ra, sp, 136
0xff7779003c 02C20076 addi.d fp, sp, 128
0xff77790040 02FE42CC addi.d t0, fp, -112
0xff77790044 02801407 addi.w a3, zero, 5
0xff77790048 29C02180 st.d zero, t0, 8
0xff7779004c 29C00180 st.d zero, t0, 0
0xff77790050 02FFFCE7 addi.d a3, a3, -1
0xff77790054 02C0418C addi.d t0, t0, 16 0xff77790058 5FFFF0E0 bne a3, zero, 0xff77790048 /// the upstream's disasm format had been updated.
0xff7779005c 29C00180 st.d zero, t0, 0
0xff77790060 29FFE2C4 st.d a0, fp, -8
0xff77790064 29FFC2C5 st.d a1, fp, -16
0xff77790068 29FFA2C6 st.d a2, fp, -24
;; size=60 bbWeight=1 PerfScore 0.00

@jakobbotsch

Copy link
Copy Markdown
Member

Before this PR, the FP/RA at bottom of frame which under the GSCookie, the FP/RA can be overwritten.

Before this change, the comment in codegenloongarch64.cpp gives the following layout:

* The LoongArch64's frame layout is liking:
*
* | |
* |-----------------------|
* | incoming arguments |
* +=======================+ <---- Caller's SP
* | Arguments Or | // if needed.
* | Varargs regs space | // Only for varargs functions; (varargs not implemented for LoongArch64)
* |-----------------------|
* | MonitorAcquired | // 8 bytes; for synchronized methods
* |-----------------------|
* | PSP slot | // 8 bytes (omitted in NativeAOT ABI)
* |-----------------------|
* | locals, temps, etc. |
* |-----------------------|
* | possible GS cookie |
* |-----------------------|
* | Saved FP | // 8 bytes
* |-----------------------|
* | Saved RA | // 8 bytes
* |-----------------------|
* |Callee saved registers | // not including FP/RA; multiple of 8 bytes
* |-----------------------|
* | Outgoing arg space | // multiple of 8 bytes; if required (i.e., #outsz != 0)
* |-----------------------| <---- Ambient SP
* | | |
* ~ | Stack grows ~
* | | downward |
* V

The GS cookie exists between the locals and FP/RA pair. I do not see how FP/RA can be overwritten without hitting the GS cookie. Was the comment wrong?

Do you mean that the FP/RA of caller's frame can be overwritten?

@jakobbotsch

Copy link
Copy Markdown
Member

If I understand correctly, the change here means you have to use negative offsets from FP to access locals more often. Does LA64/RV64 allow encoding as many negative offsets as it allows positive offsets?

@shushanhf

shushanhf commented Apr 16, 2024

Copy link
Copy Markdown
ContributorAuthor
  •  |Callee saved registers | // not including FP/RA; multiple of 8 bytes
    

The GS cookie exists between the locals and FP/RA pair. I do not see how FP/RA can be overwritten without hitting the GS cookie. Was the comment wrong?
Do you mean that the FP/RA of caller's frame can be overwritten?

The GS Cookie is only used liking the localalloc. After finished the frame allocation, when using the localalloc to allocate a new stack space, the new space maybe overwritten the new real size allocated while the GSCookie is used to recognize this case.
Before this PR which the FP/RA under GS cookie, the FP/RA maybe overwritten while the GS cookie may not recognize this.

@shushanhf

Copy link
Copy Markdown
ContributorAuthor

If I understand correctly, the change here means you have to use negative offsets from FP to access locals more often. Does LA64/RV64 allow encoding as many negative offsets as it allows positive offsets?

yes

@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch from 8601cfc to 23fc354CompareApril 16, 2024 09:22
@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch 2 times, most recently from b78f2e0 to c237762CompareApril 19, 2024 06:39
@shushanhf

Copy link
Copy Markdown
ContributorAuthor

I think the CI went wrong. e.g.

@azure-pipelines
runtime (Build Formatting linux x64) Failing after 4m — Build Formatting linux x64 failed
[Details](https://github.com/dotnet/runtime/pull/100962/checks?check_run_id=24011496326)
@azure-pipelines
runtime (Build Formatting windows x64) Failing after 7m — Build Formatting windows x64 failed

but format-patch is empty.

@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch from c237762 to feaa635CompareApril 19, 2024 09:46
@jakobbotsch

Copy link
Copy Markdown
Member

I think the CI went wrong. e.g.

@azure-pipelines
runtime (Build Formatting linux x64) Failing after 4m — Build Formatting linux x64 failed
[Details](https://github.com/dotnet/runtime/pull/100962/checks?check_run_id=24011496326)
@azure-pipelines
runtime (Build Formatting windows x64) Failing after 7m — Build Formatting windows x64 failed

but format-patch is empty.

You can run jit-format locally, see the docs at https://github.com/dotnet/jitutils and https://github.com/dotnet/jitutils/blob/main/doc/formatting.md.

@am11

am11 commented Apr 19, 2024

Copy link
Copy Markdown
Member

The underlying error shows up on Windows leg:

D:\a_work\1\s\venv\Scripts\python.exe D:\a_work\1\s/src/coreclr/scripts/jitformat.py -r D:\a_work\1\s -o windows -a x64
...
2024-04-19T09:58:48.1997764Z No cdac-build-tool set or does not exist

started happening after #100650 merge. cc @lambdageek

@jakobbotschjakobbotsch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This change looks good to me now. Thanks for addressing all the feedback! I will give RISC-V folks some time to review as well.

@tomeksowitomeksowi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@sirntar, you did more work with stack frames/OSR, could you review when you return on Monday?

@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch from feaa635 to 3092323CompareApril 20, 2024 01:14
Comment threadsrc/coreclr/jit/codegenriscv64.cpp Outdated
Comment threadsrc/coreclr/jit/codegenriscv64.cpp Outdated
to support the GSCookie.
The frame layout:
| |
|-----------------------|
| incoming arguments |
+=======================+ <---- Caller's SP
| Varargs regs space | // Only for varargs main functions; not used for LA64.
|-----------------------|
| MonitorAcquired | // 8 bytes; for synchronized methods
|-----------------------|
| PSP slot | // 8 bytes (omitted in NativeAOT ABI)
|-----------------------|
|Callee saved registers | // multiple of 8 bytes, not includting FP/RA
|-----------------------|
| Saved RA | // 8 bytes
|-----------------------|
| Saved FP | // 8 bytes
|-----------------------|
| possible GS cookie |
|-----------------------|
| locals, temps, etc. |
|-----------------------|
| possible GS cookie |
|-----------------------|
| Outgoing arg space | // multiple of 8 bytes; if required (i.e., #outsz != 0)
|-----------------------| <---- Ambient SP
| | |
~ | Stack grows ~
| | downward |
@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch from 3092323 to e254dd6CompareApril 22, 2024 07:26

@sirntarsirntar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@jakobbotsch

Copy link
Copy Markdown
Member

@shushanhf Can you please avoid amending/force pushing to PRs? It makes it hard for us to see exactly what changed and to review the new changes. If you can push them as new commits that makes it much easier. We squash every PR on merge, so the history will be cleaned up anyway.

@rzsc

rzsc commented Apr 22, 2024

Copy link
Copy Markdown
Contributor

PR tested on riscv64 architecture and ready to be merged. Thanks!

@shushanhf

shushanhf commented Apr 23, 2024

Copy link
Copy Markdown
ContributorAuthor

@shushanhf Can you please avoid amending/force pushing to PRs?

Ok, thanks, I will.

It makes it hard for us to see exactly what changed and to review the new changes. If you can push them as new commits that makes it much easier. We squash every PR on merge, so the history will be cleaned up anyway.

Sorry, I didn't know this.
I thought the github has a new button Update branch which I thought I had to update the PR's base as soon as possible.
And I thought the github reviewing is liking the gerrit which different patches within the same PR are easy to diff where independed of the base.
Maybe the github should add the similar feature.

@jakobbotsch

Copy link
Copy Markdown
Member

Thanks for helping me understand the motivation for the change, and for making LA64/RV64 more similar to ARM64 around OSR.

@jakobbotsch

Copy link
Copy Markdown
Member

@BruceForstall If you have any feedback around this then please feel free to leave it. To sum up the motivation of the change you can see #100962 (comment).

@shushanhf
shushanhf deleted the adjust_calleeSavedRegs_offset branch April 23, 2024 11:53
matouskozak pushed a commit to matouskozak/runtime that referenced this pull request Apr 30, 2024
…et#100962)
The frame layout:
| |
|-----------------------|
| incoming arguments |
+=======================+ <---- Caller's SP
| Varargs regs space | // Only for varargs main functions; not used for LA64.
|-----------------------|
| MonitorAcquired | // 8 bytes; for synchronized methods
|-----------------------|
| PSP slot | // 8 bytes (omitted in NativeAOT ABI)
|-----------------------|
|Callee saved registers | // multiple of 8 bytes, not includting FP/RA
|-----------------------|
| Saved RA | // 8 bytes
|-----------------------|
| Saved FP | // 8 bytes
|-----------------------|
| possible GS cookie |
|-----------------------|
| locals, temps, etc. |
|-----------------------|
| possible GS cookie |
|-----------------------|
| Outgoing arg space | // multiple of 8 bytes; if required (i.e., #outsz != 0)
|-----------------------| <---- Ambient SP
| | |
~ | Stack grows ~
| | downward |
michaelgsharp pushed a commit to michaelgsharp/runtime that referenced this pull request May 9, 2024
…et#100962)
The frame layout:
| |
|-----------------------|
| incoming arguments |
+=======================+ <---- Caller's SP
| Varargs regs space | // Only for varargs main functions; not used for LA64.
|-----------------------|
| MonitorAcquired | // 8 bytes; for synchronized methods
|-----------------------|
| PSP slot | // 8 bytes (omitted in NativeAOT ABI)
|-----------------------|
|Callee saved registers | // multiple of 8 bytes, not includting FP/RA
|-----------------------|
| Saved RA | // 8 bytes
|-----------------------|
| Saved FP | // 8 bytes
|-----------------------|
| possible GS cookie |
|-----------------------|
| locals, temps, etc. |
|-----------------------|
| possible GS cookie |
|-----------------------|
| Outgoing arg space | // multiple of 8 bytes; if required (i.e., #outsz != 0)
|-----------------------| <---- Ambient SP
| | |
~ | Stack grows ~
| | downward |
@github-actionsgithub-actionsBot locked and limited conversation to collaborators May 24, 2024
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

arch-loongarch64arch-riscvRelated to the RISC-V architecturearea-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIcommunity-contributionIndicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants

@shushanhf@clamp03@jakobbotsch@AndyAyersMS@bartlomiejko@am11@rzsc@tomeksowi@sirntar@Bajtazar
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Adjust the calleeSavedRegs on top frame for LoongArch64/RISCV64 - #100962

Merged
jakobbotsch merged 4 commits into
dotnet:mainfrom
shushanhf:adjust_calleeSavedRegs_offset
Apr 23, 2024
Merged

Adjust the calleeSavedRegs on top frame for LoongArch64/RISCV64#100962
jakobbotsch merged 4 commits into
dotnet:mainfrom
shushanhf:adjust_calleeSavedRegs_offset

Conversation

@shushanhf

@shushanhfshushanhf commented Apr 12, 2024

Copy link
Copy Markdown
Contributor

Adjust the calleeSavedRegs on top frame for LoongArch64/RISCV64 to support the GSCookie.

Theframelayout:
| |
|-----------------------|
| incomingarguments |
+=======================+<----Caller's SP
| Varargsregsspace | // Only for varargs main functions; not used for LA64.
|-----------------------|
| MonitorAcquired | // 8 bytes; for synchronized methods
|-----------------------|
| PSPslot | // 8 bytes (omitted in NativeAOT ABI)
|-----------------------|
|Calleesavedregisters | // multiple of 8 bytes, not including FP/RA
|-----------------------|
| SavedRA | // 8 bytes
|-----------------------|
| SavedFP | // 8 bytes
|-----------------------|
| possibleGScookie |
|-----------------------|
| locals, temps, etc. |
|-----------------------|
| possibleGScookie |
|-----------------------|
| Outgoingargspace | // multiple of 8 bytes; if required (i.e., #outsz != 0)
|-----------------------| <----AmbientSP
| | |
~ | Stackgrows ~
| | downward |

@ghostghost added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Apr 12, 2024
@dotnet-policy-servicedotnet-policy-serviceBot added the community-contribution Indicates that the PR has been added by a community member label Apr 12, 2024
@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch 5 times, most recently from 6ec45e3 to 855fdb3CompareApril 13, 2024 08:01
@am11am11 added arch-loongarch64 arch-riscv Related to the RISC-V architecture labels Apr 13, 2024
@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch 6 times, most recently from f94cc0d to cf69c78CompareApril 15, 2024 10:06
@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch from cf69c78 to 8601cfcCompareApril 16, 2024 00:44
@shushanhf

Copy link
Copy Markdown
ContributorAuthor

@jakobbotsch@clamp03
Could you please review this PR?
Thanks

@clamp03

Copy link
Copy Markdown
Member

@bartlomiejko Can you review and test this PR?
cc @dotnet/samsung

@jakobbotsch

Copy link
Copy Markdown
Member

How is the stack frame layout changed compared to previously? What was the layout before this change? Why didn't it support GS cookie?
Can you show some codegen diffs?

@shushanhf

shushanhf commented Apr 16, 2024

Copy link
Copy Markdown
ContributorAuthor

How is the stack frame layout changed compared to previously? What was the layout before this change?

Only changed the calledSavedRegs, especially the FP/RA for LA64/RV64. The layout liking this PR's first comment description #100962 (comment) .
Before this PR, the FP/RA at bottom of frame which under the GSCookie, the FP/RA can be overwritten.

Why didn't it support GS cookie? Can you show some codegen diffs?

Before this PR, the FP/RA at bottom of frame which under the GSCookie, the FP/RA can be overwritten.

Comment threadsrc/coreclr/jit/codegenloongarch64.cpp
Comment threadsrc/coreclr/jit/lclvars.cpp Outdated
@jakobbotsch

Copy link
Copy Markdown
Member

Only changed the calledSavedRegs, especially the FP/RA for LA64/RV64. The layout liking this PR's first comment description #100962 (comment) .
Before this PR, the FP/RA at bottom of frame which under the GSCookie, the FP/RA can be overwritten.

Where does FP point to in your picture? Where did it point to before?

@shushanhf

Copy link
Copy Markdown
ContributorAuthor

Only changed the calledSavedRegs, especially the FP/RA for LA64/RV64. The layout liking this PR's first comment description #100962 (comment) .
Before this PR, the FP/RA at bottom of frame which under the GSCookie, the FP/RA can be overwritten.

Where does FP point to in your picture? Where did it point to before?

The new FP is pointing to the the old FP saved slot.

Can you show some codegen diffs?

/// this is the Old one.
G_M22522_IG01: ;; offset=0x0000
0xff74a50030 02FDC063 addi.d sp, sp, -144
0xff74a50034 29C00061 st.d ra, sp, 0
0xff74a50038 29C02076 st.d fp, sp, 8
0xff74a5003c 02C02076 addi.d fp, sp, 8
0xff74a50040 02C062CC addi.d t0, fp, 24 0xff74a50044 02801407 addi.w a3, zero, 5
0xff74a50048 29C02180 st.d zero, t0, 8
0xff74a5004c 29C00180 st.d zero, t0, 0
0xff74a50050 02FFFCE7 addi.d a3, a3, -1
0xff74a50054 02C0418C addi.d t0, t0, 16 0xff74a50058 5FFFF0E0 bne a3, zero, 0xff74a50048
0xff74a5005c 29C00180 st.d zero, t0, 0
0xff74a50060 29C202C4 st.d a0, fp, 128
0xff74a50064 29C1E2C5 st.d a1, fp, 120
0xff74a50068 29C1C2C6 st.d a2, fp, 112
;; size=60 bbWeight=1 PerfScore 0.00
G_M22522_IG02: ;; offset=0x003C
/// This is the new ins.
G_M22522_IG01: ;; offset=0x0000
0xff77790030 02FDC063 addi.d sp, sp, -144
0xff77790034 29C20076 st.d fp, sp, 128
0xff77790038 29C22061 st.d ra, sp, 136
0xff7779003c 02C20076 addi.d fp, sp, 128
0xff77790040 02FE42CC addi.d t0, fp, -112
0xff77790044 02801407 addi.w a3, zero, 5
0xff77790048 29C02180 st.d zero, t0, 8
0xff7779004c 29C00180 st.d zero, t0, 0
0xff77790050 02FFFCE7 addi.d a3, a3, -1
0xff77790054 02C0418C addi.d t0, t0, 16 0xff77790058 5FFFF0E0 bne a3, zero, 0xff77790048 /// the upstream's disasm format had been updated.
0xff7779005c 29C00180 st.d zero, t0, 0
0xff77790060 29FFE2C4 st.d a0, fp, -8
0xff77790064 29FFC2C5 st.d a1, fp, -16
0xff77790068 29FFA2C6 st.d a2, fp, -24
;; size=60 bbWeight=1 PerfScore 0.00

@jakobbotsch

Copy link
Copy Markdown
Member

Before this PR, the FP/RA at bottom of frame which under the GSCookie, the FP/RA can be overwritten.

Before this change, the comment in codegenloongarch64.cpp gives the following layout:

* The LoongArch64's frame layout is liking:
*
* | |
* |-----------------------|
* | incoming arguments |
* +=======================+ <---- Caller's SP
* | Arguments Or | // if needed.
* | Varargs regs space | // Only for varargs functions; (varargs not implemented for LoongArch64)
* |-----------------------|
* | MonitorAcquired | // 8 bytes; for synchronized methods
* |-----------------------|
* | PSP slot | // 8 bytes (omitted in NativeAOT ABI)
* |-----------------------|
* | locals, temps, etc. |
* |-----------------------|
* | possible GS cookie |
* |-----------------------|
* | Saved FP | // 8 bytes
* |-----------------------|
* | Saved RA | // 8 bytes
* |-----------------------|
* |Callee saved registers | // not including FP/RA; multiple of 8 bytes
* |-----------------------|
* | Outgoing arg space | // multiple of 8 bytes; if required (i.e., #outsz != 0)
* |-----------------------| <---- Ambient SP
* | | |
* ~ | Stack grows ~
* | | downward |
* V

The GS cookie exists between the locals and FP/RA pair. I do not see how FP/RA can be overwritten without hitting the GS cookie. Was the comment wrong?

Do you mean that the FP/RA of caller's frame can be overwritten?

@jakobbotsch

Copy link
Copy Markdown
Member

If I understand correctly, the change here means you have to use negative offsets from FP to access locals more often. Does LA64/RV64 allow encoding as many negative offsets as it allows positive offsets?

@shushanhf

shushanhf commented Apr 16, 2024

Copy link
Copy Markdown
ContributorAuthor
  •  |Callee saved registers | // not including FP/RA; multiple of 8 bytes
    

The GS cookie exists between the locals and FP/RA pair. I do not see how FP/RA can be overwritten without hitting the GS cookie. Was the comment wrong?
Do you mean that the FP/RA of caller's frame can be overwritten?

The GS Cookie is only used liking the localalloc. After finished the frame allocation, when using the localalloc to allocate a new stack space, the new space maybe overwritten the new real size allocated while the GSCookie is used to recognize this case.
Before this PR which the FP/RA under GS cookie, the FP/RA maybe overwritten while the GS cookie may not recognize this.

@shushanhf

Copy link
Copy Markdown
ContributorAuthor

If I understand correctly, the change here means you have to use negative offsets from FP to access locals more often. Does LA64/RV64 allow encoding as many negative offsets as it allows positive offsets?

yes

@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch from 8601cfc to 23fc354CompareApril 16, 2024 09:22
@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch 2 times, most recently from b78f2e0 to c237762CompareApril 19, 2024 06:39
@shushanhf

Copy link
Copy Markdown
ContributorAuthor

I think the CI went wrong. e.g.

@azure-pipelines
runtime (Build Formatting linux x64) Failing after 4m — Build Formatting linux x64 failed
[Details](https://github.com/dotnet/runtime/pull/100962/checks?check_run_id=24011496326)
@azure-pipelines
runtime (Build Formatting windows x64) Failing after 7m — Build Formatting windows x64 failed

but format-patch is empty.

@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch from c237762 to feaa635CompareApril 19, 2024 09:46
@jakobbotsch

Copy link
Copy Markdown
Member

I think the CI went wrong. e.g.

@azure-pipelines
runtime (Build Formatting linux x64) Failing after 4m — Build Formatting linux x64 failed
[Details](https://github.com/dotnet/runtime/pull/100962/checks?check_run_id=24011496326)
@azure-pipelines
runtime (Build Formatting windows x64) Failing after 7m — Build Formatting windows x64 failed

but format-patch is empty.

You can run jit-format locally, see the docs at https://github.com/dotnet/jitutils and https://github.com/dotnet/jitutils/blob/main/doc/formatting.md.

@am11

am11 commented Apr 19, 2024

Copy link
Copy Markdown
Member

The underlying error shows up on Windows leg:

D:\a_work\1\s\venv\Scripts\python.exe D:\a_work\1\s/src/coreclr/scripts/jitformat.py -r D:\a_work\1\s -o windows -a x64
...
2024-04-19T09:58:48.1997764Z No cdac-build-tool set or does not exist

started happening after #100650 merge. cc @lambdageek

@jakobbotschjakobbotsch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This change looks good to me now. Thanks for addressing all the feedback! I will give RISC-V folks some time to review as well.

@tomeksowitomeksowi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@sirntar, you did more work with stack frames/OSR, could you review when you return on Monday?

@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch from feaa635 to 3092323CompareApril 20, 2024 01:14
Comment threadsrc/coreclr/jit/codegenriscv64.cpp Outdated
Comment threadsrc/coreclr/jit/codegenriscv64.cpp Outdated
to support the GSCookie.
The frame layout:
| |
|-----------------------|
| incoming arguments |
+=======================+ <---- Caller's SP
| Varargs regs space | // Only for varargs main functions; not used for LA64.
|-----------------------|
| MonitorAcquired | // 8 bytes; for synchronized methods
|-----------------------|
| PSP slot | // 8 bytes (omitted in NativeAOT ABI)
|-----------------------|
|Callee saved registers | // multiple of 8 bytes, not includting FP/RA
|-----------------------|
| Saved RA | // 8 bytes
|-----------------------|
| Saved FP | // 8 bytes
|-----------------------|
| possible GS cookie |
|-----------------------|
| locals, temps, etc. |
|-----------------------|
| possible GS cookie |
|-----------------------|
| Outgoing arg space | // multiple of 8 bytes; if required (i.e., #outsz != 0)
|-----------------------| <---- Ambient SP
| | |
~ | Stack grows ~
| | downward |
@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch from 3092323 to e254dd6CompareApril 22, 2024 07:26

@sirntarsirntar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@jakobbotsch

Copy link
Copy Markdown
Member

@shushanhf Can you please avoid amending/force pushing to PRs? It makes it hard for us to see exactly what changed and to review the new changes. If you can push them as new commits that makes it much easier. We squash every PR on merge, so the history will be cleaned up anyway.

@rzsc

rzsc commented Apr 22, 2024

Copy link
Copy Markdown
Contributor

PR tested on riscv64 architecture and ready to be merged. Thanks!

@shushanhf

shushanhf commented Apr 23, 2024

Copy link
Copy Markdown
ContributorAuthor

@shushanhf Can you please avoid amending/force pushing to PRs?

Ok, thanks, I will.

It makes it hard for us to see exactly what changed and to review the new changes. If you can push them as new commits that makes it much easier. We squash every PR on merge, so the history will be cleaned up anyway.

Sorry, I didn't know this.
I thought the github has a new button Update branch which I thought I had to update the PR's base as soon as possible.
And I thought the github reviewing is liking the gerrit which different patches within the same PR are easy to diff where independed of the base.
Maybe the github should add the similar feature.

@jakobbotsch

Copy link
Copy Markdown
Member

Thanks for helping me understand the motivation for the change, and for making LA64/RV64 more similar to ARM64 around OSR.

@jakobbotsch

Copy link
Copy Markdown
Member

@BruceForstall If you have any feedback around this then please feel free to leave it. To sum up the motivation of the change you can see #100962 (comment).

@shushanhf
shushanhf deleted the adjust_calleeSavedRegs_offset branch April 23, 2024 11:53
matouskozak pushed a commit to matouskozak/runtime that referenced this pull request Apr 30, 2024
…et#100962)
The frame layout:
| |
|-----------------------|
| incoming arguments |
+=======================+ <---- Caller's SP
| Varargs regs space | // Only for varargs main functions; not used for LA64.
|-----------------------|
| MonitorAcquired | // 8 bytes; for synchronized methods
|-----------------------|
| PSP slot | // 8 bytes (omitted in NativeAOT ABI)
|-----------------------|
|Callee saved registers | // multiple of 8 bytes, not includting FP/RA
|-----------------------|
| Saved RA | // 8 bytes
|-----------------------|
| Saved FP | // 8 bytes
|-----------------------|
| possible GS cookie |
|-----------------------|
| locals, temps, etc. |
|-----------------------|
| possible GS cookie |
|-----------------------|
| Outgoing arg space | // multiple of 8 bytes; if required (i.e., #outsz != 0)
|-----------------------| <---- Ambient SP
| | |
~ | Stack grows ~
| | downward |
michaelgsharp pushed a commit to michaelgsharp/runtime that referenced this pull request May 9, 2024
…et#100962)
The frame layout:
| |
|-----------------------|
| incoming arguments |
+=======================+ <---- Caller's SP
| Varargs regs space | // Only for varargs main functions; not used for LA64.
|-----------------------|
| MonitorAcquired | // 8 bytes; for synchronized methods
|-----------------------|
| PSP slot | // 8 bytes (omitted in NativeAOT ABI)
|-----------------------|
|Callee saved registers | // multiple of 8 bytes, not includting FP/RA
|-----------------------|
| Saved RA | // 8 bytes
|-----------------------|
| Saved FP | // 8 bytes
|-----------------------|
| possible GS cookie |
|-----------------------|
| locals, temps, etc. |
|-----------------------|
| possible GS cookie |
|-----------------------|
| Outgoing arg space | // multiple of 8 bytes; if required (i.e., #outsz != 0)
|-----------------------| <---- Ambient SP
| | |
~ | Stack grows ~
| | downward |
@github-actionsgithub-actionsBot locked and limited conversation to collaborators May 24, 2024
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

arch-loongarch64arch-riscvRelated to the RISC-V architecturearea-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIcommunity-contributionIndicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants

@shushanhf@clamp03@jakobbotsch@AndyAyersMS@bartlomiejko@am11@rzsc@tomeksowi@sirntar@Bajtazar
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Adjust the calleeSavedRegs on top frame for LoongArch64/RISCV64 - #100962

Merged
jakobbotsch merged 4 commits into
dotnet:mainfrom
shushanhf:adjust_calleeSavedRegs_offset
Apr 23, 2024
Merged

Adjust the calleeSavedRegs on top frame for LoongArch64/RISCV64#100962
jakobbotsch merged 4 commits into
dotnet:mainfrom
shushanhf:adjust_calleeSavedRegs_offset

Conversation

@shushanhf

@shushanhfshushanhf commented Apr 12, 2024

Copy link
Copy Markdown
Contributor

Adjust the calleeSavedRegs on top frame for LoongArch64/RISCV64 to support the GSCookie.

Theframelayout:
| |
|-----------------------|
| incomingarguments |
+=======================+<----Caller's SP
| Varargsregsspace | // Only for varargs main functions; not used for LA64.
|-----------------------|
| MonitorAcquired | // 8 bytes; for synchronized methods
|-----------------------|
| PSPslot | // 8 bytes (omitted in NativeAOT ABI)
|-----------------------|
|Calleesavedregisters | // multiple of 8 bytes, not including FP/RA
|-----------------------|
| SavedRA | // 8 bytes
|-----------------------|
| SavedFP | // 8 bytes
|-----------------------|
| possibleGScookie |
|-----------------------|
| locals, temps, etc. |
|-----------------------|
| possibleGScookie |
|-----------------------|
| Outgoingargspace | // multiple of 8 bytes; if required (i.e., #outsz != 0)
|-----------------------| <----AmbientSP
| | |
~ | Stackgrows ~
| | downward |

@ghostghost added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Apr 12, 2024
@dotnet-policy-servicedotnet-policy-serviceBot added the community-contribution Indicates that the PR has been added by a community member label Apr 12, 2024
@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch 5 times, most recently from 6ec45e3 to 855fdb3CompareApril 13, 2024 08:01
@am11am11 added arch-loongarch64 arch-riscv Related to the RISC-V architecture labels Apr 13, 2024
@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch 6 times, most recently from f94cc0d to cf69c78CompareApril 15, 2024 10:06
@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch from cf69c78 to 8601cfcCompareApril 16, 2024 00:44
@shushanhf

Copy link
Copy Markdown
ContributorAuthor

@jakobbotsch@clamp03
Could you please review this PR?
Thanks

@clamp03

Copy link
Copy Markdown
Member

@bartlomiejko Can you review and test this PR?
cc @dotnet/samsung

@jakobbotsch

Copy link
Copy Markdown
Member

How is the stack frame layout changed compared to previously? What was the layout before this change? Why didn't it support GS cookie?
Can you show some codegen diffs?

@shushanhf

shushanhf commented Apr 16, 2024

Copy link
Copy Markdown
ContributorAuthor

How is the stack frame layout changed compared to previously? What was the layout before this change?

Only changed the calledSavedRegs, especially the FP/RA for LA64/RV64. The layout liking this PR's first comment description #100962 (comment) .
Before this PR, the FP/RA at bottom of frame which under the GSCookie, the FP/RA can be overwritten.

Why didn't it support GS cookie? Can you show some codegen diffs?

Before this PR, the FP/RA at bottom of frame which under the GSCookie, the FP/RA can be overwritten.

Comment threadsrc/coreclr/jit/codegenloongarch64.cpp
Comment threadsrc/coreclr/jit/lclvars.cpp Outdated
@jakobbotsch

Copy link
Copy Markdown
Member

Only changed the calledSavedRegs, especially the FP/RA for LA64/RV64. The layout liking this PR's first comment description #100962 (comment) .
Before this PR, the FP/RA at bottom of frame which under the GSCookie, the FP/RA can be overwritten.

Where does FP point to in your picture? Where did it point to before?

@shushanhf

Copy link
Copy Markdown
ContributorAuthor

Only changed the calledSavedRegs, especially the FP/RA for LA64/RV64. The layout liking this PR's first comment description #100962 (comment) .
Before this PR, the FP/RA at bottom of frame which under the GSCookie, the FP/RA can be overwritten.

Where does FP point to in your picture? Where did it point to before?

The new FP is pointing to the the old FP saved slot.

Can you show some codegen diffs?

/// this is the Old one.
G_M22522_IG01: ;; offset=0x0000
0xff74a50030 02FDC063 addi.d sp, sp, -144
0xff74a50034 29C00061 st.d ra, sp, 0
0xff74a50038 29C02076 st.d fp, sp, 8
0xff74a5003c 02C02076 addi.d fp, sp, 8
0xff74a50040 02C062CC addi.d t0, fp, 24 0xff74a50044 02801407 addi.w a3, zero, 5
0xff74a50048 29C02180 st.d zero, t0, 8
0xff74a5004c 29C00180 st.d zero, t0, 0
0xff74a50050 02FFFCE7 addi.d a3, a3, -1
0xff74a50054 02C0418C addi.d t0, t0, 16 0xff74a50058 5FFFF0E0 bne a3, zero, 0xff74a50048
0xff74a5005c 29C00180 st.d zero, t0, 0
0xff74a50060 29C202C4 st.d a0, fp, 128
0xff74a50064 29C1E2C5 st.d a1, fp, 120
0xff74a50068 29C1C2C6 st.d a2, fp, 112
;; size=60 bbWeight=1 PerfScore 0.00
G_M22522_IG02: ;; offset=0x003C
/// This is the new ins.
G_M22522_IG01: ;; offset=0x0000
0xff77790030 02FDC063 addi.d sp, sp, -144
0xff77790034 29C20076 st.d fp, sp, 128
0xff77790038 29C22061 st.d ra, sp, 136
0xff7779003c 02C20076 addi.d fp, sp, 128
0xff77790040 02FE42CC addi.d t0, fp, -112
0xff77790044 02801407 addi.w a3, zero, 5
0xff77790048 29C02180 st.d zero, t0, 8
0xff7779004c 29C00180 st.d zero, t0, 0
0xff77790050 02FFFCE7 addi.d a3, a3, -1
0xff77790054 02C0418C addi.d t0, t0, 16 0xff77790058 5FFFF0E0 bne a3, zero, 0xff77790048 /// the upstream's disasm format had been updated.
0xff7779005c 29C00180 st.d zero, t0, 0
0xff77790060 29FFE2C4 st.d a0, fp, -8
0xff77790064 29FFC2C5 st.d a1, fp, -16
0xff77790068 29FFA2C6 st.d a2, fp, -24
;; size=60 bbWeight=1 PerfScore 0.00

@jakobbotsch

Copy link
Copy Markdown
Member

Before this PR, the FP/RA at bottom of frame which under the GSCookie, the FP/RA can be overwritten.

Before this change, the comment in codegenloongarch64.cpp gives the following layout:

* The LoongArch64's frame layout is liking:
*
* | |
* |-----------------------|
* | incoming arguments |
* +=======================+ <---- Caller's SP
* | Arguments Or | // if needed.
* | Varargs regs space | // Only for varargs functions; (varargs not implemented for LoongArch64)
* |-----------------------|
* | MonitorAcquired | // 8 bytes; for synchronized methods
* |-----------------------|
* | PSP slot | // 8 bytes (omitted in NativeAOT ABI)
* |-----------------------|
* | locals, temps, etc. |
* |-----------------------|
* | possible GS cookie |
* |-----------------------|
* | Saved FP | // 8 bytes
* |-----------------------|
* | Saved RA | // 8 bytes
* |-----------------------|
* |Callee saved registers | // not including FP/RA; multiple of 8 bytes
* |-----------------------|
* | Outgoing arg space | // multiple of 8 bytes; if required (i.e., #outsz != 0)
* |-----------------------| <---- Ambient SP
* | | |
* ~ | Stack grows ~
* | | downward |
* V

The GS cookie exists between the locals and FP/RA pair. I do not see how FP/RA can be overwritten without hitting the GS cookie. Was the comment wrong?

Do you mean that the FP/RA of caller's frame can be overwritten?

@jakobbotsch

Copy link
Copy Markdown
Member

If I understand correctly, the change here means you have to use negative offsets from FP to access locals more often. Does LA64/RV64 allow encoding as many negative offsets as it allows positive offsets?

@shushanhf

shushanhf commented Apr 16, 2024

Copy link
Copy Markdown
ContributorAuthor
  •  |Callee saved registers | // not including FP/RA; multiple of 8 bytes
    

The GS cookie exists between the locals and FP/RA pair. I do not see how FP/RA can be overwritten without hitting the GS cookie. Was the comment wrong?
Do you mean that the FP/RA of caller's frame can be overwritten?

The GS Cookie is only used liking the localalloc. After finished the frame allocation, when using the localalloc to allocate a new stack space, the new space maybe overwritten the new real size allocated while the GSCookie is used to recognize this case.
Before this PR which the FP/RA under GS cookie, the FP/RA maybe overwritten while the GS cookie may not recognize this.

@shushanhf

Copy link
Copy Markdown
ContributorAuthor

If I understand correctly, the change here means you have to use negative offsets from FP to access locals more often. Does LA64/RV64 allow encoding as many negative offsets as it allows positive offsets?

yes

@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch from 8601cfc to 23fc354CompareApril 16, 2024 09:22
@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch 2 times, most recently from b78f2e0 to c237762CompareApril 19, 2024 06:39
@shushanhf

Copy link
Copy Markdown
ContributorAuthor

I think the CI went wrong. e.g.

@azure-pipelines
runtime (Build Formatting linux x64) Failing after 4m — Build Formatting linux x64 failed
[Details](https://github.com/dotnet/runtime/pull/100962/checks?check_run_id=24011496326)
@azure-pipelines
runtime (Build Formatting windows x64) Failing after 7m — Build Formatting windows x64 failed

but format-patch is empty.

@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch from c237762 to feaa635CompareApril 19, 2024 09:46
@jakobbotsch

Copy link
Copy Markdown
Member

I think the CI went wrong. e.g.

@azure-pipelines
runtime (Build Formatting linux x64) Failing after 4m — Build Formatting linux x64 failed
[Details](https://github.com/dotnet/runtime/pull/100962/checks?check_run_id=24011496326)
@azure-pipelines
runtime (Build Formatting windows x64) Failing after 7m — Build Formatting windows x64 failed

but format-patch is empty.

You can run jit-format locally, see the docs at https://github.com/dotnet/jitutils and https://github.com/dotnet/jitutils/blob/main/doc/formatting.md.

@am11

am11 commented Apr 19, 2024

Copy link
Copy Markdown
Member

The underlying error shows up on Windows leg:

D:\a_work\1\s\venv\Scripts\python.exe D:\a_work\1\s/src/coreclr/scripts/jitformat.py -r D:\a_work\1\s -o windows -a x64
...
2024-04-19T09:58:48.1997764Z No cdac-build-tool set or does not exist

started happening after #100650 merge. cc @lambdageek

@jakobbotschjakobbotsch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This change looks good to me now. Thanks for addressing all the feedback! I will give RISC-V folks some time to review as well.

@tomeksowitomeksowi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@sirntar, you did more work with stack frames/OSR, could you review when you return on Monday?

@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch from feaa635 to 3092323CompareApril 20, 2024 01:14
Comment threadsrc/coreclr/jit/codegenriscv64.cpp Outdated
Comment threadsrc/coreclr/jit/codegenriscv64.cpp Outdated
to support the GSCookie.
The frame layout:
| |
|-----------------------|
| incoming arguments |
+=======================+ <---- Caller's SP
| Varargs regs space | // Only for varargs main functions; not used for LA64.
|-----------------------|
| MonitorAcquired | // 8 bytes; for synchronized methods
|-----------------------|
| PSP slot | // 8 bytes (omitted in NativeAOT ABI)
|-----------------------|
|Callee saved registers | // multiple of 8 bytes, not includting FP/RA
|-----------------------|
| Saved RA | // 8 bytes
|-----------------------|
| Saved FP | // 8 bytes
|-----------------------|
| possible GS cookie |
|-----------------------|
| locals, temps, etc. |
|-----------------------|
| possible GS cookie |
|-----------------------|
| Outgoing arg space | // multiple of 8 bytes; if required (i.e., #outsz != 0)
|-----------------------| <---- Ambient SP
| | |
~ | Stack grows ~
| | downward |
@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch from 3092323 to e254dd6CompareApril 22, 2024 07:26

@sirntarsirntar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@jakobbotsch

Copy link
Copy Markdown
Member

@shushanhf Can you please avoid amending/force pushing to PRs? It makes it hard for us to see exactly what changed and to review the new changes. If you can push them as new commits that makes it much easier. We squash every PR on merge, so the history will be cleaned up anyway.

@rzsc

rzsc commented Apr 22, 2024

Copy link
Copy Markdown
Contributor

PR tested on riscv64 architecture and ready to be merged. Thanks!

@shushanhf

shushanhf commented Apr 23, 2024

Copy link
Copy Markdown
ContributorAuthor

@shushanhf Can you please avoid amending/force pushing to PRs?

Ok, thanks, I will.

It makes it hard for us to see exactly what changed and to review the new changes. If you can push them as new commits that makes it much easier. We squash every PR on merge, so the history will be cleaned up anyway.

Sorry, I didn't know this.
I thought the github has a new button Update branch which I thought I had to update the PR's base as soon as possible.
And I thought the github reviewing is liking the gerrit which different patches within the same PR are easy to diff where independed of the base.
Maybe the github should add the similar feature.

@jakobbotsch

Copy link
Copy Markdown
Member

Thanks for helping me understand the motivation for the change, and for making LA64/RV64 more similar to ARM64 around OSR.

@jakobbotsch

Copy link
Copy Markdown
Member

@BruceForstall If you have any feedback around this then please feel free to leave it. To sum up the motivation of the change you can see #100962 (comment).

@shushanhf
shushanhf deleted the adjust_calleeSavedRegs_offset branch April 23, 2024 11:53
matouskozak pushed a commit to matouskozak/runtime that referenced this pull request Apr 30, 2024
…et#100962)
The frame layout:
| |
|-----------------------|
| incoming arguments |
+=======================+ <---- Caller's SP
| Varargs regs space | // Only for varargs main functions; not used for LA64.
|-----------------------|
| MonitorAcquired | // 8 bytes; for synchronized methods
|-----------------------|
| PSP slot | // 8 bytes (omitted in NativeAOT ABI)
|-----------------------|
|Callee saved registers | // multiple of 8 bytes, not includting FP/RA
|-----------------------|
| Saved RA | // 8 bytes
|-----------------------|
| Saved FP | // 8 bytes
|-----------------------|
| possible GS cookie |
|-----------------------|
| locals, temps, etc. |
|-----------------------|
| possible GS cookie |
|-----------------------|
| Outgoing arg space | // multiple of 8 bytes; if required (i.e., #outsz != 0)
|-----------------------| <---- Ambient SP
| | |
~ | Stack grows ~
| | downward |
michaelgsharp pushed a commit to michaelgsharp/runtime that referenced this pull request May 9, 2024
…et#100962)
The frame layout:
| |
|-----------------------|
| incoming arguments |
+=======================+ <---- Caller's SP
| Varargs regs space | // Only for varargs main functions; not used for LA64.
|-----------------------|
| MonitorAcquired | // 8 bytes; for synchronized methods
|-----------------------|
| PSP slot | // 8 bytes (omitted in NativeAOT ABI)
|-----------------------|
|Callee saved registers | // multiple of 8 bytes, not includting FP/RA
|-----------------------|
| Saved RA | // 8 bytes
|-----------------------|
| Saved FP | // 8 bytes
|-----------------------|
| possible GS cookie |
|-----------------------|
| locals, temps, etc. |
|-----------------------|
| possible GS cookie |
|-----------------------|
| Outgoing arg space | // multiple of 8 bytes; if required (i.e., #outsz != 0)
|-----------------------| <---- Ambient SP
| | |
~ | Stack grows ~
| | downward |
@github-actionsgithub-actionsBot locked and limited conversation to collaborators May 24, 2024
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

arch-loongarch64arch-riscvRelated to the RISC-V architecturearea-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIcommunity-contributionIndicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants

@shushanhf@clamp03@jakobbotsch@AndyAyersMS@bartlomiejko@am11@rzsc@tomeksowi@sirntar@Bajtazar
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Adjust the calleeSavedRegs on top frame for LoongArch64/RISCV64 - #100962

Merged
jakobbotsch merged 4 commits into
dotnet:mainfrom
shushanhf:adjust_calleeSavedRegs_offset
Apr 23, 2024
Merged

Adjust the calleeSavedRegs on top frame for LoongArch64/RISCV64#100962
jakobbotsch merged 4 commits into
dotnet:mainfrom
shushanhf:adjust_calleeSavedRegs_offset

Conversation

@shushanhf

@shushanhfshushanhf commented Apr 12, 2024

Copy link
Copy Markdown
Contributor

Adjust the calleeSavedRegs on top frame for LoongArch64/RISCV64 to support the GSCookie.

Theframelayout:
| |
|-----------------------|
| incomingarguments |
+=======================+<----Caller's SP
| Varargsregsspace | // Only for varargs main functions; not used for LA64.
|-----------------------|
| MonitorAcquired | // 8 bytes; for synchronized methods
|-----------------------|
| PSPslot | // 8 bytes (omitted in NativeAOT ABI)
|-----------------------|
|Calleesavedregisters | // multiple of 8 bytes, not including FP/RA
|-----------------------|
| SavedRA | // 8 bytes
|-----------------------|
| SavedFP | // 8 bytes
|-----------------------|
| possibleGScookie |
|-----------------------|
| locals, temps, etc. |
|-----------------------|
| possibleGScookie |
|-----------------------|
| Outgoingargspace | // multiple of 8 bytes; if required (i.e., #outsz != 0)
|-----------------------| <----AmbientSP
| | |
~ | Stackgrows ~
| | downward |

@ghostghost added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Apr 12, 2024
@dotnet-policy-servicedotnet-policy-serviceBot added the community-contribution Indicates that the PR has been added by a community member label Apr 12, 2024
@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch 5 times, most recently from 6ec45e3 to 855fdb3CompareApril 13, 2024 08:01
@am11am11 added arch-loongarch64 arch-riscv Related to the RISC-V architecture labels Apr 13, 2024
@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch 6 times, most recently from f94cc0d to cf69c78CompareApril 15, 2024 10:06
@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch from cf69c78 to 8601cfcCompareApril 16, 2024 00:44
@shushanhf

Copy link
Copy Markdown
ContributorAuthor

@jakobbotsch@clamp03
Could you please review this PR?
Thanks

@clamp03

Copy link
Copy Markdown
Member

@bartlomiejko Can you review and test this PR?
cc @dotnet/samsung

@jakobbotsch

Copy link
Copy Markdown
Member

How is the stack frame layout changed compared to previously? What was the layout before this change? Why didn't it support GS cookie?
Can you show some codegen diffs?

@shushanhf

shushanhf commented Apr 16, 2024

Copy link
Copy Markdown
ContributorAuthor

How is the stack frame layout changed compared to previously? What was the layout before this change?

Only changed the calledSavedRegs, especially the FP/RA for LA64/RV64. The layout liking this PR's first comment description #100962 (comment) .
Before this PR, the FP/RA at bottom of frame which under the GSCookie, the FP/RA can be overwritten.

Why didn't it support GS cookie? Can you show some codegen diffs?

Before this PR, the FP/RA at bottom of frame which under the GSCookie, the FP/RA can be overwritten.

Comment threadsrc/coreclr/jit/codegenloongarch64.cpp
Comment threadsrc/coreclr/jit/lclvars.cpp Outdated
@jakobbotsch

Copy link
Copy Markdown
Member

Only changed the calledSavedRegs, especially the FP/RA for LA64/RV64. The layout liking this PR's first comment description #100962 (comment) .
Before this PR, the FP/RA at bottom of frame which under the GSCookie, the FP/RA can be overwritten.

Where does FP point to in your picture? Where did it point to before?

@shushanhf

Copy link
Copy Markdown
ContributorAuthor

Only changed the calledSavedRegs, especially the FP/RA for LA64/RV64. The layout liking this PR's first comment description #100962 (comment) .
Before this PR, the FP/RA at bottom of frame which under the GSCookie, the FP/RA can be overwritten.

Where does FP point to in your picture? Where did it point to before?

The new FP is pointing to the the old FP saved slot.

Can you show some codegen diffs?

/// this is the Old one.
G_M22522_IG01: ;; offset=0x0000
0xff74a50030 02FDC063 addi.d sp, sp, -144
0xff74a50034 29C00061 st.d ra, sp, 0
0xff74a50038 29C02076 st.d fp, sp, 8
0xff74a5003c 02C02076 addi.d fp, sp, 8
0xff74a50040 02C062CC addi.d t0, fp, 24 0xff74a50044 02801407 addi.w a3, zero, 5
0xff74a50048 29C02180 st.d zero, t0, 8
0xff74a5004c 29C00180 st.d zero, t0, 0
0xff74a50050 02FFFCE7 addi.d a3, a3, -1
0xff74a50054 02C0418C addi.d t0, t0, 16 0xff74a50058 5FFFF0E0 bne a3, zero, 0xff74a50048
0xff74a5005c 29C00180 st.d zero, t0, 0
0xff74a50060 29C202C4 st.d a0, fp, 128
0xff74a50064 29C1E2C5 st.d a1, fp, 120
0xff74a50068 29C1C2C6 st.d a2, fp, 112
;; size=60 bbWeight=1 PerfScore 0.00
G_M22522_IG02: ;; offset=0x003C
/// This is the new ins.
G_M22522_IG01: ;; offset=0x0000
0xff77790030 02FDC063 addi.d sp, sp, -144
0xff77790034 29C20076 st.d fp, sp, 128
0xff77790038 29C22061 st.d ra, sp, 136
0xff7779003c 02C20076 addi.d fp, sp, 128
0xff77790040 02FE42CC addi.d t0, fp, -112
0xff77790044 02801407 addi.w a3, zero, 5
0xff77790048 29C02180 st.d zero, t0, 8
0xff7779004c 29C00180 st.d zero, t0, 0
0xff77790050 02FFFCE7 addi.d a3, a3, -1
0xff77790054 02C0418C addi.d t0, t0, 16 0xff77790058 5FFFF0E0 bne a3, zero, 0xff77790048 /// the upstream's disasm format had been updated.
0xff7779005c 29C00180 st.d zero, t0, 0
0xff77790060 29FFE2C4 st.d a0, fp, -8
0xff77790064 29FFC2C5 st.d a1, fp, -16
0xff77790068 29FFA2C6 st.d a2, fp, -24
;; size=60 bbWeight=1 PerfScore 0.00

@jakobbotsch

Copy link
Copy Markdown
Member

Before this PR, the FP/RA at bottom of frame which under the GSCookie, the FP/RA can be overwritten.

Before this change, the comment in codegenloongarch64.cpp gives the following layout:

* The LoongArch64's frame layout is liking:
*
* | |
* |-----------------------|
* | incoming arguments |
* +=======================+ <---- Caller's SP
* | Arguments Or | // if needed.
* | Varargs regs space | // Only for varargs functions; (varargs not implemented for LoongArch64)
* |-----------------------|
* | MonitorAcquired | // 8 bytes; for synchronized methods
* |-----------------------|
* | PSP slot | // 8 bytes (omitted in NativeAOT ABI)
* |-----------------------|
* | locals, temps, etc. |
* |-----------------------|
* | possible GS cookie |
* |-----------------------|
* | Saved FP | // 8 bytes
* |-----------------------|
* | Saved RA | // 8 bytes
* |-----------------------|
* |Callee saved registers | // not including FP/RA; multiple of 8 bytes
* |-----------------------|
* | Outgoing arg space | // multiple of 8 bytes; if required (i.e., #outsz != 0)
* |-----------------------| <---- Ambient SP
* | | |
* ~ | Stack grows ~
* | | downward |
* V

The GS cookie exists between the locals and FP/RA pair. I do not see how FP/RA can be overwritten without hitting the GS cookie. Was the comment wrong?

Do you mean that the FP/RA of caller's frame can be overwritten?

@jakobbotsch

Copy link
Copy Markdown
Member

If I understand correctly, the change here means you have to use negative offsets from FP to access locals more often. Does LA64/RV64 allow encoding as many negative offsets as it allows positive offsets?

@shushanhf

shushanhf commented Apr 16, 2024

Copy link
Copy Markdown
ContributorAuthor
  •  |Callee saved registers | // not including FP/RA; multiple of 8 bytes
    

The GS cookie exists between the locals and FP/RA pair. I do not see how FP/RA can be overwritten without hitting the GS cookie. Was the comment wrong?
Do you mean that the FP/RA of caller's frame can be overwritten?

The GS Cookie is only used liking the localalloc. After finished the frame allocation, when using the localalloc to allocate a new stack space, the new space maybe overwritten the new real size allocated while the GSCookie is used to recognize this case.
Before this PR which the FP/RA under GS cookie, the FP/RA maybe overwritten while the GS cookie may not recognize this.

@shushanhf

Copy link
Copy Markdown
ContributorAuthor

If I understand correctly, the change here means you have to use negative offsets from FP to access locals more often. Does LA64/RV64 allow encoding as many negative offsets as it allows positive offsets?

yes

@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch from 8601cfc to 23fc354CompareApril 16, 2024 09:22
@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch 2 times, most recently from b78f2e0 to c237762CompareApril 19, 2024 06:39
@shushanhf

Copy link
Copy Markdown
ContributorAuthor

I think the CI went wrong. e.g.

@azure-pipelines
runtime (Build Formatting linux x64) Failing after 4m — Build Formatting linux x64 failed
[Details](https://github.com/dotnet/runtime/pull/100962/checks?check_run_id=24011496326)
@azure-pipelines
runtime (Build Formatting windows x64) Failing after 7m — Build Formatting windows x64 failed

but format-patch is empty.

@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch from c237762 to feaa635CompareApril 19, 2024 09:46
@jakobbotsch

Copy link
Copy Markdown
Member

I think the CI went wrong. e.g.

@azure-pipelines
runtime (Build Formatting linux x64) Failing after 4m — Build Formatting linux x64 failed
[Details](https://github.com/dotnet/runtime/pull/100962/checks?check_run_id=24011496326)
@azure-pipelines
runtime (Build Formatting windows x64) Failing after 7m — Build Formatting windows x64 failed

but format-patch is empty.

You can run jit-format locally, see the docs at https://github.com/dotnet/jitutils and https://github.com/dotnet/jitutils/blob/main/doc/formatting.md.

@am11

am11 commented Apr 19, 2024

Copy link
Copy Markdown
Member

The underlying error shows up on Windows leg:

D:\a_work\1\s\venv\Scripts\python.exe D:\a_work\1\s/src/coreclr/scripts/jitformat.py -r D:\a_work\1\s -o windows -a x64
...
2024-04-19T09:58:48.1997764Z No cdac-build-tool set or does not exist

started happening after #100650 merge. cc @lambdageek

@jakobbotschjakobbotsch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This change looks good to me now. Thanks for addressing all the feedback! I will give RISC-V folks some time to review as well.

@tomeksowitomeksowi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@sirntar, you did more work with stack frames/OSR, could you review when you return on Monday?

@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch from feaa635 to 3092323CompareApril 20, 2024 01:14
Comment threadsrc/coreclr/jit/codegenriscv64.cpp Outdated
Comment threadsrc/coreclr/jit/codegenriscv64.cpp Outdated
to support the GSCookie.
The frame layout:
| |
|-----------------------|
| incoming arguments |
+=======================+ <---- Caller's SP
| Varargs regs space | // Only for varargs main functions; not used for LA64.
|-----------------------|
| MonitorAcquired | // 8 bytes; for synchronized methods
|-----------------------|
| PSP slot | // 8 bytes (omitted in NativeAOT ABI)
|-----------------------|
|Callee saved registers | // multiple of 8 bytes, not includting FP/RA
|-----------------------|
| Saved RA | // 8 bytes
|-----------------------|
| Saved FP | // 8 bytes
|-----------------------|
| possible GS cookie |
|-----------------------|
| locals, temps, etc. |
|-----------------------|
| possible GS cookie |
|-----------------------|
| Outgoing arg space | // multiple of 8 bytes; if required (i.e., #outsz != 0)
|-----------------------| <---- Ambient SP
| | |
~ | Stack grows ~
| | downward |
@shushanhf
shushanhfforce-pushed the adjust_calleeSavedRegs_offset branch from 3092323 to e254dd6CompareApril 22, 2024 07:26

@sirntarsirntar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@jakobbotsch

Copy link
Copy Markdown
Member

@shushanhf Can you please avoid amending/force pushing to PRs? It makes it hard for us to see exactly what changed and to review the new changes. If you can push them as new commits that makes it much easier. We squash every PR on merge, so the history will be cleaned up anyway.

@rzsc

rzsc commented Apr 22, 2024

Copy link
Copy Markdown
Contributor

PR tested on riscv64 architecture and ready to be merged. Thanks!

@shushanhf

shushanhf commented Apr 23, 2024

Copy link
Copy Markdown
ContributorAuthor

@shushanhf Can you please avoid amending/force pushing to PRs?

Ok, thanks, I will.

It makes it hard for us to see exactly what changed and to review the new changes. If you can push them as new commits that makes it much easier. We squash every PR on merge, so the history will be cleaned up anyway.

Sorry, I didn't know this.
I thought the github has a new button Update branch which I thought I had to update the PR's base as soon as possible.
And I thought the github reviewing is liking the gerrit which different patches within the same PR are easy to diff where independed of the base.
Maybe the github should add the similar feature.

@jakobbotsch

Copy link
Copy Markdown
Member

Thanks for helping me understand the motivation for the change, and for making LA64/RV64 more similar to ARM64 around OSR.

@jakobbotsch

Copy link
Copy Markdown
Member

@BruceForstall If you have any feedback around this then please feel free to leave it. To sum up the motivation of the change you can see #100962 (comment).

@shushanhf
shushanhf deleted the adjust_calleeSavedRegs_offset branch April 23, 2024 11:53
matouskozak pushed a commit to matouskozak/runtime that referenced this pull request Apr 30, 2024
…et#100962)
The frame layout:
| |
|-----------------------|
| incoming arguments |
+=======================+ <---- Caller's SP
| Varargs regs space | // Only for varargs main functions; not used for LA64.
|-----------------------|
| MonitorAcquired | // 8 bytes; for synchronized methods
|-----------------------|
| PSP slot | // 8 bytes (omitted in NativeAOT ABI)
|-----------------------|
|Callee saved registers | // multiple of 8 bytes, not includting FP/RA
|-----------------------|
| Saved RA | // 8 bytes
|-----------------------|
| Saved FP | // 8 bytes
|-----------------------|
| possible GS cookie |
|-----------------------|
| locals, temps, etc. |
|-----------------------|
| possible GS cookie |
|-----------------------|
| Outgoing arg space | // multiple of 8 bytes; if required (i.e., #outsz != 0)
|-----------------------| <---- Ambient SP
| | |
~ | Stack grows ~
| | downward |
michaelgsharp pushed a commit to michaelgsharp/runtime that referenced this pull request May 9, 2024
…et#100962)
The frame layout:
| |
|-----------------------|
| incoming arguments |
+=======================+ <---- Caller's SP
| Varargs regs space | // Only for varargs main functions; not used for LA64.
|-----------------------|
| MonitorAcquired | // 8 bytes; for synchronized methods
|-----------------------|
| PSP slot | // 8 bytes (omitted in NativeAOT ABI)
|-----------------------|
|Callee saved registers | // multiple of 8 bytes, not includting FP/RA
|-----------------------|
| Saved RA | // 8 bytes
|-----------------------|
| Saved FP | // 8 bytes
|-----------------------|
| possible GS cookie |
|-----------------------|
| locals, temps, etc. |
|-----------------------|
| possible GS cookie |
|-----------------------|
| Outgoing arg space | // multiple of 8 bytes; if required (i.e., #outsz != 0)
|-----------------------| <---- Ambient SP
| | |
~ | Stack grows ~
| | downward |
@github-actionsgithub-actionsBot locked and limited conversation to collaborators May 24, 2024
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

arch-loongarch64arch-riscvRelated to the RISC-V architecturearea-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIcommunity-contributionIndicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants

@shushanhf@clamp03@jakobbotsch@AndyAyersMS@bartlomiejko@am11@rzsc@tomeksowi@sirntar@Bajtazar