Skip to content

Commit a33a89c

Browse files
authored
[interp] Implement pinned IL locals (#118975)
Implements pinned IL locals in the interpreter
1 parent b2c99a0 commit a33a89c

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/coreclr/interpreter/compiler.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,6 +1111,9 @@ void InterpCompiler::BuildGCInfo(InterpMethod *pInterpMethod)
11111111
continue;
11121112
}
11131113

1114+
if (pVar->pinned)
1115+
flags = (GcSlotFlags)(flags | GC_SLOT_PINNED);
1116+
11141117
if (pass == 0)
11151118
slotAllocator.AllocateOrReuseGcSlot(pVar->offset, flags);
11161119
else
@@ -1520,9 +1523,11 @@ void InterpCompiler::CreateILVars()
15201523

15211524
for (int i = 0; i < numILLocals; i++) {
15221525
CORINFO_CLASS_HANDLE argClass;
1523-
CorInfoType argCorType = strip(m_compHnd->getArgType(&m_methodInfo->locals, sigArg, &argClass));
1526+
CorInfoTypeWithMod argCorTypeWithFlags = m_compHnd->getArgType(&m_methodInfo->locals, sigArg, &argClass);
1527+
CorInfoType argCorType = strip(argCorTypeWithFlags);
1528+
bool pinned = (argCorTypeWithFlags & CORINFO_TYPE_MOD_PINNED) == CORINFO_TYPE_MOD_PINNED;
15241529
InterpType interpType = GetInterpType(argCorType);
1525-
CreateNextLocalVar(index, argClass, interpType, &offset);
1530+
CreateNextLocalVar(index, argClass, interpType, &offset, pinned);
15261531
sigArg = m_compHnd->getArgNext(sigArg);
15271532
index++;
15281533
}
@@ -1550,7 +1555,7 @@ void InterpCompiler::CreateILVars()
15501555
m_totalVarsStackSize = offset;
15511556
}
15521557

1553-
void InterpCompiler::CreateNextLocalVar(int iArgToSet, CORINFO_CLASS_HANDLE argClass, InterpType interpType, int32_t *pOffset)
1558+
void InterpCompiler::CreateNextLocalVar(int iArgToSet, CORINFO_CLASS_HANDLE argClass, InterpType interpType, int32_t *pOffset, bool pinned)
15541559
{
15551560
int32_t align;
15561561
int32_t size = GetInterpTypeStackSize(argClass, interpType, &align);
@@ -1562,6 +1567,7 @@ void InterpCompiler::CreateNextLocalVar(int iArgToSet, CORINFO_CLASS_HANDLE argC
15621567
m_pVars[iArgToSet].size = size;
15631568
*pOffset = ALIGN_UP_TO(*pOffset, align);
15641569
m_pVars[iArgToSet].offset = *pOffset;
1570+
m_pVars[iArgToSet].pinned = pinned;
15651571
INTERP_DUMP("alloc arg var %d to offset %d\n", iArgToSet, *pOffset);
15661572
*pOffset += size;
15671573
}
@@ -5315,7 +5321,7 @@ void InterpCompiler::GenerateCode(CORINFO_METHOD_INFO* methodInfo)
53155321
int byrefOfTypedRefVar = m_pStackPointer[-1].var;
53165322
m_pLastNewIns->SetDVar(byrefOfTypedRefVar);
53175323
m_pStackPointer--;
5318-
5324+
53195325
AddIns(GetStindForType(InterpTypeByRef));
53205326
m_pLastNewIns->data[0] = OFFSETOF__CORINFO_TypedReference__dataPtr;
53215327
m_pLastNewIns->SetSVars2(byrefOfTypedRefVar, addressVar);
@@ -5380,7 +5386,7 @@ void InterpCompiler::GenerateCode(CORINFO_METHOD_INFO* methodInfo)
53805386
m_pLastNewIns->data[2] = 0;
53815387
m_pLastNewIns->SetSVar(typedByRefVar);
53825388
m_pLastNewIns->SetDVar(classHandleVar);
5383-
5389+
53845390
AddIns(INTOP_CALL_HELPER_P_S);
53855391
m_pLastNewIns->data[0] = GetDataForHelperFtn(CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPEHANDLE_MAYBENULL);
53865392
m_pLastNewIns->SetSVar(classHandleVar);

src/coreclr/interpreter/compiler.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ struct InterpVar
359359
unsigned int global : 1; // Dedicated stack offset throughout method execution
360360
unsigned int ILGlobal : 1; // Args and IL locals
361361
unsigned int alive : 1; // Used internally by the var offset allocator
362+
unsigned int pinned : 1; // Indicates that the var had the 'pinned' modifier in IL
362363

363364
InterpVar(InterpType interpType, CORINFO_CLASS_HANDLE clsHnd, int size)
364365
{
@@ -374,6 +375,7 @@ struct InterpVar
374375
global = false;
375376
ILGlobal = false;
376377
alive = false;
378+
pinned = false;
377379
}
378380
};
379381

@@ -683,7 +685,7 @@ class InterpCompiler
683685
int32_t GetInterpTypeStackSize(CORINFO_CLASS_HANDLE clsHnd, InterpType interpType, int32_t *pAlign);
684686
void CreateILVars();
685687

686-
void CreateNextLocalVar(int iArgToSet, CORINFO_CLASS_HANDLE argClass, InterpType interpType, int32_t *pOffset);
688+
void CreateNextLocalVar(int iArgToSet, CORINFO_CLASS_HANDLE argClass, InterpType interpType, int32_t *pOffset, bool pinned = false);
687689

688690
// Stack
689691
StackInfo *m_pStackPointer, *m_pStackBase;

0 commit comments

Comments
 (0)