From f1c5228ea7bb0d667aab92dfee2de5b22c4eab8d Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Thu, 6 Jul 2023 22:21:53 -0700 Subject: [PATCH 01/58] wip --- src/coreclr/inc/corinfo.h | 5 + src/coreclr/inc/icorjitinfoimpl_generated.h | 6 + src/coreclr/jit/ICorJitInfo_names_generated.h | 2 + .../jit/ICorJitInfo_wrapper_generated.hpp | 16 ++ src/coreclr/jit/compiler.h | 1 + src/coreclr/jit/helperexpansion.cpp | 204 +++++++++++++++++- src/coreclr/jit/importer.cpp | 31 ++- .../Common/JitInterface/CorInfoHelpFunc.cs | 5 +- .../tools/Common/JitInterface/CorInfoImpl.cs | 7 - .../JitInterface/CorInfoImpl_generated.cs | 182 +++++++++------- .../tools/Common/JitInterface/CorInfoTypes.cs | 1 + .../ThunkGenerator/ThunkInput.txt | 2 + .../DependencyAnalysis/NodeFactory.cs | 2 +- .../JitInterface/CorInfoImpl.ReadyToRun.cs | 17 ++ .../JitInterface/CorInfoImpl.RyuJit.cs | 42 +++- .../tools/aot/ILCompiler/repro/Program.cs | 33 ++- .../tools/aot/ILCompiler/repro/repro.csproj | 3 +- src/coreclr/tools/aot/ilc.sln | 145 +++++++++++++ .../aot/jitinterface/jitinterface_generated.h | 18 ++ .../icorjitinfo_generated.cpp | 14 ++ .../icorjitinfo_generated.cpp | 12 ++ 21 files changed, 644 insertions(+), 104 deletions(-) diff --git a/src/coreclr/inc/corinfo.h b/src/coreclr/inc/corinfo.h index 25634caea84e1c..258bc375a56f8c 100644 --- a/src/coreclr/inc/corinfo.h +++ b/src/coreclr/inc/corinfo.h @@ -601,6 +601,7 @@ enum CorInfoHelpFunc CORINFO_HELP_READYTORUN_GENERIC_HANDLE, CORINFO_HELP_READYTORUN_DELEGATE_CTOR, CORINFO_HELP_READYTORUN_GENERIC_STATIC_BASE, + CORINFO_HELP_READYTORUN_INLINED_THREADSTATIC_BASE_SLOW, CORINFO_HELP_EE_PERSONALITY_ROUTINE,// Not real JIT helper. Used in native images. CORINFO_HELP_EE_PERSONALITY_ROUTINE_FILTER_FUNCLET,// Not real JIT helper. Used in native images to detect filter funclets. @@ -1736,6 +1737,7 @@ struct CORINFO_THREAD_STATIC_BLOCKS_INFO uint32_t offsetOfMaxThreadStaticBlocks; uint32_t offsetOfThreadStaticBlocks; uint32_t offsetOfGCDataPointer; + CORINFO_CONST_LOOKUP tlsRoot; // for nativeaot }; //---------------------------------------------------------------------------- @@ -2789,6 +2791,9 @@ class ICorStaticInfo bool isGCType ) = 0; + virtual void getTlsRootInfo(CORINFO_CONST_LOOKUP* addr) = 0; + virtual void getThreadStaticBaseSlowInfo(CORINFO_CONST_LOOKUP* addr) = 0; + // Returns true iff "fldHnd" represents a static field. virtual bool isFieldStatic(CORINFO_FIELD_HANDLE fldHnd) = 0; diff --git a/src/coreclr/inc/icorjitinfoimpl_generated.h b/src/coreclr/inc/icorjitinfoimpl_generated.h index 20ee55464b3c46..480abb44e31e82 100644 --- a/src/coreclr/inc/icorjitinfoimpl_generated.h +++ b/src/coreclr/inc/icorjitinfoimpl_generated.h @@ -396,6 +396,12 @@ void getThreadLocalStaticBlocksInfo( CORINFO_THREAD_STATIC_BLOCKS_INFO* pInfo, bool isGCType) override; +void getTlsRootInfo( + CORINFO_CONST_LOOKUP* addr) override; + +void getThreadStaticBaseSlowInfo( + CORINFO_CONST_LOOKUP* addr) override; + bool isFieldStatic( CORINFO_FIELD_HANDLE fldHnd) override; diff --git a/src/coreclr/jit/ICorJitInfo_names_generated.h b/src/coreclr/jit/ICorJitInfo_names_generated.h index 79ca7d43da06e8..49f902ea2c4e91 100644 --- a/src/coreclr/jit/ICorJitInfo_names_generated.h +++ b/src/coreclr/jit/ICorJitInfo_names_generated.h @@ -98,6 +98,8 @@ DEF_CLR_API(getFieldOffset) DEF_CLR_API(getFieldInfo) DEF_CLR_API(getThreadLocalFieldInfo) DEF_CLR_API(getThreadLocalStaticBlocksInfo) +DEF_CLR_API(getTlsRootInfo) +DEF_CLR_API(getThreadStaticBaseSlowInfo) DEF_CLR_API(isFieldStatic) DEF_CLR_API(getArrayOrStringLength) DEF_CLR_API(getBoundaries) diff --git a/src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp b/src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp index ae0b25b0a63cc5..8030b508fdd0ef 100644 --- a/src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp +++ b/src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp @@ -932,6 +932,22 @@ void WrapICorJitInfo::getThreadLocalStaticBlocksInfo( API_LEAVE(getThreadLocalStaticBlocksInfo); } +void WrapICorJitInfo::getTlsRootInfo( + CORINFO_CONST_LOOKUP* addr) +{ + API_ENTER(getTlsRootInfo); + wrapHnd->getTlsRootInfo(addr); + API_LEAVE(getTlsRootInfo); +} + +void WrapICorJitInfo::getThreadStaticBaseSlowInfo( + CORINFO_CONST_LOOKUP* addr) +{ + API_ENTER(getThreadStaticBaseSlowInfo); + wrapHnd->getThreadStaticBaseSlowInfo(addr); + API_LEAVE(getThreadStaticBaseSlowInfo); +} + bool WrapICorJitInfo::isFieldStatic( CORINFO_FIELD_HANDLE fldHnd) { diff --git a/src/coreclr/jit/compiler.h b/src/coreclr/jit/compiler.h index e752044acf82f0..504b1aeab680f3 100644 --- a/src/coreclr/jit/compiler.h +++ b/src/coreclr/jit/compiler.h @@ -5355,6 +5355,7 @@ class Compiler PhaseStatus fgExpandThreadLocalAccess(); bool fgExpandThreadLocalAccessForCall(BasicBlock** pBlock, Statement* stmt, GenTreeCall* call); + bool fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, Statement* stmt, GenTreeCall* call); PhaseStatus fgExpandStaticInit(); bool fgExpandStaticInitForCall(BasicBlock** pBlock, Statement* stmt, GenTreeCall* call); diff --git a/src/coreclr/jit/helperexpansion.cpp b/src/coreclr/jit/helperexpansion.cpp index 795245d0dc2f23..71e27e5eeea33a 100644 --- a/src/coreclr/jit/helperexpansion.cpp +++ b/src/coreclr/jit/helperexpansion.cpp @@ -443,7 +443,192 @@ PhaseStatus Compiler::fgExpandThreadLocalAccess() return result; } - return fgExpandHelper<&Compiler::fgExpandThreadLocalAccessForCall>(true); + return opts.IsReadyToRun() ? fgExpandHelper<&Compiler::fgExpandThreadLocalAccessForCallReadyToRun>(true) + : fgExpandHelper<&Compiler::fgExpandThreadLocalAccessForCall>(true); +} + +bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, Statement* stmt, GenTreeCall* call) +{ + assert(opts.IsReadyToRun()); + BasicBlock* block = *pBlock; + assert(call->IsHelperCall()); + if (!call->IsExpTLSFieldAccess()) + { + return false; + } + + JITDUMP("Expanding thread static local access for [%06d] in " FMT_BB ":\n", dspTreeID(call), block->bbNum); + DISPTREE(call); + JITDUMP("\n"); + CORINFO_THREAD_STATIC_BLOCKS_INFO threadStaticBlocksInfo; + memset(&threadStaticBlocksInfo, 0, sizeof(CORINFO_THREAD_STATIC_BLOCKS_INFO)); + + info.compCompHnd->getThreadLocalStaticBlocksInfo(&threadStaticBlocksInfo, false); + + JITDUMP("getThreadLocalStaticBlocksInfo\n:"); + JITDUMP("tlsIndex= %p\n", dspPtr(threadStaticBlocksInfo.tlsIndex.addr)); + JITDUMP("tlsGetAddrFtnPtr= %p\n", dspPtr(threadStaticBlocksInfo.tlsGetAddrFtnPtr)); + JITDUMP("tlsIndexObject= %p\n", dspPtr(threadStaticBlocksInfo.tlsIndexObject)); + JITDUMP("threadVarsSection= %p\n", dspPtr(threadStaticBlocksInfo.threadVarsSection)); + JITDUMP("offsetOfThreadLocalStoragePointer= %u\n", + dspOffset(threadStaticBlocksInfo.offsetOfThreadLocalStoragePointer)); + JITDUMP("offsetOfMaxThreadStaticBlocks= %u\n", dspOffset(threadStaticBlocksInfo.offsetOfMaxThreadStaticBlocks)); + JITDUMP("offsetOfThreadStaticBlocks= %u\n", dspOffset(threadStaticBlocksInfo.offsetOfThreadStaticBlocks)); + JITDUMP("offsetOfGCDataPointer= %u\n", dspOffset(threadStaticBlocksInfo.offsetOfGCDataPointer)); + + call->ClearExpTLSFieldAccess(); + + // Split block right before the call tree + BasicBlock* prevBb = block; + GenTree** callUse = nullptr; + Statement* newFirstStmt = nullptr; + DebugInfo debugInfo = stmt->GetDebugInfo(); + block = fgSplitBlockBeforeTree(block, stmt, call, &newFirstStmt, &callUse); + *pBlock = block; + var_types callType = call->TypeGet(); + assert(prevBb != nullptr && block != nullptr); + + // Block ops inserted by the split need to be morphed here since we are after morph. + // We cannot morph stmt yet as we may modify it further below, and the morphing + // could invalidate callUse. + while ((newFirstStmt != nullptr) && (newFirstStmt != stmt)) + { + fgMorphStmtBlockOps(block, newFirstStmt); + newFirstStmt = newFirstStmt->GetNextStmt(); + } + + GenTreeLclVar* threadStaticBlockLcl = nullptr; + + // Grab a temp to store result (it's assigned from either fastPathBb or fallbackBb) + unsigned threadStaticBlockLclNum = lvaGrabTemp(true DEBUGARG("TLS field access")); + lvaTable[threadStaticBlockLclNum].lvType = callType; + threadStaticBlockLcl = gtNewLclvNode(threadStaticBlockLclNum, callType); + + *callUse = gtClone(threadStaticBlockLcl); + + fgMorphStmtBlockOps(block, stmt); + gtUpdateStmtSideEffects(stmt); + + GenTree* tlsValue = nullptr; + unsigned tlsLclNum = lvaGrabTemp(true DEBUGARG("TLS access")); + lvaTable[tlsLclNum].lvType = TYP_I_IMPL; + GenTree* maxThreadStaticBlocksValue = nullptr; + GenTree* threadStaticBlocksValue = nullptr; + GenTree* tlsValueDef = nullptr; + + if (TargetOS::IsWindows) + { + // Mark this ICON as a TLS_HDL, codegen will use FS:[cns] or GS:[cns] + tlsValue = gtNewIconHandleNode(threadStaticBlocksInfo.offsetOfThreadLocalStoragePointer, GTF_ICON_TLS_HDL); + tlsValue = gtNewIndir(TYP_I_IMPL, tlsValue, GTF_IND_NONFAULTING | GTF_IND_INVARIANT); + + size_t tlsIndexValue = (size_t)threadStaticBlocksInfo.tlsIndex.addr; + GenTree* dllRef = gtNewIconHandleNode(tlsIndexValue, GTF_ICON_TLS_HDL); + dllRef = gtNewIndir(TYP_I_IMPL, dllRef, GTF_IND_NONFAULTING | GTF_IND_INVARIANT); + // Add the dllRef to produce thread local storage reference for coreclr + tlsValue = gtNewOperNode(GT_ADD, TYP_I_IMPL, tlsValue, dllRef); + + // Base of coreclr's thread local storage + tlsValue = gtNewIndir(TYP_I_IMPL, tlsValue, GTF_IND_NONFAULTING | GTF_IND_INVARIANT); + + CORINFO_CONST_LOOKUP tlsRootNode; + info.compCompHnd->getTlsRootInfo(&tlsRootNode); + + GenTree* tlsRootOffset = gtNewIconHandleNode((size_t)tlsRootNode.handle, GTF_ICON_OBJ_HDL); + + // Add the tlsValue and tlsRootOffset to produce tlsRootAddr. + GenTree* tlsRootAddr = gtNewOperNode(GT_ADD, TYP_I_IMPL, tlsValue, tlsRootOffset); + + GenTree* tlsRootVal = gtNewIndir(TYP_I_IMPL, tlsRootAddr, GTF_IND_NONFAULTING | GTF_IND_INVARIANT); + + // Cache the TlsRoot value + unsigned tlsRootLclNum = lvaGrabTemp(true DEBUGARG("TlsRoot access")); + lvaTable[tlsRootLclNum].lvType = TYP_I_IMPL; + GenTree* tlsRootDef = gtNewStoreLclVarNode(tlsRootLclNum, tlsRootVal); + GenTree* tlsRootUse = gtNewLclVarNode(tlsRootLclNum); + + GenTree* tlsRootNullCond = gtNewOperNode(GT_NE, TYP_INT, tlsRootUse, gtNewIconNode(0, TYP_I_IMPL)); + tlsRootNullCond = gtNewOperNode(GT_JTRUE, TYP_VOID, tlsRootNullCond); + + // prevBb (BBJ_NONE): [weight: 1.0] + // ... + // + // tlsRootNullCondBB (BBJ_COND): [weight: 1.0] + // fastPathValue = [tlsRootAddress] + // if (fastPathValue != nullptr) + // goto fastPathBb; + // + // fallbackBb (BBJ_ALWAYS): [weight: 0] + // tlsRoot = HelperCall(); + // goto block; + // + // fastPathBb(BBJ_ALWAYS): [weight: 1.0] + // tlsRoot = fastPathValue; + // + // block (...): [weight: 1.0] + // use(tlsRoot); + // ... + + // tlsRootNullCondBB + BasicBlock* tlsRootNullCondBB = fgNewBBFromTreeAfter(BBJ_COND, prevBb, tlsRootDef, debugInfo); + + fgInsertStmtAfter(tlsRootNullCondBB, tlsRootNullCondBB->firstStmt(), fgNewStmtFromTree(tlsRootNullCond)); + + CORINFO_CONST_LOOKUP threadStaticSlowHelper; + info.compCompHnd->getThreadStaticBaseSlowInfo(&threadStaticSlowHelper); + + GenTree* slowHelper = gtNewIndCallNode(gtNewIconHandleNode((size_t)threadStaticSlowHelper.addr, GTF_ICON_TLS_HDL), TYP_VOID); + + // fallbackBb + GenTree* fallbackValueDef = gtNewStoreLclVarNode(tlsRootLclNum, slowHelper); + BasicBlock* fallbackBb = fgNewBBFromTreeAfter(BBJ_ALWAYS, tlsRootNullCondBB, fallbackValueDef, debugInfo, true); + + GenTree* fastPathValueDef = gtNewStoreLclVarNode(tlsRootLclNum, gtCloneExpr(tlsRootUse)); + BasicBlock* fastPathBb = fgNewBBFromTreeAfter(BBJ_ALWAYS, fallbackBb, fastPathValueDef, debugInfo, true); + + // + // Update preds in all new blocks + // + fgRemoveRefPred(block, prevBb); + fgAddRefPred(tlsRootNullCondBB, prevBb); + + fgAddRefPred(fallbackBb, tlsRootNullCondBB); + fgAddRefPred(fastPathBb, tlsRootNullCondBB); + + fgAddRefPred(block, fallbackBb); + fgAddRefPred(block, fastPathBb); + + tlsRootNullCondBB->bbJumpDest = fastPathBb; + fastPathBb->bbJumpDest = block; + fallbackBb->bbJumpDest = block; + + // Inherit the weights + block->inheritWeight(prevBb); + tlsRootNullCondBB->inheritWeight(prevBb); + fastPathBb->inheritWeight(prevBb); + + // fallback will just execute first time + fallbackBb->bbSetRunRarely(); + + // + // Update loop info if loop table is known to be valid + // + tlsRootNullCondBB->bbNatLoopNum = prevBb->bbNatLoopNum; + fastPathBb->bbNatLoopNum = prevBb->bbNatLoopNum; + fallbackBb->bbNatLoopNum = prevBb->bbNatLoopNum; + + // All blocks are expected to be in the same EH region + assert(BasicBlock::sameEHRegion(prevBb, block)); + assert(BasicBlock::sameEHRegion(prevBb, tlsRootNullCondBB)); + assert(BasicBlock::sameEHRegion(prevBb, fastPathBb)); + + return true; + } + else + { + assert(!"Unsupported scenario\n"); + } + return false; } //------------------------------------------------------------------------------ @@ -471,6 +656,8 @@ PhaseStatus Compiler::fgExpandThreadLocalAccess() // bool Compiler::fgExpandThreadLocalAccessForCall(BasicBlock** pBlock, Statement* stmt, GenTreeCall* call) { + assert(!opts.IsReadyToRun()); + BasicBlock* block = *pBlock; if (!call->IsHelperCall() || !call->IsExpTLSFieldAccess()) @@ -478,8 +665,6 @@ bool Compiler::fgExpandThreadLocalAccessForCall(BasicBlock** pBlock, Statement* return false; } - assert(!opts.IsReadyToRun()); - if (TargetOS::IsUnix) { #if defined(TARGET_ARM) || !defined(TARGET_64BIT) @@ -524,9 +709,9 @@ bool Compiler::fgExpandThreadLocalAccessForCall(BasicBlock** pBlock, Statement* assert((eeGetHelperNum(call->gtCallMethHnd) == CORINFO_HELP_GETSHARED_NONGCTHREADSTATIC_BASE_NOCTOR_OPTIMIZED) || (eeGetHelperNum(call->gtCallMethHnd) == CORINFO_HELP_GETSHARED_GCTHREADSTATIC_BASE_NOCTOR_OPTIMIZED)); + assert(call->gtArgs.CountArgs() == 1); call->ClearExpTLSFieldAccess(); - assert(call->gtArgs.CountArgs() == 1); // Split block right before the call tree BasicBlock* prevBb = block; @@ -559,7 +744,6 @@ bool Compiler::fgExpandThreadLocalAccessForCall(BasicBlock** pBlock, Statement* fgMorphStmtBlockOps(block, stmt); gtUpdateStmtSideEffects(stmt); - GenTree* typeThreadStaticBlockIndexValue = call->gtArgs.GetArgByIndex(0)->GetNode(); GenTree* tlsValue = nullptr; unsigned tlsLclNum = lvaGrabTemp(true DEBUGARG("TLS access")); lvaTable[tlsLclNum].lvType = TYP_I_IMPL; @@ -569,18 +753,17 @@ bool Compiler::fgExpandThreadLocalAccessForCall(BasicBlock** pBlock, Statement* if (TargetOS::IsWindows) { + // Mark this ICON as a TLS_HDL, codegen will use FS:[cns] or GS:[cns] + tlsValue = gtNewIconHandleNode(threadStaticBlocksInfo.offsetOfThreadLocalStoragePointer, GTF_ICON_TLS_HDL); + tlsValue = gtNewIndir(TYP_I_IMPL, tlsValue, GTF_IND_NONFAULTING | GTF_IND_INVARIANT); + size_t tlsIndexValue = (size_t)threadStaticBlocksInfo.tlsIndex.addr; GenTree* dllRef = nullptr; - if (tlsIndexValue != 0) { dllRef = gtNewIconHandleNode(tlsIndexValue * TARGET_POINTER_SIZE, GTF_ICON_TLS_HDL); } - // Mark this ICON as a TLS_HDL, codegen will use FS:[cns] or GS:[cns] - tlsValue = gtNewIconHandleNode(threadStaticBlocksInfo.offsetOfThreadLocalStoragePointer, GTF_ICON_TLS_HDL); - tlsValue = gtNewIndir(TYP_I_IMPL, tlsValue, GTF_IND_NONFAULTING | GTF_IND_INVARIANT); - if (dllRef != nullptr) { // Add the dllRef to produce thread local storage reference for coreclr @@ -687,6 +870,7 @@ bool Compiler::fgExpandThreadLocalAccessForCall(BasicBlock** pBlock, Statement* threadStaticBlocksValue = gtNewIndir(TYP_I_IMPL, threadStaticBlocksRef, GTF_IND_NONFAULTING | GTF_IND_INVARIANT); // Create tree for "if (maxThreadStaticBlocks < typeIndex)" + GenTree* typeThreadStaticBlockIndexValue = gtNewIconNode(0, TYP_INT); // call->gtArgs.GetArgByIndex(0)->GetNode(); GenTree* maxThreadStaticBlocksCond = gtNewOperNode(GT_LT, TYP_INT, maxThreadStaticBlocksValue, gtCloneExpr(typeThreadStaticBlockIndexValue)); maxThreadStaticBlocksCond = gtNewOperNode(GT_JTRUE, TYP_VOID, maxThreadStaticBlocksCond); diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index 6e648ac189130b..21d0c2ac1ea9c0 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -3779,14 +3779,22 @@ GenTree* Compiler::impImportStaticFieldAddress(CORINFO_RESOLVED_TOKEN* pResolved case CORINFO_FIELD_STATIC_TLS_MANAGED: - if (pFieldInfo->helper == CORINFO_HELP_GETSHARED_NONGCTHREADSTATIC_BASE_NOCTOR_OPTIMIZED) +#ifdef FEATURE_READYTORUN + if (opts.IsReadyToRun()) { - typeIndex = info.compCompHnd->getThreadLocalFieldInfo(pResolvedToken->hField, false); } else +#endif // FEATURE_READYTORUN { - assert(pFieldInfo->helper == CORINFO_HELP_GETSHARED_GCTHREADSTATIC_BASE_NOCTOR_OPTIMIZED); - typeIndex = info.compCompHnd->getThreadLocalFieldInfo(pResolvedToken->hField, true); + if (pFieldInfo->helper == CORINFO_HELP_GETSHARED_NONGCTHREADSTATIC_BASE_NOCTOR_OPTIMIZED) + { + typeIndex = info.compCompHnd->getThreadLocalFieldInfo(pResolvedToken->hField, false); + } + else + { + assert(pFieldInfo->helper == CORINFO_HELP_GETSHARED_GCTHREADSTATIC_BASE_NOCTOR_OPTIMIZED); + typeIndex = info.compCompHnd->getThreadLocalFieldInfo(pResolvedToken->hField, true); + } } FALLTHROUGH; @@ -3804,7 +3812,22 @@ GenTree* Compiler::impImportStaticFieldAddress(CORINFO_RESOLVED_TOKEN* pResolved callFlags |= GTF_CALL_HOISTABLE; } + //if (pFieldInfo->fieldAccessor == CORINFO_FIELD_STATIC_TLS_MANAGED) + ////if (pFieldInfo->helper == CORINFO_HELP_GETSHARED_NONGCTHREADSTATIC_BASE_NOCTOR_OPTIMIZED) + //{ + // // for now. We will eventually need a new helper that doesn't take argument + // op1 = gtNewHelperCallNode(pFieldInfo->helper, TYP_BYREF, gtNewIconNode(0)); + // op1->AsCall()->SetExpTLSFieldAccess(); + //} + //else + //{ + // op1 = gtNewHelperCallNode(pFieldInfo->helper, TYP_BYREF); + //} op1 = gtNewHelperCallNode(pFieldInfo->helper, TYP_BYREF); + if (pFieldInfo->fieldAccessor == CORINFO_FIELD_STATIC_TLS_MANAGED) + { + op1->AsCall()->SetExpTLSFieldAccess(); + } if (pResolvedToken->hClass == info.compClassHnd && m_preferredInitCctor == CORINFO_HELP_UNDEF && (pFieldInfo->helper == CORINFO_HELP_READYTORUN_GCSTATIC_BASE || pFieldInfo->helper == CORINFO_HELP_READYTORUN_NONGCSTATIC_BASE)) diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoHelpFunc.cs b/src/coreclr/tools/Common/JitInterface/CorInfoHelpFunc.cs index 7837e8c24f832f..a87d4770ba79a5 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoHelpFunc.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoHelpFunc.cs @@ -187,11 +187,11 @@ which is the right helper to use to allocate an object of a given type. */ CORINFO_HELP_GETSHARED_GCTHREADSTATIC_BASE, CORINFO_HELP_GETSHARED_NONGCTHREADSTATIC_BASE, CORINFO_HELP_GETSHARED_GCTHREADSTATIC_BASE_NOCTOR, - CORINFO_HELP_GETSHARED_GCTHREADSTATIC_BASE_NOCTOR_OPTIMIZED, CORINFO_HELP_GETSHARED_NONGCTHREADSTATIC_BASE_NOCTOR, - CORINFO_HELP_GETSHARED_NONGCTHREADSTATIC_BASE_NOCTOR_OPTIMIZED, CORINFO_HELP_GETSHARED_GCTHREADSTATIC_BASE_DYNAMICCLASS, CORINFO_HELP_GETSHARED_NONGCTHREADSTATIC_BASE_DYNAMICCLASS, + CORINFO_HELP_GETSHARED_GCTHREADSTATIC_BASE_NOCTOR_OPTIMIZED, + CORINFO_HELP_GETSHARED_NONGCTHREADSTATIC_BASE_NOCTOR_OPTIMIZED, /* Debugger */ @@ -243,6 +243,7 @@ which is the right helper to use to allocate an object of a given type. */ CORINFO_HELP_READYTORUN_GENERIC_HANDLE, CORINFO_HELP_READYTORUN_DELEGATE_CTOR, CORINFO_HELP_READYTORUN_GENERIC_STATIC_BASE, + CORINFO_HELP_READYTORUN_INLINED_THREADSTATIC_BASE_SLOW, CORINFO_HELP_EE_PERSONALITY_ROUTINE, // Not real JIT helper. Used in native images. CORINFO_HELP_EE_PERSONALITY_ROUTINE_FILTER_FUNCLET, // Not real JIT helper. Used in native images to detect filter funclets. diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs index 453e80c381e5c0..8c82cd3e108cde 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs @@ -2993,13 +2993,6 @@ private uint getThreadLocalFieldInfo(CORINFO_FIELD_STRUCT_* fld, bool isGCType) return 0; } -#pragma warning disable CA1822 // Mark members as static - private void getThreadLocalStaticBlocksInfo(CORINFO_THREAD_STATIC_BLOCKS_INFO* pInfo, bool isGCType) -#pragma warning restore CA1822 // Mark members as static - { - // Implemented for JIT only for now. - } - private CORINFO_CLASS_STRUCT_* getFieldClass(CORINFO_FIELD_STRUCT_* field) { var fieldDesc = HandleToObject(field); diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs b/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs index 51d3f1ba7fb658..f5d7ee0eaed9f9 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs @@ -1403,6 +1403,34 @@ private static void _getThreadLocalStaticBlocksInfo(IntPtr thisHandle, IntPtr* p } } + [UnmanagedCallersOnly] + private static void _getTlsRootInfo(IntPtr thisHandle, IntPtr* ppException, CORINFO_CONST_LOOKUP* addr) + { + var _this = GetThis(thisHandle); + try + { + _this.getTlsRootInfo(ref *addr); + } + catch (Exception ex) + { + *ppException = _this.AllocException(ex); + } + } + + [UnmanagedCallersOnly] + private static void _getThreadStaticBaseSlowInfo(IntPtr thisHandle, IntPtr* ppException, CORINFO_CONST_LOOKUP* addr) + { + var _this = GetThis(thisHandle); + try + { + _this.getThreadStaticBaseSlowInfo(ref *addr); + } + catch (Exception ex) + { + *ppException = _this.AllocException(ex); + } + } + [UnmanagedCallersOnly] private static byte _isFieldStatic(IntPtr thisHandle, IntPtr* ppException, CORINFO_FIELD_STRUCT_* fldHnd) { @@ -2507,7 +2535,7 @@ private static uint _getJitFlags(IntPtr thisHandle, IntPtr* ppException, CORJIT_ private static IntPtr GetUnmanagedCallbacks() { - void** callbacks = (void**)Marshal.AllocCoTaskMem(sizeof(IntPtr) * 169); + void** callbacks = (void**)Marshal.AllocCoTaskMem(sizeof(IntPtr) * 171); callbacks[0] = (delegate* unmanaged)&_isIntrinsic; callbacks[1] = (delegate* unmanaged)&_getMethodAttribs; @@ -2603,81 +2631,83 @@ private static IntPtr GetUnmanagedCallbacks() callbacks[91] = (delegate* unmanaged)&_getFieldInfo; callbacks[92] = (delegate* unmanaged)&_getThreadLocalFieldInfo; callbacks[93] = (delegate* unmanaged)&_getThreadLocalStaticBlocksInfo; - callbacks[94] = (delegate* unmanaged)&_isFieldStatic; - callbacks[95] = (delegate* unmanaged)&_getArrayOrStringLength; - callbacks[96] = (delegate* unmanaged)&_getBoundaries; - callbacks[97] = (delegate* unmanaged)&_setBoundaries; - callbacks[98] = (delegate* unmanaged)&_getVars; - callbacks[99] = (delegate* unmanaged)&_setVars; - callbacks[100] = (delegate* unmanaged)&_reportRichMappings; - callbacks[101] = (delegate* unmanaged)&_allocateArray; - callbacks[102] = (delegate* unmanaged)&_freeArray; - callbacks[103] = (delegate* unmanaged)&_getArgNext; - callbacks[104] = (delegate* unmanaged)&_getArgType; - callbacks[105] = (delegate* unmanaged)&_getExactClasses; - callbacks[106] = (delegate* unmanaged)&_getArgClass; - callbacks[107] = (delegate* unmanaged)&_getHFAType; - callbacks[108] = (delegate* unmanaged)&_runWithErrorTrap; - callbacks[109] = (delegate* unmanaged)&_runWithSPMIErrorTrap; - callbacks[110] = (delegate* unmanaged)&_getEEInfo; - callbacks[111] = (delegate* unmanaged)&_getJitTimeLogFilename; - callbacks[112] = (delegate* unmanaged)&_getMethodDefFromMethod; - callbacks[113] = (delegate* unmanaged)&_printMethodName; - callbacks[114] = (delegate* unmanaged)&_getMethodNameFromMetadata; - callbacks[115] = (delegate* unmanaged)&_getMethodHash; - callbacks[116] = (delegate* unmanaged)&_getSystemVAmd64PassStructInRegisterDescriptor; - callbacks[117] = (delegate* unmanaged)&_getLoongArch64PassStructInRegisterFlags; - callbacks[118] = (delegate* unmanaged)&_getRISCV64PassStructInRegisterFlags; - callbacks[119] = (delegate* unmanaged)&_getThreadTLSIndex; - callbacks[120] = (delegate* unmanaged)&_getAddrOfCaptureThreadGlobal; - callbacks[121] = (delegate* unmanaged)&_getHelperFtn; - callbacks[122] = (delegate* unmanaged)&_getFunctionEntryPoint; - callbacks[123] = (delegate* unmanaged)&_getFunctionFixedEntryPoint; - callbacks[124] = (delegate* unmanaged)&_getMethodSync; - callbacks[125] = (delegate* unmanaged)&_getLazyStringLiteralHelper; - callbacks[126] = (delegate* unmanaged)&_embedModuleHandle; - callbacks[127] = (delegate* unmanaged)&_embedClassHandle; - callbacks[128] = (delegate* unmanaged)&_embedMethodHandle; - callbacks[129] = (delegate* unmanaged)&_embedFieldHandle; - callbacks[130] = (delegate* unmanaged)&_embedGenericHandle; - callbacks[131] = (delegate* unmanaged)&_getLocationOfThisType; - callbacks[132] = (delegate* unmanaged)&_getAddressOfPInvokeTarget; - callbacks[133] = (delegate* unmanaged)&_GetCookieForPInvokeCalliSig; - callbacks[134] = (delegate* unmanaged)&_canGetCookieForPInvokeCalliSig; - callbacks[135] = (delegate* unmanaged)&_getJustMyCodeHandle; - callbacks[136] = (delegate* unmanaged)&_GetProfilingHandle; - callbacks[137] = (delegate* unmanaged)&_getCallInfo; - callbacks[138] = (delegate* unmanaged)&_getClassDomainID; - callbacks[139] = (delegate* unmanaged)&_getStaticFieldContent; - callbacks[140] = (delegate* unmanaged)&_getObjectContent; - callbacks[141] = (delegate* unmanaged)&_getStaticFieldCurrentClass; - callbacks[142] = (delegate* unmanaged)&_getVarArgsHandle; - callbacks[143] = (delegate* unmanaged)&_canGetVarArgsHandle; - callbacks[144] = (delegate* unmanaged)&_constructStringLiteral; - callbacks[145] = (delegate* unmanaged)&_emptyStringLiteral; - callbacks[146] = (delegate* unmanaged)&_getFieldThreadLocalStoreID; - callbacks[147] = (delegate* unmanaged)&_GetDelegateCtor; - callbacks[148] = (delegate* unmanaged)&_MethodCompileComplete; - callbacks[149] = (delegate* unmanaged)&_getTailCallHelpers; - callbacks[150] = (delegate* unmanaged)&_convertPInvokeCalliToCall; - callbacks[151] = (delegate* unmanaged)&_notifyInstructionSetUsage; - callbacks[152] = (delegate* unmanaged)&_updateEntryPointForTailCall; - callbacks[153] = (delegate* unmanaged)&_allocMem; - callbacks[154] = (delegate* unmanaged)&_reserveUnwindInfo; - callbacks[155] = (delegate* unmanaged)&_allocUnwindInfo; - callbacks[156] = (delegate* unmanaged)&_allocGCInfo; - callbacks[157] = (delegate* unmanaged)&_setEHcount; - callbacks[158] = (delegate* unmanaged)&_setEHinfo; - callbacks[159] = (delegate* unmanaged)&_logMsg; - callbacks[160] = (delegate* unmanaged)&_doAssert; - callbacks[161] = (delegate* unmanaged)&_reportFatalError; - callbacks[162] = (delegate* unmanaged)&_getPgoInstrumentationResults; - callbacks[163] = (delegate* unmanaged)&_allocPgoInstrumentationBySchema; - callbacks[164] = (delegate* unmanaged)&_recordCallSite; - callbacks[165] = (delegate* unmanaged)&_recordRelocation; - callbacks[166] = (delegate* unmanaged)&_getRelocTypeHint; - callbacks[167] = (delegate* unmanaged)&_getExpectedTargetArchitecture; - callbacks[168] = (delegate* unmanaged)&_getJitFlags; + callbacks[94] = (delegate* unmanaged)&_getTlsRootInfo; + callbacks[95] = (delegate* unmanaged)&_getThreadStaticBaseSlowInfo; + callbacks[96] = (delegate* unmanaged)&_isFieldStatic; + callbacks[97] = (delegate* unmanaged)&_getArrayOrStringLength; + callbacks[98] = (delegate* unmanaged)&_getBoundaries; + callbacks[99] = (delegate* unmanaged)&_setBoundaries; + callbacks[100] = (delegate* unmanaged)&_getVars; + callbacks[101] = (delegate* unmanaged)&_setVars; + callbacks[102] = (delegate* unmanaged)&_reportRichMappings; + callbacks[103] = (delegate* unmanaged)&_allocateArray; + callbacks[104] = (delegate* unmanaged)&_freeArray; + callbacks[105] = (delegate* unmanaged)&_getArgNext; + callbacks[106] = (delegate* unmanaged)&_getArgType; + callbacks[107] = (delegate* unmanaged)&_getExactClasses; + callbacks[108] = (delegate* unmanaged)&_getArgClass; + callbacks[109] = (delegate* unmanaged)&_getHFAType; + callbacks[110] = (delegate* unmanaged)&_runWithErrorTrap; + callbacks[111] = (delegate* unmanaged)&_runWithSPMIErrorTrap; + callbacks[112] = (delegate* unmanaged)&_getEEInfo; + callbacks[113] = (delegate* unmanaged)&_getJitTimeLogFilename; + callbacks[114] = (delegate* unmanaged)&_getMethodDefFromMethod; + callbacks[115] = (delegate* unmanaged)&_printMethodName; + callbacks[116] = (delegate* unmanaged)&_getMethodNameFromMetadata; + callbacks[117] = (delegate* unmanaged)&_getMethodHash; + callbacks[118] = (delegate* unmanaged)&_getSystemVAmd64PassStructInRegisterDescriptor; + callbacks[119] = (delegate* unmanaged)&_getLoongArch64PassStructInRegisterFlags; + callbacks[120] = (delegate* unmanaged)&_getRISCV64PassStructInRegisterFlags; + callbacks[121] = (delegate* unmanaged)&_getThreadTLSIndex; + callbacks[122] = (delegate* unmanaged)&_getAddrOfCaptureThreadGlobal; + callbacks[123] = (delegate* unmanaged)&_getHelperFtn; + callbacks[124] = (delegate* unmanaged)&_getFunctionEntryPoint; + callbacks[125] = (delegate* unmanaged)&_getFunctionFixedEntryPoint; + callbacks[126] = (delegate* unmanaged)&_getMethodSync; + callbacks[127] = (delegate* unmanaged)&_getLazyStringLiteralHelper; + callbacks[128] = (delegate* unmanaged)&_embedModuleHandle; + callbacks[129] = (delegate* unmanaged)&_embedClassHandle; + callbacks[130] = (delegate* unmanaged)&_embedMethodHandle; + callbacks[131] = (delegate* unmanaged)&_embedFieldHandle; + callbacks[132] = (delegate* unmanaged)&_embedGenericHandle; + callbacks[133] = (delegate* unmanaged)&_getLocationOfThisType; + callbacks[134] = (delegate* unmanaged)&_getAddressOfPInvokeTarget; + callbacks[135] = (delegate* unmanaged)&_GetCookieForPInvokeCalliSig; + callbacks[136] = (delegate* unmanaged)&_canGetCookieForPInvokeCalliSig; + callbacks[137] = (delegate* unmanaged)&_getJustMyCodeHandle; + callbacks[138] = (delegate* unmanaged)&_GetProfilingHandle; + callbacks[139] = (delegate* unmanaged)&_getCallInfo; + callbacks[140] = (delegate* unmanaged)&_getClassDomainID; + callbacks[141] = (delegate* unmanaged)&_getStaticFieldContent; + callbacks[142] = (delegate* unmanaged)&_getObjectContent; + callbacks[143] = (delegate* unmanaged)&_getStaticFieldCurrentClass; + callbacks[144] = (delegate* unmanaged)&_getVarArgsHandle; + callbacks[145] = (delegate* unmanaged)&_canGetVarArgsHandle; + callbacks[146] = (delegate* unmanaged)&_constructStringLiteral; + callbacks[147] = (delegate* unmanaged)&_emptyStringLiteral; + callbacks[148] = (delegate* unmanaged)&_getFieldThreadLocalStoreID; + callbacks[149] = (delegate* unmanaged)&_GetDelegateCtor; + callbacks[150] = (delegate* unmanaged)&_MethodCompileComplete; + callbacks[151] = (delegate* unmanaged)&_getTailCallHelpers; + callbacks[152] = (delegate* unmanaged)&_convertPInvokeCalliToCall; + callbacks[153] = (delegate* unmanaged)&_notifyInstructionSetUsage; + callbacks[154] = (delegate* unmanaged)&_updateEntryPointForTailCall; + callbacks[155] = (delegate* unmanaged)&_allocMem; + callbacks[156] = (delegate* unmanaged)&_reserveUnwindInfo; + callbacks[157] = (delegate* unmanaged)&_allocUnwindInfo; + callbacks[158] = (delegate* unmanaged)&_allocGCInfo; + callbacks[159] = (delegate* unmanaged)&_setEHcount; + callbacks[160] = (delegate* unmanaged)&_setEHinfo; + callbacks[161] = (delegate* unmanaged)&_logMsg; + callbacks[162] = (delegate* unmanaged)&_doAssert; + callbacks[163] = (delegate* unmanaged)&_reportFatalError; + callbacks[164] = (delegate* unmanaged)&_getPgoInstrumentationResults; + callbacks[165] = (delegate* unmanaged)&_allocPgoInstrumentationBySchema; + callbacks[166] = (delegate* unmanaged)&_recordCallSite; + callbacks[167] = (delegate* unmanaged)&_recordRelocation; + callbacks[168] = (delegate* unmanaged)&_getRelocTypeHint; + callbacks[169] = (delegate* unmanaged)&_getExpectedTargetArchitecture; + callbacks[170] = (delegate* unmanaged)&_getJitFlags; return (IntPtr)callbacks; } diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs b/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs index b3dc1ffc9a2974..4a9b5aa591c278 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs @@ -1156,6 +1156,7 @@ public unsafe struct CORINFO_THREAD_STATIC_BLOCKS_INFO public uint offsetOfMaxThreadStaticBlocks; public uint offsetOfThreadStaticBlocks; public uint offsetOfGCDataPointer; + public CORINFO_CONST_LOOKUP tlsRoot; }; // System V struct passing diff --git a/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt b/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt index e6892816cf410b..578498d51ace7c 100644 --- a/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt +++ b/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt @@ -255,6 +255,8 @@ FUNCTIONS void getFieldInfo(CORINFO_RESOLVED_TOKEN* pResolvedToken, CORINFO_METHOD_HANDLE callerHandle, CORINFO_ACCESS_FLAGS flags, CORINFO_FIELD_INFO* pResult) uint32_t getThreadLocalFieldInfo (CORINFO_FIELD_HANDLE field, bool isGCtype) void getThreadLocalStaticBlocksInfo (CORINFO_THREAD_STATIC_BLOCKS_INFO* pInfo, bool isGCType) + void getTlsRootInfo(CORINFO_CONST_LOOKUP* addr) + void getThreadStaticBaseSlowInfo(CORINFO_CONST_LOOKUP* addr) bool isFieldStatic(CORINFO_FIELD_HANDLE fldHnd) int getArrayOrStringLength(CORINFO_OBJECT_HANDLE objHnd) void getBoundaries(CORINFO_METHOD_HANDLE ftn, unsigned int* cILOffsets, uint32_t** pILOffsets, ICorDebugInfo::BoundaryTypes* implicitBoundaries) diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/NodeFactory.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/NodeFactory.cs index 6f17af2ddf3b8b..0cf64196e96d07 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/NodeFactory.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/NodeFactory.cs @@ -1289,7 +1289,7 @@ public string GetSymbolAlternateName(ISymbolNode node) protected internal TypeManagerIndirectionNode TypeManagerIndirection = new TypeManagerIndirectionNode(); - protected internal TlsRootNode TlsRoot = new TlsRootNode(); + public TlsRootNode TlsRoot = new TlsRootNode(); public virtual void AttachToDependencyGraph(DependencyAnalyzerBase graph) { diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs index 839b05098b76bb..1a4bb296bae60f 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs @@ -3230,5 +3230,22 @@ void ValidateSafetyOfUsingTypeEquivalenceOfType(TypeDesc type) throw new RequiresRuntimeJitException($"Type equivalent valuetype '{type}' not directly referenced from member reference"); } } + +#pragma warning disable CA1822 // Mark members as static + private void getThreadLocalStaticBlocksInfo(CORINFO_THREAD_STATIC_BLOCKS_INFO* pInfo, bool isGCType) + { + // Implemented for JIT and NativeAOT only for now. + } + + private void getTlsRootInfo(ref CORINFO_CONST_LOOKUP addr) + { + // Implemented for JIT and NativeAOT only for now. + } + + private void getThreadStaticBaseSlowInfo(ref CORINFO_CONST_LOOKUP addr) + { + // Implemented for JIT and NativeAOT only for now. + } +#pragma warning restore CA1822 // Mark members as static } } diff --git a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs index 78325206266a73..a53f9a0926a5ff 100644 --- a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs +++ b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs @@ -350,6 +350,12 @@ private bool getReadyToRunHelper(ref CORINFO_RESOLVED_TOKEN pResolvedToken, ref pLookup = CreateConstLookupToSymbol(helper); } break; + case CorInfoHelpFunc.CORINFO_HELP_READYTORUN_INLINED_THREADSTATIC_BASE_SLOW: + { + ISymbolNode helper = GetGenericLookupHelper(pGenericLookupKind.runtimeLookupKind, helperId, helperArg); + pLookup = CreateConstLookupToSymbol(helper); + } + break; default: throw new NotImplementedException("ReadyToRun: " + id.ToString()); } @@ -2137,8 +2143,22 @@ private void getFieldInfo(ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_MET } else if (field.IsThreadStatic) { - pResult->helper = CorInfoHelpFunc.CORINFO_HELP_READYTORUN_THREADSTATIC_BASE; - helperId = ReadyToRunHelperId.GetThreadStaticBase; + bool isNew = false; + if (MethodBeingCompiled.Context.Target.IsWindows && MethodBeingCompiled.Context.Target.Architecture == TargetArchitecture.X64) + { + // TODO: Do it only for windows? + fieldAccessor = CORINFO_FIELD_ACCESSOR.CORINFO_FIELD_STATIC_TLS_MANAGED; + } + if (isNew) + { + fieldAccessor = CORINFO_FIELD_ACCESSOR.CORINFO_FIELD_STATIC_TLS_MANAGED; + pResult->helper = CorInfoHelpFunc.CORINFO_HELP_GETSHARED_NONGCTHREADSTATIC_BASE_NOCTOR_OPTIMIZED; + } + else + { + pResult->helper = CorInfoHelpFunc.CORINFO_HELP_READYTORUN_THREADSTATIC_BASE; + helperId = ReadyToRunHelperId.GetThreadStaticBase; + } } else if (!_compilation.HasLazyStaticConstructor(field.OwningType)) { @@ -2398,5 +2418,23 @@ private bool getStaticBaseAddress(CORINFO_CLASS_STRUCT_* cls, bool isGc, ref COR } return true; } + + private void getTlsRootInfo(ref CORINFO_CONST_LOOKUP addr) + { + addr = CreateConstLookupToSymbol(_compilation.NodeFactory.TlsRoot); + } + + private void getThreadStaticBaseSlowInfo(ref CORINFO_CONST_LOOKUP addr) + { + addr = CreateConstLookupToSymbol(_compilation.NodeFactory.HelperEntrypoint(HelperEntrypoint.GetInlinedThreadStaticBaseSlow)); + } + + private void getThreadLocalStaticBlocksInfo(CORINFO_THREAD_STATIC_BLOCKS_INFO* pInfo, bool isGCType) + { + pInfo->offsetOfThreadLocalStoragePointer = 0x58; + pInfo->tlsIndex = CreateConstLookupToSymbol(_compilation.NodeFactory.ExternSymbol("_tls_index")); + pInfo->tlsRoot = CreateConstLookupToSymbol(_compilation.NodeFactory.TlsRoot); + // Implemented for JIT only for now. + } } } diff --git a/src/coreclr/tools/aot/ILCompiler/repro/Program.cs b/src/coreclr/tools/aot/ILCompiler/repro/Program.cs index 9e71394c3732a5..1fa02fb8906ba6 100644 --- a/src/coreclr/tools/aot/ILCompiler/repro/Program.cs +++ b/src/coreclr/tools/aot/ILCompiler/repro/Program.cs @@ -2,11 +2,42 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; +using System.Collections.Generic; +using System.Runtime.CompilerServices; + +class P1 +{ + [ThreadStatic] + public static long z; +} class Program { + [ThreadStatic] + static long x; + [ThreadStatic] + static string y; + [ThreadStatic] + static List list; + + static void Main() { - Console.WriteLine("Hello world"); + Program.x = 5; + //Program.y = 5; + P1.z = 5; + new Program().Test(); + Console.WriteLine(Program.x); + Console.WriteLine(Program.y); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + long Test() + { + Program.x = 5; + Program.y = "a"; + Program.list = new List(); + P1.z = 5; + return 0; } } diff --git a/src/coreclr/tools/aot/ILCompiler/repro/repro.csproj b/src/coreclr/tools/aot/ILCompiler/repro/repro.csproj index 131ddbd3b22576..18793b6d98c79a 100644 --- a/src/coreclr/tools/aot/ILCompiler/repro/repro.csproj +++ b/src/coreclr/tools/aot/ILCompiler/repro/repro.csproj @@ -10,6 +10,7 @@ Debug;Release;Checked true false + true - + getTlsRootInfo(_thisHandle, &pException, addr); + if (pException != nullptr) throw pException; +} + + virtual void getThreadStaticBaseSlowInfo( + CORINFO_CONST_LOOKUP* addr) +{ + CorInfoExceptionClass* pException = nullptr; + _callbacks->getThreadStaticBaseSlowInfo(_thisHandle, &pException, addr); + if (pException != nullptr) throw pException; +} + virtual bool isFieldStatic( CORINFO_FIELD_HANDLE fldHnd) { diff --git a/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo_generated.cpp b/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo_generated.cpp index bc95548b696a5b..9c160505be5990 100644 --- a/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo_generated.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo_generated.cpp @@ -763,6 +763,20 @@ void interceptor_ICJI::getThreadLocalStaticBlocksInfo( original_ICorJitInfo->getThreadLocalStaticBlocksInfo(pInfo, isGCType); } +void interceptor_ICJI::getTlsRootInfo( + CORINFO_CONST_LOOKUP* addr) +{ + mcs->AddCall("getTlsRootInfo"); + original_ICorJitInfo->getTlsRootInfo(addr); +} + +void interceptor_ICJI::getThreadStaticBaseSlowInfo( + CORINFO_CONST_LOOKUP* addr) +{ + mcs->AddCall("getThreadStaticBaseSlowInfo"); + original_ICorJitInfo->getThreadStaticBaseSlowInfo(addr); +} + bool interceptor_ICJI::isFieldStatic( CORINFO_FIELD_HANDLE fldHnd) { diff --git a/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo_generated.cpp b/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo_generated.cpp index 1ec24e309490b3..47b39147c1fc50 100644 --- a/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo_generated.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo_generated.cpp @@ -669,6 +669,18 @@ void interceptor_ICJI::getThreadLocalStaticBlocksInfo( original_ICorJitInfo->getThreadLocalStaticBlocksInfo(pInfo, isGCType); } +void interceptor_ICJI::getTlsRootInfo( + CORINFO_CONST_LOOKUP* addr) +{ + original_ICorJitInfo->getTlsRootInfo(addr); +} + +void interceptor_ICJI::getThreadStaticBaseSlowInfo( + CORINFO_CONST_LOOKUP* addr) +{ + original_ICorJitInfo->getThreadStaticBaseSlowInfo(addr); +} + bool interceptor_ICJI::isFieldStatic( CORINFO_FIELD_HANDLE fldHnd) { From 91ee21f1a72be76579b2175f9615b6089b0af7f0 Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Mon, 10 Jul 2023 08:18:03 -0700 Subject: [PATCH 02/58] working model --- src/coreclr/inc/corinfo.h | 1 + src/coreclr/jit/codegenxarch.cpp | 5 ++ src/coreclr/jit/emit.h | 2 +- src/coreclr/jit/emitxarch.cpp | 12 +++- src/coreclr/jit/gentree.h | 1 + src/coreclr/jit/helperexpansion.cpp | 56 +++++++++++-------- src/coreclr/jit/importer.cpp | 18 +----- src/coreclr/jit/instr.h | 4 +- .../src/Internal/Runtime/ThreadStatics.cs | 2 +- .../Compiler/DependencyAnalysis/Relocation.cs | 1 + .../JitInterface/CorInfoImpl.RyuJit.cs | 25 +++------ .../tools/aot/ILCompiler/repro/Program.cs | 40 ++++++++----- 12 files changed, 94 insertions(+), 73 deletions(-) diff --git a/src/coreclr/inc/corinfo.h b/src/coreclr/inc/corinfo.h index 258bc375a56f8c..103690cff3f02e 100644 --- a/src/coreclr/inc/corinfo.h +++ b/src/coreclr/inc/corinfo.h @@ -3328,6 +3328,7 @@ class ICorDynamicInfo : public ICorStaticInfo // It would be nicer to use existing IMAGE_REL_XXX constants instead of defining our own here... #define IMAGE_REL_BASED_REL32 0x10 #define IMAGE_REL_BASED_THUMB_BRANCH24 0x13 +#define IMAGE_REL_SECREL 0x104 // The identifier for ARM32-specific PC-relative address // computation corresponds to the following instruction diff --git a/src/coreclr/jit/codegenxarch.cpp b/src/coreclr/jit/codegenxarch.cpp index 23c79087d4f8c6..c66ae8214226a9 100644 --- a/src/coreclr/jit/codegenxarch.cpp +++ b/src/coreclr/jit/codegenxarch.cpp @@ -610,6 +610,11 @@ void CodeGen::genSetRegToConst(regNumber targetReg, var_types targetType, GenTre attr = EA_SET_FLG(attr, EA_BYREF_FLG); } + if (con->IsIconHandle(GTF_ICON_SECREL_OFFSET)) + { + attr = EA_SET_FLG(attr, EA_CNS_SEC_RELOC); + } + instGen_Set_Reg_To_Imm(attr, targetReg, cnsVal, INS_FLAGS_DONT_CARE DEBUGARG(con->gtTargetHandle) DEBUGARG(con->gtFlags)); regSet.verifyRegUsed(targetReg); diff --git a/src/coreclr/jit/emit.h b/src/coreclr/jit/emit.h index 4ba00b19577620..d8c6122e42fb06 100644 --- a/src/coreclr/jit/emit.h +++ b/src/coreclr/jit/emit.h @@ -1017,7 +1017,7 @@ class emitter return iiaJmpOffset; } #endif // defined(TARGET_LOONGARCH64) || defined(TARGET_RISCV64) - + bool isSecRel; } _idAddrUnion; /* Trivial wrappers to return properly typed enums */ diff --git a/src/coreclr/jit/emitxarch.cpp b/src/coreclr/jit/emitxarch.cpp index 3d6aa46842621c..cff04dd5f18547 100644 --- a/src/coreclr/jit/emitxarch.cpp +++ b/src/coreclr/jit/emitxarch.cpp @@ -5818,6 +5818,11 @@ void emitter::emitIns_R_I(instruction ins, id->idDebugOnlyInfo()->idMemCookie = targetHandle; #endif + if (emitComp->opts.IsReadyToRun() && EA_IS_CNS_SEC_RELOC(attr)) + { + id->idAddr()->isSecRel = true; + } + if (isSimdInsAndValInByte) { bool includeRexPrefixSize = true; @@ -15147,7 +15152,12 @@ BYTE* emitter::emitOutputRI(BYTE* dst, instrDesc* id) if (id->idIsCnsReloc()) { - emitRecordRelocation((void*)(dst - (unsigned)EA_SIZE(size)), (void*)(size_t)val, IMAGE_REL_BASED_MOFFSET); + uint16_t relocationType = IMAGE_REL_BASED_MOFFSET; + if (emitComp->opts.IsReadyToRun() && id->idAddr()->isSecRel) + { + relocationType = IMAGE_REL_SECREL; + } + emitRecordRelocation((void*)(dst - (unsigned)EA_SIZE(size)), (void*)(size_t)val, relocationType); } goto DONE; diff --git a/src/coreclr/jit/gentree.h b/src/coreclr/jit/gentree.h index 27688c3d41790d..9905317cd8bbab 100644 --- a/src/coreclr/jit/gentree.h +++ b/src/coreclr/jit/gentree.h @@ -534,6 +534,7 @@ enum GenTreeFlags : unsigned int GTF_ICON_STATIC_BOX_PTR = 0x10000000, // GT_CNS_INT -- constant is an address of the box for a STATIC_IN_HEAP field GTF_ICON_FIELD_SEQ = 0x11000000, // <--------> -- constant is a FieldSeq* (used only as VNHandle) GTF_ICON_STATIC_ADDR_PTR = 0x13000000, // GT_CNS_INT -- constant is a pointer to a static base address + GTF_ICON_SECREL_OFFSET = 0x14000000, // GT_CNS_INT -- constant is an offset in a certain section. // GTF_ICON_REUSE_REG_VAL = 0x00800000 // GT_CNS_INT -- GTF_REUSE_REG_VAL, defined above GTF_ICON_SIMD_COUNT = 0x00200000, // GT_CNS_INT -- constant is Vector.Count diff --git a/src/coreclr/jit/helperexpansion.cpp b/src/coreclr/jit/helperexpansion.cpp index 71e27e5eeea33a..330adcd99f34e2 100644 --- a/src/coreclr/jit/helperexpansion.cpp +++ b/src/coreclr/jit/helperexpansion.cpp @@ -497,18 +497,6 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S newFirstStmt = newFirstStmt->GetNextStmt(); } - GenTreeLclVar* threadStaticBlockLcl = nullptr; - - // Grab a temp to store result (it's assigned from either fastPathBb or fallbackBb) - unsigned threadStaticBlockLclNum = lvaGrabTemp(true DEBUGARG("TLS field access")); - lvaTable[threadStaticBlockLclNum].lvType = callType; - threadStaticBlockLcl = gtNewLclvNode(threadStaticBlockLclNum, callType); - - *callUse = gtClone(threadStaticBlockLcl); - - fgMorphStmtBlockOps(block, stmt); - gtUpdateStmtSideEffects(stmt); - GenTree* tlsValue = nullptr; unsigned tlsLclNum = lvaGrabTemp(true DEBUGARG("TLS access")); lvaTable[tlsLclNum].lvType = TYP_I_IMPL; @@ -522,9 +510,10 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S tlsValue = gtNewIconHandleNode(threadStaticBlocksInfo.offsetOfThreadLocalStoragePointer, GTF_ICON_TLS_HDL); tlsValue = gtNewIndir(TYP_I_IMPL, tlsValue, GTF_IND_NONFAULTING | GTF_IND_INVARIANT); - size_t tlsIndexValue = (size_t)threadStaticBlocksInfo.tlsIndex.addr; - GenTree* dllRef = gtNewIconHandleNode(tlsIndexValue, GTF_ICON_TLS_HDL); - dllRef = gtNewIndir(TYP_I_IMPL, dllRef, GTF_IND_NONFAULTING | GTF_IND_INVARIANT); + GenTree* dllRef = gtNewIconHandleNode((size_t)threadStaticBlocksInfo.tlsIndex.handle, GTF_ICON_OBJ_HDL); + dllRef = gtNewIndir(TYP_UINT, dllRef, GTF_IND_NONFAULTING | GTF_IND_INVARIANT); + dllRef = gtNewOperNode(GT_MUL, TYP_I_IMPL, dllRef, gtNewIconNode(TARGET_POINTER_SIZE, TYP_INT)); + // Add the dllRef to produce thread local storage reference for coreclr tlsValue = gtNewOperNode(GT_ADD, TYP_I_IMPL, tlsValue, dllRef); @@ -534,12 +523,20 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S CORINFO_CONST_LOOKUP tlsRootNode; info.compCompHnd->getTlsRootInfo(&tlsRootNode); - GenTree* tlsRootOffset = gtNewIconHandleNode((size_t)tlsRootNode.handle, GTF_ICON_OBJ_HDL); + //GenTree* tlsRootOffset = gtNewIconHandleNode((size_t)tlsRootNode.handle, GTF_ICON_SECREL_OFFSET); + GenTree* tlsRootOffset = gtNewIconNode((size_t)tlsRootNode.handle, TYP_INT); + tlsRootOffset->gtFlags |= GTF_ICON_SECREL_OFFSET; // Add the tlsValue and tlsRootOffset to produce tlsRootAddr. GenTree* tlsRootAddr = gtNewOperNode(GT_ADD, TYP_I_IMPL, tlsValue, tlsRootOffset); - GenTree* tlsRootVal = gtNewIndir(TYP_I_IMPL, tlsRootAddr, GTF_IND_NONFAULTING | GTF_IND_INVARIANT); + // Cache the TlsRootAddr value + unsigned tlsRootAddrLclNum = lvaGrabTemp(true DEBUGARG("TlsRootAddr access")); + lvaTable[tlsRootAddrLclNum].lvType = TYP_I_IMPL; + GenTree* tlsRootAddrDef = gtNewStoreLclVarNode(tlsRootAddrLclNum, tlsRootAddr); + GenTree* tlsRootAddrUse = gtNewLclVarNode(tlsRootAddrLclNum); + + GenTree* tlsRootVal = gtNewIndir(TYP_I_IMPL, tlsRootAddrUse, GTF_IND_NONFAULTING | GTF_IND_INVARIANT); // Cache the TlsRoot value unsigned tlsRootLclNum = lvaGrabTemp(true DEBUGARG("TlsRoot access")); @@ -559,7 +556,7 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S // goto fastPathBb; // // fallbackBb (BBJ_ALWAYS): [weight: 0] - // tlsRoot = HelperCall(); + // tlsRoot = HelperCall(tlsRootAddress); // goto block; // // fastPathBb(BBJ_ALWAYS): [weight: 1.0] @@ -570,14 +567,17 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S // ... // tlsRootNullCondBB - BasicBlock* tlsRootNullCondBB = fgNewBBFromTreeAfter(BBJ_COND, prevBb, tlsRootDef, debugInfo); - + BasicBlock* tlsRootNullCondBB = fgNewBBFromTreeAfter(BBJ_COND, prevBb, tlsRootAddrDef, debugInfo); fgInsertStmtAfter(tlsRootNullCondBB, tlsRootNullCondBB->firstStmt(), fgNewStmtFromTree(tlsRootNullCond)); + fgInsertStmtAfter(tlsRootNullCondBB, tlsRootNullCondBB->firstStmt(), fgNewStmtFromTree(tlsRootDef)); CORINFO_CONST_LOOKUP threadStaticSlowHelper; info.compCompHnd->getThreadStaticBaseSlowInfo(&threadStaticSlowHelper); - GenTree* slowHelper = gtNewIndCallNode(gtNewIconHandleNode((size_t)threadStaticSlowHelper.addr, GTF_ICON_TLS_HDL), TYP_VOID); + GenTreeCall* slowHelper = gtNewIndCallNode(gtNewIconHandleNode((size_t)threadStaticSlowHelper.addr, GTF_ICON_TLS_HDL), TYP_I_IMPL); + GenTree* helperArg = gtClone(tlsRootAddrUse); + slowHelper->gtArgs.PushBack(this, NewCallArg::Primitive(helperArg)); + fgMorphArgs(slowHelper); // fallbackBb GenTree* fallbackValueDef = gtNewStoreLclVarNode(tlsRootLclNum, slowHelper); @@ -585,7 +585,19 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S GenTree* fastPathValueDef = gtNewStoreLclVarNode(tlsRootLclNum, gtCloneExpr(tlsRootUse)); BasicBlock* fastPathBb = fgNewBBFromTreeAfter(BBJ_ALWAYS, fallbackBb, fastPathValueDef, debugInfo, true); - + + //GenTreeLclVar* threadStaticBlockLcl = nullptr; + + //// Grab a temp to store result (it's assigned from either fastPathBb or fallbackBb) + //unsigned threadStaticBlockLclNum = lvaGrabTemp(true DEBUGARG("TLS field access")); + //lvaTable[threadStaticBlockLclNum].lvType = callType; + //threadStaticBlockLcl = gtNewLclvNode(threadStaticBlockLclNum, callType); + + *callUse = gtClone(tlsRootUse); + + fgMorphStmtBlockOps(block, stmt); + gtUpdateStmtSideEffects(stmt); + // // Update preds in all new blocks // diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index 21d0c2ac1ea9c0..f00847516a0dbd 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -3779,11 +3779,8 @@ GenTree* Compiler::impImportStaticFieldAddress(CORINFO_RESOLVED_TOKEN* pResolved case CORINFO_FIELD_STATIC_TLS_MANAGED: -#ifdef FEATURE_READYTORUN - if (opts.IsReadyToRun()) - { - } - else +#ifdef FEATURE_READYTORUN + if (!opts.IsReadyToRun()) #endif // FEATURE_READYTORUN { if (pFieldInfo->helper == CORINFO_HELP_GETSHARED_NONGCTHREADSTATIC_BASE_NOCTOR_OPTIMIZED) @@ -3812,17 +3809,6 @@ GenTree* Compiler::impImportStaticFieldAddress(CORINFO_RESOLVED_TOKEN* pResolved callFlags |= GTF_CALL_HOISTABLE; } - //if (pFieldInfo->fieldAccessor == CORINFO_FIELD_STATIC_TLS_MANAGED) - ////if (pFieldInfo->helper == CORINFO_HELP_GETSHARED_NONGCTHREADSTATIC_BASE_NOCTOR_OPTIMIZED) - //{ - // // for now. We will eventually need a new helper that doesn't take argument - // op1 = gtNewHelperCallNode(pFieldInfo->helper, TYP_BYREF, gtNewIconNode(0)); - // op1->AsCall()->SetExpTLSFieldAccess(); - //} - //else - //{ - // op1 = gtNewHelperCallNode(pFieldInfo->helper, TYP_BYREF); - //} op1 = gtNewHelperCallNode(pFieldInfo->helper, TYP_BYREF); if (pFieldInfo->fieldAccessor == CORINFO_FIELD_STATIC_TLS_MANAGED) { diff --git a/src/coreclr/jit/instr.h b/src/coreclr/jit/instr.h index bbc8089376ae58..48a24298a63a93 100644 --- a/src/coreclr/jit/instr.h +++ b/src/coreclr/jit/instr.h @@ -428,6 +428,7 @@ enum emitAttr : unsigned EA_BYREF = EA_BYREF_FLG | EA_PTRSIZE, /* size == -2 */ EA_DSP_RELOC_FLG = 0x400, // Is the displacement of the instruction relocatable? EA_CNS_RELOC_FLG = 0x800, // Is the immediate of the instruction relocatable? + EA_CNS_SEC_RELOC = 0x1000, }; #define EA_ATTR(x) ((emitAttr)(x)) @@ -444,7 +445,8 @@ enum emitAttr : unsigned #define EA_IS_GCREF_OR_BYREF(x) ((((unsigned)(x)) & ((unsigned)(EA_BYREF_FLG | EA_GCREF_FLG))) != 0) #define EA_IS_DSP_RELOC(x) ((((unsigned)(x)) & ((unsigned)EA_DSP_RELOC_FLG)) != 0) #define EA_IS_CNS_RELOC(x) ((((unsigned)(x)) & ((unsigned)EA_CNS_RELOC_FLG)) != 0) -#define EA_IS_RELOC(x) (EA_IS_DSP_RELOC(x) || EA_IS_CNS_RELOC(x)) +#define EA_IS_CNS_SEC_RELOC(x) ((((unsigned)(x)) & ((unsigned)EA_CNS_SEC_RELOC)) != 0) +#define EA_IS_RELOC(x) ((EA_IS_DSP_RELOC(x) || EA_IS_CNS_RELOC(x)) && !EA_IS_CNS_SEC_RELOC(x)) #define EA_TYPE(x) ((emitAttr)(((unsigned)(x)) & ~(EA_OFFSET_FLG | EA_DSP_RELOC_FLG | EA_CNS_RELOC_FLG))) // clang-format on diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/ThreadStatics.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/ThreadStatics.cs index 7bfcbff517b22f..a85281ca65b5ac 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/ThreadStatics.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/ThreadStatics.cs @@ -34,7 +34,7 @@ internal static unsafe object GetThreadStaticBaseForType(TypeManagerSlot* pModul internal static unsafe object GetInlinedThreadStaticBaseSlow(ref object? threadStorage) { - Debug.Assert(threadStorage == null); + //Debug.Assert(threadStorage == null); // Allocate an object that will represent a memory block for all thread static fields TypeManagerHandle typeManager = EETypePtr.EETypePtrOf().ToPointer()->TypeManager; object threadStaticBase = AllocateThreadStaticStorageForType(typeManager, 0); diff --git a/src/coreclr/tools/Common/Compiler/DependencyAnalysis/Relocation.cs b/src/coreclr/tools/Common/Compiler/DependencyAnalysis/Relocation.cs index b833c909ff5b79..72cfcf14e6f8d9 100644 --- a/src/coreclr/tools/Common/Compiler/DependencyAnalysis/Relocation.cs +++ b/src/coreclr/tools/Common/Compiler/DependencyAnalysis/Relocation.cs @@ -428,6 +428,7 @@ public static unsafe void WriteValue(RelocType relocType, void* location, long v case RelocType.IMAGE_REL_BASED_ADDR32NB: case RelocType.IMAGE_REL_SYMBOL_SIZE: case RelocType.IMAGE_REL_FILE_ABSOLUTE: + case RelocType.IMAGE_REL_SECREL: *(int*)location = (int)value; break; case RelocType.IMAGE_REL_BASED_DIR64: diff --git a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs index a53f9a0926a5ff..f4537013b0e97a 100644 --- a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs +++ b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs @@ -350,12 +350,12 @@ private bool getReadyToRunHelper(ref CORINFO_RESOLVED_TOKEN pResolvedToken, ref pLookup = CreateConstLookupToSymbol(helper); } break; - case CorInfoHelpFunc.CORINFO_HELP_READYTORUN_INLINED_THREADSTATIC_BASE_SLOW: - { - ISymbolNode helper = GetGenericLookupHelper(pGenericLookupKind.runtimeLookupKind, helperId, helperArg); - pLookup = CreateConstLookupToSymbol(helper); - } - break; + //case CorInfoHelpFunc.CORINFO_HELP_READYTORUN_INLINED_THREADSTATIC_BASE_SLOW: + // { + // ISymbolNode helper = GetGenericLookupHelper(pGenericLookupKind.runtimeLookupKind, ReadyToRunHelperId.slo, helperArg); + // pLookup = CreateConstLookupToSymbol(helper); + // } + // break; default: throw new NotImplementedException("ReadyToRun: " + id.ToString()); } @@ -2143,22 +2143,13 @@ private void getFieldInfo(ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_MET } else if (field.IsThreadStatic) { - bool isNew = false; if (MethodBeingCompiled.Context.Target.IsWindows && MethodBeingCompiled.Context.Target.Architecture == TargetArchitecture.X64) { // TODO: Do it only for windows? fieldAccessor = CORINFO_FIELD_ACCESSOR.CORINFO_FIELD_STATIC_TLS_MANAGED; } - if (isNew) - { - fieldAccessor = CORINFO_FIELD_ACCESSOR.CORINFO_FIELD_STATIC_TLS_MANAGED; - pResult->helper = CorInfoHelpFunc.CORINFO_HELP_GETSHARED_NONGCTHREADSTATIC_BASE_NOCTOR_OPTIMIZED; - } - else - { - pResult->helper = CorInfoHelpFunc.CORINFO_HELP_READYTORUN_THREADSTATIC_BASE; - helperId = ReadyToRunHelperId.GetThreadStaticBase; - } + pResult->helper = CorInfoHelpFunc.CORINFO_HELP_READYTORUN_THREADSTATIC_BASE; + helperId = ReadyToRunHelperId.GetThreadStaticBase; } else if (!_compilation.HasLazyStaticConstructor(field.OwningType)) { diff --git a/src/coreclr/tools/aot/ILCompiler/repro/Program.cs b/src/coreclr/tools/aot/ILCompiler/repro/Program.cs index 1fa02fb8906ba6..fca7a04db9ef9b 100644 --- a/src/coreclr/tools/aot/ILCompiler/repro/Program.cs +++ b/src/coreclr/tools/aot/ILCompiler/repro/Program.cs @@ -15,29 +15,41 @@ class Program { [ThreadStatic] static long x; + //[ThreadStatic] + //static string y; [ThreadStatic] - static string y; - [ThreadStatic] - static List list; + int z; + ////[ThreadStatic] + //static List list; static void Main() { - Program.x = 5; - //Program.y = 5; - P1.z = 5; - new Program().Test(); - Console.WriteLine(Program.x); - Console.WriteLine(Program.y); + //Program.x = 5; + ////Program.y = "a"; + //Program.list = new List(); + //P1.z = 5; + Program obj = new Program(); + obj.Test(5); + //Console.WriteLine("Hello"); + Console.WriteLine(Program.x + obj.z); + //Console.WriteLine(Program.y); + //Console.WriteLine(Program.z); + Console.WriteLine(P1.z); + return; } [MethodImpl(MethodImplOptions.NoInlining)] - long Test() + long Test(int n) { - Program.x = 5; - Program.y = "a"; - Program.list = new List(); - P1.z = 5; + for (int i = 0; i < n; i++) + { + Program.x = 20; + new Program().z = 23; + //Program.y = "a"; + //Program.list = new List(); + P1.z = 5; + } return 0; } } From fe242f1a951fa9eac97e8a893cd753860b6a53e5 Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Tue, 11 Jul 2023 10:36:34 -0700 Subject: [PATCH 03/58] wip --- src/coreclr/inc/corinfo.h | 3 + src/coreclr/inc/icorjitinfoimpl_generated.h | 3 + src/coreclr/jit/ICorJitInfo_names_generated.h | 1 + .../jit/ICorJitInfo_wrapper_generated.hpp | 8 + src/coreclr/jit/gentree.h | 16 ++ src/coreclr/jit/helperexpansion.cpp | 54 +++++- src/coreclr/jit/importer.cpp | 9 + .../JitInterface/CorInfoImpl_generated.cs | 167 ++++++++++-------- .../tools/Common/JitInterface/CorInfoTypes.cs | 1 + .../ThunkGenerator/ThunkInput.txt | 1 + .../JitInterface/CorInfoImpl.ReadyToRun.cs | 6 + .../JitInterface/CorInfoImpl.RyuJit.cs | 33 +++- .../tools/aot/ILCompiler/ILCompiler.csproj | 25 +-- .../tools/aot/ILCompiler/repro/Program.cs | 49 +++-- .../aot/jitinterface/jitinterface_generated.h | 9 + .../icorjitinfo_generated.cpp | 7 + .../icorjitinfo_generated.cpp | 6 + 17 files changed, 288 insertions(+), 110 deletions(-) diff --git a/src/coreclr/inc/corinfo.h b/src/coreclr/inc/corinfo.h index 103690cff3f02e..ae36640bffc16f 100644 --- a/src/coreclr/inc/corinfo.h +++ b/src/coreclr/inc/corinfo.h @@ -1685,6 +1685,7 @@ enum CORINFO_FIELD_ACCESSOR CORINFO_FIELD_STATIC_ADDR_HELPER, // static field accessed using address-of helper (argument is FieldDesc *) CORINFO_FIELD_STATIC_TLS, // unmanaged TLS access CORINFO_FIELD_STATIC_TLS_MANAGED, // managed TLS access + CORINFO_FIELD_STATIC_TLS_MANAGED_LAZY, // managed TLS access lazy CORINFO_FIELD_STATIC_READYTORUN_HELPER, // static field access using a runtime lookup helper CORINFO_FIELD_STATIC_RELOCATABLE, // static field access using relocation (used in AOT) CORINFO_FIELD_INTRINSIC_ZERO, // intrinsic zero (IntPtr.Zero, UIntPtr.Zero) @@ -2791,8 +2792,10 @@ class ICorStaticInfo bool isGCType ) = 0; + //TODO: Rename the method names to get*Helper virtual void getTlsRootInfo(CORINFO_CONST_LOOKUP* addr) = 0; virtual void getThreadStaticBaseSlowInfo(CORINFO_CONST_LOOKUP* addr) = 0; + virtual int getEnsureClassCtorRunAndReturnThreadStaticBaseHelper(CORINFO_CLASS_HANDLE cls, CORINFO_CONST_LOOKUP* addr, CORINFO_CONST_LOOKUP* targetSymbol) = 0; // Returns true iff "fldHnd" represents a static field. virtual bool isFieldStatic(CORINFO_FIELD_HANDLE fldHnd) = 0; diff --git a/src/coreclr/inc/icorjitinfoimpl_generated.h b/src/coreclr/inc/icorjitinfoimpl_generated.h index 480abb44e31e82..f1fdbb2d18daec 100644 --- a/src/coreclr/inc/icorjitinfoimpl_generated.h +++ b/src/coreclr/inc/icorjitinfoimpl_generated.h @@ -402,6 +402,9 @@ void getTlsRootInfo( void getThreadStaticBaseSlowInfo( CORINFO_CONST_LOOKUP* addr) override; +void getEnsureClassCtorRunAndReturnThreadStaticBaseHelper( + CORINFO_CONST_LOOKUP* addr) override; + bool isFieldStatic( CORINFO_FIELD_HANDLE fldHnd) override; diff --git a/src/coreclr/jit/ICorJitInfo_names_generated.h b/src/coreclr/jit/ICorJitInfo_names_generated.h index 49f902ea2c4e91..fa8bfa67c8c598 100644 --- a/src/coreclr/jit/ICorJitInfo_names_generated.h +++ b/src/coreclr/jit/ICorJitInfo_names_generated.h @@ -100,6 +100,7 @@ DEF_CLR_API(getThreadLocalFieldInfo) DEF_CLR_API(getThreadLocalStaticBlocksInfo) DEF_CLR_API(getTlsRootInfo) DEF_CLR_API(getThreadStaticBaseSlowInfo) +DEF_CLR_API(getEnsureClassCtorRunAndReturnThreadStaticBaseHelper) DEF_CLR_API(isFieldStatic) DEF_CLR_API(getArrayOrStringLength) DEF_CLR_API(getBoundaries) diff --git a/src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp b/src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp index 8030b508fdd0ef..282efa697b788f 100644 --- a/src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp +++ b/src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp @@ -948,6 +948,14 @@ void WrapICorJitInfo::getThreadStaticBaseSlowInfo( API_LEAVE(getThreadStaticBaseSlowInfo); } +void WrapICorJitInfo::getEnsureClassCtorRunAndReturnThreadStaticBaseHelper( + CORINFO_CONST_LOOKUP* addr) +{ + API_ENTER(getEnsureClassCtorRunAndReturnThreadStaticBaseHelper); + wrapHnd->getEnsureClassCtorRunAndReturnThreadStaticBaseHelper(addr); + API_LEAVE(getEnsureClassCtorRunAndReturnThreadStaticBaseHelper); +} + bool WrapICorJitInfo::isFieldStatic( CORINFO_FIELD_HANDLE fldHnd) { diff --git a/src/coreclr/jit/gentree.h b/src/coreclr/jit/gentree.h index 9905317cd8bbab..e55f7ddce54ca1 100644 --- a/src/coreclr/jit/gentree.h +++ b/src/coreclr/jit/gentree.h @@ -4060,6 +4060,7 @@ enum GenTreeCallFlags : unsigned int GTF_CALL_M_HAS_LATE_DEVIRT_INFO = 0x10000000, // this call has late devirtualzation info GTF_CALL_M_LDVIRTFTN_INTERFACE = 0x20000000, // ldvirtftn on an interface type GTF_CALL_M_EXP_TLS_ACCESS = 0x40000000, // this call is a helper for access TLS marked field + GTF_CALL_M_EXP_TLS_ACCESS_LAZY = 0x80000000, // this call is a helper for access TLS marked field and has lazy ctor }; inline constexpr GenTreeCallFlags operator ~(GenTreeCallFlags a) @@ -5410,6 +5411,21 @@ struct GenTreeCall final : public GenTree return (gtCallMoreFlags & GTF_CALL_M_EXP_TLS_ACCESS) != 0; } + void SetExpTLSFieldAccessLazyCtor() + { + gtCallMoreFlags |= GTF_CALL_M_EXP_TLS_ACCESS_LAZY; + } + + void ClearExpTLSFieldAccessLazyCtor() + { + gtCallMoreFlags &= ~GTF_CALL_M_EXP_TLS_ACCESS_LAZY; + } + + bool IsExpTLSFieldAccessLazyCtor() const + { + return (gtCallMoreFlags & GTF_CALL_M_EXP_TLS_ACCESS_LAZY) != 0; + } + void SetExpandedEarly() { gtCallMoreFlags |= GTF_CALL_M_EXPANDED_EARLY; diff --git a/src/coreclr/jit/helperexpansion.cpp b/src/coreclr/jit/helperexpansion.cpp index 330adcd99f34e2..7b2cf663ceba85 100644 --- a/src/coreclr/jit/helperexpansion.cpp +++ b/src/coreclr/jit/helperexpansion.cpp @@ -452,7 +452,7 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S assert(opts.IsReadyToRun()); BasicBlock* block = *pBlock; assert(call->IsHelperCall()); - if (!call->IsExpTLSFieldAccess()) + if (!(call->IsExpTLSFieldAccess() && call->IsExpTLSFieldAccessLazyCtor())) { return false; } @@ -460,6 +460,8 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S JITDUMP("Expanding thread static local access for [%06d] in " FMT_BB ":\n", dspTreeID(call), block->bbNum); DISPTREE(call); JITDUMP("\n"); + bool hasLazyStaticCtor = call->IsExpTLSFieldAccessLazyCtor(); + CORINFO_THREAD_STATIC_BLOCKS_INFO threadStaticBlocksInfo; memset(&threadStaticBlocksInfo, 0, sizeof(CORINFO_THREAD_STATIC_BLOCKS_INFO)); @@ -477,6 +479,7 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S JITDUMP("offsetOfGCDataPointer= %u\n", dspOffset(threadStaticBlocksInfo.offsetOfGCDataPointer)); call->ClearExpTLSFieldAccess(); + call->ClearExpTLSFieldAccessLazyCtor(); // Split block right before the call tree BasicBlock* prevBb = block; @@ -488,6 +491,55 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S var_types callType = call->TypeGet(); assert(prevBb != nullptr && block != nullptr); + if (hasLazyStaticCtor) + { + BasicBlock* lazyCtorBlock = nullptr; + + CORINFO_CONST_LOOKUP classCtorRunHelper; + CORINFO_CONST_LOOKUP targetSymbol; + memset(&classCtorRunHelper, 0, sizeof(CORINFO_CONST_LOOKUP)); + memset(&targetSymbol, 0, sizeof(CORINFO_CONST_LOOKUP)); + int size = + info.compCompHnd->getEnsureClassCtorRunAndReturnThreadStaticBaseHelper(&classCtorRunHelper, &targetSymbol); + + // target symbol + GenTree* targetSymbolAddr = gtNewIconHandleNode(classCtorRunHelper.addr, GTF_ICON_OBJ_HDL); + targetSymbolAddr = gtNewOperNode(GT_ADD, TYP_I_IMPL, targetSymbolAddr, gtNewIconNode(size, TYP_UINT)); + targetSymbolAddr = gtNewIndir(TYP_I_IMPL, targetSymbolAddr); + + GenTree* targetSymbolNullCond = gtNewOperNode(GT_NE, TYP_INT, targetSymbolAddr, gtNewIconNode(0, TYP_I_IMPL)); + targetSymbolNullCond = gtNewOperNode(GT_JTRUE, TYP_VOID, targetSymbolNullCond); + + + GenTreeCall* classCtorRunHelperCall = + gtNewIndCallNode(gtNewIconHandleNode((size_t)classCtorRunHelper.addr, GTF_ICON_FTN_ADDR), TYP_I_IMPL); + + // arg0: unused + classCtorRunHelperCall->gtArgs.PushBack(this, NewCallArg::Primitive(gtNewIconNode(0))); + + // arg1: -1 (index of inlined storage) + classCtorRunHelperCall->gtArgs.PushBack(this, NewCallArg::Primitive(gtNewIconNode(-1))); + + // arg2: NonGCStatics targetSymbol + classCtorRunHelperCall->gtArgs.PushBack(this, NewCallArg::Primitive(gtCloneExpr(targetSymbolAddr))); + + fgMorphArgs(classCtorRunHelperCall); + + // tlsRootNullCondBB (BBJ_COND): [weight: 1.0] + // targetSymbolAddr = [targetSymbol + size] + // if (*targetSymbolAddr == 0) + // goto fastPathBb; + // + // fallbackBb (BBJ_ALWAYS): [weight: 0] ???? Check if this is true + // tlsRoot = HelperCall(0, -1, targetSymbolAddr); + // goto block; + // + // tlsAccess(BBJ_ALWAYS): [weight: 1.0] + // tlsRoot = fastPathValue; + + prevBb = lazyCtorBlock; + } + // Block ops inserted by the split need to be morphed here since we are after morph. // We cannot morph stmt yet as we may modify it further below, and the morphing // could invalidate callUse. diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index f00847516a0dbd..16e5ab0c4bc2cf 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -3778,6 +3778,7 @@ GenTree* Compiler::impImportStaticFieldAddress(CORINFO_RESOLVED_TOKEN* pResolved break; case CORINFO_FIELD_STATIC_TLS_MANAGED: + case CORINFO_FIELD_STATIC_TLS_MANAGED_LAZY: #ifdef FEATURE_READYTORUN if (!opts.IsReadyToRun()) @@ -3814,6 +3815,11 @@ GenTree* Compiler::impImportStaticFieldAddress(CORINFO_RESOLVED_TOKEN* pResolved { op1->AsCall()->SetExpTLSFieldAccess(); } + else if (pFieldInfo->fieldAccessor == CORINFO_FIELD_STATIC_TLS_MANAGED_LAZY) + { + op1->AsCall()->SetExpTLSFieldAccessLazyCtor(); + op1->AsCall()->gtInitClsHnd = pResolvedToken->hClass; + } if (pResolvedToken->hClass == info.compClassHnd && m_preferredInitCctor == CORINFO_HELP_UNDEF && (pFieldInfo->helper == CORINFO_HELP_READYTORUN_GCSTATIC_BASE || pFieldInfo->helper == CORINFO_HELP_READYTORUN_NONGCSTATIC_BASE)) @@ -8980,6 +8986,7 @@ void Compiler::impImportBlockCode(BasicBlock* block) break; case CORINFO_FIELD_STATIC_TLS_MANAGED: + case CORINFO_FIELD_STATIC_TLS_MANAGED_LAZY: setMethodHasTlsFieldAccess(); FALLTHROUGH; case CORINFO_FIELD_STATIC_SHARED_STATIC_HELPER: @@ -9160,6 +9167,7 @@ void Compiler::impImportBlockCode(BasicBlock* block) break; case CORINFO_FIELD_STATIC_TLS_MANAGED: + case CORINFO_FIELD_STATIC_TLS_MANAGED_LAZY: case CORINFO_FIELD_STATIC_ADDRESS: case CORINFO_FIELD_STATIC_RVA_ADDRESS: case CORINFO_FIELD_STATIC_SHARED_STATIC_HELPER: @@ -9260,6 +9268,7 @@ void Compiler::impImportBlockCode(BasicBlock* block) goto SPILL_APPEND; case CORINFO_FIELD_STATIC_TLS_MANAGED: + case CORINFO_FIELD_STATIC_TLS_MANAGED_LAZY: setMethodHasTlsFieldAccess(); FALLTHROUGH; case CORINFO_FIELD_STATIC_ADDRESS: diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs b/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs index f5d7ee0eaed9f9..b2fe83c576b2c6 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs @@ -1431,6 +1431,20 @@ private static void _getThreadStaticBaseSlowInfo(IntPtr thisHandle, IntPtr* ppEx } } + [UnmanagedCallersOnly] + private static void _getEnsureClassCtorRunAndReturnThreadStaticBaseHelper(IntPtr thisHandle, IntPtr* ppException, CORINFO_CONST_LOOKUP* addr) + { + var _this = GetThis(thisHandle); + try + { + _this.getEnsureClassCtorRunAndReturnThreadStaticBaseHelper(ref *addr); + } + catch (Exception ex) + { + *ppException = _this.AllocException(ex); + } + } + [UnmanagedCallersOnly] private static byte _isFieldStatic(IntPtr thisHandle, IntPtr* ppException, CORINFO_FIELD_STRUCT_* fldHnd) { @@ -2535,7 +2549,7 @@ private static uint _getJitFlags(IntPtr thisHandle, IntPtr* ppException, CORJIT_ private static IntPtr GetUnmanagedCallbacks() { - void** callbacks = (void**)Marshal.AllocCoTaskMem(sizeof(IntPtr) * 171); + void** callbacks = (void**)Marshal.AllocCoTaskMem(sizeof(IntPtr) * 172); callbacks[0] = (delegate* unmanaged)&_isIntrinsic; callbacks[1] = (delegate* unmanaged)&_getMethodAttribs; @@ -2633,81 +2647,82 @@ private static IntPtr GetUnmanagedCallbacks() callbacks[93] = (delegate* unmanaged)&_getThreadLocalStaticBlocksInfo; callbacks[94] = (delegate* unmanaged)&_getTlsRootInfo; callbacks[95] = (delegate* unmanaged)&_getThreadStaticBaseSlowInfo; - callbacks[96] = (delegate* unmanaged)&_isFieldStatic; - callbacks[97] = (delegate* unmanaged)&_getArrayOrStringLength; - callbacks[98] = (delegate* unmanaged)&_getBoundaries; - callbacks[99] = (delegate* unmanaged)&_setBoundaries; - callbacks[100] = (delegate* unmanaged)&_getVars; - callbacks[101] = (delegate* unmanaged)&_setVars; - callbacks[102] = (delegate* unmanaged)&_reportRichMappings; - callbacks[103] = (delegate* unmanaged)&_allocateArray; - callbacks[104] = (delegate* unmanaged)&_freeArray; - callbacks[105] = (delegate* unmanaged)&_getArgNext; - callbacks[106] = (delegate* unmanaged)&_getArgType; - callbacks[107] = (delegate* unmanaged)&_getExactClasses; - callbacks[108] = (delegate* unmanaged)&_getArgClass; - callbacks[109] = (delegate* unmanaged)&_getHFAType; - callbacks[110] = (delegate* unmanaged)&_runWithErrorTrap; - callbacks[111] = (delegate* unmanaged)&_runWithSPMIErrorTrap; - callbacks[112] = (delegate* unmanaged)&_getEEInfo; - callbacks[113] = (delegate* unmanaged)&_getJitTimeLogFilename; - callbacks[114] = (delegate* unmanaged)&_getMethodDefFromMethod; - callbacks[115] = (delegate* unmanaged)&_printMethodName; - callbacks[116] = (delegate* unmanaged)&_getMethodNameFromMetadata; - callbacks[117] = (delegate* unmanaged)&_getMethodHash; - callbacks[118] = (delegate* unmanaged)&_getSystemVAmd64PassStructInRegisterDescriptor; - callbacks[119] = (delegate* unmanaged)&_getLoongArch64PassStructInRegisterFlags; - callbacks[120] = (delegate* unmanaged)&_getRISCV64PassStructInRegisterFlags; - callbacks[121] = (delegate* unmanaged)&_getThreadTLSIndex; - callbacks[122] = (delegate* unmanaged)&_getAddrOfCaptureThreadGlobal; - callbacks[123] = (delegate* unmanaged)&_getHelperFtn; - callbacks[124] = (delegate* unmanaged)&_getFunctionEntryPoint; - callbacks[125] = (delegate* unmanaged)&_getFunctionFixedEntryPoint; - callbacks[126] = (delegate* unmanaged)&_getMethodSync; - callbacks[127] = (delegate* unmanaged)&_getLazyStringLiteralHelper; - callbacks[128] = (delegate* unmanaged)&_embedModuleHandle; - callbacks[129] = (delegate* unmanaged)&_embedClassHandle; - callbacks[130] = (delegate* unmanaged)&_embedMethodHandle; - callbacks[131] = (delegate* unmanaged)&_embedFieldHandle; - callbacks[132] = (delegate* unmanaged)&_embedGenericHandle; - callbacks[133] = (delegate* unmanaged)&_getLocationOfThisType; - callbacks[134] = (delegate* unmanaged)&_getAddressOfPInvokeTarget; - callbacks[135] = (delegate* unmanaged)&_GetCookieForPInvokeCalliSig; - callbacks[136] = (delegate* unmanaged)&_canGetCookieForPInvokeCalliSig; - callbacks[137] = (delegate* unmanaged)&_getJustMyCodeHandle; - callbacks[138] = (delegate* unmanaged)&_GetProfilingHandle; - callbacks[139] = (delegate* unmanaged)&_getCallInfo; - callbacks[140] = (delegate* unmanaged)&_getClassDomainID; - callbacks[141] = (delegate* unmanaged)&_getStaticFieldContent; - callbacks[142] = (delegate* unmanaged)&_getObjectContent; - callbacks[143] = (delegate* unmanaged)&_getStaticFieldCurrentClass; - callbacks[144] = (delegate* unmanaged)&_getVarArgsHandle; - callbacks[145] = (delegate* unmanaged)&_canGetVarArgsHandle; - callbacks[146] = (delegate* unmanaged)&_constructStringLiteral; - callbacks[147] = (delegate* unmanaged)&_emptyStringLiteral; - callbacks[148] = (delegate* unmanaged)&_getFieldThreadLocalStoreID; - callbacks[149] = (delegate* unmanaged)&_GetDelegateCtor; - callbacks[150] = (delegate* unmanaged)&_MethodCompileComplete; - callbacks[151] = (delegate* unmanaged)&_getTailCallHelpers; - callbacks[152] = (delegate* unmanaged)&_convertPInvokeCalliToCall; - callbacks[153] = (delegate* unmanaged)&_notifyInstructionSetUsage; - callbacks[154] = (delegate* unmanaged)&_updateEntryPointForTailCall; - callbacks[155] = (delegate* unmanaged)&_allocMem; - callbacks[156] = (delegate* unmanaged)&_reserveUnwindInfo; - callbacks[157] = (delegate* unmanaged)&_allocUnwindInfo; - callbacks[158] = (delegate* unmanaged)&_allocGCInfo; - callbacks[159] = (delegate* unmanaged)&_setEHcount; - callbacks[160] = (delegate* unmanaged)&_setEHinfo; - callbacks[161] = (delegate* unmanaged)&_logMsg; - callbacks[162] = (delegate* unmanaged)&_doAssert; - callbacks[163] = (delegate* unmanaged)&_reportFatalError; - callbacks[164] = (delegate* unmanaged)&_getPgoInstrumentationResults; - callbacks[165] = (delegate* unmanaged)&_allocPgoInstrumentationBySchema; - callbacks[166] = (delegate* unmanaged)&_recordCallSite; - callbacks[167] = (delegate* unmanaged)&_recordRelocation; - callbacks[168] = (delegate* unmanaged)&_getRelocTypeHint; - callbacks[169] = (delegate* unmanaged)&_getExpectedTargetArchitecture; - callbacks[170] = (delegate* unmanaged)&_getJitFlags; + callbacks[96] = (delegate* unmanaged)&_getEnsureClassCtorRunAndReturnThreadStaticBaseHelper; + callbacks[97] = (delegate* unmanaged)&_isFieldStatic; + callbacks[98] = (delegate* unmanaged)&_getArrayOrStringLength; + callbacks[99] = (delegate* unmanaged)&_getBoundaries; + callbacks[100] = (delegate* unmanaged)&_setBoundaries; + callbacks[101] = (delegate* unmanaged)&_getVars; + callbacks[102] = (delegate* unmanaged)&_setVars; + callbacks[103] = (delegate* unmanaged)&_reportRichMappings; + callbacks[104] = (delegate* unmanaged)&_allocateArray; + callbacks[105] = (delegate* unmanaged)&_freeArray; + callbacks[106] = (delegate* unmanaged)&_getArgNext; + callbacks[107] = (delegate* unmanaged)&_getArgType; + callbacks[108] = (delegate* unmanaged)&_getExactClasses; + callbacks[109] = (delegate* unmanaged)&_getArgClass; + callbacks[110] = (delegate* unmanaged)&_getHFAType; + callbacks[111] = (delegate* unmanaged)&_runWithErrorTrap; + callbacks[112] = (delegate* unmanaged)&_runWithSPMIErrorTrap; + callbacks[113] = (delegate* unmanaged)&_getEEInfo; + callbacks[114] = (delegate* unmanaged)&_getJitTimeLogFilename; + callbacks[115] = (delegate* unmanaged)&_getMethodDefFromMethod; + callbacks[116] = (delegate* unmanaged)&_printMethodName; + callbacks[117] = (delegate* unmanaged)&_getMethodNameFromMetadata; + callbacks[118] = (delegate* unmanaged)&_getMethodHash; + callbacks[119] = (delegate* unmanaged)&_getSystemVAmd64PassStructInRegisterDescriptor; + callbacks[120] = (delegate* unmanaged)&_getLoongArch64PassStructInRegisterFlags; + callbacks[121] = (delegate* unmanaged)&_getRISCV64PassStructInRegisterFlags; + callbacks[122] = (delegate* unmanaged)&_getThreadTLSIndex; + callbacks[123] = (delegate* unmanaged)&_getAddrOfCaptureThreadGlobal; + callbacks[124] = (delegate* unmanaged)&_getHelperFtn; + callbacks[125] = (delegate* unmanaged)&_getFunctionEntryPoint; + callbacks[126] = (delegate* unmanaged)&_getFunctionFixedEntryPoint; + callbacks[127] = (delegate* unmanaged)&_getMethodSync; + callbacks[128] = (delegate* unmanaged)&_getLazyStringLiteralHelper; + callbacks[129] = (delegate* unmanaged)&_embedModuleHandle; + callbacks[130] = (delegate* unmanaged)&_embedClassHandle; + callbacks[131] = (delegate* unmanaged)&_embedMethodHandle; + callbacks[132] = (delegate* unmanaged)&_embedFieldHandle; + callbacks[133] = (delegate* unmanaged)&_embedGenericHandle; + callbacks[134] = (delegate* unmanaged)&_getLocationOfThisType; + callbacks[135] = (delegate* unmanaged)&_getAddressOfPInvokeTarget; + callbacks[136] = (delegate* unmanaged)&_GetCookieForPInvokeCalliSig; + callbacks[137] = (delegate* unmanaged)&_canGetCookieForPInvokeCalliSig; + callbacks[138] = (delegate* unmanaged)&_getJustMyCodeHandle; + callbacks[139] = (delegate* unmanaged)&_GetProfilingHandle; + callbacks[140] = (delegate* unmanaged)&_getCallInfo; + callbacks[141] = (delegate* unmanaged)&_getClassDomainID; + callbacks[142] = (delegate* unmanaged)&_getStaticFieldContent; + callbacks[143] = (delegate* unmanaged)&_getObjectContent; + callbacks[144] = (delegate* unmanaged)&_getStaticFieldCurrentClass; + callbacks[145] = (delegate* unmanaged)&_getVarArgsHandle; + callbacks[146] = (delegate* unmanaged)&_canGetVarArgsHandle; + callbacks[147] = (delegate* unmanaged)&_constructStringLiteral; + callbacks[148] = (delegate* unmanaged)&_emptyStringLiteral; + callbacks[149] = (delegate* unmanaged)&_getFieldThreadLocalStoreID; + callbacks[150] = (delegate* unmanaged)&_GetDelegateCtor; + callbacks[151] = (delegate* unmanaged)&_MethodCompileComplete; + callbacks[152] = (delegate* unmanaged)&_getTailCallHelpers; + callbacks[153] = (delegate* unmanaged)&_convertPInvokeCalliToCall; + callbacks[154] = (delegate* unmanaged)&_notifyInstructionSetUsage; + callbacks[155] = (delegate* unmanaged)&_updateEntryPointForTailCall; + callbacks[156] = (delegate* unmanaged)&_allocMem; + callbacks[157] = (delegate* unmanaged)&_reserveUnwindInfo; + callbacks[158] = (delegate* unmanaged)&_allocUnwindInfo; + callbacks[159] = (delegate* unmanaged)&_allocGCInfo; + callbacks[160] = (delegate* unmanaged)&_setEHcount; + callbacks[161] = (delegate* unmanaged)&_setEHinfo; + callbacks[162] = (delegate* unmanaged)&_logMsg; + callbacks[163] = (delegate* unmanaged)&_doAssert; + callbacks[164] = (delegate* unmanaged)&_reportFatalError; + callbacks[165] = (delegate* unmanaged)&_getPgoInstrumentationResults; + callbacks[166] = (delegate* unmanaged)&_allocPgoInstrumentationBySchema; + callbacks[167] = (delegate* unmanaged)&_recordCallSite; + callbacks[168] = (delegate* unmanaged)&_recordRelocation; + callbacks[169] = (delegate* unmanaged)&_getRelocTypeHint; + callbacks[170] = (delegate* unmanaged)&_getExpectedTargetArchitecture; + callbacks[171] = (delegate* unmanaged)&_getJitFlags; return (IntPtr)callbacks; } diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs b/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs index 4a9b5aa591c278..9e274fa9407e73 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs @@ -1106,6 +1106,7 @@ public enum CORINFO_FIELD_ACCESSOR CORINFO_FIELD_STATIC_ADDR_HELPER, // static field accessed using address-of helper (argument is FieldDesc *) CORINFO_FIELD_STATIC_TLS, // unmanaged TLS access CORINFO_FIELD_STATIC_TLS_MANAGED, // managed TLS access + CORINFO_FIELD_STATIC_TLS_MANAGED_LAZY, // managed TLS access lazy CORINFO_FIELD_STATIC_READYTORUN_HELPER, // static field access using a runtime lookup helper CORINFO_FIELD_STATIC_RELOCATABLE, // static field access from the data segment CORINFO_FIELD_INTRINSIC_ZERO, // intrinsic zero (IntPtr.Zero, UIntPtr.Zero) diff --git a/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt b/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt index 578498d51ace7c..28e8e9e49b7123 100644 --- a/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt +++ b/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt @@ -257,6 +257,7 @@ FUNCTIONS void getThreadLocalStaticBlocksInfo (CORINFO_THREAD_STATIC_BLOCKS_INFO* pInfo, bool isGCType) void getTlsRootInfo(CORINFO_CONST_LOOKUP* addr) void getThreadStaticBaseSlowInfo(CORINFO_CONST_LOOKUP* addr) + int getEnsureClassCtorRunAndReturnThreadStaticBaseHelper(CORINFO_CONST_LOOKUP* addr, CORINFO_CONST_LOOKUP* targetSymbol) bool isFieldStatic(CORINFO_FIELD_HANDLE fldHnd) int getArrayOrStringLength(CORINFO_OBJECT_HANDLE objHnd) void getBoundaries(CORINFO_METHOD_HANDLE ftn, unsigned int* cILOffsets, uint32_t** pILOffsets, ICorDebugInfo::BoundaryTypes* implicitBoundaries) diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs index 1a4bb296bae60f..31c3d00b6c4eb7 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs @@ -3246,6 +3246,12 @@ private void getThreadStaticBaseSlowInfo(ref CORINFO_CONST_LOOKUP addr) { // Implemented for JIT and NativeAOT only for now. } + + private int getEnsureClassCtorRunAndReturnThreadStaticBaseHelper(ref CORINFO_CONST_LOOKUP addr, ref CORINFO_CONST_LOOKUP targetSymbol) + { + // Implemented for JIT and NativeAOT only for now. + return 0; + } #pragma warning restore CA1822 // Mark members as static } } diff --git a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs index f4537013b0e97a..1df8059403afe6 100644 --- a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs +++ b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs @@ -2100,6 +2100,7 @@ private void getFieldInfo(ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_MET // Find out what kind of base do we need to look up. if (field.IsThreadStatic) { + Debug.Assert(false, "Another instance"); helperId = ReadyToRunHelperId.GetThreadStaticBase; } else if (field.HasGCStaticBase) @@ -2146,7 +2147,24 @@ private void getFieldInfo(ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_MET if (MethodBeingCompiled.Context.Target.IsWindows && MethodBeingCompiled.Context.Target.Architecture == TargetArchitecture.X64) { // TODO: Do it only for windows? - fieldAccessor = CORINFO_FIELD_ACCESSOR.CORINFO_FIELD_STATIC_TLS_MANAGED; + ISortableSymbolNode index = _compilation.NodeFactory.TypeThreadStaticIndex((MetadataType)field.OwningType); + if (index is TypeThreadStaticIndexNode ti && ti.Type == null) + { + if (!_compilation.HasLazyStaticConstructor(field.OwningType)) + { + Console.WriteLine("Done: {0}.{1}", field.OwningType.Name, field.Name); + fieldAccessor = CORINFO_FIELD_ACCESSOR.CORINFO_FIELD_STATIC_TLS_MANAGED; + } + else + { + Console.WriteLine("Lazy: {0}.{1}", field.OwningType.Name, field.Name); + fieldAccessor = CORINFO_FIELD_ACCESSOR.CORINFO_FIELD_STATIC_TLS_MANAGED_LAZY; + } + } + else + { + Console.WriteLine("Non-TypeThreadStaticIndexNode: {0}.{1}", field.OwningType.Name, field.Name); + } } pResult->helper = CorInfoHelpFunc.CORINFO_HELP_READYTORUN_THREADSTATIC_BASE; helperId = ReadyToRunHelperId.GetThreadStaticBase; @@ -2427,5 +2445,18 @@ private void getThreadLocalStaticBlocksInfo(CORINFO_THREAD_STATIC_BLOCKS_INFO* p pInfo->tlsRoot = CreateConstLookupToSymbol(_compilation.NodeFactory.TlsRoot); // Implemented for JIT only for now. } + + private int getEnsureClassCtorRunAndReturnThreadStaticBaseHelper(CORINFO_CLASS_STRUCT_* cls, ref CORINFO_CONST_LOOKUP addr, ref CORINFO_CONST_LOOKUP targetSymbol) + { + MetadataType clsType = HandleToObject(cls) as MetadataType; + if (clsType == null) + { + return 0; + } + + addr = CreateConstLookupToSymbol(_compilation.NodeFactory.HelperEntrypoint(HelperEntrypoint.EnsureClassConstructorRunAndReturnThreadStaticBase)); + targetSymbol = CreateConstLookupToSymbol(_compilation.NodeFactory.TypeNonGCStaticsSymbol(clsType)); + return -NonGCStaticsNode.GetClassConstructorContextSize(_compilation.NodeFactory.Target); + } } } diff --git a/src/coreclr/tools/aot/ILCompiler/ILCompiler.csproj b/src/coreclr/tools/aot/ILCompiler/ILCompiler.csproj index 564a02b632bfbd..247a1edea3f39f 100644 --- a/src/coreclr/tools/aot/ILCompiler/ILCompiler.csproj +++ b/src/coreclr/tools/aot/ILCompiler/ILCompiler.csproj @@ -2,6 +2,7 @@ $(RuntimeBinDir)ilc/ $(PackageRID) + OnOutputUpdated @@ -23,9 +24,7 @@ - + $(RuntimeIdentifier) @@ -46,17 +45,12 @@ - + clang - + @@ -71,18 +65,17 @@ - + - + + + + diff --git a/src/coreclr/tools/aot/ILCompiler/repro/Program.cs b/src/coreclr/tools/aot/ILCompiler/repro/Program.cs index fca7a04db9ef9b..978bcce912b22d 100644 --- a/src/coreclr/tools/aot/ILCompiler/repro/Program.cs +++ b/src/coreclr/tools/aot/ILCompiler/repro/Program.cs @@ -3,23 +3,28 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Runtime.CompilerServices; +using System.Threading; +using System.Threading.Tasks; -class P1 +class P1 { [ThreadStatic] public static long z; + [ThreadStatic] + public static List list; } class Program { [ThreadStatic] - static long x; + static uint x; //[ThreadStatic] //static string y; - [ThreadStatic] - int z; - ////[ThreadStatic] + //[ThreadStatic] + //static int z; + //[ThreadStatic] //static List list; @@ -27,28 +32,40 @@ static void Main() { //Program.x = 5; ////Program.y = "a"; - //Program.list = new List(); - //P1.z = 5; + //Program.list = new List(); + P1.z = 0x900DF00E; + Program.x = 0x900DF00D; Program obj = new Program(); - obj.Test(5); + obj.Test(1); //Console.WriteLine("Hello"); - Console.WriteLine(Program.x + obj.z); + //Console.WriteLine(Program.x + P1.z); //Console.WriteLine(Program.y); //Console.WriteLine(Program.z); - Console.WriteLine(P1.z); - return; + //Console.WriteLine(Program.x + Program.z | P1.z); + + //Program.z = 15; + + Console.WriteLine(CultureInfo.CurrentCulture); + + Console.WriteLine(Program.x); + Console.WriteLine(P1.z); + //Console.WriteLine(Program.z); + Console.WriteLine(P1.list); } + [MethodImpl(MethodImplOptions.NoInlining)] + static void Test1() { Console.WriteLine("inside task"); } + [MethodImpl(MethodImplOptions.NoInlining)] long Test(int n) { - for (int i = 0; i < n; i++) + //for (int i = 0; i < n; i++) { - Program.x = 20; - new Program().z = 23; + //Program.x = 0x900DF00D; + //Program.z = 23; //Program.y = "a"; - //Program.list = new List(); - P1.z = 5; + P1.list = new List(); + //P1.z = 0x900DF00E; } return 0; } diff --git a/src/coreclr/tools/aot/jitinterface/jitinterface_generated.h b/src/coreclr/tools/aot/jitinterface/jitinterface_generated.h index b77916d24b988a..cc5cfff902bf10 100644 --- a/src/coreclr/tools/aot/jitinterface/jitinterface_generated.h +++ b/src/coreclr/tools/aot/jitinterface/jitinterface_generated.h @@ -107,6 +107,7 @@ struct JitInterfaceCallbacks void (* getThreadLocalStaticBlocksInfo)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_THREAD_STATIC_BLOCKS_INFO* pInfo, bool isGCType); void (* getTlsRootInfo)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_CONST_LOOKUP* addr); void (* getThreadStaticBaseSlowInfo)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_CONST_LOOKUP* addr); + void (* getEnsureClassCtorRunAndReturnThreadStaticBaseHelper)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_CONST_LOOKUP* addr); bool (* isFieldStatic)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_FIELD_HANDLE fldHnd); int (* getArrayOrStringLength)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_OBJECT_HANDLE objHnd); void (* getBoundaries)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_METHOD_HANDLE ftn, unsigned int* cILOffsets, uint32_t** pILOffsets, ICorDebugInfo::BoundaryTypes* implicitBoundaries); @@ -1133,6 +1134,14 @@ class JitInterfaceWrapper : public ICorJitInfo if (pException != nullptr) throw pException; } + virtual void getEnsureClassCtorRunAndReturnThreadStaticBaseHelper( + CORINFO_CONST_LOOKUP* addr) +{ + CorInfoExceptionClass* pException = nullptr; + _callbacks->getEnsureClassCtorRunAndReturnThreadStaticBaseHelper(_thisHandle, &pException, addr); + if (pException != nullptr) throw pException; +} + virtual bool isFieldStatic( CORINFO_FIELD_HANDLE fldHnd) { diff --git a/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo_generated.cpp b/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo_generated.cpp index 9c160505be5990..b282f4acb447fe 100644 --- a/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo_generated.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo_generated.cpp @@ -777,6 +777,13 @@ void interceptor_ICJI::getThreadStaticBaseSlowInfo( original_ICorJitInfo->getThreadStaticBaseSlowInfo(addr); } +void interceptor_ICJI::getEnsureClassCtorRunAndReturnThreadStaticBaseHelper( + CORINFO_CONST_LOOKUP* addr) +{ + mcs->AddCall("getEnsureClassCtorRunAndReturnThreadStaticBaseHelper"); + original_ICorJitInfo->getEnsureClassCtorRunAndReturnThreadStaticBaseHelper(addr); +} + bool interceptor_ICJI::isFieldStatic( CORINFO_FIELD_HANDLE fldHnd) { diff --git a/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo_generated.cpp b/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo_generated.cpp index 47b39147c1fc50..b0a05204d97165 100644 --- a/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo_generated.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo_generated.cpp @@ -681,6 +681,12 @@ void interceptor_ICJI::getThreadStaticBaseSlowInfo( original_ICorJitInfo->getThreadStaticBaseSlowInfo(addr); } +void interceptor_ICJI::getEnsureClassCtorRunAndReturnThreadStaticBaseHelper( + CORINFO_CONST_LOOKUP* addr) +{ + original_ICorJitInfo->getEnsureClassCtorRunAndReturnThreadStaticBaseHelper(addr); +} + bool interceptor_ICJI::isFieldStatic( CORINFO_FIELD_HANDLE fldHnd) { From fcf00d21d0ac71d6fb46d2eeb664740e518290a4 Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Fri, 21 Jul 2023 02:06:20 -0700 Subject: [PATCH 04/58] wip --- src/coreclr/inc/icorjitinfoimpl_generated.h | 6 ++++-- src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp | 9 ++++++--- src/coreclr/jit/helperexpansion.cpp | 6 +++--- .../Common/JitInterface/CorInfoImpl_generated.cs | 7 ++++--- .../JitInterface/ThunkGenerator/ThunkInput.txt | 2 +- .../JitInterface/CorInfoImpl.ReadyToRun.cs | 2 +- src/coreclr/tools/aot/ILCompiler/repro/Program.cs | 12 ++++++------ .../tools/aot/jitinterface/jitinterface_generated.h | 11 +++++++---- .../superpmi-shim-counter/icorjitinfo_generated.cpp | 8 +++++--- .../superpmi-shim-simple/icorjitinfo_generated.cpp | 8 +++++--- 10 files changed, 42 insertions(+), 29 deletions(-) diff --git a/src/coreclr/inc/icorjitinfoimpl_generated.h b/src/coreclr/inc/icorjitinfoimpl_generated.h index f1fdbb2d18daec..6fd6c0438074d5 100644 --- a/src/coreclr/inc/icorjitinfoimpl_generated.h +++ b/src/coreclr/inc/icorjitinfoimpl_generated.h @@ -402,8 +402,10 @@ void getTlsRootInfo( void getThreadStaticBaseSlowInfo( CORINFO_CONST_LOOKUP* addr) override; -void getEnsureClassCtorRunAndReturnThreadStaticBaseHelper( - CORINFO_CONST_LOOKUP* addr) override; +int getEnsureClassCtorRunAndReturnThreadStaticBaseHelper( + CORINFO_CLASS_HANDLE cls, + CORINFO_CONST_LOOKUP* addr, + CORINFO_CONST_LOOKUP* targetSymbol) override; bool isFieldStatic( CORINFO_FIELD_HANDLE fldHnd) override; diff --git a/src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp b/src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp index 282efa697b788f..84ed179e46c0f1 100644 --- a/src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp +++ b/src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp @@ -948,12 +948,15 @@ void WrapICorJitInfo::getThreadStaticBaseSlowInfo( API_LEAVE(getThreadStaticBaseSlowInfo); } -void WrapICorJitInfo::getEnsureClassCtorRunAndReturnThreadStaticBaseHelper( - CORINFO_CONST_LOOKUP* addr) +int WrapICorJitInfo::getEnsureClassCtorRunAndReturnThreadStaticBaseHelper( + CORINFO_CLASS_HANDLE cls, + CORINFO_CONST_LOOKUP* addr, + CORINFO_CONST_LOOKUP* targetSymbol) { API_ENTER(getEnsureClassCtorRunAndReturnThreadStaticBaseHelper); - wrapHnd->getEnsureClassCtorRunAndReturnThreadStaticBaseHelper(addr); + int temp = wrapHnd->getEnsureClassCtorRunAndReturnThreadStaticBaseHelper(cls, addr, targetSymbol); API_LEAVE(getEnsureClassCtorRunAndReturnThreadStaticBaseHelper); + return temp; } bool WrapICorJitInfo::isFieldStatic( diff --git a/src/coreclr/jit/helperexpansion.cpp b/src/coreclr/jit/helperexpansion.cpp index 7b2cf663ceba85..eb2e43876e66ef 100644 --- a/src/coreclr/jit/helperexpansion.cpp +++ b/src/coreclr/jit/helperexpansion.cpp @@ -500,10 +500,10 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S memset(&classCtorRunHelper, 0, sizeof(CORINFO_CONST_LOOKUP)); memset(&targetSymbol, 0, sizeof(CORINFO_CONST_LOOKUP)); int size = - info.compCompHnd->getEnsureClassCtorRunAndReturnThreadStaticBaseHelper(&classCtorRunHelper, &targetSymbol); + info.compCompHnd->getEnsureClassCtorRunAndReturnThreadStaticBaseHelper(call->gtInitClsHnd, &classCtorRunHelper, &targetSymbol); // target symbol - GenTree* targetSymbolAddr = gtNewIconHandleNode(classCtorRunHelper.addr, GTF_ICON_OBJ_HDL); + GenTree* targetSymbolAddr = gtNewIconHandleNode((size_t)classCtorRunHelper.addr, GTF_ICON_OBJ_HDL); targetSymbolAddr = gtNewOperNode(GT_ADD, TYP_I_IMPL, targetSymbolAddr, gtNewIconNode(size, TYP_UINT)); targetSymbolAddr = gtNewIndir(TYP_I_IMPL, targetSymbolAddr); @@ -527,7 +527,7 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S // tlsRootNullCondBB (BBJ_COND): [weight: 1.0] // targetSymbolAddr = [targetSymbol + size] - // if (*targetSymbolAddr == 0) + // if (*targetSymbolAddr != 0) // goto fastPathBb; // // fallbackBb (BBJ_ALWAYS): [weight: 0] ???? Check if this is true diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs b/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs index b2fe83c576b2c6..aa5fb744165709 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs @@ -1432,16 +1432,17 @@ private static void _getThreadStaticBaseSlowInfo(IntPtr thisHandle, IntPtr* ppEx } [UnmanagedCallersOnly] - private static void _getEnsureClassCtorRunAndReturnThreadStaticBaseHelper(IntPtr thisHandle, IntPtr* ppException, CORINFO_CONST_LOOKUP* addr) + private static int _getEnsureClassCtorRunAndReturnThreadStaticBaseHelper(IntPtr thisHandle, IntPtr* ppException, CORINFO_CLASS_STRUCT_* cls, CORINFO_CONST_LOOKUP* addr, CORINFO_CONST_LOOKUP* targetSymbol) { var _this = GetThis(thisHandle); try { - _this.getEnsureClassCtorRunAndReturnThreadStaticBaseHelper(ref *addr); + return _this.getEnsureClassCtorRunAndReturnThreadStaticBaseHelper(cls, ref *addr, ref *targetSymbol); } catch (Exception ex) { *ppException = _this.AllocException(ex); + return default; } } @@ -2647,7 +2648,7 @@ private static IntPtr GetUnmanagedCallbacks() callbacks[93] = (delegate* unmanaged)&_getThreadLocalStaticBlocksInfo; callbacks[94] = (delegate* unmanaged)&_getTlsRootInfo; callbacks[95] = (delegate* unmanaged)&_getThreadStaticBaseSlowInfo; - callbacks[96] = (delegate* unmanaged)&_getEnsureClassCtorRunAndReturnThreadStaticBaseHelper; + callbacks[96] = (delegate* unmanaged)&_getEnsureClassCtorRunAndReturnThreadStaticBaseHelper; callbacks[97] = (delegate* unmanaged)&_isFieldStatic; callbacks[98] = (delegate* unmanaged)&_getArrayOrStringLength; callbacks[99] = (delegate* unmanaged)&_getBoundaries; diff --git a/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt b/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt index 28e8e9e49b7123..5f28100deae1f2 100644 --- a/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt +++ b/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt @@ -257,7 +257,7 @@ FUNCTIONS void getThreadLocalStaticBlocksInfo (CORINFO_THREAD_STATIC_BLOCKS_INFO* pInfo, bool isGCType) void getTlsRootInfo(CORINFO_CONST_LOOKUP* addr) void getThreadStaticBaseSlowInfo(CORINFO_CONST_LOOKUP* addr) - int getEnsureClassCtorRunAndReturnThreadStaticBaseHelper(CORINFO_CONST_LOOKUP* addr, CORINFO_CONST_LOOKUP* targetSymbol) + int getEnsureClassCtorRunAndReturnThreadStaticBaseHelper(CORINFO_CLASS_HANDLE cls, CORINFO_CONST_LOOKUP* addr, CORINFO_CONST_LOOKUP* targetSymbol) bool isFieldStatic(CORINFO_FIELD_HANDLE fldHnd) int getArrayOrStringLength(CORINFO_OBJECT_HANDLE objHnd) void getBoundaries(CORINFO_METHOD_HANDLE ftn, unsigned int* cILOffsets, uint32_t** pILOffsets, ICorDebugInfo::BoundaryTypes* implicitBoundaries) diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs index 31c3d00b6c4eb7..7e5d95b0ca5c98 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs @@ -3247,7 +3247,7 @@ private void getThreadStaticBaseSlowInfo(ref CORINFO_CONST_LOOKUP addr) // Implemented for JIT and NativeAOT only for now. } - private int getEnsureClassCtorRunAndReturnThreadStaticBaseHelper(ref CORINFO_CONST_LOOKUP addr, ref CORINFO_CONST_LOOKUP targetSymbol) + private int getEnsureClassCtorRunAndReturnThreadStaticBaseHelper(CORINFO_CLASS_STRUCT_* cls, ref CORINFO_CONST_LOOKUP addr, ref CORINFO_CONST_LOOKUP targetSymbol) { // Implemented for JIT and NativeAOT only for now. return 0; diff --git a/src/coreclr/tools/aot/ILCompiler/repro/Program.cs b/src/coreclr/tools/aot/ILCompiler/repro/Program.cs index 978bcce912b22d..82ecf946d2cde8 100644 --- a/src/coreclr/tools/aot/ILCompiler/repro/Program.cs +++ b/src/coreclr/tools/aot/ILCompiler/repro/Program.cs @@ -12,14 +12,14 @@ class P1 { [ThreadStatic] public static long z; - [ThreadStatic] - public static List list; + //[ThreadStatic] + //public static List list; } class Program { [ThreadStatic] - static uint x; + public static uint x; //[ThreadStatic] //static string y; //[ThreadStatic] @@ -50,7 +50,7 @@ static void Main() Console.WriteLine(Program.x); Console.WriteLine(P1.z); //Console.WriteLine(Program.z); - Console.WriteLine(P1.list); + //Console.WriteLine(P1.list); } [MethodImpl(MethodImplOptions.NoInlining)] @@ -61,10 +61,10 @@ long Test(int n) { //for (int i = 0; i < n; i++) { - //Program.x = 0x900DF00D; + Program.x = 0x900DF00D; //Program.z = 23; //Program.y = "a"; - P1.list = new List(); + //P1.list = new List(); //P1.z = 0x900DF00E; } return 0; diff --git a/src/coreclr/tools/aot/jitinterface/jitinterface_generated.h b/src/coreclr/tools/aot/jitinterface/jitinterface_generated.h index cc5cfff902bf10..cb0cfba12a4020 100644 --- a/src/coreclr/tools/aot/jitinterface/jitinterface_generated.h +++ b/src/coreclr/tools/aot/jitinterface/jitinterface_generated.h @@ -107,7 +107,7 @@ struct JitInterfaceCallbacks void (* getThreadLocalStaticBlocksInfo)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_THREAD_STATIC_BLOCKS_INFO* pInfo, bool isGCType); void (* getTlsRootInfo)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_CONST_LOOKUP* addr); void (* getThreadStaticBaseSlowInfo)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_CONST_LOOKUP* addr); - void (* getEnsureClassCtorRunAndReturnThreadStaticBaseHelper)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_CONST_LOOKUP* addr); + int (* getEnsureClassCtorRunAndReturnThreadStaticBaseHelper)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_CLASS_HANDLE cls, CORINFO_CONST_LOOKUP* addr, CORINFO_CONST_LOOKUP* targetSymbol); bool (* isFieldStatic)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_FIELD_HANDLE fldHnd); int (* getArrayOrStringLength)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_OBJECT_HANDLE objHnd); void (* getBoundaries)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_METHOD_HANDLE ftn, unsigned int* cILOffsets, uint32_t** pILOffsets, ICorDebugInfo::BoundaryTypes* implicitBoundaries); @@ -1134,12 +1134,15 @@ class JitInterfaceWrapper : public ICorJitInfo if (pException != nullptr) throw pException; } - virtual void getEnsureClassCtorRunAndReturnThreadStaticBaseHelper( - CORINFO_CONST_LOOKUP* addr) + virtual int getEnsureClassCtorRunAndReturnThreadStaticBaseHelper( + CORINFO_CLASS_HANDLE cls, + CORINFO_CONST_LOOKUP* addr, + CORINFO_CONST_LOOKUP* targetSymbol) { CorInfoExceptionClass* pException = nullptr; - _callbacks->getEnsureClassCtorRunAndReturnThreadStaticBaseHelper(_thisHandle, &pException, addr); + int temp = _callbacks->getEnsureClassCtorRunAndReturnThreadStaticBaseHelper(_thisHandle, &pException, cls, addr, targetSymbol); if (pException != nullptr) throw pException; + return temp; } virtual bool isFieldStatic( diff --git a/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo_generated.cpp b/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo_generated.cpp index b282f4acb447fe..25befc051523a1 100644 --- a/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo_generated.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo_generated.cpp @@ -777,11 +777,13 @@ void interceptor_ICJI::getThreadStaticBaseSlowInfo( original_ICorJitInfo->getThreadStaticBaseSlowInfo(addr); } -void interceptor_ICJI::getEnsureClassCtorRunAndReturnThreadStaticBaseHelper( - CORINFO_CONST_LOOKUP* addr) +int interceptor_ICJI::getEnsureClassCtorRunAndReturnThreadStaticBaseHelper( + CORINFO_CLASS_HANDLE cls, + CORINFO_CONST_LOOKUP* addr, + CORINFO_CONST_LOOKUP* targetSymbol) { mcs->AddCall("getEnsureClassCtorRunAndReturnThreadStaticBaseHelper"); - original_ICorJitInfo->getEnsureClassCtorRunAndReturnThreadStaticBaseHelper(addr); + return original_ICorJitInfo->getEnsureClassCtorRunAndReturnThreadStaticBaseHelper(cls, addr, targetSymbol); } bool interceptor_ICJI::isFieldStatic( diff --git a/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo_generated.cpp b/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo_generated.cpp index b0a05204d97165..577fe3286943b0 100644 --- a/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo_generated.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo_generated.cpp @@ -681,10 +681,12 @@ void interceptor_ICJI::getThreadStaticBaseSlowInfo( original_ICorJitInfo->getThreadStaticBaseSlowInfo(addr); } -void interceptor_ICJI::getEnsureClassCtorRunAndReturnThreadStaticBaseHelper( - CORINFO_CONST_LOOKUP* addr) +int interceptor_ICJI::getEnsureClassCtorRunAndReturnThreadStaticBaseHelper( + CORINFO_CLASS_HANDLE cls, + CORINFO_CONST_LOOKUP* addr, + CORINFO_CONST_LOOKUP* targetSymbol) { - original_ICorJitInfo->getEnsureClassCtorRunAndReturnThreadStaticBaseHelper(addr); + return original_ICorJitInfo->getEnsureClassCtorRunAndReturnThreadStaticBaseHelper(cls, addr, targetSymbol); } bool interceptor_ICJI::isFieldStatic( From f736b2cb9493b7d56a9abe84b69d65a8b692ea17 Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Tue, 25 Jul 2023 05:59:44 -0700 Subject: [PATCH 05/58] working --- src/coreclr/jit/helperexpansion.cpp | 159 ++++++++++++++---- .../ILCompiler.Compiler/Compiler/ILScanner.cs | 2 +- .../JitInterface/CorInfoImpl.RyuJit.cs | 6 - .../tools/aot/ILCompiler/ILCompiler.csproj | 3 - .../tools/aot/ILCompiler/repro/Program.cs | 15 +- 5 files changed, 133 insertions(+), 52 deletions(-) diff --git a/src/coreclr/jit/helperexpansion.cpp b/src/coreclr/jit/helperexpansion.cpp index eb2e43876e66ef..97d02c020e7800 100644 --- a/src/coreclr/jit/helperexpansion.cpp +++ b/src/coreclr/jit/helperexpansion.cpp @@ -452,11 +452,17 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S assert(opts.IsReadyToRun()); BasicBlock* block = *pBlock; assert(call->IsHelperCall()); - if (!(call->IsExpTLSFieldAccess() && call->IsExpTLSFieldAccessLazyCtor())) + if (!(call->IsExpTLSFieldAccess() || call->IsExpTLSFieldAccessLazyCtor())) { return false; } + //if (info.compMethodHashPrivate == 0x2f7ba577) // 0xx009bf64b + //{ + // printf("BEFORE:\n"); + // fgDispBasicBlocks(true); + //} + JITDUMP("Expanding thread static local access for [%06d] in " FMT_BB ":\n", dspTreeID(call), block->bbNum); DISPTREE(call); JITDUMP("\n"); @@ -491,9 +497,29 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S var_types callType = call->TypeGet(); assert(prevBb != nullptr && block != nullptr); + BasicBlock* targetSymbCondBB = nullptr; + BasicBlock* lazyCtorBB = nullptr; + + unsigned finalLclNum = lvaGrabTemp(true DEBUGARG("Final offset")); + lvaTable[finalLclNum].lvType = TYP_I_IMPL; + GenTree* finalLcl = gtNewLclVarNode(finalLclNum); + if (hasLazyStaticCtor) { - BasicBlock* lazyCtorBlock = nullptr; + // targetSymbCondBB (BBJ_COND): [weight: 1.0] + // targetSymbolAddr = [targetSymbol + size] + // if (*targetSymbolAddr == 0) + // goto tlsAccessBB; + // + // lazyCtorBlock (BBJ_ALWAYS): [weight: 0] ???? Check if this is true + // tlsRoot = HelperCall(0, -1, targetSymbolAddr); + // goto block; + // + // tlsAccessBB (BBJ_ALWAYS): [weight: 1.0] + // tlsRoot = ...; + // + // block (...): [weight: 1.0] + // use(tlsRoot); CORINFO_CONST_LOOKUP classCtorRunHelper; CORINFO_CONST_LOOKUP targetSymbol; @@ -503,13 +529,22 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S info.compCompHnd->getEnsureClassCtorRunAndReturnThreadStaticBaseHelper(call->gtInitClsHnd, &classCtorRunHelper, &targetSymbol); // target symbol - GenTree* targetSymbolAddr = gtNewIconHandleNode((size_t)classCtorRunHelper.addr, GTF_ICON_OBJ_HDL); - targetSymbolAddr = gtNewOperNode(GT_ADD, TYP_I_IMPL, targetSymbolAddr, gtNewIconNode(size, TYP_UINT)); - targetSymbolAddr = gtNewIndir(TYP_I_IMPL, targetSymbolAddr); + GenTree* targetSymbolAddr = gtNewIconHandleNode((size_t)targetSymbol.addr, GTF_ICON_OBJ_HDL); + targetSymbolAddr = gtNewOperNode(GT_ADD, TYP_I_IMPL, targetSymbolAddr, gtNewIconNode(size, TYP_I_IMPL)); + GenTree* targetSymbolAddrVal = gtNewIndir(TYP_I_IMPL, targetSymbolAddr); - GenTree* targetSymbolNullCond = gtNewOperNode(GT_NE, TYP_INT, targetSymbolAddr, gtNewIconNode(0, TYP_I_IMPL)); - targetSymbolNullCond = gtNewOperNode(GT_JTRUE, TYP_VOID, targetSymbolNullCond); + //// Cache the TlsRootAddr value + //unsigned targetSymAddrLclNum = lvaGrabTemp(true DEBUGARG("targetSymbAddr access")); + //lvaTable[targetSymAddrLclNum].lvType = TYP_I_IMPL; + //GenTree* targetSymAddrDef = gtNewStoreLclVarNode(targetSymAddrLclNum, gtCloneExpr(targetSymbolAddr)); + targetSymbCondBB = fgNewBBFromTreeAfter(BBJ_COND, prevBb, gtCloneExpr(targetSymbolAddr), debugInfo); + //GenTree* targetSymAddrUse = gtNewLclVarNode(targetSymAddrLclNum); + + GenTree* targetSymbolNullCond = + gtNewOperNode(GT_EQ, TYP_INT, targetSymbolAddrVal, gtNewIconNode(0, TYP_I_IMPL)); + targetSymbolNullCond = gtNewOperNode(GT_JTRUE, TYP_VOID, targetSymbolNullCond); + fgInsertStmtAfter(targetSymbCondBB, targetSymbCondBB->firstStmt(), fgNewStmtFromTree(targetSymbolNullCond)); GenTreeCall* classCtorRunHelperCall = gtNewIndCallNode(gtNewIconHandleNode((size_t)classCtorRunHelper.addr, GTF_ICON_FTN_ADDR), TYP_I_IMPL); @@ -522,22 +557,39 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S // arg2: NonGCStatics targetSymbol classCtorRunHelperCall->gtArgs.PushBack(this, NewCallArg::Primitive(gtCloneExpr(targetSymbolAddr))); + //classCtorRunHelperCall->gtArgs.PushBack(this, NewCallArg::Primitive(targetSymAddrUse)); fgMorphArgs(classCtorRunHelperCall); - // tlsRootNullCondBB (BBJ_COND): [weight: 1.0] - // targetSymbolAddr = [targetSymbol + size] - // if (*targetSymbolAddr != 0) - // goto fastPathBb; - // - // fallbackBb (BBJ_ALWAYS): [weight: 0] ???? Check if this is true - // tlsRoot = HelperCall(0, -1, targetSymbolAddr); - // goto block; - // - // tlsAccess(BBJ_ALWAYS): [weight: 1.0] - // tlsRoot = fastPathValue; + // lazyCtorBB + //unsigned targetLclNum = lvaGrabTemp(true DEBUGARG("Target addr")); + //lvaTable[targetLclNum].lvType = TYP_I_IMPL; + //GenTree* lazyCtorValueDef = gtNewStoreLclVarNode(targetLclNum, classCtorRunHelperCall); + //GenTree* lazyCtorLcl = gtNewLclVarNode(targetLclNum); + //lazyCtorBB = fgNewBBFromTreeAfter(BBJ_ALWAYS, targetSymbCondBB, lazyCtorValueDef, debugInfo, true); + + //*callUse = lazyCtorLcl; + GenTree* lazyCtorValueDef = gtNewStoreLclVarNode(finalLclNum, classCtorRunHelperCall); + lazyCtorBB = fgNewBBFromTreeAfter(BBJ_ALWAYS, targetSymbCondBB, lazyCtorValueDef, debugInfo, true); - prevBb = lazyCtorBlock; + fgRemoveRefPred(block, prevBb); + fgAddRefPred(targetSymbCondBB, prevBb); + fgAddRefPred(lazyCtorBB, targetSymbCondBB); + fgAddRefPred(block, lazyCtorBB); + + lazyCtorBB->bbJumpDest = block; + + // Inherit the weights + block->inheritWeight(prevBb); + targetSymbCondBB->inheritWeight(prevBb); + + targetSymbCondBB->bbNatLoopNum = prevBb->bbNatLoopNum; + lazyCtorBB->bbNatLoopNum = prevBb->bbNatLoopNum; + + assert(BasicBlock::sameEHRegion(prevBb, targetSymbCondBB)); + assert(BasicBlock::sameEHRegion(prevBb, lazyCtorBB)); + + prevBb = lazyCtorBB; } // Block ops inserted by the split need to be morphed here since we are after morph. @@ -558,6 +610,8 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S if (TargetOS::IsWindows) { +#pragma region block logic + // Mark this ICON as a TLS_HDL, codegen will use FS:[cns] or GS:[cns] tlsValue = gtNewIconHandleNode(threadStaticBlocksInfo.offsetOfThreadLocalStoragePointer, GTF_ICON_TLS_HDL); tlsValue = gtNewIndir(TYP_I_IMPL, tlsValue, GTF_IND_NONFAULTING | GTF_IND_INVARIANT); @@ -591,12 +645,15 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S GenTree* tlsRootVal = gtNewIndir(TYP_I_IMPL, tlsRootAddrUse, GTF_IND_NONFAULTING | GTF_IND_INVARIANT); // Cache the TlsRoot value - unsigned tlsRootLclNum = lvaGrabTemp(true DEBUGARG("TlsRoot access")); - lvaTable[tlsRootLclNum].lvType = TYP_I_IMPL; - GenTree* tlsRootDef = gtNewStoreLclVarNode(tlsRootLclNum, tlsRootVal); - GenTree* tlsRootUse = gtNewLclVarNode(tlsRootLclNum); + //unsigned tlsRootLclNum = lvaGrabTemp(true DEBUGARG("TlsRoot access")); + //lvaTable[tlsRootLclNum].lvType = TYP_I_IMPL; + //GenTree* tlsRootDef = gtNewStoreLclVarNode(tlsRootLclNum, tlsRootVal); + //GenTree* tlsRootLcl = gtNewLclVarNode(tlsRootLclNum); + + GenTree* tlsRootDef = gtNewStoreLclVarNode(finalLclNum, tlsRootVal); - GenTree* tlsRootNullCond = gtNewOperNode(GT_NE, TYP_INT, tlsRootUse, gtNewIconNode(0, TYP_I_IMPL)); + //GenTree* tlsRootNullCond = gtNewOperNode(GT_NE, TYP_INT, tlsRootLcl, gtNewIconNode(0, TYP_I_IMPL)); + GenTree* tlsRootNullCond = gtNewOperNode(GT_NE, TYP_INT, gtCloneExpr(finalLcl), gtNewIconNode(0, TYP_I_IMPL)); tlsRootNullCond = gtNewOperNode(GT_JTRUE, TYP_VOID, tlsRootNullCond); // prevBb (BBJ_NONE): [weight: 1.0] @@ -632,20 +689,20 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S fgMorphArgs(slowHelper); // fallbackBb - GenTree* fallbackValueDef = gtNewStoreLclVarNode(tlsRootLclNum, slowHelper); + GenTree* fallbackValueDef = gtNewStoreLclVarNode(finalLclNum, slowHelper); + //GenTree* fallbackValueDef = gtNewStoreLclVarNode(tlsRootLclNum, slowHelper); BasicBlock* fallbackBb = fgNewBBFromTreeAfter(BBJ_ALWAYS, tlsRootNullCondBB, fallbackValueDef, debugInfo, true); - GenTree* fastPathValueDef = gtNewStoreLclVarNode(tlsRootLclNum, gtCloneExpr(tlsRootUse)); + GenTree* fastPathValueDef = gtNewStoreLclVarNode(finalLclNum, gtCloneExpr(finalLcl)); + //GenTree* fastPathValueDef = gtNewStoreLclVarNode(tlsRootLclNum, gtCloneExpr(tlsRootLcl)); BasicBlock* fastPathBb = fgNewBBFromTreeAfter(BBJ_ALWAYS, fallbackBb, fastPathValueDef, debugInfo, true); - //GenTreeLclVar* threadStaticBlockLcl = nullptr; + //if (!hasLazyStaticCtor) + //{ + // *callUse = gtClone(tlsRootLcl); + //} - //// Grab a temp to store result (it's assigned from either fastPathBb or fallbackBb) - //unsigned threadStaticBlockLclNum = lvaGrabTemp(true DEBUGARG("TLS field access")); - //lvaTable[threadStaticBlockLclNum].lvType = callType; - //threadStaticBlockLcl = gtNewLclvNode(threadStaticBlockLclNum, callType); - - *callUse = gtClone(tlsRootUse); + *callUse = finalLcl; fgMorphStmtBlockOps(block, stmt); gtUpdateStmtSideEffects(stmt); @@ -653,9 +710,7 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S // // Update preds in all new blocks // - fgRemoveRefPred(block, prevBb); - fgAddRefPred(tlsRootNullCondBB, prevBb); - +#pragma endregion fgAddRefPred(fallbackBb, tlsRootNullCondBB); fgAddRefPred(fastPathBb, tlsRootNullCondBB); @@ -674,6 +729,27 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S // fallback will just execute first time fallbackBb->bbSetRunRarely(); + if (hasLazyStaticCtor) + { + assert(targetSymbCondBB != nullptr); + assert(lazyCtorBB != nullptr); + + targetSymbCondBB->bbJumpDest = tlsRootNullCondBB; + lazyCtorBB->bbJumpDest = block; + + fgAddRefPred(tlsRootNullCondBB, targetSymbCondBB); + //fgAddRefPred(block, lazyCtorBB); + //fgAddRefPred(tlsRootNullCondBB, lazyCtorBB); + + // lazyCtorBB will just execute first time + lazyCtorBB->bbSetRunRarely(); + } + else + { + fgRemoveRefPred(block, prevBb); + fgAddRefPred(tlsRootNullCondBB, prevBb); + } + // // Update loop info if loop table is known to be valid // @@ -686,6 +762,12 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S assert(BasicBlock::sameEHRegion(prevBb, tlsRootNullCondBB)); assert(BasicBlock::sameEHRegion(prevBb, fastPathBb)); + //if (info.compMethodHashPrivate == 0x2f7ba577) // 0x009bf64b + //{ + // printf("AFTER:\n"); + // fgDispBasicBlocks(true); + //} + return true; } else @@ -1091,6 +1173,11 @@ PhaseStatus Compiler::fgExpandHelper(bool skipRarelyRunBlocks) if ((result == PhaseStatus::MODIFIED_EVERYTHING) && opts.OptimizationEnabled()) { fgReorderBlocks(/* useProfileData */ false); + //if (info.compMethodHashPrivate == 0x2f7ba577) // 0x009bf64b + //{ + // printf("Reorder:\n"); + // fgDispBasicBlocks(true); + //} fgUpdateChangedFlowGraph(FlowGraphUpdates::COMPUTE_BASICS); } diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ILScanner.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ILScanner.cs index abbf0663c34502..46b4727d7647c6 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ILScanner.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ILScanner.cs @@ -726,7 +726,7 @@ public ScannedInlinedThreadStatics(NodeFactory factory, ImmutableArrayhelper = CorInfoHelpFunc.CORINFO_HELP_READYTORUN_THREADSTATIC_BASE; helperId = ReadyToRunHelperId.GetThreadStaticBase; diff --git a/src/coreclr/tools/aot/ILCompiler/ILCompiler.csproj b/src/coreclr/tools/aot/ILCompiler/ILCompiler.csproj index 247a1edea3f39f..71c94c9dc1b035 100644 --- a/src/coreclr/tools/aot/ILCompiler/ILCompiler.csproj +++ b/src/coreclr/tools/aot/ILCompiler/ILCompiler.csproj @@ -74,8 +74,5 @@ - - - diff --git a/src/coreclr/tools/aot/ILCompiler/repro/Program.cs b/src/coreclr/tools/aot/ILCompiler/repro/Program.cs index 82ecf946d2cde8..757256715c2106 100644 --- a/src/coreclr/tools/aot/ILCompiler/repro/Program.cs +++ b/src/coreclr/tools/aot/ILCompiler/repro/Program.cs @@ -8,7 +8,7 @@ using System.Threading; using System.Threading.Tasks; -class P1 +class P1 { [ThreadStatic] public static long z; @@ -33,14 +33,14 @@ static void Main() //Program.x = 5; ////Program.y = "a"; //Program.list = new List(); - P1.z = 0x900DF00E; + P1.z = 0x900DF00E; Program.x = 0x900DF00D; Program obj = new Program(); obj.Test(1); //Console.WriteLine("Hello"); - //Console.WriteLine(Program.x + P1.z); + Console.WriteLine(Program.x); //Console.WriteLine(Program.y); - //Console.WriteLine(Program.z); + Console.WriteLine(P1.z); //Console.WriteLine(Program.x + Program.z | P1.z); //Program.z = 15; @@ -48,7 +48,7 @@ static void Main() Console.WriteLine(CultureInfo.CurrentCulture); Console.WriteLine(Program.x); - Console.WriteLine(P1.z); + Console.WriteLine(P1.z); //Console.WriteLine(Program.z); //Console.WriteLine(P1.list); } @@ -61,11 +61,14 @@ long Test(int n) { //for (int i = 0; i < n; i++) { + //Console.WriteLine(CultureInfo.CurrentCulture); + //Console.WriteLine(CultureInfo.CurrentCulture); + //Console.WriteLine(CultureInfo.CurrentCulture); Program.x = 0x900DF00D; //Program.z = 23; //Program.y = "a"; //P1.list = new List(); - //P1.z = 0x900DF00E; + P1.z = 0x900DF00E; } return 0; } From 6cd92f336ce02e6b068fb24f39674ea87e017df3 Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Tue, 25 Jul 2023 06:42:25 -0700 Subject: [PATCH 06/58] Add helper for tlsIndex --- src/coreclr/inc/corinfo.h | 3 +- src/coreclr/inc/icorjitinfoimpl_generated.h | 3 + src/coreclr/jit/ICorJitInfo_names_generated.h | 1 + .../jit/ICorJitInfo_wrapper_generated.hpp | 8 + src/coreclr/jit/helperexpansion.cpp | 100 +++------- .../Common/JitInterface/CorInfoHelpFunc.cs | 1 - .../JitInterface/CorInfoImpl_generated.cs | 171 ++++++++++-------- .../tools/Common/JitInterface/CorInfoTypes.cs | 1 - .../ThunkGenerator/ThunkInput.txt | 1 + .../ILCompiler.Compiler/Compiler/ILScanner.cs | 2 +- .../JitInterface/CorInfoImpl.RyuJit.cs | 8 +- .../aot/jitinterface/jitinterface_generated.h | 9 + .../icorjitinfo_generated.cpp | 7 + .../icorjitinfo_generated.cpp | 6 + 14 files changed, 165 insertions(+), 156 deletions(-) diff --git a/src/coreclr/inc/corinfo.h b/src/coreclr/inc/corinfo.h index ae36640bffc16f..0f5ac096ad2a28 100644 --- a/src/coreclr/inc/corinfo.h +++ b/src/coreclr/inc/corinfo.h @@ -601,7 +601,6 @@ enum CorInfoHelpFunc CORINFO_HELP_READYTORUN_GENERIC_HANDLE, CORINFO_HELP_READYTORUN_DELEGATE_CTOR, CORINFO_HELP_READYTORUN_GENERIC_STATIC_BASE, - CORINFO_HELP_READYTORUN_INLINED_THREADSTATIC_BASE_SLOW, CORINFO_HELP_EE_PERSONALITY_ROUTINE,// Not real JIT helper. Used in native images. CORINFO_HELP_EE_PERSONALITY_ROUTINE_FILTER_FUNCLET,// Not real JIT helper. Used in native images to detect filter funclets. @@ -1738,7 +1737,6 @@ struct CORINFO_THREAD_STATIC_BLOCKS_INFO uint32_t offsetOfMaxThreadStaticBlocks; uint32_t offsetOfThreadStaticBlocks; uint32_t offsetOfGCDataPointer; - CORINFO_CONST_LOOKUP tlsRoot; // for nativeaot }; //---------------------------------------------------------------------------- @@ -2794,6 +2792,7 @@ class ICorStaticInfo //TODO: Rename the method names to get*Helper virtual void getTlsRootInfo(CORINFO_CONST_LOOKUP* addr) = 0; + virtual void getTlsIndexInfo(CORINFO_CONST_LOOKUP* addr) = 0; virtual void getThreadStaticBaseSlowInfo(CORINFO_CONST_LOOKUP* addr) = 0; virtual int getEnsureClassCtorRunAndReturnThreadStaticBaseHelper(CORINFO_CLASS_HANDLE cls, CORINFO_CONST_LOOKUP* addr, CORINFO_CONST_LOOKUP* targetSymbol) = 0; diff --git a/src/coreclr/inc/icorjitinfoimpl_generated.h b/src/coreclr/inc/icorjitinfoimpl_generated.h index 6fd6c0438074d5..5c24cb6332449d 100644 --- a/src/coreclr/inc/icorjitinfoimpl_generated.h +++ b/src/coreclr/inc/icorjitinfoimpl_generated.h @@ -399,6 +399,9 @@ void getThreadLocalStaticBlocksInfo( void getTlsRootInfo( CORINFO_CONST_LOOKUP* addr) override; +void getTlsIndexInfo( + CORINFO_CONST_LOOKUP* addr) override; + void getThreadStaticBaseSlowInfo( CORINFO_CONST_LOOKUP* addr) override; diff --git a/src/coreclr/jit/ICorJitInfo_names_generated.h b/src/coreclr/jit/ICorJitInfo_names_generated.h index fa8bfa67c8c598..e3ebf6a4de6bb6 100644 --- a/src/coreclr/jit/ICorJitInfo_names_generated.h +++ b/src/coreclr/jit/ICorJitInfo_names_generated.h @@ -99,6 +99,7 @@ DEF_CLR_API(getFieldInfo) DEF_CLR_API(getThreadLocalFieldInfo) DEF_CLR_API(getThreadLocalStaticBlocksInfo) DEF_CLR_API(getTlsRootInfo) +DEF_CLR_API(getTlsIndexInfo) DEF_CLR_API(getThreadStaticBaseSlowInfo) DEF_CLR_API(getEnsureClassCtorRunAndReturnThreadStaticBaseHelper) DEF_CLR_API(isFieldStatic) diff --git a/src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp b/src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp index 84ed179e46c0f1..067c6310554e61 100644 --- a/src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp +++ b/src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp @@ -940,6 +940,14 @@ void WrapICorJitInfo::getTlsRootInfo( API_LEAVE(getTlsRootInfo); } +void WrapICorJitInfo::getTlsIndexInfo( + CORINFO_CONST_LOOKUP* addr) +{ + API_ENTER(getTlsIndexInfo); + wrapHnd->getTlsIndexInfo(addr); + API_LEAVE(getTlsIndexInfo); +} + void WrapICorJitInfo::getThreadStaticBaseSlowInfo( CORINFO_CONST_LOOKUP* addr) { diff --git a/src/coreclr/jit/helperexpansion.cpp b/src/coreclr/jit/helperexpansion.cpp index 97d02c020e7800..67639bb80fff06 100644 --- a/src/coreclr/jit/helperexpansion.cpp +++ b/src/coreclr/jit/helperexpansion.cpp @@ -504,23 +504,37 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S lvaTable[finalLclNum].lvType = TYP_I_IMPL; GenTree* finalLcl = gtNewLclVarNode(finalLclNum); + // if (lazyCtorBlock) + // { + // targetSymbCondBB (BBJ_COND): [weight: 1.0] + // targetSymbolAddr = [targetSymbol + size] + // if (*targetSymbolAddr == 0) + // goto tlsRootNullCondBB; + // + // lazyCtorBlock (BBJ_ALWAYS): [weight: 0] + // tlsRoot = HelperCall(0, -1, targetSymbolAddr); + // goto block + // + // } + // tlsRootNullCondBB (BBJ_COND): [weight: 1.0] + // fastPathValue = [tlsRootAddress] + // if (fastPathValue != nullptr) + // goto fastPathBb; + // + // fallbackBb (BBJ_ALWAYS): [weight: 0] + // tlsRoot = HelperCall(tlsRootAddress); + // goto block; + // + // fastPathBb(BBJ_ALWAYS): [weight: 1.0] + // tlsRoot = fastPathValue; + // + // + // block (...): [weight: 1.0] + // use(tlsRoot); + + if (hasLazyStaticCtor) { - // targetSymbCondBB (BBJ_COND): [weight: 1.0] - // targetSymbolAddr = [targetSymbol + size] - // if (*targetSymbolAddr == 0) - // goto tlsAccessBB; - // - // lazyCtorBlock (BBJ_ALWAYS): [weight: 0] ???? Check if this is true - // tlsRoot = HelperCall(0, -1, targetSymbolAddr); - // goto block; - // - // tlsAccessBB (BBJ_ALWAYS): [weight: 1.0] - // tlsRoot = ...; - // - // block (...): [weight: 1.0] - // use(tlsRoot); - CORINFO_CONST_LOOKUP classCtorRunHelper; CORINFO_CONST_LOOKUP targetSymbol; memset(&classCtorRunHelper, 0, sizeof(CORINFO_CONST_LOOKUP)); @@ -533,14 +547,8 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S targetSymbolAddr = gtNewOperNode(GT_ADD, TYP_I_IMPL, targetSymbolAddr, gtNewIconNode(size, TYP_I_IMPL)); GenTree* targetSymbolAddrVal = gtNewIndir(TYP_I_IMPL, targetSymbolAddr); - //// Cache the TlsRootAddr value - //unsigned targetSymAddrLclNum = lvaGrabTemp(true DEBUGARG("targetSymbAddr access")); - //lvaTable[targetSymAddrLclNum].lvType = TYP_I_IMPL; - //GenTree* targetSymAddrDef = gtNewStoreLclVarNode(targetSymAddrLclNum, gtCloneExpr(targetSymbolAddr)); targetSymbCondBB = fgNewBBFromTreeAfter(BBJ_COND, prevBb, gtCloneExpr(targetSymbolAddr), debugInfo); - //GenTree* targetSymAddrUse = gtNewLclVarNode(targetSymAddrLclNum); - GenTree* targetSymbolNullCond = gtNewOperNode(GT_EQ, TYP_INT, targetSymbolAddrVal, gtNewIconNode(0, TYP_I_IMPL)); targetSymbolNullCond = gtNewOperNode(GT_JTRUE, TYP_VOID, targetSymbolNullCond); @@ -557,18 +565,9 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S // arg2: NonGCStatics targetSymbol classCtorRunHelperCall->gtArgs.PushBack(this, NewCallArg::Primitive(gtCloneExpr(targetSymbolAddr))); - //classCtorRunHelperCall->gtArgs.PushBack(this, NewCallArg::Primitive(targetSymAddrUse)); fgMorphArgs(classCtorRunHelperCall); - // lazyCtorBB - //unsigned targetLclNum = lvaGrabTemp(true DEBUGARG("Target addr")); - //lvaTable[targetLclNum].lvType = TYP_I_IMPL; - //GenTree* lazyCtorValueDef = gtNewStoreLclVarNode(targetLclNum, classCtorRunHelperCall); - //GenTree* lazyCtorLcl = gtNewLclVarNode(targetLclNum); - //lazyCtorBB = fgNewBBFromTreeAfter(BBJ_ALWAYS, targetSymbCondBB, lazyCtorValueDef, debugInfo, true); - - //*callUse = lazyCtorLcl; GenTree* lazyCtorValueDef = gtNewStoreLclVarNode(finalLclNum, classCtorRunHelperCall); lazyCtorBB = fgNewBBFromTreeAfter(BBJ_ALWAYS, targetSymbCondBB, lazyCtorValueDef, debugInfo, true); @@ -629,7 +628,6 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S CORINFO_CONST_LOOKUP tlsRootNode; info.compCompHnd->getTlsRootInfo(&tlsRootNode); - //GenTree* tlsRootOffset = gtNewIconHandleNode((size_t)tlsRootNode.handle, GTF_ICON_SECREL_OFFSET); GenTree* tlsRootOffset = gtNewIconNode((size_t)tlsRootNode.handle, TYP_INT); tlsRootOffset->gtFlags |= GTF_ICON_SECREL_OFFSET; @@ -644,37 +642,12 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S GenTree* tlsRootVal = gtNewIndir(TYP_I_IMPL, tlsRootAddrUse, GTF_IND_NONFAULTING | GTF_IND_INVARIANT); - // Cache the TlsRoot value - //unsigned tlsRootLclNum = lvaGrabTemp(true DEBUGARG("TlsRoot access")); - //lvaTable[tlsRootLclNum].lvType = TYP_I_IMPL; - //GenTree* tlsRootDef = gtNewStoreLclVarNode(tlsRootLclNum, tlsRootVal); - //GenTree* tlsRootLcl = gtNewLclVarNode(tlsRootLclNum); - GenTree* tlsRootDef = gtNewStoreLclVarNode(finalLclNum, tlsRootVal); //GenTree* tlsRootNullCond = gtNewOperNode(GT_NE, TYP_INT, tlsRootLcl, gtNewIconNode(0, TYP_I_IMPL)); GenTree* tlsRootNullCond = gtNewOperNode(GT_NE, TYP_INT, gtCloneExpr(finalLcl), gtNewIconNode(0, TYP_I_IMPL)); tlsRootNullCond = gtNewOperNode(GT_JTRUE, TYP_VOID, tlsRootNullCond); - // prevBb (BBJ_NONE): [weight: 1.0] - // ... - // - // tlsRootNullCondBB (BBJ_COND): [weight: 1.0] - // fastPathValue = [tlsRootAddress] - // if (fastPathValue != nullptr) - // goto fastPathBb; - // - // fallbackBb (BBJ_ALWAYS): [weight: 0] - // tlsRoot = HelperCall(tlsRootAddress); - // goto block; - // - // fastPathBb(BBJ_ALWAYS): [weight: 1.0] - // tlsRoot = fastPathValue; - // - // block (...): [weight: 1.0] - // use(tlsRoot); - // ... - // tlsRootNullCondBB BasicBlock* tlsRootNullCondBB = fgNewBBFromTreeAfter(BBJ_COND, prevBb, tlsRootAddrDef, debugInfo); fgInsertStmtAfter(tlsRootNullCondBB, tlsRootNullCondBB->firstStmt(), fgNewStmtFromTree(tlsRootNullCond)); @@ -690,18 +663,11 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S // fallbackBb GenTree* fallbackValueDef = gtNewStoreLclVarNode(finalLclNum, slowHelper); - //GenTree* fallbackValueDef = gtNewStoreLclVarNode(tlsRootLclNum, slowHelper); BasicBlock* fallbackBb = fgNewBBFromTreeAfter(BBJ_ALWAYS, tlsRootNullCondBB, fallbackValueDef, debugInfo, true); GenTree* fastPathValueDef = gtNewStoreLclVarNode(finalLclNum, gtCloneExpr(finalLcl)); - //GenTree* fastPathValueDef = gtNewStoreLclVarNode(tlsRootLclNum, gtCloneExpr(tlsRootLcl)); BasicBlock* fastPathBb = fgNewBBFromTreeAfter(BBJ_ALWAYS, fallbackBb, fastPathValueDef, debugInfo, true); - //if (!hasLazyStaticCtor) - //{ - // *callUse = gtClone(tlsRootLcl); - //} - *callUse = finalLcl; fgMorphStmtBlockOps(block, stmt); @@ -738,8 +704,6 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S lazyCtorBB->bbJumpDest = block; fgAddRefPred(tlsRootNullCondBB, targetSymbCondBB); - //fgAddRefPred(block, lazyCtorBB); - //fgAddRefPred(tlsRootNullCondBB, lazyCtorBB); // lazyCtorBB will just execute first time lazyCtorBB->bbSetRunRarely(); @@ -762,12 +726,6 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S assert(BasicBlock::sameEHRegion(prevBb, tlsRootNullCondBB)); assert(BasicBlock::sameEHRegion(prevBb, fastPathBb)); - //if (info.compMethodHashPrivate == 0x2f7ba577) // 0x009bf64b - //{ - // printf("AFTER:\n"); - // fgDispBasicBlocks(true); - //} - return true; } else diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoHelpFunc.cs b/src/coreclr/tools/Common/JitInterface/CorInfoHelpFunc.cs index a87d4770ba79a5..ea5bfafb98bfe9 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoHelpFunc.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoHelpFunc.cs @@ -243,7 +243,6 @@ which is the right helper to use to allocate an object of a given type. */ CORINFO_HELP_READYTORUN_GENERIC_HANDLE, CORINFO_HELP_READYTORUN_DELEGATE_CTOR, CORINFO_HELP_READYTORUN_GENERIC_STATIC_BASE, - CORINFO_HELP_READYTORUN_INLINED_THREADSTATIC_BASE_SLOW, CORINFO_HELP_EE_PERSONALITY_ROUTINE, // Not real JIT helper. Used in native images. CORINFO_HELP_EE_PERSONALITY_ROUTINE_FILTER_FUNCLET, // Not real JIT helper. Used in native images to detect filter funclets. diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs b/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs index aa5fb744165709..eea9ce249e4bc0 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs @@ -1417,6 +1417,20 @@ private static void _getTlsRootInfo(IntPtr thisHandle, IntPtr* ppException, CORI } } + [UnmanagedCallersOnly] + private static void _getTlsIndexInfo(IntPtr thisHandle, IntPtr* ppException, CORINFO_CONST_LOOKUP* addr) + { + var _this = GetThis(thisHandle); + try + { + _this.getTlsIndexInfo(ref *addr); + } + catch (Exception ex) + { + *ppException = _this.AllocException(ex); + } + } + [UnmanagedCallersOnly] private static void _getThreadStaticBaseSlowInfo(IntPtr thisHandle, IntPtr* ppException, CORINFO_CONST_LOOKUP* addr) { @@ -2550,7 +2564,7 @@ private static uint _getJitFlags(IntPtr thisHandle, IntPtr* ppException, CORJIT_ private static IntPtr GetUnmanagedCallbacks() { - void** callbacks = (void**)Marshal.AllocCoTaskMem(sizeof(IntPtr) * 172); + void** callbacks = (void**)Marshal.AllocCoTaskMem(sizeof(IntPtr) * 173); callbacks[0] = (delegate* unmanaged)&_isIntrinsic; callbacks[1] = (delegate* unmanaged)&_getMethodAttribs; @@ -2647,83 +2661,84 @@ private static IntPtr GetUnmanagedCallbacks() callbacks[92] = (delegate* unmanaged)&_getThreadLocalFieldInfo; callbacks[93] = (delegate* unmanaged)&_getThreadLocalStaticBlocksInfo; callbacks[94] = (delegate* unmanaged)&_getTlsRootInfo; - callbacks[95] = (delegate* unmanaged)&_getThreadStaticBaseSlowInfo; - callbacks[96] = (delegate* unmanaged)&_getEnsureClassCtorRunAndReturnThreadStaticBaseHelper; - callbacks[97] = (delegate* unmanaged)&_isFieldStatic; - callbacks[98] = (delegate* unmanaged)&_getArrayOrStringLength; - callbacks[99] = (delegate* unmanaged)&_getBoundaries; - callbacks[100] = (delegate* unmanaged)&_setBoundaries; - callbacks[101] = (delegate* unmanaged)&_getVars; - callbacks[102] = (delegate* unmanaged)&_setVars; - callbacks[103] = (delegate* unmanaged)&_reportRichMappings; - callbacks[104] = (delegate* unmanaged)&_allocateArray; - callbacks[105] = (delegate* unmanaged)&_freeArray; - callbacks[106] = (delegate* unmanaged)&_getArgNext; - callbacks[107] = (delegate* unmanaged)&_getArgType; - callbacks[108] = (delegate* unmanaged)&_getExactClasses; - callbacks[109] = (delegate* unmanaged)&_getArgClass; - callbacks[110] = (delegate* unmanaged)&_getHFAType; - callbacks[111] = (delegate* unmanaged)&_runWithErrorTrap; - callbacks[112] = (delegate* unmanaged)&_runWithSPMIErrorTrap; - callbacks[113] = (delegate* unmanaged)&_getEEInfo; - callbacks[114] = (delegate* unmanaged)&_getJitTimeLogFilename; - callbacks[115] = (delegate* unmanaged)&_getMethodDefFromMethod; - callbacks[116] = (delegate* unmanaged)&_printMethodName; - callbacks[117] = (delegate* unmanaged)&_getMethodNameFromMetadata; - callbacks[118] = (delegate* unmanaged)&_getMethodHash; - callbacks[119] = (delegate* unmanaged)&_getSystemVAmd64PassStructInRegisterDescriptor; - callbacks[120] = (delegate* unmanaged)&_getLoongArch64PassStructInRegisterFlags; - callbacks[121] = (delegate* unmanaged)&_getRISCV64PassStructInRegisterFlags; - callbacks[122] = (delegate* unmanaged)&_getThreadTLSIndex; - callbacks[123] = (delegate* unmanaged)&_getAddrOfCaptureThreadGlobal; - callbacks[124] = (delegate* unmanaged)&_getHelperFtn; - callbacks[125] = (delegate* unmanaged)&_getFunctionEntryPoint; - callbacks[126] = (delegate* unmanaged)&_getFunctionFixedEntryPoint; - callbacks[127] = (delegate* unmanaged)&_getMethodSync; - callbacks[128] = (delegate* unmanaged)&_getLazyStringLiteralHelper; - callbacks[129] = (delegate* unmanaged)&_embedModuleHandle; - callbacks[130] = (delegate* unmanaged)&_embedClassHandle; - callbacks[131] = (delegate* unmanaged)&_embedMethodHandle; - callbacks[132] = (delegate* unmanaged)&_embedFieldHandle; - callbacks[133] = (delegate* unmanaged)&_embedGenericHandle; - callbacks[134] = (delegate* unmanaged)&_getLocationOfThisType; - callbacks[135] = (delegate* unmanaged)&_getAddressOfPInvokeTarget; - callbacks[136] = (delegate* unmanaged)&_GetCookieForPInvokeCalliSig; - callbacks[137] = (delegate* unmanaged)&_canGetCookieForPInvokeCalliSig; - callbacks[138] = (delegate* unmanaged)&_getJustMyCodeHandle; - callbacks[139] = (delegate* unmanaged)&_GetProfilingHandle; - callbacks[140] = (delegate* unmanaged)&_getCallInfo; - callbacks[141] = (delegate* unmanaged)&_getClassDomainID; - callbacks[142] = (delegate* unmanaged)&_getStaticFieldContent; - callbacks[143] = (delegate* unmanaged)&_getObjectContent; - callbacks[144] = (delegate* unmanaged)&_getStaticFieldCurrentClass; - callbacks[145] = (delegate* unmanaged)&_getVarArgsHandle; - callbacks[146] = (delegate* unmanaged)&_canGetVarArgsHandle; - callbacks[147] = (delegate* unmanaged)&_constructStringLiteral; - callbacks[148] = (delegate* unmanaged)&_emptyStringLiteral; - callbacks[149] = (delegate* unmanaged)&_getFieldThreadLocalStoreID; - callbacks[150] = (delegate* unmanaged)&_GetDelegateCtor; - callbacks[151] = (delegate* unmanaged)&_MethodCompileComplete; - callbacks[152] = (delegate* unmanaged)&_getTailCallHelpers; - callbacks[153] = (delegate* unmanaged)&_convertPInvokeCalliToCall; - callbacks[154] = (delegate* unmanaged)&_notifyInstructionSetUsage; - callbacks[155] = (delegate* unmanaged)&_updateEntryPointForTailCall; - callbacks[156] = (delegate* unmanaged)&_allocMem; - callbacks[157] = (delegate* unmanaged)&_reserveUnwindInfo; - callbacks[158] = (delegate* unmanaged)&_allocUnwindInfo; - callbacks[159] = (delegate* unmanaged)&_allocGCInfo; - callbacks[160] = (delegate* unmanaged)&_setEHcount; - callbacks[161] = (delegate* unmanaged)&_setEHinfo; - callbacks[162] = (delegate* unmanaged)&_logMsg; - callbacks[163] = (delegate* unmanaged)&_doAssert; - callbacks[164] = (delegate* unmanaged)&_reportFatalError; - callbacks[165] = (delegate* unmanaged)&_getPgoInstrumentationResults; - callbacks[166] = (delegate* unmanaged)&_allocPgoInstrumentationBySchema; - callbacks[167] = (delegate* unmanaged)&_recordCallSite; - callbacks[168] = (delegate* unmanaged)&_recordRelocation; - callbacks[169] = (delegate* unmanaged)&_getRelocTypeHint; - callbacks[170] = (delegate* unmanaged)&_getExpectedTargetArchitecture; - callbacks[171] = (delegate* unmanaged)&_getJitFlags; + callbacks[95] = (delegate* unmanaged)&_getTlsIndexInfo; + callbacks[96] = (delegate* unmanaged)&_getThreadStaticBaseSlowInfo; + callbacks[97] = (delegate* unmanaged)&_getEnsureClassCtorRunAndReturnThreadStaticBaseHelper; + callbacks[98] = (delegate* unmanaged)&_isFieldStatic; + callbacks[99] = (delegate* unmanaged)&_getArrayOrStringLength; + callbacks[100] = (delegate* unmanaged)&_getBoundaries; + callbacks[101] = (delegate* unmanaged)&_setBoundaries; + callbacks[102] = (delegate* unmanaged)&_getVars; + callbacks[103] = (delegate* unmanaged)&_setVars; + callbacks[104] = (delegate* unmanaged)&_reportRichMappings; + callbacks[105] = (delegate* unmanaged)&_allocateArray; + callbacks[106] = (delegate* unmanaged)&_freeArray; + callbacks[107] = (delegate* unmanaged)&_getArgNext; + callbacks[108] = (delegate* unmanaged)&_getArgType; + callbacks[109] = (delegate* unmanaged)&_getExactClasses; + callbacks[110] = (delegate* unmanaged)&_getArgClass; + callbacks[111] = (delegate* unmanaged)&_getHFAType; + callbacks[112] = (delegate* unmanaged)&_runWithErrorTrap; + callbacks[113] = (delegate* unmanaged)&_runWithSPMIErrorTrap; + callbacks[114] = (delegate* unmanaged)&_getEEInfo; + callbacks[115] = (delegate* unmanaged)&_getJitTimeLogFilename; + callbacks[116] = (delegate* unmanaged)&_getMethodDefFromMethod; + callbacks[117] = (delegate* unmanaged)&_printMethodName; + callbacks[118] = (delegate* unmanaged)&_getMethodNameFromMetadata; + callbacks[119] = (delegate* unmanaged)&_getMethodHash; + callbacks[120] = (delegate* unmanaged)&_getSystemVAmd64PassStructInRegisterDescriptor; + callbacks[121] = (delegate* unmanaged)&_getLoongArch64PassStructInRegisterFlags; + callbacks[122] = (delegate* unmanaged)&_getRISCV64PassStructInRegisterFlags; + callbacks[123] = (delegate* unmanaged)&_getThreadTLSIndex; + callbacks[124] = (delegate* unmanaged)&_getAddrOfCaptureThreadGlobal; + callbacks[125] = (delegate* unmanaged)&_getHelperFtn; + callbacks[126] = (delegate* unmanaged)&_getFunctionEntryPoint; + callbacks[127] = (delegate* unmanaged)&_getFunctionFixedEntryPoint; + callbacks[128] = (delegate* unmanaged)&_getMethodSync; + callbacks[129] = (delegate* unmanaged)&_getLazyStringLiteralHelper; + callbacks[130] = (delegate* unmanaged)&_embedModuleHandle; + callbacks[131] = (delegate* unmanaged)&_embedClassHandle; + callbacks[132] = (delegate* unmanaged)&_embedMethodHandle; + callbacks[133] = (delegate* unmanaged)&_embedFieldHandle; + callbacks[134] = (delegate* unmanaged)&_embedGenericHandle; + callbacks[135] = (delegate* unmanaged)&_getLocationOfThisType; + callbacks[136] = (delegate* unmanaged)&_getAddressOfPInvokeTarget; + callbacks[137] = (delegate* unmanaged)&_GetCookieForPInvokeCalliSig; + callbacks[138] = (delegate* unmanaged)&_canGetCookieForPInvokeCalliSig; + callbacks[139] = (delegate* unmanaged)&_getJustMyCodeHandle; + callbacks[140] = (delegate* unmanaged)&_GetProfilingHandle; + callbacks[141] = (delegate* unmanaged)&_getCallInfo; + callbacks[142] = (delegate* unmanaged)&_getClassDomainID; + callbacks[143] = (delegate* unmanaged)&_getStaticFieldContent; + callbacks[144] = (delegate* unmanaged)&_getObjectContent; + callbacks[145] = (delegate* unmanaged)&_getStaticFieldCurrentClass; + callbacks[146] = (delegate* unmanaged)&_getVarArgsHandle; + callbacks[147] = (delegate* unmanaged)&_canGetVarArgsHandle; + callbacks[148] = (delegate* unmanaged)&_constructStringLiteral; + callbacks[149] = (delegate* unmanaged)&_emptyStringLiteral; + callbacks[150] = (delegate* unmanaged)&_getFieldThreadLocalStoreID; + callbacks[151] = (delegate* unmanaged)&_GetDelegateCtor; + callbacks[152] = (delegate* unmanaged)&_MethodCompileComplete; + callbacks[153] = (delegate* unmanaged)&_getTailCallHelpers; + callbacks[154] = (delegate* unmanaged)&_convertPInvokeCalliToCall; + callbacks[155] = (delegate* unmanaged)&_notifyInstructionSetUsage; + callbacks[156] = (delegate* unmanaged)&_updateEntryPointForTailCall; + callbacks[157] = (delegate* unmanaged)&_allocMem; + callbacks[158] = (delegate* unmanaged)&_reserveUnwindInfo; + callbacks[159] = (delegate* unmanaged)&_allocUnwindInfo; + callbacks[160] = (delegate* unmanaged)&_allocGCInfo; + callbacks[161] = (delegate* unmanaged)&_setEHcount; + callbacks[162] = (delegate* unmanaged)&_setEHinfo; + callbacks[163] = (delegate* unmanaged)&_logMsg; + callbacks[164] = (delegate* unmanaged)&_doAssert; + callbacks[165] = (delegate* unmanaged)&_reportFatalError; + callbacks[166] = (delegate* unmanaged)&_getPgoInstrumentationResults; + callbacks[167] = (delegate* unmanaged)&_allocPgoInstrumentationBySchema; + callbacks[168] = (delegate* unmanaged)&_recordCallSite; + callbacks[169] = (delegate* unmanaged)&_recordRelocation; + callbacks[170] = (delegate* unmanaged)&_getRelocTypeHint; + callbacks[171] = (delegate* unmanaged)&_getExpectedTargetArchitecture; + callbacks[172] = (delegate* unmanaged)&_getJitFlags; return (IntPtr)callbacks; } diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs b/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs index 9e274fa9407e73..1f46f7e317ac57 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs @@ -1157,7 +1157,6 @@ public unsafe struct CORINFO_THREAD_STATIC_BLOCKS_INFO public uint offsetOfMaxThreadStaticBlocks; public uint offsetOfThreadStaticBlocks; public uint offsetOfGCDataPointer; - public CORINFO_CONST_LOOKUP tlsRoot; }; // System V struct passing diff --git a/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt b/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt index 5f28100deae1f2..c0b9ee36c76b68 100644 --- a/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt +++ b/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt @@ -256,6 +256,7 @@ FUNCTIONS uint32_t getThreadLocalFieldInfo (CORINFO_FIELD_HANDLE field, bool isGCtype) void getThreadLocalStaticBlocksInfo (CORINFO_THREAD_STATIC_BLOCKS_INFO* pInfo, bool isGCType) void getTlsRootInfo(CORINFO_CONST_LOOKUP* addr) + void getTlsIndexInfo(CORINFO_CONST_LOOKUP* addr) void getThreadStaticBaseSlowInfo(CORINFO_CONST_LOOKUP* addr) int getEnsureClassCtorRunAndReturnThreadStaticBaseHelper(CORINFO_CLASS_HANDLE cls, CORINFO_CONST_LOOKUP* addr, CORINFO_CONST_LOOKUP* targetSymbol) bool isFieldStatic(CORINFO_FIELD_HANDLE fldHnd) diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ILScanner.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ILScanner.cs index 46b4727d7647c6..abbf0663c34502 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ILScanner.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/ILScanner.cs @@ -726,7 +726,7 @@ public ScannedInlinedThreadStatics(NodeFactory factory, ImmutableArrayoffsetOfThreadLocalStoragePointer = 0x58; - pInfo->tlsIndex = CreateConstLookupToSymbol(_compilation.NodeFactory.ExternSymbol("_tls_index")); - pInfo->tlsRoot = CreateConstLookupToSymbol(_compilation.NodeFactory.TlsRoot); + //pInfo->tlsIndex = CreateConstLookupToSymbol(_compilation.NodeFactory.ExternSymbol("_tls_index")); // Implemented for JIT only for now. } diff --git a/src/coreclr/tools/aot/jitinterface/jitinterface_generated.h b/src/coreclr/tools/aot/jitinterface/jitinterface_generated.h index cb0cfba12a4020..b41972f2d0020a 100644 --- a/src/coreclr/tools/aot/jitinterface/jitinterface_generated.h +++ b/src/coreclr/tools/aot/jitinterface/jitinterface_generated.h @@ -106,6 +106,7 @@ struct JitInterfaceCallbacks uint32_t (* getThreadLocalFieldInfo)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_FIELD_HANDLE field, bool isGCtype); void (* getThreadLocalStaticBlocksInfo)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_THREAD_STATIC_BLOCKS_INFO* pInfo, bool isGCType); void (* getTlsRootInfo)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_CONST_LOOKUP* addr); + void (* getTlsIndexInfo)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_CONST_LOOKUP* addr); void (* getThreadStaticBaseSlowInfo)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_CONST_LOOKUP* addr); int (* getEnsureClassCtorRunAndReturnThreadStaticBaseHelper)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_CLASS_HANDLE cls, CORINFO_CONST_LOOKUP* addr, CORINFO_CONST_LOOKUP* targetSymbol); bool (* isFieldStatic)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_FIELD_HANDLE fldHnd); @@ -1126,6 +1127,14 @@ class JitInterfaceWrapper : public ICorJitInfo if (pException != nullptr) throw pException; } + virtual void getTlsIndexInfo( + CORINFO_CONST_LOOKUP* addr) +{ + CorInfoExceptionClass* pException = nullptr; + _callbacks->getTlsIndexInfo(_thisHandle, &pException, addr); + if (pException != nullptr) throw pException; +} + virtual void getThreadStaticBaseSlowInfo( CORINFO_CONST_LOOKUP* addr) { diff --git a/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo_generated.cpp b/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo_generated.cpp index 25befc051523a1..e34863c6a91be0 100644 --- a/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo_generated.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo_generated.cpp @@ -770,6 +770,13 @@ void interceptor_ICJI::getTlsRootInfo( original_ICorJitInfo->getTlsRootInfo(addr); } +void interceptor_ICJI::getTlsIndexInfo( + CORINFO_CONST_LOOKUP* addr) +{ + mcs->AddCall("getTlsIndexInfo"); + original_ICorJitInfo->getTlsIndexInfo(addr); +} + void interceptor_ICJI::getThreadStaticBaseSlowInfo( CORINFO_CONST_LOOKUP* addr) { diff --git a/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo_generated.cpp b/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo_generated.cpp index 577fe3286943b0..d8af9047645d2c 100644 --- a/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo_generated.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo_generated.cpp @@ -675,6 +675,12 @@ void interceptor_ICJI::getTlsRootInfo( original_ICorJitInfo->getTlsRootInfo(addr); } +void interceptor_ICJI::getTlsIndexInfo( + CORINFO_CONST_LOOKUP* addr) +{ + original_ICorJitInfo->getTlsIndexInfo(addr); +} + void interceptor_ICJI::getThreadStaticBaseSlowInfo( CORINFO_CONST_LOOKUP* addr) { From 87c3f2541330e0b3c498900ad06b494722f235ee Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Tue, 25 Jul 2023 12:22:56 -0700 Subject: [PATCH 07/58] add methods in superpmi --- src/coreclr/inc/corinfo.h | 1 - src/coreclr/inc/jiteeversionguid.h | 10 +- .../JitInterface/CorInfoImpl.ReadyToRun.cs | 11 +- .../JitInterface/CorInfoImpl.RyuJit.cs | 1 - .../tools/superpmi/superpmi-shared/agnostic.h | 7 ++ .../tools/superpmi/superpmi-shared/lwmlist.h | 4 + .../superpmi-shared/methodcontext.cpp | 118 ++++++++++++++++++ .../superpmi/superpmi-shared/methodcontext.h | 31 ++++- .../superpmi-shim-collector/icorjitinfo.cpp | 31 +++++ .../tools/superpmi/superpmi/icorjitinfo.cpp | 26 ++++ src/coreclr/vm/jitinterface.cpp | 25 ++++ 11 files changed, 252 insertions(+), 13 deletions(-) diff --git a/src/coreclr/inc/corinfo.h b/src/coreclr/inc/corinfo.h index 0f5ac096ad2a28..3ace977b2f5e36 100644 --- a/src/coreclr/inc/corinfo.h +++ b/src/coreclr/inc/corinfo.h @@ -2790,7 +2790,6 @@ class ICorStaticInfo bool isGCType ) = 0; - //TODO: Rename the method names to get*Helper virtual void getTlsRootInfo(CORINFO_CONST_LOOKUP* addr) = 0; virtual void getTlsIndexInfo(CORINFO_CONST_LOOKUP* addr) = 0; virtual void getThreadStaticBaseSlowInfo(CORINFO_CONST_LOOKUP* addr) = 0; diff --git a/src/coreclr/inc/jiteeversionguid.h b/src/coreclr/inc/jiteeversionguid.h index bcd85a573d69bc..120605440d5b5c 100644 --- a/src/coreclr/inc/jiteeversionguid.h +++ b/src/coreclr/inc/jiteeversionguid.h @@ -43,11 +43,11 @@ typedef const GUID *LPCGUID; #define GUID_DEFINED #endif // !GUID_DEFINED -constexpr GUID JITEEVersionIdentifier = { /* cef79bc8-29bf-4f7b-9d05-9fc06832098c */ - 0xcef79bc8, - 0x29bf, - 0x4f7b, - {0x9d, 0x05, 0x9f, 0xc0, 0x68, 0x32, 0x09, 0x8c} +constexpr GUID JITEEVersionIdentifier = { /* ae2c23aa-c919-44b9-a1b8-bed99aad9d20 */ + 0xae2c23aa, + 0xc919, + 0x44b9, + {0xa1, 0xb8, 0xbe, 0xd9, 0x9a, 0xad, 0x9d, 0x20} }; ////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs index 7e5d95b0ca5c98..3c9a6465e01671 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs @@ -3239,17 +3239,22 @@ private void getThreadLocalStaticBlocksInfo(CORINFO_THREAD_STATIC_BLOCKS_INFO* p private void getTlsRootInfo(ref CORINFO_CONST_LOOKUP addr) { - // Implemented for JIT and NativeAOT only for now. + // Implemented for NativeAOT only for now. + } + + private void getTlsIndexInfo(ref CORINFO_CONST_LOOKUP addr) + { + // Implemented for NativeAOT only for now. } private void getThreadStaticBaseSlowInfo(ref CORINFO_CONST_LOOKUP addr) { - // Implemented for JIT and NativeAOT only for now. + // Implemented for NativeAOT only for now. } private int getEnsureClassCtorRunAndReturnThreadStaticBaseHelper(CORINFO_CLASS_STRUCT_* cls, ref CORINFO_CONST_LOOKUP addr, ref CORINFO_CONST_LOOKUP targetSymbol) { - // Implemented for JIT and NativeAOT only for now. + // Implemented for NativeAOT only for now. return 0; } #pragma warning restore CA1822 // Mark members as static diff --git a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs index 170905154cc394..7691e5ffc3a397 100644 --- a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs +++ b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs @@ -2440,7 +2440,6 @@ private void getThreadStaticBaseSlowInfo(ref CORINFO_CONST_LOOKUP addr) private void getThreadLocalStaticBlocksInfo(CORINFO_THREAD_STATIC_BLOCKS_INFO* pInfo, bool isGCType) { pInfo->offsetOfThreadLocalStoragePointer = 0x58; - //pInfo->tlsIndex = CreateConstLookupToSymbol(_compilation.NodeFactory.ExternSymbol("_tls_index")); // Implemented for JIT only for now. } diff --git a/src/coreclr/tools/superpmi/superpmi-shared/agnostic.h b/src/coreclr/tools/superpmi/superpmi-shared/agnostic.h index b4cdb272b32091..d5e596f667b308 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/agnostic.h +++ b/src/coreclr/tools/superpmi/superpmi-shared/agnostic.h @@ -539,6 +539,13 @@ struct Agnostic_GetThreadLocalStaticBlocksInfo DWORD offsetOfGCDataPointer; }; +struct Agnostic_GetClassCtorInitializationInfo +{ + Agnostic_CORINFO_CONST_LOOKUP addr; + Agnostic_CORINFO_CONST_LOOKUP targetAddr; + int size; +}; + struct Agnostic_GetThreadLocalFieldInfo { DWORD staticBlockIndex; diff --git a/src/coreclr/tools/superpmi/superpmi-shared/lwmlist.h b/src/coreclr/tools/superpmi/superpmi-shared/lwmlist.h index 6c6bbed9bd9650..1d8f2869a06d98 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/lwmlist.h +++ b/src/coreclr/tools/superpmi/superpmi-shared/lwmlist.h @@ -39,6 +39,10 @@ LWM(EmbedMethodHandle, DWORDLONG, DLDL) LWM(EmbedModuleHandle, DWORDLONG, DLDL) LWM(GetThreadLocalFieldInfo, DLD, DWORD) LWM(GetThreadLocalStaticBlocksInfo, DWORD, Agnostic_GetThreadLocalStaticBlocksInfo) +LWM(GetTlsRootInfo, DWORD, Agnostic_CORINFO_CONST_LOOKUP) +LWM(GetTlsIndexInfo, DWORD, Agnostic_CORINFO_CONST_LOOKUP) +LWM(GetThreadStaticBaseSlowInfo, DWORD, Agnostic_CORINFO_CONST_LOOKUP) +LWM(GetEnsureClassCtorRunAndReturnThreadStaticBaseHelper, DWORDLONG, Agnostic_GetClassCtorInitializationInfo) DENSELWM(EmptyStringLiteral, DLD) DENSELWM(ErrorList, DWORD) LWM(FindCallSiteSig, Agnostic_FindCallSiteSig, Agnostic_CORINFO_SIG_INFO) diff --git a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp index ad0f2c7dd6dae3..963bd4b16c0f9d 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp @@ -3570,6 +3570,124 @@ uint32_t MethodContext::repGetThreadLocalFieldInfo(CORINFO_FIELD_HANDLE field, b return value; } +void MethodContext::recGetTlsRootInfo(CORINFO_CONST_LOOKUP* result) +{ + if (GetTlsRootInfo == nullptr) + GetTlsRootInfo = new LightWeightMap(); + + DWORD key = 0; + Agnostic_CORINFO_CONST_LOOKUP value = SpmiRecordsHelper::StoreAgnostic_CORINFO_CONST_LOOKUP(result); + GetTlsRootInfo->Add(key, value); + DEBUG_REC(dmpGetTlsRootInfo(key, result)); +} + +void MethodContext::dmpGetTlsRootInfo(DWORD key, const Agnostic_CORINFO_CONST_LOOKUP& value) +{ + printf("GetTlsRootInfo key %u, result-%s", key, SpmiDumpHelper::DumpAgnostic_CORINFO_CONST_LOOKUP(value).c_str()); +} +void MethodContext::repGetTlsRootInfo(CORINFO_CONST_LOOKUP* result) +{ + DWORD key = 0; + Agnostic_CORINFO_CONST_LOOKUP value = LookupByKeyOrMiss(GetTlsRootInfo, key, ": key 0"); + + DEBUG_REP(dmpGetTlsRootInfo(key, value)); + + *result = SpmiRecordsHelper::RestoreCORINFO_CONST_LOOKUP(value); +} + +void MethodContext::recGetTlsIndexInfo(CORINFO_CONST_LOOKUP* result) +{ + if (GetTlsIndexInfo == nullptr) + GetTlsIndexInfo = new LightWeightMap(); + + DWORD key = 0; + Agnostic_CORINFO_CONST_LOOKUP value = SpmiRecordsHelper::StoreAgnostic_CORINFO_CONST_LOOKUP(result); + GetTlsIndexInfo->Add(key, value); + DEBUG_REC(dmpGetTlsIndexInfo(key, result)); +} + +void MethodContext::dmpGetTlsIndexInfo(DWORD key, const Agnostic_CORINFO_CONST_LOOKUP& value) +{ + printf("GetTlsIndexInfo key %u, result-%s", key, SpmiDumpHelper::DumpAgnostic_CORINFO_CONST_LOOKUP(value).c_str()); +} +void MethodContext::repGetTlsIndexInfo(CORINFO_CONST_LOOKUP* result) +{ + DWORD key = 0; + Agnostic_CORINFO_CONST_LOOKUP value = LookupByKeyOrMiss(GetTlsIndexInfo, key, ": key 0"); + + DEBUG_REP(dmpGetTlsIndexInfo(key, value)); + + *result = SpmiRecordsHelper::RestoreCORINFO_CONST_LOOKUP(value); +} + +void MethodContext::recGetThreadStaticBaseSlowInfo(CORINFO_CONST_LOOKUP* result) +{ + if (GetThreadStaticBaseSlowInfo == nullptr) + GetThreadStaticBaseSlowInfo = new LightWeightMap(); + + DWORD key = 0; + Agnostic_CORINFO_CONST_LOOKUP value = SpmiRecordsHelper::StoreAgnostic_CORINFO_CONST_LOOKUP(result); + GetThreadStaticBaseSlowInfo->Add(key, value); + DEBUG_REC(dmpGetThreadStaticBaseSlowInfo(key, result)); +} + +void MethodContext::dmpGetThreadStaticBaseSlowInfo(DWORD key, const Agnostic_CORINFO_CONST_LOOKUP& value) +{ + printf("GetThreadStaticBaseSlowInfo key %u, result-%s", key, SpmiDumpHelper::DumpAgnostic_CORINFO_CONST_LOOKUP(value).c_str()); +} + +void MethodContext::repGetThreadStaticBaseSlowInfo(CORINFO_CONST_LOOKUP* result) +{ + DWORD key = 0; + Agnostic_CORINFO_CONST_LOOKUP value = LookupByKeyOrMiss(GetThreadStaticBaseSlowInfo, key, ": key 0"); + + DEBUG_REP(dmpGetThreadStaticBaseSlowInfo(key, value)); + + *result = SpmiRecordsHelper::RestoreCORINFO_CONST_LOOKUP(value); +} + +void MethodContext::recGetEnsureClassCtorRunAndReturnThreadStaticBaseHelper(CORINFO_CLASS_HANDLE cls, CORINFO_CONST_LOOKUP* addr, CORINFO_CONST_LOOKUP* targetSymbol, int size) +{ + if (GetEnsureClassCtorRunAndReturnThreadStaticBaseHelper == nullptr) + GetEnsureClassCtorRunAndReturnThreadStaticBaseHelper = new LightWeightMap(); + + Agnostic_GetClassCtorInitializationInfo value; + ZeroMemory(&value, sizeof(value)); + value.addr = SpmiRecordsHelper::StoreAgnostic_CORINFO_CONST_LOOKUP(addr); + value.targetAddr = SpmiRecordsHelper::StoreAgnostic_CORINFO_CONST_LOOKUP(targetSymbol); + value.size = size; + + DWORDLONG key = CastHandle(cls); + + GetEnsureClassCtorRunAndReturnThreadStaticBaseHelper->Add(key, value); + DEBUG_REC(dmpGetEnsureClassCtorRunAndReturnThreadStaticBaseHelper(key, result)); +} + +void MethodContext::dmpGetEnsureClassCtorRunAndReturnThreadStaticBaseHelper( + DWORDLONG key, + const Agnostic_GetClassCtorInitializationInfo& value) +{ + printf("GetEnsureClassCtorRunAndReturnThreadStaticBaseHelper key %016" PRIX64 ", addr-%s, targetAddr-%s, size-%d", key, + SpmiDumpHelper::DumpAgnostic_CORINFO_CONST_LOOKUP(value.addr).c_str(), + SpmiDumpHelper::DumpAgnostic_CORINFO_CONST_LOOKUP(value.targetAddr).c_str(), value.size); +} + +int MethodContext::repGetEnsureClassCtorRunAndReturnThreadStaticBaseHelper(CORINFO_CLASS_HANDLE cls, + CORINFO_CONST_LOOKUP* addr, + CORINFO_CONST_LOOKUP* targetSymbol) +{ + DWORDLONG key = CastHandle(cls); + Agnostic_GetClassCtorInitializationInfo value = + LookupByKeyOrMiss(GetEnsureClassCtorRunAndReturnThreadStaticBaseHelper, key, ": key %016" PRIX64 "", key); + + DEBUG_REP(dmpGetEnsureClassCtorRunAndReturnThreadStaticBaseHelper(key, value)); + + *addr = SpmiRecordsHelper::RestoreCORINFO_CONST_LOOKUP(value.addr); + *targetSymbol = SpmiRecordsHelper::RestoreCORINFO_CONST_LOOKUP(value.targetAddr); + + return value.size; +} + void MethodContext::recGetThreadLocalStaticBlocksInfo(CORINFO_THREAD_STATIC_BLOCKS_INFO* pInfo, bool isGCType) { if (GetThreadLocalStaticBlocksInfo == nullptr) diff --git a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h index 63c2f0191c3d99..0b53346b58cf01 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h +++ b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h @@ -474,6 +474,27 @@ class MethodContext void dmpGetThreadLocalStaticBlocksInfo(DWORD key, const Agnostic_GetThreadLocalStaticBlocksInfo& value); void repGetThreadLocalStaticBlocksInfo(CORINFO_THREAD_STATIC_BLOCKS_INFO* pInfo, bool isGCType); + void recGetTlsRootInfo(CORINFO_CONST_LOOKUP* result); + void dmpGetTlsRootInfo(DWORD key, const Agnostic_CORINFO_CONST_LOOKUP& value); + void repGetTlsRootInfo(CORINFO_CONST_LOOKUP* addr); + + void recGetTlsIndexInfo(CORINFO_CONST_LOOKUP* addr); + void dmpGetTlsIndexInfo(DWORD key, const Agnostic_CORINFO_CONST_LOOKUP& value); + void repGetTlsIndexInfo(CORINFO_CONST_LOOKUP* addr); + + void recGetThreadStaticBaseSlowInfo(CORINFO_CONST_LOOKUP* addr); + void dmpGetThreadStaticBaseSlowInfo(DWORD key, const Agnostic_CORINFO_CONST_LOOKUP& value); + void repGetThreadStaticBaseSlowInfo(CORINFO_CONST_LOOKUP* addr); + + void recGetEnsureClassCtorRunAndReturnThreadStaticBaseHelper(CORINFO_CLASS_HANDLE cls, + CORINFO_CONST_LOOKUP* addr, + CORINFO_CONST_LOOKUP* targetSymbol, int pSize); + void dmpGetEnsureClassCtorRunAndReturnThreadStaticBaseHelper(DWORDLONG key, + const Agnostic_GetClassCtorInitializationInfo& value); + int repGetEnsureClassCtorRunAndReturnThreadStaticBaseHelper(CORINFO_CLASS_HANDLE cls, + CORINFO_CONST_LOOKUP* addr, + CORINFO_CONST_LOOKUP* targetSymbol); + void recEmbedMethodHandle(CORINFO_METHOD_HANDLE handle, void** ppIndirection, CORINFO_METHOD_HANDLE result); void dmpEmbedMethodHandle(DWORDLONG key, DLDL value); CORINFO_METHOD_HANDLE repEmbedMethodHandle(CORINFO_METHOD_HANDLE handle, void** ppIndirection); @@ -1130,9 +1151,13 @@ enum mcPackets Packet_GetStaticBaseAddress = 206, Packet_GetThreadLocalFieldInfo = 207, Packet_GetThreadLocalStaticBlocksInfo = 208, - Packet_GetRISCV64PassStructInRegisterFlags = 209, - Packet_GetObjectContent = 210, - Packet_GetTypeLayout = 211, + Packet_GetTlsRootInfo = 209, + Packet_GetTlsIndexInfo = 210, + Packet_GetThreadStaticBaseSlowInfo = 211, + Packet_GetEnsureClassCtorRunAndReturnThreadStaticBaseHelper = 212, + Packet_GetRISCV64PassStructInRegisterFlags = 213, + Packet_GetObjectContent = 214, + Packet_GetTypeLayout = 215, }; void SetDebugDumpVariables(); diff --git a/src/coreclr/tools/superpmi/superpmi-shim-collector/icorjitinfo.cpp b/src/coreclr/tools/superpmi/superpmi-shim-collector/icorjitinfo.cpp index 48790166a53ebc..1d8874a71dda2f 100644 --- a/src/coreclr/tools/superpmi/superpmi-shim-collector/icorjitinfo.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shim-collector/icorjitinfo.cpp @@ -1047,6 +1047,37 @@ void interceptor_ICJI::getThreadLocalStaticBlocksInfo(CORINFO_THREAD_STATIC_BLOC mc->recGetThreadLocalStaticBlocksInfo(pInfo, isGCType); } +void interceptor_ICJI::getTlsRootInfo(CORINFO_CONST_LOOKUP* pInfo) +{ + mc->cr->AddCall("getTlsRootInfo"); + original_ICorJitInfo->getTlsRootInfo(pInfo); + mc->recGetTlsRootInfo(pInfo); +} + +void interceptor_ICJI::getTlsIndexInfo(CORINFO_CONST_LOOKUP* pInfo) +{ + mc->cr->AddCall("getTlsIndexInfo"); + original_ICorJitInfo->getTlsIndexInfo(pInfo); + mc->recGetTlsIndexInfo(pInfo); +} + +void interceptor_ICJI::getThreadStaticBaseSlowInfo(CORINFO_CONST_LOOKUP* pInfo) +{ + mc->cr->AddCall("getThreadStaticBaseSlowInfo"); + original_ICorJitInfo->getThreadStaticBaseSlowInfo(pInfo); + mc->repGetThreadStaticBaseSlowInfo(pInfo); +} + +int interceptor_ICJI::getEnsureClassCtorRunAndReturnThreadStaticBaseHelper(CORINFO_CLASS_HANDLE cls, + CORINFO_CONST_LOOKUP* addr, + CORINFO_CONST_LOOKUP* targetSymbol) +{ + mc->cr->AddCall("getEnsureClassCtorRunAndReturnThreadStaticBaseHelper"); + int result = original_ICorJitInfo->getEnsureClassCtorRunAndReturnThreadStaticBaseHelper(cls, addr, targetSymbol); + mc->recGetEnsureClassCtorRunAndReturnThreadStaticBaseHelper(cls, addr, targetSymbol, result); + return result; +} + // Returns true iff "fldHnd" represents a static field. bool interceptor_ICJI::isFieldStatic(CORINFO_FIELD_HANDLE fldHnd) { diff --git a/src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp b/src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp index f8f84b24cd6cd0..8be3dbeb13de2e 100644 --- a/src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp +++ b/src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp @@ -878,6 +878,32 @@ void MyICJI::getThreadLocalStaticBlocksInfo(CORINFO_THREAD_STATIC_BLOCKS_INFO* p jitInstance->mc->repGetThreadLocalStaticBlocksInfo(pInfo, isGCType); } +void MyICJI::getTlsRootInfo(CORINFO_CONST_LOOKUP* pInfo) +{ + jitInstance->mc->cr->AddCall("getTlsRootInfo"); + jitInstance->mc->repGetTlsRootInfo(pInfo); +} + +void MyICJI::getTlsIndexInfo(CORINFO_CONST_LOOKUP* pInfo) +{ + jitInstance->mc->cr->AddCall("getTlsIndexInfo"); + jitInstance->mc->repGetTlsIndexInfo(pInfo); +} + +void MyICJI::getThreadStaticBaseSlowInfo(CORINFO_CONST_LOOKUP* pInfo) +{ + jitInstance->mc->cr->AddCall("getThreadStaticBaseSlowInfo"); + jitInstance->mc->repGetThreadStaticBaseSlowInfo(pInfo); +} + +int MyICJI::getEnsureClassCtorRunAndReturnThreadStaticBaseHelper(CORINFO_CLASS_HANDLE cls, + CORINFO_CONST_LOOKUP* addr, + CORINFO_CONST_LOOKUP* targetSymbol) +{ + jitInstance->mc->cr->AddCall("getEnsureClassCtorRunAndReturnThreadStaticBaseHelper"); + return jitInstance->mc->repGetEnsureClassCtorRunAndReturnThreadStaticBaseHelper(cls, addr, targetSymbol); +} + // Returns true iff "fldHnd" represents a static field. bool MyICJI::isFieldStatic(CORINFO_FIELD_HANDLE fldHnd) { diff --git a/src/coreclr/vm/jitinterface.cpp b/src/coreclr/vm/jitinterface.cpp index b7dcf9eacd88ef..cedc54c220a73a 100644 --- a/src/coreclr/vm/jitinterface.cpp +++ b/src/coreclr/vm/jitinterface.cpp @@ -1308,6 +1308,31 @@ static CorInfoHelpFunc getInstanceFieldHelper(FieldDesc * pField, CORINFO_ACCESS /*********************************************************************/ + +void CEEInfo::getTlsRootInfo(CORINFO_CONST_LOOKUP* addr) +{ + LIMITED_METHOD_CONTRACT; + UNREACHABLE(); // only called with NativeAOT. +} +void CEEInfo::getTlsIndexInfo(CORINFO_CONST_LOOKUP* addr) +{ + LIMITED_METHOD_CONTRACT; + UNREACHABLE(); // only called with NativeAOT. +} + +void CEEInfo::getThreadStaticBaseSlowInfo(CORINFO_CONST_LOOKUP* addr) +{ + LIMITED_METHOD_CONTRACT; + UNREACHABLE(); // only called with NativeAOT. +} + +int CEEInfo::getEnsureClassCtorRunAndReturnThreadStaticBaseHelper(CORINFO_CLASS_HANDLE cls, CORINFO_CONST_LOOKUP* addr, CORINFO_CONST_LOOKUP* targetSymbol) +{ + LIMITED_METHOD_CONTRACT; + UNREACHABLE(); // only called with NativeAOT. + return 0; +} + uint32_t CEEInfo::getThreadLocalFieldInfo (CORINFO_FIELD_HANDLE field, bool isGCType) { CONTRACTL { From fb364a0f6a1a529a52010fd45153e52624c5f17d Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Tue, 25 Jul 2023 12:37:12 -0700 Subject: [PATCH 08/58] revert some local changes --- .../tools/aot/ILCompiler/ILCompiler.csproj | 22 ++- .../tools/aot/ILCompiler/repro/Program.cs | 65 +------- .../tools/aot/ILCompiler/repro/repro.csproj | 3 +- src/coreclr/tools/aot/ilc.sln | 145 ------------------ 4 files changed, 18 insertions(+), 217 deletions(-) diff --git a/src/coreclr/tools/aot/ILCompiler/ILCompiler.csproj b/src/coreclr/tools/aot/ILCompiler/ILCompiler.csproj index 71c94c9dc1b035..564a02b632bfbd 100644 --- a/src/coreclr/tools/aot/ILCompiler/ILCompiler.csproj +++ b/src/coreclr/tools/aot/ILCompiler/ILCompiler.csproj @@ -2,7 +2,6 @@ $(RuntimeBinDir)ilc/ $(PackageRID) - OnOutputUpdated @@ -24,7 +23,9 @@ - + $(RuntimeIdentifier) @@ -45,12 +46,17 @@ - + clang - + @@ -65,11 +71,15 @@ - + - + diff --git a/src/coreclr/tools/aot/ILCompiler/repro/Program.cs b/src/coreclr/tools/aot/ILCompiler/repro/Program.cs index 757256715c2106..9e71394c3732a5 100644 --- a/src/coreclr/tools/aot/ILCompiler/repro/Program.cs +++ b/src/coreclr/tools/aot/ILCompiler/repro/Program.cs @@ -2,74 +2,11 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; -using System.Collections.Generic; -using System.Globalization; -using System.Runtime.CompilerServices; -using System.Threading; -using System.Threading.Tasks; - -class P1 -{ - [ThreadStatic] - public static long z; - //[ThreadStatic] - //public static List list; -} class Program { - [ThreadStatic] - public static uint x; - //[ThreadStatic] - //static string y; - //[ThreadStatic] - //static int z; - //[ThreadStatic] - //static List list; - - static void Main() { - //Program.x = 5; - ////Program.y = "a"; - //Program.list = new List(); - P1.z = 0x900DF00E; - Program.x = 0x900DF00D; - Program obj = new Program(); - obj.Test(1); - //Console.WriteLine("Hello"); - Console.WriteLine(Program.x); - //Console.WriteLine(Program.y); - Console.WriteLine(P1.z); - //Console.WriteLine(Program.x + Program.z | P1.z); - - //Program.z = 15; - - Console.WriteLine(CultureInfo.CurrentCulture); - - Console.WriteLine(Program.x); - Console.WriteLine(P1.z); - //Console.WriteLine(Program.z); - //Console.WriteLine(P1.list); - } - - [MethodImpl(MethodImplOptions.NoInlining)] - static void Test1() { Console.WriteLine("inside task"); } - - [MethodImpl(MethodImplOptions.NoInlining)] - long Test(int n) - { - //for (int i = 0; i < n; i++) - { - //Console.WriteLine(CultureInfo.CurrentCulture); - //Console.WriteLine(CultureInfo.CurrentCulture); - //Console.WriteLine(CultureInfo.CurrentCulture); - Program.x = 0x900DF00D; - //Program.z = 23; - //Program.y = "a"; - //P1.list = new List(); - P1.z = 0x900DF00E; - } - return 0; + Console.WriteLine("Hello world"); } } diff --git a/src/coreclr/tools/aot/ILCompiler/repro/repro.csproj b/src/coreclr/tools/aot/ILCompiler/repro/repro.csproj index 18793b6d98c79a..131ddbd3b22576 100644 --- a/src/coreclr/tools/aot/ILCompiler/repro/repro.csproj +++ b/src/coreclr/tools/aot/ILCompiler/repro/repro.csproj @@ -10,7 +10,6 @@ Debug;Release;Checked true false - true - + Date: Tue, 25 Jul 2023 13:50:24 -0700 Subject: [PATCH 09/58] misc fixes --- src/coreclr/inc/corinfo.h | 2 +- src/coreclr/jit/helperexpansion.cpp | 104 ++++++++---------- src/coreclr/jit/importer.cpp | 2 +- .../src/Internal/Runtime/ThreadStatics.cs | 2 +- .../tools/Common/JitInterface/CorInfoImpl.cs | 7 ++ .../JitInterface/CorInfoImpl.ReadyToRun.cs | 4 - .../JitInterface/CorInfoImpl.RyuJit.cs | 20 +--- 7 files changed, 57 insertions(+), 84 deletions(-) diff --git a/src/coreclr/inc/corinfo.h b/src/coreclr/inc/corinfo.h index 3ace977b2f5e36..7d32378e31028d 100644 --- a/src/coreclr/inc/corinfo.h +++ b/src/coreclr/inc/corinfo.h @@ -1684,7 +1684,7 @@ enum CORINFO_FIELD_ACCESSOR CORINFO_FIELD_STATIC_ADDR_HELPER, // static field accessed using address-of helper (argument is FieldDesc *) CORINFO_FIELD_STATIC_TLS, // unmanaged TLS access CORINFO_FIELD_STATIC_TLS_MANAGED, // managed TLS access - CORINFO_FIELD_STATIC_TLS_MANAGED_LAZY, // managed TLS access lazy + CORINFO_FIELD_STATIC_TLS_MANAGED_LAZY, // managed TLS access lazy ctor initialization CORINFO_FIELD_STATIC_READYTORUN_HELPER, // static field access using a runtime lookup helper CORINFO_FIELD_STATIC_RELOCATABLE, // static field access using relocation (used in AOT) CORINFO_FIELD_INTRINSIC_ZERO, // intrinsic zero (IntPtr.Zero, UIntPtr.Zero) diff --git a/src/coreclr/jit/helperexpansion.cpp b/src/coreclr/jit/helperexpansion.cpp index 67639bb80fff06..ce162d0b15bce3 100644 --- a/src/coreclr/jit/helperexpansion.cpp +++ b/src/coreclr/jit/helperexpansion.cpp @@ -451,39 +451,16 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S { assert(opts.IsReadyToRun()); BasicBlock* block = *pBlock; - assert(call->IsHelperCall()); - if (!(call->IsExpTLSFieldAccess() || call->IsExpTLSFieldAccessLazyCtor())) + if (!call->IsHelperCall() || !(call->IsExpTLSFieldAccess() || call->IsExpTLSFieldAccessLazyCtor())) { return false; } - //if (info.compMethodHashPrivate == 0x2f7ba577) // 0xx009bf64b - //{ - // printf("BEFORE:\n"); - // fgDispBasicBlocks(true); - //} - JITDUMP("Expanding thread static local access for [%06d] in " FMT_BB ":\n", dspTreeID(call), block->bbNum); DISPTREE(call); JITDUMP("\n"); bool hasLazyStaticCtor = call->IsExpTLSFieldAccessLazyCtor(); - CORINFO_THREAD_STATIC_BLOCKS_INFO threadStaticBlocksInfo; - memset(&threadStaticBlocksInfo, 0, sizeof(CORINFO_THREAD_STATIC_BLOCKS_INFO)); - - info.compCompHnd->getThreadLocalStaticBlocksInfo(&threadStaticBlocksInfo, false); - - JITDUMP("getThreadLocalStaticBlocksInfo\n:"); - JITDUMP("tlsIndex= %p\n", dspPtr(threadStaticBlocksInfo.tlsIndex.addr)); - JITDUMP("tlsGetAddrFtnPtr= %p\n", dspPtr(threadStaticBlocksInfo.tlsGetAddrFtnPtr)); - JITDUMP("tlsIndexObject= %p\n", dspPtr(threadStaticBlocksInfo.tlsIndexObject)); - JITDUMP("threadVarsSection= %p\n", dspPtr(threadStaticBlocksInfo.threadVarsSection)); - JITDUMP("offsetOfThreadLocalStoragePointer= %u\n", - dspOffset(threadStaticBlocksInfo.offsetOfThreadLocalStoragePointer)); - JITDUMP("offsetOfMaxThreadStaticBlocks= %u\n", dspOffset(threadStaticBlocksInfo.offsetOfMaxThreadStaticBlocks)); - JITDUMP("offsetOfThreadStaticBlocks= %u\n", dspOffset(threadStaticBlocksInfo.offsetOfThreadStaticBlocks)); - JITDUMP("offsetOfGCDataPointer= %u\n", dspOffset(threadStaticBlocksInfo.offsetOfGCDataPointer)); - call->ClearExpTLSFieldAccess(); call->ClearExpTLSFieldAccessLazyCtor(); @@ -513,7 +490,7 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S // // lazyCtorBlock (BBJ_ALWAYS): [weight: 0] // tlsRoot = HelperCall(0, -1, targetSymbolAddr); - // goto block + // goto block; // // } // tlsRootNullCondBB (BBJ_COND): [weight: 1.0] @@ -532,7 +509,6 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S // block (...): [weight: 1.0] // use(tlsRoot); - if (hasLazyStaticCtor) { CORINFO_CONST_LOOKUP classCtorRunHelper; @@ -540,18 +516,18 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S memset(&classCtorRunHelper, 0, sizeof(CORINFO_CONST_LOOKUP)); memset(&targetSymbol, 0, sizeof(CORINFO_CONST_LOOKUP)); int size = - info.compCompHnd->getEnsureClassCtorRunAndReturnThreadStaticBaseHelper(call->gtInitClsHnd, &classCtorRunHelper, &targetSymbol); + info.compCompHnd->getEnsureClassCtorRunAndReturnThreadStaticBaseHelper(call->gtInitClsHnd, + &classCtorRunHelper, &targetSymbol); // target symbol GenTree* targetSymbolAddr = gtNewIconHandleNode((size_t)targetSymbol.addr, GTF_ICON_OBJ_HDL); targetSymbolAddr = gtNewOperNode(GT_ADD, TYP_I_IMPL, targetSymbolAddr, gtNewIconNode(size, TYP_I_IMPL)); - GenTree* targetSymbolAddrVal = gtNewIndir(TYP_I_IMPL, targetSymbolAddr); - targetSymbCondBB = fgNewBBFromTreeAfter(BBJ_COND, prevBb, gtCloneExpr(targetSymbolAddr), debugInfo); + GenTree* targetSymbolAddrVal = gtNewIndir(TYP_I_IMPL, targetSymbolAddr); GenTree* targetSymbolNullCond = gtNewOperNode(GT_EQ, TYP_INT, targetSymbolAddrVal, gtNewIconNode(0, TYP_I_IMPL)); - targetSymbolNullCond = gtNewOperNode(GT_JTRUE, TYP_VOID, targetSymbolNullCond); + targetSymbolNullCond = gtNewOperNode(GT_JTRUE, TYP_VOID, targetSymbolNullCond); fgInsertStmtAfter(targetSymbCondBB, targetSymbCondBB->firstStmt(), fgNewStmtFromTree(targetSymbolNullCond)); GenTreeCall* classCtorRunHelperCall = @@ -581,13 +557,14 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S // Inherit the weights block->inheritWeight(prevBb); targetSymbCondBB->inheritWeight(prevBb); - + targetSymbCondBB->bbNatLoopNum = prevBb->bbNatLoopNum; lazyCtorBB->bbNatLoopNum = prevBb->bbNatLoopNum; assert(BasicBlock::sameEHRegion(prevBb, targetSymbCondBB)); assert(BasicBlock::sameEHRegion(prevBb, lazyCtorBB)); + // lazyCtorBB is the new previous block going forward prevBb = lazyCtorBB; } @@ -600,22 +577,23 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S newFirstStmt = newFirstStmt->GetNextStmt(); } - GenTree* tlsValue = nullptr; - unsigned tlsLclNum = lvaGrabTemp(true DEBUGARG("TLS access")); - lvaTable[tlsLclNum].lvType = TYP_I_IMPL; - GenTree* maxThreadStaticBlocksValue = nullptr; - GenTree* threadStaticBlocksValue = nullptr; - GenTree* tlsValueDef = nullptr; - if (TargetOS::IsWindows) { -#pragma region block logic +#ifdef TARGET_64BIT + GenTree* tlsValue = nullptr; + unsigned tlsLclNum = lvaGrabTemp(true DEBUGARG("TLS access")); + lvaTable[tlsLclNum].lvType = TYP_I_IMPL; // Mark this ICON as a TLS_HDL, codegen will use FS:[cns] or GS:[cns] - tlsValue = gtNewIconHandleNode(threadStaticBlocksInfo.offsetOfThreadLocalStoragePointer, GTF_ICON_TLS_HDL); + uint32_t offsetOfThreadLocalStoragePointer = offsetof(_TEB, ThreadLocalStoragePointer); + tlsValue = gtNewIconHandleNode(offsetOfThreadLocalStoragePointer, GTF_ICON_TLS_HDL); tlsValue = gtNewIndir(TYP_I_IMPL, tlsValue, GTF_IND_NONFAULTING | GTF_IND_INVARIANT); - GenTree* dllRef = gtNewIconHandleNode((size_t)threadStaticBlocksInfo.tlsIndex.handle, GTF_ICON_OBJ_HDL); + CORINFO_CONST_LOOKUP tlsIndexValue; + memset(&tlsIndexValue, 0, sizeof(CORINFO_CONST_LOOKUP)); + info.compCompHnd->getTlsIndexInfo(&tlsIndexValue); + + GenTree* dllRef = gtNewIconHandleNode((size_t)tlsIndexValue.handle, GTF_ICON_OBJ_HDL); dllRef = gtNewIndir(TYP_UINT, dllRef, GTF_IND_NONFAULTING | GTF_IND_INVARIANT); dllRef = gtNewOperNode(GT_MUL, TYP_I_IMPL, dllRef, gtNewIconNode(TARGET_POINTER_SIZE, TYP_INT)); @@ -625,7 +603,8 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S // Base of coreclr's thread local storage tlsValue = gtNewIndir(TYP_I_IMPL, tlsValue, GTF_IND_NONFAULTING | GTF_IND_INVARIANT); - CORINFO_CONST_LOOKUP tlsRootNode; + CORINFO_CONST_LOOKUP tlsRootNode; + memset(&tlsRootNode, 0, sizeof(CORINFO_CONST_LOOKUP)); info.compCompHnd->getTlsRootInfo(&tlsRootNode); GenTree* tlsRootOffset = gtNewIconNode((size_t)tlsRootNode.handle, TYP_INT); @@ -644,7 +623,6 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S GenTree* tlsRootDef = gtNewStoreLclVarNode(finalLclNum, tlsRootVal); - //GenTree* tlsRootNullCond = gtNewOperNode(GT_NE, TYP_INT, tlsRootLcl, gtNewIconNode(0, TYP_I_IMPL)); GenTree* tlsRootNullCond = gtNewOperNode(GT_NE, TYP_INT, gtCloneExpr(finalLcl), gtNewIconNode(0, TYP_I_IMPL)); tlsRootNullCond = gtNewOperNode(GT_JTRUE, TYP_VOID, tlsRootNullCond); @@ -654,9 +632,11 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S fgInsertStmtAfter(tlsRootNullCondBB, tlsRootNullCondBB->firstStmt(), fgNewStmtFromTree(tlsRootDef)); CORINFO_CONST_LOOKUP threadStaticSlowHelper; + memset(&threadStaticSlowHelper, 0, sizeof(CORINFO_CONST_LOOKUP)); info.compCompHnd->getThreadStaticBaseSlowInfo(&threadStaticSlowHelper); - GenTreeCall* slowHelper = gtNewIndCallNode(gtNewIconHandleNode((size_t)threadStaticSlowHelper.addr, GTF_ICON_TLS_HDL), TYP_I_IMPL); + GenTreeCall* slowHelper = + gtNewIndCallNode(gtNewIconHandleNode((size_t)threadStaticSlowHelper.addr, GTF_ICON_TLS_HDL), TYP_I_IMPL); GenTree* helperArg = gtClone(tlsRootAddrUse); slowHelper->gtArgs.PushBack(this, NewCallArg::Primitive(helperArg)); fgMorphArgs(slowHelper); @@ -666,7 +646,7 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S BasicBlock* fallbackBb = fgNewBBFromTreeAfter(BBJ_ALWAYS, tlsRootNullCondBB, fallbackValueDef, debugInfo, true); GenTree* fastPathValueDef = gtNewStoreLclVarNode(finalLclNum, gtCloneExpr(finalLcl)); - BasicBlock* fastPathBb = fgNewBBFromTreeAfter(BBJ_ALWAYS, fallbackBb, fastPathValueDef, debugInfo, true); + BasicBlock* fastPathBb = fgNewBBFromTreeAfter(BBJ_ALWAYS, fallbackBb, fastPathValueDef, debugInfo, true); *callUse = finalLcl; @@ -676,16 +656,15 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S // // Update preds in all new blocks // -#pragma endregion fgAddRefPred(fallbackBb, tlsRootNullCondBB); fgAddRefPred(fastPathBb, tlsRootNullCondBB); fgAddRefPred(block, fallbackBb); fgAddRefPred(block, fastPathBb); - tlsRootNullCondBB->bbJumpDest = fastPathBb; - fastPathBb->bbJumpDest = block; - fallbackBb->bbJumpDest = block; + tlsRootNullCondBB->bbJumpDest = fastPathBb; + fastPathBb->bbJumpDest = block; + fallbackBb->bbJumpDest = block; // Inherit the weights block->inheritWeight(prevBb); @@ -717,14 +696,18 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S // // Update loop info if loop table is known to be valid // - tlsRootNullCondBB->bbNatLoopNum = prevBb->bbNatLoopNum; - fastPathBb->bbNatLoopNum = prevBb->bbNatLoopNum; - fallbackBb->bbNatLoopNum = prevBb->bbNatLoopNum; + tlsRootNullCondBB->bbNatLoopNum = prevBb->bbNatLoopNum; + fastPathBb->bbNatLoopNum = prevBb->bbNatLoopNum; + fallbackBb->bbNatLoopNum = prevBb->bbNatLoopNum; // All blocks are expected to be in the same EH region assert(BasicBlock::sameEHRegion(prevBb, block)); assert(BasicBlock::sameEHRegion(prevBb, tlsRootNullCondBB)); assert(BasicBlock::sameEHRegion(prevBb, fastPathBb)); +#else + assert(!"Unsupported scenario\n"); + +#endif // TARGET_64BIT return true; } @@ -848,12 +831,12 @@ bool Compiler::fgExpandThreadLocalAccessForCall(BasicBlock** pBlock, Statement* fgMorphStmtBlockOps(block, stmt); gtUpdateStmtSideEffects(stmt); - GenTree* tlsValue = nullptr; - unsigned tlsLclNum = lvaGrabTemp(true DEBUGARG("TLS access")); - lvaTable[tlsLclNum].lvType = TYP_I_IMPL; - GenTree* maxThreadStaticBlocksValue = nullptr; - GenTree* threadStaticBlocksValue = nullptr; - GenTree* tlsValueDef = nullptr; + GenTree* tlsValue = nullptr; + unsigned tlsLclNum = lvaGrabTemp(true DEBUGARG("TLS access")); + lvaTable[tlsLclNum].lvType = TYP_I_IMPL; + GenTree* maxThreadStaticBlocksValue = nullptr; + GenTree* threadStaticBlocksValue = nullptr; + GenTree* tlsValueDef = nullptr; if (TargetOS::IsWindows) { @@ -974,7 +957,8 @@ bool Compiler::fgExpandThreadLocalAccessForCall(BasicBlock** pBlock, Statement* threadStaticBlocksValue = gtNewIndir(TYP_I_IMPL, threadStaticBlocksRef, GTF_IND_NONFAULTING | GTF_IND_INVARIANT); // Create tree for "if (maxThreadStaticBlocks < typeIndex)" - GenTree* typeThreadStaticBlockIndexValue = gtNewIconNode(0, TYP_INT); // call->gtArgs.GetArgByIndex(0)->GetNode(); + GenTree* typeThreadStaticBlockIndexValue = + gtNewIconNode(0, TYP_INT); // call->gtArgs.GetArgByIndex(0)->GetNode(); GenTree* maxThreadStaticBlocksCond = gtNewOperNode(GT_LT, TYP_INT, maxThreadStaticBlocksValue, gtCloneExpr(typeThreadStaticBlockIndexValue)); maxThreadStaticBlocksCond = gtNewOperNode(GT_JTRUE, TYP_VOID, maxThreadStaticBlocksCond); @@ -1131,7 +1115,7 @@ PhaseStatus Compiler::fgExpandHelper(bool skipRarelyRunBlocks) if ((result == PhaseStatus::MODIFIED_EVERYTHING) && opts.OptimizationEnabled()) { fgReorderBlocks(/* useProfileData */ false); - //if (info.compMethodHashPrivate == 0x2f7ba577) // 0x009bf64b + // if (info.compMethodHashPrivate == 0x2f7ba577) // 0x009bf64b //{ // printf("Reorder:\n"); // fgDispBasicBlocks(true); diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index 16e5ab0c4bc2cf..30f038aa02c82a 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -3780,7 +3780,7 @@ GenTree* Compiler::impImportStaticFieldAddress(CORINFO_RESOLVED_TOKEN* pResolved case CORINFO_FIELD_STATIC_TLS_MANAGED: case CORINFO_FIELD_STATIC_TLS_MANAGED_LAZY: -#ifdef FEATURE_READYTORUN +#ifdef FEATURE_READYTORUN if (!opts.IsReadyToRun()) #endif // FEATURE_READYTORUN { diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/ThreadStatics.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/ThreadStatics.cs index a85281ca65b5ac..7bfcbff517b22f 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/ThreadStatics.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/ThreadStatics.cs @@ -34,7 +34,7 @@ internal static unsafe object GetThreadStaticBaseForType(TypeManagerSlot* pModul internal static unsafe object GetInlinedThreadStaticBaseSlow(ref object? threadStorage) { - //Debug.Assert(threadStorage == null); + Debug.Assert(threadStorage == null); // Allocate an object that will represent a memory block for all thread static fields TypeManagerHandle typeManager = EETypePtr.EETypePtrOf().ToPointer()->TypeManager; object threadStaticBase = AllocateThreadStaticStorageForType(typeManager, 0); diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs index 8c82cd3e108cde..453e80c381e5c0 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs @@ -2993,6 +2993,13 @@ private uint getThreadLocalFieldInfo(CORINFO_FIELD_STRUCT_* fld, bool isGCType) return 0; } +#pragma warning disable CA1822 // Mark members as static + private void getThreadLocalStaticBlocksInfo(CORINFO_THREAD_STATIC_BLOCKS_INFO* pInfo, bool isGCType) +#pragma warning restore CA1822 // Mark members as static + { + // Implemented for JIT only for now. + } + private CORINFO_CLASS_STRUCT_* getFieldClass(CORINFO_FIELD_STRUCT_* field) { var fieldDesc = HandleToObject(field); diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs index 3c9a6465e01671..175741310611b0 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs @@ -3232,10 +3232,6 @@ void ValidateSafetyOfUsingTypeEquivalenceOfType(TypeDesc type) } #pragma warning disable CA1822 // Mark members as static - private void getThreadLocalStaticBlocksInfo(CORINFO_THREAD_STATIC_BLOCKS_INFO* pInfo, bool isGCType) - { - // Implemented for JIT and NativeAOT only for now. - } private void getTlsRootInfo(ref CORINFO_CONST_LOOKUP addr) { diff --git a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs index 7691e5ffc3a397..be68ff3bcb94a2 100644 --- a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs +++ b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs @@ -350,12 +350,6 @@ private bool getReadyToRunHelper(ref CORINFO_RESOLVED_TOKEN pResolvedToken, ref pLookup = CreateConstLookupToSymbol(helper); } break; - //case CorInfoHelpFunc.CORINFO_HELP_READYTORUN_INLINED_THREADSTATIC_BASE_SLOW: - // { - // ISymbolNode helper = GetGenericLookupHelper(pGenericLookupKind.runtimeLookupKind, ReadyToRunHelperId.slo, helperArg); - // pLookup = CreateConstLookupToSymbol(helper); - // } - // break; default: throw new NotImplementedException("ReadyToRun: " + id.ToString()); } @@ -2100,7 +2094,6 @@ private void getFieldInfo(ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_MET // Find out what kind of base do we need to look up. if (field.IsThreadStatic) { - Debug.Assert(false, "Another instance"); helperId = ReadyToRunHelperId.GetThreadStaticBase; } else if (field.HasGCStaticBase) @@ -2146,17 +2139,16 @@ private void getFieldInfo(ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_MET { if (MethodBeingCompiled.Context.Target.IsWindows && MethodBeingCompiled.Context.Target.Architecture == TargetArchitecture.X64) { - // TODO: Do it only for windows? ISortableSymbolNode index = _compilation.NodeFactory.TypeThreadStaticIndex((MetadataType)field.OwningType); if (index is TypeThreadStaticIndexNode ti && ti.Type == null) { - if (!_compilation.HasLazyStaticConstructor(field.OwningType)) + if (_compilation.HasLazyStaticConstructor(field.OwningType)) { - fieldAccessor = CORINFO_FIELD_ACCESSOR.CORINFO_FIELD_STATIC_TLS_MANAGED; + fieldAccessor = CORINFO_FIELD_ACCESSOR.CORINFO_FIELD_STATIC_TLS_MANAGED_LAZY; } else { - fieldAccessor = CORINFO_FIELD_ACCESSOR.CORINFO_FIELD_STATIC_TLS_MANAGED_LAZY; + fieldAccessor = CORINFO_FIELD_ACCESSOR.CORINFO_FIELD_STATIC_TLS_MANAGED; } } } @@ -2437,12 +2429,6 @@ private void getThreadStaticBaseSlowInfo(ref CORINFO_CONST_LOOKUP addr) addr = CreateConstLookupToSymbol(_compilation.NodeFactory.HelperEntrypoint(HelperEntrypoint.GetInlinedThreadStaticBaseSlow)); } - private void getThreadLocalStaticBlocksInfo(CORINFO_THREAD_STATIC_BLOCKS_INFO* pInfo, bool isGCType) - { - pInfo->offsetOfThreadLocalStoragePointer = 0x58; - // Implemented for JIT only for now. - } - private int getEnsureClassCtorRunAndReturnThreadStaticBaseHelper(CORINFO_CLASS_STRUCT_* cls, ref CORINFO_CONST_LOOKUP addr, ref CORINFO_CONST_LOOKUP targetSymbol) { MetadataType clsType = HandleToObject(cls) as MetadataType; From 86d01a7c1648064647d78cce2e841864d9a5bc40 Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Tue, 25 Jul 2023 13:56:00 -0700 Subject: [PATCH 10/58] Stop emitting TLS access code for windows/x64 --- .../Target_X64/X64ReadyToRunHelperNode.cs | 42 +------------------ 1 file changed, 1 insertion(+), 41 deletions(-) diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/Target_X64/X64ReadyToRunHelperNode.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/Target_X64/X64ReadyToRunHelperNode.cs index 8fbd5f609b2546..b7d247d341c33a 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/Target_X64/X64ReadyToRunHelperNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/Target_X64/X64ReadyToRunHelperNode.cs @@ -237,47 +237,7 @@ private static void EmitInlineTLSAccess(NodeFactory factory, ref X64Emitter enco // bool isInitialExecutable = factory.CompilationModuleGroup.IsSingleFileCompilation; bool isInitialExecutable = false; - if (factory.Target.IsWindows) - { - if (isInitialExecutable) - { - // mov rax,qword ptr gs:[58h] - encoder.Builder.EmitBytes(new byte[] { 0x65, 0x48, 0x8B, 0x04, 0x25, 0x58, 0x00, 0x00, 0x00 }); - - // mov ecx, SECTIONREL tlsRoot - encoder.Builder.EmitBytes(new byte[] { 0xB9 }); - encoder.Builder.EmitReloc(tlsRoot, RelocType.IMAGE_REL_SECREL); - - // add rcx,qword ptr [rax] - encoder.Builder.EmitBytes(new byte[] { 0x48, 0x03, 0x08 }); - } - else - { - // mov ecx,dword ptr [_tls_index] - encoder.Builder.EmitBytes(new byte[] { 0x8B, 0x0D }); - encoder.Builder.EmitReloc(factory.ExternSymbol("_tls_index"), RelocType.IMAGE_REL_BASED_REL32); - - // mov rax,qword ptr gs:[58h] - encoder.Builder.EmitBytes(new byte[] { 0x65, 0x48, 0x8B, 0x04, 0x25, 0x58, 0x00, 0x00, 0x00 }); - - // mov rax,qword ptr [rax+rcx*8] - encoder.Builder.EmitBytes(new byte[] { 0x48, 0x8B, 0x04, 0xC8 }); - - // mov ecx, SECTIONREL tlsRoot - encoder.Builder.EmitBytes(new byte[] { 0xB9 }); - encoder.Builder.EmitReloc(tlsRoot, RelocType.IMAGE_REL_SECREL); - - // add rcx,rax - encoder.Builder.EmitBytes(new byte[] { 0x48, 0x01, 0xC1 }); - } - - // mov rax, qword ptr[rcx] - encoder.Builder.EmitBytes(new byte[] { 0x48, 0x8b, 0x01 }); - encoder.EmitCompareToZero(Register.RAX); - encoder.EmitJE(getInlinedThreadStaticBaseSlow); - encoder.EmitRET(); - } - else if (factory.Target.OperatingSystem == TargetOS.Linux) + if (factory.Target.OperatingSystem == TargetOS.Linux) { if (isInitialExecutable) { From 09eaeb41131b1a8516c8c896448537da60820ecf Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Thu, 27 Jul 2023 21:43:45 -0700 Subject: [PATCH 11/58] fix linux build errors --- src/coreclr/jit/helperexpansion.cpp | 5 ++++- .../tools/superpmi/superpmi-shared/methodcontext.cpp | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/coreclr/jit/helperexpansion.cpp b/src/coreclr/jit/helperexpansion.cpp index ce162d0b15bce3..2424f4bde26052 100644 --- a/src/coreclr/jit/helperexpansion.cpp +++ b/src/coreclr/jit/helperexpansion.cpp @@ -585,7 +585,10 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S lvaTable[tlsLclNum].lvType = TYP_I_IMPL; // Mark this ICON as a TLS_HDL, codegen will use FS:[cns] or GS:[cns] - uint32_t offsetOfThreadLocalStoragePointer = offsetof(_TEB, ThreadLocalStoragePointer); + uint32_t offsetOfThreadLocalStoragePointer = 0; +#ifdef _MSC_VER + offsetOfThreadLocalStoragePointer = offsetof(_TEB, ThreadLocalStoragePointer); +#endif tlsValue = gtNewIconHandleNode(offsetOfThreadLocalStoragePointer, GTF_ICON_TLS_HDL); tlsValue = gtNewIndir(TYP_I_IMPL, tlsValue, GTF_IND_NONFAULTING | GTF_IND_INVARIANT); diff --git a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp index 963bd4b16c0f9d..a5f63ca486cdb0 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp @@ -3588,7 +3588,7 @@ void MethodContext::dmpGetTlsRootInfo(DWORD key, const Agnostic_CORINFO_CONST_LO void MethodContext::repGetTlsRootInfo(CORINFO_CONST_LOOKUP* result) { DWORD key = 0; - Agnostic_CORINFO_CONST_LOOKUP value = LookupByKeyOrMiss(GetTlsRootInfo, key, ": key 0"); + Agnostic_CORINFO_CONST_LOOKUP value = LookupByKeyOrMiss(GetTlsRootInfo, key, ": key %d", 0); DEBUG_REP(dmpGetTlsRootInfo(key, value)); @@ -3613,7 +3613,7 @@ void MethodContext::dmpGetTlsIndexInfo(DWORD key, const Agnostic_CORINFO_CONST_L void MethodContext::repGetTlsIndexInfo(CORINFO_CONST_LOOKUP* result) { DWORD key = 0; - Agnostic_CORINFO_CONST_LOOKUP value = LookupByKeyOrMiss(GetTlsIndexInfo, key, ": key 0"); + Agnostic_CORINFO_CONST_LOOKUP value = LookupByKeyOrMiss(GetTlsIndexInfo, key, ": key %d", 0); DEBUG_REP(dmpGetTlsIndexInfo(key, value)); @@ -3639,7 +3639,7 @@ void MethodContext::dmpGetThreadStaticBaseSlowInfo(DWORD key, const Agnostic_COR void MethodContext::repGetThreadStaticBaseSlowInfo(CORINFO_CONST_LOOKUP* result) { DWORD key = 0; - Agnostic_CORINFO_CONST_LOOKUP value = LookupByKeyOrMiss(GetThreadStaticBaseSlowInfo, key, ": key 0"); + Agnostic_CORINFO_CONST_LOOKUP value = LookupByKeyOrMiss(GetThreadStaticBaseSlowInfo, key, ": key %d", 0); DEBUG_REP(dmpGetThreadStaticBaseSlowInfo(key, value)); From 337c2f4c3eb122b679abbb54ee4c12dedfdd60c4 Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Fri, 28 Jul 2023 00:09:07 -0700 Subject: [PATCH 12/58] Do not throw not implemented for windows/x64 --- .../Target_X64/X64ReadyToRunHelperNode.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/Target_X64/X64ReadyToRunHelperNode.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/Target_X64/X64ReadyToRunHelperNode.cs index b7d247d341c33a..9e6be08263ca62 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/Target_X64/X64ReadyToRunHelperNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/Target_X64/X64ReadyToRunHelperNode.cs @@ -237,7 +237,11 @@ private static void EmitInlineTLSAccess(NodeFactory factory, ref X64Emitter enco // bool isInitialExecutable = factory.CompilationModuleGroup.IsSingleFileCompilation; bool isInitialExecutable = false; - if (factory.Target.OperatingSystem == TargetOS.Linux) + if (factory.Target.OperatingSystem == TargetOS.Windows) + { + // JIT emits the code for Windows/x64 + } + else if (factory.Target.OperatingSystem == TargetOS.Linux) { if (isInitialExecutable) { From 12094656e4b9990dd40870546b388cbbae13bc40 Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Fri, 28 Jul 2023 05:33:35 -0700 Subject: [PATCH 13/58] fix the problem where ThreadStaticBase helper was still getting invoked --- src/coreclr/jit/helperexpansion.cpp | 7 +------ .../Target_X64/X64ReadyToRunHelperNode.cs | 6 +----- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/src/coreclr/jit/helperexpansion.cpp b/src/coreclr/jit/helperexpansion.cpp index 2424f4bde26052..eea340cf66a708 100644 --- a/src/coreclr/jit/helperexpansion.cpp +++ b/src/coreclr/jit/helperexpansion.cpp @@ -443,7 +443,7 @@ PhaseStatus Compiler::fgExpandThreadLocalAccess() return result; } - return opts.IsReadyToRun() ? fgExpandHelper<&Compiler::fgExpandThreadLocalAccessForCallReadyToRun>(true) + return opts.IsReadyToRun() ? fgExpandHelper<&Compiler::fgExpandThreadLocalAccessForCallReadyToRun>(false) : fgExpandHelper<&Compiler::fgExpandThreadLocalAccessForCall>(true); } @@ -1118,11 +1118,6 @@ PhaseStatus Compiler::fgExpandHelper(bool skipRarelyRunBlocks) if ((result == PhaseStatus::MODIFIED_EVERYTHING) && opts.OptimizationEnabled()) { fgReorderBlocks(/* useProfileData */ false); - // if (info.compMethodHashPrivate == 0x2f7ba577) // 0x009bf64b - //{ - // printf("Reorder:\n"); - // fgDispBasicBlocks(true); - //} fgUpdateChangedFlowGraph(FlowGraphUpdates::COMPUTE_BASICS); } diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/Target_X64/X64ReadyToRunHelperNode.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/Target_X64/X64ReadyToRunHelperNode.cs index 9e6be08263ca62..b7d247d341c33a 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/Target_X64/X64ReadyToRunHelperNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/Target_X64/X64ReadyToRunHelperNode.cs @@ -237,11 +237,7 @@ private static void EmitInlineTLSAccess(NodeFactory factory, ref X64Emitter enco // bool isInitialExecutable = factory.CompilationModuleGroup.IsSingleFileCompilation; bool isInitialExecutable = false; - if (factory.Target.OperatingSystem == TargetOS.Windows) - { - // JIT emits the code for Windows/x64 - } - else if (factory.Target.OperatingSystem == TargetOS.Linux) + if (factory.Target.OperatingSystem == TargetOS.Linux) { if (isInitialExecutable) { From 85e1db651ba8fc9ae8208f15a7db560fc1575c70 Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Fri, 28 Jul 2023 05:58:59 -0700 Subject: [PATCH 14/58] Revert certain changes from JIT method --- src/coreclr/jit/helperexpansion.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/coreclr/jit/helperexpansion.cpp b/src/coreclr/jit/helperexpansion.cpp index eea340cf66a708..4397590cf5be3c 100644 --- a/src/coreclr/jit/helperexpansion.cpp +++ b/src/coreclr/jit/helperexpansion.cpp @@ -843,10 +843,6 @@ bool Compiler::fgExpandThreadLocalAccessForCall(BasicBlock** pBlock, Statement* if (TargetOS::IsWindows) { - // Mark this ICON as a TLS_HDL, codegen will use FS:[cns] or GS:[cns] - tlsValue = gtNewIconHandleNode(threadStaticBlocksInfo.offsetOfThreadLocalStoragePointer, GTF_ICON_TLS_HDL); - tlsValue = gtNewIndir(TYP_I_IMPL, tlsValue, GTF_IND_NONFAULTING | GTF_IND_INVARIANT); - size_t tlsIndexValue = (size_t)threadStaticBlocksInfo.tlsIndex.addr; GenTree* dllRef = nullptr; if (tlsIndexValue != 0) @@ -854,6 +850,10 @@ bool Compiler::fgExpandThreadLocalAccessForCall(BasicBlock** pBlock, Statement* dllRef = gtNewIconHandleNode(tlsIndexValue * TARGET_POINTER_SIZE, GTF_ICON_TLS_HDL); } + // Mark this ICON as a TLS_HDL, codegen will use FS:[cns] or GS:[cns] + tlsValue = gtNewIconHandleNode(threadStaticBlocksInfo.offsetOfThreadLocalStoragePointer, GTF_ICON_TLS_HDL); + tlsValue = gtNewIndir(TYP_I_IMPL, tlsValue, GTF_IND_NONFAULTING | GTF_IND_INVARIANT); + if (dllRef != nullptr) { // Add the dllRef to produce thread local storage reference for coreclr @@ -960,8 +960,7 @@ bool Compiler::fgExpandThreadLocalAccessForCall(BasicBlock** pBlock, Statement* threadStaticBlocksValue = gtNewIndir(TYP_I_IMPL, threadStaticBlocksRef, GTF_IND_NONFAULTING | GTF_IND_INVARIANT); // Create tree for "if (maxThreadStaticBlocks < typeIndex)" - GenTree* typeThreadStaticBlockIndexValue = - gtNewIconNode(0, TYP_INT); // call->gtArgs.GetArgByIndex(0)->GetNode(); + GenTree* typeThreadStaticBlockIndexValue = call->gtArgs.GetArgByIndex(0)->GetNode(); GenTree* maxThreadStaticBlocksCond = gtNewOperNode(GT_LT, TYP_INT, maxThreadStaticBlocksValue, gtCloneExpr(typeThreadStaticBlockIndexValue)); maxThreadStaticBlocksCond = gtNewOperNode(GT_JTRUE, TYP_VOID, maxThreadStaticBlocksCond); From a3d307003d849c2af99f26940c17891dddba1634 Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Sat, 29 Jul 2023 02:25:09 -0700 Subject: [PATCH 15/58] Introduce getThreadLocalStaticInfo_ReadyToRun() --- src/coreclr/inc/corinfo.h | 19 ++ src/coreclr/inc/icorjitinfoimpl_generated.h | 4 + src/coreclr/inc/jiteeversionguid.h | 10 +- src/coreclr/jit/ICorJitInfo_names_generated.h | 1 + .../jit/ICorJitInfo_wrapper_generated.hpp | 9 + .../JitInterface/CorInfoImpl_generated.cs | 175 ++++++++++-------- .../tools/Common/JitInterface/CorInfoTypes.cs | 12 ++ .../ThunkGenerator/ThunkInput.txt | 2 + .../DependencyAnalysis/NodeFactory.cs | 7 + .../ReadyToRunHelperNode.cs | 7 + .../JitInterface/CorInfoImpl.ReadyToRun.cs | 5 + .../JitInterface/CorInfoImpl.RyuJit.cs | 19 ++ src/coreclr/tools/aot/ilc.sln | 98 ++++++++++ .../aot/jitinterface/jitinterface_generated.h | 10 + .../tools/superpmi/superpmi-shared/agnostic.h | 11 ++ .../tools/superpmi/superpmi-shared/lwmlist.h | 1 + .../superpmi-shared/methodcontext.cpp | 53 ++++++ .../superpmi/superpmi-shared/methodcontext.h | 19 +- .../superpmi-shim-collector/icorjitinfo.cpp | 8 + .../icorjitinfo_generated.cpp | 8 + .../icorjitinfo_generated.cpp | 7 + .../tools/superpmi/superpmi/icorjitinfo.cpp | 6 + src/coreclr/vm/jitinterface.cpp | 6 + 23 files changed, 405 insertions(+), 92 deletions(-) diff --git a/src/coreclr/inc/corinfo.h b/src/coreclr/inc/corinfo.h index 7d32378e31028d..b2ef0e7c4dfe99 100644 --- a/src/coreclr/inc/corinfo.h +++ b/src/coreclr/inc/corinfo.h @@ -1739,6 +1739,20 @@ struct CORINFO_THREAD_STATIC_BLOCKS_INFO uint32_t offsetOfGCDataPointer; }; +//---------------------------------------------------------------------------- +// getThreadLocalStaticInfo_ReadyToRun and CORINFO_THREAD_STATIC_INFO_READYTORUN: The EE instructs the JIT about how to access a thread local field + +struct CORINFO_THREAD_STATIC_INFO_READYTORUN +{ + uint32_t offsetOfThreadLocalStoragePointer; + CORINFO_CONST_LOOKUP tlsRootObject; + CORINFO_CONST_LOOKUP tlsIndexObject; + CORINFO_CONST_LOOKUP threadStaticBaseSlow; + uint32_t classCtorContextSize; + CORINFO_CONST_LOOKUP lazyCtorRunHelper; + CORINFO_CONST_LOOKUP lazyCtorTargetSymbol; +}; + //---------------------------------------------------------------------------- // Exception handling @@ -2790,6 +2804,11 @@ class ICorStaticInfo bool isGCType ) = 0; + virtual void getThreadLocalStaticInfo_ReadyToRun( + CORINFO_THREAD_STATIC_INFO_READYTORUN* pInfo, + CORINFO_CLASS_HANDLE cls + ) = 0; + virtual void getTlsRootInfo(CORINFO_CONST_LOOKUP* addr) = 0; virtual void getTlsIndexInfo(CORINFO_CONST_LOOKUP* addr) = 0; virtual void getThreadStaticBaseSlowInfo(CORINFO_CONST_LOOKUP* addr) = 0; diff --git a/src/coreclr/inc/icorjitinfoimpl_generated.h b/src/coreclr/inc/icorjitinfoimpl_generated.h index 5c24cb6332449d..b784b1793548ec 100644 --- a/src/coreclr/inc/icorjitinfoimpl_generated.h +++ b/src/coreclr/inc/icorjitinfoimpl_generated.h @@ -396,6 +396,10 @@ void getThreadLocalStaticBlocksInfo( CORINFO_THREAD_STATIC_BLOCKS_INFO* pInfo, bool isGCType) override; +void getThreadLocalStaticInfo_ReadyToRun( + CORINFO_THREAD_STATIC_INFO_READYTORUN* pInfo, + CORINFO_CLASS_HANDLE cls) override; + void getTlsRootInfo( CORINFO_CONST_LOOKUP* addr) override; diff --git a/src/coreclr/inc/jiteeversionguid.h b/src/coreclr/inc/jiteeversionguid.h index 120605440d5b5c..87bd41898253d2 100644 --- a/src/coreclr/inc/jiteeversionguid.h +++ b/src/coreclr/inc/jiteeversionguid.h @@ -43,11 +43,11 @@ typedef const GUID *LPCGUID; #define GUID_DEFINED #endif // !GUID_DEFINED -constexpr GUID JITEEVersionIdentifier = { /* ae2c23aa-c919-44b9-a1b8-bed99aad9d20 */ - 0xae2c23aa, - 0xc919, - 0x44b9, - {0xa1, 0xb8, 0xbe, 0xd9, 0x9a, 0xad, 0x9d, 0x20} +constexpr GUID JITEEVersionIdentifier = { /* 7dc54d34-512f-4ba6-9eb5-6ff61bab144e */ + 0x7dc54d34, + 0x512f, + 0x4ba6, + {0x9e, 0xb5, 0x6f, 0xf6, 0x1b, 0xab, 0x14, 0x4e} }; ////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/coreclr/jit/ICorJitInfo_names_generated.h b/src/coreclr/jit/ICorJitInfo_names_generated.h index e3ebf6a4de6bb6..33d07c0f2622b9 100644 --- a/src/coreclr/jit/ICorJitInfo_names_generated.h +++ b/src/coreclr/jit/ICorJitInfo_names_generated.h @@ -98,6 +98,7 @@ DEF_CLR_API(getFieldOffset) DEF_CLR_API(getFieldInfo) DEF_CLR_API(getThreadLocalFieldInfo) DEF_CLR_API(getThreadLocalStaticBlocksInfo) +DEF_CLR_API(getThreadLocalStaticInfo_ReadyToRun) DEF_CLR_API(getTlsRootInfo) DEF_CLR_API(getTlsIndexInfo) DEF_CLR_API(getThreadStaticBaseSlowInfo) diff --git a/src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp b/src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp index 067c6310554e61..14d57fa7cd34ad 100644 --- a/src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp +++ b/src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp @@ -932,6 +932,15 @@ void WrapICorJitInfo::getThreadLocalStaticBlocksInfo( API_LEAVE(getThreadLocalStaticBlocksInfo); } +void WrapICorJitInfo::getThreadLocalStaticInfo_ReadyToRun( + CORINFO_THREAD_STATIC_INFO_READYTORUN* pInfo, + CORINFO_CLASS_HANDLE cls) +{ + API_ENTER(getThreadLocalStaticInfo_ReadyToRun); + wrapHnd->getThreadLocalStaticInfo_ReadyToRun(pInfo, cls); + API_LEAVE(getThreadLocalStaticInfo_ReadyToRun); +} + void WrapICorJitInfo::getTlsRootInfo( CORINFO_CONST_LOOKUP* addr) { diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs b/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs index eea9ce249e4bc0..513968ad746ad2 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs @@ -1403,6 +1403,20 @@ private static void _getThreadLocalStaticBlocksInfo(IntPtr thisHandle, IntPtr* p } } + [UnmanagedCallersOnly] + private static void _getThreadLocalStaticInfo_ReadyToRun(IntPtr thisHandle, IntPtr* ppException, CORINFO_THREAD_STATIC_INFO_READYTORUN* pInfo, CORINFO_CLASS_STRUCT_* cls) + { + var _this = GetThis(thisHandle); + try + { + _this.getThreadLocalStaticInfo_ReadyToRun(pInfo, cls); + } + catch (Exception ex) + { + *ppException = _this.AllocException(ex); + } + } + [UnmanagedCallersOnly] private static void _getTlsRootInfo(IntPtr thisHandle, IntPtr* ppException, CORINFO_CONST_LOOKUP* addr) { @@ -2564,7 +2578,7 @@ private static uint _getJitFlags(IntPtr thisHandle, IntPtr* ppException, CORJIT_ private static IntPtr GetUnmanagedCallbacks() { - void** callbacks = (void**)Marshal.AllocCoTaskMem(sizeof(IntPtr) * 173); + void** callbacks = (void**)Marshal.AllocCoTaskMem(sizeof(IntPtr) * 174); callbacks[0] = (delegate* unmanaged)&_isIntrinsic; callbacks[1] = (delegate* unmanaged)&_getMethodAttribs; @@ -2660,85 +2674,86 @@ private static IntPtr GetUnmanagedCallbacks() callbacks[91] = (delegate* unmanaged)&_getFieldInfo; callbacks[92] = (delegate* unmanaged)&_getThreadLocalFieldInfo; callbacks[93] = (delegate* unmanaged)&_getThreadLocalStaticBlocksInfo; - callbacks[94] = (delegate* unmanaged)&_getTlsRootInfo; - callbacks[95] = (delegate* unmanaged)&_getTlsIndexInfo; - callbacks[96] = (delegate* unmanaged)&_getThreadStaticBaseSlowInfo; - callbacks[97] = (delegate* unmanaged)&_getEnsureClassCtorRunAndReturnThreadStaticBaseHelper; - callbacks[98] = (delegate* unmanaged)&_isFieldStatic; - callbacks[99] = (delegate* unmanaged)&_getArrayOrStringLength; - callbacks[100] = (delegate* unmanaged)&_getBoundaries; - callbacks[101] = (delegate* unmanaged)&_setBoundaries; - callbacks[102] = (delegate* unmanaged)&_getVars; - callbacks[103] = (delegate* unmanaged)&_setVars; - callbacks[104] = (delegate* unmanaged)&_reportRichMappings; - callbacks[105] = (delegate* unmanaged)&_allocateArray; - callbacks[106] = (delegate* unmanaged)&_freeArray; - callbacks[107] = (delegate* unmanaged)&_getArgNext; - callbacks[108] = (delegate* unmanaged)&_getArgType; - callbacks[109] = (delegate* unmanaged)&_getExactClasses; - callbacks[110] = (delegate* unmanaged)&_getArgClass; - callbacks[111] = (delegate* unmanaged)&_getHFAType; - callbacks[112] = (delegate* unmanaged)&_runWithErrorTrap; - callbacks[113] = (delegate* unmanaged)&_runWithSPMIErrorTrap; - callbacks[114] = (delegate* unmanaged)&_getEEInfo; - callbacks[115] = (delegate* unmanaged)&_getJitTimeLogFilename; - callbacks[116] = (delegate* unmanaged)&_getMethodDefFromMethod; - callbacks[117] = (delegate* unmanaged)&_printMethodName; - callbacks[118] = (delegate* unmanaged)&_getMethodNameFromMetadata; - callbacks[119] = (delegate* unmanaged)&_getMethodHash; - callbacks[120] = (delegate* unmanaged)&_getSystemVAmd64PassStructInRegisterDescriptor; - callbacks[121] = (delegate* unmanaged)&_getLoongArch64PassStructInRegisterFlags; - callbacks[122] = (delegate* unmanaged)&_getRISCV64PassStructInRegisterFlags; - callbacks[123] = (delegate* unmanaged)&_getThreadTLSIndex; - callbacks[124] = (delegate* unmanaged)&_getAddrOfCaptureThreadGlobal; - callbacks[125] = (delegate* unmanaged)&_getHelperFtn; - callbacks[126] = (delegate* unmanaged)&_getFunctionEntryPoint; - callbacks[127] = (delegate* unmanaged)&_getFunctionFixedEntryPoint; - callbacks[128] = (delegate* unmanaged)&_getMethodSync; - callbacks[129] = (delegate* unmanaged)&_getLazyStringLiteralHelper; - callbacks[130] = (delegate* unmanaged)&_embedModuleHandle; - callbacks[131] = (delegate* unmanaged)&_embedClassHandle; - callbacks[132] = (delegate* unmanaged)&_embedMethodHandle; - callbacks[133] = (delegate* unmanaged)&_embedFieldHandle; - callbacks[134] = (delegate* unmanaged)&_embedGenericHandle; - callbacks[135] = (delegate* unmanaged)&_getLocationOfThisType; - callbacks[136] = (delegate* unmanaged)&_getAddressOfPInvokeTarget; - callbacks[137] = (delegate* unmanaged)&_GetCookieForPInvokeCalliSig; - callbacks[138] = (delegate* unmanaged)&_canGetCookieForPInvokeCalliSig; - callbacks[139] = (delegate* unmanaged)&_getJustMyCodeHandle; - callbacks[140] = (delegate* unmanaged)&_GetProfilingHandle; - callbacks[141] = (delegate* unmanaged)&_getCallInfo; - callbacks[142] = (delegate* unmanaged)&_getClassDomainID; - callbacks[143] = (delegate* unmanaged)&_getStaticFieldContent; - callbacks[144] = (delegate* unmanaged)&_getObjectContent; - callbacks[145] = (delegate* unmanaged)&_getStaticFieldCurrentClass; - callbacks[146] = (delegate* unmanaged)&_getVarArgsHandle; - callbacks[147] = (delegate* unmanaged)&_canGetVarArgsHandle; - callbacks[148] = (delegate* unmanaged)&_constructStringLiteral; - callbacks[149] = (delegate* unmanaged)&_emptyStringLiteral; - callbacks[150] = (delegate* unmanaged)&_getFieldThreadLocalStoreID; - callbacks[151] = (delegate* unmanaged)&_GetDelegateCtor; - callbacks[152] = (delegate* unmanaged)&_MethodCompileComplete; - callbacks[153] = (delegate* unmanaged)&_getTailCallHelpers; - callbacks[154] = (delegate* unmanaged)&_convertPInvokeCalliToCall; - callbacks[155] = (delegate* unmanaged)&_notifyInstructionSetUsage; - callbacks[156] = (delegate* unmanaged)&_updateEntryPointForTailCall; - callbacks[157] = (delegate* unmanaged)&_allocMem; - callbacks[158] = (delegate* unmanaged)&_reserveUnwindInfo; - callbacks[159] = (delegate* unmanaged)&_allocUnwindInfo; - callbacks[160] = (delegate* unmanaged)&_allocGCInfo; - callbacks[161] = (delegate* unmanaged)&_setEHcount; - callbacks[162] = (delegate* unmanaged)&_setEHinfo; - callbacks[163] = (delegate* unmanaged)&_logMsg; - callbacks[164] = (delegate* unmanaged)&_doAssert; - callbacks[165] = (delegate* unmanaged)&_reportFatalError; - callbacks[166] = (delegate* unmanaged)&_getPgoInstrumentationResults; - callbacks[167] = (delegate* unmanaged)&_allocPgoInstrumentationBySchema; - callbacks[168] = (delegate* unmanaged)&_recordCallSite; - callbacks[169] = (delegate* unmanaged)&_recordRelocation; - callbacks[170] = (delegate* unmanaged)&_getRelocTypeHint; - callbacks[171] = (delegate* unmanaged)&_getExpectedTargetArchitecture; - callbacks[172] = (delegate* unmanaged)&_getJitFlags; + callbacks[94] = (delegate* unmanaged)&_getThreadLocalStaticInfo_ReadyToRun; + callbacks[95] = (delegate* unmanaged)&_getTlsRootInfo; + callbacks[96] = (delegate* unmanaged)&_getTlsIndexInfo; + callbacks[97] = (delegate* unmanaged)&_getThreadStaticBaseSlowInfo; + callbacks[98] = (delegate* unmanaged)&_getEnsureClassCtorRunAndReturnThreadStaticBaseHelper; + callbacks[99] = (delegate* unmanaged)&_isFieldStatic; + callbacks[100] = (delegate* unmanaged)&_getArrayOrStringLength; + callbacks[101] = (delegate* unmanaged)&_getBoundaries; + callbacks[102] = (delegate* unmanaged)&_setBoundaries; + callbacks[103] = (delegate* unmanaged)&_getVars; + callbacks[104] = (delegate* unmanaged)&_setVars; + callbacks[105] = (delegate* unmanaged)&_reportRichMappings; + callbacks[106] = (delegate* unmanaged)&_allocateArray; + callbacks[107] = (delegate* unmanaged)&_freeArray; + callbacks[108] = (delegate* unmanaged)&_getArgNext; + callbacks[109] = (delegate* unmanaged)&_getArgType; + callbacks[110] = (delegate* unmanaged)&_getExactClasses; + callbacks[111] = (delegate* unmanaged)&_getArgClass; + callbacks[112] = (delegate* unmanaged)&_getHFAType; + callbacks[113] = (delegate* unmanaged)&_runWithErrorTrap; + callbacks[114] = (delegate* unmanaged)&_runWithSPMIErrorTrap; + callbacks[115] = (delegate* unmanaged)&_getEEInfo; + callbacks[116] = (delegate* unmanaged)&_getJitTimeLogFilename; + callbacks[117] = (delegate* unmanaged)&_getMethodDefFromMethod; + callbacks[118] = (delegate* unmanaged)&_printMethodName; + callbacks[119] = (delegate* unmanaged)&_getMethodNameFromMetadata; + callbacks[120] = (delegate* unmanaged)&_getMethodHash; + callbacks[121] = (delegate* unmanaged)&_getSystemVAmd64PassStructInRegisterDescriptor; + callbacks[122] = (delegate* unmanaged)&_getLoongArch64PassStructInRegisterFlags; + callbacks[123] = (delegate* unmanaged)&_getRISCV64PassStructInRegisterFlags; + callbacks[124] = (delegate* unmanaged)&_getThreadTLSIndex; + callbacks[125] = (delegate* unmanaged)&_getAddrOfCaptureThreadGlobal; + callbacks[126] = (delegate* unmanaged)&_getHelperFtn; + callbacks[127] = (delegate* unmanaged)&_getFunctionEntryPoint; + callbacks[128] = (delegate* unmanaged)&_getFunctionFixedEntryPoint; + callbacks[129] = (delegate* unmanaged)&_getMethodSync; + callbacks[130] = (delegate* unmanaged)&_getLazyStringLiteralHelper; + callbacks[131] = (delegate* unmanaged)&_embedModuleHandle; + callbacks[132] = (delegate* unmanaged)&_embedClassHandle; + callbacks[133] = (delegate* unmanaged)&_embedMethodHandle; + callbacks[134] = (delegate* unmanaged)&_embedFieldHandle; + callbacks[135] = (delegate* unmanaged)&_embedGenericHandle; + callbacks[136] = (delegate* unmanaged)&_getLocationOfThisType; + callbacks[137] = (delegate* unmanaged)&_getAddressOfPInvokeTarget; + callbacks[138] = (delegate* unmanaged)&_GetCookieForPInvokeCalliSig; + callbacks[139] = (delegate* unmanaged)&_canGetCookieForPInvokeCalliSig; + callbacks[140] = (delegate* unmanaged)&_getJustMyCodeHandle; + callbacks[141] = (delegate* unmanaged)&_GetProfilingHandle; + callbacks[142] = (delegate* unmanaged)&_getCallInfo; + callbacks[143] = (delegate* unmanaged)&_getClassDomainID; + callbacks[144] = (delegate* unmanaged)&_getStaticFieldContent; + callbacks[145] = (delegate* unmanaged)&_getObjectContent; + callbacks[146] = (delegate* unmanaged)&_getStaticFieldCurrentClass; + callbacks[147] = (delegate* unmanaged)&_getVarArgsHandle; + callbacks[148] = (delegate* unmanaged)&_canGetVarArgsHandle; + callbacks[149] = (delegate* unmanaged)&_constructStringLiteral; + callbacks[150] = (delegate* unmanaged)&_emptyStringLiteral; + callbacks[151] = (delegate* unmanaged)&_getFieldThreadLocalStoreID; + callbacks[152] = (delegate* unmanaged)&_GetDelegateCtor; + callbacks[153] = (delegate* unmanaged)&_MethodCompileComplete; + callbacks[154] = (delegate* unmanaged)&_getTailCallHelpers; + callbacks[155] = (delegate* unmanaged)&_convertPInvokeCalliToCall; + callbacks[156] = (delegate* unmanaged)&_notifyInstructionSetUsage; + callbacks[157] = (delegate* unmanaged)&_updateEntryPointForTailCall; + callbacks[158] = (delegate* unmanaged)&_allocMem; + callbacks[159] = (delegate* unmanaged)&_reserveUnwindInfo; + callbacks[160] = (delegate* unmanaged)&_allocUnwindInfo; + callbacks[161] = (delegate* unmanaged)&_allocGCInfo; + callbacks[162] = (delegate* unmanaged)&_setEHcount; + callbacks[163] = (delegate* unmanaged)&_setEHinfo; + callbacks[164] = (delegate* unmanaged)&_logMsg; + callbacks[165] = (delegate* unmanaged)&_doAssert; + callbacks[166] = (delegate* unmanaged)&_reportFatalError; + callbacks[167] = (delegate* unmanaged)&_getPgoInstrumentationResults; + callbacks[168] = (delegate* unmanaged)&_allocPgoInstrumentationBySchema; + callbacks[169] = (delegate* unmanaged)&_recordCallSite; + callbacks[170] = (delegate* unmanaged)&_recordRelocation; + callbacks[171] = (delegate* unmanaged)&_getRelocTypeHint; + callbacks[172] = (delegate* unmanaged)&_getExpectedTargetArchitecture; + callbacks[173] = (delegate* unmanaged)&_getJitFlags; return (IntPtr)callbacks; } diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs b/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs index 1f46f7e317ac57..8321846dabb457 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs @@ -1159,6 +1159,18 @@ public unsafe struct CORINFO_THREAD_STATIC_BLOCKS_INFO public uint offsetOfGCDataPointer; }; + + public unsafe struct CORINFO_THREAD_STATIC_INFO_READYTORUN + { + public uint offsetOfThreadLocalStoragePointer; + public CORINFO_CONST_LOOKUP tlsRootObject; + public CORINFO_CONST_LOOKUP tlsIndexObject; + public CORINFO_CONST_LOOKUP threadStaticBaseSlow; + public uint classCtorContextSize; + public CORINFO_CONST_LOOKUP classCtorRunHelper; + public CORINFO_CONST_LOOKUP lazyCtorTargetSymbol; + }; + // System V struct passing // The Classification types are described in the ABI spec at https://software.intel.com/sites/default/files/article/402129/mpx-linux64-abi.pdf public enum SystemVClassificationType : byte diff --git a/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt b/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt index c0b9ee36c76b68..9f374f16190f03 100644 --- a/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt +++ b/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt @@ -87,6 +87,7 @@ CORINFO_GENERICHANDLE_RESULT*,ref CORINFO_GENERICHANDLE_RESULT CORINFO_METHOD_INFO*,CORINFO_METHOD_INFO* CORINFO_FIELD_INFO*,CORINFO_FIELD_INFO* CORINFO_THREAD_STATIC_BLOCKS_INFO*,CORINFO_THREAD_STATIC_BLOCKS_INFO* +CORINFO_THREAD_STATIC_INFO_READYTORUN*,CORINFO_THREAD_STATIC_INFO_READYTORUN* CORINFO_CALL_INFO*,CORINFO_CALL_INFO* CORINFO_DEVIRTUALIZATION_INFO*,CORINFO_DEVIRTUALIZATION_INFO* CORINFO_TYPE_LAYOUT_NODE*,CORINFO_TYPE_LAYOUT_NODE* @@ -255,6 +256,7 @@ FUNCTIONS void getFieldInfo(CORINFO_RESOLVED_TOKEN* pResolvedToken, CORINFO_METHOD_HANDLE callerHandle, CORINFO_ACCESS_FLAGS flags, CORINFO_FIELD_INFO* pResult) uint32_t getThreadLocalFieldInfo (CORINFO_FIELD_HANDLE field, bool isGCtype) void getThreadLocalStaticBlocksInfo (CORINFO_THREAD_STATIC_BLOCKS_INFO* pInfo, bool isGCType) + void getThreadLocalStaticInfo_ReadyToRun(CORINFO_THREAD_STATIC_INFO_READYTORUN* pInfo, CORINFO_CLASS_HANDLE cls) void getTlsRootInfo(CORINFO_CONST_LOOKUP* addr) void getTlsIndexInfo(CORINFO_CONST_LOOKUP* addr) void getThreadStaticBaseSlowInfo(CORINFO_CONST_LOOKUP* addr) diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/NodeFactory.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/NodeFactory.cs index 0cf64196e96d07..fe83e3061c754f 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/NodeFactory.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/NodeFactory.cs @@ -1134,6 +1134,13 @@ public DependencyNodeCore VariantInterfaceMethodUse(MethodDesc decl public ISymbolNode ReadyToRunHelper(ReadyToRunHelperId id, object target) { + if (target is MetadataType mt) + { + if (mt.DiagnosticNamespace == "System.Runtime.InteropServices" && mt.DiagnosticName == "PInvokeMarshal") + { + Console.WriteLine("here"); + } + } return _readyToRunHelpers.GetOrAdd(new ReadyToRunHelperKey(id, target)); } diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ReadyToRunHelperNode.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ReadyToRunHelperNode.cs index 36cc3c5ec1eda3..859a73924302f4 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ReadyToRunHelperNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ReadyToRunHelperNode.cs @@ -50,6 +50,13 @@ public partial class ReadyToRunHelperNode : AssemblyStubNode, INodeWithDebugInfo public ReadyToRunHelperNode(ReadyToRunHelperId id, object target) { + if (target is MetadataType mt) + { + if (mt.DiagnosticNamespace == "System.Runtime.InteropServices" && mt.DiagnosticName == "PInvokeMarshal") + { + Console.WriteLine("here"); + } + } _id = id; _target = target; diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs index 175741310611b0..3f89eb6e094cbf 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs @@ -3253,6 +3253,11 @@ private int getEnsureClassCtorRunAndReturnThreadStaticBaseHelper(CORINFO_CLASS_S // Implemented for NativeAOT only for now. return 0; } + + private void getThreadLocalStaticInfo_ReadyToRun(CORINFO_THREAD_STATIC_INFO_READYTORUN* pInfo, CORINFO_CLASS_STRUCT_* cls) + { + // Implemented for NativeAOT only for now. + } #pragma warning restore CA1822 // Mark members as static } } diff --git a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs index be68ff3bcb94a2..ad1b1a016f4285 100644 --- a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs +++ b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs @@ -2150,6 +2150,9 @@ private void getFieldInfo(ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_MET { fieldAccessor = CORINFO_FIELD_ACCESSOR.CORINFO_FIELD_STATIC_TLS_MANAGED; } + } else + { + Console.WriteLine(field.Name); } } pResult->helper = CorInfoHelpFunc.CORINFO_HELP_READYTORUN_THREADSTATIC_BASE; @@ -2441,5 +2444,21 @@ private int getEnsureClassCtorRunAndReturnThreadStaticBaseHelper(CORINFO_CLASS_S targetSymbol = CreateConstLookupToSymbol(_compilation.NodeFactory.TypeNonGCStaticsSymbol(clsType)); return -NonGCStaticsNode.GetClassConstructorContextSize(_compilation.NodeFactory.Target); } + + private void getThreadLocalStaticInfo_ReadyToRun(CORINFO_THREAD_STATIC_INFO_READYTORUN* pInfo, CORINFO_CLASS_STRUCT_* cls) + { + pInfo->offsetOfThreadLocalStoragePointer = (uint)(11 * PointerSize); // 0x58 = 0n88 + pInfo->tlsIndexObject = CreateConstLookupToSymbol(_compilation.NodeFactory.ExternSymbol("_tls_index")); + pInfo->tlsRootObject = CreateConstLookupToSymbol(_compilation.NodeFactory.TlsRoot); + pInfo->threadStaticBaseSlow = CreateConstLookupToSymbol(_compilation.NodeFactory.HelperEntrypoint(HelperEntrypoint.GetInlinedThreadStaticBaseSlow)); + + MetadataType clsType = HandleToObject(cls) as MetadataType; + if (clsType != null) + { + pInfo->classCtorContextSize = (uint)-NonGCStaticsNode.GetClassConstructorContextSize(_compilation.NodeFactory.Target); + pInfo->classCtorRunHelper = CreateConstLookupToSymbol(_compilation.NodeFactory.HelperEntrypoint(HelperEntrypoint.EnsureClassConstructorRunAndReturnThreadStaticBase)); + pInfo->lazyCtorTargetSymbol = CreateConstLookupToSymbol(_compilation.NodeFactory.TypeNonGCStaticsSymbol(clsType)); + } + } } } diff --git a/src/coreclr/tools/aot/ilc.sln b/src/coreclr/tools/aot/ilc.sln index 3fe8026533f307..c53ab72c5bd6a2 100644 --- a/src/coreclr/tools/aot/ilc.sln +++ b/src/coreclr/tools/aot/ilc.sln @@ -28,6 +28,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mono.Linker.Tests.Cases.Exp EndProject Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "ILLink.Shared", "..\..\..\tools\illink\src\ILLink.Shared\ILLink.Shared.shproj", "{FF598E93-8E9E-4091-9F50-61A7572663AE}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "clrjit_win_x64_x64", "..\..\..\..\artifacts\obj\coreclr\windows.x64.Checked\ide\jit\clrjit_win_x64_x64.vcxproj", "{74666FB9-0C0D-3452-A912-3D571F908AA8}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Checked|Any CPU = Checked|Any CPU @@ -39,6 +41,9 @@ Global Release|Any CPU = Release|Any CPU Release|x64 = Release|x64 Release|x86 = Release|x86 + RelWithDebInfo|Any CPU = RelWithDebInfo|Any CPU + RelWithDebInfo|x64 = RelWithDebInfo|x64 + RelWithDebInfo|x86 = RelWithDebInfo|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {6856F5F6-E568-493F-AF8A-7F624B5A02A5}.Checked|Any CPU.ActiveCfg = Checked|x86 @@ -56,6 +61,12 @@ Global {6856F5F6-E568-493F-AF8A-7F624B5A02A5}.Release|x64.Build.0 = Release|x64 {6856F5F6-E568-493F-AF8A-7F624B5A02A5}.Release|x86.ActiveCfg = Release|x86 {6856F5F6-E568-493F-AF8A-7F624B5A02A5}.Release|x86.Build.0 = Release|x86 + {6856F5F6-E568-493F-AF8A-7F624B5A02A5}.RelWithDebInfo|Any CPU.ActiveCfg = Release|x64 + {6856F5F6-E568-493F-AF8A-7F624B5A02A5}.RelWithDebInfo|Any CPU.Build.0 = Release|x64 + {6856F5F6-E568-493F-AF8A-7F624B5A02A5}.RelWithDebInfo|x64.ActiveCfg = Release|x64 + {6856F5F6-E568-493F-AF8A-7F624B5A02A5}.RelWithDebInfo|x64.Build.0 = Release|x64 + {6856F5F6-E568-493F-AF8A-7F624B5A02A5}.RelWithDebInfo|x86.ActiveCfg = Release|x86 + {6856F5F6-E568-493F-AF8A-7F624B5A02A5}.RelWithDebInfo|x86.Build.0 = Release|x86 {FB2D45F2-FA4C-42B2-8E53-3E1F30CF8046}.Checked|Any CPU.ActiveCfg = Checked|x86 {FB2D45F2-FA4C-42B2-8E53-3E1F30CF8046}.Checked|x64.ActiveCfg = Checked|x64 {FB2D45F2-FA4C-42B2-8E53-3E1F30CF8046}.Checked|x64.Build.0 = Checked|x64 @@ -71,6 +82,12 @@ Global {FB2D45F2-FA4C-42B2-8E53-3E1F30CF8046}.Release|x64.Build.0 = Release|x64 {FB2D45F2-FA4C-42B2-8E53-3E1F30CF8046}.Release|x86.ActiveCfg = Release|x86 {FB2D45F2-FA4C-42B2-8E53-3E1F30CF8046}.Release|x86.Build.0 = Release|x86 + {FB2D45F2-FA4C-42B2-8E53-3E1F30CF8046}.RelWithDebInfo|Any CPU.ActiveCfg = Release|x64 + {FB2D45F2-FA4C-42B2-8E53-3E1F30CF8046}.RelWithDebInfo|Any CPU.Build.0 = Release|x64 + {FB2D45F2-FA4C-42B2-8E53-3E1F30CF8046}.RelWithDebInfo|x64.ActiveCfg = Release|x64 + {FB2D45F2-FA4C-42B2-8E53-3E1F30CF8046}.RelWithDebInfo|x64.Build.0 = Release|x64 + {FB2D45F2-FA4C-42B2-8E53-3E1F30CF8046}.RelWithDebInfo|x86.ActiveCfg = Release|x86 + {FB2D45F2-FA4C-42B2-8E53-3E1F30CF8046}.RelWithDebInfo|x86.Build.0 = Release|x86 {B68D5B9E-405B-4E44-B2CC-418EC78AE070}.Checked|Any CPU.ActiveCfg = Checked|x86 {B68D5B9E-405B-4E44-B2CC-418EC78AE070}.Checked|x64.ActiveCfg = Checked|x64 {B68D5B9E-405B-4E44-B2CC-418EC78AE070}.Checked|x64.Build.0 = Checked|x64 @@ -86,6 +103,12 @@ Global {B68D5B9E-405B-4E44-B2CC-418EC78AE070}.Release|x64.Build.0 = Release|x64 {B68D5B9E-405B-4E44-B2CC-418EC78AE070}.Release|x86.ActiveCfg = Release|x86 {B68D5B9E-405B-4E44-B2CC-418EC78AE070}.Release|x86.Build.0 = Release|x86 + {B68D5B9E-405B-4E44-B2CC-418EC78AE070}.RelWithDebInfo|Any CPU.ActiveCfg = Release|x64 + {B68D5B9E-405B-4E44-B2CC-418EC78AE070}.RelWithDebInfo|Any CPU.Build.0 = Release|x64 + {B68D5B9E-405B-4E44-B2CC-418EC78AE070}.RelWithDebInfo|x64.ActiveCfg = Release|x64 + {B68D5B9E-405B-4E44-B2CC-418EC78AE070}.RelWithDebInfo|x64.Build.0 = Release|x64 + {B68D5B9E-405B-4E44-B2CC-418EC78AE070}.RelWithDebInfo|x86.ActiveCfg = Release|x86 + {B68D5B9E-405B-4E44-B2CC-418EC78AE070}.RelWithDebInfo|x86.Build.0 = Release|x86 {05E020F4-6FA1-4DEE-8B9D-4F4B79840231}.Checked|Any CPU.ActiveCfg = Checked|x86 {05E020F4-6FA1-4DEE-8B9D-4F4B79840231}.Checked|x64.ActiveCfg = Checked|x64 {05E020F4-6FA1-4DEE-8B9D-4F4B79840231}.Checked|x64.Build.0 = Checked|x64 @@ -101,6 +124,12 @@ Global {05E020F4-6FA1-4DEE-8B9D-4F4B79840231}.Release|x64.Build.0 = Release|x64 {05E020F4-6FA1-4DEE-8B9D-4F4B79840231}.Release|x86.ActiveCfg = Release|x86 {05E020F4-6FA1-4DEE-8B9D-4F4B79840231}.Release|x86.Build.0 = Release|x86 + {05E020F4-6FA1-4DEE-8B9D-4F4B79840231}.RelWithDebInfo|Any CPU.ActiveCfg = Release|x64 + {05E020F4-6FA1-4DEE-8B9D-4F4B79840231}.RelWithDebInfo|Any CPU.Build.0 = Release|x64 + {05E020F4-6FA1-4DEE-8B9D-4F4B79840231}.RelWithDebInfo|x64.ActiveCfg = Release|x64 + {05E020F4-6FA1-4DEE-8B9D-4F4B79840231}.RelWithDebInfo|x64.Build.0 = Release|x64 + {05E020F4-6FA1-4DEE-8B9D-4F4B79840231}.RelWithDebInfo|x86.ActiveCfg = Release|x86 + {05E020F4-6FA1-4DEE-8B9D-4F4B79840231}.RelWithDebInfo|x86.Build.0 = Release|x86 {07221944-6A68-4B82-8461-82C7754B1B1F}.Checked|Any CPU.ActiveCfg = Checked|x86 {07221944-6A68-4B82-8461-82C7754B1B1F}.Checked|x64.ActiveCfg = Checked|x64 {07221944-6A68-4B82-8461-82C7754B1B1F}.Checked|x64.Build.0 = Checked|x64 @@ -116,6 +145,12 @@ Global {07221944-6A68-4B82-8461-82C7754B1B1F}.Release|x64.Build.0 = Release|x64 {07221944-6A68-4B82-8461-82C7754B1B1F}.Release|x86.ActiveCfg = Release|x86 {07221944-6A68-4B82-8461-82C7754B1B1F}.Release|x86.Build.0 = Release|x86 + {07221944-6A68-4B82-8461-82C7754B1B1F}.RelWithDebInfo|Any CPU.ActiveCfg = Release|x64 + {07221944-6A68-4B82-8461-82C7754B1B1F}.RelWithDebInfo|Any CPU.Build.0 = Release|x64 + {07221944-6A68-4B82-8461-82C7754B1B1F}.RelWithDebInfo|x64.ActiveCfg = Release|x64 + {07221944-6A68-4B82-8461-82C7754B1B1F}.RelWithDebInfo|x64.Build.0 = Release|x64 + {07221944-6A68-4B82-8461-82C7754B1B1F}.RelWithDebInfo|x86.ActiveCfg = Release|x86 + {07221944-6A68-4B82-8461-82C7754B1B1F}.RelWithDebInfo|x86.Build.0 = Release|x86 {FFBD9619-DE6F-4A98-8732-8A14EC3C1A18}.Checked|Any CPU.ActiveCfg = Checked|x86 {FFBD9619-DE6F-4A98-8732-8A14EC3C1A18}.Checked|x64.ActiveCfg = Checked|x64 {FFBD9619-DE6F-4A98-8732-8A14EC3C1A18}.Checked|x64.Build.0 = Checked|x64 @@ -131,6 +166,12 @@ Global {FFBD9619-DE6F-4A98-8732-8A14EC3C1A18}.Release|x64.Build.0 = Release|x64 {FFBD9619-DE6F-4A98-8732-8A14EC3C1A18}.Release|x86.ActiveCfg = Release|x86 {FFBD9619-DE6F-4A98-8732-8A14EC3C1A18}.Release|x86.Build.0 = Release|x86 + {FFBD9619-DE6F-4A98-8732-8A14EC3C1A18}.RelWithDebInfo|Any CPU.ActiveCfg = Release|x64 + {FFBD9619-DE6F-4A98-8732-8A14EC3C1A18}.RelWithDebInfo|Any CPU.Build.0 = Release|x64 + {FFBD9619-DE6F-4A98-8732-8A14EC3C1A18}.RelWithDebInfo|x64.ActiveCfg = Release|x64 + {FFBD9619-DE6F-4A98-8732-8A14EC3C1A18}.RelWithDebInfo|x64.Build.0 = Release|x64 + {FFBD9619-DE6F-4A98-8732-8A14EC3C1A18}.RelWithDebInfo|x86.ActiveCfg = Release|x86 + {FFBD9619-DE6F-4A98-8732-8A14EC3C1A18}.RelWithDebInfo|x86.Build.0 = Release|x86 {CBDE0470-E0C9-4693-9A11-ACC117522F3F}.Checked|Any CPU.ActiveCfg = Checked|x86 {CBDE0470-E0C9-4693-9A11-ACC117522F3F}.Checked|x64.ActiveCfg = Checked|x64 {CBDE0470-E0C9-4693-9A11-ACC117522F3F}.Checked|x64.Build.0 = Checked|x64 @@ -146,6 +187,12 @@ Global {CBDE0470-E0C9-4693-9A11-ACC117522F3F}.Release|x64.Build.0 = Release|x64 {CBDE0470-E0C9-4693-9A11-ACC117522F3F}.Release|x86.ActiveCfg = Release|x86 {CBDE0470-E0C9-4693-9A11-ACC117522F3F}.Release|x86.Build.0 = Release|x86 + {CBDE0470-E0C9-4693-9A11-ACC117522F3F}.RelWithDebInfo|Any CPU.ActiveCfg = Release|x64 + {CBDE0470-E0C9-4693-9A11-ACC117522F3F}.RelWithDebInfo|Any CPU.Build.0 = Release|x64 + {CBDE0470-E0C9-4693-9A11-ACC117522F3F}.RelWithDebInfo|x64.ActiveCfg = Release|x64 + {CBDE0470-E0C9-4693-9A11-ACC117522F3F}.RelWithDebInfo|x64.Build.0 = Release|x64 + {CBDE0470-E0C9-4693-9A11-ACC117522F3F}.RelWithDebInfo|x86.ActiveCfg = Release|x86 + {CBDE0470-E0C9-4693-9A11-ACC117522F3F}.RelWithDebInfo|x86.Build.0 = Release|x86 {24CBA9C6-EDBA-47D6-A0B5-04417BDE5FE3}.Checked|Any CPU.ActiveCfg = Checked|x64 {24CBA9C6-EDBA-47D6-A0B5-04417BDE5FE3}.Checked|Any CPU.Build.0 = Checked|x64 {24CBA9C6-EDBA-47D6-A0B5-04417BDE5FE3}.Checked|x64.ActiveCfg = Checked|x64 @@ -164,6 +211,9 @@ Global {24CBA9C6-EDBA-47D6-A0B5-04417BDE5FE3}.Release|x64.Build.0 = Release|x64 {24CBA9C6-EDBA-47D6-A0B5-04417BDE5FE3}.Release|x86.ActiveCfg = Release|x86 {24CBA9C6-EDBA-47D6-A0B5-04417BDE5FE3}.Release|x86.Build.0 = Release|x86 + {24CBA9C6-EDBA-47D6-A0B5-04417BDE5FE3}.RelWithDebInfo|Any CPU.ActiveCfg = Release|x64 + {24CBA9C6-EDBA-47D6-A0B5-04417BDE5FE3}.RelWithDebInfo|x64.ActiveCfg = Release|x64 + {24CBA9C6-EDBA-47D6-A0B5-04417BDE5FE3}.RelWithDebInfo|x86.ActiveCfg = Release|x86 {740CDFF4-B8EC-4A37-951B-C9FE9980EF2A}.Checked|Any CPU.ActiveCfg = Checked|Any CPU {740CDFF4-B8EC-4A37-951B-C9FE9980EF2A}.Checked|Any CPU.Build.0 = Checked|Any CPU {740CDFF4-B8EC-4A37-951B-C9FE9980EF2A}.Checked|x64.ActiveCfg = Checked|x64 @@ -182,6 +232,9 @@ Global {740CDFF4-B8EC-4A37-951B-C9FE9980EF2A}.Release|x64.Build.0 = Release|x64 {740CDFF4-B8EC-4A37-951B-C9FE9980EF2A}.Release|x86.ActiveCfg = Release|Any CPU {740CDFF4-B8EC-4A37-951B-C9FE9980EF2A}.Release|x86.Build.0 = Release|Any CPU + {740CDFF4-B8EC-4A37-951B-C9FE9980EF2A}.RelWithDebInfo|Any CPU.ActiveCfg = Release|Any CPU + {740CDFF4-B8EC-4A37-951B-C9FE9980EF2A}.RelWithDebInfo|x64.ActiveCfg = Release|x64 + {740CDFF4-B8EC-4A37-951B-C9FE9980EF2A}.RelWithDebInfo|x86.ActiveCfg = Release|Any CPU {4CF2ECD3-A1C3-4A28-AB08-A61C53114143}.Checked|Any CPU.ActiveCfg = Checked|x64 {4CF2ECD3-A1C3-4A28-AB08-A61C53114143}.Checked|Any CPU.Build.0 = Checked|x64 {4CF2ECD3-A1C3-4A28-AB08-A61C53114143}.Checked|x64.ActiveCfg = Checked|x64 @@ -200,6 +253,9 @@ Global {4CF2ECD3-A1C3-4A28-AB08-A61C53114143}.Release|x64.Build.0 = Release|x64 {4CF2ECD3-A1C3-4A28-AB08-A61C53114143}.Release|x86.ActiveCfg = Release|x86 {4CF2ECD3-A1C3-4A28-AB08-A61C53114143}.Release|x86.Build.0 = Release|x86 + {4CF2ECD3-A1C3-4A28-AB08-A61C53114143}.RelWithDebInfo|Any CPU.ActiveCfg = Release|x64 + {4CF2ECD3-A1C3-4A28-AB08-A61C53114143}.RelWithDebInfo|x64.ActiveCfg = Release|x64 + {4CF2ECD3-A1C3-4A28-AB08-A61C53114143}.RelWithDebInfo|x86.ActiveCfg = Release|x86 {9DA153BF-51C4-4AD7-A355-9F9528843DC7}.Checked|Any CPU.ActiveCfg = Debug|Any CPU {9DA153BF-51C4-4AD7-A355-9F9528843DC7}.Checked|Any CPU.Build.0 = Debug|Any CPU {9DA153BF-51C4-4AD7-A355-9F9528843DC7}.Checked|x64.ActiveCfg = Debug|Any CPU @@ -218,6 +274,9 @@ Global {9DA153BF-51C4-4AD7-A355-9F9528843DC7}.Release|x64.Build.0 = Release|Any CPU {9DA153BF-51C4-4AD7-A355-9F9528843DC7}.Release|x86.ActiveCfg = Release|Any CPU {9DA153BF-51C4-4AD7-A355-9F9528843DC7}.Release|x86.Build.0 = Release|Any CPU + {9DA153BF-51C4-4AD7-A355-9F9528843DC7}.RelWithDebInfo|Any CPU.ActiveCfg = Release|Any CPU + {9DA153BF-51C4-4AD7-A355-9F9528843DC7}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU + {9DA153BF-51C4-4AD7-A355-9F9528843DC7}.RelWithDebInfo|x86.ActiveCfg = Release|Any CPU {219E0AC3-CDBF-4104-B324-85915DD16E25}.Checked|Any CPU.ActiveCfg = Debug|Any CPU {219E0AC3-CDBF-4104-B324-85915DD16E25}.Checked|Any CPU.Build.0 = Debug|Any CPU {219E0AC3-CDBF-4104-B324-85915DD16E25}.Checked|x64.ActiveCfg = Debug|Any CPU @@ -236,6 +295,45 @@ Global {219E0AC3-CDBF-4104-B324-85915DD16E25}.Release|x64.Build.0 = Release|Any CPU {219E0AC3-CDBF-4104-B324-85915DD16E25}.Release|x86.ActiveCfg = Release|Any CPU {219E0AC3-CDBF-4104-B324-85915DD16E25}.Release|x86.Build.0 = Release|Any CPU + {219E0AC3-CDBF-4104-B324-85915DD16E25}.RelWithDebInfo|Any CPU.ActiveCfg = Release|Any CPU + {219E0AC3-CDBF-4104-B324-85915DD16E25}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU + {219E0AC3-CDBF-4104-B324-85915DD16E25}.RelWithDebInfo|x86.ActiveCfg = Release|Any CPU + {74666FB9-0C0D-3452-A912-3D571F908AA8}.Checked|Any CPU.ActiveCfg = Checked|x64 + {74666FB9-0C0D-3452-A912-3D571F908AA8}.Checked|Any CPU.Build.0 = Checked|x64 + {74666FB9-0C0D-3452-A912-3D571F908AA8}.Checked|Any CPU.Deploy.0 = Checked|x64 + {74666FB9-0C0D-3452-A912-3D571F908AA8}.Checked|x64.ActiveCfg = Checked|x64 + {74666FB9-0C0D-3452-A912-3D571F908AA8}.Checked|x64.Build.0 = Checked|x64 + {74666FB9-0C0D-3452-A912-3D571F908AA8}.Checked|x64.Deploy.0 = Checked|x64 + {74666FB9-0C0D-3452-A912-3D571F908AA8}.Checked|x86.ActiveCfg = Checked|x64 + {74666FB9-0C0D-3452-A912-3D571F908AA8}.Checked|x86.Build.0 = Checked|x64 + {74666FB9-0C0D-3452-A912-3D571F908AA8}.Checked|x86.Deploy.0 = Checked|x64 + {74666FB9-0C0D-3452-A912-3D571F908AA8}.Debug|Any CPU.ActiveCfg = Debug|x64 + {74666FB9-0C0D-3452-A912-3D571F908AA8}.Debug|Any CPU.Build.0 = Debug|x64 + {74666FB9-0C0D-3452-A912-3D571F908AA8}.Debug|Any CPU.Deploy.0 = Debug|x64 + {74666FB9-0C0D-3452-A912-3D571F908AA8}.Debug|x64.ActiveCfg = Debug|x64 + {74666FB9-0C0D-3452-A912-3D571F908AA8}.Debug|x64.Build.0 = Debug|x64 + {74666FB9-0C0D-3452-A912-3D571F908AA8}.Debug|x64.Deploy.0 = Debug|x64 + {74666FB9-0C0D-3452-A912-3D571F908AA8}.Debug|x86.ActiveCfg = Debug|x64 + {74666FB9-0C0D-3452-A912-3D571F908AA8}.Debug|x86.Build.0 = Debug|x64 + {74666FB9-0C0D-3452-A912-3D571F908AA8}.Debug|x86.Deploy.0 = Debug|x64 + {74666FB9-0C0D-3452-A912-3D571F908AA8}.Release|Any CPU.ActiveCfg = Release|x64 + {74666FB9-0C0D-3452-A912-3D571F908AA8}.Release|Any CPU.Build.0 = Release|x64 + {74666FB9-0C0D-3452-A912-3D571F908AA8}.Release|Any CPU.Deploy.0 = Release|x64 + {74666FB9-0C0D-3452-A912-3D571F908AA8}.Release|x64.ActiveCfg = Release|x64 + {74666FB9-0C0D-3452-A912-3D571F908AA8}.Release|x64.Build.0 = Release|x64 + {74666FB9-0C0D-3452-A912-3D571F908AA8}.Release|x64.Deploy.0 = Release|x64 + {74666FB9-0C0D-3452-A912-3D571F908AA8}.Release|x86.ActiveCfg = Release|x64 + {74666FB9-0C0D-3452-A912-3D571F908AA8}.Release|x86.Build.0 = Release|x64 + {74666FB9-0C0D-3452-A912-3D571F908AA8}.Release|x86.Deploy.0 = Release|x64 + {74666FB9-0C0D-3452-A912-3D571F908AA8}.RelWithDebInfo|Any CPU.ActiveCfg = RelWithDebInfo|x64 + {74666FB9-0C0D-3452-A912-3D571F908AA8}.RelWithDebInfo|Any CPU.Build.0 = RelWithDebInfo|x64 + {74666FB9-0C0D-3452-A912-3D571F908AA8}.RelWithDebInfo|Any CPU.Deploy.0 = RelWithDebInfo|x64 + {74666FB9-0C0D-3452-A912-3D571F908AA8}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64 + {74666FB9-0C0D-3452-A912-3D571F908AA8}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64 + {74666FB9-0C0D-3452-A912-3D571F908AA8}.RelWithDebInfo|x64.Deploy.0 = RelWithDebInfo|x64 + {74666FB9-0C0D-3452-A912-3D571F908AA8}.RelWithDebInfo|x86.ActiveCfg = RelWithDebInfo|x64 + {74666FB9-0C0D-3452-A912-3D571F908AA8}.RelWithDebInfo|x86.Build.0 = RelWithDebInfo|x64 + {74666FB9-0C0D-3452-A912-3D571F908AA8}.RelWithDebInfo|x86.Deploy.0 = RelWithDebInfo|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/coreclr/tools/aot/jitinterface/jitinterface_generated.h b/src/coreclr/tools/aot/jitinterface/jitinterface_generated.h index b41972f2d0020a..9a3cf39d8b936b 100644 --- a/src/coreclr/tools/aot/jitinterface/jitinterface_generated.h +++ b/src/coreclr/tools/aot/jitinterface/jitinterface_generated.h @@ -105,6 +105,7 @@ struct JitInterfaceCallbacks void (* getFieldInfo)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_RESOLVED_TOKEN* pResolvedToken, CORINFO_METHOD_HANDLE callerHandle, CORINFO_ACCESS_FLAGS flags, CORINFO_FIELD_INFO* pResult); uint32_t (* getThreadLocalFieldInfo)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_FIELD_HANDLE field, bool isGCtype); void (* getThreadLocalStaticBlocksInfo)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_THREAD_STATIC_BLOCKS_INFO* pInfo, bool isGCType); + void (* getThreadLocalStaticInfo_ReadyToRun)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_THREAD_STATIC_INFO_READYTORUN* pInfo, CORINFO_CLASS_HANDLE cls); void (* getTlsRootInfo)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_CONST_LOOKUP* addr); void (* getTlsIndexInfo)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_CONST_LOOKUP* addr); void (* getThreadStaticBaseSlowInfo)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_CONST_LOOKUP* addr); @@ -1119,6 +1120,15 @@ class JitInterfaceWrapper : public ICorJitInfo if (pException != nullptr) throw pException; } + virtual void getThreadLocalStaticInfo_ReadyToRun( + CORINFO_THREAD_STATIC_INFO_READYTORUN* pInfo, + CORINFO_CLASS_HANDLE cls) +{ + CorInfoExceptionClass* pException = nullptr; + _callbacks->getThreadLocalStaticInfo_ReadyToRun(_thisHandle, &pException, pInfo, cls); + if (pException != nullptr) throw pException; +} + virtual void getTlsRootInfo( CORINFO_CONST_LOOKUP* addr) { diff --git a/src/coreclr/tools/superpmi/superpmi-shared/agnostic.h b/src/coreclr/tools/superpmi/superpmi-shared/agnostic.h index d5e596f667b308..72f3b5c4fd0eb3 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/agnostic.h +++ b/src/coreclr/tools/superpmi/superpmi-shared/agnostic.h @@ -539,6 +539,17 @@ struct Agnostic_GetThreadLocalStaticBlocksInfo DWORD offsetOfGCDataPointer; }; +struct Agnostic_GetThreadStaticInfo_ReadyToRun +{ + DWORD offsetOfThreadLocalStoragePointer; + Agnostic_CORINFO_CONST_LOOKUP tlsRootObject; + Agnostic_CORINFO_CONST_LOOKUP tlsIndexObject; + Agnostic_CORINFO_CONST_LOOKUP threadStaticBaseSlow; + DWORD classCtorContextSize; + Agnostic_CORINFO_CONST_LOOKUP lazyCtorRunHelper; + Agnostic_CORINFO_CONST_LOOKUP lazyCtorTargetSymbol; +}; + struct Agnostic_GetClassCtorInitializationInfo { Agnostic_CORINFO_CONST_LOOKUP addr; diff --git a/src/coreclr/tools/superpmi/superpmi-shared/lwmlist.h b/src/coreclr/tools/superpmi/superpmi-shared/lwmlist.h index 1d8f2869a06d98..c84b933523ea59 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/lwmlist.h +++ b/src/coreclr/tools/superpmi/superpmi-shared/lwmlist.h @@ -39,6 +39,7 @@ LWM(EmbedMethodHandle, DWORDLONG, DLDL) LWM(EmbedModuleHandle, DWORDLONG, DLDL) LWM(GetThreadLocalFieldInfo, DLD, DWORD) LWM(GetThreadLocalStaticBlocksInfo, DWORD, Agnostic_GetThreadLocalStaticBlocksInfo) +LWM(GetThreadLocalStaticInfo_ReadyToRun, DWORDLONG, Agnostic_GetThreadStaticInfo_ReadyToRun) LWM(GetTlsRootInfo, DWORD, Agnostic_CORINFO_CONST_LOOKUP) LWM(GetTlsIndexInfo, DWORD, Agnostic_CORINFO_CONST_LOOKUP) LWM(GetThreadStaticBaseSlowInfo, DWORD, Agnostic_CORINFO_CONST_LOOKUP) diff --git a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp index a5f63ca486cdb0..4609691ef44ce6 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp @@ -3740,6 +3740,59 @@ void MethodContext::repGetThreadLocalStaticBlocksInfo(CORINFO_THREAD_STATIC_BLOC pInfo->offsetOfGCDataPointer = value.offsetOfGCDataPointer; } +void MethodContext::recGetThreadLocalStaticInfo_ReadyToRun(CORINFO_THREAD_STATIC_INFO_READYTORUN* pInfo, + CORINFO_CLASS_HANDLE cls) +{ + if (GetThreadLocalStaticInfo_ReadyToRun == nullptr) + GetThreadLocalStaticInfo_ReadyToRun = new LightWeightMap(); + + Agnostic_GetThreadStaticInfo_ReadyToRun value; + ZeroMemory(&value, sizeof(value)); + value.tlsRootObject = SpmiRecordsHelper::StoreAgnostic_CORINFO_CONST_LOOKUP(&pInfo->tlsRootObject); + value.tlsIndexObject = SpmiRecordsHelper::StoreAgnostic_CORINFO_CONST_LOOKUP(&pInfo->tlsIndexObject); + value.offsetOfThreadLocalStoragePointer = pInfo->offsetOfThreadLocalStoragePointer; + value.threadStaticBaseSlow = SpmiRecordsHelper::StoreAgnostic_CORINFO_CONST_LOOKUP(&pInfo->threadStaticBaseSlow); + value.lazyCtorRunHelper = SpmiRecordsHelper::StoreAgnostic_CORINFO_CONST_LOOKUP(&pInfo->lazyCtorRunHelper); + value.lazyCtorTargetSymbol = SpmiRecordsHelper::StoreAgnostic_CORINFO_CONST_LOOKUP(&pInfo->lazyCtorTargetSymbol); + value.classCtorContextSize = pInfo->classCtorContextSize; + + DWORDLONG key = CastHandle(cls); + + GetThreadLocalStaticInfo_ReadyToRun->Add(key, value); + DEBUG_REC(dmpGetThreadLocalStaticInfo_ReadyToRun(key, result)); +} +void MethodContext::dmpGetThreadLocalStaticInfo_ReadyToRun(DWORDLONG key, + const Agnostic_GetThreadStaticInfo_ReadyToRun& value) +{ + printf("GetThreadLocalStaticInfo_ReadyToRun key %016" PRIX64 ", tlsRootObject-%s, tlsIndexObject-%s, offsetOfThreadLocalStoragePointer-%u, " + "threadStaticBaseSlow-%s, lazyCtorRunHelper-%s, lazyCtorTargetSymbol-%s, classCtorContextSize-%u", + key, SpmiDumpHelper::DumpAgnostic_CORINFO_CONST_LOOKUP(value.tlsRootObject).c_str(), + SpmiDumpHelper::DumpAgnostic_CORINFO_CONST_LOOKUP(value.tlsIndexObject).c_str(), + value.offsetOfThreadLocalStoragePointer, + SpmiDumpHelper::DumpAgnostic_CORINFO_CONST_LOOKUP(value.threadStaticBaseSlow).c_str(), + SpmiDumpHelper::DumpAgnostic_CORINFO_CONST_LOOKUP(value.lazyCtorRunHelper).c_str(), + SpmiDumpHelper::DumpAgnostic_CORINFO_CONST_LOOKUP(value.lazyCtorTargetSymbol).c_str(), + value.classCtorContextSize); +} + +void MethodContext::repGetThreadLocalStaticInfo_ReadyToRun(CORINFO_THREAD_STATIC_INFO_READYTORUN* pInfo, + CORINFO_CLASS_HANDLE cls) +{ + DWORDLONG key = CastHandle(cls); + Agnostic_GetThreadStaticInfo_ReadyToRun value = + LookupByKeyOrMiss(GetThreadLocalStaticInfo_ReadyToRun, key, ": key %016" PRIX64 "", key); + + DEBUG_REP(dmpGetThreadLocalStaticInfo_ReadyToRun(key, value)); + + pInfo->tlsRootObject = SpmiRecordsHelper::RestoreCORINFO_CONST_LOOKUP(value.tlsRootObject); + pInfo->tlsIndexObject = SpmiRecordsHelper::RestoreCORINFO_CONST_LOOKUP(value.tlsIndexObject); + pInfo->offsetOfThreadLocalStoragePointer = value.offsetOfThreadLocalStoragePointer; + pInfo->threadStaticBaseSlow = SpmiRecordsHelper::RestoreCORINFO_CONST_LOOKUP(value.threadStaticBaseSlow); + pInfo->lazyCtorRunHelper = SpmiRecordsHelper::RestoreCORINFO_CONST_LOOKUP(value.lazyCtorRunHelper); + pInfo->lazyCtorTargetSymbol = SpmiRecordsHelper::RestoreCORINFO_CONST_LOOKUP(value.lazyCtorTargetSymbol); + pInfo->classCtorContextSize = value.classCtorContextSize; +} + void MethodContext::recEmbedMethodHandle(CORINFO_METHOD_HANDLE handle, void** ppIndirection, CORINFO_METHOD_HANDLE result) diff --git a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h index 0b53346b58cf01..502aa80804f1c5 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h +++ b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h @@ -474,6 +474,10 @@ class MethodContext void dmpGetThreadLocalStaticBlocksInfo(DWORD key, const Agnostic_GetThreadLocalStaticBlocksInfo& value); void repGetThreadLocalStaticBlocksInfo(CORINFO_THREAD_STATIC_BLOCKS_INFO* pInfo, bool isGCType); + void recGetThreadLocalStaticInfo_ReadyToRun(CORINFO_THREAD_STATIC_INFO_READYTORUN* pInfo, CORINFO_CLASS_HANDLE cls); + void dmpGetThreadLocalStaticInfo_ReadyToRun(DWORDLONG key, const Agnostic_GetThreadStaticInfo_ReadyToRun& value); + void repGetThreadLocalStaticInfo_ReadyToRun(CORINFO_THREAD_STATIC_INFO_READYTORUN* pInfo, CORINFO_CLASS_HANDLE cls); + void recGetTlsRootInfo(CORINFO_CONST_LOOKUP* result); void dmpGetTlsRootInfo(DWORD key, const Agnostic_CORINFO_CONST_LOOKUP& value); void repGetTlsRootInfo(CORINFO_CONST_LOOKUP* addr); @@ -1151,13 +1155,14 @@ enum mcPackets Packet_GetStaticBaseAddress = 206, Packet_GetThreadLocalFieldInfo = 207, Packet_GetThreadLocalStaticBlocksInfo = 208, - Packet_GetTlsRootInfo = 209, - Packet_GetTlsIndexInfo = 210, - Packet_GetThreadStaticBaseSlowInfo = 211, - Packet_GetEnsureClassCtorRunAndReturnThreadStaticBaseHelper = 212, - Packet_GetRISCV64PassStructInRegisterFlags = 213, - Packet_GetObjectContent = 214, - Packet_GetTypeLayout = 215, + Packet_GetThreadLocalStaticInfo_ReadyToRun = 209, + Packet_GetTlsRootInfo = 210, + Packet_GetTlsIndexInfo = 211, + Packet_GetThreadStaticBaseSlowInfo = 212, + Packet_GetEnsureClassCtorRunAndReturnThreadStaticBaseHelper = 213, + Packet_GetRISCV64PassStructInRegisterFlags = 214, + Packet_GetObjectContent = 215, + Packet_GetTypeLayout = 216, }; void SetDebugDumpVariables(); diff --git a/src/coreclr/tools/superpmi/superpmi-shim-collector/icorjitinfo.cpp b/src/coreclr/tools/superpmi/superpmi-shim-collector/icorjitinfo.cpp index 1d8874a71dda2f..9ef9944ac0b448 100644 --- a/src/coreclr/tools/superpmi/superpmi-shim-collector/icorjitinfo.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shim-collector/icorjitinfo.cpp @@ -1047,6 +1047,14 @@ void interceptor_ICJI::getThreadLocalStaticBlocksInfo(CORINFO_THREAD_STATIC_BLOC mc->recGetThreadLocalStaticBlocksInfo(pInfo, isGCType); } +void interceptor_ICJI::getThreadLocalStaticInfo_ReadyToRun(CORINFO_THREAD_STATIC_INFO_READYTORUN* pInfo, + CORINFO_CLASS_HANDLE cls) +{ + mc->cr->AddCall("getThreadLocalStaticInfo_ReadyToRun"); + original_ICorJitInfo->getThreadLocalStaticInfo_ReadyToRun(pInfo, cls); + mc->recGetThreadLocalStaticInfo_ReadyToRun(pInfo, cls); +} + void interceptor_ICJI::getTlsRootInfo(CORINFO_CONST_LOOKUP* pInfo) { mc->cr->AddCall("getTlsRootInfo"); diff --git a/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo_generated.cpp b/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo_generated.cpp index e34863c6a91be0..696101451b29ff 100644 --- a/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo_generated.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo_generated.cpp @@ -763,6 +763,14 @@ void interceptor_ICJI::getThreadLocalStaticBlocksInfo( original_ICorJitInfo->getThreadLocalStaticBlocksInfo(pInfo, isGCType); } +void interceptor_ICJI::getThreadLocalStaticInfo_ReadyToRun( + CORINFO_THREAD_STATIC_INFO_READYTORUN* pInfo, + CORINFO_CLASS_HANDLE cls) +{ + mcs->AddCall("getThreadLocalStaticInfo_ReadyToRun"); + original_ICorJitInfo->getThreadLocalStaticInfo_ReadyToRun(pInfo, cls); +} + void interceptor_ICJI::getTlsRootInfo( CORINFO_CONST_LOOKUP* addr) { diff --git a/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo_generated.cpp b/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo_generated.cpp index d8af9047645d2c..634fc6e56f274d 100644 --- a/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo_generated.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo_generated.cpp @@ -669,6 +669,13 @@ void interceptor_ICJI::getThreadLocalStaticBlocksInfo( original_ICorJitInfo->getThreadLocalStaticBlocksInfo(pInfo, isGCType); } +void interceptor_ICJI::getThreadLocalStaticInfo_ReadyToRun( + CORINFO_THREAD_STATIC_INFO_READYTORUN* pInfo, + CORINFO_CLASS_HANDLE cls) +{ + original_ICorJitInfo->getThreadLocalStaticInfo_ReadyToRun(pInfo, cls); +} + void interceptor_ICJI::getTlsRootInfo( CORINFO_CONST_LOOKUP* addr) { diff --git a/src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp b/src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp index 8be3dbeb13de2e..34224d8413c0d5 100644 --- a/src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp +++ b/src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp @@ -878,6 +878,12 @@ void MyICJI::getThreadLocalStaticBlocksInfo(CORINFO_THREAD_STATIC_BLOCKS_INFO* p jitInstance->mc->repGetThreadLocalStaticBlocksInfo(pInfo, isGCType); } +void MyICJI::getThreadLocalStaticInfo_ReadyToRun(CORINFO_THREAD_STATIC_INFO_READYTORUN* pInfo, CORINFO_CLASS_HANDLE cls) +{ + jitInstance->mc->cr->AddCall("getThreadLocalStaticInfo_ReadyToRun"); + jitInstance->mc->repGetThreadLocalStaticInfo_ReadyToRun(pInfo, cls); +} + void MyICJI::getTlsRootInfo(CORINFO_CONST_LOOKUP* pInfo) { jitInstance->mc->cr->AddCall("getTlsRootInfo"); diff --git a/src/coreclr/vm/jitinterface.cpp b/src/coreclr/vm/jitinterface.cpp index cedc54c220a73a..486906b87b2d2a 100644 --- a/src/coreclr/vm/jitinterface.cpp +++ b/src/coreclr/vm/jitinterface.cpp @@ -1309,6 +1309,12 @@ static CorInfoHelpFunc getInstanceFieldHelper(FieldDesc * pField, CORINFO_ACCESS /*********************************************************************/ +void CEEInfo::getThreadLocalStaticInfo_ReadyToRun(CORINFO_THREAD_STATIC_INFO_READYTORUN* pInfo, CORINFO_CLASS_HANDLE cls) +{ + LIMITED_METHOD_CONTRACT; + UNREACHABLE(); // only called with NativeAOT. +} + void CEEInfo::getTlsRootInfo(CORINFO_CONST_LOOKUP* addr) { LIMITED_METHOD_CONTRACT; From 800005de7bc182d4e51fb23466f7a00064098404 Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Sat, 29 Jul 2023 02:55:22 -0700 Subject: [PATCH 16/58] Consume getThreadLocalStaticInfo_ReadyToRun() --- src/coreclr/jit/helperexpansion.cpp | 52 ++++++++++++++--------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/src/coreclr/jit/helperexpansion.cpp b/src/coreclr/jit/helperexpansion.cpp index 4397590cf5be3c..94081dedd05f81 100644 --- a/src/coreclr/jit/helperexpansion.cpp +++ b/src/coreclr/jit/helperexpansion.cpp @@ -464,6 +464,19 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S call->ClearExpTLSFieldAccess(); call->ClearExpTLSFieldAccessLazyCtor(); + CORINFO_THREAD_STATIC_INFO_READYTORUN threadStaticInfo; + memset(&threadStaticInfo, 0, sizeof(CORINFO_THREAD_STATIC_INFO_READYTORUN)); + + info.compCompHnd->getThreadLocalStaticInfo_ReadyToRun(&threadStaticInfo, call->gtInitClsHnd); + + JITDUMP("tlsRootObject= %p\n", dspPtr(threadStaticInfo.tlsRootObject.addr)); + JITDUMP("tlsIndexObject= %p\n", dspPtr(threadStaticInfo.tlsIndexObject.addr)); + JITDUMP("offsetOfThreadLocalStoragePointer= %u\n", dspOffset(threadStaticInfo.offsetOfThreadLocalStoragePointer)); + JITDUMP("threadStaticBaseSlow= %p\n", dspPtr(threadStaticInfo.threadStaticBaseSlow.addr)); + JITDUMP("classCtorContextSize= %u\n", threadStaticInfo.classCtorContextSize); + JITDUMP("lazyCtorRunHelper= %p\n", dspPtr(threadStaticInfo.lazyCtorRunHelper.addr)); + JITDUMP("lazyCtorTargetSymbol= %p\n", dspPtr(threadStaticInfo.lazyCtorTargetSymbol.addr)); + // Split block right before the call tree BasicBlock* prevBb = block; GenTree** callUse = nullptr; @@ -511,17 +524,14 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S if (hasLazyStaticCtor) { - CORINFO_CONST_LOOKUP classCtorRunHelper; - CORINFO_CONST_LOOKUP targetSymbol; - memset(&classCtorRunHelper, 0, sizeof(CORINFO_CONST_LOOKUP)); - memset(&targetSymbol, 0, sizeof(CORINFO_CONST_LOOKUP)); - int size = - info.compCompHnd->getEnsureClassCtorRunAndReturnThreadStaticBaseHelper(call->gtInitClsHnd, - &classCtorRunHelper, &targetSymbol); + CORINFO_CONST_LOOKUP lazyCtorRunHelper = threadStaticInfo.lazyCtorRunHelper; + CORINFO_CONST_LOOKUP lazyCtorTargetSymbol = threadStaticInfo.lazyCtorTargetSymbol; + int classCtorContextSize = threadStaticInfo.classCtorContextSize; // target symbol - GenTree* targetSymbolAddr = gtNewIconHandleNode((size_t)targetSymbol.addr, GTF_ICON_OBJ_HDL); - targetSymbolAddr = gtNewOperNode(GT_ADD, TYP_I_IMPL, targetSymbolAddr, gtNewIconNode(size, TYP_I_IMPL)); + GenTree* targetSymbolAddr = gtNewIconHandleNode((size_t)lazyCtorTargetSymbol.addr, GTF_ICON_OBJ_HDL); + targetSymbolAddr = + gtNewOperNode(GT_ADD, TYP_I_IMPL, targetSymbolAddr, gtNewIconNode(classCtorContextSize, TYP_I_IMPL)); targetSymbCondBB = fgNewBBFromTreeAfter(BBJ_COND, prevBb, gtCloneExpr(targetSymbolAddr), debugInfo); GenTree* targetSymbolAddrVal = gtNewIndir(TYP_I_IMPL, targetSymbolAddr); @@ -531,7 +541,7 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S fgInsertStmtAfter(targetSymbCondBB, targetSymbCondBB->firstStmt(), fgNewStmtFromTree(targetSymbolNullCond)); GenTreeCall* classCtorRunHelperCall = - gtNewIndCallNode(gtNewIconHandleNode((size_t)classCtorRunHelper.addr, GTF_ICON_FTN_ADDR), TYP_I_IMPL); + gtNewIndCallNode(gtNewIconHandleNode((size_t)lazyCtorRunHelper.addr, GTF_ICON_FTN_ADDR), TYP_I_IMPL); // arg0: unused classCtorRunHelperCall->gtArgs.PushBack(this, NewCallArg::Primitive(gtNewIconNode(0))); @@ -585,18 +595,12 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S lvaTable[tlsLclNum].lvType = TYP_I_IMPL; // Mark this ICON as a TLS_HDL, codegen will use FS:[cns] or GS:[cns] - uint32_t offsetOfThreadLocalStoragePointer = 0; -#ifdef _MSC_VER - offsetOfThreadLocalStoragePointer = offsetof(_TEB, ThreadLocalStoragePointer); -#endif - tlsValue = gtNewIconHandleNode(offsetOfThreadLocalStoragePointer, GTF_ICON_TLS_HDL); + tlsValue = gtNewIconHandleNode(threadStaticInfo.offsetOfThreadLocalStoragePointer, GTF_ICON_TLS_HDL); tlsValue = gtNewIndir(TYP_I_IMPL, tlsValue, GTF_IND_NONFAULTING | GTF_IND_INVARIANT); - CORINFO_CONST_LOOKUP tlsIndexValue; - memset(&tlsIndexValue, 0, sizeof(CORINFO_CONST_LOOKUP)); - info.compCompHnd->getTlsIndexInfo(&tlsIndexValue); + CORINFO_CONST_LOOKUP tlsIndexObject = threadStaticInfo.tlsIndexObject; - GenTree* dllRef = gtNewIconHandleNode((size_t)tlsIndexValue.handle, GTF_ICON_OBJ_HDL); + GenTree* dllRef = gtNewIconHandleNode((size_t)tlsIndexObject.handle, GTF_ICON_OBJ_HDL); dllRef = gtNewIndir(TYP_UINT, dllRef, GTF_IND_NONFAULTING | GTF_IND_INVARIANT); dllRef = gtNewOperNode(GT_MUL, TYP_I_IMPL, dllRef, gtNewIconNode(TARGET_POINTER_SIZE, TYP_INT)); @@ -606,11 +610,9 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S // Base of coreclr's thread local storage tlsValue = gtNewIndir(TYP_I_IMPL, tlsValue, GTF_IND_NONFAULTING | GTF_IND_INVARIANT); - CORINFO_CONST_LOOKUP tlsRootNode; - memset(&tlsRootNode, 0, sizeof(CORINFO_CONST_LOOKUP)); - info.compCompHnd->getTlsRootInfo(&tlsRootNode); + CORINFO_CONST_LOOKUP tlsRootObject = threadStaticInfo.tlsRootObject; - GenTree* tlsRootOffset = gtNewIconNode((size_t)tlsRootNode.handle, TYP_INT); + GenTree* tlsRootOffset = gtNewIconNode((size_t)tlsRootObject.handle, TYP_INT); tlsRootOffset->gtFlags |= GTF_ICON_SECREL_OFFSET; // Add the tlsValue and tlsRootOffset to produce tlsRootAddr. @@ -634,9 +636,7 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S fgInsertStmtAfter(tlsRootNullCondBB, tlsRootNullCondBB->firstStmt(), fgNewStmtFromTree(tlsRootNullCond)); fgInsertStmtAfter(tlsRootNullCondBB, tlsRootNullCondBB->firstStmt(), fgNewStmtFromTree(tlsRootDef)); - CORINFO_CONST_LOOKUP threadStaticSlowHelper; - memset(&threadStaticSlowHelper, 0, sizeof(CORINFO_CONST_LOOKUP)); - info.compCompHnd->getThreadStaticBaseSlowInfo(&threadStaticSlowHelper); + CORINFO_CONST_LOOKUP threadStaticSlowHelper = threadStaticInfo.threadStaticBaseSlow; GenTreeCall* slowHelper = gtNewIndCallNode(gtNewIconHandleNode((size_t)threadStaticSlowHelper.addr, GTF_ICON_TLS_HDL), TYP_I_IMPL); From 476621158b5af9bd005df6ddf5c8bcf4be03a0a7 Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Sat, 29 Jul 2023 03:04:23 -0700 Subject: [PATCH 17/58] Remove getTlsRootInfo() and other methods --- src/coreclr/inc/corinfo.h | 5 - src/coreclr/inc/icorjitinfoimpl_generated.h | 14 -- src/coreclr/jit/ICorJitInfo_names_generated.h | 4 - .../jit/ICorJitInfo_wrapper_generated.hpp | 35 --- .../JitInterface/CorInfoImpl_generated.cs | 213 +++++++----------- .../ThunkGenerator/ThunkInput.txt | 4 - .../JitInterface/CorInfoImpl.ReadyToRun.cs | 22 -- .../JitInterface/CorInfoImpl.RyuJit.cs | 28 --- .../aot/jitinterface/jitinterface_generated.h | 39 ---- .../tools/superpmi/superpmi-shared/lwmlist.h | 4 - .../superpmi-shared/methodcontext.cpp | 118 ---------- .../superpmi/superpmi-shared/methodcontext.h | 31 +-- .../superpmi-shim-collector/icorjitinfo.cpp | 31 --- .../icorjitinfo_generated.cpp | 30 --- .../icorjitinfo_generated.cpp | 26 --- .../tools/superpmi/superpmi/icorjitinfo.cpp | 26 --- src/coreclr/vm/jitinterface.cpp | 24 -- 17 files changed, 79 insertions(+), 575 deletions(-) diff --git a/src/coreclr/inc/corinfo.h b/src/coreclr/inc/corinfo.h index b2ef0e7c4dfe99..5c334fa7adbe22 100644 --- a/src/coreclr/inc/corinfo.h +++ b/src/coreclr/inc/corinfo.h @@ -2809,11 +2809,6 @@ class ICorStaticInfo CORINFO_CLASS_HANDLE cls ) = 0; - virtual void getTlsRootInfo(CORINFO_CONST_LOOKUP* addr) = 0; - virtual void getTlsIndexInfo(CORINFO_CONST_LOOKUP* addr) = 0; - virtual void getThreadStaticBaseSlowInfo(CORINFO_CONST_LOOKUP* addr) = 0; - virtual int getEnsureClassCtorRunAndReturnThreadStaticBaseHelper(CORINFO_CLASS_HANDLE cls, CORINFO_CONST_LOOKUP* addr, CORINFO_CONST_LOOKUP* targetSymbol) = 0; - // Returns true iff "fldHnd" represents a static field. virtual bool isFieldStatic(CORINFO_FIELD_HANDLE fldHnd) = 0; diff --git a/src/coreclr/inc/icorjitinfoimpl_generated.h b/src/coreclr/inc/icorjitinfoimpl_generated.h index b784b1793548ec..417dbb7b889eb5 100644 --- a/src/coreclr/inc/icorjitinfoimpl_generated.h +++ b/src/coreclr/inc/icorjitinfoimpl_generated.h @@ -400,20 +400,6 @@ void getThreadLocalStaticInfo_ReadyToRun( CORINFO_THREAD_STATIC_INFO_READYTORUN* pInfo, CORINFO_CLASS_HANDLE cls) override; -void getTlsRootInfo( - CORINFO_CONST_LOOKUP* addr) override; - -void getTlsIndexInfo( - CORINFO_CONST_LOOKUP* addr) override; - -void getThreadStaticBaseSlowInfo( - CORINFO_CONST_LOOKUP* addr) override; - -int getEnsureClassCtorRunAndReturnThreadStaticBaseHelper( - CORINFO_CLASS_HANDLE cls, - CORINFO_CONST_LOOKUP* addr, - CORINFO_CONST_LOOKUP* targetSymbol) override; - bool isFieldStatic( CORINFO_FIELD_HANDLE fldHnd) override; diff --git a/src/coreclr/jit/ICorJitInfo_names_generated.h b/src/coreclr/jit/ICorJitInfo_names_generated.h index 33d07c0f2622b9..2ed117e277eeb3 100644 --- a/src/coreclr/jit/ICorJitInfo_names_generated.h +++ b/src/coreclr/jit/ICorJitInfo_names_generated.h @@ -99,10 +99,6 @@ DEF_CLR_API(getFieldInfo) DEF_CLR_API(getThreadLocalFieldInfo) DEF_CLR_API(getThreadLocalStaticBlocksInfo) DEF_CLR_API(getThreadLocalStaticInfo_ReadyToRun) -DEF_CLR_API(getTlsRootInfo) -DEF_CLR_API(getTlsIndexInfo) -DEF_CLR_API(getThreadStaticBaseSlowInfo) -DEF_CLR_API(getEnsureClassCtorRunAndReturnThreadStaticBaseHelper) DEF_CLR_API(isFieldStatic) DEF_CLR_API(getArrayOrStringLength) DEF_CLR_API(getBoundaries) diff --git a/src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp b/src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp index 14d57fa7cd34ad..cb000867b1b469 100644 --- a/src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp +++ b/src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp @@ -941,41 +941,6 @@ void WrapICorJitInfo::getThreadLocalStaticInfo_ReadyToRun( API_LEAVE(getThreadLocalStaticInfo_ReadyToRun); } -void WrapICorJitInfo::getTlsRootInfo( - CORINFO_CONST_LOOKUP* addr) -{ - API_ENTER(getTlsRootInfo); - wrapHnd->getTlsRootInfo(addr); - API_LEAVE(getTlsRootInfo); -} - -void WrapICorJitInfo::getTlsIndexInfo( - CORINFO_CONST_LOOKUP* addr) -{ - API_ENTER(getTlsIndexInfo); - wrapHnd->getTlsIndexInfo(addr); - API_LEAVE(getTlsIndexInfo); -} - -void WrapICorJitInfo::getThreadStaticBaseSlowInfo( - CORINFO_CONST_LOOKUP* addr) -{ - API_ENTER(getThreadStaticBaseSlowInfo); - wrapHnd->getThreadStaticBaseSlowInfo(addr); - API_LEAVE(getThreadStaticBaseSlowInfo); -} - -int WrapICorJitInfo::getEnsureClassCtorRunAndReturnThreadStaticBaseHelper( - CORINFO_CLASS_HANDLE cls, - CORINFO_CONST_LOOKUP* addr, - CORINFO_CONST_LOOKUP* targetSymbol) -{ - API_ENTER(getEnsureClassCtorRunAndReturnThreadStaticBaseHelper); - int temp = wrapHnd->getEnsureClassCtorRunAndReturnThreadStaticBaseHelper(cls, addr, targetSymbol); - API_LEAVE(getEnsureClassCtorRunAndReturnThreadStaticBaseHelper); - return temp; -} - bool WrapICorJitInfo::isFieldStatic( CORINFO_FIELD_HANDLE fldHnd) { diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs b/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs index 513968ad746ad2..6d7753669a2a5b 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs @@ -1417,63 +1417,6 @@ private static void _getThreadLocalStaticInfo_ReadyToRun(IntPtr thisHandle, IntP } } - [UnmanagedCallersOnly] - private static void _getTlsRootInfo(IntPtr thisHandle, IntPtr* ppException, CORINFO_CONST_LOOKUP* addr) - { - var _this = GetThis(thisHandle); - try - { - _this.getTlsRootInfo(ref *addr); - } - catch (Exception ex) - { - *ppException = _this.AllocException(ex); - } - } - - [UnmanagedCallersOnly] - private static void _getTlsIndexInfo(IntPtr thisHandle, IntPtr* ppException, CORINFO_CONST_LOOKUP* addr) - { - var _this = GetThis(thisHandle); - try - { - _this.getTlsIndexInfo(ref *addr); - } - catch (Exception ex) - { - *ppException = _this.AllocException(ex); - } - } - - [UnmanagedCallersOnly] - private static void _getThreadStaticBaseSlowInfo(IntPtr thisHandle, IntPtr* ppException, CORINFO_CONST_LOOKUP* addr) - { - var _this = GetThis(thisHandle); - try - { - _this.getThreadStaticBaseSlowInfo(ref *addr); - } - catch (Exception ex) - { - *ppException = _this.AllocException(ex); - } - } - - [UnmanagedCallersOnly] - private static int _getEnsureClassCtorRunAndReturnThreadStaticBaseHelper(IntPtr thisHandle, IntPtr* ppException, CORINFO_CLASS_STRUCT_* cls, CORINFO_CONST_LOOKUP* addr, CORINFO_CONST_LOOKUP* targetSymbol) - { - var _this = GetThis(thisHandle); - try - { - return _this.getEnsureClassCtorRunAndReturnThreadStaticBaseHelper(cls, ref *addr, ref *targetSymbol); - } - catch (Exception ex) - { - *ppException = _this.AllocException(ex); - return default; - } - } - [UnmanagedCallersOnly] private static byte _isFieldStatic(IntPtr thisHandle, IntPtr* ppException, CORINFO_FIELD_STRUCT_* fldHnd) { @@ -2578,7 +2521,7 @@ private static uint _getJitFlags(IntPtr thisHandle, IntPtr* ppException, CORJIT_ private static IntPtr GetUnmanagedCallbacks() { - void** callbacks = (void**)Marshal.AllocCoTaskMem(sizeof(IntPtr) * 174); + void** callbacks = (void**)Marshal.AllocCoTaskMem(sizeof(IntPtr) * 170); callbacks[0] = (delegate* unmanaged)&_isIntrinsic; callbacks[1] = (delegate* unmanaged)&_getMethodAttribs; @@ -2675,85 +2618,81 @@ private static IntPtr GetUnmanagedCallbacks() callbacks[92] = (delegate* unmanaged)&_getThreadLocalFieldInfo; callbacks[93] = (delegate* unmanaged)&_getThreadLocalStaticBlocksInfo; callbacks[94] = (delegate* unmanaged)&_getThreadLocalStaticInfo_ReadyToRun; - callbacks[95] = (delegate* unmanaged)&_getTlsRootInfo; - callbacks[96] = (delegate* unmanaged)&_getTlsIndexInfo; - callbacks[97] = (delegate* unmanaged)&_getThreadStaticBaseSlowInfo; - callbacks[98] = (delegate* unmanaged)&_getEnsureClassCtorRunAndReturnThreadStaticBaseHelper; - callbacks[99] = (delegate* unmanaged)&_isFieldStatic; - callbacks[100] = (delegate* unmanaged)&_getArrayOrStringLength; - callbacks[101] = (delegate* unmanaged)&_getBoundaries; - callbacks[102] = (delegate* unmanaged)&_setBoundaries; - callbacks[103] = (delegate* unmanaged)&_getVars; - callbacks[104] = (delegate* unmanaged)&_setVars; - callbacks[105] = (delegate* unmanaged)&_reportRichMappings; - callbacks[106] = (delegate* unmanaged)&_allocateArray; - callbacks[107] = (delegate* unmanaged)&_freeArray; - callbacks[108] = (delegate* unmanaged)&_getArgNext; - callbacks[109] = (delegate* unmanaged)&_getArgType; - callbacks[110] = (delegate* unmanaged)&_getExactClasses; - callbacks[111] = (delegate* unmanaged)&_getArgClass; - callbacks[112] = (delegate* unmanaged)&_getHFAType; - callbacks[113] = (delegate* unmanaged)&_runWithErrorTrap; - callbacks[114] = (delegate* unmanaged)&_runWithSPMIErrorTrap; - callbacks[115] = (delegate* unmanaged)&_getEEInfo; - callbacks[116] = (delegate* unmanaged)&_getJitTimeLogFilename; - callbacks[117] = (delegate* unmanaged)&_getMethodDefFromMethod; - callbacks[118] = (delegate* unmanaged)&_printMethodName; - callbacks[119] = (delegate* unmanaged)&_getMethodNameFromMetadata; - callbacks[120] = (delegate* unmanaged)&_getMethodHash; - callbacks[121] = (delegate* unmanaged)&_getSystemVAmd64PassStructInRegisterDescriptor; - callbacks[122] = (delegate* unmanaged)&_getLoongArch64PassStructInRegisterFlags; - callbacks[123] = (delegate* unmanaged)&_getRISCV64PassStructInRegisterFlags; - callbacks[124] = (delegate* unmanaged)&_getThreadTLSIndex; - callbacks[125] = (delegate* unmanaged)&_getAddrOfCaptureThreadGlobal; - callbacks[126] = (delegate* unmanaged)&_getHelperFtn; - callbacks[127] = (delegate* unmanaged)&_getFunctionEntryPoint; - callbacks[128] = (delegate* unmanaged)&_getFunctionFixedEntryPoint; - callbacks[129] = (delegate* unmanaged)&_getMethodSync; - callbacks[130] = (delegate* unmanaged)&_getLazyStringLiteralHelper; - callbacks[131] = (delegate* unmanaged)&_embedModuleHandle; - callbacks[132] = (delegate* unmanaged)&_embedClassHandle; - callbacks[133] = (delegate* unmanaged)&_embedMethodHandle; - callbacks[134] = (delegate* unmanaged)&_embedFieldHandle; - callbacks[135] = (delegate* unmanaged)&_embedGenericHandle; - callbacks[136] = (delegate* unmanaged)&_getLocationOfThisType; - callbacks[137] = (delegate* unmanaged)&_getAddressOfPInvokeTarget; - callbacks[138] = (delegate* unmanaged)&_GetCookieForPInvokeCalliSig; - callbacks[139] = (delegate* unmanaged)&_canGetCookieForPInvokeCalliSig; - callbacks[140] = (delegate* unmanaged)&_getJustMyCodeHandle; - callbacks[141] = (delegate* unmanaged)&_GetProfilingHandle; - callbacks[142] = (delegate* unmanaged)&_getCallInfo; - callbacks[143] = (delegate* unmanaged)&_getClassDomainID; - callbacks[144] = (delegate* unmanaged)&_getStaticFieldContent; - callbacks[145] = (delegate* unmanaged)&_getObjectContent; - callbacks[146] = (delegate* unmanaged)&_getStaticFieldCurrentClass; - callbacks[147] = (delegate* unmanaged)&_getVarArgsHandle; - callbacks[148] = (delegate* unmanaged)&_canGetVarArgsHandle; - callbacks[149] = (delegate* unmanaged)&_constructStringLiteral; - callbacks[150] = (delegate* unmanaged)&_emptyStringLiteral; - callbacks[151] = (delegate* unmanaged)&_getFieldThreadLocalStoreID; - callbacks[152] = (delegate* unmanaged)&_GetDelegateCtor; - callbacks[153] = (delegate* unmanaged)&_MethodCompileComplete; - callbacks[154] = (delegate* unmanaged)&_getTailCallHelpers; - callbacks[155] = (delegate* unmanaged)&_convertPInvokeCalliToCall; - callbacks[156] = (delegate* unmanaged)&_notifyInstructionSetUsage; - callbacks[157] = (delegate* unmanaged)&_updateEntryPointForTailCall; - callbacks[158] = (delegate* unmanaged)&_allocMem; - callbacks[159] = (delegate* unmanaged)&_reserveUnwindInfo; - callbacks[160] = (delegate* unmanaged)&_allocUnwindInfo; - callbacks[161] = (delegate* unmanaged)&_allocGCInfo; - callbacks[162] = (delegate* unmanaged)&_setEHcount; - callbacks[163] = (delegate* unmanaged)&_setEHinfo; - callbacks[164] = (delegate* unmanaged)&_logMsg; - callbacks[165] = (delegate* unmanaged)&_doAssert; - callbacks[166] = (delegate* unmanaged)&_reportFatalError; - callbacks[167] = (delegate* unmanaged)&_getPgoInstrumentationResults; - callbacks[168] = (delegate* unmanaged)&_allocPgoInstrumentationBySchema; - callbacks[169] = (delegate* unmanaged)&_recordCallSite; - callbacks[170] = (delegate* unmanaged)&_recordRelocation; - callbacks[171] = (delegate* unmanaged)&_getRelocTypeHint; - callbacks[172] = (delegate* unmanaged)&_getExpectedTargetArchitecture; - callbacks[173] = (delegate* unmanaged)&_getJitFlags; + callbacks[95] = (delegate* unmanaged)&_isFieldStatic; + callbacks[96] = (delegate* unmanaged)&_getArrayOrStringLength; + callbacks[97] = (delegate* unmanaged)&_getBoundaries; + callbacks[98] = (delegate* unmanaged)&_setBoundaries; + callbacks[99] = (delegate* unmanaged)&_getVars; + callbacks[100] = (delegate* unmanaged)&_setVars; + callbacks[101] = (delegate* unmanaged)&_reportRichMappings; + callbacks[102] = (delegate* unmanaged)&_allocateArray; + callbacks[103] = (delegate* unmanaged)&_freeArray; + callbacks[104] = (delegate* unmanaged)&_getArgNext; + callbacks[105] = (delegate* unmanaged)&_getArgType; + callbacks[106] = (delegate* unmanaged)&_getExactClasses; + callbacks[107] = (delegate* unmanaged)&_getArgClass; + callbacks[108] = (delegate* unmanaged)&_getHFAType; + callbacks[109] = (delegate* unmanaged)&_runWithErrorTrap; + callbacks[110] = (delegate* unmanaged)&_runWithSPMIErrorTrap; + callbacks[111] = (delegate* unmanaged)&_getEEInfo; + callbacks[112] = (delegate* unmanaged)&_getJitTimeLogFilename; + callbacks[113] = (delegate* unmanaged)&_getMethodDefFromMethod; + callbacks[114] = (delegate* unmanaged)&_printMethodName; + callbacks[115] = (delegate* unmanaged)&_getMethodNameFromMetadata; + callbacks[116] = (delegate* unmanaged)&_getMethodHash; + callbacks[117] = (delegate* unmanaged)&_getSystemVAmd64PassStructInRegisterDescriptor; + callbacks[118] = (delegate* unmanaged)&_getLoongArch64PassStructInRegisterFlags; + callbacks[119] = (delegate* unmanaged)&_getRISCV64PassStructInRegisterFlags; + callbacks[120] = (delegate* unmanaged)&_getThreadTLSIndex; + callbacks[121] = (delegate* unmanaged)&_getAddrOfCaptureThreadGlobal; + callbacks[122] = (delegate* unmanaged)&_getHelperFtn; + callbacks[123] = (delegate* unmanaged)&_getFunctionEntryPoint; + callbacks[124] = (delegate* unmanaged)&_getFunctionFixedEntryPoint; + callbacks[125] = (delegate* unmanaged)&_getMethodSync; + callbacks[126] = (delegate* unmanaged)&_getLazyStringLiteralHelper; + callbacks[127] = (delegate* unmanaged)&_embedModuleHandle; + callbacks[128] = (delegate* unmanaged)&_embedClassHandle; + callbacks[129] = (delegate* unmanaged)&_embedMethodHandle; + callbacks[130] = (delegate* unmanaged)&_embedFieldHandle; + callbacks[131] = (delegate* unmanaged)&_embedGenericHandle; + callbacks[132] = (delegate* unmanaged)&_getLocationOfThisType; + callbacks[133] = (delegate* unmanaged)&_getAddressOfPInvokeTarget; + callbacks[134] = (delegate* unmanaged)&_GetCookieForPInvokeCalliSig; + callbacks[135] = (delegate* unmanaged)&_canGetCookieForPInvokeCalliSig; + callbacks[136] = (delegate* unmanaged)&_getJustMyCodeHandle; + callbacks[137] = (delegate* unmanaged)&_GetProfilingHandle; + callbacks[138] = (delegate* unmanaged)&_getCallInfo; + callbacks[139] = (delegate* unmanaged)&_getClassDomainID; + callbacks[140] = (delegate* unmanaged)&_getStaticFieldContent; + callbacks[141] = (delegate* unmanaged)&_getObjectContent; + callbacks[142] = (delegate* unmanaged)&_getStaticFieldCurrentClass; + callbacks[143] = (delegate* unmanaged)&_getVarArgsHandle; + callbacks[144] = (delegate* unmanaged)&_canGetVarArgsHandle; + callbacks[145] = (delegate* unmanaged)&_constructStringLiteral; + callbacks[146] = (delegate* unmanaged)&_emptyStringLiteral; + callbacks[147] = (delegate* unmanaged)&_getFieldThreadLocalStoreID; + callbacks[148] = (delegate* unmanaged)&_GetDelegateCtor; + callbacks[149] = (delegate* unmanaged)&_MethodCompileComplete; + callbacks[150] = (delegate* unmanaged)&_getTailCallHelpers; + callbacks[151] = (delegate* unmanaged)&_convertPInvokeCalliToCall; + callbacks[152] = (delegate* unmanaged)&_notifyInstructionSetUsage; + callbacks[153] = (delegate* unmanaged)&_updateEntryPointForTailCall; + callbacks[154] = (delegate* unmanaged)&_allocMem; + callbacks[155] = (delegate* unmanaged)&_reserveUnwindInfo; + callbacks[156] = (delegate* unmanaged)&_allocUnwindInfo; + callbacks[157] = (delegate* unmanaged)&_allocGCInfo; + callbacks[158] = (delegate* unmanaged)&_setEHcount; + callbacks[159] = (delegate* unmanaged)&_setEHinfo; + callbacks[160] = (delegate* unmanaged)&_logMsg; + callbacks[161] = (delegate* unmanaged)&_doAssert; + callbacks[162] = (delegate* unmanaged)&_reportFatalError; + callbacks[163] = (delegate* unmanaged)&_getPgoInstrumentationResults; + callbacks[164] = (delegate* unmanaged)&_allocPgoInstrumentationBySchema; + callbacks[165] = (delegate* unmanaged)&_recordCallSite; + callbacks[166] = (delegate* unmanaged)&_recordRelocation; + callbacks[167] = (delegate* unmanaged)&_getRelocTypeHint; + callbacks[168] = (delegate* unmanaged)&_getExpectedTargetArchitecture; + callbacks[169] = (delegate* unmanaged)&_getJitFlags; return (IntPtr)callbacks; } diff --git a/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt b/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt index 9f374f16190f03..0683a9f4b6ffef 100644 --- a/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt +++ b/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt @@ -257,10 +257,6 @@ FUNCTIONS uint32_t getThreadLocalFieldInfo (CORINFO_FIELD_HANDLE field, bool isGCtype) void getThreadLocalStaticBlocksInfo (CORINFO_THREAD_STATIC_BLOCKS_INFO* pInfo, bool isGCType) void getThreadLocalStaticInfo_ReadyToRun(CORINFO_THREAD_STATIC_INFO_READYTORUN* pInfo, CORINFO_CLASS_HANDLE cls) - void getTlsRootInfo(CORINFO_CONST_LOOKUP* addr) - void getTlsIndexInfo(CORINFO_CONST_LOOKUP* addr) - void getThreadStaticBaseSlowInfo(CORINFO_CONST_LOOKUP* addr) - int getEnsureClassCtorRunAndReturnThreadStaticBaseHelper(CORINFO_CLASS_HANDLE cls, CORINFO_CONST_LOOKUP* addr, CORINFO_CONST_LOOKUP* targetSymbol) bool isFieldStatic(CORINFO_FIELD_HANDLE fldHnd) int getArrayOrStringLength(CORINFO_OBJECT_HANDLE objHnd) void getBoundaries(CORINFO_METHOD_HANDLE ftn, unsigned int* cILOffsets, uint32_t** pILOffsets, ICorDebugInfo::BoundaryTypes* implicitBoundaries) diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs index 3f89eb6e094cbf..8b043b4f8b2d48 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs @@ -3232,28 +3232,6 @@ void ValidateSafetyOfUsingTypeEquivalenceOfType(TypeDesc type) } #pragma warning disable CA1822 // Mark members as static - - private void getTlsRootInfo(ref CORINFO_CONST_LOOKUP addr) - { - // Implemented for NativeAOT only for now. - } - - private void getTlsIndexInfo(ref CORINFO_CONST_LOOKUP addr) - { - // Implemented for NativeAOT only for now. - } - - private void getThreadStaticBaseSlowInfo(ref CORINFO_CONST_LOOKUP addr) - { - // Implemented for NativeAOT only for now. - } - - private int getEnsureClassCtorRunAndReturnThreadStaticBaseHelper(CORINFO_CLASS_STRUCT_* cls, ref CORINFO_CONST_LOOKUP addr, ref CORINFO_CONST_LOOKUP targetSymbol) - { - // Implemented for NativeAOT only for now. - return 0; - } - private void getThreadLocalStaticInfo_ReadyToRun(CORINFO_THREAD_STATIC_INFO_READYTORUN* pInfo, CORINFO_CLASS_STRUCT_* cls) { // Implemented for NativeAOT only for now. diff --git a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs index ad1b1a016f4285..e14988c2d42285 100644 --- a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs +++ b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs @@ -2417,34 +2417,6 @@ private bool getStaticBaseAddress(CORINFO_CLASS_STRUCT_* cls, bool isGc, ref COR return true; } - private void getTlsRootInfo(ref CORINFO_CONST_LOOKUP addr) - { - addr = CreateConstLookupToSymbol(_compilation.NodeFactory.TlsRoot); - } - - private void getTlsIndexInfo(ref CORINFO_CONST_LOOKUP addr) - { - addr = CreateConstLookupToSymbol(_compilation.NodeFactory.ExternSymbol("_tls_index")); - } - - private void getThreadStaticBaseSlowInfo(ref CORINFO_CONST_LOOKUP addr) - { - addr = CreateConstLookupToSymbol(_compilation.NodeFactory.HelperEntrypoint(HelperEntrypoint.GetInlinedThreadStaticBaseSlow)); - } - - private int getEnsureClassCtorRunAndReturnThreadStaticBaseHelper(CORINFO_CLASS_STRUCT_* cls, ref CORINFO_CONST_LOOKUP addr, ref CORINFO_CONST_LOOKUP targetSymbol) - { - MetadataType clsType = HandleToObject(cls) as MetadataType; - if (clsType == null) - { - return 0; - } - - addr = CreateConstLookupToSymbol(_compilation.NodeFactory.HelperEntrypoint(HelperEntrypoint.EnsureClassConstructorRunAndReturnThreadStaticBase)); - targetSymbol = CreateConstLookupToSymbol(_compilation.NodeFactory.TypeNonGCStaticsSymbol(clsType)); - return -NonGCStaticsNode.GetClassConstructorContextSize(_compilation.NodeFactory.Target); - } - private void getThreadLocalStaticInfo_ReadyToRun(CORINFO_THREAD_STATIC_INFO_READYTORUN* pInfo, CORINFO_CLASS_STRUCT_* cls) { pInfo->offsetOfThreadLocalStoragePointer = (uint)(11 * PointerSize); // 0x58 = 0n88 diff --git a/src/coreclr/tools/aot/jitinterface/jitinterface_generated.h b/src/coreclr/tools/aot/jitinterface/jitinterface_generated.h index 9a3cf39d8b936b..120bb04a479293 100644 --- a/src/coreclr/tools/aot/jitinterface/jitinterface_generated.h +++ b/src/coreclr/tools/aot/jitinterface/jitinterface_generated.h @@ -106,10 +106,6 @@ struct JitInterfaceCallbacks uint32_t (* getThreadLocalFieldInfo)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_FIELD_HANDLE field, bool isGCtype); void (* getThreadLocalStaticBlocksInfo)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_THREAD_STATIC_BLOCKS_INFO* pInfo, bool isGCType); void (* getThreadLocalStaticInfo_ReadyToRun)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_THREAD_STATIC_INFO_READYTORUN* pInfo, CORINFO_CLASS_HANDLE cls); - void (* getTlsRootInfo)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_CONST_LOOKUP* addr); - void (* getTlsIndexInfo)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_CONST_LOOKUP* addr); - void (* getThreadStaticBaseSlowInfo)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_CONST_LOOKUP* addr); - int (* getEnsureClassCtorRunAndReturnThreadStaticBaseHelper)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_CLASS_HANDLE cls, CORINFO_CONST_LOOKUP* addr, CORINFO_CONST_LOOKUP* targetSymbol); bool (* isFieldStatic)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_FIELD_HANDLE fldHnd); int (* getArrayOrStringLength)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_OBJECT_HANDLE objHnd); void (* getBoundaries)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_METHOD_HANDLE ftn, unsigned int* cILOffsets, uint32_t** pILOffsets, ICorDebugInfo::BoundaryTypes* implicitBoundaries); @@ -1129,41 +1125,6 @@ class JitInterfaceWrapper : public ICorJitInfo if (pException != nullptr) throw pException; } - virtual void getTlsRootInfo( - CORINFO_CONST_LOOKUP* addr) -{ - CorInfoExceptionClass* pException = nullptr; - _callbacks->getTlsRootInfo(_thisHandle, &pException, addr); - if (pException != nullptr) throw pException; -} - - virtual void getTlsIndexInfo( - CORINFO_CONST_LOOKUP* addr) -{ - CorInfoExceptionClass* pException = nullptr; - _callbacks->getTlsIndexInfo(_thisHandle, &pException, addr); - if (pException != nullptr) throw pException; -} - - virtual void getThreadStaticBaseSlowInfo( - CORINFO_CONST_LOOKUP* addr) -{ - CorInfoExceptionClass* pException = nullptr; - _callbacks->getThreadStaticBaseSlowInfo(_thisHandle, &pException, addr); - if (pException != nullptr) throw pException; -} - - virtual int getEnsureClassCtorRunAndReturnThreadStaticBaseHelper( - CORINFO_CLASS_HANDLE cls, - CORINFO_CONST_LOOKUP* addr, - CORINFO_CONST_LOOKUP* targetSymbol) -{ - CorInfoExceptionClass* pException = nullptr; - int temp = _callbacks->getEnsureClassCtorRunAndReturnThreadStaticBaseHelper(_thisHandle, &pException, cls, addr, targetSymbol); - if (pException != nullptr) throw pException; - return temp; -} - virtual bool isFieldStatic( CORINFO_FIELD_HANDLE fldHnd) { diff --git a/src/coreclr/tools/superpmi/superpmi-shared/lwmlist.h b/src/coreclr/tools/superpmi/superpmi-shared/lwmlist.h index c84b933523ea59..fe4c83b9aeead2 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/lwmlist.h +++ b/src/coreclr/tools/superpmi/superpmi-shared/lwmlist.h @@ -40,10 +40,6 @@ LWM(EmbedModuleHandle, DWORDLONG, DLDL) LWM(GetThreadLocalFieldInfo, DLD, DWORD) LWM(GetThreadLocalStaticBlocksInfo, DWORD, Agnostic_GetThreadLocalStaticBlocksInfo) LWM(GetThreadLocalStaticInfo_ReadyToRun, DWORDLONG, Agnostic_GetThreadStaticInfo_ReadyToRun) -LWM(GetTlsRootInfo, DWORD, Agnostic_CORINFO_CONST_LOOKUP) -LWM(GetTlsIndexInfo, DWORD, Agnostic_CORINFO_CONST_LOOKUP) -LWM(GetThreadStaticBaseSlowInfo, DWORD, Agnostic_CORINFO_CONST_LOOKUP) -LWM(GetEnsureClassCtorRunAndReturnThreadStaticBaseHelper, DWORDLONG, Agnostic_GetClassCtorInitializationInfo) DENSELWM(EmptyStringLiteral, DLD) DENSELWM(ErrorList, DWORD) LWM(FindCallSiteSig, Agnostic_FindCallSiteSig, Agnostic_CORINFO_SIG_INFO) diff --git a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp index 4609691ef44ce6..d33a2fdf7012d3 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp @@ -3570,124 +3570,6 @@ uint32_t MethodContext::repGetThreadLocalFieldInfo(CORINFO_FIELD_HANDLE field, b return value; } -void MethodContext::recGetTlsRootInfo(CORINFO_CONST_LOOKUP* result) -{ - if (GetTlsRootInfo == nullptr) - GetTlsRootInfo = new LightWeightMap(); - - DWORD key = 0; - Agnostic_CORINFO_CONST_LOOKUP value = SpmiRecordsHelper::StoreAgnostic_CORINFO_CONST_LOOKUP(result); - GetTlsRootInfo->Add(key, value); - DEBUG_REC(dmpGetTlsRootInfo(key, result)); -} - -void MethodContext::dmpGetTlsRootInfo(DWORD key, const Agnostic_CORINFO_CONST_LOOKUP& value) -{ - printf("GetTlsRootInfo key %u, result-%s", key, SpmiDumpHelper::DumpAgnostic_CORINFO_CONST_LOOKUP(value).c_str()); -} -void MethodContext::repGetTlsRootInfo(CORINFO_CONST_LOOKUP* result) -{ - DWORD key = 0; - Agnostic_CORINFO_CONST_LOOKUP value = LookupByKeyOrMiss(GetTlsRootInfo, key, ": key %d", 0); - - DEBUG_REP(dmpGetTlsRootInfo(key, value)); - - *result = SpmiRecordsHelper::RestoreCORINFO_CONST_LOOKUP(value); -} - -void MethodContext::recGetTlsIndexInfo(CORINFO_CONST_LOOKUP* result) -{ - if (GetTlsIndexInfo == nullptr) - GetTlsIndexInfo = new LightWeightMap(); - - DWORD key = 0; - Agnostic_CORINFO_CONST_LOOKUP value = SpmiRecordsHelper::StoreAgnostic_CORINFO_CONST_LOOKUP(result); - GetTlsIndexInfo->Add(key, value); - DEBUG_REC(dmpGetTlsIndexInfo(key, result)); -} - -void MethodContext::dmpGetTlsIndexInfo(DWORD key, const Agnostic_CORINFO_CONST_LOOKUP& value) -{ - printf("GetTlsIndexInfo key %u, result-%s", key, SpmiDumpHelper::DumpAgnostic_CORINFO_CONST_LOOKUP(value).c_str()); -} -void MethodContext::repGetTlsIndexInfo(CORINFO_CONST_LOOKUP* result) -{ - DWORD key = 0; - Agnostic_CORINFO_CONST_LOOKUP value = LookupByKeyOrMiss(GetTlsIndexInfo, key, ": key %d", 0); - - DEBUG_REP(dmpGetTlsIndexInfo(key, value)); - - *result = SpmiRecordsHelper::RestoreCORINFO_CONST_LOOKUP(value); -} - -void MethodContext::recGetThreadStaticBaseSlowInfo(CORINFO_CONST_LOOKUP* result) -{ - if (GetThreadStaticBaseSlowInfo == nullptr) - GetThreadStaticBaseSlowInfo = new LightWeightMap(); - - DWORD key = 0; - Agnostic_CORINFO_CONST_LOOKUP value = SpmiRecordsHelper::StoreAgnostic_CORINFO_CONST_LOOKUP(result); - GetThreadStaticBaseSlowInfo->Add(key, value); - DEBUG_REC(dmpGetThreadStaticBaseSlowInfo(key, result)); -} - -void MethodContext::dmpGetThreadStaticBaseSlowInfo(DWORD key, const Agnostic_CORINFO_CONST_LOOKUP& value) -{ - printf("GetThreadStaticBaseSlowInfo key %u, result-%s", key, SpmiDumpHelper::DumpAgnostic_CORINFO_CONST_LOOKUP(value).c_str()); -} - -void MethodContext::repGetThreadStaticBaseSlowInfo(CORINFO_CONST_LOOKUP* result) -{ - DWORD key = 0; - Agnostic_CORINFO_CONST_LOOKUP value = LookupByKeyOrMiss(GetThreadStaticBaseSlowInfo, key, ": key %d", 0); - - DEBUG_REP(dmpGetThreadStaticBaseSlowInfo(key, value)); - - *result = SpmiRecordsHelper::RestoreCORINFO_CONST_LOOKUP(value); -} - -void MethodContext::recGetEnsureClassCtorRunAndReturnThreadStaticBaseHelper(CORINFO_CLASS_HANDLE cls, CORINFO_CONST_LOOKUP* addr, CORINFO_CONST_LOOKUP* targetSymbol, int size) -{ - if (GetEnsureClassCtorRunAndReturnThreadStaticBaseHelper == nullptr) - GetEnsureClassCtorRunAndReturnThreadStaticBaseHelper = new LightWeightMap(); - - Agnostic_GetClassCtorInitializationInfo value; - ZeroMemory(&value, sizeof(value)); - value.addr = SpmiRecordsHelper::StoreAgnostic_CORINFO_CONST_LOOKUP(addr); - value.targetAddr = SpmiRecordsHelper::StoreAgnostic_CORINFO_CONST_LOOKUP(targetSymbol); - value.size = size; - - DWORDLONG key = CastHandle(cls); - - GetEnsureClassCtorRunAndReturnThreadStaticBaseHelper->Add(key, value); - DEBUG_REC(dmpGetEnsureClassCtorRunAndReturnThreadStaticBaseHelper(key, result)); -} - -void MethodContext::dmpGetEnsureClassCtorRunAndReturnThreadStaticBaseHelper( - DWORDLONG key, - const Agnostic_GetClassCtorInitializationInfo& value) -{ - printf("GetEnsureClassCtorRunAndReturnThreadStaticBaseHelper key %016" PRIX64 ", addr-%s, targetAddr-%s, size-%d", key, - SpmiDumpHelper::DumpAgnostic_CORINFO_CONST_LOOKUP(value.addr).c_str(), - SpmiDumpHelper::DumpAgnostic_CORINFO_CONST_LOOKUP(value.targetAddr).c_str(), value.size); -} - -int MethodContext::repGetEnsureClassCtorRunAndReturnThreadStaticBaseHelper(CORINFO_CLASS_HANDLE cls, - CORINFO_CONST_LOOKUP* addr, - CORINFO_CONST_LOOKUP* targetSymbol) -{ - DWORDLONG key = CastHandle(cls); - Agnostic_GetClassCtorInitializationInfo value = - LookupByKeyOrMiss(GetEnsureClassCtorRunAndReturnThreadStaticBaseHelper, key, ": key %016" PRIX64 "", key); - - DEBUG_REP(dmpGetEnsureClassCtorRunAndReturnThreadStaticBaseHelper(key, value)); - - *addr = SpmiRecordsHelper::RestoreCORINFO_CONST_LOOKUP(value.addr); - *targetSymbol = SpmiRecordsHelper::RestoreCORINFO_CONST_LOOKUP(value.targetAddr); - - return value.size; -} - void MethodContext::recGetThreadLocalStaticBlocksInfo(CORINFO_THREAD_STATIC_BLOCKS_INFO* pInfo, bool isGCType) { if (GetThreadLocalStaticBlocksInfo == nullptr) diff --git a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h index 502aa80804f1c5..5fb2c85d7f3a07 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h +++ b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h @@ -478,27 +478,6 @@ class MethodContext void dmpGetThreadLocalStaticInfo_ReadyToRun(DWORDLONG key, const Agnostic_GetThreadStaticInfo_ReadyToRun& value); void repGetThreadLocalStaticInfo_ReadyToRun(CORINFO_THREAD_STATIC_INFO_READYTORUN* pInfo, CORINFO_CLASS_HANDLE cls); - void recGetTlsRootInfo(CORINFO_CONST_LOOKUP* result); - void dmpGetTlsRootInfo(DWORD key, const Agnostic_CORINFO_CONST_LOOKUP& value); - void repGetTlsRootInfo(CORINFO_CONST_LOOKUP* addr); - - void recGetTlsIndexInfo(CORINFO_CONST_LOOKUP* addr); - void dmpGetTlsIndexInfo(DWORD key, const Agnostic_CORINFO_CONST_LOOKUP& value); - void repGetTlsIndexInfo(CORINFO_CONST_LOOKUP* addr); - - void recGetThreadStaticBaseSlowInfo(CORINFO_CONST_LOOKUP* addr); - void dmpGetThreadStaticBaseSlowInfo(DWORD key, const Agnostic_CORINFO_CONST_LOOKUP& value); - void repGetThreadStaticBaseSlowInfo(CORINFO_CONST_LOOKUP* addr); - - void recGetEnsureClassCtorRunAndReturnThreadStaticBaseHelper(CORINFO_CLASS_HANDLE cls, - CORINFO_CONST_LOOKUP* addr, - CORINFO_CONST_LOOKUP* targetSymbol, int pSize); - void dmpGetEnsureClassCtorRunAndReturnThreadStaticBaseHelper(DWORDLONG key, - const Agnostic_GetClassCtorInitializationInfo& value); - int repGetEnsureClassCtorRunAndReturnThreadStaticBaseHelper(CORINFO_CLASS_HANDLE cls, - CORINFO_CONST_LOOKUP* addr, - CORINFO_CONST_LOOKUP* targetSymbol); - void recEmbedMethodHandle(CORINFO_METHOD_HANDLE handle, void** ppIndirection, CORINFO_METHOD_HANDLE result); void dmpEmbedMethodHandle(DWORDLONG key, DLDL value); CORINFO_METHOD_HANDLE repEmbedMethodHandle(CORINFO_METHOD_HANDLE handle, void** ppIndirection); @@ -1156,13 +1135,9 @@ enum mcPackets Packet_GetThreadLocalFieldInfo = 207, Packet_GetThreadLocalStaticBlocksInfo = 208, Packet_GetThreadLocalStaticInfo_ReadyToRun = 209, - Packet_GetTlsRootInfo = 210, - Packet_GetTlsIndexInfo = 211, - Packet_GetThreadStaticBaseSlowInfo = 212, - Packet_GetEnsureClassCtorRunAndReturnThreadStaticBaseHelper = 213, - Packet_GetRISCV64PassStructInRegisterFlags = 214, - Packet_GetObjectContent = 215, - Packet_GetTypeLayout = 216, + Packet_GetRISCV64PassStructInRegisterFlags = 210, + Packet_GetObjectContent = 211, + Packet_GetTypeLayout = 212, }; void SetDebugDumpVariables(); diff --git a/src/coreclr/tools/superpmi/superpmi-shim-collector/icorjitinfo.cpp b/src/coreclr/tools/superpmi/superpmi-shim-collector/icorjitinfo.cpp index 9ef9944ac0b448..a50f651b262c92 100644 --- a/src/coreclr/tools/superpmi/superpmi-shim-collector/icorjitinfo.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shim-collector/icorjitinfo.cpp @@ -1055,37 +1055,6 @@ void interceptor_ICJI::getThreadLocalStaticInfo_ReadyToRun(CORINFO_THREAD_STATIC mc->recGetThreadLocalStaticInfo_ReadyToRun(pInfo, cls); } -void interceptor_ICJI::getTlsRootInfo(CORINFO_CONST_LOOKUP* pInfo) -{ - mc->cr->AddCall("getTlsRootInfo"); - original_ICorJitInfo->getTlsRootInfo(pInfo); - mc->recGetTlsRootInfo(pInfo); -} - -void interceptor_ICJI::getTlsIndexInfo(CORINFO_CONST_LOOKUP* pInfo) -{ - mc->cr->AddCall("getTlsIndexInfo"); - original_ICorJitInfo->getTlsIndexInfo(pInfo); - mc->recGetTlsIndexInfo(pInfo); -} - -void interceptor_ICJI::getThreadStaticBaseSlowInfo(CORINFO_CONST_LOOKUP* pInfo) -{ - mc->cr->AddCall("getThreadStaticBaseSlowInfo"); - original_ICorJitInfo->getThreadStaticBaseSlowInfo(pInfo); - mc->repGetThreadStaticBaseSlowInfo(pInfo); -} - -int interceptor_ICJI::getEnsureClassCtorRunAndReturnThreadStaticBaseHelper(CORINFO_CLASS_HANDLE cls, - CORINFO_CONST_LOOKUP* addr, - CORINFO_CONST_LOOKUP* targetSymbol) -{ - mc->cr->AddCall("getEnsureClassCtorRunAndReturnThreadStaticBaseHelper"); - int result = original_ICorJitInfo->getEnsureClassCtorRunAndReturnThreadStaticBaseHelper(cls, addr, targetSymbol); - mc->recGetEnsureClassCtorRunAndReturnThreadStaticBaseHelper(cls, addr, targetSymbol, result); - return result; -} - // Returns true iff "fldHnd" represents a static field. bool interceptor_ICJI::isFieldStatic(CORINFO_FIELD_HANDLE fldHnd) { diff --git a/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo_generated.cpp b/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo_generated.cpp index 696101451b29ff..44a13496878ee3 100644 --- a/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo_generated.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo_generated.cpp @@ -771,36 +771,6 @@ void interceptor_ICJI::getThreadLocalStaticInfo_ReadyToRun( original_ICorJitInfo->getThreadLocalStaticInfo_ReadyToRun(pInfo, cls); } -void interceptor_ICJI::getTlsRootInfo( - CORINFO_CONST_LOOKUP* addr) -{ - mcs->AddCall("getTlsRootInfo"); - original_ICorJitInfo->getTlsRootInfo(addr); -} - -void interceptor_ICJI::getTlsIndexInfo( - CORINFO_CONST_LOOKUP* addr) -{ - mcs->AddCall("getTlsIndexInfo"); - original_ICorJitInfo->getTlsIndexInfo(addr); -} - -void interceptor_ICJI::getThreadStaticBaseSlowInfo( - CORINFO_CONST_LOOKUP* addr) -{ - mcs->AddCall("getThreadStaticBaseSlowInfo"); - original_ICorJitInfo->getThreadStaticBaseSlowInfo(addr); -} - -int interceptor_ICJI::getEnsureClassCtorRunAndReturnThreadStaticBaseHelper( - CORINFO_CLASS_HANDLE cls, - CORINFO_CONST_LOOKUP* addr, - CORINFO_CONST_LOOKUP* targetSymbol) -{ - mcs->AddCall("getEnsureClassCtorRunAndReturnThreadStaticBaseHelper"); - return original_ICorJitInfo->getEnsureClassCtorRunAndReturnThreadStaticBaseHelper(cls, addr, targetSymbol); -} - bool interceptor_ICJI::isFieldStatic( CORINFO_FIELD_HANDLE fldHnd) { diff --git a/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo_generated.cpp b/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo_generated.cpp index 634fc6e56f274d..4ef3aba81e9318 100644 --- a/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo_generated.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo_generated.cpp @@ -676,32 +676,6 @@ void interceptor_ICJI::getThreadLocalStaticInfo_ReadyToRun( original_ICorJitInfo->getThreadLocalStaticInfo_ReadyToRun(pInfo, cls); } -void interceptor_ICJI::getTlsRootInfo( - CORINFO_CONST_LOOKUP* addr) -{ - original_ICorJitInfo->getTlsRootInfo(addr); -} - -void interceptor_ICJI::getTlsIndexInfo( - CORINFO_CONST_LOOKUP* addr) -{ - original_ICorJitInfo->getTlsIndexInfo(addr); -} - -void interceptor_ICJI::getThreadStaticBaseSlowInfo( - CORINFO_CONST_LOOKUP* addr) -{ - original_ICorJitInfo->getThreadStaticBaseSlowInfo(addr); -} - -int interceptor_ICJI::getEnsureClassCtorRunAndReturnThreadStaticBaseHelper( - CORINFO_CLASS_HANDLE cls, - CORINFO_CONST_LOOKUP* addr, - CORINFO_CONST_LOOKUP* targetSymbol) -{ - return original_ICorJitInfo->getEnsureClassCtorRunAndReturnThreadStaticBaseHelper(cls, addr, targetSymbol); -} - bool interceptor_ICJI::isFieldStatic( CORINFO_FIELD_HANDLE fldHnd) { diff --git a/src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp b/src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp index 34224d8413c0d5..204a2d379ce0a5 100644 --- a/src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp +++ b/src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp @@ -884,32 +884,6 @@ void MyICJI::getThreadLocalStaticInfo_ReadyToRun(CORINFO_THREAD_STATIC_INFO_READ jitInstance->mc->repGetThreadLocalStaticInfo_ReadyToRun(pInfo, cls); } -void MyICJI::getTlsRootInfo(CORINFO_CONST_LOOKUP* pInfo) -{ - jitInstance->mc->cr->AddCall("getTlsRootInfo"); - jitInstance->mc->repGetTlsRootInfo(pInfo); -} - -void MyICJI::getTlsIndexInfo(CORINFO_CONST_LOOKUP* pInfo) -{ - jitInstance->mc->cr->AddCall("getTlsIndexInfo"); - jitInstance->mc->repGetTlsIndexInfo(pInfo); -} - -void MyICJI::getThreadStaticBaseSlowInfo(CORINFO_CONST_LOOKUP* pInfo) -{ - jitInstance->mc->cr->AddCall("getThreadStaticBaseSlowInfo"); - jitInstance->mc->repGetThreadStaticBaseSlowInfo(pInfo); -} - -int MyICJI::getEnsureClassCtorRunAndReturnThreadStaticBaseHelper(CORINFO_CLASS_HANDLE cls, - CORINFO_CONST_LOOKUP* addr, - CORINFO_CONST_LOOKUP* targetSymbol) -{ - jitInstance->mc->cr->AddCall("getEnsureClassCtorRunAndReturnThreadStaticBaseHelper"); - return jitInstance->mc->repGetEnsureClassCtorRunAndReturnThreadStaticBaseHelper(cls, addr, targetSymbol); -} - // Returns true iff "fldHnd" represents a static field. bool MyICJI::isFieldStatic(CORINFO_FIELD_HANDLE fldHnd) { diff --git a/src/coreclr/vm/jitinterface.cpp b/src/coreclr/vm/jitinterface.cpp index 486906b87b2d2a..42065e61e6ab38 100644 --- a/src/coreclr/vm/jitinterface.cpp +++ b/src/coreclr/vm/jitinterface.cpp @@ -1315,30 +1315,6 @@ void CEEInfo::getThreadLocalStaticInfo_ReadyToRun(CORINFO_THREAD_STATIC_INFO_REA UNREACHABLE(); // only called with NativeAOT. } -void CEEInfo::getTlsRootInfo(CORINFO_CONST_LOOKUP* addr) -{ - LIMITED_METHOD_CONTRACT; - UNREACHABLE(); // only called with NativeAOT. -} -void CEEInfo::getTlsIndexInfo(CORINFO_CONST_LOOKUP* addr) -{ - LIMITED_METHOD_CONTRACT; - UNREACHABLE(); // only called with NativeAOT. -} - -void CEEInfo::getThreadStaticBaseSlowInfo(CORINFO_CONST_LOOKUP* addr) -{ - LIMITED_METHOD_CONTRACT; - UNREACHABLE(); // only called with NativeAOT. -} - -int CEEInfo::getEnsureClassCtorRunAndReturnThreadStaticBaseHelper(CORINFO_CLASS_HANDLE cls, CORINFO_CONST_LOOKUP* addr, CORINFO_CONST_LOOKUP* targetSymbol) -{ - LIMITED_METHOD_CONTRACT; - UNREACHABLE(); // only called with NativeAOT. - return 0; -} - uint32_t CEEInfo::getThreadLocalFieldInfo (CORINFO_FIELD_HANDLE field, bool isGCType) { CONTRACTL { From b9adff779357bc8cb12afe4c9420daa916f4203d Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Sat, 29 Jul 2023 11:09:40 -0700 Subject: [PATCH 18/58] Revert unneeded changes --- .../DependencyAnalysis/NodeFactory.cs | 7 -- .../ReadyToRunHelperNode.cs | 7 -- .../JitInterface/CorInfoImpl.RyuJit.cs | 3 - src/coreclr/tools/aot/ilc.sln | 98 ------------------- 4 files changed, 115 deletions(-) diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/NodeFactory.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/NodeFactory.cs index fe83e3061c754f..0cf64196e96d07 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/NodeFactory.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/NodeFactory.cs @@ -1134,13 +1134,6 @@ public DependencyNodeCore VariantInterfaceMethodUse(MethodDesc decl public ISymbolNode ReadyToRunHelper(ReadyToRunHelperId id, object target) { - if (target is MetadataType mt) - { - if (mt.DiagnosticNamespace == "System.Runtime.InteropServices" && mt.DiagnosticName == "PInvokeMarshal") - { - Console.WriteLine("here"); - } - } return _readyToRunHelpers.GetOrAdd(new ReadyToRunHelperKey(id, target)); } diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ReadyToRunHelperNode.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ReadyToRunHelperNode.cs index 859a73924302f4..36cc3c5ec1eda3 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ReadyToRunHelperNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/ReadyToRunHelperNode.cs @@ -50,13 +50,6 @@ public partial class ReadyToRunHelperNode : AssemblyStubNode, INodeWithDebugInfo public ReadyToRunHelperNode(ReadyToRunHelperId id, object target) { - if (target is MetadataType mt) - { - if (mt.DiagnosticNamespace == "System.Runtime.InteropServices" && mt.DiagnosticName == "PInvokeMarshal") - { - Console.WriteLine("here"); - } - } _id = id; _target = target; diff --git a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs index e14988c2d42285..34e9a72a7c177c 100644 --- a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs +++ b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs @@ -2150,9 +2150,6 @@ private void getFieldInfo(ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_MET { fieldAccessor = CORINFO_FIELD_ACCESSOR.CORINFO_FIELD_STATIC_TLS_MANAGED; } - } else - { - Console.WriteLine(field.Name); } } pResult->helper = CorInfoHelpFunc.CORINFO_HELP_READYTORUN_THREADSTATIC_BASE; diff --git a/src/coreclr/tools/aot/ilc.sln b/src/coreclr/tools/aot/ilc.sln index c53ab72c5bd6a2..3fe8026533f307 100644 --- a/src/coreclr/tools/aot/ilc.sln +++ b/src/coreclr/tools/aot/ilc.sln @@ -28,8 +28,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mono.Linker.Tests.Cases.Exp EndProject Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "ILLink.Shared", "..\..\..\tools\illink\src\ILLink.Shared\ILLink.Shared.shproj", "{FF598E93-8E9E-4091-9F50-61A7572663AE}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "clrjit_win_x64_x64", "..\..\..\..\artifacts\obj\coreclr\windows.x64.Checked\ide\jit\clrjit_win_x64_x64.vcxproj", "{74666FB9-0C0D-3452-A912-3D571F908AA8}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Checked|Any CPU = Checked|Any CPU @@ -41,9 +39,6 @@ Global Release|Any CPU = Release|Any CPU Release|x64 = Release|x64 Release|x86 = Release|x86 - RelWithDebInfo|Any CPU = RelWithDebInfo|Any CPU - RelWithDebInfo|x64 = RelWithDebInfo|x64 - RelWithDebInfo|x86 = RelWithDebInfo|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {6856F5F6-E568-493F-AF8A-7F624B5A02A5}.Checked|Any CPU.ActiveCfg = Checked|x86 @@ -61,12 +56,6 @@ Global {6856F5F6-E568-493F-AF8A-7F624B5A02A5}.Release|x64.Build.0 = Release|x64 {6856F5F6-E568-493F-AF8A-7F624B5A02A5}.Release|x86.ActiveCfg = Release|x86 {6856F5F6-E568-493F-AF8A-7F624B5A02A5}.Release|x86.Build.0 = Release|x86 - {6856F5F6-E568-493F-AF8A-7F624B5A02A5}.RelWithDebInfo|Any CPU.ActiveCfg = Release|x64 - {6856F5F6-E568-493F-AF8A-7F624B5A02A5}.RelWithDebInfo|Any CPU.Build.0 = Release|x64 - {6856F5F6-E568-493F-AF8A-7F624B5A02A5}.RelWithDebInfo|x64.ActiveCfg = Release|x64 - {6856F5F6-E568-493F-AF8A-7F624B5A02A5}.RelWithDebInfo|x64.Build.0 = Release|x64 - {6856F5F6-E568-493F-AF8A-7F624B5A02A5}.RelWithDebInfo|x86.ActiveCfg = Release|x86 - {6856F5F6-E568-493F-AF8A-7F624B5A02A5}.RelWithDebInfo|x86.Build.0 = Release|x86 {FB2D45F2-FA4C-42B2-8E53-3E1F30CF8046}.Checked|Any CPU.ActiveCfg = Checked|x86 {FB2D45F2-FA4C-42B2-8E53-3E1F30CF8046}.Checked|x64.ActiveCfg = Checked|x64 {FB2D45F2-FA4C-42B2-8E53-3E1F30CF8046}.Checked|x64.Build.0 = Checked|x64 @@ -82,12 +71,6 @@ Global {FB2D45F2-FA4C-42B2-8E53-3E1F30CF8046}.Release|x64.Build.0 = Release|x64 {FB2D45F2-FA4C-42B2-8E53-3E1F30CF8046}.Release|x86.ActiveCfg = Release|x86 {FB2D45F2-FA4C-42B2-8E53-3E1F30CF8046}.Release|x86.Build.0 = Release|x86 - {FB2D45F2-FA4C-42B2-8E53-3E1F30CF8046}.RelWithDebInfo|Any CPU.ActiveCfg = Release|x64 - {FB2D45F2-FA4C-42B2-8E53-3E1F30CF8046}.RelWithDebInfo|Any CPU.Build.0 = Release|x64 - {FB2D45F2-FA4C-42B2-8E53-3E1F30CF8046}.RelWithDebInfo|x64.ActiveCfg = Release|x64 - {FB2D45F2-FA4C-42B2-8E53-3E1F30CF8046}.RelWithDebInfo|x64.Build.0 = Release|x64 - {FB2D45F2-FA4C-42B2-8E53-3E1F30CF8046}.RelWithDebInfo|x86.ActiveCfg = Release|x86 - {FB2D45F2-FA4C-42B2-8E53-3E1F30CF8046}.RelWithDebInfo|x86.Build.0 = Release|x86 {B68D5B9E-405B-4E44-B2CC-418EC78AE070}.Checked|Any CPU.ActiveCfg = Checked|x86 {B68D5B9E-405B-4E44-B2CC-418EC78AE070}.Checked|x64.ActiveCfg = Checked|x64 {B68D5B9E-405B-4E44-B2CC-418EC78AE070}.Checked|x64.Build.0 = Checked|x64 @@ -103,12 +86,6 @@ Global {B68D5B9E-405B-4E44-B2CC-418EC78AE070}.Release|x64.Build.0 = Release|x64 {B68D5B9E-405B-4E44-B2CC-418EC78AE070}.Release|x86.ActiveCfg = Release|x86 {B68D5B9E-405B-4E44-B2CC-418EC78AE070}.Release|x86.Build.0 = Release|x86 - {B68D5B9E-405B-4E44-B2CC-418EC78AE070}.RelWithDebInfo|Any CPU.ActiveCfg = Release|x64 - {B68D5B9E-405B-4E44-B2CC-418EC78AE070}.RelWithDebInfo|Any CPU.Build.0 = Release|x64 - {B68D5B9E-405B-4E44-B2CC-418EC78AE070}.RelWithDebInfo|x64.ActiveCfg = Release|x64 - {B68D5B9E-405B-4E44-B2CC-418EC78AE070}.RelWithDebInfo|x64.Build.0 = Release|x64 - {B68D5B9E-405B-4E44-B2CC-418EC78AE070}.RelWithDebInfo|x86.ActiveCfg = Release|x86 - {B68D5B9E-405B-4E44-B2CC-418EC78AE070}.RelWithDebInfo|x86.Build.0 = Release|x86 {05E020F4-6FA1-4DEE-8B9D-4F4B79840231}.Checked|Any CPU.ActiveCfg = Checked|x86 {05E020F4-6FA1-4DEE-8B9D-4F4B79840231}.Checked|x64.ActiveCfg = Checked|x64 {05E020F4-6FA1-4DEE-8B9D-4F4B79840231}.Checked|x64.Build.0 = Checked|x64 @@ -124,12 +101,6 @@ Global {05E020F4-6FA1-4DEE-8B9D-4F4B79840231}.Release|x64.Build.0 = Release|x64 {05E020F4-6FA1-4DEE-8B9D-4F4B79840231}.Release|x86.ActiveCfg = Release|x86 {05E020F4-6FA1-4DEE-8B9D-4F4B79840231}.Release|x86.Build.0 = Release|x86 - {05E020F4-6FA1-4DEE-8B9D-4F4B79840231}.RelWithDebInfo|Any CPU.ActiveCfg = Release|x64 - {05E020F4-6FA1-4DEE-8B9D-4F4B79840231}.RelWithDebInfo|Any CPU.Build.0 = Release|x64 - {05E020F4-6FA1-4DEE-8B9D-4F4B79840231}.RelWithDebInfo|x64.ActiveCfg = Release|x64 - {05E020F4-6FA1-4DEE-8B9D-4F4B79840231}.RelWithDebInfo|x64.Build.0 = Release|x64 - {05E020F4-6FA1-4DEE-8B9D-4F4B79840231}.RelWithDebInfo|x86.ActiveCfg = Release|x86 - {05E020F4-6FA1-4DEE-8B9D-4F4B79840231}.RelWithDebInfo|x86.Build.0 = Release|x86 {07221944-6A68-4B82-8461-82C7754B1B1F}.Checked|Any CPU.ActiveCfg = Checked|x86 {07221944-6A68-4B82-8461-82C7754B1B1F}.Checked|x64.ActiveCfg = Checked|x64 {07221944-6A68-4B82-8461-82C7754B1B1F}.Checked|x64.Build.0 = Checked|x64 @@ -145,12 +116,6 @@ Global {07221944-6A68-4B82-8461-82C7754B1B1F}.Release|x64.Build.0 = Release|x64 {07221944-6A68-4B82-8461-82C7754B1B1F}.Release|x86.ActiveCfg = Release|x86 {07221944-6A68-4B82-8461-82C7754B1B1F}.Release|x86.Build.0 = Release|x86 - {07221944-6A68-4B82-8461-82C7754B1B1F}.RelWithDebInfo|Any CPU.ActiveCfg = Release|x64 - {07221944-6A68-4B82-8461-82C7754B1B1F}.RelWithDebInfo|Any CPU.Build.0 = Release|x64 - {07221944-6A68-4B82-8461-82C7754B1B1F}.RelWithDebInfo|x64.ActiveCfg = Release|x64 - {07221944-6A68-4B82-8461-82C7754B1B1F}.RelWithDebInfo|x64.Build.0 = Release|x64 - {07221944-6A68-4B82-8461-82C7754B1B1F}.RelWithDebInfo|x86.ActiveCfg = Release|x86 - {07221944-6A68-4B82-8461-82C7754B1B1F}.RelWithDebInfo|x86.Build.0 = Release|x86 {FFBD9619-DE6F-4A98-8732-8A14EC3C1A18}.Checked|Any CPU.ActiveCfg = Checked|x86 {FFBD9619-DE6F-4A98-8732-8A14EC3C1A18}.Checked|x64.ActiveCfg = Checked|x64 {FFBD9619-DE6F-4A98-8732-8A14EC3C1A18}.Checked|x64.Build.0 = Checked|x64 @@ -166,12 +131,6 @@ Global {FFBD9619-DE6F-4A98-8732-8A14EC3C1A18}.Release|x64.Build.0 = Release|x64 {FFBD9619-DE6F-4A98-8732-8A14EC3C1A18}.Release|x86.ActiveCfg = Release|x86 {FFBD9619-DE6F-4A98-8732-8A14EC3C1A18}.Release|x86.Build.0 = Release|x86 - {FFBD9619-DE6F-4A98-8732-8A14EC3C1A18}.RelWithDebInfo|Any CPU.ActiveCfg = Release|x64 - {FFBD9619-DE6F-4A98-8732-8A14EC3C1A18}.RelWithDebInfo|Any CPU.Build.0 = Release|x64 - {FFBD9619-DE6F-4A98-8732-8A14EC3C1A18}.RelWithDebInfo|x64.ActiveCfg = Release|x64 - {FFBD9619-DE6F-4A98-8732-8A14EC3C1A18}.RelWithDebInfo|x64.Build.0 = Release|x64 - {FFBD9619-DE6F-4A98-8732-8A14EC3C1A18}.RelWithDebInfo|x86.ActiveCfg = Release|x86 - {FFBD9619-DE6F-4A98-8732-8A14EC3C1A18}.RelWithDebInfo|x86.Build.0 = Release|x86 {CBDE0470-E0C9-4693-9A11-ACC117522F3F}.Checked|Any CPU.ActiveCfg = Checked|x86 {CBDE0470-E0C9-4693-9A11-ACC117522F3F}.Checked|x64.ActiveCfg = Checked|x64 {CBDE0470-E0C9-4693-9A11-ACC117522F3F}.Checked|x64.Build.0 = Checked|x64 @@ -187,12 +146,6 @@ Global {CBDE0470-E0C9-4693-9A11-ACC117522F3F}.Release|x64.Build.0 = Release|x64 {CBDE0470-E0C9-4693-9A11-ACC117522F3F}.Release|x86.ActiveCfg = Release|x86 {CBDE0470-E0C9-4693-9A11-ACC117522F3F}.Release|x86.Build.0 = Release|x86 - {CBDE0470-E0C9-4693-9A11-ACC117522F3F}.RelWithDebInfo|Any CPU.ActiveCfg = Release|x64 - {CBDE0470-E0C9-4693-9A11-ACC117522F3F}.RelWithDebInfo|Any CPU.Build.0 = Release|x64 - {CBDE0470-E0C9-4693-9A11-ACC117522F3F}.RelWithDebInfo|x64.ActiveCfg = Release|x64 - {CBDE0470-E0C9-4693-9A11-ACC117522F3F}.RelWithDebInfo|x64.Build.0 = Release|x64 - {CBDE0470-E0C9-4693-9A11-ACC117522F3F}.RelWithDebInfo|x86.ActiveCfg = Release|x86 - {CBDE0470-E0C9-4693-9A11-ACC117522F3F}.RelWithDebInfo|x86.Build.0 = Release|x86 {24CBA9C6-EDBA-47D6-A0B5-04417BDE5FE3}.Checked|Any CPU.ActiveCfg = Checked|x64 {24CBA9C6-EDBA-47D6-A0B5-04417BDE5FE3}.Checked|Any CPU.Build.0 = Checked|x64 {24CBA9C6-EDBA-47D6-A0B5-04417BDE5FE3}.Checked|x64.ActiveCfg = Checked|x64 @@ -211,9 +164,6 @@ Global {24CBA9C6-EDBA-47D6-A0B5-04417BDE5FE3}.Release|x64.Build.0 = Release|x64 {24CBA9C6-EDBA-47D6-A0B5-04417BDE5FE3}.Release|x86.ActiveCfg = Release|x86 {24CBA9C6-EDBA-47D6-A0B5-04417BDE5FE3}.Release|x86.Build.0 = Release|x86 - {24CBA9C6-EDBA-47D6-A0B5-04417BDE5FE3}.RelWithDebInfo|Any CPU.ActiveCfg = Release|x64 - {24CBA9C6-EDBA-47D6-A0B5-04417BDE5FE3}.RelWithDebInfo|x64.ActiveCfg = Release|x64 - {24CBA9C6-EDBA-47D6-A0B5-04417BDE5FE3}.RelWithDebInfo|x86.ActiveCfg = Release|x86 {740CDFF4-B8EC-4A37-951B-C9FE9980EF2A}.Checked|Any CPU.ActiveCfg = Checked|Any CPU {740CDFF4-B8EC-4A37-951B-C9FE9980EF2A}.Checked|Any CPU.Build.0 = Checked|Any CPU {740CDFF4-B8EC-4A37-951B-C9FE9980EF2A}.Checked|x64.ActiveCfg = Checked|x64 @@ -232,9 +182,6 @@ Global {740CDFF4-B8EC-4A37-951B-C9FE9980EF2A}.Release|x64.Build.0 = Release|x64 {740CDFF4-B8EC-4A37-951B-C9FE9980EF2A}.Release|x86.ActiveCfg = Release|Any CPU {740CDFF4-B8EC-4A37-951B-C9FE9980EF2A}.Release|x86.Build.0 = Release|Any CPU - {740CDFF4-B8EC-4A37-951B-C9FE9980EF2A}.RelWithDebInfo|Any CPU.ActiveCfg = Release|Any CPU - {740CDFF4-B8EC-4A37-951B-C9FE9980EF2A}.RelWithDebInfo|x64.ActiveCfg = Release|x64 - {740CDFF4-B8EC-4A37-951B-C9FE9980EF2A}.RelWithDebInfo|x86.ActiveCfg = Release|Any CPU {4CF2ECD3-A1C3-4A28-AB08-A61C53114143}.Checked|Any CPU.ActiveCfg = Checked|x64 {4CF2ECD3-A1C3-4A28-AB08-A61C53114143}.Checked|Any CPU.Build.0 = Checked|x64 {4CF2ECD3-A1C3-4A28-AB08-A61C53114143}.Checked|x64.ActiveCfg = Checked|x64 @@ -253,9 +200,6 @@ Global {4CF2ECD3-A1C3-4A28-AB08-A61C53114143}.Release|x64.Build.0 = Release|x64 {4CF2ECD3-A1C3-4A28-AB08-A61C53114143}.Release|x86.ActiveCfg = Release|x86 {4CF2ECD3-A1C3-4A28-AB08-A61C53114143}.Release|x86.Build.0 = Release|x86 - {4CF2ECD3-A1C3-4A28-AB08-A61C53114143}.RelWithDebInfo|Any CPU.ActiveCfg = Release|x64 - {4CF2ECD3-A1C3-4A28-AB08-A61C53114143}.RelWithDebInfo|x64.ActiveCfg = Release|x64 - {4CF2ECD3-A1C3-4A28-AB08-A61C53114143}.RelWithDebInfo|x86.ActiveCfg = Release|x86 {9DA153BF-51C4-4AD7-A355-9F9528843DC7}.Checked|Any CPU.ActiveCfg = Debug|Any CPU {9DA153BF-51C4-4AD7-A355-9F9528843DC7}.Checked|Any CPU.Build.0 = Debug|Any CPU {9DA153BF-51C4-4AD7-A355-9F9528843DC7}.Checked|x64.ActiveCfg = Debug|Any CPU @@ -274,9 +218,6 @@ Global {9DA153BF-51C4-4AD7-A355-9F9528843DC7}.Release|x64.Build.0 = Release|Any CPU {9DA153BF-51C4-4AD7-A355-9F9528843DC7}.Release|x86.ActiveCfg = Release|Any CPU {9DA153BF-51C4-4AD7-A355-9F9528843DC7}.Release|x86.Build.0 = Release|Any CPU - {9DA153BF-51C4-4AD7-A355-9F9528843DC7}.RelWithDebInfo|Any CPU.ActiveCfg = Release|Any CPU - {9DA153BF-51C4-4AD7-A355-9F9528843DC7}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU - {9DA153BF-51C4-4AD7-A355-9F9528843DC7}.RelWithDebInfo|x86.ActiveCfg = Release|Any CPU {219E0AC3-CDBF-4104-B324-85915DD16E25}.Checked|Any CPU.ActiveCfg = Debug|Any CPU {219E0AC3-CDBF-4104-B324-85915DD16E25}.Checked|Any CPU.Build.0 = Debug|Any CPU {219E0AC3-CDBF-4104-B324-85915DD16E25}.Checked|x64.ActiveCfg = Debug|Any CPU @@ -295,45 +236,6 @@ Global {219E0AC3-CDBF-4104-B324-85915DD16E25}.Release|x64.Build.0 = Release|Any CPU {219E0AC3-CDBF-4104-B324-85915DD16E25}.Release|x86.ActiveCfg = Release|Any CPU {219E0AC3-CDBF-4104-B324-85915DD16E25}.Release|x86.Build.0 = Release|Any CPU - {219E0AC3-CDBF-4104-B324-85915DD16E25}.RelWithDebInfo|Any CPU.ActiveCfg = Release|Any CPU - {219E0AC3-CDBF-4104-B324-85915DD16E25}.RelWithDebInfo|x64.ActiveCfg = Release|Any CPU - {219E0AC3-CDBF-4104-B324-85915DD16E25}.RelWithDebInfo|x86.ActiveCfg = Release|Any CPU - {74666FB9-0C0D-3452-A912-3D571F908AA8}.Checked|Any CPU.ActiveCfg = Checked|x64 - {74666FB9-0C0D-3452-A912-3D571F908AA8}.Checked|Any CPU.Build.0 = Checked|x64 - {74666FB9-0C0D-3452-A912-3D571F908AA8}.Checked|Any CPU.Deploy.0 = Checked|x64 - {74666FB9-0C0D-3452-A912-3D571F908AA8}.Checked|x64.ActiveCfg = Checked|x64 - {74666FB9-0C0D-3452-A912-3D571F908AA8}.Checked|x64.Build.0 = Checked|x64 - {74666FB9-0C0D-3452-A912-3D571F908AA8}.Checked|x64.Deploy.0 = Checked|x64 - {74666FB9-0C0D-3452-A912-3D571F908AA8}.Checked|x86.ActiveCfg = Checked|x64 - {74666FB9-0C0D-3452-A912-3D571F908AA8}.Checked|x86.Build.0 = Checked|x64 - {74666FB9-0C0D-3452-A912-3D571F908AA8}.Checked|x86.Deploy.0 = Checked|x64 - {74666FB9-0C0D-3452-A912-3D571F908AA8}.Debug|Any CPU.ActiveCfg = Debug|x64 - {74666FB9-0C0D-3452-A912-3D571F908AA8}.Debug|Any CPU.Build.0 = Debug|x64 - {74666FB9-0C0D-3452-A912-3D571F908AA8}.Debug|Any CPU.Deploy.0 = Debug|x64 - {74666FB9-0C0D-3452-A912-3D571F908AA8}.Debug|x64.ActiveCfg = Debug|x64 - {74666FB9-0C0D-3452-A912-3D571F908AA8}.Debug|x64.Build.0 = Debug|x64 - {74666FB9-0C0D-3452-A912-3D571F908AA8}.Debug|x64.Deploy.0 = Debug|x64 - {74666FB9-0C0D-3452-A912-3D571F908AA8}.Debug|x86.ActiveCfg = Debug|x64 - {74666FB9-0C0D-3452-A912-3D571F908AA8}.Debug|x86.Build.0 = Debug|x64 - {74666FB9-0C0D-3452-A912-3D571F908AA8}.Debug|x86.Deploy.0 = Debug|x64 - {74666FB9-0C0D-3452-A912-3D571F908AA8}.Release|Any CPU.ActiveCfg = Release|x64 - {74666FB9-0C0D-3452-A912-3D571F908AA8}.Release|Any CPU.Build.0 = Release|x64 - {74666FB9-0C0D-3452-A912-3D571F908AA8}.Release|Any CPU.Deploy.0 = Release|x64 - {74666FB9-0C0D-3452-A912-3D571F908AA8}.Release|x64.ActiveCfg = Release|x64 - {74666FB9-0C0D-3452-A912-3D571F908AA8}.Release|x64.Build.0 = Release|x64 - {74666FB9-0C0D-3452-A912-3D571F908AA8}.Release|x64.Deploy.0 = Release|x64 - {74666FB9-0C0D-3452-A912-3D571F908AA8}.Release|x86.ActiveCfg = Release|x64 - {74666FB9-0C0D-3452-A912-3D571F908AA8}.Release|x86.Build.0 = Release|x64 - {74666FB9-0C0D-3452-A912-3D571F908AA8}.Release|x86.Deploy.0 = Release|x64 - {74666FB9-0C0D-3452-A912-3D571F908AA8}.RelWithDebInfo|Any CPU.ActiveCfg = RelWithDebInfo|x64 - {74666FB9-0C0D-3452-A912-3D571F908AA8}.RelWithDebInfo|Any CPU.Build.0 = RelWithDebInfo|x64 - {74666FB9-0C0D-3452-A912-3D571F908AA8}.RelWithDebInfo|Any CPU.Deploy.0 = RelWithDebInfo|x64 - {74666FB9-0C0D-3452-A912-3D571F908AA8}.RelWithDebInfo|x64.ActiveCfg = RelWithDebInfo|x64 - {74666FB9-0C0D-3452-A912-3D571F908AA8}.RelWithDebInfo|x64.Build.0 = RelWithDebInfo|x64 - {74666FB9-0C0D-3452-A912-3D571F908AA8}.RelWithDebInfo|x64.Deploy.0 = RelWithDebInfo|x64 - {74666FB9-0C0D-3452-A912-3D571F908AA8}.RelWithDebInfo|x86.ActiveCfg = RelWithDebInfo|x64 - {74666FB9-0C0D-3452-A912-3D571F908AA8}.RelWithDebInfo|x86.Build.0 = RelWithDebInfo|x64 - {74666FB9-0C0D-3452-A912-3D571F908AA8}.RelWithDebInfo|x86.Deploy.0 = RelWithDebInfo|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From 9ca78ae2bf4848edf9644a08fe758210d67e7dc7 Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Sat, 29 Jul 2023 21:16:48 -0700 Subject: [PATCH 19/58] missing gtInitCldHnd initialization --- src/coreclr/jit/importer.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index 30f038aa02c82a..4c1961f047873a 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -3814,6 +3814,7 @@ GenTree* Compiler::impImportStaticFieldAddress(CORINFO_RESOLVED_TOKEN* pResolved if (pFieldInfo->fieldAccessor == CORINFO_FIELD_STATIC_TLS_MANAGED) { op1->AsCall()->SetExpTLSFieldAccess(); + op1->AsCall()->gtInitClsHnd = pResolvedToken->hClass; } else if (pFieldInfo->fieldAccessor == CORINFO_FIELD_STATIC_TLS_MANAGED_LAZY) { From b142d28eb167496d73276d346791c575614679a0 Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Sun, 30 Jul 2023 03:06:49 -0700 Subject: [PATCH 20/58] save target address --- src/coreclr/jit/emitxarch.cpp | 9 +++++--- src/coreclr/jit/helperexpansion.cpp | 33 ++++++++++++++++++++--------- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/src/coreclr/jit/emitxarch.cpp b/src/coreclr/jit/emitxarch.cpp index cff04dd5f18547..a3b361b6cba425 100644 --- a/src/coreclr/jit/emitxarch.cpp +++ b/src/coreclr/jit/emitxarch.cpp @@ -15152,12 +15152,15 @@ BYTE* emitter::emitOutputRI(BYTE* dst, instrDesc* id) if (id->idIsCnsReloc()) { - uint16_t relocationType = IMAGE_REL_BASED_MOFFSET; if (emitComp->opts.IsReadyToRun() && id->idAddr()->isSecRel) { - relocationType = IMAGE_REL_SECREL; + emitRecordRelocation((void*)(dst - (unsigned)EA_SIZE(size)), (void*)(size_t)val, IMAGE_REL_SECREL); + } + else + { + emitRecordRelocation((void*)(dst - (unsigned)EA_SIZE(size)), (void*)(size_t)val, + IMAGE_REL_BASED_MOFFSET); } - emitRecordRelocation((void*)(dst - (unsigned)EA_SIZE(size)), (void*)(size_t)val, relocationType); } goto DONE; diff --git a/src/coreclr/jit/helperexpansion.cpp b/src/coreclr/jit/helperexpansion.cpp index 94081dedd05f81..ca9cab1899b07d 100644 --- a/src/coreclr/jit/helperexpansion.cpp +++ b/src/coreclr/jit/helperexpansion.cpp @@ -428,7 +428,9 @@ PhaseStatus Compiler::fgExpandThreadLocalAccess() return result; } - if (opts.OptimizationDisabled()) + // Always expand for NativeAOT, see + const bool isNativeAOT = IsTargetAbi(CORINFO_NATIVEAOT_ABI); + if (!isNativeAOT && opts.OptimizationDisabled()) { JITDUMP("Optimizations aren't allowed - bail out.\n") return result; @@ -443,7 +445,8 @@ PhaseStatus Compiler::fgExpandThreadLocalAccess() return result; } - return opts.IsReadyToRun() ? fgExpandHelper<&Compiler::fgExpandThreadLocalAccessForCallReadyToRun>(false) + return isNativeAOT ? fgExpandHelper<&Compiler::fgExpandThreadLocalAccessForCallReadyToRun>( + false /* expand rarely run blocks for NativeAOT */) : fgExpandHelper<&Compiler::fgExpandThreadLocalAccessForCall>(true); } @@ -530,11 +533,18 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S // target symbol GenTree* targetSymbolAddr = gtNewIconHandleNode((size_t)lazyCtorTargetSymbol.addr, GTF_ICON_OBJ_HDL); + targetSymbolAddr = gtNewOperNode(GT_ADD, TYP_I_IMPL, targetSymbolAddr, gtNewIconNode(classCtorContextSize, TYP_I_IMPL)); - targetSymbCondBB = fgNewBBFromTreeAfter(BBJ_COND, prevBb, gtCloneExpr(targetSymbolAddr), debugInfo); - GenTree* targetSymbolAddrVal = gtNewIndir(TYP_I_IMPL, targetSymbolAddr); + unsigned targetSymbolLclNum = lvaGrabTemp(true DEBUGARG("Target symbol")); + lvaTable[targetSymbolLclNum].lvType = TYP_I_IMPL; + GenTree* tlsRootAddrDef = gtNewStoreLclVarNode(targetSymbolLclNum, targetSymbolAddr); + GenTree* tlsRootAddrUse = gtNewLclVarNode(targetSymbolLclNum); + + targetSymbCondBB = fgNewBBFromTreeAfter(BBJ_COND, prevBb, gtCloneExpr(tlsRootAddrUse), debugInfo); + + GenTree* targetSymbolAddrVal = gtNewIndir(TYP_I_IMPL, tlsRootAddrUse); GenTree* targetSymbolNullCond = gtNewOperNode(GT_EQ, TYP_INT, targetSymbolAddrVal, gtNewIconNode(0, TYP_I_IMPL)); targetSymbolNullCond = gtNewOperNode(GT_JTRUE, TYP_VOID, targetSymbolNullCond); @@ -550,12 +560,13 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S classCtorRunHelperCall->gtArgs.PushBack(this, NewCallArg::Primitive(gtNewIconNode(-1))); // arg2: NonGCStatics targetSymbol - classCtorRunHelperCall->gtArgs.PushBack(this, NewCallArg::Primitive(gtCloneExpr(targetSymbolAddr))); + classCtorRunHelperCall->gtArgs.PushBack(this, NewCallArg::Primitive(gtCloneExpr(tlsRootAddrUse))); fgMorphArgs(classCtorRunHelperCall); GenTree* lazyCtorValueDef = gtNewStoreLclVarNode(finalLclNum, classCtorRunHelperCall); lazyCtorBB = fgNewBBFromTreeAfter(BBJ_ALWAYS, targetSymbCondBB, lazyCtorValueDef, debugInfo, true); + fgInsertStmtAfter(targetSymbCondBB, targetSymbCondBB->firstStmt(), fgNewStmtFromTree(tlsRootAddrDef)); fgRemoveRefPred(block, prevBb); fgAddRefPred(targetSymbCondBB, prevBb); @@ -576,6 +587,8 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S // lazyCtorBB is the new previous block going forward prevBb = lazyCtorBB; + JITDUMP("lazyCtorBB: " FMT_BB "\n", lazyCtorBB->bbNum); + JITDUMP("targetSymbCondBB: " FMT_BB "\n", targetSymbCondBB->bbNum); } // Block ops inserted by the split need to be morphed here since we are after morph. @@ -590,12 +603,8 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S if (TargetOS::IsWindows) { #ifdef TARGET_64BIT - GenTree* tlsValue = nullptr; - unsigned tlsLclNum = lvaGrabTemp(true DEBUGARG("TLS access")); - lvaTable[tlsLclNum].lvType = TYP_I_IMPL; - // Mark this ICON as a TLS_HDL, codegen will use FS:[cns] or GS:[cns] - tlsValue = gtNewIconHandleNode(threadStaticInfo.offsetOfThreadLocalStoragePointer, GTF_ICON_TLS_HDL); + GenTree* tlsValue = gtNewIconHandleNode(threadStaticInfo.offsetOfThreadLocalStoragePointer, GTF_ICON_TLS_HDL); tlsValue = gtNewIndir(TYP_I_IMPL, tlsValue, GTF_IND_NONFAULTING | GTF_IND_INVARIANT); CORINFO_CONST_LOOKUP tlsIndexObject = threadStaticInfo.tlsIndexObject; @@ -707,6 +716,10 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S assert(BasicBlock::sameEHRegion(prevBb, block)); assert(BasicBlock::sameEHRegion(prevBb, tlsRootNullCondBB)); assert(BasicBlock::sameEHRegion(prevBb, fastPathBb)); + + JITDUMP("tlsRootNullCondBB: " FMT_BB "\n", tlsRootNullCondBB->bbNum); + JITDUMP("fastPathBb: " FMT_BB "\n", fastPathBb->bbNum); + JITDUMP("fallbackBb: " FMT_BB "\n", fallbackBb->bbNum); #else assert(!"Unsupported scenario\n"); From 79de72803cf94525c29ad00d745035b1fdfc22d0 Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Sun, 30 Jul 2023 11:28:28 -0700 Subject: [PATCH 21/58] jit format --- src/coreclr/jit/helperexpansion.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/coreclr/jit/helperexpansion.cpp b/src/coreclr/jit/helperexpansion.cpp index ca9cab1899b07d..e9979f2b899f81 100644 --- a/src/coreclr/jit/helperexpansion.cpp +++ b/src/coreclr/jit/helperexpansion.cpp @@ -447,7 +447,7 @@ PhaseStatus Compiler::fgExpandThreadLocalAccess() return isNativeAOT ? fgExpandHelper<&Compiler::fgExpandThreadLocalAccessForCallReadyToRun>( false /* expand rarely run blocks for NativeAOT */) - : fgExpandHelper<&Compiler::fgExpandThreadLocalAccessForCall>(true); + : fgExpandHelper<&Compiler::fgExpandThreadLocalAccessForCall>(true); } bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, Statement* stmt, GenTreeCall* call) @@ -541,7 +541,7 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S lvaTable[targetSymbolLclNum].lvType = TYP_I_IMPL; GenTree* tlsRootAddrDef = gtNewStoreLclVarNode(targetSymbolLclNum, targetSymbolAddr); GenTree* tlsRootAddrUse = gtNewLclVarNode(targetSymbolLclNum); - + targetSymbCondBB = fgNewBBFromTreeAfter(BBJ_COND, prevBb, gtCloneExpr(tlsRootAddrUse), debugInfo); GenTree* targetSymbolAddrVal = gtNewIndir(TYP_I_IMPL, tlsRootAddrUse); @@ -605,7 +605,7 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S #ifdef TARGET_64BIT // Mark this ICON as a TLS_HDL, codegen will use FS:[cns] or GS:[cns] GenTree* tlsValue = gtNewIconHandleNode(threadStaticInfo.offsetOfThreadLocalStoragePointer, GTF_ICON_TLS_HDL); - tlsValue = gtNewIndir(TYP_I_IMPL, tlsValue, GTF_IND_NONFAULTING | GTF_IND_INVARIANT); + tlsValue = gtNewIndir(TYP_I_IMPL, tlsValue, GTF_IND_NONFAULTING | GTF_IND_INVARIANT); CORINFO_CONST_LOOKUP tlsIndexObject = threadStaticInfo.tlsIndexObject; From 1fe8103d8f4024239930d546584d2b2cfe50fc2f Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Mon, 20 Nov 2023 07:09:50 -0800 Subject: [PATCH 22/58] run thunkgenerator --- src/coreclr/inc/jiteeversionguid.h | 10 +- .../JitInterface/CorInfoImpl_generated.cs | 155 +++++++++--------- 2 files changed, 83 insertions(+), 82 deletions(-) diff --git a/src/coreclr/inc/jiteeversionguid.h b/src/coreclr/inc/jiteeversionguid.h index 87bd41898253d2..7538272e80bcd4 100644 --- a/src/coreclr/inc/jiteeversionguid.h +++ b/src/coreclr/inc/jiteeversionguid.h @@ -43,11 +43,11 @@ typedef const GUID *LPCGUID; #define GUID_DEFINED #endif // !GUID_DEFINED -constexpr GUID JITEEVersionIdentifier = { /* 7dc54d34-512f-4ba6-9eb5-6ff61bab144e */ - 0x7dc54d34, - 0x512f, - 0x4ba6, - {0x9e, 0xb5, 0x6f, 0xf6, 0x1b, 0xab, 0x14, 0x4e} +constexpr GUID JITEEVersionIdentifier = { /* b9720ec9-0a3e-4ef7-9475-ac0e5352a32f */ + 0xb9720ec9, + 0x0a3e, + 0x4ef7, + {0x94, 0x75, 0xac, 0x0e, 0x53, 0x52, 0xa3, 0x2f} }; ////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs b/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs index 3ca4e86a7f78f1..b987c71b8083f2 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs @@ -2536,7 +2536,7 @@ private static uint _getJitFlags(IntPtr thisHandle, IntPtr* ppException, CORJIT_ private static IntPtr GetUnmanagedCallbacks() { - void** callbacks = (void**)Marshal.AllocCoTaskMem(sizeof(IntPtr) * 170); + void** callbacks = (void**)Marshal.AllocCoTaskMem(sizeof(IntPtr) * 171); callbacks[0] = (delegate* unmanaged)&_isIntrinsic; callbacks[1] = (delegate* unmanaged)&_getMethodAttribs; @@ -2632,82 +2632,83 @@ private static IntPtr GetUnmanagedCallbacks() callbacks[91] = (delegate* unmanaged)&_getFieldOffset; callbacks[92] = (delegate* unmanaged)&_getFieldInfo; callbacks[93] = (delegate* unmanaged)&_getThreadLocalFieldInfo; - callbacks[94] = (delegate* unmanaged)&_getThreadLocalStaticInfo_ReadyToRun; - callbacks[95] = (delegate* unmanaged)&_isFieldStatic; - callbacks[96] = (delegate* unmanaged)&_getArrayOrStringLength; - callbacks[97] = (delegate* unmanaged)&_getBoundaries; - callbacks[98] = (delegate* unmanaged)&_setBoundaries; - callbacks[99] = (delegate* unmanaged)&_getVars; - callbacks[100] = (delegate* unmanaged)&_setVars; - callbacks[101] = (delegate* unmanaged)&_reportRichMappings; - callbacks[102] = (delegate* unmanaged)&_allocateArray; - callbacks[103] = (delegate* unmanaged)&_freeArray; - callbacks[104] = (delegate* unmanaged)&_getArgNext; - callbacks[105] = (delegate* unmanaged)&_getArgType; - callbacks[106] = (delegate* unmanaged)&_getExactClasses; - callbacks[107] = (delegate* unmanaged)&_getArgClass; - callbacks[108] = (delegate* unmanaged)&_getHFAType; - callbacks[109] = (delegate* unmanaged)&_runWithErrorTrap; - callbacks[110] = (delegate* unmanaged)&_runWithSPMIErrorTrap; - callbacks[111] = (delegate* unmanaged)&_getEEInfo; - callbacks[112] = (delegate* unmanaged)&_getJitTimeLogFilename; - callbacks[113] = (delegate* unmanaged)&_getMethodDefFromMethod; - callbacks[114] = (delegate* unmanaged)&_printMethodName; - callbacks[115] = (delegate* unmanaged)&_getMethodNameFromMetadata; - callbacks[116] = (delegate* unmanaged)&_getMethodHash; - callbacks[117] = (delegate* unmanaged)&_getSystemVAmd64PassStructInRegisterDescriptor; - callbacks[118] = (delegate* unmanaged)&_getLoongArch64PassStructInRegisterFlags; - callbacks[119] = (delegate* unmanaged)&_getRISCV64PassStructInRegisterFlags; - callbacks[120] = (delegate* unmanaged)&_getThreadTLSIndex; - callbacks[121] = (delegate* unmanaged)&_getAddrOfCaptureThreadGlobal; - callbacks[122] = (delegate* unmanaged)&_getHelperFtn; - callbacks[123] = (delegate* unmanaged)&_getFunctionEntryPoint; - callbacks[124] = (delegate* unmanaged)&_getFunctionFixedEntryPoint; - callbacks[125] = (delegate* unmanaged)&_getMethodSync; - callbacks[126] = (delegate* unmanaged)&_getLazyStringLiteralHelper; - callbacks[127] = (delegate* unmanaged)&_embedModuleHandle; - callbacks[128] = (delegate* unmanaged)&_embedClassHandle; - callbacks[129] = (delegate* unmanaged)&_embedMethodHandle; - callbacks[130] = (delegate* unmanaged)&_embedFieldHandle; - callbacks[131] = (delegate* unmanaged)&_embedGenericHandle; - callbacks[132] = (delegate* unmanaged)&_getLocationOfThisType; - callbacks[133] = (delegate* unmanaged)&_getAddressOfPInvokeTarget; - callbacks[134] = (delegate* unmanaged)&_GetCookieForPInvokeCalliSig; - callbacks[135] = (delegate* unmanaged)&_canGetCookieForPInvokeCalliSig; - callbacks[136] = (delegate* unmanaged)&_getJustMyCodeHandle; - callbacks[137] = (delegate* unmanaged)&_GetProfilingHandle; - callbacks[138] = (delegate* unmanaged)&_getCallInfo; - callbacks[139] = (delegate* unmanaged)&_getClassDomainID; - callbacks[140] = (delegate* unmanaged)&_getStaticFieldContent; - callbacks[141] = (delegate* unmanaged)&_getObjectContent; - callbacks[142] = (delegate* unmanaged)&_getStaticFieldCurrentClass; - callbacks[143] = (delegate* unmanaged)&_getVarArgsHandle; - callbacks[144] = (delegate* unmanaged)&_canGetVarArgsHandle; - callbacks[145] = (delegate* unmanaged)&_constructStringLiteral; - callbacks[146] = (delegate* unmanaged)&_emptyStringLiteral; - callbacks[147] = (delegate* unmanaged)&_getFieldThreadLocalStoreID; - callbacks[148] = (delegate* unmanaged)&_GetDelegateCtor; - callbacks[149] = (delegate* unmanaged)&_MethodCompileComplete; - callbacks[150] = (delegate* unmanaged)&_getTailCallHelpers; - callbacks[151] = (delegate* unmanaged)&_convertPInvokeCalliToCall; - callbacks[152] = (delegate* unmanaged)&_notifyInstructionSetUsage; - callbacks[153] = (delegate* unmanaged)&_updateEntryPointForTailCall; - callbacks[154] = (delegate* unmanaged)&_allocMem; - callbacks[155] = (delegate* unmanaged)&_reserveUnwindInfo; - callbacks[156] = (delegate* unmanaged)&_allocUnwindInfo; - callbacks[157] = (delegate* unmanaged)&_allocGCInfo; - callbacks[158] = (delegate* unmanaged)&_setEHcount; - callbacks[159] = (delegate* unmanaged)&_setEHinfo; - callbacks[160] = (delegate* unmanaged)&_logMsg; - callbacks[161] = (delegate* unmanaged)&_doAssert; - callbacks[162] = (delegate* unmanaged)&_reportFatalError; - callbacks[163] = (delegate* unmanaged)&_getPgoInstrumentationResults; - callbacks[164] = (delegate* unmanaged)&_allocPgoInstrumentationBySchema; - callbacks[165] = (delegate* unmanaged)&_recordCallSite; - callbacks[166] = (delegate* unmanaged)&_recordRelocation; - callbacks[167] = (delegate* unmanaged)&_getRelocTypeHint; - callbacks[168] = (delegate* unmanaged)&_getExpectedTargetArchitecture; - callbacks[169] = (delegate* unmanaged)&_getJitFlags; + callbacks[94] = (delegate* unmanaged)&_getThreadLocalStaticBlocksInfo; + callbacks[95] = (delegate* unmanaged)&_getThreadLocalStaticInfo_ReadyToRun; + callbacks[96] = (delegate* unmanaged)&_isFieldStatic; + callbacks[97] = (delegate* unmanaged)&_getArrayOrStringLength; + callbacks[98] = (delegate* unmanaged)&_getBoundaries; + callbacks[99] = (delegate* unmanaged)&_setBoundaries; + callbacks[100] = (delegate* unmanaged)&_getVars; + callbacks[101] = (delegate* unmanaged)&_setVars; + callbacks[102] = (delegate* unmanaged)&_reportRichMappings; + callbacks[103] = (delegate* unmanaged)&_allocateArray; + callbacks[104] = (delegate* unmanaged)&_freeArray; + callbacks[105] = (delegate* unmanaged)&_getArgNext; + callbacks[106] = (delegate* unmanaged)&_getArgType; + callbacks[107] = (delegate* unmanaged)&_getExactClasses; + callbacks[108] = (delegate* unmanaged)&_getArgClass; + callbacks[109] = (delegate* unmanaged)&_getHFAType; + callbacks[110] = (delegate* unmanaged)&_runWithErrorTrap; + callbacks[111] = (delegate* unmanaged)&_runWithSPMIErrorTrap; + callbacks[112] = (delegate* unmanaged)&_getEEInfo; + callbacks[113] = (delegate* unmanaged)&_getJitTimeLogFilename; + callbacks[114] = (delegate* unmanaged)&_getMethodDefFromMethod; + callbacks[115] = (delegate* unmanaged)&_printMethodName; + callbacks[116] = (delegate* unmanaged)&_getMethodNameFromMetadata; + callbacks[117] = (delegate* unmanaged)&_getMethodHash; + callbacks[118] = (delegate* unmanaged)&_getSystemVAmd64PassStructInRegisterDescriptor; + callbacks[119] = (delegate* unmanaged)&_getLoongArch64PassStructInRegisterFlags; + callbacks[120] = (delegate* unmanaged)&_getRISCV64PassStructInRegisterFlags; + callbacks[121] = (delegate* unmanaged)&_getThreadTLSIndex; + callbacks[122] = (delegate* unmanaged)&_getAddrOfCaptureThreadGlobal; + callbacks[123] = (delegate* unmanaged)&_getHelperFtn; + callbacks[124] = (delegate* unmanaged)&_getFunctionEntryPoint; + callbacks[125] = (delegate* unmanaged)&_getFunctionFixedEntryPoint; + callbacks[126] = (delegate* unmanaged)&_getMethodSync; + callbacks[127] = (delegate* unmanaged)&_getLazyStringLiteralHelper; + callbacks[128] = (delegate* unmanaged)&_embedModuleHandle; + callbacks[129] = (delegate* unmanaged)&_embedClassHandle; + callbacks[130] = (delegate* unmanaged)&_embedMethodHandle; + callbacks[131] = (delegate* unmanaged)&_embedFieldHandle; + callbacks[132] = (delegate* unmanaged)&_embedGenericHandle; + callbacks[133] = (delegate* unmanaged)&_getLocationOfThisType; + callbacks[134] = (delegate* unmanaged)&_getAddressOfPInvokeTarget; + callbacks[135] = (delegate* unmanaged)&_GetCookieForPInvokeCalliSig; + callbacks[136] = (delegate* unmanaged)&_canGetCookieForPInvokeCalliSig; + callbacks[137] = (delegate* unmanaged)&_getJustMyCodeHandle; + callbacks[138] = (delegate* unmanaged)&_GetProfilingHandle; + callbacks[139] = (delegate* unmanaged)&_getCallInfo; + callbacks[140] = (delegate* unmanaged)&_getClassDomainID; + callbacks[141] = (delegate* unmanaged)&_getStaticFieldContent; + callbacks[142] = (delegate* unmanaged)&_getObjectContent; + callbacks[143] = (delegate* unmanaged)&_getStaticFieldCurrentClass; + callbacks[144] = (delegate* unmanaged)&_getVarArgsHandle; + callbacks[145] = (delegate* unmanaged)&_canGetVarArgsHandle; + callbacks[146] = (delegate* unmanaged)&_constructStringLiteral; + callbacks[147] = (delegate* unmanaged)&_emptyStringLiteral; + callbacks[148] = (delegate* unmanaged)&_getFieldThreadLocalStoreID; + callbacks[149] = (delegate* unmanaged)&_GetDelegateCtor; + callbacks[150] = (delegate* unmanaged)&_MethodCompileComplete; + callbacks[151] = (delegate* unmanaged)&_getTailCallHelpers; + callbacks[152] = (delegate* unmanaged)&_convertPInvokeCalliToCall; + callbacks[153] = (delegate* unmanaged)&_notifyInstructionSetUsage; + callbacks[154] = (delegate* unmanaged)&_updateEntryPointForTailCall; + callbacks[155] = (delegate* unmanaged)&_allocMem; + callbacks[156] = (delegate* unmanaged)&_reserveUnwindInfo; + callbacks[157] = (delegate* unmanaged)&_allocUnwindInfo; + callbacks[158] = (delegate* unmanaged)&_allocGCInfo; + callbacks[159] = (delegate* unmanaged)&_setEHcount; + callbacks[160] = (delegate* unmanaged)&_setEHinfo; + callbacks[161] = (delegate* unmanaged)&_logMsg; + callbacks[162] = (delegate* unmanaged)&_doAssert; + callbacks[163] = (delegate* unmanaged)&_reportFatalError; + callbacks[164] = (delegate* unmanaged)&_getPgoInstrumentationResults; + callbacks[165] = (delegate* unmanaged)&_allocPgoInstrumentationBySchema; + callbacks[166] = (delegate* unmanaged)&_recordCallSite; + callbacks[167] = (delegate* unmanaged)&_recordRelocation; + callbacks[168] = (delegate* unmanaged)&_getRelocTypeHint; + callbacks[169] = (delegate* unmanaged)&_getExpectedTargetArchitecture; + callbacks[170] = (delegate* unmanaged)&_getJitFlags; return (IntPtr)callbacks; } From 7c03b66433a2afa329a34ff8f5c7ad2bef34af00 Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Fri, 1 Dec 2023 11:05:03 -0800 Subject: [PATCH 23/58] resolve merge conflicts --- src/coreclr/jit/gentree.h | 4 ++-- src/coreclr/jit/helperexpansion.cpp | 18 +++++++----------- src/coreclr/jit/importer.cpp | 1 - 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/coreclr/jit/gentree.h b/src/coreclr/jit/gentree.h index 68327b8f89be6f..0a8ef713e0e57c 100644 --- a/src/coreclr/jit/gentree.h +++ b/src/coreclr/jit/gentree.h @@ -5452,8 +5452,6 @@ struct GenTreeCall final : public GenTree return (gtCallMoreFlags & GTF_CALL_M_EXP_RUNTIME_LOOKUP) != 0; } - } - void SetExpTLSFieldAccessLazyCtor() { gtCallMoreFlags |= GTF_CALL_M_EXP_TLS_ACCESS_LAZY; @@ -5467,6 +5465,8 @@ struct GenTreeCall final : public GenTree bool IsExpTLSFieldAccessLazyCtor() const { return (gtCallMoreFlags & GTF_CALL_M_EXP_TLS_ACCESS_LAZY) != 0; + } + void SetExpandedEarly() { gtCallMoreFlags |= GTF_CALL_M_EXPANDED_EARLY; diff --git a/src/coreclr/jit/helperexpansion.cpp b/src/coreclr/jit/helperexpansion.cpp index 4ee367d9bca4f5..00929d7c3c0c32 100644 --- a/src/coreclr/jit/helperexpansion.cpp +++ b/src/coreclr/jit/helperexpansion.cpp @@ -467,7 +467,6 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S JITDUMP("\n"); bool hasLazyStaticCtor = call->IsExpTLSFieldAccessLazyCtor(); - call->ClearExpTLSFieldAccess(); call->ClearExpTLSFieldAccessLazyCtor(); CORINFO_THREAD_STATIC_INFO_READYTORUN threadStaticInfo; @@ -568,7 +567,7 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S fgMorphArgs(classCtorRunHelperCall); GenTree* lazyCtorValueDef = gtNewStoreLclVarNode(finalLclNum, classCtorRunHelperCall); - lazyCtorBB = fgNewBBFromTreeAfter(BBJ_ALWAYS, targetSymbCondBB, lazyCtorValueDef, debugInfo, true); + lazyCtorBB = fgNewBBFromTreeAfter(BBJ_ALWAYS, targetSymbCondBB, lazyCtorValueDef, debugInfo, block, true); fgInsertStmtAfter(targetSymbCondBB, targetSymbCondBB->firstStmt(), fgNewStmtFromTree(tlsRootAddrDef)); fgRemoveRefPred(block, prevBb); @@ -576,8 +575,6 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S fgAddRefPred(lazyCtorBB, targetSymbCondBB); fgAddRefPred(block, lazyCtorBB); - lazyCtorBB->bbJumpDest = block; - // Inherit the weights block->inheritWeight(prevBb); targetSymbCondBB->inheritWeight(prevBb); @@ -658,10 +655,11 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S // fallbackBb GenTree* fallbackValueDef = gtNewStoreLclVarNode(finalLclNum, slowHelper); - BasicBlock* fallbackBb = fgNewBBFromTreeAfter(BBJ_ALWAYS, tlsRootNullCondBB, fallbackValueDef, debugInfo, true); + BasicBlock* fallbackBb = + fgNewBBFromTreeAfter(BBJ_ALWAYS, tlsRootNullCondBB, fallbackValueDef, debugInfo, block, true); GenTree* fastPathValueDef = gtNewStoreLclVarNode(finalLclNum, gtCloneExpr(finalLcl)); - BasicBlock* fastPathBb = fgNewBBFromTreeAfter(BBJ_ALWAYS, fallbackBb, fastPathValueDef, debugInfo, true); + BasicBlock* fastPathBb = fgNewBBFromTreeAfter(BBJ_ALWAYS, fallbackBb, fastPathValueDef, debugInfo, block, true); *callUse = finalLcl; @@ -677,9 +675,7 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S fgAddRefPred(block, fallbackBb); fgAddRefPred(block, fastPathBb); - tlsRootNullCondBB->bbJumpDest = fastPathBb; - fastPathBb->bbJumpDest = block; - fallbackBb->bbJumpDest = block; + tlsRootNullCondBB->SetJumpDest(fastPathBb); // Inherit the weights block->inheritWeight(prevBb); @@ -694,8 +690,8 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S assert(targetSymbCondBB != nullptr); assert(lazyCtorBB != nullptr); - targetSymbCondBB->bbJumpDest = tlsRootNullCondBB; - lazyCtorBB->bbJumpDest = block; + targetSymbCondBB->SetJumpDest(tlsRootNullCondBB); + lazyCtorBB->SetJumpDest(block); fgAddRefPred(tlsRootNullCondBB, targetSymbCondBB); diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index d6eb5bcf1fd797..f3ed57dcc2d53e 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -3795,7 +3795,6 @@ GenTree* Compiler::impImportStaticFieldAddress(CORINFO_RESOLVED_TOKEN* pResolved op1 = gtNewHelperCallNode(pFieldInfo->helper, TYP_BYREF); if (pFieldInfo->fieldAccessor == CORINFO_FIELD_STATIC_TLS_MANAGED) { - op1->AsCall()->SetExpTLSFieldAccess(); op1->AsCall()->gtInitClsHnd = pResolvedToken->hClass; } else if (pFieldInfo->fieldAccessor == CORINFO_FIELD_STATIC_TLS_MANAGED_LAZY) From 07c839bc963fcccddf7d9e163d77079c509b1051 Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Fri, 1 Dec 2023 11:09:11 -0800 Subject: [PATCH 24/58] fix issues so the TLS is inlined --- src/coreclr/jit/helperexpansion.cpp | 6 +++++- .../Target_X64/X64ReadyToRunHelperNode.cs | 5 +++-- .../JitInterface/CorInfoImpl.RyuJit.cs | 20 +++++++++++-------- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/coreclr/jit/helperexpansion.cpp b/src/coreclr/jit/helperexpansion.cpp index 00929d7c3c0c32..668c4172501ab5 100644 --- a/src/coreclr/jit/helperexpansion.cpp +++ b/src/coreclr/jit/helperexpansion.cpp @@ -457,7 +457,11 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S { assert(opts.IsReadyToRun()); BasicBlock* block = *pBlock; - if (!call->IsHelperCall() || !(call->IsExpTLSFieldAccess() || call->IsExpTLSFieldAccessLazyCtor())) + CorInfoHelpFunc helper = call->GetHelperNum(); + + bool isExpTLSFieldAccess = (helper == CORINFO_HELP_READYTORUN_THREADSTATIC_BASE) || + (helper == CORINFO_HELP_READYTORUN_NONGCTHREADSTATIC_BASE); + if (!call->IsHelperCall() || !(isExpTLSFieldAccess || call->IsExpTLSFieldAccessLazyCtor())) { return false; } diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/Target_X64/X64ReadyToRunHelperNode.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/Target_X64/X64ReadyToRunHelperNode.cs index 87a98548ca5875..07f713acfb8adc 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/Target_X64/X64ReadyToRunHelperNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/Target_X64/X64ReadyToRunHelperNode.cs @@ -274,9 +274,10 @@ private static void EmitInlineTLSAccess(NodeFactory factory, ref X64Emitter enco throw new NotImplementedException(); } - else + else if (factory.Target.IsWindows) { - throw new NotImplementedException(); + // For windows, the TLS access will get inlined by ryujit. + // No need to emit any code here. } } } diff --git a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs index 20784064aabfa5..f9598c8ba42e9d 100644 --- a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs +++ b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs @@ -2143,20 +2143,24 @@ private void getFieldInfo(ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_MET if (MethodBeingCompiled.Context.Target.IsWindows && MethodBeingCompiled.Context.Target.Architecture == TargetArchitecture.X64) { ISortableSymbolNode index = _compilation.NodeFactory.TypeThreadStaticIndex((MetadataType)field.OwningType); - if (index is TypeThreadStaticIndexNode ti && ti.Type == null) + if (index is TypeThreadStaticIndexNode ti) { - if (_compilation.HasLazyStaticConstructor(field.OwningType)) + if (ti.IsInlined) { - fieldAccessor = CORINFO_FIELD_ACCESSOR.CORINFO_FIELD_STATIC_TLS_MANAGED_LAZY; - } - else - { - fieldAccessor = CORINFO_FIELD_ACCESSOR.CORINFO_FIELD_STATIC_TLS_MANAGED; + if (_compilation.HasLazyStaticConstructor(field.OwningType)) + { + fieldAccessor = CORINFO_FIELD_ACCESSOR.CORINFO_FIELD_STATIC_TLS_MANAGED_LAZY; + } + else + { + fieldAccessor = CORINFO_FIELD_ACCESSOR.CORINFO_FIELD_STATIC_TLS_MANAGED; + } } } } - pResult->helper = CorInfoHelpFunc.CORINFO_HELP_READYTORUN_THREADSTATIC_BASE; + helperId = ReadyToRunHelperId.GetThreadStaticBase; + pResult->helper = CorInfoHelpFunc.CORINFO_HELP_READYTORUN_THREADSTATIC_BASE; } else if (!_compilation.HasLazyStaticConstructor(field.OwningType)) { From 65ceeaadd30ee8fb046068e4d6830c7854f71882 Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Thu, 7 Dec 2023 00:40:54 -0800 Subject: [PATCH 25/58] Rename data structures from *_ReadyToRun to *_NativeAOT --- src/coreclr/inc/corinfo.h | 8 +++--- src/coreclr/inc/icorjitinfoimpl_generated.h | 4 +-- src/coreclr/inc/jiteeversionguid.h | 10 +++---- src/coreclr/jit/ICorJitInfo_names_generated.h | 2 +- .../jit/ICorJitInfo_wrapper_generated.hpp | 10 +++---- src/coreclr/jit/compiler.h | 2 +- src/coreclr/jit/helperexpansion.cpp | 10 +++---- .../JitInterface/CorInfoImpl_generated.cs | 6 ++--- .../tools/Common/JitInterface/CorInfoTypes.cs | 2 +- .../ThunkGenerator/ThunkInput.txt | 4 +-- .../JitInterface/CorInfoImpl.ReadyToRun.cs | 2 +- .../JitInterface/CorInfoImpl.RyuJit.cs | 2 +- .../aot/jitinterface/jitinterface_generated.h | 8 +++--- .../tools/superpmi/superpmi-shared/agnostic.h | 2 +- .../tools/superpmi/superpmi-shared/lwmlist.h | 2 +- .../superpmi-shared/methodcontext.cpp | 26 +++++++++---------- .../superpmi/superpmi-shared/methodcontext.h | 8 +++--- .../superpmi-shim-collector/icorjitinfo.cpp | 8 +++--- .../icorjitinfo_generated.cpp | 8 +++--- .../icorjitinfo_generated.cpp | 6 ++--- .../tools/superpmi/superpmi/icorjitinfo.cpp | 6 ++--- src/coreclr/vm/jitinterface.cpp | 2 +- 22 files changed, 69 insertions(+), 69 deletions(-) diff --git a/src/coreclr/inc/corinfo.h b/src/coreclr/inc/corinfo.h index 9486a8384a6f6d..b648ba0fdface1 100644 --- a/src/coreclr/inc/corinfo.h +++ b/src/coreclr/inc/corinfo.h @@ -1740,9 +1740,9 @@ struct CORINFO_THREAD_STATIC_BLOCKS_INFO }; //---------------------------------------------------------------------------- -// getThreadLocalStaticInfo_ReadyToRun and CORINFO_THREAD_STATIC_INFO_READYTORUN: The EE instructs the JIT about how to access a thread local field +// getThreadLocalStaticInfo_NativeAOT and CORINFO_THREAD_STATIC_INFO_NATIVEAOT: The EE instructs the JIT about how to access a thread local field -struct CORINFO_THREAD_STATIC_INFO_READYTORUN +struct CORINFO_THREAD_STATIC_INFO_NATIVEAOT { uint32_t offsetOfThreadLocalStoragePointer; CORINFO_CONST_LOOKUP tlsRootObject; @@ -2833,8 +2833,8 @@ class ICorStaticInfo bool isGCType ) = 0; - virtual void getThreadLocalStaticInfo_ReadyToRun( - CORINFO_THREAD_STATIC_INFO_READYTORUN* pInfo, + virtual void getThreadLocalStaticInfo_NativeAOT( + CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo, CORINFO_CLASS_HANDLE cls ) = 0; diff --git a/src/coreclr/inc/icorjitinfoimpl_generated.h b/src/coreclr/inc/icorjitinfoimpl_generated.h index 7c1dd6c50160f1..564076d957a3fc 100644 --- a/src/coreclr/inc/icorjitinfoimpl_generated.h +++ b/src/coreclr/inc/icorjitinfoimpl_generated.h @@ -399,8 +399,8 @@ void getThreadLocalStaticBlocksInfo( CORINFO_THREAD_STATIC_BLOCKS_INFO* pInfo, bool isGCType) override; -void getThreadLocalStaticInfo_ReadyToRun( - CORINFO_THREAD_STATIC_INFO_READYTORUN* pInfo, +void getThreadLocalStaticInfo_NativeAOT( + CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo, CORINFO_CLASS_HANDLE cls) override; bool isFieldStatic( diff --git a/src/coreclr/inc/jiteeversionguid.h b/src/coreclr/inc/jiteeversionguid.h index 7538272e80bcd4..6c6ca1831dac75 100644 --- a/src/coreclr/inc/jiteeversionguid.h +++ b/src/coreclr/inc/jiteeversionguid.h @@ -43,11 +43,11 @@ typedef const GUID *LPCGUID; #define GUID_DEFINED #endif // !GUID_DEFINED -constexpr GUID JITEEVersionIdentifier = { /* b9720ec9-0a3e-4ef7-9475-ac0e5352a32f */ - 0xb9720ec9, - 0x0a3e, - 0x4ef7, - {0x94, 0x75, 0xac, 0x0e, 0x53, 0x52, 0xa3, 0x2f} +constexpr GUID JITEEVersionIdentifier = { /* 1572ff26-ec9d-48ce-b223-898c65e8e257 */ + 0x1572ff26, + 0xec9d, + 0x48ce, + {0xb2, 0x23, 0x89, 0x8c, 0x65, 0xe8, 0xe2, 0x57} }; ////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/coreclr/jit/ICorJitInfo_names_generated.h b/src/coreclr/jit/ICorJitInfo_names_generated.h index 9f0826c13a79b3..7cab76db8147f5 100644 --- a/src/coreclr/jit/ICorJitInfo_names_generated.h +++ b/src/coreclr/jit/ICorJitInfo_names_generated.h @@ -99,7 +99,7 @@ DEF_CLR_API(getFieldOffset) DEF_CLR_API(getFieldInfo) DEF_CLR_API(getThreadLocalFieldInfo) DEF_CLR_API(getThreadLocalStaticBlocksInfo) -DEF_CLR_API(getThreadLocalStaticInfo_ReadyToRun) +DEF_CLR_API(getThreadLocalStaticInfo_NativeAOT) DEF_CLR_API(isFieldStatic) DEF_CLR_API(getArrayOrStringLength) DEF_CLR_API(getBoundaries) diff --git a/src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp b/src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp index 8b16a3b43cc457..be49a542145faa 100644 --- a/src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp +++ b/src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp @@ -941,13 +941,13 @@ void WrapICorJitInfo::getThreadLocalStaticBlocksInfo( API_LEAVE(getThreadLocalStaticBlocksInfo); } -void WrapICorJitInfo::getThreadLocalStaticInfo_ReadyToRun( - CORINFO_THREAD_STATIC_INFO_READYTORUN* pInfo, +void WrapICorJitInfo::getThreadLocalStaticInfo_NativeAOT( + CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo, CORINFO_CLASS_HANDLE cls) { - API_ENTER(getThreadLocalStaticInfo_ReadyToRun); - wrapHnd->getThreadLocalStaticInfo_ReadyToRun(pInfo, cls); - API_LEAVE(getThreadLocalStaticInfo_ReadyToRun); + API_ENTER(getThreadLocalStaticInfo_NativeAOT); + wrapHnd->getThreadLocalStaticInfo_NativeAOT(pInfo, cls); + API_LEAVE(getThreadLocalStaticInfo_NativeAOT); } bool WrapICorJitInfo::isFieldStatic( diff --git a/src/coreclr/jit/compiler.h b/src/coreclr/jit/compiler.h index 2672a68523da94..e502c2ed87c2f8 100644 --- a/src/coreclr/jit/compiler.h +++ b/src/coreclr/jit/compiler.h @@ -5386,7 +5386,7 @@ class Compiler PhaseStatus fgExpandThreadLocalAccess(); bool fgExpandThreadLocalAccessForCall(BasicBlock** pBlock, Statement* stmt, GenTreeCall* call); - bool fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, Statement* stmt, GenTreeCall* call); + bool fgExpandThreadLocalAccessForCallNativeAOT(BasicBlock** pBlock, Statement* stmt, GenTreeCall* call); PhaseStatus fgExpandStaticInit(); bool fgExpandStaticInitForCall(BasicBlock** pBlock, Statement* stmt, GenTreeCall* call); diff --git a/src/coreclr/jit/helperexpansion.cpp b/src/coreclr/jit/helperexpansion.cpp index 668c4172501ab5..28ea900d65a916 100644 --- a/src/coreclr/jit/helperexpansion.cpp +++ b/src/coreclr/jit/helperexpansion.cpp @@ -448,12 +448,12 @@ PhaseStatus Compiler::fgExpandThreadLocalAccess() return result; } - return isNativeAOT ? fgExpandHelper<&Compiler::fgExpandThreadLocalAccessForCallReadyToRun>( + return isNativeAOT ? fgExpandHelper<&Compiler::fgExpandThreadLocalAccessForCallNativeAOT>( false /* expand rarely run blocks for NativeAOT */) : fgExpandHelper<&Compiler::fgExpandThreadLocalAccessForCall>(true); } -bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, Statement* stmt, GenTreeCall* call) +bool Compiler::fgExpandThreadLocalAccessForCallNativeAOT(BasicBlock** pBlock, Statement* stmt, GenTreeCall* call) { assert(opts.IsReadyToRun()); BasicBlock* block = *pBlock; @@ -473,10 +473,10 @@ bool Compiler::fgExpandThreadLocalAccessForCallReadyToRun(BasicBlock** pBlock, S call->ClearExpTLSFieldAccessLazyCtor(); - CORINFO_THREAD_STATIC_INFO_READYTORUN threadStaticInfo; - memset(&threadStaticInfo, 0, sizeof(CORINFO_THREAD_STATIC_INFO_READYTORUN)); + CORINFO_THREAD_STATIC_INFO_NATIVEAOT threadStaticInfo; + memset(&threadStaticInfo, 0, sizeof(CORINFO_THREAD_STATIC_INFO_NATIVEAOT)); - info.compCompHnd->getThreadLocalStaticInfo_ReadyToRun(&threadStaticInfo, call->gtInitClsHnd); + info.compCompHnd->getThreadLocalStaticInfo_NativeAOT(&threadStaticInfo, call->gtInitClsHnd); JITDUMP("tlsRootObject= %p\n", dspPtr(threadStaticInfo.tlsRootObject.addr)); JITDUMP("tlsIndexObject= %p\n", dspPtr(threadStaticInfo.tlsIndexObject.addr)); diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs b/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs index b987c71b8083f2..6fb60aabf23c74 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs @@ -1419,12 +1419,12 @@ private static void _getThreadLocalStaticBlocksInfo(IntPtr thisHandle, IntPtr* p } [UnmanagedCallersOnly] - private static void _getThreadLocalStaticInfo_ReadyToRun(IntPtr thisHandle, IntPtr* ppException, CORINFO_THREAD_STATIC_INFO_READYTORUN* pInfo, CORINFO_CLASS_STRUCT_* cls) + private static void _getThreadLocalStaticInfo_NativeAOT(IntPtr thisHandle, IntPtr* ppException, CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo, CORINFO_CLASS_STRUCT_* cls) { var _this = GetThis(thisHandle); try { - _this.getThreadLocalStaticInfo_ReadyToRun(pInfo, cls); + _this.getThreadLocalStaticInfo_NativeAOT(pInfo, cls); } catch (Exception ex) { @@ -2633,7 +2633,7 @@ private static IntPtr GetUnmanagedCallbacks() callbacks[92] = (delegate* unmanaged)&_getFieldInfo; callbacks[93] = (delegate* unmanaged)&_getThreadLocalFieldInfo; callbacks[94] = (delegate* unmanaged)&_getThreadLocalStaticBlocksInfo; - callbacks[95] = (delegate* unmanaged)&_getThreadLocalStaticInfo_ReadyToRun; + callbacks[95] = (delegate* unmanaged)&_getThreadLocalStaticInfo_NativeAOT; callbacks[96] = (delegate* unmanaged)&_isFieldStatic; callbacks[97] = (delegate* unmanaged)&_getArrayOrStringLength; callbacks[98] = (delegate* unmanaged)&_getBoundaries; diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs b/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs index b7392d552713c2..d398939a7a8cc4 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs @@ -1160,7 +1160,7 @@ public unsafe struct CORINFO_THREAD_STATIC_BLOCKS_INFO }; - public unsafe struct CORINFO_THREAD_STATIC_INFO_READYTORUN + public unsafe struct CORINFO_THREAD_STATIC_INFO_NATIVEAOT { public uint offsetOfThreadLocalStoragePointer; public CORINFO_CONST_LOOKUP tlsRootObject; diff --git a/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt b/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt index 45ca3da872c5b9..9cfce7fcafebd3 100644 --- a/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt +++ b/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt @@ -87,7 +87,7 @@ CORINFO_GENERICHANDLE_RESULT*,ref CORINFO_GENERICHANDLE_RESULT CORINFO_METHOD_INFO*,CORINFO_METHOD_INFO* CORINFO_FIELD_INFO*,CORINFO_FIELD_INFO* CORINFO_THREAD_STATIC_BLOCKS_INFO*,CORINFO_THREAD_STATIC_BLOCKS_INFO* -CORINFO_THREAD_STATIC_INFO_READYTORUN*,CORINFO_THREAD_STATIC_INFO_READYTORUN* +CORINFO_THREAD_STATIC_INFO_NATIVEAOT*,CORINFO_THREAD_STATIC_INFO_NATIVEAOT* CORINFO_CALL_INFO*,CORINFO_CALL_INFO* CORINFO_DEVIRTUALIZATION_INFO*,CORINFO_DEVIRTUALIZATION_INFO* CORINFO_TYPE_LAYOUT_NODE*,CORINFO_TYPE_LAYOUT_NODE* @@ -257,7 +257,7 @@ FUNCTIONS void getFieldInfo(CORINFO_RESOLVED_TOKEN* pResolvedToken, CORINFO_METHOD_HANDLE callerHandle, CORINFO_ACCESS_FLAGS flags, CORINFO_FIELD_INFO* pResult) uint32_t getThreadLocalFieldInfo (CORINFO_FIELD_HANDLE field, bool isGCtype) void getThreadLocalStaticBlocksInfo (CORINFO_THREAD_STATIC_BLOCKS_INFO* pInfo, bool isGCType) - void getThreadLocalStaticInfo_ReadyToRun(CORINFO_THREAD_STATIC_INFO_READYTORUN* pInfo, CORINFO_CLASS_HANDLE cls) + void getThreadLocalStaticInfo_NativeAOT(CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo, CORINFO_CLASS_HANDLE cls) bool isFieldStatic(CORINFO_FIELD_HANDLE fldHnd) int getArrayOrStringLength(CORINFO_OBJECT_HANDLE objHnd) void getBoundaries(CORINFO_METHOD_HANDLE ftn, unsigned int* cILOffsets, uint32_t** pILOffsets, ICorDebugInfo::BoundaryTypes* implicitBoundaries) diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs index 4958e9d2a7241e..4886fb59a4a209 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs @@ -3359,7 +3359,7 @@ void ValidateSafetyOfUsingTypeEquivalenceOfType(TypeDesc type) } #pragma warning disable CA1822 // Mark members as static - private void getThreadLocalStaticInfo_ReadyToRun(CORINFO_THREAD_STATIC_INFO_READYTORUN* pInfo, CORINFO_CLASS_STRUCT_* cls) + private void getThreadLocalStaticInfo_NativeAOT(CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo, CORINFO_CLASS_STRUCT_* cls) { // Implemented for NativeAOT only for now. } diff --git a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs index f9598c8ba42e9d..a6d715559010fb 100644 --- a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs +++ b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs @@ -2408,7 +2408,7 @@ private bool getStaticBaseAddress(CORINFO_CLASS_STRUCT_* cls, bool isGc, ref COR return true; } - private void getThreadLocalStaticInfo_ReadyToRun(CORINFO_THREAD_STATIC_INFO_READYTORUN* pInfo, CORINFO_CLASS_STRUCT_* cls) + private void getThreadLocalStaticInfo_NativeAOT(CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo, CORINFO_CLASS_STRUCT_* cls) { pInfo->offsetOfThreadLocalStoragePointer = (uint)(11 * PointerSize); // 0x58 = 0n88 pInfo->tlsIndexObject = CreateConstLookupToSymbol(_compilation.NodeFactory.ExternSymbol("_tls_index")); diff --git a/src/coreclr/tools/aot/jitinterface/jitinterface_generated.h b/src/coreclr/tools/aot/jitinterface/jitinterface_generated.h index 68b5ae9314ff71..1da47a8c8f8fbe 100644 --- a/src/coreclr/tools/aot/jitinterface/jitinterface_generated.h +++ b/src/coreclr/tools/aot/jitinterface/jitinterface_generated.h @@ -106,7 +106,7 @@ struct JitInterfaceCallbacks void (* getFieldInfo)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_RESOLVED_TOKEN* pResolvedToken, CORINFO_METHOD_HANDLE callerHandle, CORINFO_ACCESS_FLAGS flags, CORINFO_FIELD_INFO* pResult); uint32_t (* getThreadLocalFieldInfo)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_FIELD_HANDLE field, bool isGCtype); void (* getThreadLocalStaticBlocksInfo)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_THREAD_STATIC_BLOCKS_INFO* pInfo, bool isGCType); - void (* getThreadLocalStaticInfo_ReadyToRun)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_THREAD_STATIC_INFO_READYTORUN* pInfo, CORINFO_CLASS_HANDLE cls); + void (* getThreadLocalStaticInfo_NativeAOT)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo, CORINFO_CLASS_HANDLE cls); bool (* isFieldStatic)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_FIELD_HANDLE fldHnd); int (* getArrayOrStringLength)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_OBJECT_HANDLE objHnd); void (* getBoundaries)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_METHOD_HANDLE ftn, unsigned int* cILOffsets, uint32_t** pILOffsets, ICorDebugInfo::BoundaryTypes* implicitBoundaries); @@ -1126,12 +1126,12 @@ class JitInterfaceWrapper : public ICorJitInfo if (pException != nullptr) throw pException; } - virtual void getThreadLocalStaticInfo_ReadyToRun( - CORINFO_THREAD_STATIC_INFO_READYTORUN* pInfo, + virtual void getThreadLocalStaticInfo_NativeAOT( + CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo, CORINFO_CLASS_HANDLE cls) { CorInfoExceptionClass* pException = nullptr; - _callbacks->getThreadLocalStaticInfo_ReadyToRun(_thisHandle, &pException, pInfo, cls); + _callbacks->getThreadLocalStaticInfo_NativeAOT(_thisHandle, &pException, pInfo, cls); if (pException != nullptr) throw pException; } diff --git a/src/coreclr/tools/superpmi/superpmi-shared/agnostic.h b/src/coreclr/tools/superpmi/superpmi-shared/agnostic.h index 22fd5cbdbc9f59..258f43f95ebb40 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/agnostic.h +++ b/src/coreclr/tools/superpmi/superpmi-shared/agnostic.h @@ -533,7 +533,7 @@ struct Agnostic_GetThreadLocalStaticBlocksInfo DWORD offsetOfGCDataPointer; }; -struct Agnostic_GetThreadStaticInfo_ReadyToRun +struct Agnostic_GetThreadStaticInfo_NativeAOT { DWORD offsetOfThreadLocalStoragePointer; Agnostic_CORINFO_CONST_LOOKUP tlsRootObject; diff --git a/src/coreclr/tools/superpmi/superpmi-shared/lwmlist.h b/src/coreclr/tools/superpmi/superpmi-shared/lwmlist.h index c5c74e1253da8a..e6271422fc1f26 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/lwmlist.h +++ b/src/coreclr/tools/superpmi/superpmi-shared/lwmlist.h @@ -39,7 +39,7 @@ LWM(EmbedMethodHandle, DWORDLONG, DLDL) LWM(EmbedModuleHandle, DWORDLONG, DLDL) LWM(GetThreadLocalFieldInfo, DLD, DWORD) LWM(GetThreadLocalStaticBlocksInfo, DWORD, Agnostic_GetThreadLocalStaticBlocksInfo) -LWM(GetThreadLocalStaticInfo_ReadyToRun, DWORDLONG, Agnostic_GetThreadStaticInfo_ReadyToRun) +LWM(GetThreadLocalStaticInfo_NativeAOT, DWORDLONG, Agnostic_GetThreadStaticInfo_NativeAOT) DENSELWM(EmptyStringLiteral, DLD) DENSELWM(ErrorList, DWORD) LWM(FindCallSiteSig, Agnostic_FindCallSiteSig, Agnostic_CORINFO_SIG_INFO) diff --git a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp index 3634f59fd2a16c..452a5884fbad57 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp @@ -3635,13 +3635,13 @@ void MethodContext::repGetThreadLocalStaticBlocksInfo(CORINFO_THREAD_STATIC_BLOC pInfo->offsetOfGCDataPointer = value.offsetOfGCDataPointer; } -void MethodContext::recGetThreadLocalStaticInfo_ReadyToRun(CORINFO_THREAD_STATIC_INFO_READYTORUN* pInfo, +void MethodContext::recGetThreadLocalStaticInfo_NativeAOT(CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo, CORINFO_CLASS_HANDLE cls) { - if (GetThreadLocalStaticInfo_ReadyToRun == nullptr) - GetThreadLocalStaticInfo_ReadyToRun = new LightWeightMap(); + if (GetThreadLocalStaticInfo_NativeAOT == nullptr) + GetThreadLocalStaticInfo_NativeAOT = new LightWeightMap(); - Agnostic_GetThreadStaticInfo_ReadyToRun value; + Agnostic_GetThreadStaticInfo_NativeAOT value; ZeroMemory(&value, sizeof(value)); value.tlsRootObject = SpmiRecordsHelper::StoreAgnostic_CORINFO_CONST_LOOKUP(&pInfo->tlsRootObject); value.tlsIndexObject = SpmiRecordsHelper::StoreAgnostic_CORINFO_CONST_LOOKUP(&pInfo->tlsIndexObject); @@ -3653,13 +3653,13 @@ void MethodContext::recGetThreadLocalStaticInfo_ReadyToRun(CORINFO_THREAD_STATIC DWORDLONG key = CastHandle(cls); - GetThreadLocalStaticInfo_ReadyToRun->Add(key, value); - DEBUG_REC(dmpGetThreadLocalStaticInfo_ReadyToRun(key, result)); + GetThreadLocalStaticInfo_NativeAOT->Add(key, value); + DEBUG_REC(dmpGetThreadLocalStaticInfo_NativeAOT(key, result)); } -void MethodContext::dmpGetThreadLocalStaticInfo_ReadyToRun(DWORDLONG key, - const Agnostic_GetThreadStaticInfo_ReadyToRun& value) +void MethodContext::dmpGetThreadLocalStaticInfo_NativeAOT(DWORDLONG key, + const Agnostic_GetThreadStaticInfo_NativeAOT& value) { - printf("GetThreadLocalStaticInfo_ReadyToRun key %016" PRIX64 ", tlsRootObject-%s, tlsIndexObject-%s, offsetOfThreadLocalStoragePointer-%u, " + printf("GetThreadLocalStaticInfo_NativeAOT key %016" PRIX64 ", tlsRootObject-%s, tlsIndexObject-%s, offsetOfThreadLocalStoragePointer-%u, " "threadStaticBaseSlow-%s, lazyCtorRunHelper-%s, lazyCtorTargetSymbol-%s, classCtorContextSize-%u", key, SpmiDumpHelper::DumpAgnostic_CORINFO_CONST_LOOKUP(value.tlsRootObject).c_str(), SpmiDumpHelper::DumpAgnostic_CORINFO_CONST_LOOKUP(value.tlsIndexObject).c_str(), @@ -3670,14 +3670,14 @@ void MethodContext::dmpGetThreadLocalStaticInfo_ReadyToRun(DWORDLONG value.classCtorContextSize); } -void MethodContext::repGetThreadLocalStaticInfo_ReadyToRun(CORINFO_THREAD_STATIC_INFO_READYTORUN* pInfo, +void MethodContext::repGetThreadLocalStaticInfo_NativeAOT(CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo, CORINFO_CLASS_HANDLE cls) { DWORDLONG key = CastHandle(cls); - Agnostic_GetThreadStaticInfo_ReadyToRun value = - LookupByKeyOrMiss(GetThreadLocalStaticInfo_ReadyToRun, key, ": key %016" PRIX64 "", key); + Agnostic_GetThreadStaticInfo_NativeAOT value = + LookupByKeyOrMiss(GetThreadLocalStaticInfo_NativeAOT, key, ": key %016" PRIX64 "", key); - DEBUG_REP(dmpGetThreadLocalStaticInfo_ReadyToRun(key, value)); + DEBUG_REP(dmpGetThreadLocalStaticInfo_NativeAOT(key, value)); pInfo->tlsRootObject = SpmiRecordsHelper::RestoreCORINFO_CONST_LOOKUP(value.tlsRootObject); pInfo->tlsIndexObject = SpmiRecordsHelper::RestoreCORINFO_CONST_LOOKUP(value.tlsIndexObject); diff --git a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h index fc4b5f11f51d4b..d3dc4f4135fd0d 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h +++ b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h @@ -478,9 +478,9 @@ class MethodContext void dmpGetThreadLocalStaticBlocksInfo(DWORD key, const Agnostic_GetThreadLocalStaticBlocksInfo& value); void repGetThreadLocalStaticBlocksInfo(CORINFO_THREAD_STATIC_BLOCKS_INFO* pInfo, bool isGCType); - void recGetThreadLocalStaticInfo_ReadyToRun(CORINFO_THREAD_STATIC_INFO_READYTORUN* pInfo, CORINFO_CLASS_HANDLE cls); - void dmpGetThreadLocalStaticInfo_ReadyToRun(DWORDLONG key, const Agnostic_GetThreadStaticInfo_ReadyToRun& value); - void repGetThreadLocalStaticInfo_ReadyToRun(CORINFO_THREAD_STATIC_INFO_READYTORUN* pInfo, CORINFO_CLASS_HANDLE cls); + void recGetThreadLocalStaticInfo_NativeAOT(CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo, CORINFO_CLASS_HANDLE cls); + void dmpGetThreadLocalStaticInfo_NativeAOT(DWORDLONG key, const Agnostic_GetThreadStaticInfo_NativeAOT& value); + void repGetThreadLocalStaticInfo_NativeAOT(CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo, CORINFO_CLASS_HANDLE cls); void recEmbedMethodHandle(CORINFO_METHOD_HANDLE handle, void** ppIndirection, CORINFO_METHOD_HANDLE result); void dmpEmbedMethodHandle(DWORDLONG key, DLDL value); @@ -1138,7 +1138,7 @@ enum mcPackets Packet_GetStaticBaseAddress = 206, Packet_GetThreadLocalFieldInfo = 207, Packet_GetThreadLocalStaticBlocksInfo = 208, - Packet_GetThreadLocalStaticInfo_ReadyToRun = 209, + Packet_GetThreadLocalStaticInfo_NativeAOT = 209, Packet_GetRISCV64PassStructInRegisterFlags = 210, Packet_GetObjectContent = 211, Packet_GetTypeLayout = 212, diff --git a/src/coreclr/tools/superpmi/superpmi-shim-collector/icorjitinfo.cpp b/src/coreclr/tools/superpmi/superpmi-shim-collector/icorjitinfo.cpp index c8284c149fc227..3d4ccb5a759210 100644 --- a/src/coreclr/tools/superpmi/superpmi-shim-collector/icorjitinfo.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shim-collector/icorjitinfo.cpp @@ -1072,12 +1072,12 @@ void interceptor_ICJI::getThreadLocalStaticBlocksInfo(CORINFO_THREAD_STATIC_BLOC mc->recGetThreadLocalStaticBlocksInfo(pInfo, isGCType); } -void interceptor_ICJI::getThreadLocalStaticInfo_ReadyToRun(CORINFO_THREAD_STATIC_INFO_READYTORUN* pInfo, +void interceptor_ICJI::getThreadLocalStaticInfo_NativeAOT(CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo, CORINFO_CLASS_HANDLE cls) { - mc->cr->AddCall("getThreadLocalStaticInfo_ReadyToRun"); - original_ICorJitInfo->getThreadLocalStaticInfo_ReadyToRun(pInfo, cls); - mc->recGetThreadLocalStaticInfo_ReadyToRun(pInfo, cls); + mc->cr->AddCall("getThreadLocalStaticInfo_NativeAOT"); + original_ICorJitInfo->getThreadLocalStaticInfo_NativeAOT(pInfo, cls); + mc->recGetThreadLocalStaticInfo_NativeAOT(pInfo, cls); } // Returns true iff "fldHnd" represents a static field. diff --git a/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo_generated.cpp b/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo_generated.cpp index 457bda8f02c1f5..34bd0461f5f8f4 100644 --- a/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo_generated.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo_generated.cpp @@ -770,12 +770,12 @@ void interceptor_ICJI::getThreadLocalStaticBlocksInfo( original_ICorJitInfo->getThreadLocalStaticBlocksInfo(pInfo, isGCType); } -void interceptor_ICJI::getThreadLocalStaticInfo_ReadyToRun( - CORINFO_THREAD_STATIC_INFO_READYTORUN* pInfo, +void interceptor_ICJI::getThreadLocalStaticInfo_NativeAOT( + CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo, CORINFO_CLASS_HANDLE cls) { - mcs->AddCall("getThreadLocalStaticInfo_ReadyToRun"); - original_ICorJitInfo->getThreadLocalStaticInfo_ReadyToRun(pInfo, cls); + mcs->AddCall("getThreadLocalStaticInfo_NativeAOT"); + original_ICorJitInfo->getThreadLocalStaticInfo_NativeAOT(pInfo, cls); } bool interceptor_ICJI::isFieldStatic( diff --git a/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo_generated.cpp b/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo_generated.cpp index fd7c28c5e83a64..480edec6736797 100644 --- a/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo_generated.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo_generated.cpp @@ -675,11 +675,11 @@ void interceptor_ICJI::getThreadLocalStaticBlocksInfo( original_ICorJitInfo->getThreadLocalStaticBlocksInfo(pInfo, isGCType); } -void interceptor_ICJI::getThreadLocalStaticInfo_ReadyToRun( - CORINFO_THREAD_STATIC_INFO_READYTORUN* pInfo, +void interceptor_ICJI::getThreadLocalStaticInfo_NativeAOT( + CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo, CORINFO_CLASS_HANDLE cls) { - original_ICorJitInfo->getThreadLocalStaticInfo_ReadyToRun(pInfo, cls); + original_ICorJitInfo->getThreadLocalStaticInfo_NativeAOT(pInfo, cls); } bool interceptor_ICJI::isFieldStatic( diff --git a/src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp b/src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp index 874e1426cb7ccc..6d47e8bd030c2a 100644 --- a/src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp +++ b/src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp @@ -891,10 +891,10 @@ void MyICJI::getThreadLocalStaticBlocksInfo(CORINFO_THREAD_STATIC_BLOCKS_INFO* p jitInstance->mc->repGetThreadLocalStaticBlocksInfo(pInfo, isGCType); } -void MyICJI::getThreadLocalStaticInfo_ReadyToRun(CORINFO_THREAD_STATIC_INFO_READYTORUN* pInfo, CORINFO_CLASS_HANDLE cls) +void MyICJI::getThreadLocalStaticInfo_NativeAOT(CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo, CORINFO_CLASS_HANDLE cls) { - jitInstance->mc->cr->AddCall("getThreadLocalStaticInfo_ReadyToRun"); - jitInstance->mc->repGetThreadLocalStaticInfo_ReadyToRun(pInfo, cls); + jitInstance->mc->cr->AddCall("getThreadLocalStaticInfo_NativeAOT"); + jitInstance->mc->repGetThreadLocalStaticInfo_NativeAOT(pInfo, cls); } // Returns true iff "fldHnd" represents a static field. diff --git a/src/coreclr/vm/jitinterface.cpp b/src/coreclr/vm/jitinterface.cpp index 7bf4e7ebdf9cb5..87ae3f1cc784e3 100644 --- a/src/coreclr/vm/jitinterface.cpp +++ b/src/coreclr/vm/jitinterface.cpp @@ -1309,7 +1309,7 @@ static CorInfoHelpFunc getInstanceFieldHelper(FieldDesc * pField, CORINFO_ACCESS /*********************************************************************/ -void CEEInfo::getThreadLocalStaticInfo_ReadyToRun(CORINFO_THREAD_STATIC_INFO_READYTORUN* pInfo, CORINFO_CLASS_HANDLE cls) +void CEEInfo::getThreadLocalStaticInfo_NativeAOT(CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo, CORINFO_CLASS_HANDLE cls) { LIMITED_METHOD_CONTRACT; UNREACHABLE(); // only called with NativeAOT. From fc8e2b85213246e42227b7be4ec9c4bc166685ec Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Thu, 7 Dec 2023 14:20:08 -0800 Subject: [PATCH 26/58] jit format --- src/coreclr/jit/helperexpansion.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/jit/helperexpansion.cpp b/src/coreclr/jit/helperexpansion.cpp index ac7ba0659aef7e..8ae6f1ecf53133 100644 --- a/src/coreclr/jit/helperexpansion.cpp +++ b/src/coreclr/jit/helperexpansion.cpp @@ -463,7 +463,7 @@ PhaseStatus Compiler::fgExpandThreadLocalAccess() bool Compiler::fgExpandThreadLocalAccessForCallNativeAOT(BasicBlock** pBlock, Statement* stmt, GenTreeCall* call) { assert(opts.IsReadyToRun()); - BasicBlock* block = *pBlock; + BasicBlock* block = *pBlock; CorInfoHelpFunc helper = call->GetHelperNum(); bool isExpTLSFieldAccess = (helper == CORINFO_HELP_READYTORUN_THREADSTATIC_BASE) || From d7e7f9daa2f2deb400f72de08c547210f5e1bec0 Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Thu, 7 Dec 2023 23:24:28 -0800 Subject: [PATCH 27/58] fix some unit test --- src/coreclr/jit/helperexpansion.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/coreclr/jit/helperexpansion.cpp b/src/coreclr/jit/helperexpansion.cpp index 8ae6f1ecf53133..2a28b027735039 100644 --- a/src/coreclr/jit/helperexpansion.cpp +++ b/src/coreclr/jit/helperexpansion.cpp @@ -462,7 +462,7 @@ PhaseStatus Compiler::fgExpandThreadLocalAccess() bool Compiler::fgExpandThreadLocalAccessForCallNativeAOT(BasicBlock** pBlock, Statement* stmt, GenTreeCall* call) { - assert(opts.IsReadyToRun()); + assert(IsTargetAbi(CORINFO_NATIVEAOT_ABI)); BasicBlock* block = *pBlock; CorInfoHelpFunc helper = call->GetHelperNum(); @@ -596,8 +596,6 @@ bool Compiler::fgExpandThreadLocalAccessForCallNativeAOT(BasicBlock** pBlock, St assert(BasicBlock::sameEHRegion(prevBb, targetSymbCondBB)); assert(BasicBlock::sameEHRegion(prevBb, lazyCtorBB)); - // lazyCtorBB is the new previous block going forward - prevBb = lazyCtorBB; JITDUMP("lazyCtorBB: " FMT_BB "\n", lazyCtorBB->bbNum); JITDUMP("targetSymbCondBB: " FMT_BB "\n", targetSymbCondBB->bbNum); } @@ -621,7 +619,7 @@ bool Compiler::fgExpandThreadLocalAccessForCallNativeAOT(BasicBlock** pBlock, St CORINFO_CONST_LOOKUP tlsIndexObject = threadStaticInfo.tlsIndexObject; GenTree* dllRef = gtNewIconHandleNode((size_t)tlsIndexObject.handle, GTF_ICON_OBJ_HDL); - dllRef = gtNewIndir(TYP_UINT, dllRef, GTF_IND_NONFAULTING | GTF_IND_INVARIANT); + dllRef = gtNewIndir(TYP_I_IMPL, dllRef, GTF_IND_NONFAULTING | GTF_IND_INVARIANT); dllRef = gtNewOperNode(GT_MUL, TYP_I_IMPL, dllRef, gtNewIconNode(TARGET_POINTER_SIZE, TYP_INT)); // Add the dllRef to produce thread local storage reference for coreclr @@ -701,6 +699,7 @@ bool Compiler::fgExpandThreadLocalAccessForCallNativeAOT(BasicBlock** pBlock, St assert(targetSymbCondBB != nullptr); assert(lazyCtorBB != nullptr); + prevBb->SetJumpDest(targetSymbCondBB); targetSymbCondBB->SetJumpDest(tlsRootNullCondBB); lazyCtorBB->SetJumpDest(block); @@ -713,6 +712,7 @@ bool Compiler::fgExpandThreadLocalAccessForCallNativeAOT(BasicBlock** pBlock, St { fgRemoveRefPred(block, prevBb); fgAddRefPred(tlsRootNullCondBB, prevBb); + prevBb->SetJumpDest(tlsRootNullCondBB); } // From b70ceebb0bc54959f03211bd8f20a52b01bda33c Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Fri, 8 Dec 2023 11:25:26 -0800 Subject: [PATCH 28/58] fix a bug --- src/coreclr/jit/helperexpansion.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/jit/helperexpansion.cpp b/src/coreclr/jit/helperexpansion.cpp index 2a28b027735039..4d17ba3fb8500d 100644 --- a/src/coreclr/jit/helperexpansion.cpp +++ b/src/coreclr/jit/helperexpansion.cpp @@ -619,7 +619,7 @@ bool Compiler::fgExpandThreadLocalAccessForCallNativeAOT(BasicBlock** pBlock, St CORINFO_CONST_LOOKUP tlsIndexObject = threadStaticInfo.tlsIndexObject; GenTree* dllRef = gtNewIconHandleNode((size_t)tlsIndexObject.handle, GTF_ICON_OBJ_HDL); - dllRef = gtNewIndir(TYP_I_IMPL, dllRef, GTF_IND_NONFAULTING | GTF_IND_INVARIANT); + dllRef = gtNewIndir(TYP_INT, dllRef, GTF_IND_NONFAULTING | GTF_IND_INVARIANT); dllRef = gtNewOperNode(GT_MUL, TYP_I_IMPL, dllRef, gtNewIconNode(TARGET_POINTER_SIZE, TYP_INT)); // Add the dllRef to produce thread local storage reference for coreclr From f6552f27ca33a3277135ce524b99c583e808b023 Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Sat, 9 Dec 2023 09:00:23 -0800 Subject: [PATCH 29/58] fix the weird jump problem --- src/coreclr/jit/helperexpansion.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/coreclr/jit/helperexpansion.cpp b/src/coreclr/jit/helperexpansion.cpp index 4d17ba3fb8500d..73d89562404b6b 100644 --- a/src/coreclr/jit/helperexpansion.cpp +++ b/src/coreclr/jit/helperexpansion.cpp @@ -586,18 +586,27 @@ bool Compiler::fgExpandThreadLocalAccessForCallNativeAOT(BasicBlock** pBlock, St fgAddRefPred(lazyCtorBB, targetSymbCondBB); fgAddRefPred(block, lazyCtorBB); + prevBb->SetJumpDest(targetSymbCondBB); + lazyCtorBB->SetJumpDest(block); + // Inherit the weights block->inheritWeight(prevBb); targetSymbCondBB->inheritWeight(prevBb); + // lazyCtorBB will just execute first time + lazyCtorBB->bbSetRunRarely(); + targetSymbCondBB->bbNatLoopNum = prevBb->bbNatLoopNum; lazyCtorBB->bbNatLoopNum = prevBb->bbNatLoopNum; assert(BasicBlock::sameEHRegion(prevBb, targetSymbCondBB)); assert(BasicBlock::sameEHRegion(prevBb, lazyCtorBB)); - JITDUMP("lazyCtorBB: " FMT_BB "\n", lazyCtorBB->bbNum); + // lazyCtorBB is the new prevBb going forward + prevBb = lazyCtorBB; + JITDUMP("targetSymbCondBB: " FMT_BB "\n", targetSymbCondBB->bbNum); + JITDUMP("lazyCtorBB: " FMT_BB "\n", lazyCtorBB->bbNum); } // Block ops inserted by the split need to be morphed here since we are after morph. @@ -699,14 +708,8 @@ bool Compiler::fgExpandThreadLocalAccessForCallNativeAOT(BasicBlock** pBlock, St assert(targetSymbCondBB != nullptr); assert(lazyCtorBB != nullptr); - prevBb->SetJumpDest(targetSymbCondBB); targetSymbCondBB->SetJumpDest(tlsRootNullCondBB); - lazyCtorBB->SetJumpDest(block); - fgAddRefPred(tlsRootNullCondBB, targetSymbCondBB); - - // lazyCtorBB will just execute first time - lazyCtorBB->bbSetRunRarely(); } else { @@ -728,8 +731,8 @@ bool Compiler::fgExpandThreadLocalAccessForCallNativeAOT(BasicBlock** pBlock, St assert(BasicBlock::sameEHRegion(prevBb, fastPathBb)); JITDUMP("tlsRootNullCondBB: " FMT_BB "\n", tlsRootNullCondBB->bbNum); - JITDUMP("fastPathBb: " FMT_BB "\n", fastPathBb->bbNum); JITDUMP("fallbackBb: " FMT_BB "\n", fallbackBb->bbNum); + JITDUMP("fastPathBb: " FMT_BB "\n", fastPathBb->bbNum); #else assert(!"Unsupported scenario\n"); From 57893d898c65f3562305bee50965afc5659d9d6d Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Sun, 10 Dec 2023 11:46:06 -0800 Subject: [PATCH 30/58] use enclosing type cls handle for VN of static gc/non-gc helper --- src/coreclr/jit/valuenum.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/coreclr/jit/valuenum.cpp b/src/coreclr/jit/valuenum.cpp index 773f51f9888080..779ed59596cf40 100644 --- a/src/coreclr/jit/valuenum.cpp +++ b/src/coreclr/jit/valuenum.cpp @@ -12301,6 +12301,7 @@ void Compiler::fgValueNumberHelperCallFunc(GenTreeCall* call, VNFunc vnf, ValueN CallArgs* args = &call->gtArgs; bool generateUniqueVN = false; bool useEntryPointAddrAsArg0 = false; + bool useEnclosingTypeAsArg0 = false; switch (vnf) { @@ -12364,6 +12365,17 @@ void Compiler::fgValueNumberHelperCallFunc(GenTreeCall* call, VNFunc vnf, ValueN case VNF_ReadyToRunStaticBaseNonGC: case VNF_ReadyToRunStaticBaseThread: case VNF_ReadyToRunStaticBaseThreadNonGC: + { + if (call->gtInitClsHnd != NO_CLASS_HANDLE) + { + useEnclosingTypeAsArg0 = true; + } + else + { + useEntryPointAddrAsArg0 = true; + } + } + break; case VNF_ReadyToRunGenericStaticBase: case VNF_ReadyToRunIsInstanceOf: case VNF_ReadyToRunCastClass: @@ -12433,6 +12445,12 @@ void Compiler::fgValueNumberHelperCallFunc(GenTreeCall* call, VNFunc vnf, ValueN ValueNum callAddrVN = vnStore->VNForHandle(addrValue, GTF_ICON_FTN_ADDR); vnp0 = ValueNumPair(callAddrVN, callAddrVN); } + else if (useEnclosingTypeAsArg0) + { + ssize_t addrValue = (ssize_t)call->gtInitClsHnd; + ValueNum callAddrVN = vnStore->VNForHandle(addrValue, GTF_ICON_FTN_ADDR); + vnp0 = ValueNumPair(callAddrVN, callAddrVN); + } else #endif // FEATURE_READYTORUN { From 1537ecd7f36b7c1ff40f42e95863603415658f71 Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Mon, 11 Dec 2023 09:49:39 -0800 Subject: [PATCH 31/58] fix a bug of resetting the flag --- src/coreclr/jit/valuenum.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/coreclr/jit/valuenum.cpp b/src/coreclr/jit/valuenum.cpp index 779ed59596cf40..80e217398ede93 100644 --- a/src/coreclr/jit/valuenum.cpp +++ b/src/coreclr/jit/valuenum.cpp @@ -12419,6 +12419,7 @@ void Compiler::fgValueNumberHelperCallFunc(GenTreeCall* call, VNFunc vnf, ValueN // added this arg, so we do not need to use EntryPointAddrAsArg0 // because the indirection cell itself allows us to disambiguate. useEntryPointAddrAsArg0 = false; + useEnclosingTypeAsArg0 = false; } CallArg* curArg = args->Args().begin().GetArg(); From ab95bb9f9ae668f58e8916b740a4665e523a038a Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Wed, 13 Dec 2023 07:38:39 -0800 Subject: [PATCH 32/58] useEnclosingTypeOnly from runtime to determine if VN should optimize it --- src/coreclr/inc/corinfo.h | 1 + src/coreclr/inc/jiteeversionguid.h | 10 +++++----- src/coreclr/jit/gentree.h | 16 ++++++++++++++++ src/coreclr/jit/importer.cpp | 4 ++++ src/coreclr/jit/valuenum.cpp | 12 +++++++----- src/coreclr/jit/valuenumfuncs.h | 1 + .../tools/Common/JitInterface/CorInfoTypes.cs | 3 +++ .../JitInterface/CorInfoImpl.RyuJit.cs | 3 ++- 8 files changed, 39 insertions(+), 11 deletions(-) diff --git a/src/coreclr/inc/corinfo.h b/src/coreclr/inc/corinfo.h index 4941bf56f7d68a..9ecac5848c6f7f 100644 --- a/src/coreclr/inc/corinfo.h +++ b/src/coreclr/inc/corinfo.h @@ -1721,6 +1721,7 @@ struct CORINFO_FIELD_INFO CORINFO_HELPER_DESC accessCalloutHelper; CORINFO_CONST_LOOKUP fieldLookup; // Used by Ready-to-Run + bool useEnclosingTypeOnly; // Used by NativeAOT }; //---------------------------------------------------------------------------- diff --git a/src/coreclr/inc/jiteeversionguid.h b/src/coreclr/inc/jiteeversionguid.h index 139ec31efae5d4..1b80566acb25dd 100644 --- a/src/coreclr/inc/jiteeversionguid.h +++ b/src/coreclr/inc/jiteeversionguid.h @@ -43,11 +43,11 @@ typedef const GUID *LPCGUID; #define GUID_DEFINED #endif // !GUID_DEFINED -constexpr GUID JITEEVersionIdentifier = { /* e15e62ce-d9c6-418a-a5a7-26ad17fcf4bf */ - 0xe15e62ce, - 0xd9c6, - 0x418a, - {0xa5, 0xa7, 0x26, 0xad, 0x17, 0xfc, 0xf4, 0xbf} +constexpr GUID JITEEVersionIdentifier = { /* 315babf8-3790-4267-a046-c13271a0be49 */ + 0x315babf8, + 0x3790, + 0x4267, + {0xa0, 0x46, 0xc1, 0x32, 0x71, 0xa0, 0xbe, 0x49} }; ////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/coreclr/jit/gentree.h b/src/coreclr/jit/gentree.h index ceb73997663842..ba21cf907b8974 100644 --- a/src/coreclr/jit/gentree.h +++ b/src/coreclr/jit/gentree.h @@ -4078,6 +4078,7 @@ enum GenTreeCallFlags : unsigned int GTF_CALL_M_EXPANDED_EARLY = 0x00800000, // the Virtual Call target address is expanded and placed in gtControlExpr in Morph rather than in Lower GTF_CALL_M_HAS_LATE_DEVIRT_INFO = 0x01000000, // this call has late devirtualzation info GTF_CALL_M_LDVIRTFTN_INTERFACE = 0x02000000, // ldvirtftn on an interface type + GTF_CALL_M_ENCLOSING_TYPE_ONLY = 0x04000000, // helper call needs enclosing type as parameter }; inline constexpr GenTreeCallFlags operator ~(GenTreeCallFlags a) @@ -5450,6 +5451,21 @@ struct GenTreeCall final : public GenTree return (gtCallMoreFlags & GTF_CALL_M_EXP_RUNTIME_LOOKUP) != 0; } + void SetArgNeedsEnclosingType() + { + gtCallMoreFlags |= GTF_CALL_M_ENCLOSING_TYPE_ONLY; + } + + void ClearArgNeedsEnclosingType() + { + gtCallMoreFlags &= ~GTF_CALL_M_ENCLOSING_TYPE_ONLY; + } + + bool IsArgNeedsEnclosingType() const + { + return (gtCallMoreFlags & GTF_CALL_M_ENCLOSING_TYPE_ONLY) != 0; + } + void SetExpandedEarly() { gtCallMoreFlags |= GTF_CALL_M_EXPANDED_EARLY; diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index 6e4449581e5ac7..6faf42a3b9b13a 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -3859,6 +3859,10 @@ GenTree* Compiler::impImportStaticFieldAddress(CORINFO_RESOLVED_TOKEN* pResolved { // Keep class handle attached to the helper call since it's difficult to restore it. op1->AsCall()->gtInitClsHnd = pResolvedToken->hClass; + if (pFieldInfo->useEnclosingTypeOnly) + { + op1->AsCall()->SetArgNeedsEnclosingType(); + } } op1->gtFlags |= callFlags; diff --git a/src/coreclr/jit/valuenum.cpp b/src/coreclr/jit/valuenum.cpp index 80e217398ede93..5006e648cd0fc0 100644 --- a/src/coreclr/jit/valuenum.cpp +++ b/src/coreclr/jit/valuenum.cpp @@ -12301,7 +12301,7 @@ void Compiler::fgValueNumberHelperCallFunc(GenTreeCall* call, VNFunc vnf, ValueN CallArgs* args = &call->gtArgs; bool generateUniqueVN = false; bool useEntryPointAddrAsArg0 = false; - bool useEnclosingTypeAsArg0 = false; + bool useEnclosingTypeAsArg0 = call->IsArgNeedsEnclosingType(); switch (vnf) { @@ -12363,12 +12363,12 @@ void Compiler::fgValueNumberHelperCallFunc(GenTreeCall* call, VNFunc vnf, ValueN case VNF_ReadyToRunStaticBaseGC: case VNF_ReadyToRunStaticBaseNonGC: - case VNF_ReadyToRunStaticBaseThread: - case VNF_ReadyToRunStaticBaseThreadNonGC: { - if (call->gtInitClsHnd != NO_CLASS_HANDLE) + if (IsTargetAbi(CORINFO_NATIVEAOT_ABI)) { - useEnclosingTypeAsArg0 = true; + // TODO: Do this for R2R as well + vnf = VNF_ReadyToRunStaticBaseCommon; + assert(useEnclosingTypeAsArg0 || (call->gtInitClsHnd == NO_CLASS_HANDLE)); } else { @@ -12376,6 +12376,8 @@ void Compiler::fgValueNumberHelperCallFunc(GenTreeCall* call, VNFunc vnf, ValueN } } break; + case VNF_ReadyToRunStaticBaseThread: + case VNF_ReadyToRunStaticBaseThreadNonGC: case VNF_ReadyToRunGenericStaticBase: case VNF_ReadyToRunIsInstanceOf: case VNF_ReadyToRunCastClass: diff --git a/src/coreclr/jit/valuenumfuncs.h b/src/coreclr/jit/valuenumfuncs.h index f875f3aadaf43d..75848b53d1035b 100644 --- a/src/coreclr/jit/valuenumfuncs.h +++ b/src/coreclr/jit/valuenumfuncs.h @@ -119,6 +119,7 @@ ValueNumFuncDef(GetsharedGcstaticBase, 2, false, true, true, false) ValueNumFuncDef(GetsharedNongcstaticBase, 2, false, true, true, false) ValueNumFuncDef(GetsharedGcstaticBaseNoctor, 1, false, true, true, false) ValueNumFuncDef(GetsharedNongcstaticBaseNoctor, 1, false, true, true, false) +ValueNumFuncDef(ReadyToRunStaticBaseCommon, 1, false, true, true, false) ValueNumFuncDef(ReadyToRunStaticBaseGC, 1, false, true, true, false) ValueNumFuncDef(ReadyToRunStaticBaseNonGC, 1, false, true, true, false) ValueNumFuncDef(ReadyToRunStaticBaseThread, 1, false, true, true, false) diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs b/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs index 47e7e6bb7dd710..434ec00c432fde 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs @@ -1144,6 +1144,9 @@ public unsafe struct CORINFO_FIELD_INFO // Used by Ready-to-Run public CORINFO_CONST_LOOKUP fieldLookup; + + // Used by NativeAOT + public bool useEnclosingTypeOnly; }; public unsafe struct CORINFO_THREAD_STATIC_BLOCKS_INFO diff --git a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs index eb988b0b604f8c..dee0cb94cc1760 100644 --- a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs +++ b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs @@ -2051,7 +2051,7 @@ private void getFieldInfo(ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_MET CORINFO_FIELD_ACCESSOR fieldAccessor; CORINFO_FIELD_FLAGS fieldFlags = (CORINFO_FIELD_FLAGS)0; uint fieldOffset = (field.IsStatic && field.HasRva ? 0xBAADF00D : (uint)field.Offset.AsInt); - + pResult->useEnclosingTypeOnly = false; if (field.IsThreadStatic && field.OwningType is MetadataType mt) { fieldOffset += _compilation.NodeFactory.ThreadStaticBaseOffset(mt); @@ -2175,6 +2175,7 @@ private void getFieldInfo(ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_MET if (helperId != ReadyToRunHelperId.Invalid) { + pResult->useEnclosingTypeOnly = true; pResult->fieldLookup = CreateConstLookupToSymbol( _compilation.NodeFactory.ReadyToRunHelper(helperId, field.OwningType)); } From c9040a2ce62dce3fd43b0aa95e6b8a4f1b75efe0 Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Wed, 13 Dec 2023 20:04:57 -0800 Subject: [PATCH 33/58] do not use vnf, but only use useEnclosingTypeAsArg0 --- src/coreclr/jit/valuenum.cpp | 13 ++++++++++--- src/coreclr/jit/valuenumfuncs.h | 1 - 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/coreclr/jit/valuenum.cpp b/src/coreclr/jit/valuenum.cpp index 5006e648cd0fc0..a4a64c6b1b6117 100644 --- a/src/coreclr/jit/valuenum.cpp +++ b/src/coreclr/jit/valuenum.cpp @@ -12301,7 +12301,7 @@ void Compiler::fgValueNumberHelperCallFunc(GenTreeCall* call, VNFunc vnf, ValueN CallArgs* args = &call->gtArgs; bool generateUniqueVN = false; bool useEntryPointAddrAsArg0 = false; - bool useEnclosingTypeAsArg0 = call->IsArgNeedsEnclosingType(); + bool useEnclosingTypeAsArg0 = false; switch (vnf) { @@ -12367,8 +12367,15 @@ void Compiler::fgValueNumberHelperCallFunc(GenTreeCall* call, VNFunc vnf, ValueN if (IsTargetAbi(CORINFO_NATIVEAOT_ABI)) { // TODO: Do this for R2R as well - vnf = VNF_ReadyToRunStaticBaseCommon; - assert(useEnclosingTypeAsArg0 || (call->gtInitClsHnd == NO_CLASS_HANDLE)); + if (call->IsArgNeedsEnclosingType()) + { + useEnclosingTypeAsArg0 = true; + assert((call->gtInitClsHnd != NO_CLASS_HANDLE) && ((ssize_t)call->gtInitClsHnd != 0xcccccccc)); + } + else + { + useEntryPointAddrAsArg0 = true; + } } else { diff --git a/src/coreclr/jit/valuenumfuncs.h b/src/coreclr/jit/valuenumfuncs.h index 75848b53d1035b..f875f3aadaf43d 100644 --- a/src/coreclr/jit/valuenumfuncs.h +++ b/src/coreclr/jit/valuenumfuncs.h @@ -119,7 +119,6 @@ ValueNumFuncDef(GetsharedGcstaticBase, 2, false, true, true, false) ValueNumFuncDef(GetsharedNongcstaticBase, 2, false, true, true, false) ValueNumFuncDef(GetsharedGcstaticBaseNoctor, 1, false, true, true, false) ValueNumFuncDef(GetsharedNongcstaticBaseNoctor, 1, false, true, true, false) -ValueNumFuncDef(ReadyToRunStaticBaseCommon, 1, false, true, true, false) ValueNumFuncDef(ReadyToRunStaticBaseGC, 1, false, true, true, false) ValueNumFuncDef(ReadyToRunStaticBaseNonGC, 1, false, true, true, false) ValueNumFuncDef(ReadyToRunStaticBaseThread, 1, false, true, true, false) From 5f76a6c0b57987ec2383d6cf0ed324a0fbbcfb5e Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Thu, 14 Dec 2023 07:00:37 -0800 Subject: [PATCH 34/58] Use GT_COMMA to add GCStaticBase call next to TLS call --- src/coreclr/jit/importer.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index 0a311c6655501e..04d6b406ba1789 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -3838,7 +3838,25 @@ GenTree* Compiler::impImportStaticFieldAddress(CORINFO_RESOLVED_TOKEN* pResolved else if (pFieldInfo->fieldAccessor == CORINFO_FIELD_STATIC_TLS_MANAGED_LAZY) { op1->AsCall()->SetExpTLSFieldAccessLazyCtor(); + // TODO: Add GT_COMMA here. + // op1 = GT_COMMA(gtUnusedValue(CORINFO_HELP_READYTORUN_GCSTATIC_BASE), op1); + GenTreeCall* lazyCtorCall = gtNewHelperCallNode(CORINFO_HELP_READYTORUN_GCSTATIC_BASE, TYP_BYREF); + if (pResolvedToken->hClass == info.compClassHnd && m_preferredInitCctor == CORINFO_HELP_UNDEF) + { + m_preferredInitCctor = pFieldInfo->helper; + } + lazyCtorCall->setEntryPoint(pFieldInfo->fieldLookup); + lazyCtorCall->gtInitClsHnd = pResolvedToken->hClass; + lazyCtorCall->gtFlags |= callFlags; + op1->AsCall()->gtInitClsHnd = pResolvedToken->hClass; + op1->gtFlags |= callFlags; + + op1->AsCall()->setEntryPoint(pFieldInfo->fieldLookup); + + op1 = gtNewOperNode(GT_COMMA, op1->TypeGet(), gtUnusedValNode(lazyCtorCall), op1); + op1 = gtNewOperNode(GT_ADD, op1->TypeGet(), op1, gtNewIconNode(pFieldInfo->offset, innerFldSeq)); + break; } if (pResolvedToken->hClass == info.compClassHnd && m_preferredInitCctor == CORINFO_HELP_UNDEF && (pFieldInfo->helper == CORINFO_HELP_READYTORUN_GCSTATIC_BASE || From daca626a189860d523f35563d715c3a04f46d91a Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Thu, 14 Dec 2023 15:52:14 -0800 Subject: [PATCH 35/58] optimize the cctor call --- src/coreclr/jit/compiler.cpp | 1 + src/coreclr/jit/compiler.h | 1 + src/coreclr/jit/importer.cpp | 33 ++++++++++++++++++++------------- src/coreclr/jit/valuenum.cpp | 3 +-- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/coreclr/jit/compiler.cpp b/src/coreclr/jit/compiler.cpp index f3eee4ec87bcdd..27e8923208ff2c 100644 --- a/src/coreclr/jit/compiler.cpp +++ b/src/coreclr/jit/compiler.cpp @@ -2396,6 +2396,7 @@ unsigned ReinterpretHexAsDecimal(unsigned in) void Compiler::compInitOptions(JitFlags* jitFlags) { + useNewFeature = false; opts = {}; if (compIsForInlining()) diff --git a/src/coreclr/jit/compiler.h b/src/coreclr/jit/compiler.h index 6397839ddbe336..a48163e90138ee 100644 --- a/src/coreclr/jit/compiler.h +++ b/src/coreclr/jit/compiler.h @@ -2531,6 +2531,7 @@ class Compiler #ifdef DEBUG bool verbose; + bool useNewFeature; bool verboseTrees; bool shouldUseVerboseTrees(); bool asciiTrees; // If true, dump trees using only ASCII characters diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index afd6ea6c4982e5..db4d3677e0086c 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -3860,24 +3860,31 @@ GenTree* Compiler::impImportStaticFieldAddress(CORINFO_RESOLVED_TOKEN* pResolved } else if (pFieldInfo->fieldAccessor == CORINFO_FIELD_STATIC_TLS_MANAGED_LAZY) { - op1->AsCall()->SetExpTLSFieldAccessLazyCtor(); - // TODO: Add GT_COMMA here. - // op1 = GT_COMMA(gtUnusedValue(CORINFO_HELP_READYTORUN_GCSTATIC_BASE), op1); - GenTreeCall* lazyCtorCall = gtNewHelperCallNode(CORINFO_HELP_READYTORUN_GCSTATIC_BASE, TYP_BYREF); - if (pResolvedToken->hClass == info.compClassHnd && m_preferredInitCctor == CORINFO_HELP_UNDEF) - { - m_preferredInitCctor = pFieldInfo->helper; - } - lazyCtorCall->setEntryPoint(pFieldInfo->fieldLookup); - lazyCtorCall->gtInitClsHnd = pResolvedToken->hClass; - lazyCtorCall->gtFlags |= callFlags; op1->AsCall()->gtInitClsHnd = pResolvedToken->hClass; op1->gtFlags |= callFlags; - op1->AsCall()->setEntryPoint(pFieldInfo->fieldLookup); - op1 = gtNewOperNode(GT_COMMA, op1->TypeGet(), gtUnusedValNode(lazyCtorCall), op1); + if (useNewFeature) + { + GenTreeCall* lazyCtorCall = + gtNewHelperCallNode(CORINFO_HELP_READYTORUN_GCSTATIC_BASE, TYP_BYREF); + if (pResolvedToken->hClass == info.compClassHnd && m_preferredInitCctor == CORINFO_HELP_UNDEF) + { + m_preferredInitCctor = pFieldInfo->helper; + } + lazyCtorCall->setEntryPoint(pFieldInfo->fieldLookup); + lazyCtorCall->gtInitClsHnd = pResolvedToken->hClass; + lazyCtorCall->gtFlags |= callFlags; + lazyCtorCall->SetArgNeedsEnclosingType(); + + op1 = gtNewOperNode(GT_COMMA, op1->TypeGet(), gtUnusedValNode(lazyCtorCall), op1); + } + else + { + op1->AsCall()->SetExpTLSFieldAccessLazyCtor(); + } + op1 = gtNewOperNode(GT_ADD, op1->TypeGet(), op1, gtNewIconNode(pFieldInfo->offset, innerFldSeq)); break; } diff --git a/src/coreclr/jit/valuenum.cpp b/src/coreclr/jit/valuenum.cpp index a4a64c6b1b6117..fe09d88f13e16a 100644 --- a/src/coreclr/jit/valuenum.cpp +++ b/src/coreclr/jit/valuenum.cpp @@ -12366,8 +12366,7 @@ void Compiler::fgValueNumberHelperCallFunc(GenTreeCall* call, VNFunc vnf, ValueN { if (IsTargetAbi(CORINFO_NATIVEAOT_ABI)) { - // TODO: Do this for R2R as well - if (call->IsArgNeedsEnclosingType()) + if (call->IsArgNeedsEnclosingType() && useNewFeature) { useEnclosingTypeAsArg0 = true; assert((call->gtInitClsHnd != NO_CLASS_HANDLE) && ((ssize_t)call->gtInitClsHnd != 0xcccccccc)); From c7d75efcc5c8ffbbe4422e2671d99c029bf40f3e Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Thu, 14 Dec 2023 16:04:59 -0800 Subject: [PATCH 36/58] Remove lazy ctor generation from tls --- src/coreclr/jit/compiler.cpp | 1 - src/coreclr/jit/compiler.h | 1 - src/coreclr/jit/gentree.h | 16 ---- src/coreclr/jit/helperexpansion.cpp | 127 +--------------------------- src/coreclr/jit/importer.cpp | 29 +++---- src/coreclr/jit/valuenum.cpp | 2 +- 6 files changed, 16 insertions(+), 160 deletions(-) diff --git a/src/coreclr/jit/compiler.cpp b/src/coreclr/jit/compiler.cpp index 27e8923208ff2c..f3eee4ec87bcdd 100644 --- a/src/coreclr/jit/compiler.cpp +++ b/src/coreclr/jit/compiler.cpp @@ -2396,7 +2396,6 @@ unsigned ReinterpretHexAsDecimal(unsigned in) void Compiler::compInitOptions(JitFlags* jitFlags) { - useNewFeature = false; opts = {}; if (compIsForInlining()) diff --git a/src/coreclr/jit/compiler.h b/src/coreclr/jit/compiler.h index a48163e90138ee..6397839ddbe336 100644 --- a/src/coreclr/jit/compiler.h +++ b/src/coreclr/jit/compiler.h @@ -2531,7 +2531,6 @@ class Compiler #ifdef DEBUG bool verbose; - bool useNewFeature; bool verboseTrees; bool shouldUseVerboseTrees(); bool asciiTrees; // If true, dump trees using only ASCII characters diff --git a/src/coreclr/jit/gentree.h b/src/coreclr/jit/gentree.h index 6b781916a58432..83ab8e5ae5c4c4 100644 --- a/src/coreclr/jit/gentree.h +++ b/src/coreclr/jit/gentree.h @@ -4080,7 +4080,6 @@ enum GenTreeCallFlags : unsigned int GTF_CALL_M_HAS_LATE_DEVIRT_INFO = 0x01000000, // this call has late devirtualzation info GTF_CALL_M_LDVIRTFTN_INTERFACE = 0x02000000, // ldvirtftn on an interface type GTF_CALL_M_ENCLOSING_TYPE_ONLY = 0x04000000, // helper call needs enclosing type as parameter - GTF_CALL_M_EXP_TLS_ACCESS_LAZY = 0x08000000, // this call is a helper for access TLS marked field and has lazy ctor }; inline constexpr GenTreeCallFlags operator ~(GenTreeCallFlags a) @@ -5468,21 +5467,6 @@ struct GenTreeCall final : public GenTree return (gtCallMoreFlags & GTF_CALL_M_ENCLOSING_TYPE_ONLY) != 0; } - void SetExpTLSFieldAccessLazyCtor() - { - gtCallMoreFlags |= GTF_CALL_M_EXP_TLS_ACCESS_LAZY; - } - - void ClearExpTLSFieldAccessLazyCtor() - { - gtCallMoreFlags &= ~GTF_CALL_M_EXP_TLS_ACCESS_LAZY; - } - - bool IsExpTLSFieldAccessLazyCtor() const - { - return (gtCallMoreFlags & GTF_CALL_M_EXP_TLS_ACCESS_LAZY) != 0; - } - void SetExpandedEarly() { gtCallMoreFlags |= GTF_CALL_M_EXPANDED_EARLY; diff --git a/src/coreclr/jit/helperexpansion.cpp b/src/coreclr/jit/helperexpansion.cpp index 73d89562404b6b..2de25e2cb01d56 100644 --- a/src/coreclr/jit/helperexpansion.cpp +++ b/src/coreclr/jit/helperexpansion.cpp @@ -468,7 +468,7 @@ bool Compiler::fgExpandThreadLocalAccessForCallNativeAOT(BasicBlock** pBlock, St bool isExpTLSFieldAccess = (helper == CORINFO_HELP_READYTORUN_THREADSTATIC_BASE) || (helper == CORINFO_HELP_READYTORUN_NONGCTHREADSTATIC_BASE); - if (!call->IsHelperCall() || !(isExpTLSFieldAccess || call->IsExpTLSFieldAccessLazyCtor())) + if (!call->IsHelperCall() || !isExpTLSFieldAccess) { return false; } @@ -476,9 +476,6 @@ bool Compiler::fgExpandThreadLocalAccessForCallNativeAOT(BasicBlock** pBlock, St JITDUMP("Expanding thread static local access for [%06d] in " FMT_BB ":\n", dspTreeID(call), block->bbNum); DISPTREE(call); JITDUMP("\n"); - bool hasLazyStaticCtor = call->IsExpTLSFieldAccessLazyCtor(); - - call->ClearExpTLSFieldAccessLazyCtor(); CORINFO_THREAD_STATIC_INFO_NATIVEAOT threadStaticInfo; memset(&threadStaticInfo, 0, sizeof(CORINFO_THREAD_STATIC_INFO_NATIVEAOT)); @@ -489,9 +486,6 @@ bool Compiler::fgExpandThreadLocalAccessForCallNativeAOT(BasicBlock** pBlock, St JITDUMP("tlsIndexObject= %p\n", dspPtr(threadStaticInfo.tlsIndexObject.addr)); JITDUMP("offsetOfThreadLocalStoragePointer= %u\n", dspOffset(threadStaticInfo.offsetOfThreadLocalStoragePointer)); JITDUMP("threadStaticBaseSlow= %p\n", dspPtr(threadStaticInfo.threadStaticBaseSlow.addr)); - JITDUMP("classCtorContextSize= %u\n", threadStaticInfo.classCtorContextSize); - JITDUMP("lazyCtorRunHelper= %p\n", dspPtr(threadStaticInfo.lazyCtorRunHelper.addr)); - JITDUMP("lazyCtorTargetSymbol= %p\n", dspPtr(threadStaticInfo.lazyCtorTargetSymbol.addr)); // Split block right before the call tree BasicBlock* prevBb = block; @@ -503,112 +497,10 @@ bool Compiler::fgExpandThreadLocalAccessForCallNativeAOT(BasicBlock** pBlock, St var_types callType = call->TypeGet(); assert(prevBb != nullptr && block != nullptr); - BasicBlock* targetSymbCondBB = nullptr; - BasicBlock* lazyCtorBB = nullptr; - unsigned finalLclNum = lvaGrabTemp(true DEBUGARG("Final offset")); lvaTable[finalLclNum].lvType = TYP_I_IMPL; GenTree* finalLcl = gtNewLclVarNode(finalLclNum); - // if (lazyCtorBlock) - // { - // targetSymbCondBB (BBJ_COND): [weight: 1.0] - // targetSymbolAddr = [targetSymbol + size] - // if (*targetSymbolAddr == 0) - // goto tlsRootNullCondBB; - // - // lazyCtorBlock (BBJ_ALWAYS): [weight: 0] - // tlsRoot = HelperCall(0, -1, targetSymbolAddr); - // goto block; - // - // } - // tlsRootNullCondBB (BBJ_COND): [weight: 1.0] - // fastPathValue = [tlsRootAddress] - // if (fastPathValue != nullptr) - // goto fastPathBb; - // - // fallbackBb (BBJ_ALWAYS): [weight: 0] - // tlsRoot = HelperCall(tlsRootAddress); - // goto block; - // - // fastPathBb(BBJ_ALWAYS): [weight: 1.0] - // tlsRoot = fastPathValue; - // - // - // block (...): [weight: 1.0] - // use(tlsRoot); - - if (hasLazyStaticCtor) - { - CORINFO_CONST_LOOKUP lazyCtorRunHelper = threadStaticInfo.lazyCtorRunHelper; - CORINFO_CONST_LOOKUP lazyCtorTargetSymbol = threadStaticInfo.lazyCtorTargetSymbol; - int classCtorContextSize = threadStaticInfo.classCtorContextSize; - - // target symbol - GenTree* targetSymbolAddr = gtNewIconHandleNode((size_t)lazyCtorTargetSymbol.addr, GTF_ICON_OBJ_HDL); - - targetSymbolAddr = - gtNewOperNode(GT_ADD, TYP_I_IMPL, targetSymbolAddr, gtNewIconNode(classCtorContextSize, TYP_I_IMPL)); - - unsigned targetSymbolLclNum = lvaGrabTemp(true DEBUGARG("Target symbol")); - lvaTable[targetSymbolLclNum].lvType = TYP_I_IMPL; - GenTree* tlsRootAddrDef = gtNewStoreLclVarNode(targetSymbolLclNum, targetSymbolAddr); - GenTree* tlsRootAddrUse = gtNewLclVarNode(targetSymbolLclNum); - - targetSymbCondBB = fgNewBBFromTreeAfter(BBJ_COND, prevBb, gtCloneExpr(tlsRootAddrUse), debugInfo); - - GenTree* targetSymbolAddrVal = gtNewIndir(TYP_I_IMPL, tlsRootAddrUse); - GenTree* targetSymbolNullCond = - gtNewOperNode(GT_EQ, TYP_INT, targetSymbolAddrVal, gtNewIconNode(0, TYP_I_IMPL)); - targetSymbolNullCond = gtNewOperNode(GT_JTRUE, TYP_VOID, targetSymbolNullCond); - fgInsertStmtAfter(targetSymbCondBB, targetSymbCondBB->firstStmt(), fgNewStmtFromTree(targetSymbolNullCond)); - - GenTreeCall* classCtorRunHelperCall = - gtNewIndCallNode(gtNewIconHandleNode((size_t)lazyCtorRunHelper.addr, GTF_ICON_FTN_ADDR), TYP_I_IMPL); - - // arg0: unused - classCtorRunHelperCall->gtArgs.PushBack(this, NewCallArg::Primitive(gtNewIconNode(0))); - - // arg1: -1 (index of inlined storage) - classCtorRunHelperCall->gtArgs.PushBack(this, NewCallArg::Primitive(gtNewIconNode(-1))); - - // arg2: NonGCStatics targetSymbol - classCtorRunHelperCall->gtArgs.PushBack(this, NewCallArg::Primitive(gtCloneExpr(tlsRootAddrUse))); - - fgMorphArgs(classCtorRunHelperCall); - - GenTree* lazyCtorValueDef = gtNewStoreLclVarNode(finalLclNum, classCtorRunHelperCall); - lazyCtorBB = fgNewBBFromTreeAfter(BBJ_ALWAYS, targetSymbCondBB, lazyCtorValueDef, debugInfo, block, true); - fgInsertStmtAfter(targetSymbCondBB, targetSymbCondBB->firstStmt(), fgNewStmtFromTree(tlsRootAddrDef)); - - fgRemoveRefPred(block, prevBb); - fgAddRefPred(targetSymbCondBB, prevBb); - fgAddRefPred(lazyCtorBB, targetSymbCondBB); - fgAddRefPred(block, lazyCtorBB); - - prevBb->SetJumpDest(targetSymbCondBB); - lazyCtorBB->SetJumpDest(block); - - // Inherit the weights - block->inheritWeight(prevBb); - targetSymbCondBB->inheritWeight(prevBb); - - // lazyCtorBB will just execute first time - lazyCtorBB->bbSetRunRarely(); - - targetSymbCondBB->bbNatLoopNum = prevBb->bbNatLoopNum; - lazyCtorBB->bbNatLoopNum = prevBb->bbNatLoopNum; - - assert(BasicBlock::sameEHRegion(prevBb, targetSymbCondBB)); - assert(BasicBlock::sameEHRegion(prevBb, lazyCtorBB)); - - // lazyCtorBB is the new prevBb going forward - prevBb = lazyCtorBB; - - JITDUMP("targetSymbCondBB: " FMT_BB "\n", targetSymbCondBB->bbNum); - JITDUMP("lazyCtorBB: " FMT_BB "\n", lazyCtorBB->bbNum); - } - // Block ops inserted by the split need to be morphed here since we are after morph. // We cannot morph stmt yet as we may modify it further below, and the morphing // could invalidate callUse. @@ -703,20 +595,9 @@ bool Compiler::fgExpandThreadLocalAccessForCallNativeAOT(BasicBlock** pBlock, St // fallback will just execute first time fallbackBb->bbSetRunRarely(); - if (hasLazyStaticCtor) - { - assert(targetSymbCondBB != nullptr); - assert(lazyCtorBB != nullptr); - - targetSymbCondBB->SetJumpDest(tlsRootNullCondBB); - fgAddRefPred(tlsRootNullCondBB, targetSymbCondBB); - } - else - { - fgRemoveRefPred(block, prevBb); - fgAddRefPred(tlsRootNullCondBB, prevBb); - prevBb->SetJumpDest(tlsRootNullCondBB); - } + fgRemoveRefPred(block, prevBb); + fgAddRefPred(tlsRootNullCondBB, prevBb); + prevBb->SetJumpDest(tlsRootNullCondBB); // // Update loop info if loop table is known to be valid diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index db4d3677e0086c..7b9c25bee717ff 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -3860,30 +3860,23 @@ GenTree* Compiler::impImportStaticFieldAddress(CORINFO_RESOLVED_TOKEN* pResolved } else if (pFieldInfo->fieldAccessor == CORINFO_FIELD_STATIC_TLS_MANAGED_LAZY) { - op1->AsCall()->gtInitClsHnd = pResolvedToken->hClass; op1->gtFlags |= callFlags; op1->AsCall()->setEntryPoint(pFieldInfo->fieldLookup); - if (useNewFeature) - { - GenTreeCall* lazyCtorCall = - gtNewHelperCallNode(CORINFO_HELP_READYTORUN_GCSTATIC_BASE, TYP_BYREF); - if (pResolvedToken->hClass == info.compClassHnd && m_preferredInitCctor == CORINFO_HELP_UNDEF) - { - m_preferredInitCctor = pFieldInfo->helper; - } - lazyCtorCall->setEntryPoint(pFieldInfo->fieldLookup); - lazyCtorCall->gtInitClsHnd = pResolvedToken->hClass; - lazyCtorCall->gtFlags |= callFlags; - lazyCtorCall->SetArgNeedsEnclosingType(); - - op1 = gtNewOperNode(GT_COMMA, op1->TypeGet(), gtUnusedValNode(lazyCtorCall), op1); - } - else + // Create a GT_COMMA to invoke the lazyCtor + GenTreeCall* lazyCtorCall = + gtNewHelperCallNode(CORINFO_HELP_READYTORUN_GCSTATIC_BASE, TYP_BYREF); + if (pResolvedToken->hClass == info.compClassHnd && m_preferredInitCctor == CORINFO_HELP_UNDEF) { - op1->AsCall()->SetExpTLSFieldAccessLazyCtor(); + m_preferredInitCctor = pFieldInfo->helper; } + lazyCtorCall->setEntryPoint(pFieldInfo->fieldLookup); + lazyCtorCall->gtInitClsHnd = pResolvedToken->hClass; + lazyCtorCall->gtFlags |= callFlags; + lazyCtorCall->SetArgNeedsEnclosingType(); + + op1 = gtNewOperNode(GT_COMMA, op1->TypeGet(), gtUnusedValNode(lazyCtorCall), op1); op1 = gtNewOperNode(GT_ADD, op1->TypeGet(), op1, gtNewIconNode(pFieldInfo->offset, innerFldSeq)); break; diff --git a/src/coreclr/jit/valuenum.cpp b/src/coreclr/jit/valuenum.cpp index fe09d88f13e16a..cd9c977a81bcc4 100644 --- a/src/coreclr/jit/valuenum.cpp +++ b/src/coreclr/jit/valuenum.cpp @@ -12366,7 +12366,7 @@ void Compiler::fgValueNumberHelperCallFunc(GenTreeCall* call, VNFunc vnf, ValueN { if (IsTargetAbi(CORINFO_NATIVEAOT_ABI)) { - if (call->IsArgNeedsEnclosingType() && useNewFeature) + if (call->IsArgNeedsEnclosingType()) { useEnclosingTypeAsArg0 = true; assert((call->gtInitClsHnd != NO_CLASS_HANDLE) && ((ssize_t)call->gtInitClsHnd != 0xcccccccc)); From 5895ab300af17bc855391605e4d88fc28ee9c424 Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Thu, 14 Dec 2023 16:06:52 -0800 Subject: [PATCH 37/58] Update jitinterface to not fetch data for lazy ctor --- src/coreclr/inc/corinfo.h | 6 +----- src/coreclr/inc/icorjitinfoimpl_generated.h | 3 +-- src/coreclr/inc/jiteeversionguid.h | 10 +++++----- .../jit/ICorJitInfo_wrapper_generated.hpp | 5 ++--- src/coreclr/jit/helperexpansion.cpp | 2 +- .../Common/JitInterface/CorInfoImpl_generated.cs | 6 +++--- .../tools/Common/JitInterface/CorInfoTypes.cs | 3 --- .../JitInterface/ThunkGenerator/ThunkInput.txt | 2 +- .../JitInterface/CorInfoImpl.ReadyToRun.cs | 2 +- .../JitInterface/CorInfoImpl.RyuJit.cs | 10 +--------- .../aot/jitinterface/jitinterface_generated.h | 7 +++---- .../superpmi/superpmi-shared/methodcontext.cpp | 16 ++++------------ .../superpmi/superpmi-shared/methodcontext.h | 4 ++-- .../superpmi-shim-collector/icorjitinfo.cpp | 7 +++---- .../icorjitinfo_generated.cpp | 5 ++--- .../icorjitinfo_generated.cpp | 5 ++--- .../tools/superpmi/superpmi/icorjitinfo.cpp | 4 ++-- src/coreclr/vm/jitinterface.cpp | 2 +- 18 files changed, 35 insertions(+), 64 deletions(-) diff --git a/src/coreclr/inc/corinfo.h b/src/coreclr/inc/corinfo.h index bd0b15a0e2b574..582ba6ecf707be 100644 --- a/src/coreclr/inc/corinfo.h +++ b/src/coreclr/inc/corinfo.h @@ -1749,9 +1749,6 @@ struct CORINFO_THREAD_STATIC_INFO_NATIVEAOT CORINFO_CONST_LOOKUP tlsRootObject; CORINFO_CONST_LOOKUP tlsIndexObject; CORINFO_CONST_LOOKUP threadStaticBaseSlow; - uint32_t classCtorContextSize; - CORINFO_CONST_LOOKUP lazyCtorRunHelper; - CORINFO_CONST_LOOKUP lazyCtorTargetSymbol; }; //---------------------------------------------------------------------------- @@ -2835,8 +2832,7 @@ class ICorStaticInfo ) = 0; virtual void getThreadLocalStaticInfo_NativeAOT( - CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo, - CORINFO_CLASS_HANDLE cls + CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo ) = 0; // Returns true iff "fldHnd" represents a static field. diff --git a/src/coreclr/inc/icorjitinfoimpl_generated.h b/src/coreclr/inc/icorjitinfoimpl_generated.h index 564076d957a3fc..610a7de5b46f8d 100644 --- a/src/coreclr/inc/icorjitinfoimpl_generated.h +++ b/src/coreclr/inc/icorjitinfoimpl_generated.h @@ -400,8 +400,7 @@ void getThreadLocalStaticBlocksInfo( bool isGCType) override; void getThreadLocalStaticInfo_NativeAOT( - CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo, - CORINFO_CLASS_HANDLE cls) override; + CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo) override; bool isFieldStatic( CORINFO_FIELD_HANDLE fldHnd) override; diff --git a/src/coreclr/inc/jiteeversionguid.h b/src/coreclr/inc/jiteeversionguid.h index 49009af58bbfdd..6262bcdf852760 100644 --- a/src/coreclr/inc/jiteeversionguid.h +++ b/src/coreclr/inc/jiteeversionguid.h @@ -43,11 +43,11 @@ typedef const GUID *LPCGUID; #define GUID_DEFINED #endif // !GUID_DEFINED -constexpr GUID JITEEVersionIdentifier = { /* 1572ff26-ec9d-48ce-b223-898c65e8e257 */ - 0x1572ff26, - 0xec9d, - 0x48ce, - {0xb2, 0x23, 0x89, 0x8c, 0x65, 0xe8, 0xe2, 0x57} +constexpr GUID JITEEVersionIdentifier = { /* d7bbeb5a-aa7d-43ec-b29e-6f24dd3bca9c */ + 0xd7bbeb5a, + 0xaa7d, + 0x43ec, + {0xb2, 0x9e, 0x6f, 0x24, 0xdd, 0x3b, 0xca, 0x9c} }; ////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp b/src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp index be49a542145faa..f400e80ac19003 100644 --- a/src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp +++ b/src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp @@ -942,11 +942,10 @@ void WrapICorJitInfo::getThreadLocalStaticBlocksInfo( } void WrapICorJitInfo::getThreadLocalStaticInfo_NativeAOT( - CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo, - CORINFO_CLASS_HANDLE cls) + CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo) { API_ENTER(getThreadLocalStaticInfo_NativeAOT); - wrapHnd->getThreadLocalStaticInfo_NativeAOT(pInfo, cls); + wrapHnd->getThreadLocalStaticInfo_NativeAOT(pInfo); API_LEAVE(getThreadLocalStaticInfo_NativeAOT); } diff --git a/src/coreclr/jit/helperexpansion.cpp b/src/coreclr/jit/helperexpansion.cpp index 2de25e2cb01d56..6e47a98836a7a6 100644 --- a/src/coreclr/jit/helperexpansion.cpp +++ b/src/coreclr/jit/helperexpansion.cpp @@ -480,7 +480,7 @@ bool Compiler::fgExpandThreadLocalAccessForCallNativeAOT(BasicBlock** pBlock, St CORINFO_THREAD_STATIC_INFO_NATIVEAOT threadStaticInfo; memset(&threadStaticInfo, 0, sizeof(CORINFO_THREAD_STATIC_INFO_NATIVEAOT)); - info.compCompHnd->getThreadLocalStaticInfo_NativeAOT(&threadStaticInfo, call->gtInitClsHnd); + info.compCompHnd->getThreadLocalStaticInfo_NativeAOT(&threadStaticInfo); JITDUMP("tlsRootObject= %p\n", dspPtr(threadStaticInfo.tlsRootObject.addr)); JITDUMP("tlsIndexObject= %p\n", dspPtr(threadStaticInfo.tlsIndexObject.addr)); diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs b/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs index 6fb60aabf23c74..4238ae6642457c 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs @@ -1419,12 +1419,12 @@ private static void _getThreadLocalStaticBlocksInfo(IntPtr thisHandle, IntPtr* p } [UnmanagedCallersOnly] - private static void _getThreadLocalStaticInfo_NativeAOT(IntPtr thisHandle, IntPtr* ppException, CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo, CORINFO_CLASS_STRUCT_* cls) + private static void _getThreadLocalStaticInfo_NativeAOT(IntPtr thisHandle, IntPtr* ppException, CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo) { var _this = GetThis(thisHandle); try { - _this.getThreadLocalStaticInfo_NativeAOT(pInfo, cls); + _this.getThreadLocalStaticInfo_NativeAOT(pInfo); } catch (Exception ex) { @@ -2633,7 +2633,7 @@ private static IntPtr GetUnmanagedCallbacks() callbacks[92] = (delegate* unmanaged)&_getFieldInfo; callbacks[93] = (delegate* unmanaged)&_getThreadLocalFieldInfo; callbacks[94] = (delegate* unmanaged)&_getThreadLocalStaticBlocksInfo; - callbacks[95] = (delegate* unmanaged)&_getThreadLocalStaticInfo_NativeAOT; + callbacks[95] = (delegate* unmanaged)&_getThreadLocalStaticInfo_NativeAOT; callbacks[96] = (delegate* unmanaged)&_isFieldStatic; callbacks[97] = (delegate* unmanaged)&_getArrayOrStringLength; callbacks[98] = (delegate* unmanaged)&_getBoundaries; diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs b/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs index 587f95d6b213db..72c6673ab50c10 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs @@ -1169,9 +1169,6 @@ public unsafe struct CORINFO_THREAD_STATIC_INFO_NATIVEAOT public CORINFO_CONST_LOOKUP tlsRootObject; public CORINFO_CONST_LOOKUP tlsIndexObject; public CORINFO_CONST_LOOKUP threadStaticBaseSlow; - public uint classCtorContextSize; - public CORINFO_CONST_LOOKUP classCtorRunHelper; - public CORINFO_CONST_LOOKUP lazyCtorTargetSymbol; }; // System V struct passing diff --git a/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt b/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt index 9cfce7fcafebd3..b3bc46c4ddf654 100644 --- a/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt +++ b/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt @@ -257,7 +257,7 @@ FUNCTIONS void getFieldInfo(CORINFO_RESOLVED_TOKEN* pResolvedToken, CORINFO_METHOD_HANDLE callerHandle, CORINFO_ACCESS_FLAGS flags, CORINFO_FIELD_INFO* pResult) uint32_t getThreadLocalFieldInfo (CORINFO_FIELD_HANDLE field, bool isGCtype) void getThreadLocalStaticBlocksInfo (CORINFO_THREAD_STATIC_BLOCKS_INFO* pInfo, bool isGCType) - void getThreadLocalStaticInfo_NativeAOT(CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo, CORINFO_CLASS_HANDLE cls) + void getThreadLocalStaticInfo_NativeAOT(CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo) bool isFieldStatic(CORINFO_FIELD_HANDLE fldHnd) int getArrayOrStringLength(CORINFO_OBJECT_HANDLE objHnd) void getBoundaries(CORINFO_METHOD_HANDLE ftn, unsigned int* cILOffsets, uint32_t** pILOffsets, ICorDebugInfo::BoundaryTypes* implicitBoundaries) diff --git a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs index 03c8a5079dfcf2..aa3cacd3a7b008 100644 --- a/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs +++ b/src/coreclr/tools/aot/ILCompiler.ReadyToRun/JitInterface/CorInfoImpl.ReadyToRun.cs @@ -3359,7 +3359,7 @@ void ValidateSafetyOfUsingTypeEquivalenceOfType(TypeDesc type) } #pragma warning disable CA1822 // Mark members as static - private void getThreadLocalStaticInfo_NativeAOT(CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo, CORINFO_CLASS_STRUCT_* cls) + private void getThreadLocalStaticInfo_NativeAOT(CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo) { // Implemented for NativeAOT only for now. } diff --git a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs index a184289ef79b9b..349f81459cd281 100644 --- a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs +++ b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs @@ -2409,20 +2409,12 @@ private bool getStaticBaseAddress(CORINFO_CLASS_STRUCT_* cls, bool isGc, ref COR return true; } - private void getThreadLocalStaticInfo_NativeAOT(CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo, CORINFO_CLASS_STRUCT_* cls) + private void getThreadLocalStaticInfo_NativeAOT(CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo) { pInfo->offsetOfThreadLocalStoragePointer = (uint)(11 * PointerSize); // 0x58 = 0n88 pInfo->tlsIndexObject = CreateConstLookupToSymbol(_compilation.NodeFactory.ExternSymbol("_tls_index")); pInfo->tlsRootObject = CreateConstLookupToSymbol(_compilation.NodeFactory.TlsRoot); pInfo->threadStaticBaseSlow = CreateConstLookupToSymbol(_compilation.NodeFactory.HelperEntrypoint(HelperEntrypoint.GetInlinedThreadStaticBaseSlow)); - - MetadataType clsType = HandleToObject(cls) as MetadataType; - if (clsType != null) - { - pInfo->classCtorContextSize = (uint)-NonGCStaticsNode.GetClassConstructorContextSize(_compilation.NodeFactory.Target); - pInfo->classCtorRunHelper = CreateConstLookupToSymbol(_compilation.NodeFactory.HelperEntrypoint(HelperEntrypoint.EnsureClassConstructorRunAndReturnThreadStaticBase)); - pInfo->lazyCtorTargetSymbol = CreateConstLookupToSymbol(_compilation.NodeFactory.TypeNonGCStaticsSymbol(clsType)); - } } } } diff --git a/src/coreclr/tools/aot/jitinterface/jitinterface_generated.h b/src/coreclr/tools/aot/jitinterface/jitinterface_generated.h index 1da47a8c8f8fbe..78fb6621ba7ac4 100644 --- a/src/coreclr/tools/aot/jitinterface/jitinterface_generated.h +++ b/src/coreclr/tools/aot/jitinterface/jitinterface_generated.h @@ -106,7 +106,7 @@ struct JitInterfaceCallbacks void (* getFieldInfo)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_RESOLVED_TOKEN* pResolvedToken, CORINFO_METHOD_HANDLE callerHandle, CORINFO_ACCESS_FLAGS flags, CORINFO_FIELD_INFO* pResult); uint32_t (* getThreadLocalFieldInfo)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_FIELD_HANDLE field, bool isGCtype); void (* getThreadLocalStaticBlocksInfo)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_THREAD_STATIC_BLOCKS_INFO* pInfo, bool isGCType); - void (* getThreadLocalStaticInfo_NativeAOT)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo, CORINFO_CLASS_HANDLE cls); + void (* getThreadLocalStaticInfo_NativeAOT)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo); bool (* isFieldStatic)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_FIELD_HANDLE fldHnd); int (* getArrayOrStringLength)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_OBJECT_HANDLE objHnd); void (* getBoundaries)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_METHOD_HANDLE ftn, unsigned int* cILOffsets, uint32_t** pILOffsets, ICorDebugInfo::BoundaryTypes* implicitBoundaries); @@ -1127,11 +1127,10 @@ class JitInterfaceWrapper : public ICorJitInfo } virtual void getThreadLocalStaticInfo_NativeAOT( - CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo, - CORINFO_CLASS_HANDLE cls) + CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo) { CorInfoExceptionClass* pException = nullptr; - _callbacks->getThreadLocalStaticInfo_NativeAOT(_thisHandle, &pException, pInfo, cls); + _callbacks->getThreadLocalStaticInfo_NativeAOT(_thisHandle, &pException, pInfo); if (pException != nullptr) throw pException; } diff --git a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp index 452a5884fbad57..377bfd309e5ae5 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp @@ -3635,8 +3635,7 @@ void MethodContext::repGetThreadLocalStaticBlocksInfo(CORINFO_THREAD_STATIC_BLOC pInfo->offsetOfGCDataPointer = value.offsetOfGCDataPointer; } -void MethodContext::recGetThreadLocalStaticInfo_NativeAOT(CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo, - CORINFO_CLASS_HANDLE cls) +void MethodContext::recGetThreadLocalStaticInfo_NativeAOT(CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo) { if (GetThreadLocalStaticInfo_NativeAOT == nullptr) GetThreadLocalStaticInfo_NativeAOT = new LightWeightMap(); @@ -3647,11 +3646,8 @@ void MethodContext::recGetThreadLocalStaticInfo_NativeAOT(CORINFO_THREAD_STATIC_ value.tlsIndexObject = SpmiRecordsHelper::StoreAgnostic_CORINFO_CONST_LOOKUP(&pInfo->tlsIndexObject); value.offsetOfThreadLocalStoragePointer = pInfo->offsetOfThreadLocalStoragePointer; value.threadStaticBaseSlow = SpmiRecordsHelper::StoreAgnostic_CORINFO_CONST_LOOKUP(&pInfo->threadStaticBaseSlow); - value.lazyCtorRunHelper = SpmiRecordsHelper::StoreAgnostic_CORINFO_CONST_LOOKUP(&pInfo->lazyCtorRunHelper); - value.lazyCtorTargetSymbol = SpmiRecordsHelper::StoreAgnostic_CORINFO_CONST_LOOKUP(&pInfo->lazyCtorTargetSymbol); - value.classCtorContextSize = pInfo->classCtorContextSize; - DWORDLONG key = CastHandle(cls); + DWORDLONG key = 1; GetThreadLocalStaticInfo_NativeAOT->Add(key, value); DEBUG_REC(dmpGetThreadLocalStaticInfo_NativeAOT(key, result)); @@ -3670,10 +3666,9 @@ void MethodContext::dmpGetThreadLocalStaticInfo_NativeAOT(DWORDLONG value.classCtorContextSize); } -void MethodContext::repGetThreadLocalStaticInfo_NativeAOT(CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo, - CORINFO_CLASS_HANDLE cls) +void MethodContext::repGetThreadLocalStaticInfo_NativeAOT(CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo) { - DWORDLONG key = CastHandle(cls); + DWORDLONG key = 1; Agnostic_GetThreadStaticInfo_NativeAOT value = LookupByKeyOrMiss(GetThreadLocalStaticInfo_NativeAOT, key, ": key %016" PRIX64 "", key); @@ -3683,9 +3678,6 @@ void MethodContext::repGetThreadLocalStaticInfo_NativeAOT(CORINFO_THREAD_STATIC_ pInfo->tlsIndexObject = SpmiRecordsHelper::RestoreCORINFO_CONST_LOOKUP(value.tlsIndexObject); pInfo->offsetOfThreadLocalStoragePointer = value.offsetOfThreadLocalStoragePointer; pInfo->threadStaticBaseSlow = SpmiRecordsHelper::RestoreCORINFO_CONST_LOOKUP(value.threadStaticBaseSlow); - pInfo->lazyCtorRunHelper = SpmiRecordsHelper::RestoreCORINFO_CONST_LOOKUP(value.lazyCtorRunHelper); - pInfo->lazyCtorTargetSymbol = SpmiRecordsHelper::RestoreCORINFO_CONST_LOOKUP(value.lazyCtorTargetSymbol); - pInfo->classCtorContextSize = value.classCtorContextSize; } void MethodContext::recEmbedMethodHandle(CORINFO_METHOD_HANDLE handle, diff --git a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h index d3dc4f4135fd0d..4927f70e22ac6d 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h +++ b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h @@ -478,9 +478,9 @@ class MethodContext void dmpGetThreadLocalStaticBlocksInfo(DWORD key, const Agnostic_GetThreadLocalStaticBlocksInfo& value); void repGetThreadLocalStaticBlocksInfo(CORINFO_THREAD_STATIC_BLOCKS_INFO* pInfo, bool isGCType); - void recGetThreadLocalStaticInfo_NativeAOT(CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo, CORINFO_CLASS_HANDLE cls); + void recGetThreadLocalStaticInfo_NativeAOT(CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo); void dmpGetThreadLocalStaticInfo_NativeAOT(DWORDLONG key, const Agnostic_GetThreadStaticInfo_NativeAOT& value); - void repGetThreadLocalStaticInfo_NativeAOT(CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo, CORINFO_CLASS_HANDLE cls); + void repGetThreadLocalStaticInfo_NativeAOT(CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo); void recEmbedMethodHandle(CORINFO_METHOD_HANDLE handle, void** ppIndirection, CORINFO_METHOD_HANDLE result); void dmpEmbedMethodHandle(DWORDLONG key, DLDL value); diff --git a/src/coreclr/tools/superpmi/superpmi-shim-collector/icorjitinfo.cpp b/src/coreclr/tools/superpmi/superpmi-shim-collector/icorjitinfo.cpp index 3d4ccb5a759210..2d8ede0ed0df17 100644 --- a/src/coreclr/tools/superpmi/superpmi-shim-collector/icorjitinfo.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shim-collector/icorjitinfo.cpp @@ -1072,12 +1072,11 @@ void interceptor_ICJI::getThreadLocalStaticBlocksInfo(CORINFO_THREAD_STATIC_BLOC mc->recGetThreadLocalStaticBlocksInfo(pInfo, isGCType); } -void interceptor_ICJI::getThreadLocalStaticInfo_NativeAOT(CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo, - CORINFO_CLASS_HANDLE cls) +void interceptor_ICJI::getThreadLocalStaticInfo_NativeAOT(CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo) { mc->cr->AddCall("getThreadLocalStaticInfo_NativeAOT"); - original_ICorJitInfo->getThreadLocalStaticInfo_NativeAOT(pInfo, cls); - mc->recGetThreadLocalStaticInfo_NativeAOT(pInfo, cls); + original_ICorJitInfo->getThreadLocalStaticInfo_NativeAOT(pInfo); + mc->recGetThreadLocalStaticInfo_NativeAOT(pInfo); } // Returns true iff "fldHnd" represents a static field. diff --git a/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo_generated.cpp b/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo_generated.cpp index 34bd0461f5f8f4..a10e0389275c6f 100644 --- a/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo_generated.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo_generated.cpp @@ -771,11 +771,10 @@ void interceptor_ICJI::getThreadLocalStaticBlocksInfo( } void interceptor_ICJI::getThreadLocalStaticInfo_NativeAOT( - CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo, - CORINFO_CLASS_HANDLE cls) + CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo) { mcs->AddCall("getThreadLocalStaticInfo_NativeAOT"); - original_ICorJitInfo->getThreadLocalStaticInfo_NativeAOT(pInfo, cls); + original_ICorJitInfo->getThreadLocalStaticInfo_NativeAOT(pInfo); } bool interceptor_ICJI::isFieldStatic( diff --git a/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo_generated.cpp b/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo_generated.cpp index 480edec6736797..5ac4459b4e5337 100644 --- a/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo_generated.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo_generated.cpp @@ -676,10 +676,9 @@ void interceptor_ICJI::getThreadLocalStaticBlocksInfo( } void interceptor_ICJI::getThreadLocalStaticInfo_NativeAOT( - CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo, - CORINFO_CLASS_HANDLE cls) + CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo) { - original_ICorJitInfo->getThreadLocalStaticInfo_NativeAOT(pInfo, cls); + original_ICorJitInfo->getThreadLocalStaticInfo_NativeAOT(pInfo); } bool interceptor_ICJI::isFieldStatic( diff --git a/src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp b/src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp index 6d47e8bd030c2a..66353e1649e0c9 100644 --- a/src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp +++ b/src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp @@ -891,10 +891,10 @@ void MyICJI::getThreadLocalStaticBlocksInfo(CORINFO_THREAD_STATIC_BLOCKS_INFO* p jitInstance->mc->repGetThreadLocalStaticBlocksInfo(pInfo, isGCType); } -void MyICJI::getThreadLocalStaticInfo_NativeAOT(CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo, CORINFO_CLASS_HANDLE cls) +void MyICJI::getThreadLocalStaticInfo_NativeAOT(CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo) { jitInstance->mc->cr->AddCall("getThreadLocalStaticInfo_NativeAOT"); - jitInstance->mc->repGetThreadLocalStaticInfo_NativeAOT(pInfo, cls); + jitInstance->mc->repGetThreadLocalStaticInfo_NativeAOT(pInfo); } // Returns true iff "fldHnd" represents a static field. diff --git a/src/coreclr/vm/jitinterface.cpp b/src/coreclr/vm/jitinterface.cpp index 89d280bc95681d..1a13efba0811ff 100644 --- a/src/coreclr/vm/jitinterface.cpp +++ b/src/coreclr/vm/jitinterface.cpp @@ -1294,7 +1294,7 @@ static CorInfoHelpFunc getInstanceFieldHelper(FieldDesc * pField, CORINFO_ACCESS /*********************************************************************/ -void CEEInfo::getThreadLocalStaticInfo_NativeAOT(CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo, CORINFO_CLASS_HANDLE cls) +void CEEInfo::getThreadLocalStaticInfo_NativeAOT(CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo) { LIMITED_METHOD_CONTRACT; UNREACHABLE(); // only called with NativeAOT. From 571b6df617046a530d818e6dc03342613cc01481 Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Thu, 14 Dec 2023 16:50:53 -0800 Subject: [PATCH 38/58] fix errors after merge --- src/coreclr/jit/helperexpansion.cpp | 4 ++-- src/coreclr/jit/importer.cpp | 3 +-- src/coreclr/jit/valuenum.cpp | 2 +- src/coreclr/tools/superpmi/superpmi-shared/agnostic.h | 3 --- .../tools/superpmi/superpmi-shared/methodcontext.cpp | 7 ++----- 5 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/coreclr/jit/helperexpansion.cpp b/src/coreclr/jit/helperexpansion.cpp index 64179fcbf6c29b..31aeb124590264 100644 --- a/src/coreclr/jit/helperexpansion.cpp +++ b/src/coreclr/jit/helperexpansion.cpp @@ -585,7 +585,7 @@ bool Compiler::fgExpandThreadLocalAccessForCallNativeAOT(BasicBlock** pBlock, St fgAddRefPred(block, fallbackBb); fgAddRefPred(block, fastPathBb); - tlsRootNullCondBB->SetJumpDest(fastPathBb); + tlsRootNullCondBB->SetTarget(fastPathBb); // Inherit the weights block->inheritWeight(prevBb); @@ -597,7 +597,7 @@ bool Compiler::fgExpandThreadLocalAccessForCallNativeAOT(BasicBlock** pBlock, St fgRemoveRefPred(block, prevBb); fgAddRefPred(tlsRootNullCondBB, prevBb); - prevBb->SetJumpDest(tlsRootNullCondBB); + prevBb->SetTarget(tlsRootNullCondBB); // // Update loop info if loop table is known to be valid diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index 31e0361109be1c..1dacd9fe0ecade 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -3865,8 +3865,7 @@ GenTree* Compiler::impImportStaticFieldAddress(CORINFO_RESOLVED_TOKEN* pResolved op1->AsCall()->setEntryPoint(pFieldInfo->fieldLookup); // Create a GT_COMMA to invoke the lazyCtor - GenTreeCall* lazyCtorCall = - gtNewHelperCallNode(CORINFO_HELP_READYTORUN_GCSTATIC_BASE, TYP_BYREF); + GenTreeCall* lazyCtorCall = gtNewHelperCallNode(CORINFO_HELP_READYTORUN_GCSTATIC_BASE, TYP_BYREF); if (pResolvedToken->hClass == info.compClassHnd && m_preferredInitCctor == CORINFO_HELP_UNDEF) { m_preferredInitCctor = pFieldInfo->helper; diff --git a/src/coreclr/jit/valuenum.cpp b/src/coreclr/jit/valuenum.cpp index e5ecc8f25ec26e..5b887677550c67 100644 --- a/src/coreclr/jit/valuenum.cpp +++ b/src/coreclr/jit/valuenum.cpp @@ -12413,7 +12413,7 @@ void Compiler::fgValueNumberHelperCallFunc(GenTreeCall* call, VNFunc vnf, ValueN // added this arg, so we do not need to use EntryPointAddrAsArg0 // because the indirection cell itself allows us to disambiguate. useEntryPointAddrAsArg0 = false; - useEnclosingTypeAsArg0 = false; + useEnclosingTypeAsArg0 = false; } CallArg* curArg = args->Args().begin().GetArg(); diff --git a/src/coreclr/tools/superpmi/superpmi-shared/agnostic.h b/src/coreclr/tools/superpmi/superpmi-shared/agnostic.h index 258f43f95ebb40..65881596a73d5f 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/agnostic.h +++ b/src/coreclr/tools/superpmi/superpmi-shared/agnostic.h @@ -539,9 +539,6 @@ struct Agnostic_GetThreadStaticInfo_NativeAOT Agnostic_CORINFO_CONST_LOOKUP tlsRootObject; Agnostic_CORINFO_CONST_LOOKUP tlsIndexObject; Agnostic_CORINFO_CONST_LOOKUP threadStaticBaseSlow; - DWORD classCtorContextSize; - Agnostic_CORINFO_CONST_LOOKUP lazyCtorRunHelper; - Agnostic_CORINFO_CONST_LOOKUP lazyCtorTargetSymbol; }; struct Agnostic_GetClassCtorInitializationInfo diff --git a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp index 377bfd309e5ae5..3a2c7c98517a12 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp @@ -3656,14 +3656,11 @@ void MethodContext::dmpGetThreadLocalStaticInfo_NativeAOT(DWORDLONG const Agnostic_GetThreadStaticInfo_NativeAOT& value) { printf("GetThreadLocalStaticInfo_NativeAOT key %016" PRIX64 ", tlsRootObject-%s, tlsIndexObject-%s, offsetOfThreadLocalStoragePointer-%u, " - "threadStaticBaseSlow-%s, lazyCtorRunHelper-%s, lazyCtorTargetSymbol-%s, classCtorContextSize-%u", + "threadStaticBaseSlow-%s", key, SpmiDumpHelper::DumpAgnostic_CORINFO_CONST_LOOKUP(value.tlsRootObject).c_str(), SpmiDumpHelper::DumpAgnostic_CORINFO_CONST_LOOKUP(value.tlsIndexObject).c_str(), value.offsetOfThreadLocalStoragePointer, - SpmiDumpHelper::DumpAgnostic_CORINFO_CONST_LOOKUP(value.threadStaticBaseSlow).c_str(), - SpmiDumpHelper::DumpAgnostic_CORINFO_CONST_LOOKUP(value.lazyCtorRunHelper).c_str(), - SpmiDumpHelper::DumpAgnostic_CORINFO_CONST_LOOKUP(value.lazyCtorTargetSymbol).c_str(), - value.classCtorContextSize); + SpmiDumpHelper::DumpAgnostic_CORINFO_CONST_LOOKUP(value.threadStaticBaseSlow).c_str()); } void MethodContext::repGetThreadLocalStaticInfo_NativeAOT(CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo) From da9565977d539a01804a9d9b8dc8a195b58aee5e Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Fri, 15 Dec 2023 16:43:41 -0800 Subject: [PATCH 39/58] fix test build errors --- src/coreclr/jit/helperexpansion.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/coreclr/jit/helperexpansion.cpp b/src/coreclr/jit/helperexpansion.cpp index 31aeb124590264..0dd6fdc112cea9 100644 --- a/src/coreclr/jit/helperexpansion.cpp +++ b/src/coreclr/jit/helperexpansion.cpp @@ -513,6 +513,25 @@ bool Compiler::fgExpandThreadLocalAccessForCallNativeAOT(BasicBlock** pBlock, St if (TargetOS::IsWindows) { #ifdef TARGET_64BIT + // prevBb (BBJ_NONE): [weight: 1.0] + // ... + // + // tlsRootNullCondBB (BBJ_COND): [weight: 1.0] + // fastPathValue = [tlsRootAddress] + // if (fastPathValue != nullptr) + // goto fastPathBb; + // + // fallbackBb (BBJ_ALWAYS): [weight: 0] + // tlsRoot = HelperCall(); + // goto block; + // + // fastPathBb(BBJ_ALWAYS): [weight: 1.0] + // tlsRoot = fastPathValue; + // + // block (...): [weight: 1.0] + // use(tlsRoot); + // ... + // Mark this ICON as a TLS_HDL, codegen will use FS:[cns] or GS:[cns] GenTree* tlsValue = gtNewIconHandleNode(threadStaticInfo.offsetOfThreadLocalStoragePointer, GTF_ICON_TLS_HDL); tlsValue = gtNewIndir(TYP_I_IMPL, tlsValue, GTF_IND_NONFAULTING | GTF_IND_INVARIANT); @@ -585,7 +604,7 @@ bool Compiler::fgExpandThreadLocalAccessForCallNativeAOT(BasicBlock** pBlock, St fgAddRefPred(block, fallbackBb); fgAddRefPred(block, fastPathBb); - tlsRootNullCondBB->SetTarget(fastPathBb); + tlsRootNullCondBB->SetTrueTarget(fastPathBb); // Inherit the weights block->inheritWeight(prevBb); From 8679e4b34c84f3f656dd949e3f2425a3ccff87d9 Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Fri, 15 Dec 2023 16:43:53 -0800 Subject: [PATCH 40/58] fix bug in CSE --- src/coreclr/jit/gentree.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/coreclr/jit/gentree.cpp b/src/coreclr/jit/gentree.cpp index 974be388ebfe1d..e114c15c9e16c3 100644 --- a/src/coreclr/jit/gentree.cpp +++ b/src/coreclr/jit/gentree.cpp @@ -16927,13 +16927,19 @@ void Compiler::gtExtractSideEffList(GenTree* expr, fgWalkResult PreOrderVisit(GenTree** use, GenTree* user) { - GenTree* node = *use; + GenTree* node = *use; + GenTreeFlags flags = m_flags; - bool treeHasSideEffects = m_compiler->gtTreeHasSideEffects(node, m_flags); + if ((user != nullptr) && (user->OperIs(GT_COMMA)) && (user->AsOp()->gtGetOp1() == node)) + { + flags &= ~GTF_IS_IN_CSE; + } + + bool treeHasSideEffects = m_compiler->gtTreeHasSideEffects(node, flags); if (treeHasSideEffects) { - if (m_compiler->gtNodeHasSideEffects(node, m_flags)) + if (m_compiler->gtNodeHasSideEffects(node, flags)) { if (node->OperIsBlk() && !node->OperIsStoreBlk()) { From 0ce7618c74a7adc85a8a2af6ee019a0aea0328cc Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Mon, 18 Dec 2023 09:33:35 -0800 Subject: [PATCH 41/58] Use CORINFO_FLG_FIELD_INITCLASS instead of separate flag --- src/coreclr/inc/corinfo.h | 1 - src/coreclr/jit/importer.cpp | 40 +++++++++---------- .../tools/Common/JitInterface/CorInfoTypes.cs | 3 +- .../Target_X64/X64ReadyToRunHelperNode.cs | 5 +-- .../JitInterface/CorInfoImpl.RyuJit.cs | 7 +--- 5 files changed, 24 insertions(+), 32 deletions(-) diff --git a/src/coreclr/inc/corinfo.h b/src/coreclr/inc/corinfo.h index 582ba6ecf707be..0a7400dee32173 100644 --- a/src/coreclr/inc/corinfo.h +++ b/src/coreclr/inc/corinfo.h @@ -1684,7 +1684,6 @@ enum CORINFO_FIELD_ACCESSOR CORINFO_FIELD_STATIC_ADDR_HELPER, // static field accessed using address-of helper (argument is FieldDesc *) CORINFO_FIELD_STATIC_TLS, // unmanaged TLS access CORINFO_FIELD_STATIC_TLS_MANAGED, // managed TLS access - CORINFO_FIELD_STATIC_TLS_MANAGED_LAZY, // managed TLS access lazy ctor initialization CORINFO_FIELD_STATIC_READYTORUN_HELPER, // static field access using a runtime lookup helper CORINFO_FIELD_STATIC_RELOCATABLE, // static field access using relocation (used in AOT) CORINFO_FIELD_INTRINSIC_ZERO, // intrinsic zero (IntPtr.Zero, UIntPtr.Zero) diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index 1dacd9fe0ecade..e12fd9893f55a8 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -3821,7 +3821,6 @@ GenTree* Compiler::impImportStaticFieldAddress(CORINFO_RESOLVED_TOKEN* pResolved break; case CORINFO_FIELD_STATIC_TLS_MANAGED: - case CORINFO_FIELD_STATIC_TLS_MANAGED_LAZY: #ifdef FEATURE_READYTORUN if (!opts.IsReadyToRun()) @@ -3857,27 +3856,29 @@ GenTree* Compiler::impImportStaticFieldAddress(CORINFO_RESOLVED_TOKEN* pResolved if (pFieldInfo->fieldAccessor == CORINFO_FIELD_STATIC_TLS_MANAGED) { op1->AsCall()->gtInitClsHnd = pResolvedToken->hClass; - } - else if (pFieldInfo->fieldAccessor == CORINFO_FIELD_STATIC_TLS_MANAGED_LAZY) - { - op1->AsCall()->gtInitClsHnd = pResolvedToken->hClass; - op1->gtFlags |= callFlags; - op1->AsCall()->setEntryPoint(pFieldInfo->fieldLookup); - // Create a GT_COMMA to invoke the lazyCtor - GenTreeCall* lazyCtorCall = gtNewHelperCallNode(CORINFO_HELP_READYTORUN_GCSTATIC_BASE, TYP_BYREF); - if (pResolvedToken->hClass == info.compClassHnd && m_preferredInitCctor == CORINFO_HELP_UNDEF) + if (pFieldInfo->fieldFlags & CORINFO_FLG_FIELD_INITCLASS) { - m_preferredInitCctor = pFieldInfo->helper; - } - lazyCtorCall->setEntryPoint(pFieldInfo->fieldLookup); - lazyCtorCall->gtInitClsHnd = pResolvedToken->hClass; - lazyCtorCall->gtFlags |= callFlags; - lazyCtorCall->SetArgNeedsEnclosingType(); + op1->gtFlags |= callFlags; + op1->AsCall()->setEntryPoint(pFieldInfo->fieldLookup); - op1 = gtNewOperNode(GT_COMMA, op1->TypeGet(), gtUnusedValNode(lazyCtorCall), op1); + // Create a GT_COMMA to invoke the lazyCtor + GenTreeCall* lazyCtorCall = + gtNewHelperCallNode(CORINFO_HELP_READYTORUN_GCSTATIC_BASE, TYP_BYREF); + if (pResolvedToken->hClass == info.compClassHnd && m_preferredInitCctor == CORINFO_HELP_UNDEF) + { + m_preferredInitCctor = pFieldInfo->helper; + } + lazyCtorCall->setEntryPoint(pFieldInfo->fieldLookup); + lazyCtorCall->gtInitClsHnd = pResolvedToken->hClass; + lazyCtorCall->gtFlags |= callFlags; + lazyCtorCall->SetArgNeedsEnclosingType(); - op1 = gtNewOperNode(GT_ADD, op1->TypeGet(), op1, gtNewIconNode(pFieldInfo->offset, innerFldSeq)); + op1 = gtNewOperNode(GT_COMMA, op1->TypeGet(), gtUnusedValNode(lazyCtorCall), op1); + + op1 = + gtNewOperNode(GT_ADD, op1->TypeGet(), op1, gtNewIconNode(pFieldInfo->offset, innerFldSeq)); + } break; } if (pResolvedToken->hClass == info.compClassHnd && m_preferredInitCctor == CORINFO_HELP_UNDEF && @@ -9049,7 +9050,6 @@ void Compiler::impImportBlockCode(BasicBlock* block) break; case CORINFO_FIELD_STATIC_TLS_MANAGED: - case CORINFO_FIELD_STATIC_TLS_MANAGED_LAZY: setMethodHasTlsFieldAccess(); FALLTHROUGH; case CORINFO_FIELD_STATIC_SHARED_STATIC_HELPER: @@ -9230,7 +9230,6 @@ void Compiler::impImportBlockCode(BasicBlock* block) break; case CORINFO_FIELD_STATIC_TLS_MANAGED: - case CORINFO_FIELD_STATIC_TLS_MANAGED_LAZY: case CORINFO_FIELD_STATIC_ADDRESS: case CORINFO_FIELD_STATIC_RVA_ADDRESS: case CORINFO_FIELD_STATIC_SHARED_STATIC_HELPER: @@ -9331,7 +9330,6 @@ void Compiler::impImportBlockCode(BasicBlock* block) goto SPILL_APPEND; case CORINFO_FIELD_STATIC_TLS_MANAGED: - case CORINFO_FIELD_STATIC_TLS_MANAGED_LAZY: setMethodHasTlsFieldAccess(); FALLTHROUGH; case CORINFO_FIELD_STATIC_ADDRESS: diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs b/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs index 72c6673ab50c10..4ba4f8fbde79b5 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs @@ -1106,11 +1106,10 @@ public enum CORINFO_FIELD_ACCESSOR CORINFO_FIELD_STATIC_ADDR_HELPER, // static field accessed using address-of helper (argument is FieldDesc *) CORINFO_FIELD_STATIC_TLS, // unmanaged TLS access CORINFO_FIELD_STATIC_TLS_MANAGED, // managed TLS access - CORINFO_FIELD_STATIC_TLS_MANAGED_LAZY, // managed TLS access lazy CORINFO_FIELD_STATIC_READYTORUN_HELPER, // static field access using a runtime lookup helper CORINFO_FIELD_STATIC_RELOCATABLE, // static field access from the data segment CORINFO_FIELD_INTRINSIC_ZERO, // intrinsic zero (IntPtr.Zero, UIntPtr.Zero) - CORINFO_FIELD_INTRINSIC_EMPTY_STRING, // intrinsic emptry string (String.Empty) + CORINFO_FIELD_INTRINSIC_EMPTY_STRING, // intrinsic empty string (String.Empty) CORINFO_FIELD_INTRINSIC_ISLITTLEENDIAN, // intrinsic BitConverter.IsLittleEndian } diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/Target_X64/X64ReadyToRunHelperNode.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/Target_X64/X64ReadyToRunHelperNode.cs index 07f713acfb8adc..87a98548ca5875 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/Target_X64/X64ReadyToRunHelperNode.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/Target_X64/X64ReadyToRunHelperNode.cs @@ -274,10 +274,9 @@ private static void EmitInlineTLSAccess(NodeFactory factory, ref X64Emitter enco throw new NotImplementedException(); } - else if (factory.Target.IsWindows) + else { - // For windows, the TLS access will get inlined by ryujit. - // No need to emit any code here. + throw new NotImplementedException(); } } } diff --git a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs index 349f81459cd281..81c5944f467e1c 100644 --- a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs +++ b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs @@ -2147,13 +2147,10 @@ private void getFieldInfo(ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_MET { if (ti.IsInlined) { + fieldAccessor = CORINFO_FIELD_ACCESSOR.CORINFO_FIELD_STATIC_TLS_MANAGED; if (_compilation.HasLazyStaticConstructor(field.OwningType)) { - fieldAccessor = CORINFO_FIELD_ACCESSOR.CORINFO_FIELD_STATIC_TLS_MANAGED_LAZY; - } - else - { - fieldAccessor = CORINFO_FIELD_ACCESSOR.CORINFO_FIELD_STATIC_TLS_MANAGED; + fieldFlags |= CORINFO_FIELD_FLAGS.CORINFO_FLG_FIELD_INITCLASS; } } } From b38a17c3fbc1c28fe227cf3a6e9b60269d01792c Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Mon, 18 Dec 2023 15:33:10 -0800 Subject: [PATCH 42/58] Use the INITCLASS flag --- src/coreclr/jit/importer.cpp | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index e12fd9893f55a8..2ec28f6469cbe6 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -3856,29 +3856,8 @@ GenTree* Compiler::impImportStaticFieldAddress(CORINFO_RESOLVED_TOKEN* pResolved if (pFieldInfo->fieldAccessor == CORINFO_FIELD_STATIC_TLS_MANAGED) { op1->AsCall()->gtInitClsHnd = pResolvedToken->hClass; - - if (pFieldInfo->fieldFlags & CORINFO_FLG_FIELD_INITCLASS) - { - op1->gtFlags |= callFlags; - op1->AsCall()->setEntryPoint(pFieldInfo->fieldLookup); - - // Create a GT_COMMA to invoke the lazyCtor - GenTreeCall* lazyCtorCall = - gtNewHelperCallNode(CORINFO_HELP_READYTORUN_GCSTATIC_BASE, TYP_BYREF); - if (pResolvedToken->hClass == info.compClassHnd && m_preferredInitCctor == CORINFO_HELP_UNDEF) - { - m_preferredInitCctor = pFieldInfo->helper; - } - lazyCtorCall->setEntryPoint(pFieldInfo->fieldLookup); - lazyCtorCall->gtInitClsHnd = pResolvedToken->hClass; - lazyCtorCall->gtFlags |= callFlags; - lazyCtorCall->SetArgNeedsEnclosingType(); - - op1 = gtNewOperNode(GT_COMMA, op1->TypeGet(), gtUnusedValNode(lazyCtorCall), op1); - - op1 = - gtNewOperNode(GT_ADD, op1->TypeGet(), op1, gtNewIconNode(pFieldInfo->offset, innerFldSeq)); - } + op1 = gtNewOperNode(GT_ADD, op1->TypeGet(), op1, gtNewIconNode(pFieldInfo->offset, innerFldSeq)); + m_preferredInitCctor = CORINFO_HELP_READYTORUN_GCSTATIC_BASE; break; } if (pResolvedToken->hClass == info.compClassHnd && m_preferredInitCctor == CORINFO_HELP_UNDEF && @@ -9132,6 +9111,10 @@ void Compiler::impImportBlockCode(BasicBlock* block) if (fieldInfo.fieldFlags & CORINFO_FLG_FIELD_INITCLASS) { GenTree* helperNode = impInitClass(&resolvedToken); + if (fieldInfo.useEnclosingTypeOnly) + { + helperNode->AsCall()->SetArgNeedsEnclosingType(); + } if (compDonotInline()) { return; From 1c1092d04b4da1f8387a6d0c717183c10f4df5ea Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Mon, 18 Dec 2023 20:17:57 -0800 Subject: [PATCH 43/58] Remove useEnclosingTypeOnly --- src/coreclr/inc/corinfo.h | 1 - src/coreclr/jit/gentree.h | 16 ----------- src/coreclr/jit/importer.cpp | 8 ------ src/coreclr/jit/valuenum.cpp | 27 ------------------- .../tools/Common/JitInterface/CorInfoTypes.cs | 3 --- .../JitInterface/CorInfoImpl.RyuJit.cs | 2 -- 6 files changed, 57 deletions(-) diff --git a/src/coreclr/inc/corinfo.h b/src/coreclr/inc/corinfo.h index 0a7400dee32173..83ab2fbdcc418e 100644 --- a/src/coreclr/inc/corinfo.h +++ b/src/coreclr/inc/corinfo.h @@ -1721,7 +1721,6 @@ struct CORINFO_FIELD_INFO CORINFO_HELPER_DESC accessCalloutHelper; CORINFO_CONST_LOOKUP fieldLookup; // Used by Ready-to-Run - bool useEnclosingTypeOnly; // Used by NativeAOT }; //---------------------------------------------------------------------------- diff --git a/src/coreclr/jit/gentree.h b/src/coreclr/jit/gentree.h index 244b1d75acab48..3a22eff38b0d58 100644 --- a/src/coreclr/jit/gentree.h +++ b/src/coreclr/jit/gentree.h @@ -4079,7 +4079,6 @@ enum GenTreeCallFlags : unsigned int GTF_CALL_M_EXPANDED_EARLY = 0x00800000, // the Virtual Call target address is expanded and placed in gtControlExpr in Morph rather than in Lower GTF_CALL_M_HAS_LATE_DEVIRT_INFO = 0x01000000, // this call has late devirtualzation info GTF_CALL_M_LDVIRTFTN_INTERFACE = 0x02000000, // ldvirtftn on an interface type - GTF_CALL_M_ENCLOSING_TYPE_ONLY = 0x04000000, // helper call needs enclosing type as parameter }; inline constexpr GenTreeCallFlags operator ~(GenTreeCallFlags a) @@ -5452,21 +5451,6 @@ struct GenTreeCall final : public GenTree return (gtCallMoreFlags & GTF_CALL_M_EXP_RUNTIME_LOOKUP) != 0; } - void SetArgNeedsEnclosingType() - { - gtCallMoreFlags |= GTF_CALL_M_ENCLOSING_TYPE_ONLY; - } - - void ClearArgNeedsEnclosingType() - { - gtCallMoreFlags &= ~GTF_CALL_M_ENCLOSING_TYPE_ONLY; - } - - bool IsArgNeedsEnclosingType() const - { - return (gtCallMoreFlags & GTF_CALL_M_ENCLOSING_TYPE_ONLY) != 0; - } - void SetExpandedEarly() { gtCallMoreFlags |= GTF_CALL_M_EXPANDED_EARLY; diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index 2ec28f6469cbe6..d56737e7bfd080 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -3871,10 +3871,6 @@ GenTree* Compiler::impImportStaticFieldAddress(CORINFO_RESOLVED_TOKEN* pResolved { // Keep class handle attached to the helper call since it's difficult to restore it. op1->AsCall()->gtInitClsHnd = pResolvedToken->hClass; - if (pFieldInfo->useEnclosingTypeOnly) - { - op1->AsCall()->SetArgNeedsEnclosingType(); - } } op1->gtFlags |= callFlags; @@ -9111,10 +9107,6 @@ void Compiler::impImportBlockCode(BasicBlock* block) if (fieldInfo.fieldFlags & CORINFO_FLG_FIELD_INITCLASS) { GenTree* helperNode = impInitClass(&resolvedToken); - if (fieldInfo.useEnclosingTypeOnly) - { - helperNode->AsCall()->SetArgNeedsEnclosingType(); - } if (compDonotInline()) { return; diff --git a/src/coreclr/jit/valuenum.cpp b/src/coreclr/jit/valuenum.cpp index 5b887677550c67..6d820cb216207b 100644 --- a/src/coreclr/jit/valuenum.cpp +++ b/src/coreclr/jit/valuenum.cpp @@ -12287,7 +12287,6 @@ void Compiler::fgValueNumberHelperCallFunc(GenTreeCall* call, VNFunc vnf, ValueN CallArgs* args = &call->gtArgs; bool generateUniqueVN = false; bool useEntryPointAddrAsArg0 = false; - bool useEnclosingTypeAsArg0 = false; switch (vnf) { @@ -12349,25 +12348,6 @@ void Compiler::fgValueNumberHelperCallFunc(GenTreeCall* call, VNFunc vnf, ValueN case VNF_ReadyToRunStaticBaseGC: case VNF_ReadyToRunStaticBaseNonGC: - { - if (IsTargetAbi(CORINFO_NATIVEAOT_ABI)) - { - if (call->IsArgNeedsEnclosingType()) - { - useEnclosingTypeAsArg0 = true; - assert((call->gtInitClsHnd != NO_CLASS_HANDLE) && ((ssize_t)call->gtInitClsHnd != 0xcccccccc)); - } - else - { - useEntryPointAddrAsArg0 = true; - } - } - else - { - useEntryPointAddrAsArg0 = true; - } - } - break; case VNF_ReadyToRunStaticBaseThread: case VNF_ReadyToRunStaticBaseThreadNonGC: case VNF_ReadyToRunGenericStaticBase: @@ -12413,7 +12393,6 @@ void Compiler::fgValueNumberHelperCallFunc(GenTreeCall* call, VNFunc vnf, ValueN // added this arg, so we do not need to use EntryPointAddrAsArg0 // because the indirection cell itself allows us to disambiguate. useEntryPointAddrAsArg0 = false; - useEnclosingTypeAsArg0 = false; } CallArg* curArg = args->Args().begin().GetArg(); @@ -12440,12 +12419,6 @@ void Compiler::fgValueNumberHelperCallFunc(GenTreeCall* call, VNFunc vnf, ValueN ValueNum callAddrVN = vnStore->VNForHandle(addrValue, GTF_ICON_FTN_ADDR); vnp0 = ValueNumPair(callAddrVN, callAddrVN); } - else if (useEnclosingTypeAsArg0) - { - ssize_t addrValue = (ssize_t)call->gtInitClsHnd; - ValueNum callAddrVN = vnStore->VNForHandle(addrValue, GTF_ICON_FTN_ADDR); - vnp0 = ValueNumPair(callAddrVN, callAddrVN); - } else #endif // FEATURE_READYTORUN { diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs b/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs index 4ba4f8fbde79b5..9a96457b6f7f62 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs @@ -1144,9 +1144,6 @@ public unsafe struct CORINFO_FIELD_INFO // Used by Ready-to-Run public CORINFO_CONST_LOOKUP fieldLookup; - - // Used by NativeAOT - public bool useEnclosingTypeOnly; }; public unsafe struct CORINFO_THREAD_STATIC_BLOCKS_INFO diff --git a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs index 81c5944f467e1c..5df8a0503ebd5f 100644 --- a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs +++ b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs @@ -2051,7 +2051,6 @@ private void getFieldInfo(ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_MET CORINFO_FIELD_ACCESSOR fieldAccessor; CORINFO_FIELD_FLAGS fieldFlags = (CORINFO_FIELD_FLAGS)0; uint fieldOffset = (field.IsStatic && field.HasRva ? 0xBAADF00D : (uint)field.Offset.AsInt); - pResult->useEnclosingTypeOnly = false; if (field.IsThreadStatic && field.OwningType is MetadataType mt) { fieldOffset += _compilation.NodeFactory.ThreadStaticBaseOffset(mt); @@ -2191,7 +2190,6 @@ private void getFieldInfo(ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_MET if (helperId != ReadyToRunHelperId.Invalid) { - pResult->useEnclosingTypeOnly = true; pResult->fieldLookup = CreateConstLookupToSymbol( _compilation.NodeFactory.ReadyToRunHelper(helperId, field.OwningType)); } From 119e2ae3d890376570fc0a31a2c06381b7b02407 Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Mon, 18 Dec 2023 20:44:41 -0800 Subject: [PATCH 44/58] Add NoCtor --- src/coreclr/inc/corinfo.h | 1 + src/coreclr/inc/jithelpers.h | 1 + src/coreclr/jit/compiler.hpp | 1 + src/coreclr/jit/helperexpansion.cpp | 3 +-- src/coreclr/jit/importer.cpp | 4 ++++ src/coreclr/jit/utils.cpp | 1 + src/coreclr/jit/valuenum.cpp | 4 ++++ src/coreclr/jit/valuenumfuncs.h | 1 + src/coreclr/tools/Common/JitInterface/CorInfoHelpFunc.cs | 1 + 9 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/coreclr/inc/corinfo.h b/src/coreclr/inc/corinfo.h index 83ab2fbdcc418e..08d1cd6f6a8fc3 100644 --- a/src/coreclr/inc/corinfo.h +++ b/src/coreclr/inc/corinfo.h @@ -596,6 +596,7 @@ enum CorInfoHelpFunc CORINFO_HELP_READYTORUN_GCSTATIC_BASE, // static gc field access CORINFO_HELP_READYTORUN_NONGCSTATIC_BASE, // static non gc field access CORINFO_HELP_READYTORUN_THREADSTATIC_BASE, + CORINFO_HELP_READYTORUN_THREADSTATIC_BASE_NOCTOR, CORINFO_HELP_READYTORUN_NONGCTHREADSTATIC_BASE, CORINFO_HELP_READYTORUN_VIRTUAL_FUNC_PTR, CORINFO_HELP_READYTORUN_GENERIC_HANDLE, diff --git a/src/coreclr/inc/jithelpers.h b/src/coreclr/inc/jithelpers.h index 06d09a1b5e15ab..a7a90c3adc5016 100644 --- a/src/coreclr/inc/jithelpers.h +++ b/src/coreclr/inc/jithelpers.h @@ -264,6 +264,7 @@ JITHELPER(CORINFO_HELP_READYTORUN_GCSTATIC_BASE, NULL, CORINFO_HELP_SIG_NO_ALIGN_STUB) JITHELPER(CORINFO_HELP_READYTORUN_NONGCSTATIC_BASE, NULL, CORINFO_HELP_SIG_NO_ALIGN_STUB) JITHELPER(CORINFO_HELP_READYTORUN_THREADSTATIC_BASE, NULL, CORINFO_HELP_SIG_NO_ALIGN_STUB) + JITHELPER(CORINFO_HELP_READYTORUN_THREADSTATIC_BASE_NOCTOR, NULL, CORINFO_HELP_SIG_NO_ALIGN_STUB) JITHELPER(CORINFO_HELP_READYTORUN_NONGCTHREADSTATIC_BASE, NULL,CORINFO_HELP_SIG_NO_ALIGN_STUB) JITHELPER(CORINFO_HELP_READYTORUN_VIRTUAL_FUNC_PTR, NULL, CORINFO_HELP_SIG_NO_ALIGN_STUB) JITHELPER(CORINFO_HELP_READYTORUN_GENERIC_HANDLE, NULL, CORINFO_HELP_SIG_NO_ALIGN_STUB) diff --git a/src/coreclr/jit/compiler.hpp b/src/coreclr/jit/compiler.hpp index c954c08dce71ec..34d078b29ab5e9 100644 --- a/src/coreclr/jit/compiler.hpp +++ b/src/coreclr/jit/compiler.hpp @@ -3949,6 +3949,7 @@ inline bool Compiler::IsSharedStaticHelper(GenTree* tree) #ifdef FEATURE_READYTORUN helper == CORINFO_HELP_READYTORUN_GENERIC_STATIC_BASE || helper == CORINFO_HELP_READYTORUN_GCSTATIC_BASE || helper == CORINFO_HELP_READYTORUN_NONGCSTATIC_BASE || helper == CORINFO_HELP_READYTORUN_THREADSTATIC_BASE || + helper == CORINFO_HELP_READYTORUN_THREADSTATIC_BASE_NOCTOR || helper == CORINFO_HELP_READYTORUN_NONGCTHREADSTATIC_BASE || #endif helper == CORINFO_HELP_CLASSINIT_SHARED_DYNAMICCLASS; diff --git a/src/coreclr/jit/helperexpansion.cpp b/src/coreclr/jit/helperexpansion.cpp index 0dd6fdc112cea9..291c2851e8ab2e 100644 --- a/src/coreclr/jit/helperexpansion.cpp +++ b/src/coreclr/jit/helperexpansion.cpp @@ -466,8 +466,7 @@ bool Compiler::fgExpandThreadLocalAccessForCallNativeAOT(BasicBlock** pBlock, St BasicBlock* block = *pBlock; CorInfoHelpFunc helper = call->GetHelperNum(); - bool isExpTLSFieldAccess = (helper == CORINFO_HELP_READYTORUN_THREADSTATIC_BASE) || - (helper == CORINFO_HELP_READYTORUN_NONGCTHREADSTATIC_BASE); + bool isExpTLSFieldAccess = (helper == CORINFO_HELP_READYTORUN_THREADSTATIC_BASE); if (!call->IsHelperCall() || !isExpTLSFieldAccess) { return false; diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index d56737e7bfd080..3d7fdbffb61e6e 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -3856,7 +3856,11 @@ GenTree* Compiler::impImportStaticFieldAddress(CORINFO_RESOLVED_TOKEN* pResolved if (pFieldInfo->fieldAccessor == CORINFO_FIELD_STATIC_TLS_MANAGED) { op1->AsCall()->gtInitClsHnd = pResolvedToken->hClass; + op1->AsCall()->setEntryPoint(pFieldInfo->fieldLookup); + op1->gtFlags |= callFlags; + op1 = gtNewOperNode(GT_ADD, op1->TypeGet(), op1, gtNewIconNode(pFieldInfo->offset, innerFldSeq)); + m_preferredInitCctor = CORINFO_HELP_READYTORUN_GCSTATIC_BASE; break; } diff --git a/src/coreclr/jit/utils.cpp b/src/coreclr/jit/utils.cpp index 50885fb94da722..4b3c9c6a60c86f 100644 --- a/src/coreclr/jit/utils.cpp +++ b/src/coreclr/jit/utils.cpp @@ -1557,6 +1557,7 @@ void HelperCallProperties::init() case CORINFO_HELP_GETSHARED_GCTHREADSTATIC_BASE_NOCTOR_OPTIMIZED: case CORINFO_HELP_GETSHARED_NONGCTHREADSTATIC_BASE_NOCTOR: case CORINFO_HELP_GETSHARED_NONGCTHREADSTATIC_BASE_NOCTOR_OPTIMIZED: + case CORINFO_HELP_READYTORUN_THREADSTATIC_BASE_NOCTOR: // These do not invoke static class constructors // diff --git a/src/coreclr/jit/valuenum.cpp b/src/coreclr/jit/valuenum.cpp index 6d820cb216207b..9318ca55dd656b 100644 --- a/src/coreclr/jit/valuenum.cpp +++ b/src/coreclr/jit/valuenum.cpp @@ -12349,6 +12349,7 @@ void Compiler::fgValueNumberHelperCallFunc(GenTreeCall* call, VNFunc vnf, ValueN case VNF_ReadyToRunStaticBaseGC: case VNF_ReadyToRunStaticBaseNonGC: case VNF_ReadyToRunStaticBaseThread: + case VNF_ReadyToRunStaticBaseThreadNoctor: case VNF_ReadyToRunStaticBaseThreadNonGC: case VNF_ReadyToRunGenericStaticBase: case VNF_ReadyToRunIsInstanceOf: @@ -12736,6 +12737,9 @@ VNFunc Compiler::fgValueNumberJitHelperMethodVNFunc(CorInfoHelpFunc helpFunc) case CORINFO_HELP_READYTORUN_THREADSTATIC_BASE: vnf = VNF_ReadyToRunStaticBaseThread; break; + case CORINFO_HELP_READYTORUN_THREADSTATIC_BASE_NOCTOR: + vnf = VNF_ReadyToRunStaticBaseThreadNoctor; + break; case CORINFO_HELP_READYTORUN_NONGCTHREADSTATIC_BASE: vnf = VNF_ReadyToRunStaticBaseThreadNonGC; break; diff --git a/src/coreclr/jit/valuenumfuncs.h b/src/coreclr/jit/valuenumfuncs.h index f875f3aadaf43d..bb098dca7ab8ce 100644 --- a/src/coreclr/jit/valuenumfuncs.h +++ b/src/coreclr/jit/valuenumfuncs.h @@ -122,6 +122,7 @@ ValueNumFuncDef(GetsharedNongcstaticBaseNoctor, 1, false, true, true, false) ValueNumFuncDef(ReadyToRunStaticBaseGC, 1, false, true, true, false) ValueNumFuncDef(ReadyToRunStaticBaseNonGC, 1, false, true, true, false) ValueNumFuncDef(ReadyToRunStaticBaseThread, 1, false, true, true, false) +ValueNumFuncDef(ReadyToRunStaticBaseThreadNoctor, 1, false, true, true, false) ValueNumFuncDef(ReadyToRunStaticBaseThreadNonGC, 1, false, true, true, false) ValueNumFuncDef(ReadyToRunGenericStaticBase, 2, false, true, true, false) ValueNumFuncDef(GetsharedGcstaticBaseDynamicclass, 2, false, true, true, false) diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoHelpFunc.cs b/src/coreclr/tools/Common/JitInterface/CorInfoHelpFunc.cs index ea5bfafb98bfe9..78d441f583b080 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoHelpFunc.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoHelpFunc.cs @@ -238,6 +238,7 @@ which is the right helper to use to allocate an object of a given type. */ CORINFO_HELP_READYTORUN_GCSTATIC_BASE, CORINFO_HELP_READYTORUN_NONGCSTATIC_BASE, CORINFO_HELP_READYTORUN_THREADSTATIC_BASE, + CORINFO_HELP_READYTORUN_THREADSTATIC_BASE_NOCTOR, CORINFO_HELP_READYTORUN_NONGCTHREADSTATIC_BASE, CORINFO_HELP_READYTORUN_VIRTUAL_FUNC_PTR, CORINFO_HELP_READYTORUN_GENERIC_HANDLE, From 9cfea3990afafa3204edce8c092518959fa6f9e6 Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Mon, 18 Dec 2023 22:02:57 -0800 Subject: [PATCH 45/58] Use CORINFO_HELP_READYTORUN_THREADSTATIC_BASE_NOCTOR --- src/coreclr/jit/gentree.cpp | 12 +++--------- src/coreclr/jit/helperexpansion.cpp | 2 +- src/coreclr/jit/importer.cpp | 7 ++++++- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/coreclr/jit/gentree.cpp b/src/coreclr/jit/gentree.cpp index e114c15c9e16c3..974be388ebfe1d 100644 --- a/src/coreclr/jit/gentree.cpp +++ b/src/coreclr/jit/gentree.cpp @@ -16927,19 +16927,13 @@ void Compiler::gtExtractSideEffList(GenTree* expr, fgWalkResult PreOrderVisit(GenTree** use, GenTree* user) { - GenTree* node = *use; - GenTreeFlags flags = m_flags; + GenTree* node = *use; - if ((user != nullptr) && (user->OperIs(GT_COMMA)) && (user->AsOp()->gtGetOp1() == node)) - { - flags &= ~GTF_IS_IN_CSE; - } - - bool treeHasSideEffects = m_compiler->gtTreeHasSideEffects(node, flags); + bool treeHasSideEffects = m_compiler->gtTreeHasSideEffects(node, m_flags); if (treeHasSideEffects) { - if (m_compiler->gtNodeHasSideEffects(node, flags)) + if (m_compiler->gtNodeHasSideEffects(node, m_flags)) { if (node->OperIsBlk() && !node->OperIsStoreBlk()) { diff --git a/src/coreclr/jit/helperexpansion.cpp b/src/coreclr/jit/helperexpansion.cpp index 291c2851e8ab2e..537383466ef37e 100644 --- a/src/coreclr/jit/helperexpansion.cpp +++ b/src/coreclr/jit/helperexpansion.cpp @@ -466,7 +466,7 @@ bool Compiler::fgExpandThreadLocalAccessForCallNativeAOT(BasicBlock** pBlock, St BasicBlock* block = *pBlock; CorInfoHelpFunc helper = call->GetHelperNum(); - bool isExpTLSFieldAccess = (helper == CORINFO_HELP_READYTORUN_THREADSTATIC_BASE); + bool isExpTLSFieldAccess = (helper == CORINFO_HELP_READYTORUN_THREADSTATIC_BASE_NOCTOR); if (!call->IsHelperCall() || !isExpTLSFieldAccess) { return false; diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index 3d7fdbffb61e6e..cec598cc8787ae 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -3852,9 +3852,11 @@ GenTree* Compiler::impImportStaticFieldAddress(CORINFO_RESOLVED_TOKEN* pResolved callFlags |= GTF_CALL_HOISTABLE; } - op1 = gtNewHelperCallNode(pFieldInfo->helper, TYP_BYREF); if (pFieldInfo->fieldAccessor == CORINFO_FIELD_STATIC_TLS_MANAGED) { + assert(pFieldInfo->helper == CORINFO_HELP_READYTORUN_THREADSTATIC_BASE); + op1 = gtNewHelperCallNode(CORINFO_HELP_READYTORUN_THREADSTATIC_BASE_NOCTOR, TYP_BYREF); + op1->AsCall()->gtInitClsHnd = pResolvedToken->hClass; op1->AsCall()->setEntryPoint(pFieldInfo->fieldLookup); op1->gtFlags |= callFlags; @@ -3864,6 +3866,9 @@ GenTree* Compiler::impImportStaticFieldAddress(CORINFO_RESOLVED_TOKEN* pResolved m_preferredInitCctor = CORINFO_HELP_READYTORUN_GCSTATIC_BASE; break; } + + op1 = gtNewHelperCallNode(pFieldInfo->helper, TYP_BYREF); + if (pResolvedToken->hClass == info.compClassHnd && m_preferredInitCctor == CORINFO_HELP_UNDEF && (pFieldInfo->helper == CORINFO_HELP_READYTORUN_GCSTATIC_BASE || pFieldInfo->helper == CORINFO_HELP_READYTORUN_NONGCSTATIC_BASE)) From 2cc3ca1976f30268960e88c6cf5de2e797860798 Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Tue, 19 Dec 2023 06:25:38 -0800 Subject: [PATCH 46/58] Minor cleanup --- src/coreclr/jit/helperexpansion.cpp | 2 +- src/coreclr/jit/importer.cpp | 1 - .../aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs | 3 ++- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/coreclr/jit/helperexpansion.cpp b/src/coreclr/jit/helperexpansion.cpp index 537383466ef37e..52bc4c0b0b8f5e 100644 --- a/src/coreclr/jit/helperexpansion.cpp +++ b/src/coreclr/jit/helperexpansion.cpp @@ -438,7 +438,7 @@ PhaseStatus Compiler::fgExpandThreadLocalAccess() return result; } - // Always expand for NativeAOT, see + // Always expand for NativeAOT const bool isNativeAOT = IsTargetAbi(CORINFO_NATIVEAOT_ABI); if (!isNativeAOT && opts.OptimizationDisabled()) { diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index cec598cc8787ae..7948925b129b78 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -3868,7 +3868,6 @@ GenTree* Compiler::impImportStaticFieldAddress(CORINFO_RESOLVED_TOKEN* pResolved } op1 = gtNewHelperCallNode(pFieldInfo->helper, TYP_BYREF); - if (pResolvedToken->hClass == info.compClassHnd && m_preferredInitCctor == CORINFO_HELP_UNDEF && (pFieldInfo->helper == CORINFO_HELP_READYTORUN_GCSTATIC_BASE || pFieldInfo->helper == CORINFO_HELP_READYTORUN_NONGCSTATIC_BASE)) diff --git a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs index 5df8a0503ebd5f..38d98ef203d263 100644 --- a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs +++ b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs @@ -2051,6 +2051,7 @@ private void getFieldInfo(ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_MET CORINFO_FIELD_ACCESSOR fieldAccessor; CORINFO_FIELD_FLAGS fieldFlags = (CORINFO_FIELD_FLAGS)0; uint fieldOffset = (field.IsStatic && field.HasRva ? 0xBAADF00D : (uint)field.Offset.AsInt); + if (field.IsThreadStatic && field.OwningType is MetadataType mt) { fieldOffset += _compilation.NodeFactory.ThreadStaticBaseOffset(mt); @@ -2155,8 +2156,8 @@ private void getFieldInfo(ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_MET } } - helperId = ReadyToRunHelperId.GetThreadStaticBase; pResult->helper = CorInfoHelpFunc.CORINFO_HELP_READYTORUN_THREADSTATIC_BASE; + helperId = ReadyToRunHelperId.GetThreadStaticBase; } else if (!_compilation.HasLazyStaticConstructor(field.OwningType)) { From 59085d264b6edbccf28ce6067426d35144dfbb92 Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Wed, 3 Jan 2024 12:08:32 -0800 Subject: [PATCH 47/58] Renegenrate thunk --- .../JitInterface/CorInfoImpl_generated.cs | 155 +++++++++--------- 1 file changed, 78 insertions(+), 77 deletions(-) diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs b/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs index b5a57c126dd572..0db8ace5e1d482 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs @@ -2551,7 +2551,7 @@ private static uint _getJitFlags(IntPtr thisHandle, IntPtr* ppException, CORJIT_ private static IntPtr GetUnmanagedCallbacks() { - void** callbacks = (void**)Marshal.AllocCoTaskMem(sizeof(IntPtr) * 171); + void** callbacks = (void**)Marshal.AllocCoTaskMem(sizeof(IntPtr) * 172); callbacks[0] = (delegate* unmanaged)&_isIntrinsic; callbacks[1] = (delegate* unmanaged)&_notifyMethodInfoUsage; @@ -2648,82 +2648,83 @@ private static IntPtr GetUnmanagedCallbacks() callbacks[92] = (delegate* unmanaged)&_getFieldOffset; callbacks[93] = (delegate* unmanaged)&_getFieldInfo; callbacks[94] = (delegate* unmanaged)&_getThreadLocalFieldInfo; - callbacks[95] = (delegate* unmanaged)&_getThreadLocalStaticInfo_NativeAOT; - callbacks[96] = (delegate* unmanaged)&_isFieldStatic; - callbacks[97] = (delegate* unmanaged)&_getArrayOrStringLength; - callbacks[98] = (delegate* unmanaged)&_getBoundaries; - callbacks[99] = (delegate* unmanaged)&_setBoundaries; - callbacks[100] = (delegate* unmanaged)&_getVars; - callbacks[101] = (delegate* unmanaged)&_setVars; - callbacks[102] = (delegate* unmanaged)&_reportRichMappings; - callbacks[103] = (delegate* unmanaged)&_allocateArray; - callbacks[104] = (delegate* unmanaged)&_freeArray; - callbacks[105] = (delegate* unmanaged)&_getArgNext; - callbacks[106] = (delegate* unmanaged)&_getArgType; - callbacks[107] = (delegate* unmanaged)&_getExactClasses; - callbacks[108] = (delegate* unmanaged)&_getArgClass; - callbacks[109] = (delegate* unmanaged)&_getHFAType; - callbacks[110] = (delegate* unmanaged)&_runWithErrorTrap; - callbacks[111] = (delegate* unmanaged)&_runWithSPMIErrorTrap; - callbacks[112] = (delegate* unmanaged)&_getEEInfo; - callbacks[113] = (delegate* unmanaged)&_getJitTimeLogFilename; - callbacks[114] = (delegate* unmanaged)&_getMethodDefFromMethod; - callbacks[115] = (delegate* unmanaged)&_printMethodName; - callbacks[116] = (delegate* unmanaged)&_getMethodNameFromMetadata; - callbacks[117] = (delegate* unmanaged)&_getMethodHash; - callbacks[118] = (delegate* unmanaged)&_getSystemVAmd64PassStructInRegisterDescriptor; - callbacks[119] = (delegate* unmanaged)&_getLoongArch64PassStructInRegisterFlags; - callbacks[120] = (delegate* unmanaged)&_getRISCV64PassStructInRegisterFlags; - callbacks[121] = (delegate* unmanaged)&_getThreadTLSIndex; - callbacks[122] = (delegate* unmanaged)&_getAddrOfCaptureThreadGlobal; - callbacks[123] = (delegate* unmanaged)&_getHelperFtn; - callbacks[124] = (delegate* unmanaged)&_getFunctionEntryPoint; - callbacks[125] = (delegate* unmanaged)&_getFunctionFixedEntryPoint; - callbacks[126] = (delegate* unmanaged)&_getMethodSync; - callbacks[127] = (delegate* unmanaged)&_getLazyStringLiteralHelper; - callbacks[128] = (delegate* unmanaged)&_embedModuleHandle; - callbacks[129] = (delegate* unmanaged)&_embedClassHandle; - callbacks[130] = (delegate* unmanaged)&_embedMethodHandle; - callbacks[131] = (delegate* unmanaged)&_embedFieldHandle; - callbacks[132] = (delegate* unmanaged)&_embedGenericHandle; - callbacks[133] = (delegate* unmanaged)&_getLocationOfThisType; - callbacks[134] = (delegate* unmanaged)&_getAddressOfPInvokeTarget; - callbacks[135] = (delegate* unmanaged)&_GetCookieForPInvokeCalliSig; - callbacks[136] = (delegate* unmanaged)&_canGetCookieForPInvokeCalliSig; - callbacks[137] = (delegate* unmanaged)&_getJustMyCodeHandle; - callbacks[138] = (delegate* unmanaged)&_GetProfilingHandle; - callbacks[139] = (delegate* unmanaged)&_getCallInfo; - callbacks[140] = (delegate* unmanaged)&_getClassDomainID; - callbacks[141] = (delegate* unmanaged)&_getStaticFieldContent; - callbacks[142] = (delegate* unmanaged)&_getObjectContent; - callbacks[143] = (delegate* unmanaged)&_getStaticFieldCurrentClass; - callbacks[144] = (delegate* unmanaged)&_getVarArgsHandle; - callbacks[145] = (delegate* unmanaged)&_canGetVarArgsHandle; - callbacks[146] = (delegate* unmanaged)&_constructStringLiteral; - callbacks[147] = (delegate* unmanaged)&_emptyStringLiteral; - callbacks[148] = (delegate* unmanaged)&_getFieldThreadLocalStoreID; - callbacks[149] = (delegate* unmanaged)&_GetDelegateCtor; - callbacks[150] = (delegate* unmanaged)&_MethodCompileComplete; - callbacks[151] = (delegate* unmanaged)&_getTailCallHelpers; - callbacks[152] = (delegate* unmanaged)&_convertPInvokeCalliToCall; - callbacks[153] = (delegate* unmanaged)&_notifyInstructionSetUsage; - callbacks[154] = (delegate* unmanaged)&_updateEntryPointForTailCall; - callbacks[155] = (delegate* unmanaged)&_allocMem; - callbacks[156] = (delegate* unmanaged)&_reserveUnwindInfo; - callbacks[157] = (delegate* unmanaged)&_allocUnwindInfo; - callbacks[158] = (delegate* unmanaged)&_allocGCInfo; - callbacks[159] = (delegate* unmanaged)&_setEHcount; - callbacks[160] = (delegate* unmanaged)&_setEHinfo; - callbacks[161] = (delegate* unmanaged)&_logMsg; - callbacks[162] = (delegate* unmanaged)&_doAssert; - callbacks[163] = (delegate* unmanaged)&_reportFatalError; - callbacks[164] = (delegate* unmanaged)&_getPgoInstrumentationResults; - callbacks[165] = (delegate* unmanaged)&_allocPgoInstrumentationBySchema; - callbacks[166] = (delegate* unmanaged)&_recordCallSite; - callbacks[167] = (delegate* unmanaged)&_recordRelocation; - callbacks[168] = (delegate* unmanaged)&_getRelocTypeHint; - callbacks[169] = (delegate* unmanaged)&_getExpectedTargetArchitecture; - callbacks[170] = (delegate* unmanaged)&_getJitFlags; + callbacks[95] = (delegate* unmanaged)&_getThreadLocalStaticBlocksInfo; + callbacks[96] = (delegate* unmanaged)&_getThreadLocalStaticInfo_NativeAOT; + callbacks[97] = (delegate* unmanaged)&_isFieldStatic; + callbacks[98] = (delegate* unmanaged)&_getArrayOrStringLength; + callbacks[99] = (delegate* unmanaged)&_getBoundaries; + callbacks[100] = (delegate* unmanaged)&_setBoundaries; + callbacks[101] = (delegate* unmanaged)&_getVars; + callbacks[102] = (delegate* unmanaged)&_setVars; + callbacks[103] = (delegate* unmanaged)&_reportRichMappings; + callbacks[104] = (delegate* unmanaged)&_allocateArray; + callbacks[105] = (delegate* unmanaged)&_freeArray; + callbacks[106] = (delegate* unmanaged)&_getArgNext; + callbacks[107] = (delegate* unmanaged)&_getArgType; + callbacks[108] = (delegate* unmanaged)&_getExactClasses; + callbacks[109] = (delegate* unmanaged)&_getArgClass; + callbacks[110] = (delegate* unmanaged)&_getHFAType; + callbacks[111] = (delegate* unmanaged)&_runWithErrorTrap; + callbacks[112] = (delegate* unmanaged)&_runWithSPMIErrorTrap; + callbacks[113] = (delegate* unmanaged)&_getEEInfo; + callbacks[114] = (delegate* unmanaged)&_getJitTimeLogFilename; + callbacks[115] = (delegate* unmanaged)&_getMethodDefFromMethod; + callbacks[116] = (delegate* unmanaged)&_printMethodName; + callbacks[117] = (delegate* unmanaged)&_getMethodNameFromMetadata; + callbacks[118] = (delegate* unmanaged)&_getMethodHash; + callbacks[119] = (delegate* unmanaged)&_getSystemVAmd64PassStructInRegisterDescriptor; + callbacks[120] = (delegate* unmanaged)&_getLoongArch64PassStructInRegisterFlags; + callbacks[121] = (delegate* unmanaged)&_getRISCV64PassStructInRegisterFlags; + callbacks[122] = (delegate* unmanaged)&_getThreadTLSIndex; + callbacks[123] = (delegate* unmanaged)&_getAddrOfCaptureThreadGlobal; + callbacks[124] = (delegate* unmanaged)&_getHelperFtn; + callbacks[125] = (delegate* unmanaged)&_getFunctionEntryPoint; + callbacks[126] = (delegate* unmanaged)&_getFunctionFixedEntryPoint; + callbacks[127] = (delegate* unmanaged)&_getMethodSync; + callbacks[128] = (delegate* unmanaged)&_getLazyStringLiteralHelper; + callbacks[129] = (delegate* unmanaged)&_embedModuleHandle; + callbacks[130] = (delegate* unmanaged)&_embedClassHandle; + callbacks[131] = (delegate* unmanaged)&_embedMethodHandle; + callbacks[132] = (delegate* unmanaged)&_embedFieldHandle; + callbacks[133] = (delegate* unmanaged)&_embedGenericHandle; + callbacks[134] = (delegate* unmanaged)&_getLocationOfThisType; + callbacks[135] = (delegate* unmanaged)&_getAddressOfPInvokeTarget; + callbacks[136] = (delegate* unmanaged)&_GetCookieForPInvokeCalliSig; + callbacks[137] = (delegate* unmanaged)&_canGetCookieForPInvokeCalliSig; + callbacks[138] = (delegate* unmanaged)&_getJustMyCodeHandle; + callbacks[139] = (delegate* unmanaged)&_GetProfilingHandle; + callbacks[140] = (delegate* unmanaged)&_getCallInfo; + callbacks[141] = (delegate* unmanaged)&_getClassDomainID; + callbacks[142] = (delegate* unmanaged)&_getStaticFieldContent; + callbacks[143] = (delegate* unmanaged)&_getObjectContent; + callbacks[144] = (delegate* unmanaged)&_getStaticFieldCurrentClass; + callbacks[145] = (delegate* unmanaged)&_getVarArgsHandle; + callbacks[146] = (delegate* unmanaged)&_canGetVarArgsHandle; + callbacks[147] = (delegate* unmanaged)&_constructStringLiteral; + callbacks[148] = (delegate* unmanaged)&_emptyStringLiteral; + callbacks[149] = (delegate* unmanaged)&_getFieldThreadLocalStoreID; + callbacks[150] = (delegate* unmanaged)&_GetDelegateCtor; + callbacks[151] = (delegate* unmanaged)&_MethodCompileComplete; + callbacks[152] = (delegate* unmanaged)&_getTailCallHelpers; + callbacks[153] = (delegate* unmanaged)&_convertPInvokeCalliToCall; + callbacks[154] = (delegate* unmanaged)&_notifyInstructionSetUsage; + callbacks[155] = (delegate* unmanaged)&_updateEntryPointForTailCall; + callbacks[156] = (delegate* unmanaged)&_allocMem; + callbacks[157] = (delegate* unmanaged)&_reserveUnwindInfo; + callbacks[158] = (delegate* unmanaged)&_allocUnwindInfo; + callbacks[159] = (delegate* unmanaged)&_allocGCInfo; + callbacks[160] = (delegate* unmanaged)&_setEHcount; + callbacks[161] = (delegate* unmanaged)&_setEHinfo; + callbacks[162] = (delegate* unmanaged)&_logMsg; + callbacks[163] = (delegate* unmanaged)&_doAssert; + callbacks[164] = (delegate* unmanaged)&_reportFatalError; + callbacks[165] = (delegate* unmanaged)&_getPgoInstrumentationResults; + callbacks[166] = (delegate* unmanaged)&_allocPgoInstrumentationBySchema; + callbacks[167] = (delegate* unmanaged)&_recordCallSite; + callbacks[168] = (delegate* unmanaged)&_recordRelocation; + callbacks[169] = (delegate* unmanaged)&_getRelocTypeHint; + callbacks[170] = (delegate* unmanaged)&_getExpectedTargetArchitecture; + callbacks[171] = (delegate* unmanaged)&_getJitFlags; return (IntPtr)callbacks; } From fa1059f307765ca6d4605374cf5f069173eed01b Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Wed, 3 Jan 2024 22:56:28 -0800 Subject: [PATCH 48/58] Add the SetFalseTarget --- src/coreclr/jit/helperexpansion.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/coreclr/jit/helperexpansion.cpp b/src/coreclr/jit/helperexpansion.cpp index 1de8cb72f1dd2b..494ac25d158073 100644 --- a/src/coreclr/jit/helperexpansion.cpp +++ b/src/coreclr/jit/helperexpansion.cpp @@ -608,6 +608,7 @@ bool Compiler::fgExpandThreadLocalAccessForCallNativeAOT(BasicBlock** pBlock, St fgAddRefPred(block, fastPathBb); tlsRootNullCondBB->SetTrueTarget(fastPathBb); + tlsRootNullCondBB->SetFalseTarget(fallbackBb); // Inherit the weights block->inheritWeight(prevBb); From 0069167ef1e4c32bca20601066ebf6baa1e1dd6b Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Wed, 10 Jan 2024 12:20:53 -0800 Subject: [PATCH 49/58] fix merge conflict resolution --- src/coreclr/jit/emit.h | 2 +- .../tools/Common/Compiler/DependencyAnalysis/Relocation.cs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/coreclr/jit/emit.h b/src/coreclr/jit/emit.h index 70e4730cda7cd1..ff03b1ad407183 100644 --- a/src/coreclr/jit/emit.h +++ b/src/coreclr/jit/emit.h @@ -1021,7 +1021,6 @@ class emitter { return iiaJmpOffset; } - bool isSecRel; #elif defined(TARGET_RISCV64) struct @@ -1041,6 +1040,7 @@ class emitter } #endif // defined(TARGET_RISCV64) + bool isSecRel; } _idAddrUnion; diff --git a/src/coreclr/tools/Common/Compiler/DependencyAnalysis/Relocation.cs b/src/coreclr/tools/Common/Compiler/DependencyAnalysis/Relocation.cs index b5711f08ce3d8e..bbe1ce26784b8e 100644 --- a/src/coreclr/tools/Common/Compiler/DependencyAnalysis/Relocation.cs +++ b/src/coreclr/tools/Common/Compiler/DependencyAnalysis/Relocation.cs @@ -475,7 +475,6 @@ public static unsafe void WriteValue(RelocType relocType, void* location, long v case RelocType.IMAGE_REL_TPOFF: case RelocType.IMAGE_REL_SYMBOL_SIZE: case RelocType.IMAGE_REL_FILE_ABSOLUTE: - case RelocType.IMAGE_REL_SECREL: *(int*)location = (int)value; break; case RelocType.IMAGE_REL_BASED_DIR64: From 38bca3b7ce6b4bcb44d3bed791082d86472d80af Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Wed, 10 Jan 2024 12:22:58 -0800 Subject: [PATCH 50/58] better handling of GTF_ICON_SECREL_OFFSET better handling of GTF_ICON_SECREL_OFFSET --- src/coreclr/jit/codegenxarch.cpp | 16 ++++++++++++---- src/coreclr/jit/helperexpansion.cpp | 1 + src/coreclr/jit/instr.h | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/coreclr/jit/codegenxarch.cpp b/src/coreclr/jit/codegenxarch.cpp index b5208ad8876bb3..8230c1f676e4fc 100644 --- a/src/coreclr/jit/codegenxarch.cpp +++ b/src/coreclr/jit/codegenxarch.cpp @@ -410,10 +410,18 @@ void CodeGen::instGen_Set_Reg_To_Imm(emitAttr size, // Only use lea if the original was relocatable. Otherwise we can get spurious // instruction selection due to different memory placement at runtime. if (EA_IS_RELOC(origAttr) && genDataIndirAddrCanBeEncodedAsPCRelOffset(imm)) - { - // We will use lea so displacement and not immediate will be relocatable - size = EA_SET_FLG(EA_REMOVE_FLG(size, EA_CNS_RELOC_FLG), EA_DSP_RELOC_FLG); - GetEmitter()->emitIns_R_AI(INS_lea, size, reg, imm DEBUGARG(targetHandle) DEBUGARG(gtFlags)); + { + if (!EA_IS_CNS_SEC_RELOC(origAttr)) + { + // We will use lea so displacement and not immediate will be relocatable + size = EA_SET_FLG(EA_REMOVE_FLG(size, EA_CNS_RELOC_FLG), EA_DSP_RELOC_FLG); + GetEmitter()->emitIns_R_AI(INS_lea, size, reg, imm DEBUGARG(targetHandle) DEBUGARG(gtFlags)); + } + else + { + // For section constant, the immediate will be relocatable + GetEmitter()->emitIns_R_I(INS_mov, size, reg, imm DEBUGARG(targetHandle) DEBUGARG(gtFlags)); + } } else { diff --git a/src/coreclr/jit/helperexpansion.cpp b/src/coreclr/jit/helperexpansion.cpp index 494ac25d158073..2f3f37fc680a97 100644 --- a/src/coreclr/jit/helperexpansion.cpp +++ b/src/coreclr/jit/helperexpansion.cpp @@ -553,6 +553,7 @@ bool Compiler::fgExpandThreadLocalAccessForCallNativeAOT(BasicBlock** pBlock, St CORINFO_CONST_LOOKUP tlsRootObject = threadStaticInfo.tlsRootObject; + // This resolves to an offset which is TYP_INT GenTree* tlsRootOffset = gtNewIconNode((size_t)tlsRootObject.handle, TYP_INT); tlsRootOffset->gtFlags |= GTF_ICON_SECREL_OFFSET; diff --git a/src/coreclr/jit/instr.h b/src/coreclr/jit/instr.h index 5842772d04384c..ab78b5ee851a32 100644 --- a/src/coreclr/jit/instr.h +++ b/src/coreclr/jit/instr.h @@ -492,7 +492,7 @@ enum emitAttr : unsigned #define EA_IS_DSP_RELOC(x) ((((unsigned)(x)) & ((unsigned)EA_DSP_RELOC_FLG)) != 0) #define EA_IS_CNS_RELOC(x) ((((unsigned)(x)) & ((unsigned)EA_CNS_RELOC_FLG)) != 0) #define EA_IS_CNS_SEC_RELOC(x) ((((unsigned)(x)) & ((unsigned)EA_CNS_SEC_RELOC)) != 0) -#define EA_IS_RELOC(x) ((EA_IS_DSP_RELOC(x) || EA_IS_CNS_RELOC(x)) && !EA_IS_CNS_SEC_RELOC(x)) +#define EA_IS_RELOC(x) (EA_IS_DSP_RELOC(x) || EA_IS_CNS_RELOC(x)) #define EA_TYPE(x) ((emitAttr)(((unsigned)(x)) & ~(EA_OFFSET_FLG | EA_DSP_RELOC_FLG | EA_CNS_RELOC_FLG))) // clang-format on From a5fcc59bdb4035d56d5fb5794ead89dfd4eb92ed Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Wed, 10 Jan 2024 14:07:43 -0800 Subject: [PATCH 51/58] review feedback --- src/coreclr/jit/gentree.cpp | 5 +++++ src/coreclr/jit/helperexpansion.cpp | 22 ++++++++++++++++++---- src/coreclr/jit/instr.h | 2 +- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/coreclr/jit/gentree.cpp b/src/coreclr/jit/gentree.cpp index 0e1f86701138ea..720196c3626642 100644 --- a/src/coreclr/jit/gentree.cpp +++ b/src/coreclr/jit/gentree.cpp @@ -10770,6 +10770,8 @@ const char* GenTree::gtGetHandleKindString(GenTreeFlags flags) return "GTF_ICON_FIELD_SEQ"; case GTF_ICON_STATIC_ADDR_PTR: return "GTF_ICON_STATIC_ADDR_PTR"; + case GTF_ICON_SECREL_OFFSET: + return "GTF_ICON_SECREL_OFFSET"; default: return "ILLEGAL!"; } @@ -11999,6 +12001,9 @@ void Compiler::gtDispConst(GenTree* tree) case GTF_ICON_STATIC_ADDR_PTR: printf(" static base addr cell"); break; + case GTF_ICON_SECREL_OFFSET: + printf(" relative offset in section"); + break; default: printf(" UNKNOWN"); break; diff --git a/src/coreclr/jit/helperexpansion.cpp b/src/coreclr/jit/helperexpansion.cpp index 2f3f37fc680a97..e8a3350927a665 100644 --- a/src/coreclr/jit/helperexpansion.cpp +++ b/src/coreclr/jit/helperexpansion.cpp @@ -464,13 +464,27 @@ PhaseStatus Compiler::fgExpandThreadLocalAccess() : fgExpandHelper<&Compiler::fgExpandThreadLocalAccessForCall>(true); } +//------------------------------------------------------------------------------ +// fgExpandThreadLocalAccessForCallNativeAOT : Expand the access of tlsRoot needed +// to access fields marked with [ThreadLocal]. +// +// Arguments: +// pBlock - Block containing the helper call to expand. If expansion is performed, +// this is updated to the new block that was an outcome of block splitting. +// stmt - Statement containing the helper call +// call - The helper call +// +// +// Returns: +// true if we expanded any field access, false otherwise. +// bool Compiler::fgExpandThreadLocalAccessForCallNativeAOT(BasicBlock** pBlock, Statement* stmt, GenTreeCall* call) { assert(IsTargetAbi(CORINFO_NATIVEAOT_ABI)); BasicBlock* block = *pBlock; CorInfoHelpFunc helper = call->GetHelperNum(); - bool isExpTLSFieldAccess = (helper == CORINFO_HELP_READYTORUN_THREADSTATIC_BASE_NOCTOR); + const bool isExpTLSFieldAccess = (helper == CORINFO_HELP_READYTORUN_THREADSTATIC_BASE_NOCTOR); if (!call->IsHelperCall() || !isExpTLSFieldAccess) { return false; @@ -639,7 +653,7 @@ bool Compiler::fgExpandThreadLocalAccessForCallNativeAOT(BasicBlock** pBlock, St JITDUMP("fallbackBb: " FMT_BB "\n", fallbackBb->bbNum); JITDUMP("fastPathBb: " FMT_BB "\n", fastPathBb->bbNum); #else - assert(!"Unsupported scenario\n"); + unreached(); #endif // TARGET_64BIT @@ -647,7 +661,7 @@ bool Compiler::fgExpandThreadLocalAccessForCallNativeAOT(BasicBlock** pBlock, St } else { - assert(!"Unsupported scenario\n"); + unreached(); } return false; } @@ -664,7 +678,7 @@ bool Compiler::fgExpandThreadLocalAccessForCallNativeAOT(BasicBlock** pBlock, St // // // Returns: -// PhaseStatus indicating what, if anything, was changed. +// true if we expanded any field access, false otherwise. // // Notes: // A cache is stored in thread local storage (TLS) of coreclr. It maps the typeIndex (embedded in diff --git a/src/coreclr/jit/instr.h b/src/coreclr/jit/instr.h index ab78b5ee851a32..ffaa2af6c2d90e 100644 --- a/src/coreclr/jit/instr.h +++ b/src/coreclr/jit/instr.h @@ -491,7 +491,7 @@ enum emitAttr : unsigned #define EA_IS_GCREF_OR_BYREF(x) ((((unsigned)(x)) & ((unsigned)(EA_BYREF_FLG | EA_GCREF_FLG))) != 0) #define EA_IS_DSP_RELOC(x) ((((unsigned)(x)) & ((unsigned)EA_DSP_RELOC_FLG)) != 0) #define EA_IS_CNS_RELOC(x) ((((unsigned)(x)) & ((unsigned)EA_CNS_RELOC_FLG)) != 0) -#define EA_IS_CNS_SEC_RELOC(x) ((((unsigned)(x)) & ((unsigned)EA_CNS_SEC_RELOC)) != 0) +#define EA_IS_CNS_SEC_RELOC(x) ((((unsigned)(x)) & ((unsigned)EA_CNS_SEC_RELOC)) != 0) #define EA_IS_RELOC(x) (EA_IS_DSP_RELOC(x) || EA_IS_CNS_RELOC(x)) #define EA_TYPE(x) ((emitAttr)(((unsigned)(x)) & ~(EA_OFFSET_FLG | EA_DSP_RELOC_FLG | EA_CNS_RELOC_FLG))) From ceda4782b7beb70fb53f6bfc9f5abb448b0cb2a9 Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Wed, 10 Jan 2024 18:16:28 -0800 Subject: [PATCH 52/58] Disable optimization for minopts --- src/coreclr/jit/helperexpansion.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/jit/helperexpansion.cpp b/src/coreclr/jit/helperexpansion.cpp index e8a3350927a665..3bed7a00e56d71 100644 --- a/src/coreclr/jit/helperexpansion.cpp +++ b/src/coreclr/jit/helperexpansion.cpp @@ -444,7 +444,7 @@ PhaseStatus Compiler::fgExpandThreadLocalAccess() // Always expand for NativeAOT const bool isNativeAOT = IsTargetAbi(CORINFO_NATIVEAOT_ABI); - if (!isNativeAOT && opts.OptimizationDisabled()) + if (opts.OptimizationDisabled()) { JITDUMP("Optimizations aren't allowed - bail out.\n") return result; From aba00e23109a18b72df772b7e25e2675780a268d Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Wed, 10 Jan 2024 18:17:23 -0800 Subject: [PATCH 53/58] Add comments around iiaSecRel --- src/coreclr/jit/emit.h | 3 ++- src/coreclr/jit/emitxarch.cpp | 8 +++++--- src/coreclr/jit/instr.h | 2 +- .../ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs | 2 +- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/coreclr/jit/emit.h b/src/coreclr/jit/emit.h index ff03b1ad407183..4cee26ed618e3a 100644 --- a/src/coreclr/jit/emit.h +++ b/src/coreclr/jit/emit.h @@ -1040,7 +1040,8 @@ class emitter } #endif // defined(TARGET_RISCV64) - bool isSecRel; + // Used for instrDesc that has relocatable immediate offset + bool iiaSecRel; } _idAddrUnion; diff --git a/src/coreclr/jit/emitxarch.cpp b/src/coreclr/jit/emitxarch.cpp index cac818361f84b4..2a294ec3516a9c 100644 --- a/src/coreclr/jit/emitxarch.cpp +++ b/src/coreclr/jit/emitxarch.cpp @@ -5712,9 +5712,10 @@ void emitter::emitIns_R_I(instruction ins, id->idDebugOnlyInfo()->idMemCookie = targetHandle; #endif - if (emitComp->opts.IsReadyToRun() && EA_IS_CNS_SEC_RELOC(attr)) + if (emitComp->IsTargetAbi(CORINFO_NATIVEAOT_ABI) && EA_IS_CNS_SEC_RELOC(attr)) { - id->idAddr()->isSecRel = true; + assert(!id->idIsSmallDsc()); + id->idAddr()->iiaSecRel = true; } if (isSimdInsAndValInByte) @@ -15103,8 +15104,9 @@ BYTE* emitter::emitOutputRI(BYTE* dst, instrDesc* id) if (id->idIsCnsReloc()) { - if (emitComp->opts.IsReadyToRun() && id->idAddr()->isSecRel) + if (emitComp->IsTargetAbi(CORINFO_NATIVEAOT_ABI) && id->idAddr()->iiaSecRel) { + // For section relative, the immediate offset is relocatable and hence need IMAGE_REL_SECREL emitRecordRelocation((void*)(dst - (unsigned)EA_SIZE(size)), (void*)(size_t)val, IMAGE_REL_SECREL); } else diff --git a/src/coreclr/jit/instr.h b/src/coreclr/jit/instr.h index ffaa2af6c2d90e..85c7c2cf54fa5b 100644 --- a/src/coreclr/jit/instr.h +++ b/src/coreclr/jit/instr.h @@ -474,7 +474,7 @@ enum emitAttr : unsigned EA_BYREF = EA_BYREF_FLG | EA_PTRSIZE, /* size == -2 */ EA_DSP_RELOC_FLG = 0x400, // Is the displacement of the instruction relocatable? EA_CNS_RELOC_FLG = 0x800, // Is the immediate of the instruction relocatable? - EA_CNS_SEC_RELOC = 0x1000, + EA_CNS_SEC_RELOC = 0x1000, // Is the offset immediate that should be relocatable }; #define EA_ATTR(x) ((emitAttr)(x)) diff --git a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs index c9953301c9f6d8..b00f3f00a47372 100644 --- a/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs +++ b/src/coreclr/tools/aot/ILCompiler.RyuJit/JitInterface/CorInfoImpl.RyuJit.cs @@ -2407,7 +2407,7 @@ private bool getStaticBaseAddress(CORINFO_CLASS_STRUCT_* cls, bool isGc, ref COR private void getThreadLocalStaticInfo_NativeAOT(CORINFO_THREAD_STATIC_INFO_NATIVEAOT* pInfo) { - pInfo->offsetOfThreadLocalStoragePointer = (uint)(11 * PointerSize); // 0x58 = 0n88 + pInfo->offsetOfThreadLocalStoragePointer = (uint)(11 * PointerSize); // Offset of ThreadLocalStoragePointer in the TEB pInfo->tlsIndexObject = CreateConstLookupToSymbol(_compilation.NodeFactory.ExternSymbol("_tls_index")); pInfo->tlsRootObject = CreateConstLookupToSymbol(_compilation.NodeFactory.TlsRoot); pInfo->threadStaticBaseSlow = CreateConstLookupToSymbol(_compilation.NodeFactory.HelperEntrypoint(HelperEntrypoint.GetInlinedThreadStaticBaseSlow)); From 24f88a0abd46665562deb40bead8e1a14193982a Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Wed, 10 Jan 2024 18:23:50 -0800 Subject: [PATCH 54/58] jit format --- src/coreclr/jit/codegenxarch.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coreclr/jit/codegenxarch.cpp b/src/coreclr/jit/codegenxarch.cpp index 8230c1f676e4fc..c202ff594f2063 100644 --- a/src/coreclr/jit/codegenxarch.cpp +++ b/src/coreclr/jit/codegenxarch.cpp @@ -410,12 +410,12 @@ void CodeGen::instGen_Set_Reg_To_Imm(emitAttr size, // Only use lea if the original was relocatable. Otherwise we can get spurious // instruction selection due to different memory placement at runtime. if (EA_IS_RELOC(origAttr) && genDataIndirAddrCanBeEncodedAsPCRelOffset(imm)) - { + { if (!EA_IS_CNS_SEC_RELOC(origAttr)) { // We will use lea so displacement and not immediate will be relocatable size = EA_SET_FLG(EA_REMOVE_FLG(size, EA_CNS_RELOC_FLG), EA_DSP_RELOC_FLG); - GetEmitter()->emitIns_R_AI(INS_lea, size, reg, imm DEBUGARG(targetHandle) DEBUGARG(gtFlags)); + GetEmitter()->emitIns_R_AI(INS_lea, size, reg, imm DEBUGARG(targetHandle) DEBUGARG(gtFlags)); } else { From 65f3900691e19b92b5611ac215c517d1dee909f8 Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Wed, 10 Jan 2024 22:24:47 -0800 Subject: [PATCH 55/58] create emitNewInstrCns() --- src/coreclr/jit/emitxarch.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/coreclr/jit/emitxarch.cpp b/src/coreclr/jit/emitxarch.cpp index 2a294ec3516a9c..9bcb574578cc6e 100644 --- a/src/coreclr/jit/emitxarch.cpp +++ b/src/coreclr/jit/emitxarch.cpp @@ -5702,7 +5702,15 @@ void emitter::emitIns_R_I(instruction ins, break; } - id = emitNewInstrSC(attr, val); + if (emitComp->IsTargetAbi(CORINFO_NATIVEAOT_ABI) && EA_IS_CNS_SEC_RELOC(attr)) + { + id = emitNewInstrCns(attr, val); + id->idAddr()->iiaSecRel = true; + } + else + { + id = emitNewInstrSC(attr, val); + } id->idIns(ins); id->idInsFmt(fmt); id->idReg1(reg); @@ -5712,12 +5720,6 @@ void emitter::emitIns_R_I(instruction ins, id->idDebugOnlyInfo()->idMemCookie = targetHandle; #endif - if (emitComp->IsTargetAbi(CORINFO_NATIVEAOT_ABI) && EA_IS_CNS_SEC_RELOC(attr)) - { - assert(!id->idIsSmallDsc()); - id->idAddr()->iiaSecRel = true; - } - if (isSimdInsAndValInByte) { bool includeRexPrefixSize = true; From 5bc0a1a9ac7ce5ba9e382e6201da3477135a2e78 Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Thu, 11 Jan 2024 17:01:35 -0800 Subject: [PATCH 56/58] Expand TLS even if optimization is disabled --- src/coreclr/jit/helperexpansion.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coreclr/jit/helperexpansion.cpp b/src/coreclr/jit/helperexpansion.cpp index 3bed7a00e56d71..d233e50786a892 100644 --- a/src/coreclr/jit/helperexpansion.cpp +++ b/src/coreclr/jit/helperexpansion.cpp @@ -442,9 +442,9 @@ PhaseStatus Compiler::fgExpandThreadLocalAccess() return result; } - // Always expand for NativeAOT + // Always expand for NativeAOT because the TLS access will not be generated by NativeAOT const bool isNativeAOT = IsTargetAbi(CORINFO_NATIVEAOT_ABI); - if (opts.OptimizationDisabled()) + if (!isNativeAOT && opts.OptimizationDisabled()) { JITDUMP("Optimizations aren't allowed - bail out.\n") return result; From 959869a0e67d3f17a9f53c45a1f1c5f60d5ff7b1 Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Fri, 12 Jan 2024 15:36:34 -0800 Subject: [PATCH 57/58] Track t_inlinedThreadStaticBase Better tracking `t_inlinedThreadStaticBase` as TYP_REF --- src/coreclr/jit/helperexpansion.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/coreclr/jit/helperexpansion.cpp b/src/coreclr/jit/helperexpansion.cpp index d233e50786a892..d9f88d62b04b9a 100644 --- a/src/coreclr/jit/helperexpansion.cpp +++ b/src/coreclr/jit/helperexpansion.cpp @@ -515,7 +515,9 @@ bool Compiler::fgExpandThreadLocalAccessForCallNativeAOT(BasicBlock** pBlock, St assert(prevBb != nullptr && block != nullptr); unsigned finalLclNum = lvaGrabTemp(true DEBUGARG("Final offset")); - lvaTable[finalLclNum].lvType = TYP_I_IMPL; + // Note, `tlsRoot` refers to the TLS blob object, which is an unpinned managed object, + // thus the type of the local is TYP_REF + lvaTable[finalLclNum].lvType = TYP_REF; GenTree* finalLcl = gtNewLclVarNode(finalLclNum); // Block ops inserted by the split need to be morphed here since we are after morph. @@ -580,7 +582,8 @@ bool Compiler::fgExpandThreadLocalAccessForCallNativeAOT(BasicBlock** pBlock, St GenTree* tlsRootAddrDef = gtNewStoreLclVarNode(tlsRootAddrLclNum, tlsRootAddr); GenTree* tlsRootAddrUse = gtNewLclVarNode(tlsRootAddrLclNum); - GenTree* tlsRootVal = gtNewIndir(TYP_I_IMPL, tlsRootAddrUse, GTF_IND_NONFAULTING | GTF_IND_INVARIANT); + // See comments near finalLclNum above regarding TYP_REF + GenTree* tlsRootVal = gtNewIndir(TYP_REF, tlsRootAddrUse, GTF_IND_NONFAULTING | GTF_IND_INVARIANT); GenTree* tlsRootDef = gtNewStoreLclVarNode(finalLclNum, tlsRootVal); @@ -594,8 +597,9 @@ bool Compiler::fgExpandThreadLocalAccessForCallNativeAOT(BasicBlock** pBlock, St CORINFO_CONST_LOOKUP threadStaticSlowHelper = threadStaticInfo.threadStaticBaseSlow; + // See comments near finalLclNum above regarding TYP_REF GenTreeCall* slowHelper = - gtNewIndCallNode(gtNewIconHandleNode((size_t)threadStaticSlowHelper.addr, GTF_ICON_TLS_HDL), TYP_I_IMPL); + gtNewIndCallNode(gtNewIconHandleNode((size_t)threadStaticSlowHelper.addr, GTF_ICON_TLS_HDL), TYP_REF); GenTree* helperArg = gtClone(tlsRootAddrUse); slowHelper->gtArgs.PushBack(this, NewCallArg::Primitive(helperArg)); fgMorphArgs(slowHelper); From bff4728f781772c6f790e7ab45ea5e65fc91ed84 Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Fri, 12 Jan 2024 17:09:55 -0800 Subject: [PATCH 58/58] jit format --- src/coreclr/jit/helperexpansion.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/jit/helperexpansion.cpp b/src/coreclr/jit/helperexpansion.cpp index d9f88d62b04b9a..0aec6e7cd38fd4 100644 --- a/src/coreclr/jit/helperexpansion.cpp +++ b/src/coreclr/jit/helperexpansion.cpp @@ -514,7 +514,7 @@ bool Compiler::fgExpandThreadLocalAccessForCallNativeAOT(BasicBlock** pBlock, St var_types callType = call->TypeGet(); assert(prevBb != nullptr && block != nullptr); - unsigned finalLclNum = lvaGrabTemp(true DEBUGARG("Final offset")); + unsigned finalLclNum = lvaGrabTemp(true DEBUGARG("Final offset")); // Note, `tlsRoot` refers to the TLS blob object, which is an unpinned managed object, // thus the type of the local is TYP_REF lvaTable[finalLclNum].lvType = TYP_REF;