@@ -5168,6 +5168,10 @@ void Compiler::lvaFixVirtualFrameOffsets()
5168
5168
{
5169
5169
LclVarDsc* varDsc;
5170
5170
5171
+ #if defined(TARGET_LOONGARCH64) || defined(TARGET_XARCH)
5172
+
5173
+ // For X86/AMD64/LoongArch64, there is no need to recompute the offset.
5174
+
5171
5175
#if defined(FEATURE_EH_FUNCLETS) && defined(TARGET_AMD64)
5172
5176
if (lvaPSPSym != BAD_VAR_NUM)
5173
5177
{
@@ -5177,18 +5181,12 @@ void Compiler::lvaFixVirtualFrameOffsets()
5177
5181
varDsc = lvaGetDesc (lvaPSPSym);
5178
5182
assert (varDsc->lvFramePointerBased ); // We always access it RBP-relative.
5179
5183
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 ());
5189
5185
}
5190
5186
#endif
5191
5187
5188
+ #else
5189
+
5192
5190
// The delta to be added to virtual offset to adjust it relative to frame pointer or SP
5193
5191
int delta = 0 ;
5194
5192
@@ -5224,8 +5222,6 @@ void Compiler::lvaFixVirtualFrameOffsets()
5224
5222
}
5225
5223
#endif // TARGET_AMD64 || TARGET_ARM64 || TARGET_RISCV64
5226
5224
5227
- #if !defined(TARGET_LOONGARCH64)
5228
- // For LoongArch64, there is no need to recompute the offset.
5229
5225
if (opts.IsOSR ())
5230
5226
{
5231
5227
#if defined(TARGET_AMD64) || defined(TARGET_ARM64) || defined(TARGET_RISCV64)
@@ -5334,14 +5330,15 @@ void Compiler::lvaFixVirtualFrameOffsets()
5334
5330
5335
5331
#endif // FEATURE_FIXED_OUT_ARGS
5336
5332
5337
- #if defined(TARGET_ARM64) || defined(TARGET_LOONGARCH64)
5333
+ #if defined(TARGET_ARM64) || defined(TARGET_LOONGARCH64) || defined(TARGET_XARCH)
5338
5334
// We normally add alignment below the locals between them and the outgoing
5339
5335
// arg space area. When we store fp/lr(ra) at the bottom, however, this will
5340
5336
// be below the alignment. So we should not apply the alignment adjustment to
5341
5337
// them. It turns out we always store these at +0 and +8 of the FP,
5342
5338
// so instead of dealing with skipping adjustment just for them we just set
5343
5339
// them here always.
5344
5340
// 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.
5345
5342
assert (codeGen->isFramePointerUsed ());
5346
5343
if (lvaRetAddrVar != BAD_VAR_NUM)
5347
5344
{
@@ -5423,7 +5420,7 @@ void Compiler::lvaAssignVirtualFrameOffsetsToArgs()
5423
5420
unsigned lclNum = 0 ;
5424
5421
int argOffs = 0 ;
5425
5422
#ifdef UNIX_AMD64_ABI
5426
- int callerArgOffset = 0 ;
5423
+ int callerArgOffset = TARGET_POINTER_SIZE * 2 ; // return address and rbp.
5427
5424
#endif // UNIX_AMD64_ABI
5428
5425
5429
5426
/*
@@ -5676,7 +5673,7 @@ int Compiler::lvaAssignVirtualFrameOffsetToArg(unsigned lclNum,
5676
5673
// location on the callee stack (like any other local var.) In such a case, the register passed, stack homed
5677
5674
// arguments are accessed using negative offsets and the stack passed arguments are accessed using positive
5678
5675
// 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
5680
5677
// callee allocated space. If frame register is used, the callee allocated space should not be included for
5681
5678
// accessing the caller stack parameters. The last two requirements are met in lvaFixVirtualFrameOffsets
5682
5679
// method, which fixes the offsets, based on frame pointer existence, existence of alloca instructions, ret
@@ -6088,38 +6085,21 @@ void Compiler::lvaAssignVirtualFrameOffsetsToLocals()
6088
6085
}
6089
6086
#endif // TARGET_ARM64
6090
6087
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
-
6100
6088
// If we are an OSR method, we "inherit" the frame of the original method
6101
6089
//
6102
6090
if (opts.IsOSR ())
6103
6091
{
6104
6092
#if defined(TARGET_LOONGARCH64)
6105
6093
originalFrameStkOffs = (compCalleeRegsPushed << 3 ) + info.compPatchpointInfo ->CalleeSaveRegisters ();
6094
+ #elif defined(TARGET_XARCH)
6095
+ originalFrameStkOffs = info.compPatchpointInfo ->TotalFrameSize () + TARGET_POINTER_SIZE; // add RA.
6106
6096
#else
6107
6097
originalFrameSize = info.compPatchpointInfo ->TotalFrameSize ();
6108
6098
originalFrameStkOffs = stkOffs;
6109
6099
stkOffs -= originalFrameSize;
6110
6100
#endif
6111
6101
}
6112
6102
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
-
6123
6103
int preSpillSize = 0 ;
6124
6104
bool mustDoubleAlign = false ;
6125
6105
@@ -6962,14 +6942,6 @@ void Compiler::lvaAssignVirtualFrameOffsetsToLocals()
6962
6942
}
6963
6943
#endif
6964
6944
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
-
6973
6945
noway_assert (compLclFrameSize + originalFrameSize ==
6974
6946
(unsigned )-(stkOffs + (pushedCount * (int )TARGET_POINTER_SIZE)));
6975
6947
#endif
0 commit comments