Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 07586f8

Browse files
committedApr 9, 2024·
Redesign the frame layout for LoongArch64/RISCV64 to
avoid the redundant computation of the stackOffsets. After the `lvaAssignVirtualFrameOffsetsToLocals`, there is no need to recompute the LclVarDsc's StackOffset within the `lvaFixVirtualFrameOffsets`.
1 parent 22d1288 commit 07586f8

7 files changed

+541
-747
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

+39-14
Original file line numberDiff line numberDiff line change
@@ -4926,7 +4926,7 @@ void CodeGen::genEnregisterOSRArgsAndLocals()
49264926

49274927
GetEmitter()->emitIns_R_AR(ins_Load(lclTyp), size, varDsc->GetRegNum(), genFramePointerReg(), offset);
49284928

4929-
#elif defined(TARGET_ARM64) || defined(TARGET_LOONGARCH64) || defined(TARGET_RISCV64)
4929+
#elif defined(TARGET_ARM64)
49304930

49314931
// Patchpoint offset is from top of Tier0 frame
49324932
//
@@ -4958,7 +4958,39 @@ void CodeGen::genEnregisterOSRArgsAndLocals()
49584958

49594959
genInstrWithConstant(ins_Load(lclTyp), size, varDsc->GetRegNum(), genFramePointerReg(), offset, initReg);
49604960
*pInitRegZeroed = false;
4961-
#endif // TARGET_ARM64 || TARGET_LOONGARCH64 || TARGET_RISCV64
4961+
#elif defined(TARGET_LOONGARCH64) || defined(TARGET_RISCV64)
4962+
4963+
// Patchpoint offset is from top of Tier0 frame
4964+
//
4965+
// We need to determine the frame-pointer relative
4966+
// offset for this variable in the osr frame.
4967+
//
4968+
// First get the fp's relative offset within Tier0 frame
4969+
//
4970+
const int tier0FrameOffset = (int)compiler->info.compPatchpointInfo->CalleeSaveRegisters();
4971+
4972+
// then add the OSR frame size
4973+
//
4974+
const int osrFrameSize = genTotalFrameSize();
4975+
4976+
// then subtract OSR SP-FP delta
4977+
//
4978+
const int osrSpToFpDelta = genSPtoFPdelta();
4979+
4980+
// | => tier0 top of frame relative
4981+
// | + => tier0's fp relative offset
4982+
// | | + => osr bottom of frame (sp) relative
4983+
// | | | - => osr fp relative
4984+
// | | | |
4985+
const int offset = stkOffs + tier0FrameOffset + osrFrameSize - osrSpToFpDelta;
4986+
4987+
JITDUMP("---OSR--- V%02u (reg) Tier0 virtual offset %d OSR frame size %d OSR sp-fp "
4988+
"delta %d total offset %d (0x%x)\n",
4989+
varNum, stkOffs, osrFrameSize, osrSpToFpDelta, offset, offset);
4990+
4991+
genInstrWithConstant(ins_Load(lclTyp), size, varDsc->GetRegNum(), genFramePointerReg(), offset, initReg);
4992+
*pInitRegZeroed = false;
4993+
#endif // TARGET_LOONGARCH64 || TARGET_RISCV64
49624994
}
49634995
}
49644996

@@ -5563,20 +5595,13 @@ void CodeGen::genFinalizeFrame()
55635595
#endif // defined(TARGET_XARCH)
55645596

55655597
#if defined(TARGET_LOONGARCH64) || defined(TARGET_RISCV64)
5566-
if (isFramePointerUsed())
5567-
{
5568-
// For a FP based frame we have to push/pop the FP register
5569-
//
5570-
maskCalleeRegsPushed |= RBM_FPBASE;
5598+
// This assert check that we are not using REG_FP
5599+
assert(!regSet.rsRegsModified(RBM_FPBASE));
55715600

5572-
// This assert check that we are not using REG_FP
5573-
// as both the frame pointer and as a codegen register
5574-
//
5575-
assert(!regSet.rsRegsModified(RBM_FPBASE));
5576-
}
5601+
assert(isFramePointerUsed());
5602+
// we always push FP/RA. See genPushCalleeSavedRegisters
5603+
maskCalleeRegsPushed |= (RBM_FPBASE | RBM_RA);
55775604

5578-
// we always push RA. See genPushCalleeSavedRegisters
5579-
maskCalleeRegsPushed |= RBM_RA;
55805605
#endif // TARGET_LOONGARCH64 || TARGET_RISCV64
55815606

55825607
compiler->compCalleeRegsPushed = genCountBits(maskCalleeRegsPushed);

0 commit comments

Comments
 (0)
Please sign in to comment.