Skip to content

Commit c5304c2

Browse files
shushanhfmatouskozak
authored andcommitted
Adjust the calleeSavedRegs on top frame for LoongArch64/RISCV64 (dotnet#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 |
1 parent fef7ba0 commit c5304c2

File tree

6 files changed

+450
-726
lines changed

6 files changed

+450
-726
lines changed

src/coreclr/jit/codegen.h

+1-22
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ class CodeGen final : public CodeGenInterface
437437

438438
FuncletFrameInfoDsc genFuncletInfo;
439439

440-
#elif defined(TARGET_LOONGARCH64)
440+
#elif defined(TARGET_LOONGARCH64) || defined(TARGET_RISCV64)
441441

442442
// A set of information that is used by funclet prolog and epilog generation.
443443
// It is collected once, before funclet prologs and epilogs are generated,
@@ -448,26 +448,6 @@ class CodeGen final : public CodeGenInterface
448448
int fiFunction_CallerSP_to_FP_delta; // Delta between caller SP and the frame pointer in the parent function
449449
// (negative)
450450
int fiSP_to_CalleeSaved_delta; // CalleeSaved register save offset from SP (positive)
451-
int fiCalleeSavedPadding; // CalleeSaved offset padding (positive)
452-
int fiSP_to_PSP_slot_delta; // PSP slot offset from SP (positive)
453-
int fiCallerSP_to_PSP_slot_delta; // PSP slot offset from Caller SP (negative)
454-
int fiSpDelta; // Stack pointer delta (negative)
455-
};
456-
457-
FuncletFrameInfoDsc genFuncletInfo;
458-
459-
#elif defined(TARGET_RISCV64)
460-
461-
// A set of information that is used by funclet prolog and epilog generation.
462-
// It is collected once, before funclet prologs and epilogs are generated,
463-
// and used by all funclet prologs and epilogs, which must all be the same.
464-
struct FuncletFrameInfoDsc
465-
{
466-
regMaskTP fiSaveRegs; // Set of callee-saved registers saved in the funclet prolog (includes RA)
467-
int fiFunction_CallerSP_to_FP_delta; // Delta between caller SP and the frame pointer in the parent function
468-
// (negative)
469-
int fiSP_to_CalleeSaved_delta; // CalleeSaved register save offset from SP (positive)
470-
int fiCalleeSavedPadding; // CalleeSaved offset padding (positive)
471451
int fiSP_to_PSP_slot_delta; // PSP slot offset from SP (positive)
472452
int fiCallerSP_to_PSP_slot_delta; // PSP slot offset from Caller SP (negative)
473453
int fiSpDelta; // Stack pointer delta (negative)
@@ -1272,7 +1252,6 @@ class CodeGen final : public CodeGenInterface
12721252
void genJmpMethod(GenTree* jmp);
12731253
BasicBlock* genCallFinally(BasicBlock* block);
12741254
#if defined(TARGET_LOONGARCH64) || defined(TARGET_RISCV64)
1275-
// TODO: refactor for LA.
12761255
void genCodeForJumpCompare(GenTreeOpCC* tree);
12771256
#endif
12781257
#if defined(TARGET_ARM64)

src/coreclr/jit/codegencommon.cpp

+5-12
Original file line numberDiff line numberDiff line change
@@ -4744,20 +4744,13 @@ void CodeGen::genFinalizeFrame()
47444744
#endif // defined(TARGET_XARCH)
47454745

47464746
#if defined(TARGET_LOONGARCH64) || defined(TARGET_RISCV64)
4747-
if (isFramePointerUsed())
4748-
{
4749-
// For a FP based frame we have to push/pop the FP register
4750-
//
4751-
maskCalleeRegsPushed |= RBM_FPBASE;
4747+
// This assert check that we are not using REG_FP
4748+
assert(!regSet.rsRegsModified(RBM_FPBASE));
47524749

4753-
// This assert check that we are not using REG_FP
4754-
// as both the frame pointer and as a codegen register
4755-
//
4756-
assert(!regSet.rsRegsModified(RBM_FPBASE));
4757-
}
4750+
assert(isFramePointerUsed());
4751+
// we always push FP/RA. See genPushCalleeSavedRegisters
4752+
maskCalleeRegsPushed |= (RBM_FPBASE | RBM_RA);
47584753

4759-
// we always push RA. See genPushCalleeSavedRegisters
4760-
maskCalleeRegsPushed |= RBM_RA;
47614754
#endif // TARGET_LOONGARCH64 || TARGET_RISCV64
47624755

47634756
compiler->compCalleeRegsPushed = genCountBits(maskCalleeRegsPushed);

0 commit comments

Comments
 (0)