@@ -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)
@@ -5275,6 +5271,7 @@ void Compiler::lvaFixVirtualFrameOffsets()
5275
5271
&& compIsProfilerHookNeeded () &&
5276
5272
!lvaIsPreSpilled (lclNum, codeGen->regSet .rsMaskPreSpillRegs (false )) // We need assign stack offsets
5277
5273
// for prespilled arguments
5274
+
5278
5275
#endif
5279
5276
)
5280
5277
#endif // !defined(TARGET_AMD64)
@@ -5334,14 +5331,15 @@ void Compiler::lvaFixVirtualFrameOffsets()
5334
5331
5335
5332
#endif // FEATURE_FIXED_OUT_ARGS
5336
5333
5337
- #if defined(TARGET_ARM64) || defined(TARGET_LOONGARCH64)
5334
+ #if defined(TARGET_ARM64) || defined(TARGET_LOONGARCH64) || defined(TARGET_XARCH)
5338
5335
// We normally add alignment below the locals between them and the outgoing
5339
5336
// arg space area. When we store fp/lr(ra) at the bottom, however, this will
5340
5337
// be below the alignment. So we should not apply the alignment adjustment to
5341
5338
// them. It turns out we always store these at +0 and +8 of the FP,
5342
5339
// so instead of dealing with skipping adjustment just for them we just set
5343
5340
// them here always.
5344
5341
// 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.
5345
5343
assert (codeGen->isFramePointerUsed ());
5346
5344
if (lvaRetAddrVar != BAD_VAR_NUM)
5347
5345
{
@@ -5423,7 +5421,8 @@ void Compiler::lvaAssignVirtualFrameOffsetsToArgs()
5423
5421
unsigned lclNum = 0 ;
5424
5422
int argOffs = 0 ;
5425
5423
#ifdef UNIX_AMD64_ABI
5426
- int callerArgOffset = 0 ;
5424
+ // add the return address and rbp.
5425
+ int callerArgOffset = TARGET_POINTER_SIZE * 2 ;
5427
5426
#endif // UNIX_AMD64_ABI
5428
5427
5429
5428
/*
@@ -5676,7 +5675,7 @@ int Compiler::lvaAssignVirtualFrameOffsetToArg(unsigned lclNum,
5676
5675
// location on the callee stack (like any other local var.) In such a case, the register passed, stack homed
5677
5676
// arguments are accessed using negative offsets and the stack passed arguments are accessed using positive
5678
5677
// 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
5680
5679
// callee allocated space. If frame register is used, the callee allocated space should not be included for
5681
5680
// accessing the caller stack parameters. The last two requirements are met in lvaFixVirtualFrameOffsets
5682
5681
// method, which fixes the offsets, based on frame pointer existence, existence of alloca instructions, ret
@@ -6088,38 +6087,21 @@ void Compiler::lvaAssignVirtualFrameOffsetsToLocals()
6088
6087
}
6089
6088
#endif // TARGET_ARM64
6090
6089
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
6090
// If we are an OSR method, we "inherit" the frame of the original method
6101
6091
//
6102
6092
if (opts.IsOSR ())
6103
6093
{
6104
6094
#if defined(TARGET_LOONGARCH64)
6105
6095
originalFrameStkOffs = (compCalleeRegsPushed << 3 ) + info.compPatchpointInfo ->CalleeSaveRegisters ();
6096
+ #elif defined(TARGET_XARCH)
6097
+ originalFrameStkOffs = info.compPatchpointInfo ->TotalFrameSize () + TARGET_POINTER_SIZE; // add RA.
6106
6098
#else
6107
6099
originalFrameSize = info.compPatchpointInfo ->TotalFrameSize ();
6108
6100
originalFrameStkOffs = stkOffs;
6109
6101
stkOffs -= originalFrameSize;
6110
6102
#endif
6111
6103
}
6112
6104
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
6105
int preSpillSize = 0 ;
6124
6106
bool mustDoubleAlign = false ;
6125
6107
@@ -6962,14 +6944,6 @@ void Compiler::lvaAssignVirtualFrameOffsetsToLocals()
6962
6944
}
6963
6945
#endif
6964
6946
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
6947
noway_assert (compLclFrameSize + originalFrameSize ==
6974
6948
(unsigned )-(stkOffs + (pushedCount * (int )TARGET_POINTER_SIZE)));
6975
6949
#endif
0 commit comments