Skip to content

Commit

Permalink
[LoongArch64] redesign the frame layout to avoid the redundant
Browse files Browse the repository at this point in the history
computation of the stackOffsets.
After the `lvaAssignVirtualFrameOffsetsToLocals`, there is no need
to recompute the LclVarDsc's StackOffset within the `lvaFixVirtualFrameOffsets`.
  • Loading branch information
shushanhf committed Mar 5, 2024
1 parent 0df43f2 commit 7d09326
Show file tree
Hide file tree
Showing 5 changed files with 344 additions and 357 deletions.
2 changes: 0 additions & 2 deletions src/coreclr/jit/codegen.h
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,6 @@ class CodeGen final : public CodeGenInterface
int fiFunction_CallerSP_to_FP_delta; // Delta between caller SP and the frame pointer in the parent function
// (negative)
int fiSP_to_CalleeSaved_delta; // CalleeSaved register save offset from SP (positive)
int fiCalleeSavedPadding; // CalleeSaved offset padding (positive)
int fiSP_to_PSP_slot_delta; // PSP slot offset from SP (positive)
int fiCallerSP_to_PSP_slot_delta; // PSP slot offset from Caller SP (negative)
int fiSpDelta; // Stack pointer delta (negative)
Expand Down Expand Up @@ -1281,7 +1280,6 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
void genJmpMethod(GenTree* jmp);
BasicBlock* genCallFinally(BasicBlock* block);
#if defined(TARGET_LOONGARCH64) || defined(TARGET_RISCV64)
// TODO: refactor for LA.
void genCodeForJumpCompare(GenTreeOpCC* tree);
#endif
#if defined(TARGET_ARM64)
Expand Down
35 changes: 34 additions & 1 deletion src/coreclr/jit/codegencommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4930,7 +4930,7 @@ void CodeGen::genEnregisterOSRArgsAndLocals()

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

#elif defined(TARGET_ARM64) || defined(TARGET_LOONGARCH64) || defined(TARGET_RISCV64)
#elif defined(TARGET_ARM64) || defined(TARGET_RISCV64)

// Patchpoint offset is from top of Tier0 frame
//
Expand All @@ -4956,6 +4956,39 @@ void CodeGen::genEnregisterOSRArgsAndLocals()
// | | | |
const int offset = stkOffs + tier0FrameSize + osrFrameSize - osrSpToFpDelta;

JITDUMP("---OSR--- V%02u (reg) Tier0 virtual offset %d OSR frame size %d OSR sp-fp "
"delta %d total offset %d (0x%x)\n",
varNum, stkOffs, osrFrameSize, osrSpToFpDelta, offset, offset);

genInstrWithConstant(ins_Load(lclTyp), size, varDsc->GetRegNum(), genFramePointerReg(), offset, initReg);
*pInitRegZeroed = false;

#elif defined(TARGET_LOONGARCH64)

// Patchpoint offset is from top of Tier0 frame
//
// We need to determine the frame-pointer relative
// offset for this variable in the osr frame.
//
// First get the fp's relative offset within Tier0 frame
//
const int tier0FrameOffset = compiler->info.compPatchpointInfo->CalleeSaveRegisters();

// then add the OSR frame size
//
const int osrFrameSize = genTotalFrameSize();

// then subtract OSR SP-FP delta
//
const int osrSpToFpDelta = genSPtoFPdelta();

// | => tier0 top of frame relative
// | + => tier0's fp relative offset
// | | + => osr bottom of frame (sp) relative
// | | | - => osr fp relative
// | | | |
const int offset = stkOffs + tier0FrameOffset + osrFrameSize - osrSpToFpDelta;

JITDUMP("---OSR--- V%02u (reg) Tier0 virtual offset %d OSR frame size %d OSR sp-fp "
"delta %d total offset %d (0x%x)\n",
varNum, stkOffs, osrFrameSize, osrSpToFpDelta, offset, offset);
Expand Down
Loading

0 comments on commit 7d09326

Please sign in to comment.