Skip to content

Commit

Permalink
new helper
Browse files Browse the repository at this point in the history
  • Loading branch information
EgorBo committed Dec 2, 2023
1 parent 712c5e9 commit 262c43c
Show file tree
Hide file tree
Showing 22 changed files with 69 additions and 19 deletions.
1 change: 1 addition & 0 deletions docs/design/coreclr/botr/readytorun-format.md
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,7 @@ enum ReadyToRunHelper

// JIT32 x86-specific exception handling
READYTORUN_HELPER_EndCatch = 0x110,
READYTORUN_HELPER_MemSetGc = 0x115,
};
```

Expand Down
1 change: 1 addition & 0 deletions src/coreclr/inc/corinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,7 @@ enum CorInfoHelpFunc
CORINFO_HELP_INIT_PINVOKE_FRAME, // initialize an inlined PInvoke Frame for the JIT-compiler

CORINFO_HELP_MEMSET, // Init block of memory
CORINFO_HELP_MEMSET_GC, // Init block of memory (with GC pointers)
CORINFO_HELP_MEMCPY, // Copy block of memory

CORINFO_HELP_RUNTIMEHANDLE_METHOD, // determine a type/field/method handle at run-time
Expand Down
10 changes: 5 additions & 5 deletions src/coreclr/inc/jiteeversionguid.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 = { /* 315a2753-6b4e-4b31-b8b0-c1b9b53ba8f6 */
0x315a2753,
0x6b4e,
0x4b31,
{0xb8, 0xb0, 0xc1, 0xb9, 0xb5, 0x3b, 0xa8, 0xf6}
};

//////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/inc/jithelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@
JITHELPER(CORINFO_HELP_MEMCPY, NULL, CORINFO_HELP_SIG_CANNOT_USE_ALIGN_STUB)
#else
JITHELPER(CORINFO_HELP_MEMSET, JIT_MemSet, CORINFO_HELP_SIG_REG_ONLY)
JITHELPER(CORINFO_HELP_MEMSET_GC, JIT_MemSetGc, CORINFO_HELP_SIG_REG_ONLY)
JITHELPER(CORINFO_HELP_MEMCPY, JIT_MemCpy, CORINFO_HELP_SIG_REG_ONLY)
#endif

Expand Down
4 changes: 3 additions & 1 deletion src/coreclr/inc/readytorun.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// src/coreclr/tools/Common/Internal/Runtime/ModuleHeaders.cs
// src/coreclr/nativeaot/Runtime/inc/ModuleHeaders.h
#define READYTORUN_MAJOR_VERSION 0x0009
#define READYTORUN_MINOR_VERSION 0x0001
#define READYTORUN_MINOR_VERSION 0x0002

#define MINIMUM_READYTORUN_MAJOR_VERSION 0x009

Expand All @@ -31,6 +31,7 @@
// R2R Version 8.0 Changes the alignment of the Int128 type
// R2R Version 9.0 adds support for the Vector512 type
// R2R Version 9.1 adds new helpers to allocate objects on frozen segments
// R2R Version 9.2 adds GC-aware memset helper

struct READYTORUN_CORE_HEADER
{
Expand Down Expand Up @@ -439,6 +440,7 @@ enum ReadyToRunHelper
// Array helpers for use with native ints
READYTORUN_HELPER_Stelem_Ref_I = 0x113,
READYTORUN_HELPER_Ldelema_Ref_I = 0x114,
READYTORUN_HELPER_MemSetGc = 0x115,
};

#include "readytoruninstructionset.h"
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/inc/readytorunhelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ HELPER(READYTORUN_HELPER_Stelem_Ref, CORINFO_HELP_ARRADDR_ST,
HELPER(READYTORUN_HELPER_Ldelema_Ref, CORINFO_HELP_LDELEMA_REF, )

HELPER(READYTORUN_HELPER_MemSet, CORINFO_HELP_MEMSET, )
HELPER(READYTORUN_HELPER_MemSetGc, CORINFO_HELP_MEMSET_GC, )
HELPER(READYTORUN_HELPER_MemCpy, CORINFO_HELP_MEMCPY, )

HELPER(READYTORUN_HELPER_LogMethodEnter, CORINFO_HELP_BBT_FCN_ENTER, )
Expand Down
6 changes: 4 additions & 2 deletions src/coreclr/jit/codegenarmarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3232,15 +3232,17 @@ void CodeGen::genCodeForInitBlkHelper(GenTreeBlk* initBlkNode)
{
// Size goes in arg2, source address goes in arg1, and size goes in arg2.
// genConsumeBlockOp takes care of this for us.
genConsumeBlockOp(initBlkNode, REG_ARG_0, REG_ARG_1, REG_ARG_2);
// NOTE: CORINFO_HELP_MEMSET_GC only zeroes memory so it doesn't need source arg.
const bool gcAware = initBlkNode->IsOnHeapAndContainsReferences();
genConsumeBlockOp(initBlkNode, REG_ARG_0, gcAware ? REG_NA : REG_ARG_1, REG_ARG_2);

if (initBlkNode->IsVolatile())
{
// issue a full memory barrier before a volatile initBlock Operation
instGen_MemoryBarrier();
}

genEmitHelperCall(CORINFO_HELP_MEMSET, 0, EA_UNKNOWN);
genEmitHelperCall(gcAware ? CORINFO_HELP_MEMSET_GC : CORINFO_HELP_MEMSET, 0, EA_UNKNOWN);
}

//------------------------------------------------------------------------
Expand Down
5 changes: 4 additions & 1 deletion src/coreclr/jit/codegenlinear.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2050,7 +2050,10 @@ void CodeGen::genConsumeBlockOp(GenTreeBlk* blkNode, regNumber dstReg, regNumber

// Next, perform any necessary moves.
genCopyRegIfNeeded(dstAddr, dstReg);
genSetBlockSrc(blkNode, srcReg);
if (srcReg != REG_NA)
{
genSetBlockSrc(blkNode, srcReg);
}
genSetBlockSize(blkNode, sizeReg);
}

Expand Down
6 changes: 4 additions & 2 deletions src/coreclr/jit/codegenloongarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6375,15 +6375,17 @@ void CodeGen::genCodeForInitBlkHelper(GenTreeBlk* initBlkNode)
{
// Size goes in arg2, source address goes in arg1, and size goes in arg2.
// genConsumeBlockOp takes care of this for us.
genConsumeBlockOp(initBlkNode, REG_ARG_0, REG_ARG_1, REG_ARG_2);
// NOTE: CORINFO_HELP_MEMSET_GC only zeroes memory so it doesn't need source arg.
const bool gcAware = initBlkNode->IsOnHeapAndContainsReferences();
genConsumeBlockOp(initBlkNode, REG_ARG_0, gcAware ? REG_NA : REG_ARG_1, REG_ARG_2);

if (initBlkNode->IsVolatile())
{
// issue a full memory barrier before a volatile initBlock Operation
instGen_MemoryBarrier();
}

genEmitHelperCall(CORINFO_HELP_MEMSET, 0, EA_UNKNOWN);
genEmitHelperCall(gcAware ? CORINFO_HELP_MEMSET_GC : CORINFO_HELP_MEMSET, 0, EA_UNKNOWN);
}

// Generate code for a load from some address + offset
Expand Down
6 changes: 4 additions & 2 deletions src/coreclr/jit/codegenriscv64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6073,15 +6073,17 @@ void CodeGen::genCodeForInitBlkHelper(GenTreeBlk* initBlkNode)
{
// Size goes in arg2, source address goes in arg1, and size goes in arg2.
// genConsumeBlockOp takes care of this for us.
genConsumeBlockOp(initBlkNode, REG_ARG_0, REG_ARG_1, REG_ARG_2);
// NOTE: CORINFO_HELP_MEMSET_GC only zeroes memory so it doesn't need source arg.
const bool gcAware = initBlkNode->IsOnHeapAndContainsReferences();
genConsumeBlockOp(initBlkNode, REG_ARG_0, gcAware ? REG_NA : REG_ARG_1, REG_ARG_2);

if (initBlkNode->IsVolatile())
{
// issue a full memory barrier before a volatile initBlock Operation
instGen_MemoryBarrier();
}

genEmitHelperCall(CORINFO_HELP_MEMSET, 0, EA_UNKNOWN);
genEmitHelperCall(gcAware ? CORINFO_HELP_MEMSET_GC : CORINFO_HELP_MEMSET, 0, EA_UNKNOWN);
}

//------------------------------------------------------------------------
Expand Down
7 changes: 4 additions & 3 deletions src/coreclr/jit/codegenxarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3326,9 +3326,10 @@ void CodeGen::genCodeForInitBlkHelper(GenTreeBlk* initBlkNode)
{
// Destination address goes in arg0, source address goes in arg1, and size goes in arg2.
// genConsumeBlockOp takes care of this for us.
genConsumeBlockOp(initBlkNode, REG_ARG_0, REG_ARG_1, REG_ARG_2);

genEmitHelperCall(CORINFO_HELP_MEMSET, 0, EA_UNKNOWN);
// NOTE: CORINFO_HELP_MEMSET_GC only zeroes memory so it doesn't need source arg.
const bool gcAware = initBlkNode->IsOnHeapAndContainsReferences();
genConsumeBlockOp(initBlkNode, REG_ARG_0, gcAware ? REG_NA : REG_ARG_1, REG_ARG_2);
genEmitHelperCall(gcAware ? CORINFO_HELP_MEMSET_GC : CORINFO_HELP_MEMSET, 0, EA_UNKNOWN);
}
#endif // TARGET_AMD64

Expand Down
2 changes: 0 additions & 2 deletions src/coreclr/jit/gentree.h
Original file line number Diff line number Diff line change
Expand Up @@ -7337,12 +7337,10 @@ struct GenTreeBlk : public GenTreeIndir
bool gtBlkOpGcUnsafe;
#endif

#ifdef TARGET_XARCH
bool IsOnHeapAndContainsReferences()
{
return (m_layout != nullptr) && m_layout->HasGCPtr() && !Addr()->OperIs(GT_LCL_ADDR);
}
#endif

GenTreeBlk(genTreeOps oper, var_types type, GenTree* addr, ClassLayout* layout)
: GenTreeIndir(oper, type, addr, nullptr)
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5577,6 +5577,7 @@ PhaseStatus Compiler::optFindLoopsPhase()

case CORINFO_HELP_ASSIGN_STRUCT: // Not strictly needed as we don't use this
case CORINFO_HELP_MEMSET: // Not strictly needed as we don't make a GT_CALL with this
case CORINFO_HELP_MEMSET_GC: // Not strictly needed as we don't make a GT_CALL with this
case CORINFO_HELP_MEMCPY: // Not strictly needed as we don't make a GT_CALL with this
case CORINFO_HELP_SETFIELDSTRUCT:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,17 @@ public static unsafe void RhUnbox(object? obj, ref byte data, MethodTable* pUnbo
}
}

[RuntimeExport("MemSetGc")]
public static unsafe void MemSetGc(nuint* dest, nuint size)
{
nuint numOfPointers = size / (nuint)sizeof(nuint);
Debug.Assert(size % (nuint)sizeof(nuint) == 0);
for (nuint i = 0; i < numOfPointers; i++)
{
dest[i] = 0;
}
}

[RuntimeExport("RhGetCurrentThreadStackTrace")]
[MethodImpl(MethodImplOptions.NoInlining)] // Ensures that the RhGetCurrentThreadStackTrace frame is always present
public static unsafe int RhGetCurrentThreadStackTrace(IntPtr[] outputBuffer)
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/tools/Common/Internal/Runtime/ModuleHeaders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal struct ReadyToRunHeaderConstants
public const uint Signature = 0x00525452; // 'RTR'

public const ushort CurrentMajorVersion = 9;
public const ushort CurrentMinorVersion = 1;
public const ushort CurrentMinorVersion = 2;
}
#if READYTORUN
#pragma warning disable 0169
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ public enum ReadyToRunHelper
StackProbe = 0x111,

GetCurrentManagedThreadId = 0x112,
MemSetGc = 0x115,

// **********************************************************************************************
//
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/tools/Common/JitInterface/CorInfoHelpFunc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ public enum CorInfoHelpFunc
CORINFO_HELP_INIT_PINVOKE_FRAME, // initialize an inlined PInvoke Frame for the JIT-compiler

CORINFO_HELP_MEMSET, // Init block of memory
CORINFO_HELP_MEMSET_GC, // Init block of memory (with GC pointers)
CORINFO_HELP_MEMCPY, // Copy block of memory

CORINFO_HELP_RUNTIMEHANDLE_METHOD, // determine a type/field/method handle at run-time
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ public static void GetEntryPoint(TypeSystemContext context, ReadyToRunHelper id,
case ReadyToRunHelper.MemSet:
mangledName = "memset"; // TODO: Null reference handling
break;
case ReadyToRunHelper.MemSetGc:
mangledName = "MemSetGc";
break;

case ReadyToRunHelper.GetRuntimeTypeHandle:
methodDesc = context.GetHelperEntryPoint("LdTokenHelpers", "GetRuntimeTypeHandle");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,9 @@ private ISymbolNode GetHelperFtnUncached(CorInfoHelpFunc ftnNum)
case CorInfoHelpFunc.CORINFO_HELP_MEMSET:
id = ReadyToRunHelper.MemSet;
break;
case CorInfoHelpFunc.CORINFO_HELP_MEMSET_GC:
id = ReadyToRunHelper.MemSetGc;
break;
case CorInfoHelpFunc.CORINFO_HELP_MEMCPY:
id = ReadyToRunHelper.MemCpy;
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1684,6 +1684,9 @@ private void ParseHelper(StringBuilder builder)
case ReadyToRunHelper.MemSet:
builder.Append("MEM_SET");
break;
case ReadyToRunHelper.MemSetGc:
builder.Append("MEM_SET_GC");
break;

case ReadyToRunHelper.MemCpy:
builder.Append("MEM_CPY");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,9 @@ private ISymbolNode GetHelperFtnUncached(CorInfoHelpFunc ftnNum)
case CorInfoHelpFunc.CORINFO_HELP_MEMSET:
id = ReadyToRunHelper.MemSet;
break;
case CorInfoHelpFunc.CORINFO_HELP_MEMSET_GC:
id = ReadyToRunHelper.MemSetGc;
break;
case CorInfoHelpFunc.CORINFO_HELP_MEMCPY:
id = ReadyToRunHelper.MemCpy;
break;
Expand Down
10 changes: 10 additions & 0 deletions src/coreclr/vm/jithelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5114,6 +5114,16 @@ FCIMPL0(INT32, JIT_GetCurrentManagedThreadId)
}
FCIMPLEND

HCIMPL2(void, JIT_MemSetGc, intptr_t* dest, size_t count)
{
const size_t numOfPointers = count / sizeof(intptr_t);
_ASSERT(count % sizeof(intptr_t) == 0);
for (size_t i = 0; i < numOfPointers; i++)
{
dest[i] = 0;
}
}
HCIMPLEND

/*********************************************************************/
/* we don't use HCIMPL macros because we don't want the overhead even in debug mode */
Expand Down

0 comments on commit 262c43c

Please sign in to comment.