Skip to content

Commit 9deea5f

Browse files
committed
supporting TARGET_XARCH.
1 parent b96f05c commit 9deea5f

File tree

1 file changed

+13
-41
lines changed

1 file changed

+13
-41
lines changed

src/coreclr/jit/lclvars.cpp

+13-41
Original file line numberDiff line numberDiff line change
@@ -5168,6 +5168,10 @@ void Compiler::lvaFixVirtualFrameOffsets()
51685168
{
51695169
LclVarDsc* varDsc;
51705170

5171+
#if defined(TARGET_LOONGARCH64) || defined(TARGET_XARCH)
5172+
5173+
// For X86/AMD64/LoongArch64, there is no need to recompute the offset.
5174+
51715175
#if defined(FEATURE_EH_FUNCLETS) && defined(TARGET_AMD64)
51725176
if (lvaPSPSym != BAD_VAR_NUM)
51735177
{
@@ -5177,18 +5181,12 @@ void Compiler::lvaFixVirtualFrameOffsets()
51775181
varDsc = lvaGetDesc(lvaPSPSym);
51785182
assert(varDsc->lvFramePointerBased); // We always access it RBP-relative.
51795183
assert(!varDsc->lvMustInit); // It is never "must init".
5180-
varDsc->SetStackOffset(codeGen->genCallerSPtoInitialSPdelta() + lvaLclSize(lvaOutgoingArgSpaceVar));
5181-
5182-
if (opts.IsOSR())
5183-
{
5184-
// With OSR RBP points at the base of the OSR frame, but the virtual offsets
5185-
// are from the base of the Tier0 frame. Adjust.
5186-
//
5187-
varDsc->SetStackOffset(varDsc->GetStackOffset() - info.compPatchpointInfo->TotalFrameSize());
5188-
}
5184+
varDsc->SetStackOffset(lvaLclSize(lvaOutgoingArgSpaceVar) - codeGen->genTotalFrameSize());
51895185
}
51905186
#endif
51915187

5188+
#else
5189+
51925190
// The delta to be added to virtual offset to adjust it relative to frame pointer or SP
51935191
int delta = 0;
51945192

@@ -5224,8 +5222,6 @@ void Compiler::lvaFixVirtualFrameOffsets()
52245222
}
52255223
#endif // TARGET_AMD64 || TARGET_ARM64 || TARGET_RISCV64
52265224

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

53355331
#endif // FEATURE_FIXED_OUT_ARGS
53365332

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

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

6091-
#ifdef TARGET_XARCH
6092-
// On x86/amd64, the return address has already been pushed by the call instruction in the caller.
6093-
stkOffs -= TARGET_POINTER_SIZE; // return address;
6094-
if (lvaRetAddrVar != BAD_VAR_NUM)
6095-
{
6096-
lvaTable[lvaRetAddrVar].SetStackOffset(stkOffs);
6097-
}
6098-
#endif
6099-
61006088
// If we are an OSR method, we "inherit" the frame of the original method
61016089
//
61026090
if (opts.IsOSR())
61036091
{
61046092
#if defined(TARGET_LOONGARCH64)
61056093
originalFrameStkOffs = (compCalleeRegsPushed << 3) + info.compPatchpointInfo->CalleeSaveRegisters();
6094+
#elif defined(TARGET_XARCH)
6095+
originalFrameStkOffs = info.compPatchpointInfo->TotalFrameSize() + TARGET_POINTER_SIZE; // add RA.
61066096
#else
61076097
originalFrameSize = info.compPatchpointInfo->TotalFrameSize();
61086098
originalFrameStkOffs = stkOffs;
61096099
stkOffs -= originalFrameSize;
61106100
#endif
61116101
}
61126102

6113-
#ifdef TARGET_XARCH
6114-
// TODO-AMD64-CQ: for X64 eventually this should be pushed with all the other
6115-
// calleeregs. When you fix this, you'll also need to fix
6116-
// the assert at the bottom of this method
6117-
if (codeGen->doubleAlignOrFramePointerUsed())
6118-
{
6119-
stkOffs -= REGSIZE_BYTES;
6120-
}
6121-
#endif
6122-
61236103
int preSpillSize = 0;
61246104
bool mustDoubleAlign = false;
61256105

@@ -6962,14 +6942,6 @@ void Compiler::lvaAssignVirtualFrameOffsetsToLocals()
69626942
}
69636943
#endif
69646944

6965-
#ifdef TARGET_XARCH
6966-
if (codeGen->doubleAlignOrFramePointerUsed())
6967-
{
6968-
pushedCount += 1; // pushed EBP (frame pointer)
6969-
}
6970-
pushedCount += 1; // pushed PC (return address)
6971-
#endif
6972-
69736945
noway_assert(compLclFrameSize + originalFrameSize ==
69746946
(unsigned)-(stkOffs + (pushedCount * (int)TARGET_POINTER_SIZE)));
69756947
#endif

0 commit comments

Comments
 (0)