From 31448be25207356ae51553b2fc03fc9fd7a2dd3d Mon Sep 17 00:00:00 2001 From: David Wrighton Date: Thu, 12 Jun 2025 13:26:23 -0700 Subject: [PATCH 1/4] getHelperFtn support for getting CORINFO_METHOD_HANDLE - If there is one associated, we will get the method handle. This is an optional parameter, as is the logic to get the existing result. - This will be used in the interpreter to generate different bytecode that knows about calling managed methods when needed - There is also some prior interest from the JIT team about using such an api, but it didn't quite get in. See PR #110267. This PR takes the comment from @jkotas into account to adjust the signature of the method to be something which is simpler and easier to understand --- src/coreclr/inc/corinfo.h | 7 +- src/coreclr/inc/icorjitinfoimpl_generated.h | 5 +- src/coreclr/inc/jiteeversionguid.h | 10 +-- src/coreclr/interpreter/compiler.cpp | 17 +++-- .../jit/ICorJitInfo_wrapper_generated.hpp | 8 +-- src/coreclr/jit/codegenarm.cpp | 11 ++- src/coreclr/jit/codegenarm64.cpp | 18 +++-- src/coreclr/jit/codegenarmarch.cpp | 6 +- src/coreclr/jit/codegencommon.cpp | 3 +- src/coreclr/jit/codegenloongarch64.cpp | 55 ++++++++++----- src/coreclr/jit/codegenriscv64.cpp | 50 ++++++++++---- src/coreclr/jit/codegenxarch.cpp | 20 ++++-- src/coreclr/jit/compiler.cpp | 14 ++-- src/coreclr/jit/compiler.h | 3 +- src/coreclr/jit/importer.cpp | 3 +- src/coreclr/jit/lower.cpp | 19 +----- .../tools/Common/JitInterface/CorInfoImpl.cs | 37 ++++++---- .../JitInterface/CorInfoImpl_generated.cs | 7 +- .../ThunkGenerator/ThunkInput.txt | 19 +++--- .../aot/jitinterface/jitinterface_generated.h | 10 +-- .../tools/superpmi/superpmi-shared/agnostic.h | 6 ++ .../superpmi-shared/compileresult.cpp | 4 +- .../tools/superpmi/superpmi-shared/lwmlist.h | 2 +- .../superpmi-shared/methodcontext.cpp | 37 ++++++---- .../superpmi/superpmi-shared/methodcontext.h | 9 +-- .../superpmi-shim-collector/icorjitinfo.cpp | 17 +++-- .../icorjitinfo_generated.cpp | 7 +- .../icorjitinfo_generated.cpp | 7 +- .../tools/superpmi/superpmi/icorjitinfo.cpp | 4 +- src/coreclr/vm/jitinterface.cpp | 68 +++++++++++++------ src/coreclr/vm/jitinterface.h | 5 +- 31 files changed, 304 insertions(+), 184 deletions(-) diff --git a/src/coreclr/inc/corinfo.h b/src/coreclr/inc/corinfo.h index 2309db3383ecc3..6b42672c953894 100644 --- a/src/coreclr/inc/corinfo.h +++ b/src/coreclr/inc/corinfo.h @@ -3100,10 +3100,11 @@ class ICorDynamicInfo : public ICorStaticInfo void **ppIndirection = NULL ) = 0; - // return the native entry point to an EE helper (see CorInfoHelpFunc) - virtual void* getHelperFtn ( + // return the native entry point and/or managed method of an EE helper (see CorInfoHelpFunc) + virtual void getHelperFtn ( CorInfoHelpFunc ftnNum, - void **ppIndirection = NULL + CORINFO_CONST_LOOKUP * pNativeEntrypoint, + CORINFO_METHOD_HANDLE * pMethodHandle = NULL /* OUT */ ) = 0; // return a callable address of the function (native code). This function diff --git a/src/coreclr/inc/icorjitinfoimpl_generated.h b/src/coreclr/inc/icorjitinfoimpl_generated.h index 73e330058f9d2d..06ae3497691b8f 100644 --- a/src/coreclr/inc/icorjitinfoimpl_generated.h +++ b/src/coreclr/inc/icorjitinfoimpl_generated.h @@ -535,9 +535,10 @@ uint32_t getThreadTLSIndex( int32_t* getAddrOfCaptureThreadGlobal( void** ppIndirection) override; -void* getHelperFtn( +void getHelperFtn( CorInfoHelpFunc ftnNum, - void** ppIndirection) override; + CORINFO_CONST_LOOKUP* pNativeEntrypoint, + CORINFO_METHOD_HANDLE* pMethod) override; void getFunctionEntryPoint( CORINFO_METHOD_HANDLE ftn, diff --git a/src/coreclr/inc/jiteeversionguid.h b/src/coreclr/inc/jiteeversionguid.h index 736504aa9d126a..38a900d0178d00 100644 --- a/src/coreclr/inc/jiteeversionguid.h +++ b/src/coreclr/inc/jiteeversionguid.h @@ -37,11 +37,11 @@ #include -constexpr GUID JITEEVersionIdentifier = { /* ecc9bc7e-9223-4af6-af2f-b63e89c09279 */ - 0xecc9bc7e, - 0x9223, - 0x4af6, - {0xaf, 0x2f, 0xb6, 0x3e, 0x89, 0xc0, 0x92, 0x79} +constexpr GUID JITEEVersionIdentifier = { /* 2004006b-bdff-4357-8e60-3ae950a4f165 */ + 0x2004006b, + 0xbdff, + 0x4357, + {0x8e, 0x60, 0x3a, 0xe9, 0x50, 0xa4, 0xf1, 0x65} }; #endif // JIT_EE_VERSIONING_GUID_H diff --git a/src/coreclr/interpreter/compiler.cpp b/src/coreclr/interpreter/compiler.cpp index 5f6b789b696519..f1837dabeb0bc3 100644 --- a/src/coreclr/interpreter/compiler.cpp +++ b/src/coreclr/interpreter/compiler.cpp @@ -2123,13 +2123,16 @@ int32_t InterpCompiler::GetMethodDataItemIndex(CORINFO_METHOD_HANDLE mHandle) int32_t InterpCompiler::GetDataItemIndexForHelperFtn(CorInfoHelpFunc ftn) { // Interpreter-TODO: Find an existing data item index for this helper if possible and reuse it - void *indirect; - void *direct = m_compHnd->getHelperFtn(ftn, &indirect); - size_t data = !direct - ? (size_t)indirect | INTERP_INDIRECT_HELPER_TAG - : (size_t)direct; - assert(data); - return GetDataItemIndex((void*)data); + CORINFO_CONST_LOOKUP ftnLookup; + m_compHnd->getHelperFtn(ftn, &ftnLookup); + void* addr = ftnLookup.addr; + if (ftnLookup.accessType == IAT_PVALUE) + { + addr = (void*)((size_t)addr | INTERP_INDIRECT_HELPER_TAG); + } + assert(ftnLookup.accessType == IAT_VALUE || ftnLookup.accessType == IAT_PVALUE); + + return GetDataItemIndex(addr); } bool InterpCompiler::EmitCallIntrinsics(CORINFO_METHOD_HANDLE method, CORINFO_SIG_INFO sig) diff --git a/src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp b/src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp index bcc31380d5ce14..fef62e38179314 100644 --- a/src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp +++ b/src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp @@ -1269,14 +1269,14 @@ int32_t* WrapICorJitInfo::getAddrOfCaptureThreadGlobal( return temp; } -void* WrapICorJitInfo::getHelperFtn( +void WrapICorJitInfo::getHelperFtn( CorInfoHelpFunc ftnNum, - void** ppIndirection) + CORINFO_CONST_LOOKUP* pNativeEntrypoint, + CORINFO_METHOD_HANDLE* pMethod) { API_ENTER(getHelperFtn); - void* temp = wrapHnd->getHelperFtn(ftnNum, ppIndirection); + wrapHnd->getHelperFtn(ftnNum, pNativeEntrypoint, pMethod); API_LEAVE(getHelperFtn); - return temp; } void WrapICorJitInfo::getFunctionEntryPoint( diff --git a/src/coreclr/jit/codegenarm.cpp b/src/coreclr/jit/codegenarm.cpp index 7e9df15ff4fea5..0a7f9b21d9eeab 100644 --- a/src/coreclr/jit/codegenarm.cpp +++ b/src/coreclr/jit/codegenarm.cpp @@ -1616,7 +1616,16 @@ void CodeGen::genEmitHelperCall(unsigned helper, int argSize, emitAttr retSize, else #endif { - addr = compiler->compGetHelperFtn((CorInfoHelpFunc)helper, (void**)&pAddr); + CORINFO_CONST_LOOKUP helperFunction = compiler->compGetHelperFtn((CorInfoHelpFunc)helper); + if (helperFunction.accessType == IAT_VALUE) + { + addr = helperFunction.addr; + } + else + { + assert(helperFunction.accessType == IAT_PVALUE); + pAddr = (void**)helperFunction.addr; + } } EmitCallParams params; diff --git a/src/coreclr/jit/codegenarm64.cpp b/src/coreclr/jit/codegenarm64.cpp index 1ba4369e342368..7ea58ce666c4dc 100644 --- a/src/coreclr/jit/codegenarm64.cpp +++ b/src/coreclr/jit/codegenarm64.cpp @@ -5134,15 +5134,23 @@ bool CodeGen::IsSaveFpLrWithAllCalleeSavedRegisters() const void CodeGen::genEmitHelperCall(unsigned helper, int argSize, emitAttr retSize, regNumber callTargetReg /*= REG_NA */) { - void* pAddr = nullptr; - EmitCallParams params; - params.callType = EC_FUNC_TOKEN; - params.addr = compiler->compGetHelperFtn((CorInfoHelpFunc)helper, &pAddr); + + CORINFO_CONST_LOOKUP helperFunction = compiler->compGetHelperFtn((CorInfoHelpFunc)helper); regMaskTP killSet = compiler->compHelperCallKillSet((CorInfoHelpFunc)helper); - if (params.addr == nullptr) + params.callType = EC_FUNC_TOKEN; + + if (helperFunction.accessType == IAT_VALUE) { + params.addr = (void*)helperFunction.addr; + } + else + { + params.addr = nullptr; + assert(helperFunction.accessType == IAT_PVALUE); + void* pAddr = helperFunction.addr; + // This is call to a runtime helper. // adrp x, [reloc:rel page addr] // add x, x, [reloc:page offset] diff --git a/src/coreclr/jit/codegenarmarch.cpp b/src/coreclr/jit/codegenarmarch.cpp index 58275619194d22..b1a83a1687a06a 100644 --- a/src/coreclr/jit/codegenarmarch.cpp +++ b/src/coreclr/jit/codegenarmarch.cpp @@ -3452,9 +3452,9 @@ void CodeGen::genCallInstruction(GenTreeCall* call) CorInfoHelpFunc helperNum = compiler->eeGetHelperNum(params.methHnd); noway_assert(helperNum != CORINFO_HELP_UNDEF); - void* pAddr = nullptr; - params.addr = compiler->compGetHelperFtn(helperNum, (void**)&pAddr); - assert(pAddr == nullptr); + CORINFO_CONST_LOOKUP helperLookup = compiler->compGetHelperFtn(helperNum); + params.addr = helperLookup.addr; + assert(helperLookup.accessType == IAT_VALUE); } else { diff --git a/src/coreclr/jit/codegencommon.cpp b/src/coreclr/jit/codegencommon.cpp index 8fc6ccce7adf7f..22ec04909917e9 100644 --- a/src/coreclr/jit/codegencommon.cpp +++ b/src/coreclr/jit/codegencommon.cpp @@ -1764,10 +1764,9 @@ void CodeGen::genGenerateCode(void** codePtr, uint32_t* nativeSizeOfCode) // if (genWriteBarrierUsed && JitConfig.EnableExtraSuperPmiQueries() && !compiler->IsAot()) { - void* ignored; for (int i = CORINFO_HELP_ASSIGN_REF; i <= CORINFO_HELP_BULK_WRITEBARRIER; i++) { - compiler->compGetHelperFtn((CorInfoHelpFunc)i, &ignored); + compiler->compGetHelperFtn((CorInfoHelpFunc)i); } } #endif diff --git a/src/coreclr/jit/codegenloongarch64.cpp b/src/coreclr/jit/codegenloongarch64.cpp index cc488deb7023fc..5807ed26081ef1 100644 --- a/src/coreclr/jit/codegenloongarch64.cpp +++ b/src/coreclr/jit/codegenloongarch64.cpp @@ -2688,11 +2688,18 @@ void CodeGen::genCodeForReturnTrap(GenTreeOp* tree) EmitCallParams params; - void* pAddr = nullptr; - params.addr = compiler->compGetHelperFtn(CORINFO_HELP_STOP_FOR_GC, &pAddr); - - if (params.addr == nullptr) + CORINFO_CONST_LOOKUP helperFunction = compiler->compGetHelperFtn(CORINFO_HELP_STOP_FOR_GC); + if (helperFunction.accessType == IAT_VALUE) { + // If the helper is a value, we need to use the address of the helper. + params.addr = helperFunction.addr; + } + else + { + params.addr = nullptr; + assert(helperFunction.accessType == IAT_PVALUE); + void* pAddr = helperFunction.addr; + params.callType = EC_INDIR_R; params.ireg = REG_DEFAULT_HELPER_CALL_TARGET; @@ -3758,15 +3765,23 @@ int CodeGenInterface::genCallerSPtoInitialSPdelta() const void CodeGen::genEmitHelperCall(unsigned helper, int argSize, emitAttr retSize, regNumber callTargetReg /*= REG_NA */) { - void* pAddr = nullptr; - EmitCallParams params; - params.callType = EC_FUNC_TOKEN; - params.addr = compiler->compGetHelperFtn((CorInfoHelpFunc)helper, &pAddr); + + CORINFO_CONST_LOOKUP helperFunction = compiler->compGetHelperFtn((CorInfoHelpFunc)helper); regMaskTP killSet = compiler->compHelperCallKillSet((CorInfoHelpFunc)helper); - if (params.addr == nullptr) + params.callType = EC_FUNC_TOKEN; + + if (helperFunction.accessType == IAT_VALUE) { + params.addr = (void*)helperFunction.addr; + } + else + { + params.addr = nullptr; + assert(helperFunction.accessType == IAT_PVALUE); + void* pAddr = helperFunction.addr; + // This is call to a runtime helper. // li reg, pAddr #NOTE: this maybe multi-instructions. // ld_d reg, reg @@ -5793,9 +5808,9 @@ void CodeGen::genCallInstruction(GenTreeCall* call) CorInfoHelpFunc helperNum = compiler->eeGetHelperNum(params.methHnd); noway_assert(helperNum != CORINFO_HELP_UNDEF); - void* pAddr = nullptr; - params.addr = compiler->compGetHelperFtn(helperNum, (void**)&pAddr); - assert(pAddr == nullptr); + CORINFO_CONST_LOOKUP helperLookup = compiler->compGetHelperFtn(helperNum); + params.addr = helperLookup.addr; + assert(helperLookup.accessType == IAT_VALUE); } else { @@ -6483,10 +6498,8 @@ inline void CodeGen::genJumpToThrowHlpBlk_la( // The code to throw the exception will be generated inline, and // we will jump around it in the normal non-exception case. - void* pAddr = nullptr; EmitCallParams params; - params.addr = compiler->compGetHelperFtn((CorInfoHelpFunc)(compiler->acdHelper(codeKind)), &pAddr); - + // maybe optimize // ins = (instruction)(ins^((ins != INS_beq)+(ins != INS_bne))); if (ins == INS_blt) @@ -6510,8 +6523,18 @@ inline void CodeGen::genJumpToThrowHlpBlk_la( ins = ins == INS_beq ? INS_bne : INS_beq; } - if (params.addr == nullptr) + CORINFO_CONST_LOOKUP helperFunction = compiler->compGetHelperFtn((CorInfoHelpFunc)(compiler->acdHelper(codeKind))); + if (helperFunction.accessType == IAT_VALUE) { + // If the helper is a value, we need to use the address of the helper. + params.addr = helperFunction.addr; + } + else + { + params.addr = nullptr; + assert(helperFunction.accessType == IAT_PVALUE); + void* pAddr = helperFunction.addr; + params.callType = EC_INDIR_R; params.ireg = REG_DEFAULT_HELPER_CALL_TARGET; diff --git a/src/coreclr/jit/codegenriscv64.cpp b/src/coreclr/jit/codegenriscv64.cpp index 680b18213f9aeb..4707ca49d0fa31 100644 --- a/src/coreclr/jit/codegenriscv64.cpp +++ b/src/coreclr/jit/codegenriscv64.cpp @@ -2712,11 +2712,15 @@ void CodeGen::genCodeForReturnTrap(GenTreeOp* tree) EmitCallParams params; - void* pAddr = nullptr; - params.addr = compiler->compGetHelperFtn(CORINFO_HELP_STOP_FOR_GC, &pAddr); - - if (params.addr == nullptr) + CORINFO_CONST_LOOKUP helperFunction = compiler->compGetHelperFtn(CORINFO_HELP_STOP_FOR_GC); + if (helperFunction.accessType == IAT_VALUE) { + // If the helper is a value, we need to use the address of the helper. + params.addr = helperFunction.addr; + } + else + { + params.addr = nullptr; params.callType = EC_INDIR_R; params.ireg = REG_DEFAULT_HELPER_CALL_TARGET; @@ -3614,15 +3618,23 @@ static void emitLoadConstAtAddr(emitter* emit, regNumber dstRegister, ssize_t im void CodeGen::genEmitHelperCall(unsigned helper, int argSize, emitAttr retSize, regNumber callTargetReg /*= REG_NA */) { - void* pAddr = nullptr; - EmitCallParams params; - params.callType = EC_FUNC_TOKEN; - params.addr = compiler->compGetHelperFtn((CorInfoHelpFunc)helper, &pAddr); + + CORINFO_CONST_LOOKUP helperFunction = compiler->compGetHelperFtn((CorInfoHelpFunc)helper); regMaskTP killSet = compiler->compHelperCallKillSet((CorInfoHelpFunc)helper); - if (params.addr == nullptr) + params.callType = EC_FUNC_TOKEN; + + if (helperFunction.accessType == IAT_VALUE) { + params.addr = (void*)helperFunction.addr; + } + else + { + params.addr = nullptr; + assert(helperFunction.accessType == IAT_PVALUE); + void* pAddr = helperFunction.addr; + // This is call to a runtime helper. // lui reg, pAddr #NOTE: this maybe multi-instructions. // ld reg, reg @@ -5872,9 +5884,9 @@ void CodeGen::genCallInstruction(GenTreeCall* call) CorInfoHelpFunc helperNum = compiler->eeGetHelperNum(params.methHnd); noway_assert(helperNum != CORINFO_HELP_UNDEF); - void* pAddr = nullptr; - params.addr = compiler->compGetHelperFtn(helperNum, (void**)&pAddr); - assert(pAddr == nullptr); + CORINFO_CONST_LOOKUP helperLookup = compiler->compGetHelperFtn(helperNum); + params.addr = helperLookup.addr; + assert(helperLookup.accessType == IAT_VALUE); } else { @@ -6495,9 +6507,7 @@ void CodeGen::genJumpToThrowHlpBlk_la( // The code to throw the exception will be generated inline, and // we will jump around it in the normal non-exception case. - void* pAddr = nullptr; EmitCallParams params; - params.addr = compiler->compGetHelperFtn((CorInfoHelpFunc)(compiler->acdHelper(codeKind)), &pAddr); // maybe optimize // ins = (instruction)(ins^((ins != INS_beq)+(ins != INS_bne))); @@ -6522,8 +6532,18 @@ void CodeGen::genJumpToThrowHlpBlk_la( ins = ins == INS_beq ? INS_bne : INS_beq; } - if (params.addr == nullptr) + CORINFO_CONST_LOOKUP helperFunction = compiler->compGetHelperFtn((CorInfoHelpFunc)(compiler->acdHelper(codeKind))); + if (helperFunction.accessType == IAT_VALUE) { + // If the helper is a value, we need to use the address of the helper. + params.addr = helperFunction.addr; + } + else + { + params.addr = nullptr; + assert(helperFunction.accessType == IAT_PVALUE); + void* pAddr = helperFunction.addr; + params.callType = EC_INDIR_R; params.ireg = REG_DEFAULT_HELPER_CALL_TARGET; if (compiler->opts.compReloc) diff --git a/src/coreclr/jit/codegenxarch.cpp b/src/coreclr/jit/codegenxarch.cpp index 4b3d13059e977c..543460a7211091 100644 --- a/src/coreclr/jit/codegenxarch.cpp +++ b/src/coreclr/jit/codegenxarch.cpp @@ -6504,9 +6504,9 @@ void CodeGen::genCallInstruction(GenTreeCall* call X86_ARG(target_ssize_t stackA CorInfoHelpFunc helperNum = compiler->eeGetHelperNum(params.methHnd); noway_assert(helperNum != CORINFO_HELP_UNDEF); - void* pAddr = nullptr; - addr = compiler->compGetHelperFtn(helperNum, (void**)&pAddr); - assert(pAddr == nullptr); + CORINFO_CONST_LOOKUP helperLookup = compiler->compGetHelperFtn(helperNum); + addr = helperLookup.addr; + assert(helperLookup.accessType == IAT_VALUE); } else { @@ -8832,15 +8832,21 @@ void CodeGen::genCreateAndStoreGCInfoX64(unsigned codeSize, unsigned prologSize void CodeGen::genEmitHelperCall(unsigned helper, int argSize, emitAttr retSize, regNumber callTargetReg) { - void* pAddr = nullptr; - EmitCallParams params; params.callType = EC_FUNC_TOKEN; - params.addr = compiler->compGetHelperFtn((CorInfoHelpFunc)helper, &pAddr); + + CORINFO_CONST_LOOKUP helperFunction = compiler->compGetHelperFtn((CorInfoHelpFunc)helper); regMaskTP killMask = compiler->compHelperCallKillSet((CorInfoHelpFunc)helper); - if (params.addr == nullptr) + if (helperFunction.accessType == IAT_VALUE) + { + params.addr = (void*)helperFunction.addr; + } + else { + params.addr = nullptr; + assert(helperFunction.accessType == IAT_PVALUE); + void* pAddr = helperFunction.addr; assert(pAddr != nullptr); // Absolute indirect call addr diff --git a/src/coreclr/jit/compiler.cpp b/src/coreclr/jit/compiler.cpp index 2c2f199102209e..7f3f30bfadd70d 100644 --- a/src/coreclr/jit/compiler.cpp +++ b/src/coreclr/jit/compiler.cpp @@ -1666,22 +1666,24 @@ void Compiler::compDone() #endif // LATE_DISASM } -void* Compiler::compGetHelperFtn(CorInfoHelpFunc ftnNum, /* IN */ - void** ppIndirection) /* OUT */ +CORINFO_CONST_LOOKUP Compiler::compGetHelperFtn(CorInfoHelpFunc ftnNum) { - void* addr; + CORINFO_CONST_LOOKUP lookup; if (info.compMatchedVM) { - addr = info.compCompHnd->getHelperFtn(ftnNum, ppIndirection); + info.compCompHnd->getHelperFtn(ftnNum, &lookup); + // The JIT only expects these two possible access types + assert(lookup.accessType == IAT_VALUE || lookup.accessType == IAT_PVALUE); } else { // If we don't have a matched VM, we won't get valid results when asking for a helper function. - addr = (void*)(uintptr_t)(0xCA11CA11); // "callcall" + lookup.addr = (void*)(uintptr_t)(0xCA11CA11); // "callcall" + lookup.accessType = IAT_VALUE; } - return addr; + return lookup; } unsigned Compiler::compGetTypeSize(CorInfoType cit, CORINFO_CLASS_HANDLE clsHnd) diff --git a/src/coreclr/jit/compiler.h b/src/coreclr/jit/compiler.h index 83b7288075f6f4..5ea130635b4e5c 100644 --- a/src/coreclr/jit/compiler.h +++ b/src/coreclr/jit/compiler.h @@ -10898,8 +10898,7 @@ class Compiler //------------ Some utility functions -------------- - void* compGetHelperFtn(CorInfoHelpFunc ftnNum, /* IN */ - void** ppIndirection); /* OUT */ + CORINFO_CONST_LOOKUP compGetHelperFtn(CorInfoHelpFunc ftnNum); // Several JIT/EE interface functions return a CorInfoType, and also return a // class handle as an out parameter if the type is a value class. Returns the diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index 191939105b0d6b..5b91fcd6df3a6a 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -9999,8 +9999,7 @@ void Compiler::impImportBlockCode(BasicBlock* block) typGetObjLayout(elemClsHnd); info.compCompHnd->isValueClass(elemClsHnd); } - void* pIndirection; - info.compCompHnd->getHelperFtn(CORINFO_HELP_MEMZERO, &pIndirection); + compGetHelperFtn(CORINFO_HELP_MEMZERO); } #endif } diff --git a/src/coreclr/jit/lower.cpp b/src/coreclr/jit/lower.cpp index d27dec517ada88..95b6bf1e681368 100644 --- a/src/coreclr/jit/lower.cpp +++ b/src/coreclr/jit/lower.cpp @@ -6113,22 +6113,9 @@ GenTree* Lowering::LowerDirectCall(GenTreeCall* call) { noway_assert(helperNum != CORINFO_HELP_UNDEF); - // the convention on getHelperFtn seems to be (it's not documented) - // that it returns an address or if it returns null, pAddr is set to - // another address, which requires an indirection - void* pAddr; - addr = comp->info.compCompHnd->getHelperFtn(helperNum, (void**)&pAddr); - - if (addr != nullptr) - { - assert(pAddr == nullptr); - accessType = IAT_VALUE; - } - else - { - accessType = IAT_PVALUE; - addr = pAddr; - } + CORINFO_CONST_LOOKUP addrInfo = comp->compGetHelperFtn(helperNum); + addr = addrInfo.addr; + accessType = addrInfo.accessType; } else { diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs index d4fd37a6b56034..34bfa91ca528fe 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs @@ -3538,23 +3538,30 @@ private uint getThreadTLSIndex(ref void* ppIndirection) { throw new NotImplementedException("getThreadTLSIndex"); } private Dictionary _helperCache = new Dictionary(); - private void* getHelperFtn(CorInfoHelpFunc ftnNum, ref void* ppIndirection) + private void getHelperFtn(CorInfoHelpFunc ftnNum, CORINFO_CONST_LOOKUP *pNativeEntrypoint, CORINFO_METHOD_STRUCT_** pMethod) { - ISymbolNode entryPoint; - if (!_helperCache.TryGetValue(ftnNum, out entryPoint)) - { - entryPoint = GetHelperFtnUncached(ftnNum); - _helperCache.Add(ftnNum, entryPoint); - } - if (entryPoint.RepresentsIndirectionCell) - { - ppIndirection = (void*)ObjectToHandle(entryPoint); - return null; - } - else + // We never return a method handle from the managed implementation of this method today + if (pMethod != null) + *pMethod = null; + + if (pNativeEntrypoint != null) { - ppIndirection = null; - return (void*)ObjectToHandle(entryPoint); + ISymbolNode entryPoint; + if (!_helperCache.TryGetValue(ftnNum, out entryPoint)) + { + entryPoint = GetHelperFtnUncached(ftnNum); + _helperCache.Add(ftnNum, entryPoint); + } + if (entryPoint.RepresentsIndirectionCell) + { + pNativeEntrypoint->addr = (void*)ObjectToHandle(entryPoint); + pNativeEntrypoint->accessType = InfoAccessType.IAT_PVALUE; + } + else + { + pNativeEntrypoint->addr = (void*)ObjectToHandle(entryPoint); + pNativeEntrypoint->accessType = InfoAccessType.IAT_VALUE; + } } } diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs b/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs index 8b1a6f5d8d0442..852de22e4b0a38 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs @@ -1917,17 +1917,16 @@ private static uint _getThreadTLSIndex(IntPtr thisHandle, IntPtr* ppException, v } [UnmanagedCallersOnly] - private static void* _getHelperFtn(IntPtr thisHandle, IntPtr* ppException, CorInfoHelpFunc ftnNum, void** ppIndirection) + private static void _getHelperFtn(IntPtr thisHandle, IntPtr* ppException, CorInfoHelpFunc ftnNum, CORINFO_CONST_LOOKUP* pNativeEntrypoint, CORINFO_METHOD_STRUCT_** pMethod) { var _this = GetThis(thisHandle); try { - return _this.getHelperFtn(ftnNum, ref *ppIndirection); + _this.getHelperFtn(ftnNum, pNativeEntrypoint, pMethod); } catch (Exception ex) { *ppException = _this.AllocException(ex); - return default; } } @@ -2768,7 +2767,7 @@ private static IntPtr GetUnmanagedCallbacks() callbacks[126] = (delegate* unmanaged)&_getFpStructLowering; callbacks[127] = (delegate* unmanaged)&_getThreadTLSIndex; callbacks[128] = (delegate* unmanaged)&_getAddrOfCaptureThreadGlobal; - callbacks[129] = (delegate* unmanaged)&_getHelperFtn; + callbacks[129] = (delegate* unmanaged)&_getHelperFtn; callbacks[130] = (delegate* unmanaged)&_getFunctionEntryPoint; callbacks[131] = (delegate* unmanaged)&_getFunctionFixedEntryPoint; callbacks[132] = (delegate* unmanaged)&_getMethodSync; diff --git a/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt b/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt index 6030b745b013e4..fe68b70a2b0dbc 100644 --- a/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt +++ b/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt @@ -73,7 +73,8 @@ const wchar_t*,String uint32_t**,ref uint* unsigned*,ref uint CORJIT_FLAGS*,ref CORJIT_FLAGS -CORINFO_CONST_LOOKUP*,ref CORINFO_CONST_LOOKUP +REF_CORINFO_CONST_LOOKUP,ref CORINFO_CONST_LOOKUP,CORINFO_CONST_LOOKUP*,CORINFO_CONST_LOOKUP* +CORINFO_CONST_LOOKUP* CORINFO_LOOKUP*,ref CORINFO_LOOKUP CORINFO_LOOKUP_KIND*,ref CORINFO_LOOKUP_KIND CORINFO_EH_CLAUSE*,ref CORINFO_EH_CLAUSE @@ -212,10 +213,10 @@ FUNCTIONS const char* getClassAssemblyName(CORINFO_CLASS_HANDLE cls) void* LongLifetimeMalloc(size_t sz) void LongLifetimeFree(void* obj) - bool getIsClassInitedFlagAddress(CORINFO_CLASS_HANDLE cls, CORINFO_CONST_LOOKUP* addr, int* offset) + bool getIsClassInitedFlagAddress(CORINFO_CLASS_HANDLE cls, REF_CORINFO_CONST_LOOKUP addr, int* offset) size_t getClassThreadStaticDynamicInfo(CORINFO_CLASS_HANDLE clr) size_t getClassStaticDynamicInfo(CORINFO_CLASS_HANDLE clr) - bool getStaticBaseAddress(CORINFO_CLASS_HANDLE cls, bool isGc, CORINFO_CONST_LOOKUP* addr) + bool getStaticBaseAddress(CORINFO_CLASS_HANDLE cls, bool isGc, REF_CORINFO_CONST_LOOKUP addr) unsigned getClassSize(CORINFO_CLASS_HANDLE cls) unsigned getHeapClassSize(CORINFO_CLASS_HANDLE cls) bool canAllocateOnStack(CORINFO_CLASS_HANDLE cls) @@ -236,7 +237,7 @@ FUNCTIONS bool isObjectImmutable(CORINFO_OBJECT_HANDLE objPtr) bool getStringChar(CORINFO_OBJECT_HANDLE strObj, int index, uint16_t* value); CORINFO_CLASS_HANDLE getObjectType(CORINFO_OBJECT_HANDLE objPtr) - bool getReadyToRunHelper(CORINFO_RESOLVED_TOKEN * pResolvedToken, CORINFO_LOOKUP_KIND * pGenericLookupKind, CorInfoHelpFunc id, CORINFO_METHOD_HANDLE callerHandle, CORINFO_CONST_LOOKUP *pLookup) + bool getReadyToRunHelper(CORINFO_RESOLVED_TOKEN * pResolvedToken, CORINFO_LOOKUP_KIND * pGenericLookupKind, CorInfoHelpFunc id, CORINFO_METHOD_HANDLE callerHandle, REF_CORINFO_CONST_LOOKUP pLookup) void getReadyToRunDelegateCtorHelper(CORINFO_RESOLVED_TOKEN * pTargetMethod, mdToken targetConstraint, CORINFO_CLASS_HANDLE delegateType, CORINFO_METHOD_HANDLE callerHandle, CORINFO_LOOKUP *pLookup) CorInfoInitClassResult initClass(CORINFO_FIELD_HANDLE field, CORINFO_METHOD_HANDLE method, CORINFO_CONTEXT_HANDLE context) void classMustBeLoadedBeforeCodeIsRun(CORINFO_CLASS_HANDLE cls) @@ -294,9 +295,9 @@ FUNCTIONS void getFpStructLowering(CORINFO_CLASS_HANDLE structHnd, CORINFO_FPSTRUCT_LOWERING* pLowering); uint32_t getThreadTLSIndex(void **ppIndirection); int32_t * getAddrOfCaptureThreadGlobal(void **ppIndirection); - void* getHelperFtn (CorInfoHelpFunc ftnNum, void **ppIndirection); - void getFunctionEntryPoint(CORINFO_METHOD_HANDLE ftn, CORINFO_CONST_LOOKUP * pResult, CORINFO_ACCESS_FLAGS accessFlags); - void getFunctionFixedEntryPoint(CORINFO_METHOD_HANDLE ftn, bool isUnsafeFunctionPointer, CORINFO_CONST_LOOKUP * pResult); + void getHelperFtn (CorInfoHelpFunc ftnNum, CORINFO_CONST_LOOKUP* pNativeEntrypoint, CORINFO_METHOD_HANDLE *pMethod); + void getFunctionEntryPoint(CORINFO_METHOD_HANDLE ftn, REF_CORINFO_CONST_LOOKUP pResult, CORINFO_ACCESS_FLAGS accessFlags); + void getFunctionFixedEntryPoint(CORINFO_METHOD_HANDLE ftn, bool isUnsafeFunctionPointer, REF_CORINFO_CONST_LOOKUP pResult); void* getMethodSync(CORINFO_METHOD_HANDLE ftn, void **ppIndirection); CorInfoHelpFunc getLazyStringLiteralHelper(CORINFO_MODULE_HANDLE handle); CORINFO_MODULE_HANDLE embedModuleHandle(CORINFO_MODULE_HANDLE handle, void **ppIndirection); @@ -305,7 +306,7 @@ FUNCTIONS CORINFO_FIELD_HANDLE embedFieldHandle(CORINFO_FIELD_HANDLE handle, void **ppIndirection); void embedGenericHandle(CORINFO_RESOLVED_TOKEN * pResolvedToken, bool fEmbedParent, CORINFO_METHOD_HANDLE callerHandle, CORINFO_GENERICHANDLE_RESULT * pResult); void getLocationOfThisType(CORINFO_METHOD_HANDLE context, CORINFO_LOOKUP_KIND* pLookupKind); - void getAddressOfPInvokeTarget(CORINFO_METHOD_HANDLE method, CORINFO_CONST_LOOKUP *pLookup); + void getAddressOfPInvokeTarget(CORINFO_METHOD_HANDLE method, REF_CORINFO_CONST_LOOKUP pLookup); void* GetCookieForPInvokeCalliSig(CORINFO_SIG_INFO* szMetaSig, void ** ppIndirection); bool canGetCookieForPInvokeCalliSig(CORINFO_SIG_INFO* szMetaSig); CORINFO_JUST_MY_CODE_HANDLE getJustMyCodeHandle(CORINFO_METHOD_HANDLE method, CORINFO_JUST_MY_CODE_HANDLE**ppIndirection); @@ -325,7 +326,7 @@ FUNCTIONS CORINFO_METHOD_HANDLE getAsyncResumptionStub(); bool convertPInvokeCalliToCall(CORINFO_RESOLVED_TOKEN * pResolvedToken, bool mustConvert); bool notifyInstructionSetUsage(CORINFO_InstructionSet instructionSet,bool supportEnabled); - void updateEntryPointForTailCall(CORINFO_CONST_LOOKUP* entryPoint); + void updateEntryPointForTailCall(REF_CORINFO_CONST_LOOKUP entryPoint); void allocMem(AllocMemArgs* pArgs); void reserveUnwindInfo(bool isFunclet, bool isColdCode, uint32_t unwindSize) void allocUnwindInfo(uint8_t* pHotCode, uint8_t* pColdCode, uint32_t startOffset, uint32_t endOffset, uint32_t unwindSize, uint8_t* pUnwindBlock, CorJitFuncKind funcKind) diff --git a/src/coreclr/tools/aot/jitinterface/jitinterface_generated.h b/src/coreclr/tools/aot/jitinterface/jitinterface_generated.h index 729a09de403eac..41b2d0fa65a82d 100644 --- a/src/coreclr/tools/aot/jitinterface/jitinterface_generated.h +++ b/src/coreclr/tools/aot/jitinterface/jitinterface_generated.h @@ -140,7 +140,7 @@ struct JitInterfaceCallbacks void (* getFpStructLowering)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_CLASS_HANDLE structHnd, CORINFO_FPSTRUCT_LOWERING* pLowering); uint32_t (* getThreadTLSIndex)(void * thisHandle, CorInfoExceptionClass** ppException, void** ppIndirection); int32_t* (* getAddrOfCaptureThreadGlobal)(void * thisHandle, CorInfoExceptionClass** ppException, void** ppIndirection); - void* (* getHelperFtn)(void * thisHandle, CorInfoExceptionClass** ppException, CorInfoHelpFunc ftnNum, void** ppIndirection); + void (* getHelperFtn)(void * thisHandle, CorInfoExceptionClass** ppException, CorInfoHelpFunc ftnNum, CORINFO_CONST_LOOKUP* pNativeEntrypoint, CORINFO_METHOD_HANDLE* pMethod); void (* getFunctionEntryPoint)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_METHOD_HANDLE ftn, CORINFO_CONST_LOOKUP* pResult, CORINFO_ACCESS_FLAGS accessFlags); void (* getFunctionFixedEntryPoint)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_METHOD_HANDLE ftn, bool isUnsafeFunctionPointer, CORINFO_CONST_LOOKUP* pResult); void* (* getMethodSync)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_METHOD_HANDLE ftn, void** ppIndirection); @@ -1449,14 +1449,14 @@ class JitInterfaceWrapper : public ICorJitInfo return temp; } - virtual void* getHelperFtn( + virtual void getHelperFtn( CorInfoHelpFunc ftnNum, - void** ppIndirection) + CORINFO_CONST_LOOKUP* pNativeEntrypoint, + CORINFO_METHOD_HANDLE* pMethod) { CorInfoExceptionClass* pException = nullptr; - void* temp = _callbacks->getHelperFtn(_thisHandle, &pException, ftnNum, ppIndirection); + _callbacks->getHelperFtn(_thisHandle, &pException, ftnNum, pNativeEntrypoint, pMethod); if (pException != nullptr) throw pException; - return temp; } virtual void getFunctionEntryPoint( diff --git a/src/coreclr/tools/superpmi/superpmi-shared/agnostic.h b/src/coreclr/tools/superpmi/superpmi-shared/agnostic.h index cefd14edde954f..3a385026e521ab 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/agnostic.h +++ b/src/coreclr/tools/superpmi/superpmi-shared/agnostic.h @@ -268,6 +268,12 @@ struct Agnostic_CORINFO_CONST_LOOKUP DWORDLONG handle; // actually a union of two pointer sized things }; +struct Agnostic_GetHelperFtn +{ + Agnostic_CORINFO_CONST_LOOKUP helperLookup; + DWORDLONG helperMethod; +}; + struct Agnostic_CORINFO_LOOKUP_KIND { DWORD needsRuntimeLookup; diff --git a/src/coreclr/tools/superpmi/superpmi-shared/compileresult.cpp b/src/coreclr/tools/superpmi/superpmi-shared/compileresult.cpp index e91450825837a5..8c9252869fe243 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/compileresult.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shared/compileresult.cpp @@ -993,8 +993,8 @@ void CompileResult::applyRelocs(RelocContext* rc, unsigned char* block1, ULONG b { for (unsigned int idx = 0; idx < rc->mc->GetHelperFtn->GetCount(); idx++) { - DLDL value = rc->mc->GetHelperFtn->GetItem(idx); - if (value.B == tmp.target) + Agnostic_GetHelperFtn value = rc->mc->GetHelperFtn->GetItem(idx); + if (value.helperLookup.handle == tmp.target) { LogDebug(" REL32 target is result of getHelperFtn(): setting delta=%d (0x%X)", (int)tmp.target, (int)tmp.target); diff --git a/src/coreclr/tools/superpmi/superpmi-shared/lwmlist.h b/src/coreclr/tools/superpmi/superpmi-shared/lwmlist.h index f81a8680ab5d74..3ba52311b87cfa 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/lwmlist.h +++ b/src/coreclr/tools/superpmi/superpmi-shared/lwmlist.h @@ -94,7 +94,7 @@ LWM(GetFieldType, DLDL, DLD) LWM(GetFunctionEntryPoint, DLD, DLD) LWM(GetFunctionFixedEntryPoint, DWORDLONG, Agnostic_CORINFO_CONST_LOOKUP) LWM(GetGSCookie, DWORD, DLDL) -LWM(GetHelperFtn, DWORD, DLDL) +LWM(GetHelperFtn, DWORD, Agnostic_GetHelperFtn) LWM(GetHFAType, DWORDLONG, DWORD) LWM(GetIntConfigValue, Agnostic_ConfigIntInfo, DWORD) LWM(GetJitFlags, DWORD, DD) diff --git a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp index e414a1d0b00c21..e671133fb4945e 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp @@ -2380,32 +2380,41 @@ void MethodContext::repGetReadyToRunDelegateCtorHelper(CORINFO_RESOLVED_TOKEN* p *pLookup = SpmiRecordsHelper::RestoreCORINFO_LOOKUP(value); } -void MethodContext::recGetHelperFtn(CorInfoHelpFunc ftnNum, void** ppIndirection, void* result) +void MethodContext::recGetHelperFtn(CorInfoHelpFunc ftnNum, CORINFO_CONST_LOOKUP pNativeEntrypoint,CORINFO_METHOD_HANDLE methodHandle) { if (GetHelperFtn == nullptr) - GetHelperFtn = new LightWeightMap(); + GetHelperFtn = new LightWeightMap(); DWORD key = (DWORD)ftnNum; - DLDL value; - value.A = CastPointer(*ppIndirection); - value.B = CastPointer(result); + Agnostic_GetHelperFtn value; + value.helperLookup = SpmiRecordsHelper::StoreAgnostic_CORINFO_CONST_LOOKUP(&pNativeEntrypoint); + value.helperMethod = CastHandle(methodHandle); GetHelperFtn->Add(key, value); DEBUG_REC(dmpGetHelperFtn(key, value)); } -void MethodContext::dmpGetHelperFtn(DWORD key, DLDL value) +void MethodContext::dmpGetHelperFtn(DWORD key, Agnostic_GetHelperFtn value) { - printf("GetHelperFtn key ftn-%u, value ppi-%016" PRIX64 " res-%016" PRIX64 "", key, value.A, value.B); + printf("GetHelperFtn key ftn-%u nativeEntrypoint {%s}, helperMethod-%016" PRIX64 "", key, + SpmiDumpHelper::DumpAgnostic_CORINFO_CONST_LOOKUP(value.helperLookup).c_str(), + value.helperMethod); } -void* MethodContext::repGetHelperFtn(CorInfoHelpFunc ftnNum, void** ppIndirection) + +void MethodContext::repGetHelperFtn(CorInfoHelpFunc ftnNum, CORINFO_CONST_LOOKUP* pNativeEntrypoint,CORINFO_METHOD_HANDLE *pMethodHandle) { DWORD key = (DWORD)ftnNum; - DLDL value = LookupByKeyOrMiss(GetHelperFtn, key, ": key %u", key); + Agnostic_GetHelperFtn value = LookupByKeyOrMiss(GetHelperFtn, key, ": key %u", key); DEBUG_REP(dmpGetHelperFtn(key, value)); - *ppIndirection = (void*)value.A; - return (void*)value.B; + if (pNativeEntrypoint != nullptr) + { + *pNativeEntrypoint = SpmiRecordsHelper::RestoreCORINFO_CONST_LOOKUP(value.helperLookup); + } + if (pMethodHandle != nullptr) + { + *pMethodHandle = (CORINFO_METHOD_HANDLE)value.helperMethod; + } } // @@ -2430,12 +2439,12 @@ bool MethodContext::fndGetHelperFtn(void* functionAddress, CorInfoHelpFunc* pRes { for (unsigned int i = 0; i < GetHelperFtn->GetCount(); i++) { - DWORD key = GetHelperFtn->GetKey(i); - DLDL val = GetHelperFtn->GetItem(i); + DWORD key = GetHelperFtn->GetKey(i); + Agnostic_GetHelperFtn val = GetHelperFtn->GetItem(i); // TODO-Cleanup: this only compares the function addresses, and doesn't account for // ppIndirection, which will break if the helper is a dynamic helper function. - if (val.B == CastPointer(functionAddress)) + if (val.helperLookup.handle == CastPointer(functionAddress)) { *pResult = (CorInfoHelpFunc)key; return true; diff --git a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h index 1a25a3a24c5a96..8246cc8c7810bd 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h +++ b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h @@ -336,9 +336,9 @@ class MethodContext CORINFO_METHOD_HANDLE callerHandle, CORINFO_LOOKUP* pLookup); - void recGetHelperFtn(CorInfoHelpFunc ftnNum, void** ppIndirection, void* result); - void dmpGetHelperFtn(DWORD key, DLDL value); - void* repGetHelperFtn(CorInfoHelpFunc ftnNum, void** ppIndirection); + void recGetHelperFtn(CorInfoHelpFunc ftnNum, CORINFO_CONST_LOOKUP pNativeEntrypoint,CORINFO_METHOD_HANDLE methodHandle); + void dmpGetHelperFtn(DWORD key, Agnostic_GetHelperFtn value); + void repGetHelperFtn(CorInfoHelpFunc ftnNum, CORINFO_CONST_LOOKUP* pNativeEntrypoint,CORINFO_METHOD_HANDLE *pMethodHandle); bool fndGetHelperFtn(void* functionAddress, CorInfoHelpFunc* pResult); void recGetJustMyCodeHandle(CORINFO_METHOD_HANDLE method, @@ -1052,7 +1052,7 @@ enum mcPackets Packet_GetFunctionEntryPoint = 60, Packet_GetFunctionFixedEntryPoint = 61, Packet_GetGSCookie = 62, - Packet_GetHelperFtn = 63, + //Packet_GetHelperFtn = 63, //Packet_GetInlinedCallFrameVptr = 65, Packet_GetArrayIntrinsicID = 66, //Packet_GetJitTimeLogFilename = 67, @@ -1218,6 +1218,7 @@ enum mcPackets Packet_NotifyInstructionSetUsage = 229, Packet_GetAsyncInfo = 230, Packet_GetAsyncResumptionStub = 231, + Packet_GetHelperFtn = 233, }; 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 835d6a22d448de..d4decffceeee06 100644 --- a/src/coreclr/tools/superpmi/superpmi-shim-collector/icorjitinfo.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shim-collector/icorjitinfo.cpp @@ -1462,12 +1462,21 @@ int32_t* interceptor_ICJI::getAddrOfCaptureThreadGlobal(void** ppIndirection) } // return the native entry point to an EE helper (see CorInfoHelpFunc) -void* interceptor_ICJI::getHelperFtn(CorInfoHelpFunc ftnNum, void** ppIndirection) +void interceptor_ICJI::getHelperFtn(CorInfoHelpFunc ftnNum, CORINFO_CONST_LOOKUP *pNativeEntrypoint, CORINFO_METHOD_HANDLE *methodHandle) { mc->cr->AddCall("getHelperFtn"); - void* temp = original_ICorJitInfo->getHelperFtn(ftnNum, ppIndirection); - mc->recGetHelperFtn(ftnNum, ppIndirection, temp); - return temp; + CORINFO_CONST_LOOKUP localNativeEntrypoint; + CORINFO_METHOD_HANDLE localMethodHandle; + original_ICorJitInfo->getHelperFtn(ftnNum, &localNativeEntrypoint, &localMethodHandle); + mc->recGetHelperFtn(ftnNum, localNativeEntrypoint, localMethodHandle); + if (pNativeEntrypoint != nullptr) + { + *pNativeEntrypoint = localNativeEntrypoint; + } + if (methodHandle != nullptr) + { + *methodHandle = localMethodHandle; + } } // return a callable address of the function (native code). This function 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 60d344324e98cd..714ad80f1809cb 100644 --- a/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo_generated.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo_generated.cpp @@ -1042,12 +1042,13 @@ int32_t* interceptor_ICJI::getAddrOfCaptureThreadGlobal( return original_ICorJitInfo->getAddrOfCaptureThreadGlobal(ppIndirection); } -void* interceptor_ICJI::getHelperFtn( +void interceptor_ICJI::getHelperFtn( CorInfoHelpFunc ftnNum, - void** ppIndirection) + CORINFO_CONST_LOOKUP* pNativeEntrypoint, + CORINFO_METHOD_HANDLE* pMethod) { mcs->AddCall("getHelperFtn"); - return original_ICorJitInfo->getHelperFtn(ftnNum, ppIndirection); + original_ICorJitInfo->getHelperFtn(ftnNum, pNativeEntrypoint, pMethod); } void interceptor_ICJI::getFunctionEntryPoint( 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 c04554b5844f63..eb0503222ede41 100644 --- a/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo_generated.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo_generated.cpp @@ -913,11 +913,12 @@ int32_t* interceptor_ICJI::getAddrOfCaptureThreadGlobal( return original_ICorJitInfo->getAddrOfCaptureThreadGlobal(ppIndirection); } -void* interceptor_ICJI::getHelperFtn( +void interceptor_ICJI::getHelperFtn( CorInfoHelpFunc ftnNum, - void** ppIndirection) + CORINFO_CONST_LOOKUP* pNativeEntrypoint, + CORINFO_METHOD_HANDLE* pMethod) { - return original_ICorJitInfo->getHelperFtn(ftnNum, ppIndirection); + original_ICorJitInfo->getHelperFtn(ftnNum, pNativeEntrypoint, pMethod); } void interceptor_ICJI::getFunctionEntryPoint( diff --git a/src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp b/src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp index 98c22710cbbb9b..5326d1c57b6963 100644 --- a/src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp +++ b/src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp @@ -1270,10 +1270,10 @@ int32_t* MyICJI::getAddrOfCaptureThreadGlobal(void** ppIndirection) } // return the native entry point to an EE helper (see CorInfoHelpFunc) -void* MyICJI::getHelperFtn(CorInfoHelpFunc ftnNum, void** ppIndirection) +void MyICJI::getHelperFtn(CorInfoHelpFunc ftnNum, CORINFO_CONST_LOOKUP *pNativeEntrypoint, CORINFO_METHOD_HANDLE *methodHandle) { jitInstance->mc->cr->AddCall("getHelperFtn"); - return jitInstance->mc->repGetHelperFtn(ftnNum, ppIndirection); + jitInstance->mc->repGetHelperFtn(ftnNum, pNativeEntrypoint, methodHandle); } // return a callable address of the function (native code). This function diff --git a/src/coreclr/vm/jitinterface.cpp b/src/coreclr/vm/jitinterface.cpp index 26b9b246d58e68..3be0b073c90a72 100644 --- a/src/coreclr/vm/jitinterface.cpp +++ b/src/coreclr/vm/jitinterface.cpp @@ -10833,8 +10833,9 @@ CEECodeGenInfo::CEECodeGenInfo(PrepareCodeConfig* config, MethodDesc* fd, COR_IL m_jitFlags = GetCompileFlags(config, m_pMethodBeingCompiled, &m_MethodInfo); } -void* CEECodeGenInfo::getHelperFtn(CorInfoHelpFunc ftnNum, /* IN */ - void ** ppIndirection) /* OUT */ +void CEECodeGenInfo::getHelperFtn(CorInfoHelpFunc ftnNum, /* IN */ + CORINFO_CONST_LOOKUP* pNativeEntrypoint, /* OUT */ + CORINFO_METHOD_HANDLE* pMethod) /* OUT */ { CONTRACTL { THROWS; @@ -10842,13 +10843,13 @@ void* CEECodeGenInfo::getHelperFtn(CorInfoHelpFunc ftnNum, /* IN */ MODE_PREEMPTIVE; } CONTRACTL_END; - void* result = NULL; - - if (ppIndirection != NULL) - *ppIndirection = NULL; - JIT_TO_EE_TRANSITION(); + if (pMethod != NULL) + { + *pMethod = NULL; + } + _ASSERTE(ftnNum < CORINFO_HELP_COUNT); void* pfnHelper = hlpFuncTable[ftnNum].pfnHelper; @@ -10872,11 +10873,13 @@ void* CEECodeGenInfo::getHelperFtn(CorInfoHelpFunc ftnNum, /* IN */ dynamicFtnNum == DYNAMIC_CORINFO_HELP_PROF_FCN_TAILCALL || dynamicFtnNum == DYNAMIC_CORINFO_HELP_DISPATCH_INDIRECT_CALL) { - _ASSERTE(ppIndirection != NULL); - _ASSERTE(hlpDynamicFuncTable[dynamicFtnNum].pfnHelper != NULL); // Confirm the helper is non-null and doesn't require lazy loading. - *ppIndirection = &hlpDynamicFuncTable[dynamicFtnNum].pfnHelper; - _ASSERTE(IndirectionAllowedForJitHelper(ftnNum)); - result = NULL; + if (pNativeEntrypoint != NULL) + { + pNativeEntrypoint->accessType = IAT_PVALUE; + _ASSERTE(hlpDynamicFuncTable[dynamicFtnNum].pfnHelper != NULL); // Confirm the helper is non-null and doesn't require lazy loading. + pNativeEntrypoint->addr = &hlpDynamicFuncTable[dynamicFtnNum].pfnHelper; + _ASSERTE(IndirectionAllowedForJitHelper(ftnNum)); + } goto exit; } #endif @@ -10886,7 +10889,16 @@ void* CEECodeGenInfo::getHelperFtn(CorInfoHelpFunc ftnNum, /* IN */ LPVOID finalTierAddr = hlpFinalTierAddrTable[dynamicFtnNum]; if (finalTierAddr != NULL) { - result = finalTierAddr; + if (pNativeEntrypoint != NULL) + { + pNativeEntrypoint->accessType = IAT_VALUE; + pNativeEntrypoint->addr = finalTierAddr; + } + if (pMethod != nullptr && HasILBasedDynamicJitHelper((DynamicCorInfoHelpFunc)dynamicFtnNum)) + { + (void)LoadDynamicJitHelper((DynamicCorInfoHelpFunc)dynamicFtnNum, (MethodDesc**)pMethod); + _ASSERT(*pMethod != NULL); + } goto exit; } @@ -10896,6 +10908,11 @@ void* CEECodeGenInfo::getHelperFtn(CorInfoHelpFunc ftnNum, /* IN */ (void)LoadDynamicJitHelper((DynamicCorInfoHelpFunc)dynamicFtnNum, &helperMD); _ASSERT(helperMD != NULL); + if (pMethod != NULL) + { + *pMethod = (CORINFO_METHOD_HANDLE)helperMD; + } + // Check if the target MethodDesc is already jitted to its final Tier // so we no longer need to use indirections and can emit a direct call instead. // @@ -10922,7 +10939,11 @@ void* CEECodeGenInfo::getHelperFtn(CorInfoHelpFunc ftnNum, /* IN */ { // Cache it for future uses to avoid taking the lock again. hlpFinalTierAddrTable[dynamicFtnNum] = finalTierAddr; - result = finalTierAddr; + if (pNativeEntrypoint != NULL) + { + pNativeEntrypoint->accessType = IAT_VALUE; + pNativeEntrypoint->addr = finalTierAddr; + } goto exit; } } @@ -10932,8 +10953,11 @@ void* CEECodeGenInfo::getHelperFtn(CorInfoHelpFunc ftnNum, /* IN */ { Precode* pPrecode = helperMD->GetPrecode(); _ASSERTE(pPrecode->GetType() == PRECODE_FIXUP); - *ppIndirection = ((FixupPrecode*)pPrecode)->GetTargetSlot(); - result = NULL; + if (pNativeEntrypoint != NULL) + { + pNativeEntrypoint->accessType = IAT_PVALUE; + pNativeEntrypoint->addr = ((FixupPrecode*)pPrecode)->GetTargetSlot(); + } goto exit; } } @@ -10943,11 +10967,14 @@ void* CEECodeGenInfo::getHelperFtn(CorInfoHelpFunc ftnNum, /* IN */ _ASSERTE(pfnHelper != NULL); - result = (LPVOID)GetEEFuncEntryPoint(pfnHelper); + if (pNativeEntrypoint != NULL) + { + pNativeEntrypoint->accessType = IAT_VALUE; + pNativeEntrypoint->addr = (LPVOID)GetEEFuncEntryPoint(pfnHelper); + } exit: ; EE_TO_JIT_TRANSITION(); - return result; } PCODE CEECodeGenInfo::getHelperFtnStatic(CorInfoHelpFunc ftnNum) @@ -14973,8 +15000,9 @@ CORINFO_METHOD_HANDLE CEEInfo::getAsyncResumptionStub() UNREACHABLE(); // only called on derived class. } -void* CEEInfo::getHelperFtn(CorInfoHelpFunc ftnNum, /* IN */ - void ** ppIndirection) /* OUT */ +void CEEInfo::getHelperFtn(CorInfoHelpFunc ftnNum, /* IN */ + CORINFO_CONST_LOOKUP* pNativeEntrypoint, /* OUT */ + CORINFO_METHOD_HANDLE* pMethod) /* OUT */ { LIMITED_METHOD_CONTRACT; UNREACHABLE(); // only called on derived class. diff --git a/src/coreclr/vm/jitinterface.h b/src/coreclr/vm/jitinterface.h index ceb999589a2562..65a5f52c76396e 100644 --- a/src/coreclr/vm/jitinterface.h +++ b/src/coreclr/vm/jitinterface.h @@ -570,8 +570,9 @@ class CEECodeGenInfo : public CEEInfo virtual void WriteCode(EECodeGenManager * jitMgr) = 0; - void* getHelperFtn(CorInfoHelpFunc ftnNum, /* IN */ - void ** ppIndirection) override; /* OUT */ + void getHelperFtn(CorInfoHelpFunc tnNum, /* IN */ + CORINFO_CONST_LOOKUP * pNativeEntrypoint, /* OUT */ + CORINFO_METHOD_HANDLE * pMethodHandle) override; /* OUT */ static PCODE getHelperFtnStatic(CorInfoHelpFunc ftnNum); InfoAccessType constructStringLiteral(CORINFO_MODULE_HANDLE scopeHnd, mdToken metaTok, void **ppValue) override; From cc8b66b3bff0ddea0c426a99210c8daee2c77b6a Mon Sep 17 00:00:00 2001 From: David Wrighton Date: Thu, 12 Jun 2025 13:45:54 -0700 Subject: [PATCH 2/4] JIT formatting --- src/coreclr/jit/codegenarm64.cpp | 4 ++-- src/coreclr/jit/codegenarmarch.cpp | 2 +- src/coreclr/jit/codegenloongarch64.cpp | 11 ++++++----- src/coreclr/jit/codegenriscv64.cpp | 11 ++++++----- src/coreclr/jit/codegenxarch.cpp | 6 +++--- src/coreclr/jit/compiler.cpp | 2 +- src/coreclr/jit/lower.cpp | 4 ++-- 7 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/coreclr/jit/codegenarm64.cpp b/src/coreclr/jit/codegenarm64.cpp index 7ea58ce666c4dc..a03afd93a9759f 100644 --- a/src/coreclr/jit/codegenarm64.cpp +++ b/src/coreclr/jit/codegenarm64.cpp @@ -5137,9 +5137,9 @@ void CodeGen::genEmitHelperCall(unsigned helper, int argSize, emitAttr retSize, EmitCallParams params; CORINFO_CONST_LOOKUP helperFunction = compiler->compGetHelperFtn((CorInfoHelpFunc)helper); - regMaskTP killSet = compiler->compHelperCallKillSet((CorInfoHelpFunc)helper); + regMaskTP killSet = compiler->compHelperCallKillSet((CorInfoHelpFunc)helper); - params.callType = EC_FUNC_TOKEN; + params.callType = EC_FUNC_TOKEN; if (helperFunction.accessType == IAT_VALUE) { diff --git a/src/coreclr/jit/codegenarmarch.cpp b/src/coreclr/jit/codegenarmarch.cpp index b1a83a1687a06a..0de0942063360e 100644 --- a/src/coreclr/jit/codegenarmarch.cpp +++ b/src/coreclr/jit/codegenarmarch.cpp @@ -3453,7 +3453,7 @@ void CodeGen::genCallInstruction(GenTreeCall* call) noway_assert(helperNum != CORINFO_HELP_UNDEF); CORINFO_CONST_LOOKUP helperLookup = compiler->compGetHelperFtn(helperNum); - params.addr = helperLookup.addr; + params.addr = helperLookup.addr; assert(helperLookup.accessType == IAT_VALUE); } else diff --git a/src/coreclr/jit/codegenloongarch64.cpp b/src/coreclr/jit/codegenloongarch64.cpp index 5807ed26081ef1..685cf6a6ec9c14 100644 --- a/src/coreclr/jit/codegenloongarch64.cpp +++ b/src/coreclr/jit/codegenloongarch64.cpp @@ -3768,9 +3768,9 @@ void CodeGen::genEmitHelperCall(unsigned helper, int argSize, emitAttr retSize, EmitCallParams params; CORINFO_CONST_LOOKUP helperFunction = compiler->compGetHelperFtn((CorInfoHelpFunc)helper); - regMaskTP killSet = compiler->compHelperCallKillSet((CorInfoHelpFunc)helper); + regMaskTP killSet = compiler->compHelperCallKillSet((CorInfoHelpFunc)helper); - params.callType = EC_FUNC_TOKEN; + params.callType = EC_FUNC_TOKEN; if (helperFunction.accessType == IAT_VALUE) { @@ -5809,7 +5809,7 @@ void CodeGen::genCallInstruction(GenTreeCall* call) noway_assert(helperNum != CORINFO_HELP_UNDEF); CORINFO_CONST_LOOKUP helperLookup = compiler->compGetHelperFtn(helperNum); - params.addr = helperLookup.addr; + params.addr = helperLookup.addr; assert(helperLookup.accessType == IAT_VALUE); } else @@ -6499,7 +6499,7 @@ inline void CodeGen::genJumpToThrowHlpBlk_la( // we will jump around it in the normal non-exception case. EmitCallParams params; - + // maybe optimize // ins = (instruction)(ins^((ins != INS_beq)+(ins != INS_bne))); if (ins == INS_blt) @@ -6523,7 +6523,8 @@ inline void CodeGen::genJumpToThrowHlpBlk_la( ins = ins == INS_beq ? INS_bne : INS_beq; } - CORINFO_CONST_LOOKUP helperFunction = compiler->compGetHelperFtn((CorInfoHelpFunc)(compiler->acdHelper(codeKind))); + CORINFO_CONST_LOOKUP helperFunction = + compiler->compGetHelperFtn((CorInfoHelpFunc)(compiler->acdHelper(codeKind))); if (helperFunction.accessType == IAT_VALUE) { // If the helper is a value, we need to use the address of the helper. diff --git a/src/coreclr/jit/codegenriscv64.cpp b/src/coreclr/jit/codegenriscv64.cpp index 4707ca49d0fa31..fc382c31023375 100644 --- a/src/coreclr/jit/codegenriscv64.cpp +++ b/src/coreclr/jit/codegenriscv64.cpp @@ -2720,7 +2720,7 @@ void CodeGen::genCodeForReturnTrap(GenTreeOp* tree) } else { - params.addr = nullptr; + params.addr = nullptr; params.callType = EC_INDIR_R; params.ireg = REG_DEFAULT_HELPER_CALL_TARGET; @@ -3621,9 +3621,9 @@ void CodeGen::genEmitHelperCall(unsigned helper, int argSize, emitAttr retSize, EmitCallParams params; CORINFO_CONST_LOOKUP helperFunction = compiler->compGetHelperFtn((CorInfoHelpFunc)helper); - regMaskTP killSet = compiler->compHelperCallKillSet((CorInfoHelpFunc)helper); + regMaskTP killSet = compiler->compHelperCallKillSet((CorInfoHelpFunc)helper); - params.callType = EC_FUNC_TOKEN; + params.callType = EC_FUNC_TOKEN; if (helperFunction.accessType == IAT_VALUE) { @@ -5885,7 +5885,7 @@ void CodeGen::genCallInstruction(GenTreeCall* call) noway_assert(helperNum != CORINFO_HELP_UNDEF); CORINFO_CONST_LOOKUP helperLookup = compiler->compGetHelperFtn(helperNum); - params.addr = helperLookup.addr; + params.addr = helperLookup.addr; assert(helperLookup.accessType == IAT_VALUE); } else @@ -6532,7 +6532,8 @@ void CodeGen::genJumpToThrowHlpBlk_la( ins = ins == INS_beq ? INS_bne : INS_beq; } - CORINFO_CONST_LOOKUP helperFunction = compiler->compGetHelperFtn((CorInfoHelpFunc)(compiler->acdHelper(codeKind))); + CORINFO_CONST_LOOKUP helperFunction = + compiler->compGetHelperFtn((CorInfoHelpFunc)(compiler->acdHelper(codeKind))); if (helperFunction.accessType == IAT_VALUE) { // If the helper is a value, we need to use the address of the helper. diff --git a/src/coreclr/jit/codegenxarch.cpp b/src/coreclr/jit/codegenxarch.cpp index 543460a7211091..c33b039de0c3fe 100644 --- a/src/coreclr/jit/codegenxarch.cpp +++ b/src/coreclr/jit/codegenxarch.cpp @@ -6505,7 +6505,7 @@ void CodeGen::genCallInstruction(GenTreeCall* call X86_ARG(target_ssize_t stackA noway_assert(helperNum != CORINFO_HELP_UNDEF); CORINFO_CONST_LOOKUP helperLookup = compiler->compGetHelperFtn(helperNum); - addr = helperLookup.addr; + addr = helperLookup.addr; assert(helperLookup.accessType == IAT_VALUE); } else @@ -8833,10 +8833,10 @@ void CodeGen::genCreateAndStoreGCInfoX64(unsigned codeSize, unsigned prologSize void CodeGen::genEmitHelperCall(unsigned helper, int argSize, emitAttr retSize, regNumber callTargetReg) { EmitCallParams params; - params.callType = EC_FUNC_TOKEN; + params.callType = EC_FUNC_TOKEN; CORINFO_CONST_LOOKUP helperFunction = compiler->compGetHelperFtn((CorInfoHelpFunc)helper); - regMaskTP killMask = compiler->compHelperCallKillSet((CorInfoHelpFunc)helper); + regMaskTP killMask = compiler->compHelperCallKillSet((CorInfoHelpFunc)helper); if (helperFunction.accessType == IAT_VALUE) { diff --git a/src/coreclr/jit/compiler.cpp b/src/coreclr/jit/compiler.cpp index 7f3f30bfadd70d..d0d704f02063a2 100644 --- a/src/coreclr/jit/compiler.cpp +++ b/src/coreclr/jit/compiler.cpp @@ -1679,7 +1679,7 @@ CORINFO_CONST_LOOKUP Compiler::compGetHelperFtn(CorInfoHelpFunc ftnNum) else { // If we don't have a matched VM, we won't get valid results when asking for a helper function. - lookup.addr = (void*)(uintptr_t)(0xCA11CA11); // "callcall" + lookup.addr = (void*)(uintptr_t)(0xCA11CA11); // "callcall" lookup.accessType = IAT_VALUE; } diff --git a/src/coreclr/jit/lower.cpp b/src/coreclr/jit/lower.cpp index 95b6bf1e681368..75f49a1d3e93c4 100644 --- a/src/coreclr/jit/lower.cpp +++ b/src/coreclr/jit/lower.cpp @@ -6114,8 +6114,8 @@ GenTree* Lowering::LowerDirectCall(GenTreeCall* call) noway_assert(helperNum != CORINFO_HELP_UNDEF); CORINFO_CONST_LOOKUP addrInfo = comp->compGetHelperFtn(helperNum); - addr = addrInfo.addr; - accessType = addrInfo.accessType; + addr = addrInfo.addr; + accessType = addrInfo.accessType; } else { From 6c21cd21b1847d11944f9afd053f2ca726add008 Mon Sep 17 00:00:00 2001 From: David Wrighton Date: Thu, 12 Jun 2025 14:41:57 -0700 Subject: [PATCH 3/4] Attempt to address build breaks --- src/coreclr/jit/codegenloongarch64.cpp | 32 +++++++++++------------- src/coreclr/jit/codegenriscv64.cpp | 34 ++++++++++++-------------- 2 files changed, 30 insertions(+), 36 deletions(-) diff --git a/src/coreclr/jit/codegenloongarch64.cpp b/src/coreclr/jit/codegenloongarch64.cpp index 685cf6a6ec9c14..4111afcafd9b53 100644 --- a/src/coreclr/jit/codegenloongarch64.cpp +++ b/src/coreclr/jit/codegenloongarch64.cpp @@ -2692,7 +2692,8 @@ void CodeGen::genCodeForReturnTrap(GenTreeOp* tree) if (helperFunction.accessType == IAT_VALUE) { // If the helper is a value, we need to use the address of the helper. - params.addr = helperFunction.addr; + params.addr = helperFunction.addr; + params.callType = EC_FUNC_TOKEN; } else { @@ -2719,10 +2720,6 @@ void CodeGen::genCodeForReturnTrap(GenTreeOp* tree) } regSet.verifyRegUsed(params.ireg); } - else - { - params.callType = EC_FUNC_TOKEN; - } // TODO-LOONGARCH64: can optimize further !!! // TODO-LOONGARCH64: Why does this not use genEmitHelperCall? @@ -6527,8 +6524,19 @@ inline void CodeGen::genJumpToThrowHlpBlk_la( compiler->compGetHelperFtn((CorInfoHelpFunc)(compiler->acdHelper(codeKind))); if (helperFunction.accessType == IAT_VALUE) { + // INS_OPTS_C + // If the helper is a value, we need to use the address of the helper. - params.addr = helperFunction.addr; + params.addr = helperFunction.addr; + params.callType = EC_FUNC_TOKEN; + + ssize_t imm = 5 << 2; + if (compiler->opts.compReloc) + { + imm = 3 << 2; + } + + emit->emitIns_R_R_I(ins, EA_PTRSIZE, reg1, reg2, imm); } else { @@ -6558,18 +6566,6 @@ inline void CodeGen::genJumpToThrowHlpBlk_la( ((ssize_t)pAddr & 0xfff) >> 2); } } - else - { // INS_OPTS_C - params.callType = EC_FUNC_TOKEN; - - ssize_t imm = 5 << 2; - if (compiler->opts.compReloc) - { - imm = 3 << 2; - } - - emit->emitIns_R_R_I(ins, EA_PTRSIZE, reg1, reg2, imm); - } BasicBlock* skipLabel = genCreateTempLabel(); diff --git a/src/coreclr/jit/codegenriscv64.cpp b/src/coreclr/jit/codegenriscv64.cpp index fc382c31023375..bcab1b81c1860c 100644 --- a/src/coreclr/jit/codegenriscv64.cpp +++ b/src/coreclr/jit/codegenriscv64.cpp @@ -2716,7 +2716,8 @@ void CodeGen::genCodeForReturnTrap(GenTreeOp* tree) if (helperFunction.accessType == IAT_VALUE) { // If the helper is a value, we need to use the address of the helper. - params.addr = helperFunction.addr; + params.addr = helperFunction.addr; + params.callType = EC_FUNC_TOKEN; } else { @@ -2726,20 +2727,16 @@ void CodeGen::genCodeForReturnTrap(GenTreeOp* tree) if (compiler->opts.compReloc) { - GetEmitter()->emitIns_R_AI(INS_jal, EA_PTR_DSP_RELOC, params.ireg, (ssize_t)pAddr); + GetEmitter()->emitIns_R_AI(INS_jal, EA_PTR_DSP_RELOC, params.ireg, (ssize_t)helperFunction.addr); } else { // TODO-RISCV64: maybe optimize further. - GetEmitter()->emitLoadImmediate(EA_PTRSIZE, params.ireg, (ssize_t)pAddr); + GetEmitter()->emitLoadImmediate(EA_PTRSIZE, params.ireg, (ssize_t)helperFunction.addr); GetEmitter()->emitIns_R_R_I(INS_ld, EA_PTRSIZE, params.ireg, params.ireg, 0); } regSet.verifyRegUsed(params.ireg); } - else - { - params.callType = EC_FUNC_TOKEN; - } // TODO-RISCV64: can optimize further !!! // TODO-RISCV64: Why does this not use genEmitHelperCall? @@ -6536,8 +6533,18 @@ void CodeGen::genJumpToThrowHlpBlk_la( compiler->compGetHelperFtn((CorInfoHelpFunc)(compiler->acdHelper(codeKind))); if (helperFunction.accessType == IAT_VALUE) { + // INS_OPTS_C // If the helper is a value, we need to use the address of the helper. - params.addr = helperFunction.addr; + params.addr = helperFunction.addr; + params.callType = EC_FUNC_TOKEN; + + ssize_t imm = 9 << 2; + if (compiler->opts.compReloc) + { + imm = 3 << 2; + } + + emit->emitIns_R_R_I(ins, EA_PTRSIZE, reg1, reg2, imm); } else { @@ -6564,16 +6571,7 @@ void CodeGen::genJumpToThrowHlpBlk_la( regSet.verifyRegUsed(params.ireg); } else - { // INS_OPTS_C - params.callType = EC_FUNC_TOKEN; - - ssize_t imm = 9 << 2; - if (compiler->opts.compReloc) - { - imm = 3 << 2; - } - - emit->emitIns_R_R_I(ins, EA_PTRSIZE, reg1, reg2, imm); + { } BasicBlock* skipLabel = genCreateTempLabel(); From a6513e36266ea31f26c432b37f515f944f151418 Mon Sep 17 00:00:00 2001 From: David Wrighton Date: Thu, 12 Jun 2025 15:27:39 -0700 Subject: [PATCH 4/4] Fix build break --- src/coreclr/jit/codegenriscv64.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/coreclr/jit/codegenriscv64.cpp b/src/coreclr/jit/codegenriscv64.cpp index bcab1b81c1860c..640cb5ec6bf330 100644 --- a/src/coreclr/jit/codegenriscv64.cpp +++ b/src/coreclr/jit/codegenriscv64.cpp @@ -6570,9 +6570,6 @@ void CodeGen::genJumpToThrowHlpBlk_la( } regSet.verifyRegUsed(params.ireg); } - else - { - } BasicBlock* skipLabel = genCreateTempLabel();