Skip to content

Commit

Permalink
supporting TARGET_XARCH.
Browse files Browse the repository at this point in the history
  • Loading branch information
shushanhf committed Mar 19, 2024
1 parent b96f05c commit 9deea5f
Showing 1 changed file with 13 additions and 41 deletions.
54 changes: 13 additions & 41 deletions src/coreclr/jit/lclvars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5168,6 +5168,10 @@ void Compiler::lvaFixVirtualFrameOffsets()
{
LclVarDsc* varDsc;

#if defined(TARGET_LOONGARCH64) || defined(TARGET_XARCH)

// For X86/AMD64/LoongArch64, there is no need to recompute the offset.

#if defined(FEATURE_EH_FUNCLETS) && defined(TARGET_AMD64)
if (lvaPSPSym != BAD_VAR_NUM)
{
Expand All @@ -5177,18 +5181,12 @@ void Compiler::lvaFixVirtualFrameOffsets()
varDsc = lvaGetDesc(lvaPSPSym);
assert(varDsc->lvFramePointerBased); // We always access it RBP-relative.
assert(!varDsc->lvMustInit); // It is never "must init".
varDsc->SetStackOffset(codeGen->genCallerSPtoInitialSPdelta() + lvaLclSize(lvaOutgoingArgSpaceVar));

if (opts.IsOSR())
{
// With OSR RBP points at the base of the OSR frame, but the virtual offsets
// are from the base of the Tier0 frame. Adjust.
//
varDsc->SetStackOffset(varDsc->GetStackOffset() - info.compPatchpointInfo->TotalFrameSize());
}
varDsc->SetStackOffset(lvaLclSize(lvaOutgoingArgSpaceVar) - codeGen->genTotalFrameSize());
}
#endif

#else

// The delta to be added to virtual offset to adjust it relative to frame pointer or SP
int delta = 0;

Expand Down Expand Up @@ -5224,8 +5222,6 @@ void Compiler::lvaFixVirtualFrameOffsets()
}
#endif // TARGET_AMD64 || TARGET_ARM64 || TARGET_RISCV64

#if !defined(TARGET_LOONGARCH64)
// For LoongArch64, there is no need to recompute the offset.
if (opts.IsOSR())
{
#if defined(TARGET_AMD64) || defined(TARGET_ARM64) || defined(TARGET_RISCV64)
Expand Down Expand Up @@ -5334,14 +5330,15 @@ void Compiler::lvaFixVirtualFrameOffsets()

#endif // FEATURE_FIXED_OUT_ARGS

#if defined(TARGET_ARM64) || defined(TARGET_LOONGARCH64)
#if defined(TARGET_ARM64) || defined(TARGET_LOONGARCH64) || defined(TARGET_XARCH)
// We normally add alignment below the locals between them and the outgoing
// arg space area. When we store fp/lr(ra) at the bottom, however, this will
// be below the alignment. So we should not apply the alignment adjustment to
// them. It turns out we always store these at +0 and +8 of the FP,
// so instead of dealing with skipping adjustment just for them we just set
// them here always.
// For LoongArch64, the RA is above the fp. see the `genPushCalleeSavedRegisters`
// On x86/amd64, the return address has already been pushed by the call instruction in the caller.
assert(codeGen->isFramePointerUsed());
if (lvaRetAddrVar != BAD_VAR_NUM)
{
Expand Down Expand Up @@ -5423,7 +5420,7 @@ void Compiler::lvaAssignVirtualFrameOffsetsToArgs()
unsigned lclNum = 0;
int argOffs = 0;
#ifdef UNIX_AMD64_ABI
int callerArgOffset = 0;
int callerArgOffset = TARGET_POINTER_SIZE * 2; // return address and rbp.
#endif // UNIX_AMD64_ABI

/*
Expand Down Expand Up @@ -5676,7 +5673,7 @@ int Compiler::lvaAssignVirtualFrameOffsetToArg(unsigned lclNum,
// location on the callee stack (like any other local var.) In such a case, the register passed, stack homed
// arguments are accessed using negative offsets and the stack passed arguments are accessed using positive
// offset (from the caller's stack.)
// For System V platforms if there is no frame pointer the caller stack parameter offset should include the
// For System V platforms if there is no frame pointer the caller stack parameter offset should include the
// callee allocated space. If frame register is used, the callee allocated space should not be included for
// accessing the caller stack parameters. The last two requirements are met in lvaFixVirtualFrameOffsets
// method, which fixes the offsets, based on frame pointer existence, existence of alloca instructions, ret
Expand Down Expand Up @@ -6088,38 +6085,21 @@ void Compiler::lvaAssignVirtualFrameOffsetsToLocals()
}
#endif // TARGET_ARM64

#ifdef TARGET_XARCH
// On x86/amd64, the return address has already been pushed by the call instruction in the caller.
stkOffs -= TARGET_POINTER_SIZE; // return address;
if (lvaRetAddrVar != BAD_VAR_NUM)
{
lvaTable[lvaRetAddrVar].SetStackOffset(stkOffs);
}
#endif

// If we are an OSR method, we "inherit" the frame of the original method
//
if (opts.IsOSR())
{
#if defined(TARGET_LOONGARCH64)
originalFrameStkOffs = (compCalleeRegsPushed << 3) + info.compPatchpointInfo->CalleeSaveRegisters();
#elif defined(TARGET_XARCH)
originalFrameStkOffs = info.compPatchpointInfo->TotalFrameSize() + TARGET_POINTER_SIZE; // add RA.
#else
originalFrameSize = info.compPatchpointInfo->TotalFrameSize();
originalFrameStkOffs = stkOffs;
stkOffs -= originalFrameSize;
#endif
}

#ifdef TARGET_XARCH
// TODO-AMD64-CQ: for X64 eventually this should be pushed with all the other
// calleeregs. When you fix this, you'll also need to fix
// the assert at the bottom of this method
if (codeGen->doubleAlignOrFramePointerUsed())
{
stkOffs -= REGSIZE_BYTES;
}
#endif

int preSpillSize = 0;
bool mustDoubleAlign = false;

Expand Down Expand Up @@ -6962,14 +6942,6 @@ void Compiler::lvaAssignVirtualFrameOffsetsToLocals()
}
#endif

#ifdef TARGET_XARCH
if (codeGen->doubleAlignOrFramePointerUsed())
{
pushedCount += 1; // pushed EBP (frame pointer)
}
pushedCount += 1; // pushed PC (return address)
#endif

noway_assert(compLclFrameSize + originalFrameSize ==
(unsigned)-(stkOffs + (pushedCount * (int)TARGET_POINTER_SIZE)));
#endif
Expand Down

0 comments on commit 9deea5f

Please sign in to comment.