From 9deea5f7d65ad4940c96f926515a4db6746d6334 Mon Sep 17 00:00:00 2001 From: qiaopengcheng Date: Tue, 19 Mar 2024 15:26:33 +0800 Subject: [PATCH] supporting TARGET_XARCH. --- src/coreclr/jit/lclvars.cpp | 54 +++++++++---------------------------- 1 file changed, 13 insertions(+), 41 deletions(-) diff --git a/src/coreclr/jit/lclvars.cpp b/src/coreclr/jit/lclvars.cpp index 591d581361b13..801b04dd00172 100644 --- a/src/coreclr/jit/lclvars.cpp +++ b/src/coreclr/jit/lclvars.cpp @@ -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) { @@ -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; @@ -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) @@ -5334,7 +5330,7 @@ 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 @@ -5342,6 +5338,7 @@ void Compiler::lvaFixVirtualFrameOffsets() // 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) { @@ -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 /* @@ -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 @@ -6088,21 +6085,14 @@ 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; @@ -6110,16 +6100,6 @@ void Compiler::lvaAssignVirtualFrameOffsetsToLocals() #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; @@ -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