Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 5.6k
[clr-interp] Implement intrinsics for startup path#117263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kotlarmilos
merged 15 commits into
dotnet:main
from
kotlarmilos:feature/coreclr-interp-startup-pathJul 15, 2025
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
3f6bc68
Test startup path
kotlarmilos 2bd4e92
Merge branch 'main' into feature/coreclr-interp-startup-path
kotlarmilos ca173e6
Avoid memset in newobj.vt
kotlarmilos 974d69d
Merge branch 'feature/coreclr-interp-startup-path' of github.com:kotl…
kotlarmilos 91fbac7
Add support for FastPollGC intrinsic
kotlarmilos 2bd3db7
Merge branch 'main' into feature/coreclr-interp-startup-path
kotlarmilos b229ecf
Resolve merge conflicts
kotlarmilos bad4a60
Implement COMPARE_EXCHANGE macro
kotlarmilos ceba9d4
Remove comment
kotlarmilos 6cb1503
Merge branch 'main' into feature/coreclr-interp-startup-path
kotlarmilos 508ea32
Resolve merge conflicts
kotlarmilos f6968ee
Enhance intrinsic call handling and add null check operation
kotlarmilos 42cdf9c
Replace INTOP_GETMETHODTABLE opcode with INTOP_LDIND_I
kotlarmilos ae4cfc0
Remove emitMemBarrier parameter and related logic
kotlarmilos 43fd9bb
Use enclosingClassNames to retrieve the top level namespace
kotlarmilos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -2181,6 +2181,27 @@ int32_t InterpCompiler::GetDataItemIndexForHelperFtn(CorInfoHelpFunc ftn) | ||
| return GetDataItemIndex(addr); | ||
| } | ||
| static int32_t GetLdindForType(InterpType interpType) | ||
| { | ||
| switch (interpType) | ||
| { | ||
| case InterpTypeI1: return INTOP_LDIND_I1; | ||
| case InterpTypeU1: return INTOP_LDIND_U1; | ||
| case InterpTypeI2: return INTOP_LDIND_I2; | ||
| case InterpTypeU2: return INTOP_LDIND_U2; | ||
| case InterpTypeI4: return INTOP_LDIND_I4; | ||
| case InterpTypeI8: return INTOP_LDIND_I8; | ||
| case InterpTypeR4: return INTOP_LDIND_R4; | ||
| case InterpTypeR8: return INTOP_LDIND_R8; | ||
| case InterpTypeO: return INTOP_LDIND_I; | ||
| case InterpTypeVT: return INTOP_LDIND_VT; | ||
| case InterpTypeByRef: return INTOP_LDIND_I; | ||
| default: | ||
| assert(0); | ||
| } | ||
| return -1; | ||
| } | ||
| bool InterpCompiler::EmitNamedIntrinsicCall(NamedIntrinsic ni, CORINFO_CLASS_HANDLE clsHnd, CORINFO_METHOD_HANDLE method, CORINFO_SIG_INFO sig) | ||
| { | ||
| bool mustExpand = (method == m_methodHnd); | ||
| @@ -2201,6 +2222,135 @@ bool InterpCompiler::EmitNamedIntrinsicCall(NamedIntrinsic ni, CORINFO_CLASS_HAN | ||
| AddIns(INTOP_THROW_PNSE); | ||
| return true; | ||
| case NI_System_Runtime_CompilerServices_StaticsHelpers_VolatileReadAsByref: | ||
| { | ||
| CHECK_STACK(1); | ||
| m_pStackPointer--; | ||
| int32_t addrVar = m_pStackPointer[0].var; | ||
| InterpType retType = GetInterpType(sig.retType); | ||
| int32_t opcode = GetLdindForType(retType); | ||
| AddIns(opcode); | ||
| m_pLastNewIns->SetSVar(addrVar); | ||
| CORINFO_CLASS_HANDLE clsHnd = NULL; | ||
| if (sig.retType == CORINFO_TYPE_CLASS) | ||
| { | ||
| clsHnd = sig.retTypeClass; | ||
| } | ||
| PushInterpType(retType, clsHnd); | ||
| m_pLastNewIns->SetDVar(m_pStackPointer[-1].var); | ||
| // Acquire barrier after the load | ||
| AddIns(INTOP_MEMBAR); | ||
| return true; | ||
| } | ||
| case NI_System_Threading_Volatile_ReadBarrier: | ||
| AddIns(INTOP_MEMBAR); | ||
| return true; | ||
| case NI_System_Runtime_CompilerServices_RuntimeHelpers_GetMethodTable: | ||
| { | ||
| CHECK_STACK(1); | ||
| m_pStackPointer--; | ||
| AddIns(INTOP_LDIND_I); | ||
| m_pLastNewIns->data[0] = 0; | ||
| m_pLastNewIns->SetSVar(m_pStackPointer[0].var); | ||
| PushStackType(StackTypeI, NULL); | ||
| m_pLastNewIns->SetDVar(m_pStackPointer[-1].var); | ||
| return true; | ||
| } | ||
| case NI_System_Threading_Interlocked_CompareExchange: | ||
| { | ||
| CHECK_STACK(3); | ||
| InterpType retType = GetInterpType(sig.retType); | ||
| int32_t opcode; | ||
| switch (retType) | ||
| { | ||
| case InterpTypeI4: | ||
| opcode = INTOP_COMPARE_EXCHANGE_I4; | ||
| break; | ||
| case InterpTypeI8: | ||
| opcode = INTOP_COMPARE_EXCHANGE_I8; | ||
| break; | ||
| default: | ||
| return false; | ||
| } | ||
| AddIns(opcode); | ||
| m_pStackPointer -= 3; | ||
| int32_t addrVar = m_pStackPointer[0].var; | ||
| int32_t valueVar = m_pStackPointer[1].var; | ||
| int32_t comparandVar = m_pStackPointer[2].var; | ||
| PushInterpType(retType, nullptr); | ||
| m_pLastNewIns->SetSVars3(addrVar, valueVar, comparandVar); | ||
| m_pLastNewIns->SetDVar(m_pStackPointer[-1].var); | ||
| return true; | ||
| } | ||
| case NI_System_Runtime_CompilerServices_RuntimeHelpers_IsReferenceOrContainsReferences: | ||
| { | ||
| CORINFO_CLASS_HANDLE clsHnd = sig.sigInst.methInst[0]; | ||
| bool isValueType = (m_compHnd->getClassAttribs(clsHnd) & CORINFO_FLG_VALUECLASS) != 0; | ||
| bool hasGCRefs = false; | ||
| if (isValueType) | ||
| { | ||
| // Walk the layout to see if any field is a GC pointer | ||
| const uint32_t maxSlots = 256; | ||
| BYTE gcLayout[maxSlots]; | ||
| uint32_t numSlots = m_compHnd->getClassGClayout(clsHnd, gcLayout); | ||
| for (uint32_t i = 0; i < numSlots; ++i) | ||
| { | ||
| if (gcLayout[i] != TYPE_GC_NONE) | ||
| { | ||
| hasGCRefs = true; | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| int32_t result = (!isValueType || hasGCRefs) ? 1 : 0; | ||
| AddIns(INTOP_LDC_I4); | ||
| m_pLastNewIns->data[0] = result; | ||
| PushInterpType(InterpTypeI4, nullptr); | ||
| m_pLastNewIns->SetDVar(m_pStackPointer[-1].var); | ||
| return true; | ||
| } | ||
| case NI_System_Runtime_InteropService_MemoryMarshal_GetArrayDataReference: | ||
| { | ||
| CHECK_STACK(1); | ||
| m_pStackPointer--; | ||
| int32_t arrayVar = m_pStackPointer[0].var; | ||
| AddIns(INTOP_NULLCHECK); | ||
| m_pLastNewIns->SetSVar(arrayVar); | ||
| AddIns(INTOP_ADD_P_IMM); | ||
kotlarmilos marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| m_pLastNewIns->SetSVar(arrayVar); | ||
| m_pLastNewIns->data[0] = OFFSETOF__CORINFO_Array__data; | ||
| PushInterpType(InterpTypeByRef, NULL); | ||
| m_pLastNewIns->SetDVar(m_pStackPointer[-1].var); | ||
| return true; | ||
| } | ||
| case NI_System_Threading_Thread_FastPollGC: | ||
| AddIns(INTOP_SAFEPOINT); | ||
| return true; | ||
| default: | ||
| { | ||
| #ifdef DEBUG | ||
| @@ -2257,7 +2407,6 @@ bool InterpCompiler::EmitCallIntrinsics(CORINFO_METHOD_HANDLE method, CORINFO_SI | ||
| return true; | ||
| } | ||
| } | ||
| // TODO: Add multi-dimensional array getters and setters | ||
| } | ||
| return false; | ||
| @@ -2990,27 +3139,6 @@ void InterpCompiler::EmitCall(CORINFO_RESOLVED_TOKEN* pConstrainedToken, bool re | ||
| m_ip += 5; | ||
| } | ||
| static int32_t GetLdindForType(InterpType interpType) | ||
| { | ||
| switch (interpType) | ||
| { | ||
| case InterpTypeI1: return INTOP_LDIND_I1; | ||
| case InterpTypeU1: return INTOP_LDIND_U1; | ||
| case InterpTypeI2: return INTOP_LDIND_I2; | ||
| case InterpTypeU2: return INTOP_LDIND_U2; | ||
| case InterpTypeI4: return INTOP_LDIND_I4; | ||
| case InterpTypeI8: return INTOP_LDIND_I8; | ||
| case InterpTypeR4: return INTOP_LDIND_R4; | ||
| case InterpTypeR8: return INTOP_LDIND_R8; | ||
| case InterpTypeO: return INTOP_LDIND_I; | ||
| case InterpTypeVT: return INTOP_LDIND_VT; | ||
| case InterpTypeByRef: return INTOP_LDIND_I; | ||
| default: | ||
| assert(0); | ||
| } | ||
| return -1; | ||
| } | ||
| static int32_t GetStindForType(InterpType interpType) | ||
| { | ||
| switch (interpType) | ||
| @@ -5153,6 +5281,9 @@ void InterpCompiler::GenerateCode(CORINFO_METHOD_INFO* methodInfo) | ||
| volatile_ = true; | ||
| m_ip++; | ||
| break; | ||
| case CEE_UNALIGNED: | ||
| m_ip += 2; | ||
| break; | ||
| case CEE_INITOBJ: | ||
| { | ||
| CHECK_STACK(1); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.