Skip to content

Commit 6ca44dd

Browse files
committed
supporting TARGET_XARCH.
1 parent b96f05c commit 6ca44dd

File tree

1 file changed

+15
-41
lines changed

1 file changed

+15
-41
lines changed

src/coreclr/jit/lclvars.cpp

+15-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)
@@ -5275,6 +5271,7 @@ void Compiler::lvaFixVirtualFrameOffsets()
52755271
&& compIsProfilerHookNeeded() &&
52765272
!lvaIsPreSpilled(lclNum, codeGen->regSet.rsMaskPreSpillRegs(false)) // We need assign stack offsets
52775273
// for prespilled arguments
5274+
52785275
#endif
52795276
)
52805277
#endif // !defined(TARGET_AMD64)
@@ -5334,14 +5331,15 @@ void Compiler::lvaFixVirtualFrameOffsets()
53345331

53355332
#endif // FEATURE_FIXED_OUT_ARGS
53365333

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

54295428
/*
@@ -5676,7 +5675,7 @@ int Compiler::lvaAssignVirtualFrameOffsetToArg(unsigned lclNum,
56765675
// location on the callee stack (like any other local var.) In such a case, the register passed, stack homed
56775676
// arguments are accessed using negative offsets and the stack passed arguments are accessed using positive
56785677
// 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
5678+
// For System V platforms if there is no frame pointer the caller stack parameter offset should include the
56805679
// callee allocated space. If frame register is used, the callee allocated space should not be included for
56815680
// accessing the caller stack parameters. The last two requirements are met in lvaFixVirtualFrameOffsets
56825681
// method, which fixes the offsets, based on frame pointer existence, existence of alloca instructions, ret
@@ -6088,38 +6087,21 @@ void Compiler::lvaAssignVirtualFrameOffsetsToLocals()
60886087
}
60896088
#endif // TARGET_ARM64
60906089

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-
61006090
// If we are an OSR method, we "inherit" the frame of the original method
61016091
//
61026092
if (opts.IsOSR())
61036093
{
61046094
#if defined(TARGET_LOONGARCH64)
61056095
originalFrameStkOffs = (compCalleeRegsPushed << 3) + info.compPatchpointInfo->CalleeSaveRegisters();
6096+
#elif defined(TARGET_XARCH)
6097+
originalFrameStkOffs = info.compPatchpointInfo->TotalFrameSize() + TARGET_POINTER_SIZE; // add RA.
61066098
#else
61076099
originalFrameSize = info.compPatchpointInfo->TotalFrameSize();
61086100
originalFrameStkOffs = stkOffs;
61096101
stkOffs -= originalFrameSize;
61106102
#endif
61116103
}
61126104

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-
61236105
int preSpillSize = 0;
61246106
bool mustDoubleAlign = false;
61256107

@@ -6962,14 +6944,6 @@ void Compiler::lvaAssignVirtualFrameOffsetsToLocals()
69626944
}
69636945
#endif
69646946

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-
69736947
noway_assert(compLclFrameSize + originalFrameSize ==
69746948
(unsigned)-(stkOffs + (pushedCount * (int)TARGET_POINTER_SIZE)));
69756949
#endif

0 commit comments

Comments
 (0)